2013/11/07

find string from apk with apktool and ubuntu

#!/usr/bin/python
#find string from apk with apktool and ubuntu
import os
import glob
import sys
import subprocess

def F_FIND_KEY(lv_path):
    lv_rtn = False
    lv_key=['KeyGenerator','setSeed','SecretKeySpec','KeyPairGenerator']
    ix=0
    while ix<len(lv_key):
        lv_out = subprocess.Popen(['grep',lv_key[ix],lv_path,'-r'],stdout=subprocess.PIPE).communicate()[0]
        if len(lv_out) >0 :
            lv_rtn = True
            return lv_rtn
        #end if
        ix=ix+1
    #end while
    return lv_rtn
#end def

lv_path = '/tmp'

#print len(sys.argv)

if len(sys.argv)>=2 :
    lv_path = sys.argv[1]
    #print lv_path
#end if

lv_apk = lv_path+'/*.apk'
lv_dec = lv_path+'/apk_dec/'

lv_list  = glob.glob(lv_apk)

if os.path.exists(lv_dec)==False:
    os.mkdir(lv_dec)
#end if

ix=0
jx=0
while ix<len(lv_list):
    #print os.path.splitext(lv_list[ix])
    lv_name = os.path.splitext(os.path.basename(lv_list[ix]))[0]
    if os.path.exists(lv_dec+lv_name) == False :
        #os.mkdir(lv_dec+lv_name)
        #os.system('apktool d '+lv_list[ix]+' '+lv_dec+lv_name)
        subprocess.Popen(['apktool','d',lv_list[ix],lv_dec+lv_name],stdout=subprocess.PIPE).communicate()[0]
        #end if
    #end if
    #### grep key ####
    if F_FIND_KEY(lv_dec+lv_name) == True:
        open('result.txt','ab').write(lv_name+'\n')
        jx=jx+1
    #end if
    ix=ix+1
#end while

print 'done with ' + str(jx) + ' apks...'

0개의 덧글:

댓글 쓰기

에 가입 댓글 [Atom]

<< 홈