add old go tooling
This commit is contained in:
33
macho-go/internal/wrapper/action/action.go
Normal file
33
macho-go/internal/wrapper/action/action.go
Normal file
@ -0,0 +1,33 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
. "ios-wrapper/internal/wrapper/ofile"
|
||||
)
|
||||
|
||||
// Actions on MachoFile
|
||||
type Action interface {
|
||||
withMacho(mf *MachoFile) error
|
||||
withFat(ff *FatFile) error
|
||||
// TODO: error context
|
||||
}
|
||||
|
||||
func RunAction(action Action, ofile OFile) error {
|
||||
switch ofile.(type) {
|
||||
case *MachoFile:
|
||||
return action.withMacho(ofile.(*MachoFile))
|
||||
case *FatFile:
|
||||
return action.withFat(ofile.(*FatFile))
|
||||
}
|
||||
// not likely
|
||||
return nil
|
||||
}
|
||||
|
||||
func defaultWithFat(action Action, ff *FatFile) error {
|
||||
for _, macho := range ff.Machos() {
|
||||
err := action.withMacho(macho)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
31
macho-go/internal/wrapper/action/add_dylib.go
Normal file
31
macho-go/internal/wrapper/action/add_dylib.go
Normal file
@ -0,0 +1,31 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
. "ios-wrapper/internal/wrapper/ofile"
|
||||
)
|
||||
|
||||
type addDylib struct {
|
||||
dylib_to_add []string
|
||||
}
|
||||
|
||||
func (action *addDylib) withMacho(mf *MachoFile) error {
|
||||
for _, dylib := range action.dylib_to_add {
|
||||
mf.Context().AddDylib(dylib)
|
||||
log.WithFields(log.Fields{
|
||||
"dylib": dylib,
|
||||
}).Info("Add Load Dylib Command")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (action *addDylib) withFat(ff *FatFile) error {
|
||||
return defaultWithFat(action, ff)
|
||||
}
|
||||
|
||||
func NewAddDylibAction(dylib_to_add []string) *addDylib {
|
||||
return &addDylib{
|
||||
dylib_to_add,
|
||||
}
|
||||
}
|
31
macho-go/internal/wrapper/action/add_rpath.go
Normal file
31
macho-go/internal/wrapper/action/add_rpath.go
Normal file
@ -0,0 +1,31 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
. "ios-wrapper/internal/wrapper/ofile"
|
||||
)
|
||||
|
||||
type addRpath struct {
|
||||
rpath []string
|
||||
}
|
||||
|
||||
func (action *addRpath) withMacho(mf *MachoFile) error {
|
||||
for _, rpath := range action.rpath {
|
||||
mf.Context().AddRPath(rpath)
|
||||
log.WithFields(log.Fields{
|
||||
"rpath": rpath,
|
||||
}).Info("Add Rpath Command")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (action *addRpath) withFat(ff *FatFile) error {
|
||||
return defaultWithFat(action, ff)
|
||||
}
|
||||
|
||||
func NewAddRpathAction(rpath []string) *addRpath {
|
||||
return &addRpath{
|
||||
rpath,
|
||||
}
|
||||
}
|
20
macho-go/internal/wrapper/action/remove_classic_symbols.go
Normal file
20
macho-go/internal/wrapper/action/remove_classic_symbols.go
Normal file
@ -0,0 +1,20 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
. "ios-wrapper/internal/wrapper/ofile"
|
||||
)
|
||||
|
||||
type removeClassicSymbol struct{}
|
||||
|
||||
func (action *removeClassicSymbol) withMacho(mf *MachoFile) error {
|
||||
mf.Context().RemoveClassicSymbol()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (action *removeClassicSymbol) withFat(ff *FatFile) error {
|
||||
return defaultWithFat(action, ff)
|
||||
}
|
||||
|
||||
func NewRemoveClassicSymbolAction() *removeClassicSymbol {
|
||||
return &removeClassicSymbol{}
|
||||
}
|
20
macho-go/internal/wrapper/action/remove_code.go
Normal file
20
macho-go/internal/wrapper/action/remove_code.go
Normal file
@ -0,0 +1,20 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
. "ios-wrapper/internal/wrapper/ofile"
|
||||
)
|
||||
|
||||
type removeCodeSignature struct{}
|
||||
|
||||
func (action *removeCodeSignature) withMacho(mf *MachoFile) error {
|
||||
mf.Context().RemoveCodesign()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (action *removeCodeSignature) withFat(ff *FatFile) error {
|
||||
return defaultWithFat(action, ff)
|
||||
}
|
||||
|
||||
func NewRemoveCodeSignatureAction() *removeCodeSignature {
|
||||
return &removeCodeSignature{}
|
||||
}
|
20
macho-go/internal/wrapper/action/remove_init_pointer.go
Normal file
20
macho-go/internal/wrapper/action/remove_init_pointer.go
Normal file
@ -0,0 +1,20 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
. "ios-wrapper/internal/wrapper/ofile"
|
||||
)
|
||||
|
||||
type removeInitPointer struct{}
|
||||
|
||||
func (action *removeInitPointer) withMacho(mf *MachoFile) error {
|
||||
mf.Context().RemoveInitFunctions()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (action *removeInitPointer) withFat(ff *FatFile) error {
|
||||
return defaultWithFat(action, ff)
|
||||
}
|
||||
|
||||
func NewRemoveInitPointerAction() *removeInitPointer {
|
||||
return &removeInitPointer{}
|
||||
}
|
20
macho-go/internal/wrapper/action/remove_unncessary_info.go
Normal file
20
macho-go/internal/wrapper/action/remove_unncessary_info.go
Normal file
@ -0,0 +1,20 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
. "ios-wrapper/internal/wrapper/ofile"
|
||||
)
|
||||
|
||||
type removeUnnecessaryInfo struct{}
|
||||
|
||||
func (action *removeUnnecessaryInfo) withMacho(mf *MachoFile) error {
|
||||
mf.Context().RemoveUnnecessaryInfo()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (action *removeUnnecessaryInfo) withFat(ff *FatFile) error {
|
||||
return defaultWithFat(action, ff)
|
||||
}
|
||||
|
||||
func NewRemoveUnnecessaryInfoAction() *removeUnnecessaryInfo {
|
||||
return &removeUnnecessaryInfo{}
|
||||
}
|
68
macho-go/internal/wrapper/action/save_bcell_file.go
Normal file
68
macho-go/internal/wrapper/action/save_bcell_file.go
Normal file
@ -0,0 +1,68 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
. "ios-wrapper/internal/wrapper/ofile"
|
||||
"ios-wrapper/pkg/protomodel"
|
||||
)
|
||||
|
||||
type saveBcellFile struct {
|
||||
bcellfile string
|
||||
content *protomodel.BcellFile
|
||||
signed bool
|
||||
}
|
||||
|
||||
func (action *saveBcellFile) addMacho(mf *MachoFile) {
|
||||
action.content.MachoInfos[mf.Context().ArchName()] = mf.Info()
|
||||
}
|
||||
|
||||
func (action *saveBcellFile) writeFile() error {
|
||||
outfile := fmt.Sprintf(action.bcellfile)
|
||||
content, err := proto.Marshal(action.content)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if action.signed {
|
||||
blocks := []*protomodel.Block{
|
||||
{
|
||||
Key: 0,
|
||||
Value: content,
|
||||
},
|
||||
}
|
||||
signed_data := protomodel.SignedData{
|
||||
Blocks: blocks,
|
||||
}
|
||||
content, err = proto.Marshal(&signed_data)
|
||||
}
|
||||
|
||||
return ioutil.WriteFile(outfile, content, 0644)
|
||||
}
|
||||
|
||||
func (action *saveBcellFile) withMacho(mf *MachoFile) error {
|
||||
action.addMacho(mf)
|
||||
return action.writeFile()
|
||||
}
|
||||
|
||||
func (action *saveBcellFile) withFat(ff *FatFile) error {
|
||||
for _, macho := range ff.Machos() {
|
||||
action.addMacho(macho)
|
||||
}
|
||||
return action.writeFile()
|
||||
}
|
||||
|
||||
func NewSaveBcellFileAction(userconfig *protomodel.Config, bcellfile string, signed bool) *saveBcellFile {
|
||||
content := &protomodel.BcellFile{
|
||||
BcellConfig: userconfig,
|
||||
MachoInfos: make(map[string]*protomodel.MachoInfo),
|
||||
}
|
||||
return &saveBcellFile{
|
||||
bcellfile,
|
||||
content,
|
||||
signed,
|
||||
}
|
||||
}
|
34
macho-go/internal/wrapper/action/save_init_pointer.go
Normal file
34
macho-go/internal/wrapper/action/save_init_pointer.go
Normal file
@ -0,0 +1,34 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
. "ios-wrapper/internal/wrapper/ofile"
|
||||
"ios-wrapper/pkg/protomodel"
|
||||
)
|
||||
|
||||
type saveInitPointer struct{}
|
||||
|
||||
func (action *saveInitPointer) withMacho(mf *MachoFile) error {
|
||||
init_pointers := []*protomodel.MachoInfo_InitPointer{}
|
||||
for _, ptr := range mf.Context().InitFunctions() {
|
||||
init_pointers = append(init_pointers,
|
||||
&protomodel.MachoInfo_InitPointer{
|
||||
Offset: ptr.Offset(),
|
||||
Value: ptr.Value(),
|
||||
})
|
||||
}
|
||||
log.WithFields(log.Fields{
|
||||
"pointers": init_pointers,
|
||||
}).Info("Saved Init Pointers")
|
||||
mf.Info().InitPointers = init_pointers
|
||||
return nil
|
||||
}
|
||||
|
||||
func (action *saveInitPointer) withFat(ff *FatFile) error {
|
||||
return defaultWithFat(action, ff)
|
||||
}
|
||||
|
||||
func NewSaveInitPointerAction() *saveInitPointer {
|
||||
return &saveInitPointer{}
|
||||
}
|
32
macho-go/internal/wrapper/action/write_file.go
Normal file
32
macho-go/internal/wrapper/action/write_file.go
Normal file
@ -0,0 +1,32 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
|
||||
. "ios-wrapper/internal/wrapper/ofile"
|
||||
"ios-wrapper/pkg/ios/fat"
|
||||
)
|
||||
|
||||
type writeFile struct {
|
||||
outfile string
|
||||
}
|
||||
|
||||
func (action *writeFile) withMacho(mf *MachoFile) error {
|
||||
data, _ := ioutil.ReadFile(mf.TmpFile())
|
||||
return ioutil.WriteFile(action.outfile, data, 0644)
|
||||
}
|
||||
|
||||
func (action *writeFile) withFat(ff *FatFile) error {
|
||||
var files []string
|
||||
for _, macho := range ff.Machos() {
|
||||
files = append(files, macho.TmpFile())
|
||||
}
|
||||
fat.FatJoin(files, action.outfile)
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewWriteFileAction(outfile string) *writeFile {
|
||||
return &writeFile{
|
||||
outfile,
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user