From 9cdf9f0ff50f768af42bd71e0a3e93deee05378f Mon Sep 17 00:00:00 2001 From: nganhkhoa Date: Mon, 26 Aug 2024 16:08:10 +0700 Subject: [PATCH] overwrite old cstring data with random --- macho-go/pkg/ios/macho/edit.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/macho-go/pkg/ios/macho/edit.go b/macho-go/pkg/ios/macho/edit.go index 4508626..e2de0da 100644 --- a/macho-go/pkg/ios/macho/edit.go +++ b/macho-go/pkg/ios/macho/edit.go @@ -769,11 +769,17 @@ func (mc *MachoContext) RemoveStrings() { mc.file.WriteAt(old_linkedit, int64(edit_segment.Fileoff())) // prepare dummy bytes into new string segment, 0 for now + // this is a way to divert their effort, writing fake strings + // will be written again at runtime dummy := make([]byte, edit_segment.Fileoff() - string_segment.Fileoff()) copy(dummy, []byte("We R BShield\n")) mc.file.WriteAt(dummy, int64(string_segment.Fileoff())) // TODO: erase old strings + cstring_start := uint64(cstring.Offset()) + random := make([]byte, cstring.Size()) + rand.Read(random) + mc.file.WriteAt(random, int64(cstring_start)) // re-read internal buffer last, _ := mc.file.Seek(0, io.SeekEnd) @@ -870,7 +876,7 @@ func (mc *MachoContext) RemoveStrings() { value := C.MakeRebaseFixupOpcode(C.int(symbol.next), C.ulonglong(target), C.ulonglong(high8)) v := make([]byte, 8) mc.byteorder.PutUint64(v, uint64(value)) - fmt.Printf("change to rebase at %x\n", symbol.file_address) + fmt.Printf("string rebase change at %x\n", symbol.file_address) mc.file.WriteAt(v, int64(symbol.file_address)) } }