Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You just do it the wrong way. I wrote some code for you, hope it helps.It can show the data of the last section of a PE file.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;malloc.h&gt; #include &lt;windows.h&gt; void ShowHexData(BYTE *ptr,DWORD len) { int index = 0; int i = 0; const int width = 16; while(index + width &lt; len) { int i; for(i = 0; i &lt; width; ++i) { printf(" %02X",ptr[index + i]); } printf(" \t"); for(i = 0; i &lt; width; ++i) { if(ptr[index + i] &gt;= 0x20 &amp;&amp; ptr[index + i] &lt;= 0x7F) { putchar(ptr[index + i]); }else{ putchar('.'); } } index += width; putchar('\n'); } for(i = 0; index + i &lt; len; ++ i) { printf(" %02X",ptr[index + i]); } while(i &lt; width) { printf(" "); i += 1; } printf(" \t"); for(i = 0; index + i &lt; len; ++ i) { if(ptr[index + i] &gt;= 0x20 &amp;&amp; ptr[index + i] &lt;= 0x7F) { putchar(ptr[index + i]); }else{ putchar('.'); } } putchar('\n'); } int main(int argc, char *argv[]) { if(argc != 2) { printf("Usage : %s filename\n",argv[0]); return -1; }else{ FILE *fp = fopen(argv[1],"rb"); IMAGE_DOS_HEADER DosHeader = {0}; IMAGE_FILE_HEADER FileHeader = {0}; IMAGE_SECTION_HEADER SectionHeader = {0}; DWORD Signature = 0; DWORD RawPointerToPeHeader = 0, SizeOfFile = 0; DWORD SectionCount = 0; DWORD ByteCount = 0; BYTE *pData = NULL; if(!fp) { perror(""); return -1; } fseek(fp,0,SEEK_END); SizeOfFile = ftell(fp); if(SizeOfFile &lt; sizeof(IMAGE_DOS_HEADER) + sizeof(IMAGE_NT_HEADERS)) goto not_pe_file; fseek(fp,0,SEEK_SET); fread(&amp;DosHeader,1,sizeof DosHeader,fp); if(DosHeader.e_magic != 'M' + 'Z' * 256) goto not_pe_file; RawPointerToPeHeader = DosHeader.e_lfanew; if(SizeOfFile &lt;= RawPointerToPeHeader + sizeof(IMAGE_NT_HEADERS)) goto not_pe_file; fseek(fp,RawPointerToPeHeader,SEEK_SET); fread(&amp;Signature,1,sizeof(DWORD),fp); if(Signature != 'P' + 'E' * 256) goto not_pe_file; fread(&amp;FileHeader,1,sizeof FileHeader,fp); if(FileHeader.SizeOfOptionalHeader != sizeof(IMAGE_OPTIONAL_HEADER)) goto not_pe_file; SectionCount = FileHeader.NumberOfSections; if(SectionCount == 0) { printf("No section for this file.\n"); fclose(fp); return -1; } if(SizeOfFile &lt;= RawPointerToPeHeader + sizeof(IMAGE_NT_HEADERS) + SectionCount * sizeof(IMAGE_SECTION_HEADER)) goto not_pe_file; fseek(fp, RawPointerToPeHeader + sizeof(IMAGE_NT_HEADERS) + (SectionCount - 1) * sizeof(IMAGE_SECTION_HEADER), SEEK_SET); fread(&amp;SectionHeader,1,sizeof SectionHeader,fp); ByteCount = SectionHeader.Misc.VirtualSize &lt; SectionHeader.PointerToRawData ? SectionHeader.Misc.VirtualSize : SectionHeader.PointerToRawData; if(ByteCount == 0) { printf("No data to read for target section.\n"); fclose(fp); return -1; }else if(ByteCount + SectionHeader.PointerToRawData &gt; SizeOfFile) { printf("Bad section data.\n"); fclose(fp); return -1; } fseek(fp,SectionHeader.PointerToRawData,SEEK_SET); pData = (BYTE*)malloc(ByteCount); fread(pData,1,ByteCount,fp); ShowHexData(pData,ByteCount); free(pData); fclose(fp); return 0; not_pe_file: printf("Not a PE file.\n"); fclose(fp); return -1; } return 0; } </code></pre> <p>In short, you do not know where the data is, until you analyze the data according to the file header.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload