From 0640d38627e49f314f91ce1ba12a39c71ab31b0c Mon Sep 17 00:00:00 2001 From: nganhkhoa Date: Mon, 26 Aug 2024 16:00:17 +0700 Subject: [PATCH] re-read internal buffer after moving file's contents --- macho-go/pkg/ios/macho/edit.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/macho-go/pkg/ios/macho/edit.go b/macho-go/pkg/ios/macho/edit.go index 748c15e..8cdce51 100644 --- a/macho-go/pkg/ios/macho/edit.go +++ b/macho-go/pkg/ios/macho/edit.go @@ -774,6 +774,16 @@ func (mc *MachoContext) RemoveStrings() { copy(dummy, []byte("We R BShield\n")) mc.file.WriteAt(dummy, int64(string_segment.Fileoff())) + // TODO: erase old strings + + // re-read internal buffer + last, _ := mc.file.Seek(0, io.SeekEnd) + mc.buf = make([]byte, last) + mc.file.Seek(0, io.SeekStart) + if _, err := io.ReadFull(mc.file, mc.buf); err != nil { + // panic? + } + // loop over __TEXT,__text and find all occurances of (adrp, add) // edit the offset to points to new region // because adrp sets the register to the address page at its address