#endif␊ |
␊ |
// NOTE: Global so that modules can link with this␊ |
unsigned long long textAddress = 0;␊ |
unsigned long long textSection = 0;␊ |
UInt64 textAddress = 0;␊ |
UInt64 textSection = 0;␊ |
␊ |
void* symbols_module_start = (void*)0xFFFFFFFF;␉// Global, value is populated by the makefile with actual address␊ |
␊ |
|
␉}␊ |
␉␊ |
#if CONFIG_MODULE_DEBUG␊ |
␉verbose("Unable to locate symbol %s\n", name);␊ |
␉printf("Unable to locate symbol %s\n", name);␊ |
␉getchar();␊ |
#endif␊ |
␉␊ |
|
␉␉// Rebase the module before binding it.␊ |
␉␉if(dyldInfoCommand->rebase_off)␉␉rebase_macho(binary, (char*)dyldInfoCommand->rebase_off,␉dyldInfoCommand->rebase_size);␊ |
␉␉// Bind all symbols. ␊ |
␉␉if(dyldInfoCommand->bind_off)␉␉bind_macho(binary, (char*)dyldInfoCommand->bind_off,␉␉dyldInfoCommand->bind_size);␊ |
␉␉if(dyldInfoCommand->weak_bind_off)␉bind_macho(binary, (char*)dyldInfoCommand->weak_bind_off,␉dyldInfoCommand->weak_bind_size);␊ |
␉␉if(dyldInfoCommand->lazy_bind_off)␉bind_macho(binary, (char*)dyldInfoCommand->lazy_bind_off,␉dyldInfoCommand->lazy_bind_size);␊ |
␉␉if(dyldInfoCommand->bind_off)␉␉bind_macho(binary, (UInt8*)dyldInfoCommand->bind_off,␉␉dyldInfoCommand->bind_size);␊ |
␉␉if(dyldInfoCommand->weak_bind_off)␉bind_macho(binary, (UInt8*)dyldInfoCommand->weak_bind_off,␉dyldInfoCommand->weak_bind_size);␊ |
␉␉if(dyldInfoCommand->lazy_bind_off)␉bind_macho(binary, (UInt8*)dyldInfoCommand->lazy_bind_off,␉dyldInfoCommand->lazy_bind_size);␊ |
␉}␊ |
␉␊ |
␉return module_start;␊ |
|
}␊ |
␊ |
␊ |
UInt32 read_uleb(UInt8* bind_stream, unsigned int* i)␊ |
{␊ |
// Read in offset␊ |
UInt32 tmp = 0;␊ |
UInt8 bits = 0;␊ |
do␊ |
{␊ |
if(bits < sizeof(UInt32)*8) // hack␊ |
{␊ |
tmp |= (bind_stream[++(*i)] & 0x7f) << bits;␊ |
bits += 7;␊ |
}␊ |
else␊ |
{␊ |
++(*i);␊ |
}␊ |
}␊ |
while(bind_stream[*i] & 0x80);␊ |
return tmp;␊ |
}␊ |
␊ |
␊ |
// Based on code from dylibinfo.cpp and ImageLoaderMachOCompressed.cpp␊ |
// NOTE: this uses 32bit values, and not 64bit values. ␊ |
// There is a possibility that this could cause issues,␊ |
// however the modules are 32 bits, so it shouldn't matter too much␊ |
void bind_macho(void* base, char* bind_stream, UInt32 size)␊ |
void bind_macho(void* base, UInt8* bind_stream, UInt32 size)␊ |
{␉␊ |
␉bind_stream += (UInt32)base;␊ |
␉␊ |
|
␉UInt32 symbolAddr = 0xFFFFFFFF;␊ |
␉␊ |
␉// Temperary variables␊ |
␉UInt8 bits = 0;␊ |
␉UInt32 tmp = 0;␊ |
␉UInt32 tmp2 = 0;␊ |
␉UInt32 index = 0;␊ |
|
␉␉␉␉break;␊ |
␉␉␉␉␊ |
␉␉␉case BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB:␊ |
␉␉␉␉libraryOrdinal = 0;␊ |
␉␉␉␉bits = 0;␊ |
␉␉␉␉do␊ |
␉␉␉␉{␊ |
␉␉␉␉␉libraryOrdinal |= (bind_stream[++i] & 0x7f) << bits;␊ |
␉␉␉␉␉bits += 7;␊ |
␉␉␉␉}␊ |
␉␉␉␉while(bind_stream[i] & 0x80);␊ |
␉␉␉␉libraryOrdinal = read_uleb(bind_stream, &i);␊ |
␉␉␉␉break;␊ |
␉␉␉␉␊ |
␉␉␉case BIND_OPCODE_SET_DYLIB_SPECIAL_IMM:␊ |
|
␉␉␉␉break;␊ |
␉␉␉␉␊ |
␉␉␉case BIND_OPCODE_SET_ADDEND_SLEB:␊ |
␉␉␉␉addend = 0;␊ |
␉␉␉␉bits = 0;␊ |
␉␉␉␉do␊ |
␉␉␉␉{␊ |
␉␉␉␉␉addend |= (bind_stream[++i] & 0x7f) << bits;␊ |
␉␉␉␉␉bits += 7;␊ |
␉␉␉␉}␊ |
␉␉␉␉while(bind_stream[i] & 0x80);␊ |
␉␉␉␉␊ |
␉␉␉␉addend = read_uleb(bind_stream, &i);␉␉␉␉␊ |
␉␉␉␉if(!(bind_stream[i-1] & 0x40)) addend *= -1;␊ |
␉␉␉␉break;␊ |
␉␉␉␉␊ |
|
␉␉␉␉while(index <= immediate);␊ |
␉␉␉␉␊ |
␉␉␉␉segmentAddress = segCommand->fileoff;␊ |
␉␉␉␉␊ |
␉␉␉␉// Read in offset␊ |
␉␉␉␉tmp = 0;␊ |
␉␉␉␉bits = 0;␊ |
␉␉␉␉do␊ |
␉␉␉␉{␊ |
␉␉␉␉␉tmp |= (bind_stream[++i] & 0x7f) << bits;␊ |
␉␉␉␉␉bits += 7;␊ |
␉␉␉␉}␊ |
␉␉␉␉while(bind_stream[i] & 0x80);␊ |
␉␉␉␉␊ |
␉␉␉␉segmentAddress += tmp;␊ |
␉␉␉␉␉␉␉␉␊ |
␉␉␉␉segmentAddress += read_uleb(bind_stream, &i);␊ |
␉␉␉␉break;␊ |
␉␉␉␉␊ |
␉␉␉case BIND_OPCODE_ADD_ADDR_ULEB:␊ |
␉␉␉␉// Read in offset␊ |
␉␉␉␉tmp = 0;␊ |
␉␉␉␉bits = 0;␊ |
␉␉␉␉do␊ |
␉␉␉␉{␊ |
␉␉␉␉␉tmp |= (bind_stream[++i] & 0x7f) << bits;␊ |
␉␉␉␉␉bits += 7;␊ |
␉␉␉␉}␊ |
␉␉␉␉while(bind_stream[i] & 0x80);␊ |
␉␉␉␉␊ |
␉␉␉␉segmentAddress += tmp;␊ |
␉␉␉␉segmentAddress += read_uleb(bind_stream, &i);␊ |
␉␉␉␉break;␊ |
␉␉␉␉␊ |
␉␉␉case BIND_OPCODE_DO_BIND:␊ |
|
␉␉␉␉␊ |
␉␉␉case BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB:␊ |
␉␉␉␉// Read in offset␊ |
␉␉␉␉tmp = 0;␊ |
␉␉␉␉bits = 0;␊ |
␉␉␉␉do␊ |
␉␉␉␉{␊ |
␉␉␉␉␉tmp |= (bind_stream[++i] & 0x7f) << bits;␊ |
␉␉␉␉␉bits += 7;␊ |
␉␉␉␉}␊ |
␉␉␉␉while(bind_stream[i] & 0x80);␊ |
␉␉␉␉tmp = read_uleb(bind_stream, &i);␊ |
␊ |
␉␉␉␉if(symbolAddr != 0xFFFFFFFF)␊ |
␉␉␉␉{␊ |
|
␉␉␉␉break;␊ |
␉␉␉␉␊ |
␉␉␉case BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB:␊ |
␉␉␉␉tmp = 0;␊ |
␉␉␉␉bits = 0;␊ |
␉␉␉␉do␊ |
␉␉␉␉{␊ |
␉␉␉␉␉tmp |= (bind_stream[++i] & 0x7f) << bits;␊ |
␉␉␉␉␉bits += 7;␊ |
␉␉␉␉}␊ |
␉␉␉␉while(bind_stream[i] & 0x80);␊ |
␉␉␉␉tmp = read_uleb(bind_stream, &i);␉␉␉␉␊ |
␉␉␉␉␊ |
␉␉␉␉tmp2 = read_uleb(bind_stream, &i);␉␉␉␉␊ |
␉␉␉␉␊ |
␉␉␉␉tmp2 = 0;␊ |
␉␉␉␉bits = 0;␊ |
␉␉␉␉do␊ |
␉␉␉␉{␊ |
␉␉␉␉␉tmp2 |= (bind_stream[++i] & 0x7f) << bits;␊ |
␉␉␉␉␉bits += 7;␊ |
␉␉␉␉}␊ |
␉␉␉␉while(bind_stream[i] & 0x80);␊ |
␉␉␉␉␊ |
␉␉␉␉␊ |
␉␉␉␉if(symbolAddr != 0xFFFFFFFF)␊ |
␉␉␉␉{␊ |
␉␉␉␉␉for(index = 0; index < tmp; index++)␊ |
|
␉␉i++;␊ |
␉}␊ |
}␊ |
␊ |
␊ |
inline void bind_location(UInt32* location, char* value, UInt32 addend, int type)␊ |
{␉␊ |
|
␉␉hooks = hooks->next;␊ |
␉}␊ |
}␊ |
␊ |
#endif␊ |
␊ |
/********************************************************************************/␊ |
/*␉dyld / Linker Interface␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
/*␉dyld / Linker Interface␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
/********************************************************************************/␊ |
␊ |
void dyld_stub_binder()␊ |