Created
November 14, 2017 17:20
-
-
Save f0r34chb3t4/af9db52b40af4242ab434cf8ebb6bdf8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| void getPSN(char *PSN) | |
| { | |
| int varEAX, varEBX, varECX, varEDX; | |
| char str[9]; | |
| //%eax=1 gives most significant 32 bits in eax | |
| __asm__ __volatile__ ("cpuid" : "=a" (varEAX), "=b" (varEBX), "=c" (varECX), "=d" (varEDX) : "a" (1)); | |
| sprintf(str, "%08X", varEAX); //i.e. XXXX-XXXX-xxxx-xxxx-xxxx-xxxx | |
| sprintf(PSN, "%C%C%C%C-%C%C%C%C", str[0], str[1], str[2], str[3], str[4], str[5], str[6], str[7]); | |
| //%eax=3 gives least significant 64 bits in edx and ecx [if PN is enabled] | |
| __asm__ __volatile__ ("cpuid" : "=a" (varEAX), "=b" (varEBX), "=c" (varECX), "=d" (varEDX) : "a" (3)); | |
| sprintf(str, "%08X", varEDX); //i.e. xxxx-xxxx-XXXX-XXXX-xxxx-xxxx | |
| sprintf(PSN, "%s-%C%C%C%C-%C%C%C%C", PSN, str[0], str[1], str[2], str[3], str[4], str[5], str[6], str[7]); | |
| sprintf(str, "%08X", varECX); //i.e. xxxx-xxxx-xxxx-xxxx-XXXX-XXXX | |
| sprintf(PSN, "%s-%C%C%C%C-%C%C%C%C", PSN, str[0], str[1], str[2], str[3], str[4], str[5], str[6], str[7]); | |
| } | |
| int main() | |
| { | |
| char PSN[30]; //24 Hex digits, 5 '-' separators, and a '\0' | |
| getPSN(PSN); | |
| printf("%s\n", PSN); //compare with: lshw | grep serial: | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment