iterate fixups segment pages

was not parse through each page, so it stucks on one page
This commit is contained in:
nganhkhoa 2024-07-18 16:24:28 +07:00
parent 06525b8a5e
commit 8e1e176068
3 changed files with 5 additions and 3 deletions

View File

@ -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)

View File

@ -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;
}

View File

@ -22,6 +22,7 @@ struct SegmentFix {
uint64_t segment;
uint32_t format;
uint32_t page_count;
uint16_t page_size;
uint16_t* pages;
};