add remove imports command

This commit is contained in:
2023-06-01 17:29:23 +07:00
parent 9d94dd5494
commit b5ee7124ab
7 changed files with 161 additions and 46 deletions

View File

@ -0,0 +1,21 @@
package action
import (
. "ios-wrapper/internal/wrapper/ofile"
)
type removeImports struct{}
func (action *removeImports) withMacho(mf *MachoFile) error {
mf.Context().RemoveBindSymbols()
return nil
}
func (action *removeImports) withFat(ff *FatFile) error {
return defaultWithFat(action, ff)
}
func NewRemoveImportsAction() *removeImports {
return &removeImports{}
}

View File

@ -94,6 +94,12 @@ func Cli() {
pc.remove_codesign = true
pc.outfile = arg.Out
case "remove-imports":
arg := cli.RemoveImports
ofile = NewOFile(arg.OFile)
pc.remove_imports = true
pc.outfile = arg.Out
default:
return
}

View File

@ -24,6 +24,11 @@ type RemoveCodesignArgument struct {
OFile string `arg help:"Path to Mach-O/Fat binary file" type:"existingfile"`
}
type RemoveImportsArgument struct {
Out string `short:"o" required name:"outfile" help:"Modified Mach-O/Fat binary output file" type:"path"`
OFile string `arg help:"Path to Mach-O/Fat binary file" type:"existingfile"`
}
type SignedBcellArgument struct {
Out string `short:"o" required name:"outfile" help:"bcell.dat.signed output file" type:"existingfile"`
Bcell string `arg short:"b" required help:"bcell.dat input file" type:"existingfile"`
@ -57,6 +62,7 @@ type Argument struct {
Wrap WrapArgument `cmd help:"Modifies Mach-O/Fat binary"`
Vltk VltkArgument `cmd help:"Modifies Mach-O/Fat binary"`
Info InfoArgument `cmd help:"Show Mach-O/Fat binary information"`
RemoveImports RemoveImportsArgument `cmd aliases:"remove-imports" name:"remove-imports" help:"Remove imports"`
RemoveCodesign RemoveCodesignArgument `cmd aliases:"remove-signature" name:"remove-codesign" help:"Remove LC_CODE_SIGNATURE from Mach-O/Fat binary"`
SignedBcell SignedBcellArgument `cmd name:"signed-bcell" help:"Change Protobuf<BcellFile> into Protobuf<SignedData>"`
DisplayBcell DisplayBcellArgument `cmd name:"display-bcell" help:"Display Protobuf<BcellFile> content"`

View File

@ -34,21 +34,17 @@ func (printer *InfoPrinter) Print() {
fmt.Printf("Init functions at offset %s\n", &fun)
}
symbols := mc.CollectLazyBindSymbols()
if len(symbols) > 0 {
fmt.Println("Lazy Symbols")
for _, sym := range symbols {
fmt.Printf(
"%s\n\tStub=0x%x Address=0x%x\n\tDylib=%s\n",
sym.Name(),
sym.Stub(),
sym.Address(),
sym.Dylib(),
)
}
} else {
fmt.Println("No lazy symbols")
}
symbols := mc.CollectBindSymbols()
for _, sym := range symbols {
fmt.Printf(
"%s (%s)\n\tStub=0x%x Address=0x%x\n\tDylib=%s\n",
sym.Name(),
sym.Type(),
sym.Stub(),
sym.Address(),
sym.Dylib(),
)
}
fmt.Println("======")
}

View File

@ -40,6 +40,7 @@ func (uc *UserConfig) Protomodel() *protomodel.Config {
type ProgramContext struct {
strip_init_pointers bool
remove_codesign bool
remove_imports bool
dylib_to_add []string
rpath_to_add []string
@ -83,6 +84,12 @@ func (pc *ProgramContext) dispatchActions(ofile OFile) {
}
func (pc *ProgramContext) Process(ofile OFile) {
if pc.remove_imports {
pc.AddAction(NewRemoveImportsAction())
pc.AddAction(NewWriteFileAction(pc.outfile))
pc.dispatchActions(ofile)
return
}
if pc.remove_codesign {
pc.AddAction(NewRemoveCodeSignatureAction())
}