format go code
This commit is contained in:
parent
b8d8343835
commit
2eede8f9b2
@ -18,4 +18,3 @@ func (action *removeExports) withFat(ff *FatFile) error {
|
|||||||
func NewRemoveExportsAction() *removeExports {
|
func NewRemoveExportsAction() *removeExports {
|
||||||
return &removeExports{}
|
return &removeExports{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,4 +20,3 @@ func (action *removeImports) withFat(ff *FatFile) error {
|
|||||||
func NewRemoveImportsAction() *removeImports {
|
func NewRemoveImportsAction() *removeImports {
|
||||||
return &removeImports{}
|
return &removeImports{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ func (mc *MachoContext) CollectBindSymbols() []*ImportSymbol {
|
|||||||
|
|
||||||
func (mc *MachoContext) findSegmentIndexAt(address uint64) int {
|
func (mc *MachoContext) findSegmentIndexAt(address uint64) int {
|
||||||
for i, segment := range mc.Segments() {
|
for i, segment := range mc.Segments() {
|
||||||
if segment.Fileoff() <= address && segment.Fileoff() + segment.Filesize() > address {
|
if segment.Fileoff() <= address && segment.Fileoff()+segment.Filesize() > address {
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,13 +82,13 @@ func (mc *MachoContext) findSegmentIndexAt(address uint64) int {
|
|||||||
func (mc *MachoContext) CollectBindSymbolsModern() []*ImportSymbol {
|
func (mc *MachoContext) CollectBindSymbolsModern() []*ImportSymbol {
|
||||||
start := mc.fixups.dataoff
|
start := mc.fixups.dataoff
|
||||||
size := mc.fixups.datasize
|
size := mc.fixups.datasize
|
||||||
buf := mc.buf[start:start+size]
|
buf := mc.buf[start : start+size]
|
||||||
|
|
||||||
// all pointers used are based from this **buf**
|
// all pointers used are based from this **buf**
|
||||||
// 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
|
||||||
@ -160,7 +160,7 @@ func (mc *MachoContext) CollectBindSymbolsModern() []*ImportSymbol {
|
|||||||
}
|
}
|
||||||
// because the pointer move up 8 bytes already so we minus 8
|
// because the pointer move up 8 bytes already so we minus 8
|
||||||
address += int64(next * 4)
|
address += int64(next * 4)
|
||||||
mc.file.Seek(int64(next * 4) - 8, io.SeekCurrent)
|
mc.file.Seek(int64(next*4)-8, io.SeekCurrent)
|
||||||
}
|
}
|
||||||
mc.file.Seek(0, io.SeekStart)
|
mc.file.Seek(0, io.SeekStart)
|
||||||
}
|
}
|
||||||
|
@ -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"
|
||||||
|
|
||||||
@ -386,9 +386,9 @@ func (mc *MachoContext) ReworkForObjc() {
|
|||||||
if bytes.Compare(bytes.Trim(section.SectName(), "\x00"), []byte("__init_offsets")) == 0 {
|
if bytes.Compare(bytes.Trim(section.SectName(), "\x00"), []byte("__init_offsets")) == 0 {
|
||||||
// mc.file.WriteAt([]byte("__init_offsetx"), section_ptr)
|
// mc.file.WriteAt([]byte("__init_offsetx"), section_ptr)
|
||||||
// edit flags to not S_MOD_INIT_FUNC
|
// edit flags to not S_MOD_INIT_FUNC
|
||||||
mc.file.WriteAt([]byte{0, 0, 0, 0}, section_ptr + 0x40)
|
mc.file.WriteAt([]byte{0, 0, 0, 0}, section_ptr+0x40)
|
||||||
}
|
}
|
||||||
section_ptr += 16 * 2 + 8 * 2 + 4 * 8
|
section_ptr += 16*2 + 8*2 + 4*8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if bytes.Compare(bytes.Trim(segment.SegName(), "\x00"), []byte("__DATA_CONST")) == 0 {
|
if bytes.Compare(bytes.Trim(segment.SegName(), "\x00"), []byte("__DATA_CONST")) == 0 {
|
||||||
@ -400,7 +400,7 @@ func (mc *MachoContext) ReworkForObjc() {
|
|||||||
if bytes.Compare(bytes.Trim(section.SectName(), "\x00"), []byte("__objc_nlclslist")) == 0 {
|
if bytes.Compare(bytes.Trim(section.SectName(), "\x00"), []byte("__objc_nlclslist")) == 0 {
|
||||||
mc.file.WriteAt([]byte("__objc_nlclsbruh"), section_ptr)
|
mc.file.WriteAt([]byte("__objc_nlclsbruh"), section_ptr)
|
||||||
}
|
}
|
||||||
section_ptr += 16 * 2 + 8 * 2 + 4 * 8
|
section_ptr += 16*2 + 8*2 + 4*8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if bytes.Compare(bytes.Trim(segment.SegName(), "\x00"), []byte("__DATA")) == 0 {
|
if bytes.Compare(bytes.Trim(segment.SegName(), "\x00"), []byte("__DATA")) == 0 {
|
||||||
@ -409,11 +409,11 @@ func (mc *MachoContext) ReworkForObjc() {
|
|||||||
// __bss section is dynamically allocated at the end to or something, hmmge
|
// __bss section is dynamically allocated at the end to or something, hmmge
|
||||||
// assume that it order correctly, which it should if compiled and not modified
|
// assume that it order correctly, which it should if compiled and not modified
|
||||||
sections := segment.Sections()
|
sections := segment.Sections()
|
||||||
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()
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user