format go code

This commit is contained in:
nganhkhoa 2023-06-26 15:28:16 +07:00
parent b8d8343835
commit 2eede8f9b2
12 changed files with 542 additions and 544 deletions

View File

@ -18,4 +18,3 @@ func (action *removeExports) withFat(ff *FatFile) error {
func NewRemoveExportsAction() *removeExports { func NewRemoveExportsAction() *removeExports {
return &removeExports{} return &removeExports{}
} }

View File

@ -20,4 +20,3 @@ func (action *removeImports) withFat(ff *FatFile) error {
func NewRemoveImportsAction() *removeImports { func NewRemoveImportsAction() *removeImports {
return &removeImports{} return &removeImports{}
} }

View File

@ -43,7 +43,7 @@ func (action *saveImports) withMacho(mf *MachoFile) error {
} }
fmt.Printf("{\"%s\", \"%s\", 0x%x, 0x%x, 0x%x},\n", fmt.Printf("{\"%s\", \"%s\", 0x%x, 0x%x, 0x%x},\n",
symbol.Name(), symbol.Dylib(), dylib_hash, symbol.Segment(), offset); symbol.Name(), symbol.Dylib(), dylib_hash, symbol.Segment(), offset)
symbols = append(symbols, symbols = append(symbols,
&protomodel.MachoInfo_BindSymbol{ &protomodel.MachoInfo_BindSymbol{
@ -56,7 +56,7 @@ func (action *saveImports) withMacho(mf *MachoFile) error {
} }
fmt.Println("};") fmt.Println("};")
fmt.Printf("uint32_t nimports = %d;\n", len(symbols)); fmt.Printf("uint32_t nimports = %d;\n", len(symbols))
mf.Info().Symbols = symbols mf.Info().Symbols = symbols
return nil return nil
} }
@ -68,4 +68,3 @@ func (action *saveImports) withFat(ff *FatFile) error {
func NewSaveImportsAction() *saveImports { func NewSaveImportsAction() *saveImports {
return &saveImports{} return &saveImports{}
} }

View File

@ -88,7 +88,7 @@ func (mc *MachoContext) CollectBindSymbolsModern() []*ImportSymbol {
// until buf is freed, all pointers are valid // until buf is freed, all pointers are valid
// remember to copy before moving out // remember to copy before moving out
header := (*C.uchar)(unsafe.Pointer(&buf[0])) header := (*C.uchar)(unsafe.Pointer(&buf[0]))
imports_table := C.GetImportsTable(header); imports_table := C.GetImportsTable(header)
// for i := 0; i < int(imports_table.size); i++ { // for i := 0; i < int(imports_table.size); i++ {
// s := C.GetImportsAt(&imports_table, C.int(i)) // s := C.GetImportsAt(&imports_table, C.int(i))
@ -108,7 +108,7 @@ func (mc *MachoContext) CollectBindSymbolsModern() []*ImportSymbol {
status := int(C.GetSegmentFixAt(header, C.uint(segment_i), fix_ptr)) status := int(C.GetSegmentFixAt(header, C.uint(segment_i), fix_ptr))
segment_i += 1 segment_i += 1
if status == 2 { if status == 2 {
break; break
} }
if status == 3 { if status == 3 {
continue continue

View File

@ -1,11 +1,11 @@
package macho package macho
import ( import (
"bytes"
"fmt" "fmt"
"io" "io"
"math/rand" "math/rand"
"time" "time"
"bytes"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@ -412,7 +412,7 @@ func (mc *MachoContext) ReworkForObjc() {
last := sections[len(sections)-1] last := sections[len(sections)-1]
data_end = int(last.Offset()) + int(last.Size()) data_end = int(last.Offset()) + int(last.Size())
if (last.Offset() == 0) { if last.Offset() == 0 {
before_last := sections[len(sections)-2] before_last := sections[len(sections)-2]
data_end += int(before_last.Offset()) + int(before_last.Size()) data_end += int(before_last.Offset()) + int(before_last.Size())
} }
@ -529,7 +529,6 @@ func (mc *MachoContext) ReworkForObjc() {
} }
} }
func (mc *MachoContext) RemoveSymbolTable() { func (mc *MachoContext) RemoveSymbolTable() {
// try to remove symtab and dysymtab // try to remove symtab and dysymtab
mc.removeSymtabCommand() mc.removeSymtabCommand()

View File

@ -248,12 +248,14 @@ func (mc *MachoContext) Parse(r *bufio.Reader) error {
lcmd.Deserialize(mc, command_buf) lcmd.Deserialize(mc, command_buf)
mc.commands = append(mc.commands, lcmd) mc.commands = append(mc.commands, lcmd)
mc.symtab = lcmd mc.symtab = lcmd
break
case LC_DYSYMTAB: case LC_DYSYMTAB:
lcmd := new(DySymtab) lcmd := new(DySymtab)
lcmd.Deserialize(mc, command_buf) lcmd.Deserialize(mc, command_buf)
mc.commands = append(mc.commands, lcmd) mc.commands = append(mc.commands, lcmd)
mc.dysymtab = lcmd mc.dysymtab = lcmd
break
default: default:
lcmd := new(LoadCmd) lcmd := new(LoadCmd)