示例#1
0
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
示例#2
0
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