Skip to content

Commit

Permalink
Many bug fixes and improvements
Browse files Browse the repository at this point in the history
modules/sysappdb
    added `list` function
    fixed issue with "debuggable"
    added "allow_backup" to schema
    fixed quoting issues for shell commands
    moved helpers to Utils

modules/frameworkdb
    fixed quoting issues for shell commands
    moved helpers to Utils

modules/frameworkdexdb
    fixed quoting issues for shell commands
    moved helpers to Utils

modules/fixresources
    fixed copyright

modules/generateaidl
    fixed quoting issues for shell commands
    fixed failover to ODEX

library/Utils
    initial commit

libraries/AppDb
    added "allw_backup" schema change
  • Loading branch information
jakev committed Feb 24, 2016
1 parent 66d55a1 commit bc7df81
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 199 deletions.
61 changes: 43 additions & 18 deletions libraries/AppDb/AppDb.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ class Application(object):
successfully_unpacked = None
shared_user_id = ''
shared_user_label = ''
allow_backup = None

def __init__(self, package_name, project_name, decoded_path, has_native,
min_sdk_version, target_sdk_version, version_name,
version_code, permission, debuggable, shared_user_id,
shared_user_label, id=None):
shared_user_label, allow_backup, id=None):

self.project_name = project_name
self.package_name = package_name
Expand All @@ -107,6 +108,13 @@ def __init__(self, package_name, project_name, decoded_path, has_native,
elif debuggable == False:
self.debuggable = 0

if allow_backup == None:
self.allow_backup = None
elif allow_backup == True:
self.allow_backup = 1
elif allow_backup == False:
self.allow_backup = 0

self.min_sdk_version = min_sdk_version
self.target_sdk_version = target_sdk_version
self.version_name = version_name
Expand All @@ -131,6 +139,23 @@ def getDebuggable(self):
elif self.debuggable == 1:
return True

def setAllowBackup(self, value):

"""Set allow_backup value"""

self.allow_backup = value

def getAllowBackup(self):

"""Check if app allows backup"""

if self.allow_backup == None:
return None
elif self.allow_backup == 0:
return False
elif self.allow_backup == 1:
return True

# Component Object Classes
class PermissionGroup(object):

Expand Down Expand Up @@ -513,7 +538,8 @@ def createAppsTable(self):
'successfully_pulled INTEGER DEFAULT 0, '
'successfully_unpacked INTEGER DEFAULT 0, '
'shared_user_id TEXT, '
'shared_user_label TEXT)')
'shared_user_label TEXT, '
'allow_backup INTEGER)')

return self.app_db.execute(sql)

Expand Down Expand Up @@ -1142,7 +1168,7 @@ def getApps(self, dont_resolve=False):
'decoded_path, has_native, min_sdk_version, '
'target_sdk_version, version_name, version_code, '
'permission, debuggable, successfully_unpacked, '
'shared_user_id, shared_user_label '
'shared_user_id, shared_user_label, allow_backup '
'FROM apps '
'ORDER BY id')

Expand All @@ -1162,6 +1188,7 @@ def getApps(self, dont_resolve=False):
successfully_unpacked = line[11]
shared_user_id = line[12]
shared_user_label = line[13]
allow_backup = line[14]

if not dont_resolve:
if permission_id != 0 and permission_id is not None:
Expand All @@ -1176,6 +1203,7 @@ def getApps(self, dont_resolve=False):
has_native, min_sdk_version, target_sdk_version,
version_name, version_code, permission,
debuggable, shared_user_id, shared_user_label,
allow_backup,
id=id))
return app_list

Expand Down Expand Up @@ -1208,7 +1236,7 @@ def getFailedToUnpackApps(self):
'decoded_path, has_native, min_sdk_version, '
'target_sdk_version, version_name, version_code, '
'permission, debuggable, successfully_unpacked, '
'shared_user_id, shared_user_label '
'shared_user_id, shared_user_label, allow_backup '
'FROM apps '
'WHERE successfully_unpacked=0 '
'ORDER BY id')
Expand All @@ -1229,6 +1257,7 @@ def getFailedToUnpackApps(self):
successfully_unpacked = line[11]
shared_user_id = line[12]
shared_user_label = line[13]
allow_backup = line[14]

