Advertisement
repeat83

Untitled

Oct 23rd, 2015
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <windows.h>
  6. #include <vector>
  7.  
  8. #define KEY_WOW64_64KEY 0x0100
  9. #define KEY_WOW64_32KEY 0x0200
  10.  
  11. using namespace std;
  12.  
  13. int* cpuid(int eax, int ecx) {
  14. static int r[4];
  15.  
  16. asm volatile (
  17. "mov %%eax,%0;"
  18. "mov %%ecx,%1;"
  19. "cpuid;"
  20. : "=a" (r[0]), "=b" (r[1]), "=c" (r[2]), "=d" (r[3])
  21. : "r" (eax), "r" (ecx)
  22. );
  23. return r;
  24. }
  25.  
  26.  
  27. vector<unsigned char> intToBytes(int paramInt)
  28. {
  29. vector<unsigned char> arrayOfByte(4);
  30. for (int i = 0; i < 4; i++)
  31. arrayOfByte[3 - i] = (paramInt >> (i * 8));
  32. return arrayOfByte;
  33. }
  34.  
  35. int main() {
  36.  
  37. int h1, h2, h3, h4;
  38. h2 = 0;
  39.  
  40. int* reg = cpuid(0,0);
  41. h3 = reg[3];
  42.  
  43. cpuid(1,0);
  44. h1 = reg[3] & 0xFFFFFDFF;
  45. h4 = reg[0] | 0x20;
  46.  
  47. printf(" 0x%08x",h1);
  48. printf(" 0x%08x",h2);
  49. printf(" 0x%08x",h3);
  50. printf(" 0x%08x",h4);
  51. printf(" ProductID");
  52. printf(" [f1.xyz_len24]\n");
  53.  
  54. HKEY hKey;
  55. DWORD dwBufSize = 200;
  56. byte dwReturn[dwBufSize];
  57. if( RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",0, KEY_QUERY_VALUE | KEY_WOW64_64KEY | KEY_WOW64_32KEY, &hKey) == ERROR_SUCCESS)
  58. {
  59. DWORD error = RegQueryValueEx(hKey,"ProductId",0,0, (LPBYTE)dwReturn, &dwBufSize);
  60. if(error == ERROR_SUCCESS)
  61. {
  62. cout << "ProductID: " << dwReturn << endl;
  63. }
  64. else
  65. {
  66. cout << "Cannot query for key value; Error is : " << error << ", dwBufSize="<<dwBufSize<<endl;
  67. }
  68. }
  69. RegCloseKey(hKey);
  70.  
  71. UCHAR t[4];
  72. t = intToBytes(h1);
  73. cout << t << endl;
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement