Skip to content

Commit

Permalink
Migration 5 + bugfixes
Browse files Browse the repository at this point in the history
Added: permissions, sysservicedb
  • Loading branch information
jakev committed Nov 10, 2015
1 parent c9a2275 commit 846377e
Show file tree
Hide file tree
Showing 5 changed files with 872 additions and 669 deletions.
2 changes: 1 addition & 1 deletion modules/classsearch
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class classsearch(Module):

if class_name is None and method_name is None:
log.e(TAG, "You need to specify a class_name to search for!")
exit(2)
return -2

db_dir = prop.get_prop("Local", "db-dir")

Expand Down
181 changes: 101 additions & 80 deletions modules/frameworkdb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@ class frameworkdb(Module):
# End XZ Compression

# Zip Stuff
@classmethod
def file_in_zip(cls, zip_file, file_name):

"""Determine if file in ZIP"""

cmd = ("unzip -t %s %s" % (zip_file, file_name)).split(' ')

p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=False)
p.wait()

if p.returncode == 0:
return True
else:
return False

@classmethod
def extract_from_zip_to(cls, zip_file, extract_path, file_name=None):

Expand All @@ -188,119 +203,125 @@ class frameworkdb(Module):
# End Zip Stuff

# Unpack related
def do_unpack(self, local_db):

"""Perform the unpack"""

frameworks_dir = prop.get_prop("Local", "framework-dir")
sdk = prop.get_prop("Info", "sdk")
fwdb = FrameworkDb.FrameworkDb(local_db)

for framework in fwdb.getFrameworks():

log.i(TAG, "Unframeworking '%s'..." % framework)
def do_unpack_fw(self, fwdb, framework, sdk, frameworks_dir):

framework_jar = "%s/%s.jar" % (frameworks_dir, framework)
framework_odex = "%s/%s.odex" % (frameworks_dir, framework)
"""Do actual unpack"""
framework_jar = "%s/%s.jar" % (frameworks_dir, framework)
framework_odex = "%s/%s.odex" % (frameworks_dir, framework)

out_dir = "%s/%s" % (UNFRAMEWORKS_DIR, framework)
out_framework_dex = "%s/classes.dex" % out_dir
out_framework_meta = "%s/META-INF" % out_dir
out_dir = "%s/%s" % (UNFRAMEWORKS_DIR, framework)
out_framework_dex = "%s/classes.dex" % out_dir
out_framework_meta = "%s/META-INF" % out_dir

# There should be a JAR, but there might not be.
if isfile(framework_jar):
# There should be a JAR, but might not be
if isfile(framework_jar):

log.d(TAG, "Doing JAR mode")
log.d(TAG, "Trying JAR mode")
# There is a JAR, but is there a 'classs.dex' inside?
if self.file_in_zip(framework_jar, 'classes.dex'):

# There is a JAR, so unzip first.
log.d(TAG, "classes.dex found, trying to unpack")
# Unzip the classes.dex
if self.extract_from_zip_to(framework_jar, out_dir) != 0:
log.e(TAG, "Unable to extact ZIP '%s'" % framework_jar)

# Mark Failed
if self.reporting:
self.report.add_failed(framework)
continue

# Now, check for ODEX, and handle that.
if isfile(framework_odex):

log.d(TAG, "Found ODEX files for this framework")
out, err, rtn = baksmali("-a %s -x -o %s -d %s %s" %
(sdk, out_dir, frameworks_dir, framework_odex))

# Unzip success, do unpack!
else:
log.d(TAG, "Unpacking DEX framework")
out, err, rtn = baksmali("-a %s -o %s %s"
% (sdk, out_dir,
out_framework_dex))
# Error
if rtn != 0:
log.e(TAG, "Error unpacking framework ODEX (%d)" % rtn)
log.e(TAG, "Error unpacking framework DEX (%d)" % rtn)

# Mark Failed
# Mark failure
if self.reporting:
self.report.add_failed(framework)
continue

# Mark complete and add to report.
fwdb.markUnpacked(framework)
if self.reporting:
self.report.add_completed(framework)

# Cleanup
rmtree(out_framework_meta, ignore_errors=True)

# No ODEX, use classes.dex.
elif isfile(out_framework_dex):
# Success!
else:
fwdb.markUnpacked(framework)
rmtree(out_framework_meta, ignore_errors=True)
self.rmfile(out_framework_dex)
if self.reporting:
self.report.add_completed(framework)

log.d(TAG, "No ODEX, looking for classes.dex")
out, err, rtn = baksmali("-a %s -o %s %s" %
(sdk, out_dir, out_framework_dex))
# JAR, no classes.dex, ODEX?
elif isfile(framework_odex):

if rtn != 0:
log.e(TAG, "Error unpacking framework DEX (%d)" % rtn)
log.d(TAG, "Unpacking ODEX framework")
out, err, rtn = baksmali("-a %s -x -o %s -d %s %s" %
(sdk, out_dir, frameworks_dir, framework_odex))

