IDA逆向:结构体的逆向

源代码:

int _tmain(int argc, _TCHAR* argv[])
{
    struct v1 {
        int a;
        short b;
        char c;
        int d;
        double e;
    };
    v1* heap_struct = (v1*)malloc(sizeof(v1));
    heap_struct->a = 10;
    heap_struct->b = 20;
    heap_struct->c = 30;
    heap_struct->d = 40;
    heap_struct->e = 50;
    return 0;

}

逆向分析:

结构体中的数据字段是通过名称访问的,但编译器将名称访问转换为数字偏移
所以在反汇编中难以区别
堆分配结构体

push    24              ; Size
call    ds:__imp__malloc
add     esp, 4
cmp     esi, esp
call    j___RTC_CheckEsp
mov     [ebp+heap_struct], eax
mov     eax, [ebp+heap_struct]
mov     dword ptr [eax], 10
mov     eax, 20
mov     ecx, [ebp+heap_struct]
mov     [ecx+4], ax
mov     eax, [ebp+heap_struct]
mov     byte ptr [eax+6], 30
mov     eax, [ebp+heap_struct]
mov     dword ptr [eax+8], 40
mov     eax, [ebp+heap_struct]
fld     ds:__real@4049000000000000
fstp    qword ptr [eax+10h]
原类型     大小             偏移
int         4(dword)       0
short       2()            4
char        1byte6
int         4(dword)       8
double      8(qword)      16

  为默认4字节对齐

总结:全局和栈分配方式中的结构体 与  普通变量相似 难以区分

原文地址:https://www.cnblogs.com/HsinTsao/p/6440784.html