Detectar EOF usando el PE

Iniciado por linkgl, Agosto 14, 2011, 12:13:14 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Bueno esta función retorna true si existe EOF en un ejecutable y false si no existe jeje saludos!.
Código: c
#include <stdio.h>
#include <windows.h>
/***************************\
*        _                  *
*       | |                 *
*       | |__               *
* Coder |____|inkgl         *
* Fecha: 02/01/11           *
\***************************/

bool existe_EOF(char *ruta)
{
  //-> Estructuras necesarias
  IMAGE_DOS_HEADER idh;
  IMAGE_NT_HEADERS inh;
  IMAGE_SECTION_HEADER ish;
  //-> Variables necesarias
  FILE *fp;
  DWORD iTam;
  DWORD hTam;
  //Abrimos el archivo para leer en binario
  fp=fopen(ruta,"rb");
  if(fp!=NULL)
  {
    fseek(fp,0,SEEK_END);
    iTam=ftell(fp);
    rewind(fp);
    fread(&idh,sizeof(IMAGE_DOS_HEADER),1,fp);
    fseek(fp,idh.e_lfanew,SEEK_SET);
    fread(&inh,sizeof(IMAGE_NT_HEADERS),1,fp);
    fseek(fp,idh.e_lfanew + sizeof(IMAGE_NT_HEADERS) + sizeof(IMAGE_SECTION_HEADER) * (inh.FileHeader.NumberOfSections - 1),SEEK_SET);
    fread(&ish,sizeof(IMAGE_SECTION_HEADER),1,fp);
    fclose(fp);
    hTam=ish.PointerToRawData + ish.SizeOfRawData;
    if(hTam < iTam)
      return true;
    else
      return false;
  }
}

//->USO
int main()
{
  if(existe_EOF("C:\\salida.exe"))
    printf("El ejecutable tiene EOF");
  else
    printf("El ejecutable no tiene EOF");
  getchar();
  return 0;
}