Por si a alguien le ayuda. Es mejorable, no tiene ningun control de errores era solo para mostrar la idea
.
No se si esto va en esta sección o en la de Programacion en C. Creo que esta mas relacionado con esto.
hookiat.c#include "hookiat.h"
void HookIAT(char *tohooklibrary, char *tohookfunc, void *newfunc)
{
DWORD image_base=GetModuleHandleA(0);
PIMAGE_DOS_HEADER DOS;
PIMAGE_NT_HEADERS NT;
PIMAGE_IMPORT_DESCRIPTOR IT;
PIMAGE_IMPORT_BY_NAME *IMPORTED_FUNCTIONS;
PIMAGE_THUNK_DATA Funcion;
DWORD *IMPORTED_DLL_NAME;
DWORD *IMPORTED_FUNCTION_NAME;
unsigned int i=0;
DOS=(PIMAGE_DOS_HEADER)image_base;
NT=(PIMAGE_NT_HEADERS)(DOS->e_lfanew + image_base);
IT=(PIMAGE_IMPORT_DESCRIPTOR)(NT->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress + image_base);
IMPORTED_DLL_NAME=(DWORD *)(IT->Name + image_base);
while( (IT->Name) != 0 )
{
IMPORTED_DLL_NAME=(DWORD *)(IT->Name + image_base);
if(!strcmp((char *)IMPORTED_DLL_NAME
, tohooklibrary
)) {
break;
}
IT++;
}
IMPORTED_FUNCTIONS=(PIMAGE_IMPORT_BY_NAME *)(IT->Characteristics + image_base);
for(i=0;;i++)
{
IMPORTED_FUNCTION_NAME=(DWORD *)((*IMPORTED_FUNCTIONS)->Name + image_base);
if(((*IMPORTED_FUNCTIONS
)!=0) && (!strcmp((char *)IMPORTED_FUNCTION_NAME
, tohookfunc
))) {
break;
}
IMPORTED_FUNCTIONS++;
}
Funcion=(PIMAGE_THUNK_DATA)(IT->FirstThunk + image_base);
Funcion+=i;
ORIGINAL_FUNCTION=(void *)Funcion->u1.Function;
Funcion->u1.Function=(DWORD)newfunc;
}
hookiat.h#include <string.h>
#include <windows.h>
void *ORIGINAL_FUNCTION;
void HookIAT(char *tohooklibrary, char *tohookfunc, void *newfunc);
Sa1uDoS