APKinspector / jad.py

import os
import sys
import zipfile

from startQT import SYSPATH

# delete all files and dirs in the "./temp/" dictionary
# return 0: success;
def clear():
    cmd = "rm -rf " + SYSPATH + "/temp/*"
    return os.system(cmd)



# use the dex2jar to generate the .jar file.
# Then move .jar file to the "./temp/" dictionary
# At last, unzip the .jar file to "./temp/" dictionary
# return 1: success ; return 0: fail
def dex2jar(filename):
    cmd1 = SYSPATH +"/dex2jar/dex2jar.sh " + filename
    if os.system(cmd1) !=0:
        return 0
    
    newfilename = os.path.split(filename)[-1] + ".dex2jar.jar"
    cmd2 = "mv " + os.path.dirname(filename) + "/" + newfilename + " " + SYSPATH + "/temp/"
    if os.system(cmd2) !=0:
        return 0
        
    if unzip(SYSPATH + "/temp/" + newfilename) != 0:
        return 0
    
    return 1
    


# unzip the .jar file
# return 0: success;
def unzip(filename):
    cmd = "unzip -o " + filename + " -d" + SYSPATH + "/temp/unzip"
    return os.system(cmd)



# decompile the apk to the Javacodes
# parameter:
#       filename: the full absolute path of the apk file
# return 1: success; return 0:fail
def decompile(filename):
    if clear() != 0:
        return 0
        
    if dex2jar(filename) != 1:
        return 0
    
    cmd = SYSPATH + "/jad158e.linux.static/jad -o -r -sjava -d" + SYSPATH + "/temp/java " + SYSPATH + "/temp/unzip/**/*.class"
    if os.system(cmd) != 0:
        return 0
 
    return 1



    
    
    
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.