X-Git-Url: https://sigrok.org/gitweb/?p=sigrok-util.git;a=blobdiff_plain;f=firmware%2Fsaleae-logic16%2Fsigrok-fwextract-saleae-logic16;h=a1213c8674c9e4676f740b1f50ca2e30f1c0ab2c;hp=45f98277c879a46d3d02fa1094a9551e64b6ab26;hb=beb1bd5a897f78f73d817fe178c0b446d333e082;hpb=1b0c6828974e6c18763600aeb09034d5686f21f1 diff --git a/firmware/saleae-logic16/sigrok-fwextract-saleae-logic16 b/firmware/saleae-logic16/sigrok-fwextract-saleae-logic16 index 45f9827..a1213c8 100755 --- a/firmware/saleae-logic16/sigrok-fwextract-saleae-logic16 +++ b/firmware/saleae-logic16/sigrok-fwextract-saleae-logic16 @@ -24,7 +24,7 @@ import parseelf class searcher: - def reset(this, offs = 0): + def reset(this, offs=0): if offs < 0 or offs > this.length: raise Exception('Reset past end of section') this.address = this.baseaddr + offs @@ -47,6 +47,15 @@ class searcher: raise Exception('Needle not found in haystack') this.skip(pos - this.offset) + def look_for_either(this, needle1, needle2): + pos1 = this.data.find(needle1, this.offset) + pos2 = this.data.find(needle2, this.offset) + if pos1 < 0 and pos2 < 0: + raise Exception('Needle not found in haystack') + if pos1 < 0 or pos2 < pos1: + pos1 = pos2 + this.skip(pos1 - this.offset) + def __init__(this, data, addr): this.data = data this.baseaddr = addr @@ -69,7 +78,7 @@ def search_plt_64(plt, addr): def find_hex_file_lines_constructor_32(text, hex_file_lines_got, got_plt): while True: - text.look_for(b'\x8b\xbb') # mov offs32(%ebx),%edi + text.look_for_either(b'\x8b\xbb', b'\x8b\xb3') # mov offs32(%ebx),{%edi,%esi} offs = struct.unpack(' 0: if text.peek(2) == b'\x8d\x45': # lea offs8(%ebp),%eax text.skip(3) elif text.peek(2) == b'\x8d\x85': # lea offs32(%ebp),%eax text.skip(6) - if text.peek(1) == b'\xbe': # mov $imm32,%esi + if text.peek(1) == (b'\xbf' if esi else b'\xbe'): # mov $imm32,%esi text.skip(5) - elif text.peek(2) == b'\x31\xf6': # xor %esi,%esi + elif text.peek(2) == (b'\x31\xff' if esi else b'\x31\xf6'): # xor %esi,%esi text.skip(2) if text.peek(4) == b'\x89\x44\x24\x08': # mov %eax,0x8(%esp) text.skip(4) @@ -103,21 +115,21 @@ def parse_hex_file_lines_constructor_32(text, basic_string_plt, got_plt, lines): text.skip(6) straddr += got_plt else: - raise Exception('Expected lea offs32(%ebx),%eax @ '+ + raise Exception('Expected lea offs32(%ebx),%eax @ ' + ('0x%x' % text.address)) if text.peek(4) == b'\x89\x44\x24\x04': # mov %eax,0x4(%esp) text.skip(4) - if text.peek(3) == b'\x89\x3c\x24': # mov %edi,(%esp) + if text.peek(3) == (b'\x89\x34\x24' if esi else b'\x89\x3c\x24'): # mov %edi,(%esp) offs = 0 text.skip(3) - elif text.peek(2) == b'\x8d\x47': # lea offs8(%edi),%eax + elif text.peek(2) == (b'\x8d\x46' if esi else b'\x8d\x47'): # lea offs8(%edi),%eax offs = struct.unpack(' (len(lines) << 2) or (offs & 3) != 0: raise Exception('Invalid offset %d' % offs) @@ -130,10 +142,10 @@ def parse_hex_file_lines_constructor_32(text, basic_string_plt, got_plt, lines): offs = struct.unpack(' (len(lines) << 3) or (offs & 7) != 0: raise Exception('Invalid offset %d' % offs) index = offs >> 3 @@ -179,10 +195,10 @@ def parse_hex_file_lines_constructor_64(text, basic_string_plt, lines): offs = struct.unpack('") @@ -311,4 +327,3 @@ try: extract_bitstream(elf, '33') except Exception as e: print("Error: %s" % str(e)) -