| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/python | |
| 2 # | |
| 3 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 4 # Use of this source code is governed by a BSD-style license that can be | |
| 5 # found in the LICENSE file. | |
| 6 # | |
| 7 # This generates symbol signatures with the same algorithm as | |
| 8 # src/breakpad/src/common/linux/file_id.cc@461 | |
| 9 | |
| 10 import struct | |
| 11 import sys | |
| 12 import subprocess | |
| 13 | |
| 14 if len(sys.argv) != 2: | |
| 15 sys.stderr.write("Error, no filename specified.\n") | |
| 16 sys.exit(1) | |
| 17 | |
| 18 # Shell out to objdump to get the offset of the .text section | |
| 19 objdump = subprocess.Popen(['objdump', '-h', sys.argv[1]], stdout = subprocess.P
IPE) | |
| 20 (sections, _) = objdump.communicate() | |
| 21 if objdump.returncode != 0: | |
| 22 sys.stderr.write('Failed to run objdump to find .text section.\n') | |
| 23 sys.exit(1) | |
| 24 | |
| 25 text_section = [x for x in sections.splitlines() if '.text' in x] | |
| 26 if len(text_section) == 0: | |
| 27 sys.stderr.write('objdump failed to find a .text section.\n') | |
| 28 sys.exit(1) | |
| 29 text_section = text_section[0] | |
| 30 try: | |
| 31 file_offset = int(text_section.split()[5], 16) | |
| 32 except ValueError: | |
| 33 sys.stderr.write("Failed to parse objdump output. Here is the failing line:\n"
); | |
| 34 sys.stderr.write(text_section) | |
| 35 sys.exit(1) | |
| 36 | |
| 37 bin = open(sys.argv[1]) | |
| 38 bin.seek(file_offset) | |
| 39 if bin.tell() != file_offset: | |
| 40 sys.stderr.write("Failed to seek to the .text segment. Truncated file?\n"); | |
| 41 sys.exit(1) | |
| 42 | |
| 43 data = bin.read(4096) | |
| 44 if len(data) != 4096: | |
| 45 sys.stderr.write("Error, did not read first page of data.\n"); | |
| 46 sys.exit(1) | |
| 47 bin.close() | |
| 48 | |
| 49 signature = [0] * 16 | |
| 50 for i in range(0, 4096): | |
| 51 signature[i % 16] ^= ord(data[i]) | |
| 52 | |
| 53 # Append a 0 at the end for the generation number (always 0 on Linux) | |
| 54 out = ('%08X%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X0' % | |
| 55 struct.unpack('I2H8B', struct.pack('16B', *signature))) | |
| 56 sys.stdout.write(out) | |
| OLD | NEW |