126 lines
3.1 KiB
Go
126 lines
3.1 KiB
Go
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 {
|
|
remove_inits bool
|
|
remove_codesign bool
|
|
remove_imports bool
|
|
remove_others bool
|
|
remove_exports bool
|
|
remove_symbol_table bool
|
|
dylib_to_add []string
|
|
rpath_to_add []string
|
|
symbols_keep []string
|
|
|
|
outfile string
|
|
|
|
actions []Action
|
|
err error
|
|
|
|
user_config UserConfig
|
|
bcellfile string
|
|
signed bool // true: Protobuf<SignedData>; false: Protobuf<BcellFile>
|
|
}
|
|
|
|
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.remove_inits {
|
|
pc.AddAction(NewSaveInitPointerAction())
|
|
pc.AddAction(NewRemoveInitPointerAction())
|
|
}
|
|
if pc.remove_imports {
|
|
pc.AddAction(NewSaveImportsAction(pc.symbols_keep))
|
|
pc.AddAction(NewRemoveImportsAction())
|
|
pc.AddAction(NewRewriteImportsWithKeepSymbolsAction(pc.symbols_keep))
|
|
}
|
|
if pc.remove_symbol_table {
|
|
pc.AddAction(NewRemoveClassicSymbolAction())
|
|
}
|
|
if pc.remove_exports {
|
|
pc.AddAction(NewRemoveExportsAction())
|
|
}
|
|
ExperimentalFeature("Remove Unnecessary Info", func() {
|
|
if pc.remove_others {
|
|
pc.AddAction(NewRemoveUnnecessaryInfoAction())
|
|
}
|
|
})
|
|
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)
|
|
}
|