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 {
|
func (action *removeImports) withMacho(mf *MachoFile) error {
|
||||||
mf.Context().RemoveBindSymbols()
|
mf.Context().RemoveBindSymbols()
|
||||||
mf.Context().RemoveSymbolTable()
|
|
||||||
mf.Context().RemoveExportTrie()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ type ImportSymbol struct {
|
|||||||
segment_offset uint32
|
segment_offset uint32
|
||||||
address uint64
|
address uint64
|
||||||
file_address uint64
|
file_address uint64
|
||||||
|
lib_ordinal uint32
|
||||||
|
|
||||||
// push number
|
// push number
|
||||||
pnum uint32
|
pnum uint32
|
||||||
@ -45,6 +46,10 @@ func (sym *ImportSymbol) Dylib() string {
|
|||||||
return sym.dylib
|
return sym.dylib
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sym *ImportSymbol) LibOrdinal() uint32 {
|
||||||
|
return sym.lib_ordinal
|
||||||
|
}
|
||||||
|
|
||||||
func (sym *ImportSymbol) Address() uint64 {
|
func (sym *ImportSymbol) Address() uint64 {
|
||||||
return sym.address
|
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("segment=%x format=%x page_count=%d\n", fix.segment, fix.format, fix.page_count)
|
||||||
// fmt.Printf("pages=%x\n", fix.pages)
|
// fmt.Printf("pages=%x\n", fix.pages)
|
||||||
pages := ([]C.ushort)(unsafe.Slice(fix.pages, fix.page_count))
|
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++ {
|
for page_i := 0; page_i < int(fix.page_count); page_i++ {
|
||||||
// fmt.Printf(" page offset=%x\n", pages[page_i])
|
// fmt.Printf(" page offset=%x\n", pages[page_i])
|
||||||
|
|
||||||
address := int64(fix.segment) + int64(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)
|
code := make([]byte, 8)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
mc.file.Read(code)
|
reader.Read(code)
|
||||||
v := mc.byteorder.Uint64(code)
|
v := mc.byteorder.Uint64(code)
|
||||||
|
|
||||||
var bind C.int
|
var bind C.int
|
||||||
@ -145,6 +151,7 @@ func (mc *MachoContext) CollectBindSymbolsModern() []*ImportSymbol {
|
|||||||
sym.name = name
|
sym.name = name
|
||||||
sym.dylib = dylib
|
sym.dylib = dylib
|
||||||
sym.typ = "lazy"
|
sym.typ = "lazy"
|
||||||
|
sym.lib_ordinal = uint32(s.lib_ordinal)
|
||||||
|
|
||||||
sym.segment = uint32(mc.findSegmentIndexAt(uint64(address)))
|
sym.segment = uint32(mc.findSegmentIndexAt(uint64(address)))
|
||||||
sym.file_address = 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
|
// because the pointer move up 8 bytes already so we minus 8
|
||||||
address += int64(next * 4)
|
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
|
return syms
|
||||||
|
@ -282,7 +282,10 @@ func (mc *MachoContext) RemoveBindSymbols() {
|
|||||||
} else {
|
} else {
|
||||||
mc.removeBindSymbolsLegacy()
|
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
|
// due to some limitations when design this tool
|
||||||
// we write the c code to stdout lol
|
// we write the c code to stdout lol
|
||||||
|
Loading…
Reference in New Issue
Block a user