support for removing LC_DYLD_FIXUPS_CHAINS data
This commit is contained in:
parent
7592cfd2dd
commit
6d757108a7
@ -278,40 +278,6 @@ func (mc *MachoContext) RemoveBindSymbols() {
|
|||||||
} else {
|
} else {
|
||||||
mc.removeBindSymbolsLegacy()
|
mc.removeBindSymbolsLegacy()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (mc *MachoContext) removeBindSymbolsModern() {
|
|
||||||
calculateHash := func(name string) uint32 {
|
|
||||||
var h uint32 = 0x811c9dc5
|
|
||||||
for _, s := range name {
|
|
||||||
h ^= uint32(s)
|
|
||||||
h *= 0x01000193
|
|
||||||
}
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
// due to some limitations when design this tool
|
|
||||||
// we write the c code to stdout lol
|
|
||||||
fmt.Println("struct imported_symbol {const char* name; const char* lib; uint32_t hash; uint64_t address;};")
|
|
||||||
fmt.Println("struct imported_symbol imported_table[] = {")
|
|
||||||
count := 0
|
|
||||||
for _, symbol := range mc.CollectBindSymbols() {
|
|
||||||
count += 1
|
|
||||||
dylib_hash := calculateHash(symbol.Dylib())
|
|
||||||
fmt.Printf("{\"%s\", \"%s\", 0x%x, 0x%x},\n",
|
|
||||||
symbol.Name(), symbol.Dylib(), dylib_hash, symbol.Address());
|
|
||||||
mc.file.WriteAt(make([]byte, 8), int64(symbol.file_address))
|
|
||||||
}
|
|
||||||
fmt.Println("};")
|
|
||||||
fmt.Printf("uint32_t nimports = %d;\n", count);
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mc *MachoContext) removeBindSymbolsLegacy() {
|
|
||||||
start := mc.dyldinfo.lazy_bind_off
|
|
||||||
size := mc.dyldinfo.lazy_bind_size
|
|
||||||
// set lazy opcodes to 0x00 == DO_BIND
|
|
||||||
// but no symbol state to bind
|
|
||||||
mc.file.WriteAt(make([]byte, size), int64(start))
|
|
||||||
|
|
||||||
calculateHash := func(name string) uint32 {
|
calculateHash := func(name string) uint32 {
|
||||||
var h uint32 = 0x811c9dc5
|
var h uint32 = 0x811c9dc5
|
||||||
@ -334,12 +300,32 @@ func (mc *MachoContext) removeBindSymbolsLegacy() {
|
|||||||
count += 1
|
count += 1
|
||||||
dylib_hash := calculateHash(symbol.Dylib())
|
dylib_hash := calculateHash(symbol.Dylib())
|
||||||
seg := mc.segments[symbol.segment]
|
seg := mc.segments[symbol.segment]
|
||||||
offset := symbol.address - seg.Vmaddr()
|
|
||||||
|
var offset uint64
|
||||||
|
|
||||||
|
if symbol.address >= seg.Vmaddr() {
|
||||||
|
// this is virtual address
|
||||||
|
offset = symbol.address - seg.Vmaddr()
|
||||||
|
} else {
|
||||||
|
// this is file address
|
||||||
|
offset = symbol.address - seg.Fileoff()
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf("{\"%s\", \"%s\", 0x%x, 0x%x, 0x%x},\n",
|
fmt.Printf("{\"%s\", \"%s\", 0x%x, 0x%x, 0x%x},\n",
|
||||||
symbol.Name(), symbol.Dylib(), dylib_hash, symbol.segment, offset);
|
symbol.Name(), symbol.Dylib(), dylib_hash, symbol.segment, offset);
|
||||||
mc.file.WriteAt(make([]byte, 8), int64(seg.Fileoff() + offset))
|
mc.file.WriteAt(make([]byte, 8), int64(symbol.file_address))
|
||||||
}
|
}
|
||||||
fmt.Println("};")
|
fmt.Println("};")
|
||||||
fmt.Printf("uint32_t nimports = %d;\n", count);
|
fmt.Printf("uint32_t nimports = %d;\n", count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mc *MachoContext) removeBindSymbolsModern() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mc *MachoContext) removeBindSymbolsLegacy() {
|
||||||
|
start := mc.dyldinfo.lazy_bind_off
|
||||||
|
size := mc.dyldinfo.lazy_bind_size
|
||||||
|
// set lazy opcodes to 0x00 == DO_BIND
|
||||||
|
// but no symbol state to bind
|
||||||
|
mc.file.WriteAt(make([]byte, size), int64(start))
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user