1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| #include<stdio.h> #include<stdlib.h> #include<string.h> void* readtest() { FILE* fp = fopen("test32.exe","rb"); long n; void* p; if(fp == NULL) { printf("failed"); exit(0); } fseek(fp,0,2); n = ftell(fp); p = malloc(n); if(p == NULL) { printf("failed"); exit(0); } fseek(fp,0,0); fread(p,1,n,fp); return p; } int main() { char* p; p = (char*)readtest(); int NT_offset; int sizeofoptionalheader; int numberofsections; int sec_offset; int i; NT_offset = *(int*)(p + 0x3c); sizeofoptionalheader = *(short*)(p + NT_offset + 4 + 0x10); numberofsections = *(short*)(p + NT_offset + 4 + 2); printf("DWORD e_lfanew:0x%x\n",NT_offset); printf("WORD SizeOfOptionalHeader:0x%x\n",sizeofoptionalheader); printf("WORD NumberOfSections:0x%x\n",numberofsections); sec_offset = NT_offset + 4 + 0x14 + sizeofoptionalheader; for(i=0;i<numberofsections;i++) { char tmp[9]; tmp[8] = '\0'; memcpy(tmp,(p + sec_offset + i*0x28),8); printf("Name:%s\n",tmp); printf("Misc:0x%x\n",*(int*)(p + sec_offset + i*0x28 + 8)); printf("VirtualAddress:0x%x\n",*(int*)(p + sec_offset + i*0x28 + 0x0c)); printf("SizeOfRawData:0x%x\n",*(int*)(p + sec_offset + i*0x28 + 0x10)); printf("PointerToRawData:0x%x\n",*(int*)(p + sec_offset + i*0x28 + 0x14)); printf("PointerToRelocations:0x%x\n",*(int*)(p + sec_offset + i*0x28 + 0x18)); printf("PointerToLinenumbers:0x%x\n",*(int*)(p + sec_offset + i*0x28 + 0x1c)); printf("NumberOfRelocations:0x%x\n",*(short*)(p + sec_offset + i*0x28 + 0x20)); printf("NumberOfLinenumbers:0x%x\n",*(short*)(p + sec_offset + i*0x28 + 0x22)); printf("Characteristics:0x%x\n",*(int*)(p + sec_offset + i*0x28 + 0x24)); } return 0; }
|