Skip to content

Commit

Permalink
fix: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Dec 6, 2020
1 parent 28ba354 commit a865e30
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 31 deletions.
95 changes: 72 additions & 23 deletions cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,14 +471,57 @@ type Dysymtab struct {
}

func (d *Dysymtab) String() string {
// TODO make this like jtool
// 1 local symbols at index 0
// 29 external symbols at index 1
// 709 undefined symbols at index 30
// No TOC
// No modtab
// 1149 Indirect symbols at offset 0x1695f0
return fmt.Sprintf("%d Indirect symbols at offset 0x%08X", d.Nindirectsyms, d.Indirectsymoff)
var tocStr, modStr, extSymStr, indirSymStr, extRelStr, locRelStr string
if d.Ntoc == 0 {
tocStr = "No"
} else {
tocStr = fmt.Sprintf("%d at 0x%08x", d.Ntoc, d.Tocoffset)
}
if d.Nmodtab == 0 {
modStr = "No"
} else {
modStr = fmt.Sprintf("%d at 0x%08x", d.Nmodtab, d.Modtaboff)
}
if d.Nextrefsyms == 0 {
extSymStr = "None"
} else {
extSymStr = fmt.Sprintf("%d at 0x%08x", d.Nextrefsyms, d.Extrefsymoff)
}
if d.Nindirectsyms == 0 {
indirSymStr = "None"
} else {
indirSymStr = fmt.Sprintf("%d at 0x%08x", d.Nindirectsyms, d.Indirectsymoff)
}
if d.Nextrel == 0 {
extRelStr = "None"
} else {
extRelStr = fmt.Sprintf("%d at 0x%08x", d.Nextrel, d.Extreloff)
}
if d.Nlocrel == 0 {
locRelStr = "None"
} else {
locRelStr = fmt.Sprintf("%d at 0x%08x", d.Nlocrel, d.Locreloff)
}
return fmt.Sprintf(
"\n"+
"\t Local Syms: %d at %d\n"+
"\t External Syms: %d at %d\n"+
"\t Undefined Syms: %d at %d\n"+
"\t TOC: %s\n"+
"\t Modtab: %s\n"+
"\tExternal symtab Entries: %s\n"+
"\tIndirect symtab Entries: %s\n"+
"\t External Reloc Entries: %s\n"+
"\t Local Reloc Entries: %s",
d.Nlocalsym, d.Ilocalsym,
d.Nextdefsym, d.Iextdefsym,
d.Nundefsym, d.Iundefsym,
tocStr,
modStr,
extSymStr,
indirSymStr,
extRelStr,
locRelStr)
}

