SoFunction
Updated on 2024-11-13

Question about using python to decompile apk signature out of package

demo implementation script download

mounting tool

needpython3,,apktool

1. Decompile with apktool

cmd = 'apktool d -f '+apkPath+' -o '+outPath

2. Modify the values of the parameters to be configured

Note: If yes, note that you must set namespace before parse, otherwise you will get an ns0:name error instead of the expected android:name, the way to set namespace ET.register_namespace('android', "/apk/res/android")

curPath = (apktoolPath+'/ihdrm202103161405apk/')
 tree = (curPath + '')  # Open xml
 root = () #Find the root manifest file
 print()    #We know that the root directory is the manifest directory when we export it.
 print()   # Output the members of the root directory
 # Get the package
 versionName = ('package')
 #Modify
 ('package', '')
 # Get the application directory
 application = ('application')
 # Iterate over all meta-data
 for item in ('meta-data'):
  name = (SPACE +'name')
  value = (SPACE +'value')

3. Modify the application name

def appnamechang():
 print('-------- modify application name to complete --------')
 tree = read_xml(in_path)
 text_nodes = get_node_by_keyvalue(find_nodes(tree, "string"), {"name": "app_name"})
 change_node_text(text_nodes, "The Legend of Domination.")
# write_xml(tree, ". /strings absolute path.xml")
 write_xml(tree,apktoolPath+"/ihdrm202103161405apk/res/values/")

4. Modify the icon icon

source_path = (apktoolPath+'/icon')
target_path = (apktoolPath+'/ihdrm202103161405apk/res')
def copy_search_file():
 print('-------- modified icon successfully --------')
 '''Copy and overwrite all files and directories from one directory to another.'''
 # source_path source directory
 # target_path target directory
 if not ((source_path) and (target_path)):
  return
 for a in (source_path):
# # Create a directory
  for d in a[1]:
   dir_path = (a[0].replace(source_path,target_path),d)
   if not (dir_path):
    (dir_path)
  #Copy the file
  for p in a[2]:
   dep_path = (a[0],p)
   arr_path = (a[0].replace(source_path,target_path),p)
   (dep_path,arr_path)

5. Remove signatures and compile back

cmd = 'apktool b -f '+outPath

6. Create a certificate

def createzu():
 cmd = 'keytool -genkey -alias  -keyalg RSA -validity 20000 -keystore '
 print('-------- create certificate --------')
 (cmd)

to this article on the use of python decompile apk signature out of the package is introduced to this article, more related python decompile apk content please search for my previous articles or continue to browse the following related articles I hope that you will support me more in the future!