From 8e1e17606824329539ac90714a5e34bad1ca629a Mon Sep 17 00:00:00 2001 From: nganhkhoa Date: Thu, 18 Jul 2024 16:24:28 +0700 Subject: [PATCH] iterate fixups segment pages was not parse through each page, so it stucks on one page --- macho-go/pkg/ios/macho/dyld_info.go | 6 +++--- macho-go/pkg/ios/macho/fixups.c | 1 + macho-go/pkg/ios/macho/fixups.h | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/macho-go/pkg/ios/macho/dyld_info.go b/macho-go/pkg/ios/macho/dyld_info.go index a616392..d5199d0 100644 --- a/macho-go/pkg/ios/macho/dyld_info.go +++ b/macho-go/pkg/ios/macho/dyld_info.go @@ -127,9 +127,9 @@ func (mc *MachoContext) CollectBindSymbolsModern() []*ImportSymbol { pages := ([]C.ushort)(unsafe.Slice(fix.pages, fix.page_count)) reader := bytes.NewReader(mc.buf) for page_i := 0; page_i < int(fix.page_count); page_i++ { - // fmt.Printf(" page offset=%x\n", pages[page_i]) - - address := int64(fix.segment) + int64(pages[page_i]) + // loop through each page in segment, each page has size fix.page_size + // the first item in page is offset through pages[page_i] + address := int64(fix.segment) + int64(page_i) * int64(fix.page_size) + int64(pages[page_i]) reader.Seek(address, io.SeekStart) code := make([]byte, 8) diff --git a/macho-go/pkg/ios/macho/fixups.c b/macho-go/pkg/ios/macho/fixups.c index dc4ab09..0a577bf 100644 --- a/macho-go/pkg/ios/macho/fixups.c +++ b/macho-go/pkg/ios/macho/fixups.c @@ -54,6 +54,7 @@ int GetSegmentFixAt(uint8_t* buffer, uint32_t i, struct SegmentFix* fix) { fix->format = chain_header->pointer_format; fix->page_count = chain_header->page_count; fix->pages = chain_header->page_start; + fix->page_size = chain_header->page_size; return 0; } diff --git a/macho-go/pkg/ios/macho/fixups.h b/macho-go/pkg/ios/macho/fixups.h index 443a1c1..d0d36f5 100644 --- a/macho-go/pkg/ios/macho/fixups.h +++ b/macho-go/pkg/ios/macho/fixups.h @@ -22,6 +22,7 @@ struct SegmentFix { uint64_t segment; uint32_t format; uint32_t page_count; + uint16_t page_size; uint16_t* pages; };