Skip to content

Commit 4f08b6d

Browse files
authored
Allow setting context.device=None, and use context.arch to determine default ABI for adb.compile (#950)
1 parent 065c79d commit 4f08b6d

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

pwnlib/adb/adb.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,14 +1197,24 @@ def compile(source):
11971197
if not project:
11981198
# Realistically this should inherit from context.arch, but
11991199
# this works for now.
1200-
abi = 'armeabi-v7a'
12011200
sdk = '21'
1201+
abi = {
1202+
'aarch64': 'arm64-v8a',
1203+
'amd64': 'x86_64',
1204+
'arm': 'armeabi-v7a',
1205+
'i386': 'x86',
1206+
'mips': 'mips',
1207+
'mips64': 'mips64',
1208+
}.get(context.arch, None)
12021209

12031210
# If we have an attached device, use its settings.
12041211
if context.device:
12051212
abi = str(properties.ro.product.cpu.abi)
12061213
sdk = str(properties.ro.build.version.sdk)
12071214

1215+
if abi is None:
1216+
log.error("Unknown CPU ABI")
1217+
12081218
project = _generate_ndk_project(source, abi, sdk)
12091219

12101220
# Remove any output files

pwnlib/context/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ def device(self, device):
11271127
self.os = device.os or self.os
11281128
elif isinstance(device, str):
11291129
device = Device(device)
1130-
else:
1130+
elif device is not None:
11311131
raise AttributeError("device must be either a Device object or a serial number as a string")
11321132

11331133
return device

0 commit comments

Comments
 (0)