package wrapper import ( "encoding/json" "io/ioutil" log "github.com/sirupsen/logrus" . "ios-wrapper/internal/wrapper/action" . "ios-wrapper/internal/wrapper/ofile" "ios-wrapper/pkg/protomodel" ) type UserConfig struct { Repack bool `json:"repack"` Hook bool `json:"hook"` Emulator bool `json:"emulator"` Debug bool `json:"debug"` Root bool `json:"root"` ServerURL string `json:"server_url"` ReportType int32 `json:"report_type"` RemoteConfigURL string `json:"remote_config_url"` DomainID string `json:"domain_id"` } func (uc *UserConfig) Protomodel() *protomodel.Config { return &protomodel.Config{ Hook: uc.Hook, Repack: uc.Repack, Emulator: uc.Emulator, Debug: uc.Debug, Root: uc.Root, ServerUrl: uc.ServerURL, ReportType: uc.ReportType, RemoteConfigUrl: uc.RemoteConfigURL, DomainId: uc.DomainID, } } type ProgramContext struct { strip_init_pointers bool remove_codesign bool dylib_to_add []string rpath_to_add []string outfile string actions []Action err error user_config UserConfig bcellfile string signed bool // true: Protobuf; false: Protobuf } func (pc *ProgramContext) ExplainError(err error) { log.WithFields(log.Fields{ "pc error": pc.err, "ofile error": err, }).Error("OFile Process gone wrong") } func (pc *ProgramContext) ReadUserConfig(f string) { json_data, err := ioutil.ReadFile(f) if err != nil { log.Panic("User Config file is invalid") } json.Unmarshal(json_data, &pc.user_config) } func (pc *ProgramContext) AddAction(action Action) { pc.actions = append(pc.actions, action) } func (pc *ProgramContext) dispatchActions(ofile OFile) { for _, action := range pc.actions { err := RunAction(action, ofile) if err != nil { pc.err = err break } } } func (pc *ProgramContext) Process(ofile OFile) { if pc.remove_codesign { pc.AddAction(NewRemoveCodeSignatureAction()) } if pc.strip_init_pointers { pc.AddAction(NewSaveInitPointerAction()) pc.AddAction(NewRemoveInitPointerAction()) } ExperimentalFeature("Remove Unnecessary Info", func() { pc.AddAction(NewRemoveUnnecessaryInfoAction()) }) ExperimentalFeature("Remove Classic Symbol", func() { pc.AddAction(NewRemoveClassicSymbolAction()) }) pc.AddAction(NewAddRpathAction(pc.rpath_to_add)) pc.AddAction(NewAddDylibAction(pc.dylib_to_add)) if pc.bcellfile != "" { pc.AddAction(NewSaveBcellFileAction(pc.user_config.Protomodel(), pc.bcellfile, pc.signed)) } else { log.Warn("bcellfile is not set, no output bcellfile") } pc.AddAction(NewWriteFileAction(pc.outfile)) pc.dispatchActions(ofile) }