import os
def getName(AAPTLocation, apkFile):
AAPTLocation = AAPTLocation.replace('\\','\\\\')
apkFile = apkFile.replace('\\','\\\\')
pname = ''
cmd = ' \"\"' + AAPTLocation + '\" dump badging \"' + apkFile + '\"\"'
p = os.popen(cmd)
while 1:
s = p.readline()
if s:
print s
if s.find('package') != -1 and s.find('name') != -1:
pname = s
if not s:
break
p.close()
return pname
AAPTLocation = 'C:\Program Files\Android\android-sdk\platform-tools\aapt.exe'
apkFile = 'C:\APKs\test.apk'
print getName(AAPTLocation, apkFile)
I need to run aapt.exe, get the package name of the apk and parse the result.
Running “C:\Program Files\Android\android-sdk\platform-tools\aapt.exe” dump badging “C:\APKs\test.apk” directly in the commandline interface is working fine. However in the python script I pasted above it doesn’t give me anything.
I already tried escaping the backslash but it doesn’t make a difference at all. Is there something wrong with my code?.
You need to double the slashes in the python literal, they are being interpreted as the start of an escape code otherwise:
Notice how in the first example (from your code) python has interpreted the
\aentries as a hex 07 character instead, the ASCII code for BELL.The alterative is to use a raw python string literal, by prefixing it with the letter
r:See the string literals documentation for more info on how string escapes work in string literals.