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.
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