Chameleon

Chameleon Commit Details

Date:2014-01-07 09:37:37 (10 years 3 months ago)
Author:Chuck Fry
Commit:2312
Parents: 2311
Message:Add closedir() to match opendir() call; relocate a malloc() call to fix a memory leak on error; better defense against buffer overruns
Changes:
M/branches/chucko/i386/boot2/modules.c

File differences

branches/chucko/i386/boot2/modules.c
105105
106106
107107
108
108
109109
110
110
111111
112112
113113
114114
115
115
116116
117117
118118
......
122122
123123
124124
125
126125
126
127127
128128
129129
......
143143
144144
145145
146
146
147147
148148
149149
......
982982
983983
984984
985
986985
987
988
989986
990987
991
992
993
994
995
996
997
988
989
990
991
992
993
994
995
998996
999997
1000998
long flags;
long time;
struct dirstuff* moduleDir = opendir("/Extra/modules/");
while(readdir(moduleDir, (const char**)&name, &flags, &time) >= 0)
while (readdir(moduleDir, (const char**)&name, &flags, &time) >= 0)
{
if(strcmp(&name[strlen(name) - sizeof("dylib")], ".dylib") == 0)
if (strcmp(&name[strlen(name) - sizeof("dylib")], ".dylib") == 0)
{
char* tmp = malloc(strlen(name) + 1);
strcpy(tmp, name);
if(!load_module(tmp))
if (!load_module(tmp))
{
// failed to load
// free(tmp);
{
DBG("Ignoring %s\n", name);
}
}
closedir(moduleDir);
}
return 1;
}
sprintf(modString, MODULE_PATH "%s", module);
snprintf(modString, sizeof(modString), MODULE_PATH "%s", module);
fh = open(modString, 0);
if(fh < 0)
{
*/
int replace_function(const char* symbol, void* newAddress)
{
UInt32* jumpPointer = malloc(sizeof(UInt32*));
UInt32 addr = lookup_all_symbols(symbol);
char* binary = (char*)addr;
if(addr != 0xFFFFFFFF)
{
//DBG("Replacing %s to point to 0x%x\n", symbol, newAddress);
*binary++ = 0xFF;// Jump
*binary++ = 0x25;// Long Jump
*((UInt32*)binary) = (UInt32)jumpPointer;
*jumpPointer = (UInt32)newAddress;
return 1;
//DBG("Replacing %s to point to 0x%x\n", symbol, newAddress);
UInt32* jumpPointer = malloc(sizeof(UInt32*));
char* binary = (char*)addr;
*binary++ = 0xFF;// Jump
*binary++ = 0x25;// Long Jump
*((UInt32*)binary) = (UInt32)jumpPointer;
*jumpPointer = (UInt32)newAddress;
return 1;
}
return 0;
}

Archive Download the corresponding diff file

Revision: 2312