format go code
This commit is contained in:
@ -18,4 +18,3 @@ func (action *removeExports) withFat(ff *FatFile) error {
|
||||
func NewRemoveExportsAction() *removeExports {
|
||||
return &removeExports{}
|
||||
}
|
||||
|
||||
|
@ -20,4 +20,3 @@ func (action *removeImports) withFat(ff *FatFile) error {
|
||||
func NewRemoveImportsAction() *removeImports {
|
||||
return &removeImports{}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fmt"
|
||||
// log "github.com/sirupsen/logrus"
|
||||
|
||||
. "ios-wrapper/internal/wrapper/ofile"
|
||||
@ -11,52 +11,52 @@ import (
|
||||
type saveImports struct{}
|
||||
|
||||
func (action *saveImports) withMacho(mf *MachoFile) error {
|
||||
calculateHash := func(name string) uint32 {
|
||||
var h uint32 = 0x811c9dc5
|
||||
for _, s := range name {
|
||||
h ^= uint32(s)
|
||||
h *= 0x01000193
|
||||
}
|
||||
return h
|
||||
}
|
||||
calculateHash := func(name string) uint32 {
|
||||
var h uint32 = 0x811c9dc5
|
||||
for _, s := range name {
|
||||
h ^= uint32(s)
|
||||
h *= 0x01000193
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
mc := mf.Context()
|
||||
mc := mf.Context()
|
||||
symbols := []*protomodel.MachoInfo_BindSymbol{}
|
||||
fmt.Println("struct imported_symbol {const char* name; const char* lib; uint32_t hash; int segment_i; uint64_t offset;};")
|
||||
fmt.Println("const char* lib_to_resolve = \"main\";")
|
||||
fmt.Println("struct imported_symbol imported_table[] = {")
|
||||
for _, symbol := range mc.CollectBindSymbols() {
|
||||
if symbol.Type() != "lazy" {
|
||||
continue
|
||||
}
|
||||
dylib_hash := calculateHash(symbol.Dylib())
|
||||
seg := mc.Segments()[symbol.Segment()]
|
||||
fmt.Println("struct imported_symbol {const char* name; const char* lib; uint32_t hash; int segment_i; uint64_t offset;};")
|
||||
fmt.Println("const char* lib_to_resolve = \"main\";")
|
||||
fmt.Println("struct imported_symbol imported_table[] = {")
|
||||
for _, symbol := range mc.CollectBindSymbols() {
|
||||
if symbol.Type() != "lazy" {
|
||||
continue
|
||||
}
|
||||
dylib_hash := calculateHash(symbol.Dylib())
|
||||
seg := mc.Segments()[symbol.Segment()]
|
||||
|
||||
var offset uint64
|
||||
var offset uint64
|
||||
|
||||
if symbol.Address() >= seg.Vmaddr() {
|
||||
// this is virtual address
|
||||
offset = symbol.Address() - seg.Vmaddr()
|
||||
} else {
|
||||
// this is file address
|
||||
offset = symbol.Address() - seg.Fileoff()
|
||||
}
|
||||
if symbol.Address() >= seg.Vmaddr() {
|
||||
// this is virtual address
|
||||
offset = symbol.Address() - seg.Vmaddr()
|
||||
} else {
|
||||
// this is file address
|
||||
offset = symbol.Address() - seg.Fileoff()
|
||||
}
|
||||
|
||||
fmt.Printf("{\"%s\", \"%s\", 0x%x, 0x%x, 0x%x},\n",
|
||||
symbol.Name(), symbol.Dylib(), dylib_hash, symbol.Segment(), offset);
|
||||
fmt.Printf("{\"%s\", \"%s\", 0x%x, 0x%x, 0x%x},\n",
|
||||
symbol.Name(), symbol.Dylib(), dylib_hash, symbol.Segment(), offset)
|
||||
|
||||
symbols = append(symbols,
|
||||
&protomodel.MachoInfo_BindSymbol{
|
||||
Name: symbol.Name(),
|
||||
Libname: symbol.Dylib(),
|
||||
Libhash: dylib_hash,
|
||||
Segment: symbol.Segment(),
|
||||
Offset: offset,
|
||||
Name: symbol.Name(),
|
||||
Libname: symbol.Dylib(),
|
||||
Libhash: dylib_hash,
|
||||
Segment: symbol.Segment(),
|
||||
Offset: offset,
|
||||
})
|
||||
|
||||
}
|
||||
fmt.Println("};")
|
||||
fmt.Printf("uint32_t nimports = %d;\n", len(symbols));
|
||||
}
|
||||
fmt.Println("};")
|
||||
fmt.Printf("uint32_t nimports = %d;\n", len(symbols))
|
||||
mf.Info().Symbols = symbols
|
||||
return nil
|
||||
}
|
||||
@ -68,4 +68,3 @@ func (action *saveImports) withFat(ff *FatFile) error {
|
||||
func NewSaveImportsAction() *saveImports {
|
||||
return &saveImports{}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user