def getProtectedBroadcastDict(fIn,fInEmu): outdict = {} emuDict={} f = open(fIn, 'r') fEmu = open(fInEmu, 'r') while True: line=fEmu.readline() if not line: break if line.find('.xml:') > -1: #idx1 = line.find('/') + 1 #idx2 = line.find(':') #key = line[idx1:idx2] key = P.getAttrValueByAttrTitle('android:name', line) if not emuDict.has_key(key): emuDict[key] = 'YES' while True: line = f.readline() if not line: break if line.find('.xml:') > -1: #idx1 = line.find('/') + 1 #idx2 = line.find(':') #key = line[idx1:idx2] key = P.getAttrValueByAttrTitle('android:name', line) if not outdict.has_key(key): outdict[key]='NO' if emuDict.has_key(key): outdict[key] = emuDict[key] return outdict
def generateProtectionLevelToProtectionLevelDict(): protectionLevelDict = {} f = open(protectionLevelTxt, 'r') while True: line = f.readline() if not line: break if line.find('android:protectionLevel') > -1: value = P.getAttrValueByAttrTitle('android:protectionLevel', line) key = P.getAttrValueByAttrTitle('android:name', line) protectionLevelDict[key] = value #print protectionLevelDict return protectionLevelDict
def genPkgPermissionProtectionLevelDict(fIn): outdict = {} f = open(fIn, 'r') while True: line = f.readline() if not line: break if line.find('.xml:') > -1: idx1 = line.find('/') + 1 idx2 = line.find(':') key = line[idx1:idx2] permissionName = P.getAttrValueByAttrTitle('android:name', line) protectionLevel = P.getAttrValueByAttrTitle('android:protectionLevel', line) if not protectionLevel: protectionLevel = 'Not Found' if not outdict.has_key(key): outdict[key] = {} outdict[key][permissionName] = protectionLevel return outdict
def genPkgAndPermssionDict(fIn): outdict = {} f = open(fIn, 'r') while True: line = f.readline() if not line: break if line.find('.xml:') > -1: idx1 = line.find('/') + 1 idx2 = line.find(':') key = line[idx1:idx2] value = P.getAttrValueByAttrTitle('android:name', line) if not outdict.has_key(key): outdict[key] = [] outdict[key].append(value) return outdict
def genBundledPkgInfo(pkgPermissionDict, pkgUsesPermissionDict, pkgSourceDict, pkgProtectionLevelDict): outList = [] #print pkgSourceDict #print P.protectionLevelDict #print P.pathDict #print pkgPermissionDict #print pkgUsesPermissionDict #print pkgProtectionLevelDict #pkgPermissionDict = sorted(pkgPermissionDict.items(), key=lambda e:e[0], reverse=False) for root,dirs,files in os.walk(P.ManifestListPath): for filespath in files: jrdfilepath = os.path.join(root,filespath) pkg = Package() manifestStr = P.getNodeByTag('manifest', jrdfilepath) name = P.getAttrValueByAttrTitle('package', manifestStr) shareUserId = P.getAttrValueByAttrTitle('android:sharedUserId', manifestStr).strip(' ') pkg.name = name if shareUserId == '': pkg.packageUID = 'system assigned' else: pkg.packageUID = shareUserId if P.pathDict.has_key(name): tmpStr = P.pathDict[name] idx = tmpStr.rfind('/') pkg.location = tmpStr[:idx] pkg.apkname = tmpStr[idx+1:] if pkgSourceDict.has_key(name): pkg.source = pkgSourceDict[name] if pkgPermissionDict.has_key(filespath): for per in pkgPermissionDict[filespath]: permission = Permission() permission.name = per if pkgProtectionLevelDict[filespath].has_key(per): permission.protectionLevel = checkProtectionLevelValue(pkgProtectionLevelDict[filespath][per]) else: permission.protectionLevel = 'Not Found' pkg.permission.append(permission) if pkgUsesPermissionDict.has_key(filespath): for per in pkgUsesPermissionDict[filespath]: permission = Permission() permission.name = per tmpProtectionLevel = '' if pkgProtectionLevelDict.has_key(filespath): if pkgProtectionLevelDict[filespath].has_key(per): #permission.protectionLevel = checkProtectionLevelValue() tmpProtectionLevel = pkgProtectionLevelDict[filespath][per] elif P.protectionLevelDict.has_key(per): #permission.protectionLevel = checkProtectionLevelValue(P.protectionLevelDict[per]) tmpProtectionLevel = P.protectionLevelDict[per] #print '@@@ ' + tmpProtectionLevel else: tmpProtectionLevel = 'Not Found' elif P.protectionLevelDict.has_key(per): #permission.protectionLevel = checkProtectionLevelValue(P.protectionLevelDict[per]) tmpProtectionLevel = P.protectionLevelDict[per] #print '@@@ ' + tmpProtectionLevel else: tmpProtectionLevel = 'Not Found' permission.protectionLevel = checkProtectionLevelValue(tmpProtectionLevel) pkg.usesPermission.append(permission) outList.append(pkg) return outList
def genBundledPkgInfo(pkgPermissionDict, pkgUsesPermissionDict, pkgSourceDict, pkgProtectionLevelDict): outList = [] #print pkgSourceDict #print P.protectionLevelDict #print P.pathDict #print pkgPermissionDict #print pkgUsesPermissionDict #print pkgProtectionLevelDict #pkgPermissionDict = sorted(pkgPermissionDict.items(), key=lambda e:e[0], reverse=False) for root,dirs,files in os.walk(P.ManifestListPath): for filespath in files: jrdfilepath = os.path.join(root,filespath) apkNameFromFileName=filespath[:filespath.find('.',filespath.find('.')+1)] #print apkNameFromFileName pkg = Package() manifestStr = P.getNodeByTag('manifest', jrdfilepath) if P.renamePkgDict.has_key(apkNameFromFileName): name=P.renamePkgDict[apkNameFromFileName] else: name=P.getAttrValueByAttrTitle('package', manifestStr) #name = P.renamePkgDict.has_key(apkNameFromFileName)?P.renamePkgDict[apkNameFromFileName]:P.getAttrValueByAttrTitle('package', manifestStr) shareUserId = P.getAttrValueByAttrTitle('android:sharedUserId', manifestStr).strip(' ') pkg.name = name splitedName='' if shareUserId == '': pkg.packageUID = 'system assigned' else: pkg.packageUID = shareUserId if P.pathDict.has_key(name): tmpStr = P.pathDict[name] idx = tmpStr.rfind('/') pkg.location = tmpStr[:idx] pkg.apkname = tmpStr[idx+1:] else: #modify for googleDrive.apk and soft link. print "BundledPackages error:"+name+" not found,retry once after split the package name." splitedName=name[:name.rfind('.')] if P.pathDict.has_key(splitedName): tmpStr = P.pathDict[splitedName] idx = tmpStr.rfind('/') pkg.location = tmpStr[:idx] pkg.apkname = tmpStr[idx+1:] pkg.name=splitedName print "BundledPackages info:"+name+" has been repaired->"+splitedName else: print "BundledPackages fatal error:"+name+" still not found,skip." continue if pkgSourceDict.has_key(name): pkg.source = pkgSourceDict[name] else: if pkgSourceDict.has_key(splitedName): pkg.source=pkgSourceDict[splitedName] if pkgPermissionDict.has_key(filespath): for per in pkgPermissionDict[filespath]: permission = Permission() permission.name = per if pkgProtectionLevelDict[filespath].has_key(per): permission.protectionLevel = checkProtectionLevelValue(pkgProtectionLevelDict[filespath][per]) else: permission.protectionLevel = 'Not Found' pkg.permission.append(permission) if pkgUsesPermissionDict.has_key(filespath): for per in pkgUsesPermissionDict[filespath]: permission = Permission() permission.name = per tmpProtectionLevel = '' if pkgProtectionLevelDict.has_key(filespath): if pkgProtectionLevelDict[filespath].has_key(per): #permission.protectionLevel = checkProtectionLevelValue() tmpProtectionLevel = pkgProtectionLevelDict[filespath][per] elif P.protectionLevelDict.has_key(per): #permission.protectionLevel = checkProtectionLevelValue(P.protectionLevelDict[per]) tmpProtectionLevel = P.protectionLevelDict[per] #print '@@@ ' + tmpProtectionLevel else: tmpProtectionLevel = 'Not Found' elif P.protectionLevelDict.has_key(per): #permission.protectionLevel = checkProtectionLevelValue(P.protectionLevelDict[per]) tmpProtectionLevel = P.protectionLevelDict[per] #print '@@@ ' + tmpProtectionLevel else: tmpProtectionLevel = 'Not Found' permission.protectionLevel = checkProtectionLevelValue(tmpProtectionLevel) pkg.usesPermission.append(permission) outList.append(pkg) return outList