Created
December 2, 2021 13:02
-
-
Save aaaddress1/7243554426f5ceee7d0ed8179d57c5d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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