metasm/exe_format/macho.rb in metasm-1.0.2 vs metasm/exe_format/macho.rb in metasm-1.0.3
- old
+ new
@@ -41,10 +41,12 @@
1 => '780', 2 => '785', 3 => '750', 4 => '730',
5 => 'UVAXI', 6 => 'UVAXII', 7 => '8200', 8 => '8500',
9 => '8600', 10 => '8650', 11 => '8800', 12 => 'UVAXIII',
},
'ROMP' => { 0 => 'ALL', 1 => 'PC', 2 => 'APC', 3 => '135',
+ },
+ 'NS32032' => { # same for NS*
0 => 'MMAX_ALL', 1 => 'MMAX_DPC', 2 => 'SQT',
3 => 'MMAX_APC_FPU', 4 => 'MMAX_APC_FPA', 5 => 'MMAX_XPC',
},
'I386' => { 3 => 'ALL', 4 => '486', 4+128 => '486SX',
0 => 'INTEL_MODEL_ALL', 10 => 'PENTIUM_4',
@@ -136,11 +138,15 @@
GENERIC_RELOC = { 0 => 'VANILLA', 1 => 'PAIR', 2 => 'SECTDIFF', 3 => 'LOCAL_SECTDIFF', 4 => 'PB_LA_PTR' }
SEC_TYPE = {
0 => 'REGULAR', 1 => 'ZEROFILL', 2 => 'CSTRING_LITERALS', 3 => '4BYTE_LITERALS',
4 => '8BYTE_LITERALS', 5 => 'LITERAL_POINTERS', 6 => 'NON_LAZY_SYMBOL_POINTERS',
- 7 => 'LAZY_SYMBOL_POINTERS', 8 => 'SYMBOL_STUBS', 9 => 'MOD_INIT_FUNC_POINTERS'
+ 7 => 'LAZY_SYMBOL_POINTERS', 8 => 'SYMBOL_STUBS', 9 => 'MOD_INIT_FUNC_POINTERS',
+ 10 => 'MOD_TERM_FUNC_POINTERS', 11 => 'COALESCED', 12 => 'GB_ZEROFILL', 13 => 'INTERPOSING',
+ 14 => '16BYTE_LITERALS', 15 => 'DTRACE_DOF', 16 => 'LAZY_DYLIB_SYMBOL_POINTERS',
+ 17 => 'THREAD_LOCAL_REGULAR', 18 => 'THREAD_LOCAL_ZEROFILL', 19 => 'THREAD_LOCAL_VARIABLES',
+ 20 => 'THREAD_LOCAL_VARIABLE_POINTERS', 21 => 'THREAD_LOCAL_INIT_FUNCTION_POINTERS'
}
class SerialStruct < Metasm::SerialStruct
new_int_field :xword
end
@@ -626,34 +632,42 @@
case sec.type
when 'NON_LAZY_SYMBOL_POINTERS', 'LAZY_SYMBOL_POINTERS'
edata = seg.encoded
off = sec.offset - seg.fileoff
- (sec.size / 4).times { |i|
+ (sec.size / sizeof_xword).times { |i|
sidx = indsymtab[sec.res1+i]
+ if not sidx
+ puts "W: osx: invalid symbol pointer index #{i} ?" if $VERBOSE
+ next
+ end
case IND_SYM_IDX[sidx]
when 'INDIRECT_SYMBOL_LOCAL' # base reloc: add delta from prefered image base
edata.ptr = off
- addr = decode_word(edata)
+ addr = decode_xword(edata)
if s = segment_at(addr)
label = label_at(s.encoded, s.encoded.ptr, "xref_#{Expression[addr]}")
- seg.encoded.reloc[off] = Metasm::Relocation.new(Expression[label], :u32, @endianness)
+ seg.encoded.reloc[off] = Metasm::Relocation.new(Expression[label], "u#@size".to_sym, @endianness)
end
when 'INDIRECT_SYMBOL_ABS' # nothing
else
sym = @symbols[sidx]
- seg.encoded.reloc[off] = Metasm::Relocation.new(Expression[sym.name], :u32, @endianness)
+ seg.encoded.reloc[off] = Metasm::Relocation.new(Expression[sym.name],"u#@size".to_sym, @endianness)
end
- off += 4
+ off += sizeof_xword
}
when 'SYMBOL_STUBS'
# TODO next unless arch == 386 and sec.attrs & SELF_MODIFYING_CODE and sec.res2 == 5
edata = seg.encoded
edata.data = edata.data.to_str.dup
off = sec.offset - seg.fileoff + 1
(sec.size / 5).times { |i|
sidx = indsymtab[sec.res1+i]
+ if not sidx
+ puts "W: osx: invalid symbol stub index #{i} ?" if $VERBOSE
+ next
+ end
case IND_SYM_IDX[sidx]
when 'INDIRECT_SYMBOL_LOCAL' # base reloc: add delta from prefered image base
edata.ptr = off
addr = decode_word(edata)
if s = segment_at(addr)