permission = None

Expand All @@ -1237,7 +1266,7 @@ def getFailedToUnpackApps(self):
has_native, min_sdk_version, target_sdk_version,
version_name, version_code, permission,
debuggable, shared_user_id, shared_user_label,
id=id))
allow_backup, id=id))
return app_list


Expand All @@ -1247,7 +1276,7 @@ def getAppById(self, application_id):
'decoded_path, has_native, min_sdk_version, '
'target_sdk_version, version_name, version_code, '
'permission, debuggable, successfully_unpacked, '
'shared_user_id, shared_user_label '
'shared_user_id, shared_user_label, allow_backup '
'FROM apps '
"WHERE id=%d "
'ORDER BY id '
Expand All @@ -1265,7 +1294,7 @@ def getAppById(self, application_id):
(id, package_name, project_name, decoded_path, has_native,
min_sdk_version, target_sdk_version, version_name, version_code,
permission_id, debuggable, successfully_unpacked, shared_user_id,
shared_user_label) = fetched
shared_user_label, allow_backup) = fetched

if permission_id != 0 and permission_id is not None:
permission = self.resolvePermissionById(permission_id)
Expand All @@ -1276,7 +1305,7 @@ def getAppById(self, application_id):
has_native, min_sdk_version, target_sdk_version,
version_name, version_code, permission,
debuggable, shared_user_id, shared_user_label,
id=id)
allow_backup, id=id)
except TypeError:
log.e(_TAG, "Unable to resolve application ID %d!" % id)
return 0
Expand All @@ -1287,7 +1316,7 @@ def getAppByName(self, name):
'decoded_path, has_native, min_sdk_version, '
'target_sdk_version, version_name, version_code, '
'permission, debuggable, successfully_unpacked, '
'shared_user_id, shared_user_label '
'shared_user_id, shared_user_label, allow_backup '
'FROM apps '
"WHERE project_name='%s' "
'ORDER BY id '
Expand All @@ -1305,7 +1334,7 @@ def getAppByName(self, name):
(id, package_name, project_name, decoded_path, has_native,
min_sdk_version, target_sdk_version, version_name, version_code,
permission_id, debuggable, successfully_unpacked, shared_user_id,
shared_user_label) = fetched
shared_user_label, allow_backup) = fetched

if permission_id != 0 and permission_id is not None:
permission = self.resolvePermissionById(permission_id)
Expand All @@ -1316,7 +1345,7 @@ def getAppByName(self, name):
has_native, min_sdk_version, target_sdk_version,
version_name, version_code, permission,
debuggable, shared_user_id, shared_user_label,
id=id)
allow_backup, id=id)
except TypeError:
log.e(_TAG, "Unable to resolve application ID %d!" % id)
return 0
Expand Down Expand Up @@ -1397,7 +1426,6 @@ def getAppsBySharedUserId(self, shared_id_name):
def resolveGroupByName(self, permission_group_name):
c = self.app_db.cursor()

#rtn = c.execute("SELECT * FROM permission_groups WHERE name=\"%s\"" % permission_group_name)
rtn = c.execute('SELECT id, name, application_id '
'FROM permission_groups '
"WHERE name=\"%s\"" % permission_group_name)
Expand All @@ -1414,7 +1442,6 @@ def resolveGroupById(self, permission_group_id):

c = self.app_db.cursor()

#rtn = c.execute("SELECT * FROM permission_groups WHERE id=%i" % permission_group_id)
rtn = c.execute('SELECT id, name, application_id '
'FROM permission_groups '
"WHERE id=%i" % permission_group_id)
Expand All @@ -1431,7 +1458,6 @@ def resolvePermissionByName(self, permission_name):

c = self.app_db.cursor()

