add keep imports action
This commit is contained in:
26
macho-go/internal/wrapper/action/rewrite_imports.go
Normal file
26
macho-go/internal/wrapper/action/rewrite_imports.go
Normal file
@ -0,0 +1,26 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
. "ios-wrapper/internal/wrapper/ofile"
|
||||
)
|
||||
|
||||
type rewriteImports struct{
|
||||
symbols []string
|
||||
}
|
||||
|
||||
func (action *rewriteImports) withMacho(mf *MachoFile) error {
|
||||
mc := mf.Context()
|
||||
mc.RewriteImportsTable(action.symbols)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (action *rewriteImports) withFat(ff *FatFile) error {
|
||||
return defaultWithFat(action, ff)
|
||||
}
|
||||
|
||||
func NewRewriteImportsWithKeepSymbolsAction(symbols []string) *rewriteImports {
|
||||
return &rewriteImports{
|
||||
symbols,
|
||||
}
|
||||
}
|
||||
|
@ -3,13 +3,16 @@ package action
|
||||
import (
|
||||
// "fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
// log "github.com/sirupsen/logrus"
|
||||
|
||||
. "ios-wrapper/internal/wrapper/ofile"
|
||||
"ios-wrapper/pkg/protomodel"
|
||||
)
|
||||
|
||||
type saveImports struct{}
|
||||
type saveImports struct{
|
||||
keepSymbols []string
|
||||
}
|
||||
|
||||
func (action *saveImports) withMacho(mf *MachoFile) error {
|
||||
// calculateHash := func(name string) uint32 {
|
||||
@ -51,6 +54,30 @@ func (action *saveImports) withMacho(mf *MachoFile) error {
|
||||
if symbol.Type() != "lazy" {
|
||||
continue
|
||||
}
|
||||
|
||||
skip := false
|
||||
for _, keep := range action.keepSymbols {
|
||||
name := keep
|
||||
lib := ""
|
||||
parts := strings.Split(keep, ",")
|
||||
if len(parts) == 2 {
|
||||
name = parts[0]
|
||||
lib = parts[1]
|
||||
}
|
||||
|
||||
if symbol.Name() != name {
|
||||
continue
|
||||
}
|
||||
if lib == "" || lib == symbol.Dylib() {
|
||||
skip = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if skip {
|
||||
continue
|
||||
}
|
||||
|
||||
// dylib_hash := calculateHash(symbol.Dylib())
|
||||
seg := mc.Segments()[symbol.Segment()]
|
||||
|
||||
@ -113,6 +140,8 @@ func (action *saveImports) withFat(ff *FatFile) error {
|
||||
return defaultWithFat(action, ff)
|
||||
}
|
||||
|
||||
func NewSaveImportsAction() *saveImports {
|
||||
return &saveImports{}
|
||||
func NewSaveImportsAction(keepSymbols []string) *saveImports {
|
||||
return &saveImports{
|
||||
keepSymbols,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user