#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#define USAGE "usage : ./%s <file>.\r\n"
int main(int argc , char* argv[])
{
printf("ViewTheFuckinPE par 0vercl0k.\n");
if(!argv[1]){printf(USAGE,argv[0]);return 0;}
PIMAGE_DOS_HEADER infosExecutable; PIMAGE_NT_HEADERS infosPE; HANDLE executableHandle = CreateFile(argv[1] , GENERIC_READ , FILE_SHARE_READ , NULL , OPEN_EXISTING , 0 , 0) , executableMappe = CreateFileMapping(executableHandle , NULL , PAGE_READONLY , 0 , 0 , NULL) ; LPVOID executableEnMemoire = MapViewOfFile(executableMappe , FILE_MAP_READ , 0 , 0 , 0); if(executableHandle == INVALID_HANDLE_VALUE || executableMappe == INVALID_HANDLE_VALUE || executableEnMemoire == INVALID_HANDLE_VALUE)return 0;
infosExecutable = (PIMAGE_DOS_HEADER)executableEnMemoire;
if(infosExecutable->e_magic != IMAGE_DOS_SIGNATURE)
{
printf("[!] Il ne s'agit pas d'un binaire au format PE.\n");
return 0;
}
printf("[~] Analyse en cours : \n");
printf("- Entete DOS : %08X.\n",infosExecutable->e_magic);
printf("- Adresse de la table de realocation : %08X.\n",infosExecutable->e_lfarlc);
printf("- Adresse de l'entete PE de notre executable : %08X.\n",infosExecutable->e_lfanew);
infosPE = (PIMAGE_NT_HEADERS)((char*)infosExecutable + infosExecutable->e_lfanew); if(infosPE->Signature != IMAGE_NT_SIGNATURE)
{
printf("[-] La signature PE est corrompu.\n");
return 0;
}
printf("\n---<PE header>---\n\n- Signature PE : %08X\n",infosPE->Signature);
printf("- Machine qui à compiler le binaire : %08X\n- Adresse du point d'entré : %08X\n",infosPE->FileHeader.Machine,infosPE->OptionalHeader.AddressOfEntryPoint);
printf("- Nombre de sections (NumberOfSections) : %08X\n- Offset de la table des symboles (PointerToSymbolTable) : %08X\n",infosPE->FileHeader.NumberOfSections,infosPE->FileHeader.PointerToSymbolTable);
printf("- Adresse Image Base (ImagaBase) : %08X\n\n---</PE header>---\n---<Sections>---\n\n",infosPE->OptionalHeader.ImageBase);
PIMAGE_SECTION_HEADER infosSection = (PIMAGE_SECTION_HEADER)((char*)infosPE + sizeof(IMAGE_NT_HEADERS));
for(int i = 0 ; i < (infosPE->FileHeader.NumberOfSections) ; i++)
{
printf("- Section %d(%s) : \n\t ->Adresse Virtual (RVA de la section) (VirtualAddress) : %08X\n\n",i,(char*)infosSection->Name,infosSection->VirtualAddress);
infosSection++;
}
return 0;
}