rework ios-wrapper cli parsing
This commit is contained in:
@ -7,7 +7,7 @@ import (
|
||||
type removeClassicSymbol struct{}
|
||||
|
||||
func (action *removeClassicSymbol) withMacho(mf *MachoFile) error {
|
||||
mf.Context().RemoveClassicSymbol()
|
||||
mf.Context().RemoveSymbolTable()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
21
macho-go/internal/wrapper/action/remove_exports.go
Normal file
21
macho-go/internal/wrapper/action/remove_exports.go
Normal file
@ -0,0 +1,21 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
. "ios-wrapper/internal/wrapper/ofile"
|
||||
)
|
||||
|
||||
type removeExports struct{}
|
||||
|
||||
func (action *removeExports) withMacho(mf *MachoFile) error {
|
||||
mf.Context().RemoveExportTrie()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (action *removeExports) withFat(ff *FatFile) error {
|
||||
return defaultWithFat(action, ff)
|
||||
}
|
||||
|
||||
func NewRemoveExportsAction() *removeExports {
|
||||
return &removeExports{}
|
||||
}
|
||||
|
71
macho-go/internal/wrapper/action/save_imports.go
Normal file
71
macho-go/internal/wrapper/action/save_imports.go
Normal file
@ -0,0 +1,71 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
// log "github.com/sirupsen/logrus"
|
||||
|
||||
. "ios-wrapper/internal/wrapper/ofile"
|
||||
"ios-wrapper/pkg/protomodel"
|
||||
)
|
||||
|
||||
type saveImports struct{}
|
||||
|
||||
func (action *saveImports) withMacho(mf *MachoFile) error {
|
||||
calculateHash := func(name string) uint32 {
|
||||
var h uint32 = 0x811c9dc5
|
||||
for _, s := range name {
|
||||
h ^= uint32(s)
|
||||
h *= 0x01000193
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
mc := mf.Context()
|
||||
symbols := []*protomodel.MachoInfo_BindSymbol{}
|
||||
fmt.Println("struct imported_symbol {const char* name; const char* lib; uint32_t hash; int segment_i; uint64_t offset;};")
|
||||
fmt.Println("const char* lib_to_resolve = \"main\";")
|
||||
fmt.Println("struct imported_symbol imported_table[] = {")
|
||||
for _, symbol := range mc.CollectBindSymbols() {
|
||||
if symbol.Type() != "lazy" {
|
||||
continue
|
||||
}
|
||||
dylib_hash := calculateHash(symbol.Dylib())
|
||||
seg := mc.Segments()[symbol.Segment()]
|
||||
|
||||
var offset uint64
|
||||
|
||||
if symbol.Address() >= seg.Vmaddr() {
|
||||
// this is virtual address
|
||||
offset = symbol.Address() - seg.Vmaddr()
|
||||
} else {
|
||||
// this is file address
|
||||
offset = symbol.Address() - seg.Fileoff()
|
||||
}
|
||||
|
||||
fmt.Printf("{\"%s\", \"%s\", 0x%x, 0x%x, 0x%x},\n",
|
||||
symbol.Name(), symbol.Dylib(), dylib_hash, symbol.Segment(), offset);
|
||||
|
||||
symbols = append(symbols,
|
||||
&protomodel.MachoInfo_BindSymbol{
|
||||
Name: symbol.Name(),
|
||||
Libname: symbol.Dylib(),
|
||||
Libhash: dylib_hash,
|
||||
Segment: symbol.Segment(),
|
||||
Offset: offset,
|
||||
})
|
||||
|
||||
}
|
||||
fmt.Println("};")
|
||||
fmt.Printf("uint32_t nimports = %d;\n", len(symbols));
|
||||
mf.Info().Symbols = symbols
|
||||
return nil
|
||||
}
|
||||
|
||||
func (action *saveImports) withFat(ff *FatFile) error {
|
||||
return defaultWithFat(action, ff)
|
||||
}
|
||||
|
||||
func NewSaveImportsAction() *saveImports {
|
||||
return &saveImports{}
|
||||
}
|
||||
|
Reference in New Issue
Block a user