x86/x64 CPUID in C#

后端 未结 7 934
谎友^
谎友^ 2020-11-28 03:18

Related to my other question, please help me debug \"An unhandled exception of type \'System.AccessViolationException\' occurred in Unknown Module. Additional information:

相关标签:
7条回答
  • 2020-11-28 04:07

    i know this thread is old, but i like this thread very much. after coding, I figure out there is problem to get data while "EAX=7,ECX=0" so, I add "mov ecx, 0" in x64CodeBytes.

    private readonly static byte[] x64CodeBytes = {
        0x53,                         // push rbx    this gets clobbered by cpuid
    
        // rcx is level
        // rdx is buffer.
        // Need to save buffer elsewhere, cpuid overwrites rdx
        // Put buffer in r8, use r8 to reference buffer later.        
    
        // Save rdx (buffer addy) to r8
        0x49, 0x89, 0xd0,             // mov r8,  rdx
    
        // Move ecx (level) to eax to call cpuid, call cpuid
        0x89, 0xc8,                   // mov eax, ecx
        0xB9, 0x00, 0x00, 0x00, 0x00, // mov ecx, 0
        0x0F, 0xA2,                   // cpuid
    
        // Write eax et al to buffer
        0x41, 0x89, 0x40, 0x00,       // mov    dword ptr [r8+0],  eax
        0x41, 0x89, 0x58, 0x04,       // mov    dword ptr [r8+4],  ebx
        0x41, 0x89, 0x48, 0x08,       // mov    dword ptr [r8+8],  ecx
        0x41, 0x89, 0x50, 0x0c,       // mov    dword ptr [r8+12], edx
    
        0x5b,                         // pop rbx
        0xc3                          // ret
        };
    
    0 讨论(0)
提交回复
热议问题