Skip to content

Instantly share code, notes, and snippets.

@aaaddress1
Created December 2, 2021 13:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaaddress1/7243554426f5ceee7d0ed8179d57c5d8 to your computer and use it in GitHub Desktop.
Save aaaddress1/7243554426f5ceee7d0ed8179d57c5d8 to your computer and use it in GitHub Desktop.
#include <windows.h>
#include <iostream>
bool readBinFile(const char fileName[], char*& bufPtr, DWORD& length) {
if (FILE* fp = fopen(fileName, "rb")) {
fseek(fp, 0, SEEK_END);
length = ftell(fp);
bufPtr = new char[length + 1];
fseek(fp, 0, SEEK_SET);
fread(bufPtr, sizeof(char), length, fp);
return true;
}
else return false;
}
int main(void) {
char *peData; DWORD peLen;
readBinFile("msgbox.exe", peData, peLen);
IMAGE_DOS_HEADER *dosHdr = (IMAGE_DOS_HEADER *)peData;
IMAGE_NT_HEADERS *ntHdrs = (IMAGE_NT_HEADERS *)&peData[dosHdr->e_lfanew];
printf("dosHdr Magic = %x\n", dosHdr->e_magic);
printf("ntHdrs Magic = %x\n", ntHdrs->Signature);
auto sectionHdrs = (IMAGE_SECTION_HEADER *)((size_t)ntHdrs + sizeof(*ntHdrs));
for (int i = 0; i < ntHdrs->FileHeader.NumberOfSections ; i++) {
printf("%s -> %s\n", sectionHdrs[i].Name, &peData[sectionHdrs[i].PointerToRawData] );
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment