Wednesday, 21 December 2011

Retrieve CPU brand by C and Win32 API

Retrieve CPU brand by C and Win32 API
This task use C and Win32 API to read CPU brand.
Read CPU brand using cpuid
Call GetCPUBrand method to retrieve CPU brand.
1string GetCPUBrand() {
2 char pszCPUBrand[49];
3 memset(pszCPUBrand, ' ', 49);
4
5 _asm {
6 mov eax, 80000002h
7 cpuid
8
9 // getting information from EAX
10
11 mov pszCPUBrand[0], al
12 mov pszCPUBrand[1], ah
13 ror eax, 16
14 mov pszCPUBrand[2], al
15 mov pszCPUBrand[3], ah
16
17 // getting information from EBX
18
19 mov pszCPUBrand[4], bl
20 mov pszCPUBrand[5], bh
21 ror ebx, 16
22 mov pszCPUBrand[6], bl
23 mov pszCPUBrand[7], bh
24
25 // getting information from ECX
26
27 mov pszCPUBrand[8], cl
28 mov pszCPUBrand[9], ch
29 ror ecx, 16
30 mov pszCPUBrand[10], cl
31 mov pszCPUBrand[11], ch
32
33 // getting information from EDX
34
35 mov pszCPUBrand[12], dl
36 mov pszCPUBrand[13], dh
37 ror edx, 16
38 mov pszCPUBrand[14], dl
39 mov pszCPUBrand[15], dh
40
41 mov eax, 80000003h
42 cpuid
43
44 // getting information from EAX
45
46 mov pszCPUBrand[16], al
47 mov pszCPUBrand[17], ah
48 ror eax, 16
49 mov pszCPUBrand[18], al
50 mov pszCPUBrand[19], ah
51
52 // getting information from EBX
53
54 mov pszCPUBrand[20], bl
55 mov pszCPUBrand[21], bh
56 ror ebx, 16
57 mov pszCPUBrand[22], bl
58 mov pszCPUBrand[23], bh
59
60 // getting information from ECX
61
62 mov pszCPUBrand[24], cl
63 mov pszCPUBrand[25], ch
64 ror ecx, 16
65 mov pszCPUBrand[26], cl
66 mov pszCPUBrand[27], ch
67
68 // getting information from EDX
69
70 mov pszCPUBrand[28], dl
71 mov pszCPUBrand[29], dh
72 ror edx, 16
73 mov pszCPUBrand[30], dl
74 mov pszCPUBrand[31], dh
75
76 mov eax, 80000004h
77 cpuid
78
79 // getting information from EAX
80
81 mov pszCPUBrand[32], al
82 mov pszCPUBrand[33], ah
83 ror eax, 16
84 mov pszCPUBrand[34], al
85 mov pszCPUBrand[35], ah
86
87 // getting information from EBX
88
89 mov pszCPUBrand[36], bl
90 mov pszCPUBrand[37], bh
91 ror ebx, 16
92 mov pszCPUBrand[38], bl
93 mov pszCPUBrand[39], bh
94
95 // getting information from ECX
96
97 mov pszCPUBrand[40], cl
98 mov pszCPUBrand[41], ch
99 ror ecx, 16
100 mov pszCPUBrand[42], cl
101 mov pszCPUBrand[43], ch
102
103 // getting information from EDX
104
105 mov pszCPUBrand[44], dl
106 mov pszCPUBrand[45], dh
107 ror edx, 16
108 mov pszCPUBrand[46], dl
109 mov pszCPUBrand[47], dh
110
111 }
112
113 pszCPUBrand[48] = '\0';
114
115 return string(pszCPUBrand);
116}
string GetCPUBrand() {
    char pszCPUBrand[49];  
    memset(pszCPUBrand, ' ', 49);  
     
    _asm {
        mov eax, 80000002h
        cpuid
  
        // getting information from EAX
  
        mov pszCPUBrand[0], al
        mov pszCPUBrand[1], ah
        ror eax, 16
        mov pszCPUBrand[2], al
        mov pszCPUBrand[3], ah
  
        // getting information from EBX
  
        mov pszCPUBrand[4], bl
        mov pszCPUBrand[5], bh
        ror ebx, 16
        mov pszCPUBrand[6], bl
        mov pszCPUBrand[7], bh
  
        // getting information from ECX
  
        mov pszCPUBrand[8], cl
        mov pszCPUBrand[9], ch
        ror ecx, 16
        mov pszCPUBrand[10], cl
        mov pszCPUBrand[11], ch
  
        // getting information from EDX
  
        mov pszCPUBrand[12], dl
        mov pszCPUBrand[13], dh
        ror edx, 16
        mov pszCPUBrand[14], dl
        mov pszCPUBrand[15], dh
  
        mov eax, 80000003h
        cpuid
  
        // getting information from EAX
  
        mov pszCPUBrand[16], al
        mov pszCPUBrand[17], ah
        ror eax, 16
        mov pszCPUBrand[18], al
        mov pszCPUBrand[19], ah
  
        // getting information from EBX
  
        mov pszCPUBrand[20], bl
        mov pszCPUBrand[21], bh
        ror ebx, 16
        mov pszCPUBrand[22], bl
        mov pszCPUBrand[23], bh
  
        // getting information from ECX
  
        mov pszCPUBrand[24], cl
        mov pszCPUBrand[25], ch
        ror ecx, 16
        mov pszCPUBrand[26], cl
        mov pszCPUBrand[27], ch
  
        // getting information from EDX
  
        mov pszCPUBrand[28], dl
        mov pszCPUBrand[29], dh
        ror edx, 16
        mov pszCPUBrand[30], dl
        mov pszCPUBrand[31], dh
  
        mov eax, 80000004h
        cpuid
  
        // getting information from EAX
  
        mov pszCPUBrand[32], al
        mov pszCPUBrand[33], ah
        ror eax, 16
        mov pszCPUBrand[34], al
        mov pszCPUBrand[35], ah
  
        // getting information from EBX
   
        mov pszCPUBrand[36], bl
        mov pszCPUBrand[37], bh
        ror ebx, 16
        mov pszCPUBrand[38], bl
        mov pszCPUBrand[39], bh
  
        // getting information from ECX
  
        mov pszCPUBrand[40], cl
        mov pszCPUBrand[41], ch
        ror ecx, 16
        mov pszCPUBrand[42], cl
        mov pszCPUBrand[43], ch
  
        // getting information from EDX
  
        mov pszCPUBrand[44], dl
        mov pszCPUBrand[45], dh
        ror edx, 16
        mov pszCPUBrand[46], dl
        mov pszCPUBrand[47], dh
  
    }
  
    pszCPUBrand[48] = '\0';
  
    return string(pszCPUBrand);
}

  Protected by Copyscape Online Copyright Protection

No comments:

Post a Comment