diff options
Diffstat (limited to 'scripts/relocate_sdk.py')
| -rwxr-xr-x | scripts/relocate_sdk.py | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/scripts/relocate_sdk.py b/scripts/relocate_sdk.py index 8c0fdb986a..4ed8bfc0d1 100755 --- a/scripts/relocate_sdk.py +++ b/scripts/relocate_sdk.py | |||
| @@ -30,9 +30,16 @@ else: | |||
| 30 | old_prefix = re.compile(b("##DEFAULT_INSTALL_DIR##")) | 30 | old_prefix = re.compile(b("##DEFAULT_INSTALL_DIR##")) |
| 31 | 31 | ||
| 32 | def get_arch(): | 32 | def get_arch(): |
| 33 | global endian_prefix | ||
| 33 | f.seek(0) | 34 | f.seek(0) |
| 34 | e_ident =f.read(16) | 35 | e_ident =f.read(16) |
| 35 | ei_mag0,ei_mag1_3,ei_class = struct.unpack("<B3sB11x", e_ident) | 36 | ei_mag0,ei_mag1_3,ei_class,ei_data,ei_version = struct.unpack("<B3sBBB9x", e_ident) |
| 37 | |||
| 38 | # ei_data = 1 for little-endian & 0 for big-endian | ||
| 39 | if ei_data == 1: | ||
| 40 | endian_prefix = '<' | ||
| 41 | else: | ||
| 42 | endian_prefix = '>' | ||
| 36 | 43 | ||
| 37 | if (ei_mag0 != 0x7f and ei_mag1_3 != "ELF") or ei_class == 0: | 44 | if (ei_mag0 != 0x7f and ei_mag1_3 != "ELF") or ei_class == 0: |
| 38 | return 0 | 45 | return 0 |
| @@ -51,11 +58,11 @@ def parse_elf_header(): | |||
| 51 | 58 | ||
| 52 | if arch == 32: | 59 | if arch == 32: |
| 53 | # 32bit | 60 | # 32bit |
| 54 | hdr_fmt = "<HHILLLIHHHHHH" | 61 | hdr_fmt = endian_prefix + "HHILLLIHHHHHH" |
| 55 | hdr_size = 52 | 62 | hdr_size = 52 |
| 56 | else: | 63 | else: |
| 57 | # 64bit | 64 | # 64bit |
| 58 | hdr_fmt = "<HHIQQQIHHHHHH" | 65 | hdr_fmt = endian_prefix + "HHIQQQIHHHHHH" |
| 59 | hdr_size = 64 | 66 | hdr_size = 64 |
| 60 | 67 | ||
| 61 | e_type, e_machine, e_version, e_entry, e_phoff, e_shoff, e_flags,\ | 68 | e_type, e_machine, e_version, e_entry, e_phoff, e_shoff, e_flags,\ |
| @@ -64,9 +71,9 @@ def parse_elf_header(): | |||
| 64 | 71 | ||
| 65 | def change_interpreter(elf_file_name): | 72 | def change_interpreter(elf_file_name): |
| 66 | if arch == 32: | 73 | if arch == 32: |
| 67 | ph_fmt = "<IIIIIIII" | 74 | ph_fmt = endian_prefix + "IIIIIIII" |
| 68 | else: | 75 | else: |
| 69 | ph_fmt = "<IIQQQQQQ" | 76 | ph_fmt = endian_prefix + "IIQQQQQQ" |
| 70 | 77 | ||
| 71 | """ look for PT_INTERP section """ | 78 | """ look for PT_INTERP section """ |
| 72 | for i in range(0,e_phnum): | 79 | for i in range(0,e_phnum): |
| @@ -105,17 +112,17 @@ def change_interpreter(elf_file_name): | |||
| 105 | 112 | ||
| 106 | def change_dl_sysdirs(elf_file_name): | 113 | def change_dl_sysdirs(elf_file_name): |
| 107 | if arch == 32: | 114 | if arch == 32: |
| 108 | sh_fmt = "<IIIIIIIIII" | 115 | sh_fmt = endian_prefix + "IIIIIIIIII" |
| 109 | else: | 116 | else: |
| 110 | sh_fmt = "<IIQQQQIIQQ" | 117 | sh_fmt = endian_prefix + "IIQQQQIIQQ" |
| 111 | 118 | ||
| 112 | """ read section string table """ | 119 | """ read section string table """ |
| 113 | f.seek(e_shoff + e_shstrndx * e_shentsize) | 120 | f.seek(e_shoff + e_shstrndx * e_shentsize) |
| 114 | sh_hdr = f.read(e_shentsize) | 121 | sh_hdr = f.read(e_shentsize) |
| 115 | if arch == 32: | 122 | if arch == 32: |
| 116 | sh_offset, sh_size = struct.unpack("<16xII16x", sh_hdr) | 123 | sh_offset, sh_size = struct.unpack(endian_prefix + "16xII16x", sh_hdr) |
| 117 | else: | 124 | else: |
| 118 | sh_offset, sh_size = struct.unpack("<24xQQ24x", sh_hdr) | 125 | sh_offset, sh_size = struct.unpack(endian_prefix + "24xQQ24x", sh_hdr) |
| 119 | 126 | ||
| 120 | f.seek(sh_offset) | 127 | f.seek(sh_offset) |
| 121 | sh_strtab = f.read(sh_size) | 128 | sh_strtab = f.read(sh_size) |
