Giter VIP home page Giter VIP logo

cpuid.py's Introduction

cpuid.py

Now, this is silly!

Pure Python library for accessing information about x86 processors by querying the CPUID instruction. Well, not exactly pure Python...

It works by allocating a small piece of virtual memory, copying a raw x86 function to that memory, giving the memory execute permissions and then calling the memory as a function. The injected function executes the CPUID instruction and copies the result back to a ctypes.Structure where is can be read by Python.

It should work fine on both 32 and 64 bit versions of Windows and Linux running x86 processors. Apple OS X and other BSD systems should also work, not tested though...

Why?

For poops and giggles. Plus, having access to a low-level feature without having to compile a C wrapper is pretty neat.

Forker's note

I wanted the output to be compatible with the GNU cpuid, so that I could run the script (without even downloading it) on a remote machine and pipe the output into cpuid -f.

Examples

Getting info with eax=0:

import cpuid

q = cpuid.CPUID()
eax, ebx, ecx, edx = q(0)

Running the files:

$ python cpuid.py
CPU:
   0x00000000 0x00: eax=0x00000010 ebx=0x68747541 ecx=0x444d4163 edx=0x69746e65
   0x00000001 0x00: eax=0x00a20f12 ebx=0x0a100800 ecx=0x7ef8320b edx=0x178bfbff
   0x00000002 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x00000003 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x00000004 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x00000005 0x00: eax=0x00000040 ebx=0x00000040 ecx=0x00000003 edx=0x00000011
   0x00000006 0x00: eax=0x00000004 ebx=0x00000000 ecx=0x00000001 edx=0x00000000
   0x00000007 0x00: eax=0x00000000 ebx=0x219c97a9 ecx=0x0040068c edx=0x00000010
   0x00000008 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x00000009 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x0000000a 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x0000000b 0x00: eax=0x00000001 ebx=0x00000002 ecx=0x00000100 edx=0x00000006
   0x0000000b 0x01: eax=0x00000004 ebx=0x00000010 ecx=0x00000201 edx=0x0000000e
   0x0000000b 0x02: eax=0x00000000 ebx=0x00000000 ecx=0x00000002 edx=0x0000000a
   0x0000000c 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x0000000d 0x00: eax=0x00000207 ebx=0x00000340 ecx=0x00000988 edx=0x00000000
   0x0000000d 0x01: eax=0x0000000f ebx=0x00000350 ecx=0x00001800 edx=0x00000000
   0x0000000d 0x02: eax=0x00000100 ebx=0x00000240 ecx=0x00000000 edx=0x00000000
   0x0000000d 0x09: eax=0x00000008 ebx=0x00000980 ecx=0x00000000 edx=0x00000000
   0x0000000d 0x0b: eax=0x00000010 ebx=0x00000000 ecx=0x00000001 edx=0x00000000
   0x0000000d 0x0c: eax=0x00000018 ebx=0x00000000 ecx=0x00000001 edx=0x00000000
   0x0000000e 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x0000000f 0x00: eax=0x00000000 ebx=0x000000ff ecx=0x00000000 edx=0x00000002
   0x0000000f 0x01: eax=0x00000000 ebx=0x00000040 ecx=0x000000ff edx=0x00000007
   0x00000010 0x00: eax=0x00000000 ebx=0x00000002 ecx=0x00000000 edx=0x00000000
   0x00000010 0x01: eax=0x0000000f ebx=0x00000000 ecx=0x00000004 edx=0x0000000f
   0x20000000 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x80000000 0x00: eax=0x80000023 ebx=0x68747541 ecx=0x444d4163 edx=0x69746e65
   0x80000001 0x00: eax=0x00a20f12 ebx=0x20000000 ecx=0x75c237ff edx=0x2fd3fbff
   0x80000002 0x00: eax=0x20444d41 ebx=0x657a7952 ecx=0x2037206e edx=0x30303835
   0x80000003 0x00: eax=0x2d382058 ebx=0x65726f43 ecx=0x6f725020 edx=0x73736563
   0x80000004 0x00: eax=0x2020726f ebx=0x20202020 ecx=0x20202020 edx=0x00202020
   0x80000005 0x00: eax=0xff40ff40 ebx=0xff40ff40 ecx=0x20080140 edx=0x20080140
   0x80000006 0x00: eax=0x48002200 ebx=0x68004200 ecx=0x02006140 edx=0x01009140
   0x80000007 0x00: eax=0x00000000 ebx=0x0000003b ecx=0x00000000 edx=0x00006799
   0x80000008 0x00: eax=0x00003030 ebx=0x111ef657 ecx=0x0000400f edx=0x00010000
   0x80000009 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x8000000a 0x00: eax=0x00000001 ebx=0x00008000 ecx=0x00000000 edx=0x101bbcff
   0x8000000b 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x8000000c 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x8000000d 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x8000000e 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x8000000f 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x80000010 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x80000011 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x80000012 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x80000013 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x80000014 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x80000015 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x80000016 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x80000017 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x80000018 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x80000019 0x00: eax=0xf040f040 ebx=0xf0400000 ecx=0x00000000 edx=0x00000000
   0x8000001a 0x00: eax=0x00000006 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x8000001b 0x00: eax=0x000003ff ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x8000001c 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x8000001d 0x00: eax=0x00004121 ebx=0x01c0003f ecx=0x0000003f edx=0x00000000
   0x8000001d 0x01: eax=0x00004122 ebx=0x01c0003f ecx=0x0000003f edx=0x00000000
   0x8000001d 0x02: eax=0x00004143 ebx=0x01c0003f ecx=0x000003ff edx=0x00000002
   0x8000001d 0x03: eax=0x0003c163 ebx=0x03c0003f ecx=0x00007fff edx=0x00000001
   0x8000001e 0x00: eax=0x00000002 ebx=0x00000101 ecx=0x00000000 edx=0x00000000
   0x8000001f 0x00: eax=0x0001780f ebx=0x00000173 ecx=0x000001fd edx=0x00000001
   0x80000020 0x00: eax=0x00000000 ebx=0x00000002 ecx=0x00000000 edx=0x00000000
   0x80000020 0x01: eax=0x0000000b ebx=0x00000000 ecx=0x00000000 edx=0x0000000f
   0x80000021 0x00: eax=0x0000004d ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x80000022 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x80000023 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0x80860000 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000
   0xc0000000 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000

cpuid.py's People

Contributors

flababah avatar niklasf avatar dw avatar zeevro avatar vxuyu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.