diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/relocate_sdk.py | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/scripts/relocate_sdk.py b/scripts/relocate_sdk.py index 8a728720ba..9e01c09cb0 100755 --- a/scripts/relocate_sdk.py +++ b/scripts/relocate_sdk.py | |||
| @@ -49,6 +49,34 @@ def get_arch(): | |||
| 49 | elif ei_class == 2: | 49 | elif ei_class == 2: |
| 50 | return 64 | 50 | return 64 |
| 51 | 51 | ||
| 52 | def get_dl_arch(dl_path): | ||
| 53 | try: | ||
| 54 | with open(dl_path, "r+b") as f: | ||
| 55 | e_ident =f.read(16) | ||
| 56 | except IOError: | ||
| 57 | exctype, ioex = sys.exc_info()[:2] | ||
| 58 | if ioex.errno == errno.ETXTBSY: | ||
| 59 | print("Could not open %s. File used by another process.\nPlease "\ | ||
| 60 | "make sure you exit all processes that might use any SDK "\ | ||
| 61 | "binaries." % e) | ||
| 62 | else: | ||
| 63 | print("Could not open %s: %s(%d)" % (e, ioex.strerror, ioex.errno)) | ||
| 64 | sys.exit(-1) | ||
| 65 | |||
| 66 | ei_mag0,ei_mag1_3,ei_class,ei_data,ei_version = struct.unpack("<B3sBBB9x", e_ident) | ||
| 67 | |||
| 68 | if (ei_mag0 != 0x7f and ei_mag1_3 != "ELF") or ei_class == 0: | ||
| 69 | print("ERROR: unknow %s" % dl_path) | ||
| 70 | sys.exit(-1) | ||
| 71 | |||
| 72 | if ei_class == 1: | ||
| 73 | arch = 32 | ||
| 74 | elif ei_class == 2: | ||
| 75 | arch = 64 | ||
| 76 | |||
| 77 | return arch | ||
| 78 | |||
| 79 | |||
| 52 | def parse_elf_header(): | 80 | def parse_elf_header(): |
| 53 | global e_type, e_machine, e_version, e_entry, e_phoff, e_shoff, e_flags,\ | 81 | global e_type, e_machine, e_version, e_entry, e_phoff, e_shoff, e_flags,\ |
| 54 | e_ehsize, e_phentsize, e_phnum, e_shentsize, e_shnum, e_shstrndx | 82 | e_ehsize, e_phentsize, e_phnum, e_shentsize, e_shnum, e_shstrndx |
| @@ -223,6 +251,8 @@ else: | |||
| 223 | 251 | ||
| 224 | executables_list = sys.argv[3:] | 252 | executables_list = sys.argv[3:] |
| 225 | 253 | ||
| 254 | dl_arch = get_dl_arch(new_dl_path) | ||
| 255 | |||
| 226 | errors = False | 256 | errors = False |
| 227 | for e in executables_list: | 257 | for e in executables_list: |
| 228 | perms = os.stat(e)[stat.ST_MODE] | 258 | perms = os.stat(e)[stat.ST_MODE] |
| @@ -247,7 +277,7 @@ for e in executables_list: | |||
| 247 | old_size = os.path.getsize(e) | 277 | old_size = os.path.getsize(e) |
| 248 | if old_size >= 64: | 278 | if old_size >= 64: |
| 249 | arch = get_arch() | 279 | arch = get_arch() |
| 250 | if arch: | 280 | if arch and arch == dl_arch: |
| 251 | parse_elf_header() | 281 | parse_elf_header() |
| 252 | if not change_interpreter(e): | 282 | if not change_interpreter(e): |
| 253 | errors = True | 283 | errors = True |
