Skip to content

Instantly share code, notes, and snippets.

@dwisiswant0
Created December 11, 2018 06:01
Show Gist options
  • Save dwisiswant0/0bbb02428f5beb99248829ab2956b521 to your computer and use it in GitHub Desktop.
Save dwisiswant0/0bbb02428f5beb99248829ab2956b521 to your computer and use it in GitHub Desktop.
Strings Extractor for APK
# -*- coding: utf_8 -*-
# sudo pip install androguard django
import io
import os
import subprocess
import sys
from androguard.core.bytecodes import apk
from django.conf import settings
def strings_jar(app_file, app_dir):
"""
Extract the strings from an app.
from https://github.com/MobSF/Mobile-Security-Framework-MobSF/blob/master/StaticAnalyzer/views/android/strings.py
"""
try:
print("\x1b[0;35;40m[INFO] Extracting Strings from APK\x1b[0m")
dat = []
apk_file = os.path.join(app_dir, app_file)
and_a = apk.APK(apk_file)
rsrc = and_a.get_android_resources()
pkg = rsrc.get_packages_names()[0]
rsrc.get_strings_resources()
for i in rsrc.values[pkg].keys():
string = rsrc.values[pkg][i].get('string')
if string is None:
return dat
for duo in string:
dat.append('"'+duo[0]+'" : "'+duo[1]+'"')
return dat
except:
sys.exit("\x1b[0;31;40m[ERROR] Extracting Strings from APK\x1b[0m")
def main():
app_dir = raw_input("Enter a application path: ")
if os.path.isdir(app_dir) is True:
app_file = raw_input("Enter a application file: ")
if os.path.exists(app_dir + "/" + app_file) is True:
print("-----------------------------")
out = "\n".join(strings_jar(app_file, app_dir))
print(out)
res = io.open(app_file + "-strings.txt", "w", encoding="utf8")
res.write(out)
else:
sys.exit("\x1b[0;31;40m[ERROR] Application file not found\x1b[0m")
else:
sys.exit("\x1b[0;31;40m[ERROR] Application path doesn't exists\x1b[0m")
if __name__== "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment