Chameleon

Chameleon Commit Details

Date:2010-08-13 06:29:35 (13 years 7 months ago)
Author:Evan Lojewski
Commit:357
Parents: 356
Message:Modules can now replace an already laoded function. Added a typecast from char* to UInt32
Changes:
M/branches/meklort/i386/boot2/modules.c

File differences

branches/meklort/i386/boot2/modules.c
855855
856856
857857
858
858
859859
860860
861861
......
926926
927927
928928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
929967
unsigned int lookup_all_symbols(const char* name)
{
unsigned int addr = 0xFFFFFFFF;
if(lookup_symbol && lookup_symbol != 0xFFFFFFFF)
if(lookup_symbol && (UInt32)lookup_symbol != 0xFFFFFFFF)
{
addr = lookup_symbol(name);
if(addr != 0xFFFFFFFF)
return module_start;
}
/*
* Modify a function to call this one, then return once finished.
*/
int hook_function(const char* symbol)
{
return 0;
}
/*
* Locate the symbol for an already loaded function and modify the beginning of
* the function to jump directly to the new one
* example: replace_function("_HelloWorld_start", &replacement_start);
*/
int replace_function(const char* symbol, void* newAddress)
{
UInt32* jumpPointer = malloc(sizeof(UInt32*));
// TODO: look into using the next four bytes of the function instead
UInt32 addr = lookup_all_symbols(symbol);
char* binary = (char*)addr;
if(addr != 0xFFFFFFFF)
{
*binary++ = 0xFF;// Jump
*binary++ = 0x25;// Long Jump
*((UInt32*)binary) = (UInt32)jumpPointer;
*jumpPointer = (UInt32)newAddress;
return 1;
}
else
{
return 0;
}
}

Archive Download the corresponding diff file

Revision: 357