Skip to content

Commit

Permalink
Merge slices into given path
Browse files Browse the repository at this point in the history
  • Loading branch information
alterakey committed Sep 17, 2024
1 parent 603ac57 commit e6523fb
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions trueseeing/app/cmd/android/asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_commands(self) -> CommandMap:
'cd!':dict(e=self._disassemble, t={'apk'}),
'cds':dict(e=self._disassemble_nodex, t={'apk'}),
'cds!':dict(e=self._disassemble_nodex, t={'apk'}),
'cm':dict(e=self._merge, n='cm[!]', d='merge slices', t={'xapk'}),
'cm':dict(e=self._merge, n='cm[!] [output.apk]', d='merge slices into a plain apk', t={'xapk'}),
'cm!':dict(e=self._merge, t={'xapk'}),
'co':dict(e=self._export_context, n='co[!] /path [pat]', d='export codebase', t={'apk'}),
'co!':dict(e=self._export_context, t={'apk'}),
Expand Down Expand Up @@ -254,22 +254,26 @@ async def _merge(self, args: deque[str]) -> None:
from trueseeing.core.android.asm import APKAssembler
from trueseeing.core.android.tools import move_apk

apk = target.replace('.xapk', '.apk')
origapk = apk.replace('.apk', '.apk.orig')
if args:
outfn = args.popleft()
else:
outfn = target.replace('.xapk', '.apk')

origfn = outfn.replace('.apk', '.apk.orig')

if os.path.exists(origapk) and not cmd.endswith('!'):
if os.path.exists(origfn) and not cmd.endswith('!'):
ui.fatal('backup file exists; force (!) to overwrite')

ui.info('merging slices {target} -> {apk}'.format(target=target, apk=apk))
ui.info('merging slices {target} -> {outfn}'.format(target=target, outfn=outfn))

at = time.time()

with TemporaryDirectory() as td:
outapk, outsig = await APKAssembler.merge_slices(target, td)
apk, sig = await APKAssembler.merge_slices(target, td)

if os.path.exists(apk):
move_apk(apk, origapk)
if os.path.exists(outfn):
move_apk(outfn, origfn)

move_apk(outapk, apk)
move_apk(apk, outfn)

ui.success('done ({t:.02f} sec.)'.format(t=(time.time() - at)))

0 comments on commit e6523fb

Please sign in to comment.