small changes to remove imports action
This commit is contained in:
parent
eccd0bf845
commit
557eed0254
@ -8,8 +8,6 @@ type removeImports struct{}
|
||||
|
||||
func (action *removeImports) withMacho(mf *MachoFile) error {
|
||||
mf.Context().RemoveBindSymbols()
|
||||
mf.Context().RemoveSymbolTable()
|
||||
mf.Context().RemoveExportTrie()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@ type ImportSymbol struct {
|
||||
segment_offset uint32
|
||||
address uint64
|
||||
file_address uint64
|
||||
lib_ordinal uint32
|
||||
|
||||
// push number
|
||||
pnum uint32
|
||||
@ -45,6 +46,10 @@ func (sym *ImportSymbol) Dylib() string {
|
||||
return sym.dylib
|
||||
}
|
||||
|
||||
func (sym *ImportSymbol) LibOrdinal() uint32 {
|
||||
return sym.lib_ordinal
|
||||
}
|
||||
|
||||
func (sym *ImportSymbol) Address() uint64 {
|
||||
return sym.address
|
||||
}
|
||||
@ -116,16 +121,17 @@ func (mc *MachoContext) CollectBindSymbolsModern() []*ImportSymbol {
|
||||
// fmt.Printf("segment=%x format=%x page_count=%d\n", fix.segment, fix.format, fix.page_count)
|
||||
// fmt.Printf("pages=%x\n", fix.pages)
|
||||
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])
|
||||
mc.file.Seek(address, io.SeekStart)
|
||||
reader.Seek(address, io.SeekStart)
|
||||
|
||||
code := make([]byte, 8)
|
||||
|
||||
for {
|
||||
mc.file.Read(code)
|
||||
reader.Read(code)
|
||||
v := mc.byteorder.Uint64(code)
|
||||
|
||||
var bind C.int
|
||||
@ -145,6 +151,7 @@ func (mc *MachoContext) CollectBindSymbolsModern() []*ImportSymbol {
|
||||
sym.name = name
|
||||
sym.dylib = dylib
|
||||
sym.typ = "lazy"
|
||||
sym.lib_ordinal = uint32(s.lib_ordinal)
|
||||
|
||||
sym.segment = uint32(mc.findSegmentIndexAt(uint64(address)))
|
||||
sym.file_address = uint64(address)
|
||||
@ -160,9 +167,9 @@ func (mc *MachoContext) CollectBindSymbolsModern() []*ImportSymbol {
|
||||
}
|
||||
// because the pointer move up 8 bytes already so we minus 8
|
||||
address += int64(next * 4)
|
||||
mc.file.Seek(int64(next*4)-8, io.SeekCurrent)
|
||||
reader.Seek(int64(next*4)-8, io.SeekCurrent)
|
||||
}
|
||||
mc.file.Seek(0, io.SeekStart)
|
||||
reader.Seek(0, io.SeekStart)
|
||||
}
|
||||
}
|
||||
return syms
|
||||
|
@ -282,7 +282,10 @@ func (mc *MachoContext) RemoveBindSymbols() {
|
||||
} else {
|
||||
mc.removeBindSymbolsLegacy()
|
||||
}
|
||||
mc.ReworkForObjc()
|
||||
// Objective-C stub replaces main which can only appears in executable
|
||||
if mc.Header().IsExecutable() {
|
||||
mc.ReworkForObjc()
|
||||
}
|
||||
|
||||
// due to some limitations when design this tool
|
||||
// we write the c code to stdout lol
|
||||
|
Loading…
Reference in New Issue
Block a user