Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add 'AMD64' arch in get_system_arch() #555

Merged
merged 2 commits into from
Mar 25, 2022

Conversation

pingport80
Copy link
Contributor

Summary

This PR appends a condition in the method get_system_arch() which returns the value of platform.uname()[4] when ctypes module is not present. The value can be x86_64 and AMD64 based on the processor type. But for consistency it should return x64 in both the cases.

Before

if arch == 'x86_64`:
    return arch

After

if arch == `x86_64` or arch == `AMD64`:
    return arch

@@ -483,7 +483,7 @@ def get_system_arch():
ctypes.windll.kernel32.GetNativeSystemInfo(ctypes.byref(sysinfo))
values = {0:'x86', 5:'armle', 6:'IA64', 9:'x64'}
arch = values.get(sysinfo.wProcessorArchitecture, uname_info[4])
if arch == 'x86_64':
if arch == 'x86_64' or arch == 'AMD64':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this should be a case insensitive test instead? I'm not sure about the exact output of platform.uname().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, I'll update it, thanks!

@adfoster-r7
Copy link
Contributor

Mac:

>>> import platform
>>> platform.uname()[4]
'x86_64'

Linux:

>>> import platform
>>> platform.uname()[4]
'x86_64'

Windows vm with python 3.1.1 installed via choco

>>> import platform
>>> platform.uname()[4]
'AMD64'
>>>

Potentially relevant issue was raised on Python itself platform.uname()[4] returns 'amd64' on Windows and 'x86-64' on Linux:

Cygwin on Windows uses "x86_64", FreeBSD uses "amd64", Linux uses "x86_64". Mac OS X uses "x86_64" for Intels (and ppc64" for PowerPCs).

@@ -483,7 +483,7 @@ def get_system_arch():
ctypes.windll.kernel32.GetNativeSystemInfo(ctypes.byref(sysinfo))
values = {0:'x86', 5:'armle', 6:'IA64', 9:'x64'}
arch = values.get(sysinfo.wProcessorArchitecture, uname_info[4])
if arch == 'x86_64':
if arch == 'x86_64' or arch.lower() == 'amd64':
Copy link
Contributor

@adfoster-r7 adfoster-r7 Mar 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#555 (comment)

In particular:

Cygwin on Windows uses "x86_64", FreeBSD uses "amd64", Linux uses "x86_64". Mac OS X uses "x86_64" for Intels (and ppc64" for PowerPCs).

Should we add those values too? 👀

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the edgecases are only really around powerpc, which isn't a super relevant target these days

From the freebsd uname man pages:

EXAMPLES
     The hardware platform (-m)	can be different from the machine's processor
     architecture (-p),	e.g., on 64-bit	PowerPC, -m would return powerpc and
     -p	would return powerpc64

@adfoster-r7 adfoster-r7 merged commit cce7414 into rapid7:master Mar 25, 2022
@pingport80 pingport80 deleted the add_AMD64_get_system_arch branch March 25, 2022 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants