Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions dcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
NDKBUILD = 'ndk-build'
LIBNATIVECODE = 'libnc.so'

show_logging(level=logging.INFO)
logger = logging.getLogger('dcc')

tempfiles = []
Expand Down Expand Up @@ -87,14 +88,17 @@ def build_project(project_dir, num_processes=0):
subprocess.check_call([NDKBUILD, '-j%d' % cpu_count(), '-C', project_dir])


def auto_vm(filename):
def auto_vms(filename):
ret = androconf.is_android(filename)
if ret == 'APK':
return dvm.DalvikVMFormat(apk.APK(filename).get_dex())
vms = []
for dex in apk.APK(filename).get_all_dex():
vms.append(dvm.DalvikVMFormat(dex))
return vms
elif ret == 'DEX':
return dvm.DalvikVMFormat(read(filename))
return [dvm.DalvikVMFormat(read(filename))]
elif ret == 'DEY':
return dvm.DalvikOdexVMFormat(read(filename))
return [dvm.DalvikOdexVMFormat(read(filename))]
raise Exception("unsupported file %s" % filename)


Expand Down Expand Up @@ -339,21 +343,17 @@ def archive_compiled_code(project_dir):
outfile = shutil.make_archive(outfile, 'zip', project_dir)
return outfile

def compile_dex(apkfile, filtercfg, dynamic_register):
show_logging(level=logging.INFO)

d = auto_vm(apkfile)
dx = analysis.Analysis(d)

method_filter = MethodFilter(filtercfg, d)

compiler = Dex2C(d, dx, dynamic_register)
def compile_dex(vm, filtercfg, dynamic_register):
vmx = analysis.Analysis(vm)
method_filter = MethodFilter(filtercfg, vm)
compiler = Dex2C(vm, vmx, dynamic_register)

native_method_prototype = {}
compiled_method_code = {}
errors = []

for m in d.get_methods():
for m in vm.get_methods():
method_triple = get_method_triple(m)

jni_longname = JniLongName(*method_triple)
Expand All @@ -378,6 +378,21 @@ def compile_dex(apkfile, filtercfg, dynamic_register):

return compiled_method_code, native_method_prototype, errors

def compile_all_dex(apkfile, filtercfg, dynamic_register):
vms = auto_vms(apkfile)

compiled_method_code = {}
native_method_prototypes = {}
errors = []

for vm in vms:
codes, native_method_prototype, errors = compile_dex(vm, filtercfg, dynamic_register)
compiled_method_code.update(codes)
native_method_prototypes.update(native_method_prototype)
errors.extend(errors)

return compiled_method_code, native_method_prototypes, errors

def is_apk(name):
return name.endswith('.apk')

Expand Down Expand Up @@ -450,7 +465,7 @@ def dcc_main(apkfile, filtercfg, outapk, do_compile=True, project_dir=None, sour
logger.error("file %s is not exists", apkfile)
return

compiled_methods, method_prototypes, errors = compile_dex(apkfile, filtercfg, dynamic_register)
compiled_methods, method_prototypes, errors = compile_all_dex(apkfile, filtercfg, dynamic_register)

if errors:
logger.warning('================================')
Expand Down