1
1
mirror of https://github.com/wader/fq.git synced 2024-12-25 22:34:14 +03:00

macho: mach_header_X to header

arch_bits as value fields
This commit is contained in:
siddik.acil 2022-01-10 21:15:41 +01:00
parent 2638f419eb
commit 141a8e84be

View File

@ -316,7 +316,8 @@ func machoDecode(d *decode.D, in interface{}) interface{} {
}
d.SeekAbs(0)
d.FieldStruct(fmt.Sprintf("mach_header_%d", archBits), func(d *decode.D) {
d.FieldStruct("header", func(d *decode.D) {
d.FieldValueS("arch_bits", int64(archBits))
d.FieldU32("magic", scalar.Hex, classBits, endianNames)
cpuSubType := d.FieldS32("cputype", cpuTypes)
d.FieldS32("cpusubtype", cpuSubTypes[cpuSubType])
@ -343,31 +344,25 @@ func machoDecode(d *decode.D, in interface{}) interface{} {
case LC_SEGMENT, LC_SEGMENT_64:
// nsect := (cmdsize - uint64(archBits)) / uint64(archBits)
var nsects uint64
if archBits == 32 {
d.FieldStruct("segment_command", func(d *decode.D) {
d.FieldValueS("arch_bits", int64(archBits))
d.FieldUTF8NullFixedLen("segname", 16)
if archBits == 32 {
d.FieldU32("vmaddr", scalar.Hex)
d.FieldU32("vmsize")
d.FieldU32("fileoff")
d.FieldU32("tfilesize")
d.FieldS32("initprot")
d.FieldS32("maxprot")
nsects = d.FieldU32("nsects")
d.FieldU32("flags") // TODO expand flags
})
} else {
d.FieldStruct("segment_command_64", func(d *decode.D) {
d.FieldUTF8NullFixedLen("segname", 16)
d.FieldU64("vmaddr", scalar.Hex)
d.FieldU64("vmsize")
d.FieldU64("fileoff")
d.FieldU64("tfilesize")
}
d.FieldS32("initprot")
d.FieldS32("maxprot")
nsects = d.FieldU32("nsects")
d.FieldU32("flags") // TODO expand flags
})
}
var nsectIdx uint64
d.FieldStructArrayLoop("sections", "section", func() bool {
return nsectIdx < nsects