| OLD | NEW |
| 1 | 1 |
| 2 # Modifies ld.so's ELF Program Headers to get a version that NaCl's | 2 # Modifies ld.so's ELF Program Headers to get a version that NaCl's |
| 3 # sel_ldr will run. | 3 # sel_ldr will run. |
| 4 # | 4 # |
| 5 # For a discussion, see: | 5 # For a discussion, see: |
| 6 # http://code.google.com/p/nativeclient/issues/detail?id=156 | 6 # http://code.google.com/p/nativeclient/issues/detail?id=156 |
| 7 # http://code.google.com/p/nativeclient/issues/detail?id=558 | 7 # http://code.google.com/p/nativeclient/issues/detail?id=558 |
| 8 | 8 |
| 9 import struct | 9 import struct |
| 10 import sys | 10 import sys |
| 11 | 11 |
| 12 | 12 |
| 13 offset_e_type = 16 | 13 offset_e_type = 16 |
| 14 offset_e_phnum32 = 44 | 14 offset_e_phnum32 = 44 |
| 15 offset_e_phnum64 = 56 | 15 offset_e_phnum64 = 56 |
| 16 | 16 |
| 17 offset_ei_class = 4 | 17 offset_ei_class = 4 |
| 18 elfclass32 = "\001" | 18 elfclass32 = "\001" |
| 19 elfclass64 = "\002" | 19 elfclass64 = "\002" |
| 20 | 20 |
| 21 ET_EXEC = 2 | 21 ET_EXEC = 2 |
| 22 ET_DYN = 3 | 22 ET_DYN = 3 |
| 23 | 23 |
| 24 | 24 |
| 25 def main(args): | 25 def main(args): |
| 26 if len(args) != 1: | 26 if len(args) != 1: |
| 27 raise Exception("Usage: fixup <filename>") | 27 raise Exception("Usage: fixup <filename>") |
| 28 filename = args[0] | 28 filename = args[0] |
| 29 fh = open(filename, "r+") | 29 fh = open(filename, "r+") |
| 30 | 30 |
| 31 def check(ty, offset, expected): | 31 def check(ty, offset, expected): |
| 32 fh.seek(offset) | 32 fh.seek(offset) |
| 33 data = fh.read(struct.calcsize(ty)) | 33 data = fh.read(struct.calcsize(ty)) |
| 34 got = struct.unpack(ty, data)[0] | 34 got = struct.unpack(ty, data)[0] |
| 35 if got != expected: | 35 if got != expected: |
| 36 raise AssertionError("Expected %s, got %s" % (expected, got)) | 36 raise AssertionError("Expected %s, got %s" % (expected, got)) |
| 37 | 37 |
| 38 def replace(ty, offset, value): | 38 def replace(ty, offset, value): |
| 39 fh.seek(offset) | 39 fh.seek(offset) |
| 40 fh.write(struct.pack(ty, value)) | 40 fh.write(struct.pack(ty, value)) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 54 check("H", offset_e_phnum64, 7) | 54 check("H", offset_e_phnum64, 7) |
| 55 replace("H", offset_e_phnum64, 3) | 55 replace("H", offset_e_phnum64, 3) |
| 56 else: | 56 else: |
| 57 raise AssertionError("Unknown ELF class in file %s." % filename) | 57 raise AssertionError("Unknown ELF class in file %s." % filename) |
| 58 | 58 |
| 59 fh.close() | 59 fh.close() |
| 60 | 60 |
| 61 | 61 |
| 62 if __name__ == "__main__": | 62 if __name__ == "__main__": |
| 63 main(sys.argv[1:]) | 63 main(sys.argv[1:]) |
| OLD | NEW |