#rtn = c.execute("SELECT * FROM permissions WHERE name=\"%s\"" % permission_name)
rtn = c.execute('SELECT id, name, permission_group, protection_level, '
'application_id '
'FROM permissions '
Expand All @@ -1455,7 +1481,6 @@ def resolvePermissionById(self, permission_id):

c = self.app_db.cursor()

#rtn = c.execute("SELECT * FROM permissions WHERE id=%d" % permission_id)
rtn = c.execute('SELECT id, name, permission_group, protection_level, '
'application_id '
'FROM permissions '
Expand Down Expand Up @@ -1907,22 +1932,22 @@ def updateApplication(self, a):
'has_native=?, min_sdk_version=?, target_sdk_version=?, '
'version_name=?, version_code=?, debuggable=?, permission=?, '
'successfully_unpacked=?, shared_user_id=?, '
'shared_user_label=? '
'shared_user_label=?, allow_backup=? '
'WHERE id=?')

return self.app_db.execute(sql,
(a._id, a.package_name, a.project_name, a.decoded_path,
a.has_native, a.min_sdk_version, a.target_sdk_version,
a.version_name, a.version_code, a.debuggable,
permission_id, a.successfully_unpacked, a.shared_user_id,
a.shared_user_label, a._id))
a.shared_user_label, a.allow_backup, a._id))
# End class AppDb

# Helpers
def getAttrib(element, attrib, default="None"):

try:
return element.attrib['{http://schemas.android.com/apk/res/android}'+attrib]
return element.attrib['{http://schemas.android.com/apk/res/android}' + attrib]
except KeyError:
return default

Expand Down
105 changes: 105 additions & 0 deletions libraries/Utils/Utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/usr/bin/env python
# Copyright 2013-2016 Jake Valletta (@jake_valletta)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Helper methods for various functionality"""

import hashlib
import os
import shlex

from subprocess import Popen, PIPE

# MD5 Related
# Global Helpers
def md5_file(file_path):

"""MD5 a file"""

try:
file_f = open(file_path, 'rb')

my_md5 = hashlib.md5()
while True:
data = file_f.read(128)
if not data:
break
my_md5.update(data)
return my_md5.hexdigest()

except IOError:
return None

# XZ Related
def test_xz():

"""Confirm that xz is installed"""

lexed = shlex.split("command -v xz")

proc = Popen(lexed, stdout=PIPE, stderr=PIPE, shell=True)
proc.wait()

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

def decompress_xz(file_name):

"""Decompress an xz resource"""

lexed = shlex.split("xz -d \"%s\"" % file_name)

proc = Popen(lexed, stdout=PIPE, stderr=PIPE, shell=False)
proc.wait()

return proc.returncode
# End XZ Related

# ZIP Related
def extract_from_zip_to(zip_file, extract_path, file_name=None):

"""Extract a file from a ZIP"""

null_f = open(os.devnull, 'w')

if file_name is None:
lexed = shlex.split("unzip -u \"%s\" -d \"%s\""
% (zip_file, extract_path))
else:
lexed = shlex.split("unzip -u \"%s\" \"%s\" -d \"%s\""
% (zip_file, file_name, extract_path))

proc = Popen(lexed, stdout=null_f, stderr=null_f, shell=False)
proc.wait()

null_f.close()

return proc.returncode

def file_in_zip(zip_file, file_name):

"""Determine if file in ZIP"""

lexed = shlex.split("unzip -t \"%s\" \"%s\"" % (zip_file, file_name))

proc = Popen(lexed, stdout=PIPE, stderr=PIPE, shell=False)
proc.wait()

if proc.returncode == 0:
return True
else:
return False
# End ZIP Related
9 changes: 9 additions & 0 deletions manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,15 @@
author="Jake Valletta (jakev)"
localName="libraries/UserDb" />

<Item type="library"
name="Utils"
about="Helper methods"
majorVersion="1"
minorVersion="0"
health="stable"
author="Jake Valletta (jakev)"
localName="libraries/Utils" />

<!-- Binary Content -->
<Item type="binary"
name="dexdiff.py"
Expand Down
2 changes: 1 addition & 1 deletion modules/fixresources
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

# DTF Core Content
# Copyright 2013-201x65 Jake Valletta (@jake_valletta)
# Copyright 2013-2016 Jake Valletta (@jake_valletta)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit bc7df81

Please sign in to comment.