/*******************************************************************************
Expand Down Expand Up @@ -656,7 +699,7 @@ type CodeSignature struct {
func (c *CodeSignature) String() string {
// TODO: fix this once codesigs are done
// return fmt.Sprintf("offset=0x%08x-0x%08x, size=%d, ID: %s", c.Offset, c.Offset+c.Size, c.Size, c.ID)
return fmt.Sprintf("offset=0x%08x-0x%08x, size=%5d", c.Offset, c.Offset+c.Size, c.Size)
return fmt.Sprintf("offset=0x%08x-0x%08x size=%5d", c.Offset, c.Offset+c.Size, c.Size)
}

/*******************************************************************************
Expand All @@ -679,7 +722,7 @@ func (s *SplitInfo) String() string {
} else {
version = fmt.Sprintf("kind=0x%x", s.Version)
}
return fmt.Sprintf("offset=0x%08x-0x%08x, size=%5d, %s", s.Offset, s.Offset+s.Size, s.Size, version)
return fmt.Sprintf("offset=0x%08x-0x%08x size=%5d, %s", s.Offset, s.Offset+s.Size, s.Size, version)
}

/*******************************************************************************
Expand Down Expand Up @@ -717,9 +760,9 @@ type EncryptionInfo struct {

func (e *EncryptionInfo) String() string {
if e.CryptID == 0 {
return fmt.Sprintf("Offset: 0x%x, Size: 0x%x (not-encrypted yet)", e.Offset, e.Size)
return fmt.Sprintf("offset=0x%x size=0x%x (not-encrypted yet)", e.Offset, e.Size)
}
return fmt.Sprintf("Offset: 0x%x, Size: 0x%x, CryptID: 0x%x", e.Offset, e.Size, e.CryptID)
return fmt.Sprintf("offset=0x%x size=0x%x CryptID: 0x%x", e.Offset, e.Size, e.CryptID)
}
func (e *EncryptionInfo) Copy() *EncryptionInfo {
return &EncryptionInfo{EncryptionInfoCmd: e.EncryptionInfoCmd}
Expand Down Expand Up @@ -910,7 +953,8 @@ type FunctionStarts struct {
}

func (f *FunctionStarts) String() string {
return fmt.Sprintf("offset=0x%08x-0x%08x, size=%5d, count=%d", f.Offset, f.Offset+f.Size, f.Size, len(f.VMAddrs))
return fmt.Sprintf("offset=0x%08x-0x%08x size=%5d", f.Offset, f.Offset+f.Size, f.Size)
// return fmt.Sprintf("offset=0x%08x-0x%08x size=%5d count=%d", f.Offset, f.Offset+f.Size, f.Size, len(f.VMAddrs))
}

/*******************************************************************************
Expand Down Expand Up @@ -970,7 +1014,7 @@ type DataInCode struct {
}

func (d *DataInCode) String() string {
return fmt.Sprintf("offset=0x%08x-0x%08x, size=%5d, entries=%d", d.Offset, d.Offset+d.Size, d.Size, len(d.Entries))
return fmt.Sprintf("offset=0x%08x-0x%08x size=%5d entries=%d", d.Offset, d.Offset+d.Size, d.Size, len(d.Entries))
}

/*******************************************************************************
Expand Down Expand Up @@ -1005,9 +1049,9 @@ type EncryptionInfo64 struct {

func (e *EncryptionInfo64) String() string {
if e.CryptID == 0 {
return fmt.Sprintf("Offset: 0x%x, Size: 0x%x (not-encrypted yet)", e.Offset, e.Size)
return fmt.Sprintf("offset=0x%09x size=0x%x (not-encrypted yet)", e.Offset, e.Size)
}
return fmt.Sprintf("Offset: 0x%x, Size: 0x%x, CryptID: 0x%x", e.Offset, e.Size, e.CryptID)
return fmt.Sprintf("offset=0x%09x size=0x%x CryptID: 0x%x", e.Offset, e.Size, e.CryptID)
}
func (e *EncryptionInfo64) Copy() *EncryptionInfo64 {
return &EncryptionInfo64{EncryptionInfo64Cmd: e.EncryptionInfo64Cmd}
Expand Down Expand Up @@ -1080,11 +1124,16 @@ type BuildVersion struct {
}

func (b *BuildVersion) String() string {
return fmt.Sprintf("Platform: %s, SDK: %s, Tool: %s (%s)",
if b.NumTools > 0 {
return fmt.Sprintf("Platform: %s, SDK: %s, Tool: %s (%s)",
b.Platform,
b.Sdk,
b.Tool,
b.ToolVersion)
}
return fmt.Sprintf("Platform: %s, SDK: %s",
b.Platform,
b.Sdk,
b.Tool,
b.ToolVersion)
b.Sdk)
}

/*******************************************************************************
Expand All @@ -1100,7 +1149,7 @@ type DyldExportsTrie struct {
}

func (t *DyldExportsTrie) String() string {
return fmt.Sprintf("Offset: 0x%x, Size: 0x%x", t.Offset, t.Size)
return fmt.Sprintf("offset=0x%09x size=0x%x", t.Offset, t.Size)
}

/*******************************************************************************
Expand All @@ -1116,7 +1165,7 @@ type DyldChainedFixups struct {
}

func (cf *DyldChainedFixups) String() string {
return fmt.Sprintf("Offset: 0x%x, Size: 0x%x", cf.Offset, cf.Size)
return fmt.Sprintf("offset=0x%09x size=0x%x", cf.Offset, cf.Size)
}

/*******************************************************************************
Expand All @@ -1133,7 +1182,7 @@ type FilesetEntry struct {
}

func (f *FilesetEntry) String() string {
return fmt.Sprintf("Addr: 0x%016x, Offset: 0x%09x, EntryID: %s", f.Addr, f.Offset, f.EntryID)
return fmt.Sprintf("offset=0x%09x addr=0x%016x %s", f.Offset, f.Addr, f.EntryID)
}

/*******************************************************************************
Expand Down
6 changes: 3 additions & 3 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ func (t *FileTOC) LoadsString() string {
var loadsStr string
for i, l := range t.Loads {
if s, ok := l.(*Segment); ok {
loadsStr += fmt.Sprintf("%02d: %s offset=0x%08x-0x%08x, addr=0x%09x-0x%09x %s/%s %s%s%s\n", i, s.Command(), s.Offset, s.Offset+s.Filesz, s.Addr, s.Addr+s.Memsz, s.Prot, s.Maxprot, s.Name, pad(20-len(s.Name)), s.Flag)
loadsStr += fmt.Sprintf("%03d: %s sz=0x%08x off=0x%08x-0x%08x addr=0x%09x-0x%09x %s/%s %s%s%s\n", i, s.Command(), s.Filesz, s.Offset, s.Offset+s.Filesz, s.Addr, s.Addr+s.Memsz, s.Prot, s.Maxprot, s.Name, pad(20-len(s.Name)), s.Flag)
for j := uint32(0); j < s.Nsect; j++ {
c := t.Sections[j+s.Firstsect]
secFlags := ""
if !c.Flags.IsRegular() {
secFlags = fmt.Sprintf("(%s)", c.Flags)
}
loadsStr += fmt.Sprintf("\toffset=0x%08x-0x%08x, addr=0x%09x-0x%09x\t\t%s.%s%s%s %s\n", c.Offset, uint64(c.Offset)+c.Size, c.Addr, c.Addr+c.Size, s.Name, c.Name, pad(32-(len(s.Name)+len(c.Name)+1)), c.Flags.AttributesString(), secFlags)
loadsStr += fmt.Sprintf("\tsz=0x%08x off=0x%08x-0x%08x addr=0x%09x-0x%09x\t\t%s.%s%s%s %s\n", c.Size, c.Offset, uint64(c.Offset)+c.Size, c.Addr, c.Addr+c.Size, s.Name, c.Name, pad(32-(len(s.Name)+len(c.Name)+1)), c.Flags.AttributesString(), secFlags)
}
} else {
if l != nil {
loadsStr += fmt.Sprintf("%02d: %s%s%v\n", i, l.Command(), pad(28-len(l.Command().String())), l)
loadsStr += fmt.Sprintf("%03d: %s%s%v\n", i, l.Command(), pad(28-len(l.Command().String())), l)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion types/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ var cpuSubtypeArmStrings = []IntName{
var cpuSubtypeArm64Strings = []IntName{
{uint32(CPUSubtypeArm64All), "ARM64"},
{uint32(CPUSubtypeArm64V8), "ARM64 (ARMv8)"},
{uint32(CPUSubtypeArm64E), "ARM64e (ARMv8.3)"},
{uint32(CPUSubtypeArm64E), "ARM64e"},
}

func (st CPUSubtype) String(cpu CPU) string {
Expand Down
6 changes: 6 additions & 0 deletions types/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ const (
)

// GETTERS
func (f HeaderFlag) None() bool {
return f == 0
}
func (f HeaderFlag) NoUndefs() bool {
return (f & NoUndefs) != 0
}
Expand Down Expand Up @@ -212,6 +215,9 @@ func (f *HeaderFlag) Set(flag HeaderFlag, set bool) {
// List returns a string array of flag names
func (f HeaderFlag) List() []string {
var flags []string
if f.None() {
flags = append(flags, None.String())
}
if f.NoUndefs() {
flags = append(flags, NoUndefs.String())
}
Expand Down
1 change: 1 addition & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func (sv SrcVersion) String() string {
type Tool uint32

const (
none Tool = 0
clang Tool = 1 // TOOL_CLANG
swift Tool = 2 // TOOL_SWIFT
ld Tool = 3 // TOOL_LD
Expand Down
8 changes: 4 additions & 4 deletions types/types_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a865e30

Please sign in to comment.