# Mark Failed
if self.reporting:
self.report.add_failed(framework)
continue
# Mark failure
if rtn != 0:
log.e(TAG, "Error unpacking framework ODEX (%d)" % rtn)

# Mark complete and add to report.
# Mark Failed
if self.reporting:
self.report.add_failed(framework)
# Success!
else:
fwdb.markUnpacked(framework)
rmtree(out_framework_meta, ignore_errors=True)
if self.reporting:
self.report.add_completed(framework)

# Cleanup
self.rmfile(out_framework_dex)
rmtree(out_framework_meta, ignore_errors=True)

# No classes.dex or ODEX?
else:
log.w(TAG, "No ODEX or classes.dex found?")
continue
# None of the above, another error/continue
else:
# Without a JAR, we're forced to just use the ODEX.
if not isfile(framework_odex):
log.e(TAG, "No JAR or ODEX, how is this even possible?")
log.w(TAG, "No ODEX or classes.dex in JAR!")

# Mark Failed
if self.reporting:
self.report.add_failed(framework)
continue
# Mark Failed
fwdb.markUnpacked(framework)
if self.reporting:
self.report.add_completed(framework)

log.d(TAG, "Found ODEX files for this framework")
out, err, rtn = baksmali("-a %s -x -o %s -d %s %s" %
(sdk, out_dir, frameworks_dir, framework_odex))
# Ok, no JAR. How about an ODEX?
elif isfile(framework_odex):

if rtn != 0:
log.e(TAG, "Error unpacking framework (%d)" % rtn)
log.d(TAG, "Unpacking ODEX framework")
out, err, rtn = baksmali("-a %s -x -o %s -d %s %s" %
(sdk, out_dir, frameworks_dir, framework_odex))

# Mark Failed
if self.reporting:
self.report.add_failed(framework)
continue
# Mark failure
if rtn != 0:
log.e(TAG, "Error unpacking framework ODEX (%d)" % rtn)

# Mark complete and add to report.
# Mark Failed
if self.reporting:
self.report.add_failed(framework)
# Success!
else:
fwdb.markUnpacked(framework)
rmtree(out_framework_meta, ignore_errors=True)
if self.reporting:
self.report.add_completed(framework)

# Cleanup$
rmtree(out_framework_meta, ignore_errors=True)
# Neither
else:
log.e(TAG, "No JAR or ODEX!")

# Mark Failed
if self.reporting:
self.report.add_failed(framework)

return 0

def do_unpack(self, local_db):

"""Perform the unpack"""

frameworks_dir = prop.get_prop("Local", "framework-dir")
sdk = prop.get_prop("Info", "sdk")
fwdb = FrameworkDb.FrameworkDb(local_db)

for framework in fwdb.getFrameworks():

log.i(TAG, "Unframeworking '%s'..." % framework)
self.do_unpack_fw(fwdb, framework, sdk, frameworks_dir)

# If reporting is enabled, show it.
if self.reporting:
Expand Down
27 changes: 20 additions & 7 deletions modules/frameworkdexdb
Original file line number Diff line number Diff line change
Expand Up @@ -207,20 +207,33 @@ class frameworkdexdb(Module):
jar_name = "%s/%s.jar" % (self.frameworks_dir, base_name)
out_name = "%s/%s.db" % (self.frameworkdexdbs_dir, base_name)

# ART-runtime
if vm_type[:3] == "ART":
# Need to handle the ELF BS.
if os.path.isfile(odex_name):
log.d(TAG, "ART ODEX mode selected.")
rtn |= self.process_framework(odex_name, out_name)
rtn = self.process_framework(odex_name, out_name)
else:
log.w(TAG, "No ODEX file found for package '%s'"
% base_name)
elif os.path.isfile(odex_name):
log.d(TAG, "ODEX mode selected.")
rtn |= self.process_framework(odex_name, out_name)
% base_name)
# Dalvik run-time
else:
log.d(TAG, "JAR mode selected.")
rtn |= self.process_framework(jar_name, out_name)
# First try the JAR
if os.path.isfile(jar_name):

log.d(TAG, "Trying JAR first...")
rtn = self.process_framework(jar_name, out_name)
if rtn != 0:
# Well, might as well try ODEX.
if os.path.isfile(odex_name):
log.d(TAG, "Failing to ODEX mode")
rtn = self.process_framework(odex_name, out_name)
# No JAR, go for the ODEX
elif os.path.isfile(odex_name):
log.d(TAG, "ODEX mode selected.")
rtn = self.process_framework(odex_name, out_name)
else:
log.e(TAG, "JAR nor ODEX exists!")

return rtn

Expand Down
Loading

0 comments on commit 846377e

Please sign in to comment.