59 lines
1.1 KiB
Go
59 lines
1.1 KiB
Go
package ofile
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"ios-wrapper/pkg/ios/fat"
|
|
)
|
|
|
|
type FatFile struct {
|
|
machos []*MachoFile
|
|
files []string
|
|
tmp_file string
|
|
}
|
|
|
|
func (ff *FatFile) Machos() []*MachoFile {
|
|
return ff.machos
|
|
}
|
|
|
|
func (ff *FatFile) Cleanup() {
|
|
for _, macho := range ff.machos {
|
|
macho.Cleanup()
|
|
}
|
|
os.Remove(ff.tmp_file)
|
|
}
|
|
|
|
func NewFatFile(f string) *FatFile {
|
|
// create a tmp working file
|
|
tmp, _ := ioutil.TempFile("", "bcell_*")
|
|
data, _ := ioutil.ReadFile(f)
|
|
ioutil.WriteFile(tmp.Name(), data, 0644)
|
|
|
|
var machos []*MachoFile
|
|
var files []string
|
|
splitted_files, err := fat.FatSplit(tmp.Name())
|
|
if err != nil {
|
|
log.WithFields(log.Fields{
|
|
"err": err,
|
|
"splitted_ok": splitted_files,
|
|
}).Panic("Cannot split Fat binary")
|
|
}
|
|
for _, splitted_file := range splitted_files {
|
|
macho := NewMachoFile(splitted_file)
|
|
machos = append(machos, macho)
|
|
files = append(files, macho.tmp_file)
|
|
|
|
// NewMachoFile creates another tmp file, remove this temp splitted file
|
|
os.Remove(splitted_file)
|
|
}
|
|
|
|
return &FatFile{
|
|
machos: machos,
|
|
tmp_file: tmp.Name(),
|
|
files: files,
|
|
}
|
|
}
|