| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
import re |
| 4 |
import sys |
| 5 |
import shutil |
| 6 |
import subprocess |
| 7 |
|
| 8 |
exepath = sys.argv[1] |
| 9 |
want_arch = sys.argv[2] |
| 10 |
dummy_output = sys.argv[3] |
| 11 |
|
| 12 |
with open(dummy_output, 'w') as f: |
| 13 |
f.write('') |
| 14 |
|
| 15 |
if not shutil.which('dumpbin'): |
| 16 |
print('dumpbin not found, skipping') |
| 17 |
sys.exit(0) |
| 18 |
|
| 19 |
out = subprocess.check_output(['dumpbin', '/HEADERS', exepath], |
| 20 |
universal_newlines=True) |
| 21 |
for line in out.split('\n'): |
| 22 |
m = re.match(r'.* machine \(([A-Za-z0-9]+)\)$', line) |
| 23 |
if m: |
| 24 |
arch = m.groups()[0].lower() |
| 25 |
|
| 26 |
if arch == 'arm64': |
| 27 |
arch = 'aarch64' |
| 28 |
elif arch == 'x64': |
| 29 |
arch = 'x86_64' |
| 30 |
|
| 31 |
if arch != want_arch: |
| 32 |
raise RuntimeError(f'Wanted arch {want_arch} but exe uses {arch}') |