69 lines
1.3 KiB
Go
69 lines
1.3 KiB
Go
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,
|
|
}
|
|
}
|