What does this line mean in Python? What does this line mean in Python? windows windows

What does this line mean in Python?


It executes the following machine code:

push bxxor ax, axinc axcpuidpop bxretn

Basically it calls CPUID instruction of the CPU in order to get information about the CPU. Since EAX=1 it gets the processor info and feature bits. The result 32-bit integer is then displayed on the screen, see the wikipedia article or this page to decode the result.

EDIT: Since that's what you're looking for, here's an excellent article about invoking CPUID in a .NET/C# environment (sort of, with P/Invoke)


In addition to DrJokepu's answer. The python code is using the ctypes modules do implement the following C code(/hack):

char *CPUID = "\x53\x31\xc0\x40\x0f\xa2\x5b\xc3"; // x86 codeunsigned int (*cpuid)() = (unsigned int (*)()) CPUID; // CPUID points to first instruction in above code; cast it to a function pointerprintf("%u",cpuid()); // calling cpuid() effectively executes the x86 code.

Also note that this only returns the information in EAX and the x86 code should probably have also pushed/popped the values of ECX and EDX to be safe.