Advertisement
tojik_proof_93

FindInst_V1.1

Nov 14th, 2024
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.92 KB | Source Code | 0 0
  1. import r2pipe
  2. import os
  3. import re
  4. import platform
  5. import subprocess
  6. import sys
  7.  
  8. def clear_console():
  9.     os.system('cls' if platform.system() == 'Windows' else 'clear')
  10.  
  11. clear_console()
  12.  
  13. def install_and_import(package):
  14.     try:
  15.         __import__(package)
  16.     except ImportError:
  17.         print(f"'{package}' is not installed. Installing now...")
  18.         subprocess.check_call([sys.executable, "-m", "pip", "install", package])
  19.         print(f"'{package}' has been installed successfully.")
  20.     finally:
  21.         globals()[package] = __import__(package)
  22.  
  23. install_and_import('r2pipe')
  24.  
  25. wlcm_msg = """\033[38;5;208m
  26. _____ _           _   ___           _  
  27. |  ___(_)_ __   __| | |_ _|_ __  ___| |_
  28. | |_  | | '_ \ / _` |  | || '_ \/ __| __|
  29. |  _| | | | | | (_| |  | || | | \__ \ |_
  30. |_|   |_|_| |_|\__,_| |___|_| |_|___/\__|   V1.1\033[0m"""
  31.  
  32. print(wlcm_msg)
  33. print("\033[34m\n↯ Big Thanks to sir Kirlif' For pptool\033[0m")
  34. print("\033[34m➜ This Tool Is Designed By Mohamed Abozaid To Help Patching libapp.so In Obfuscated Flutter Apps.\n\033[0m")
  35.  
  36.  
  37. def get_app_so_path():
  38.     path = input("\033[93m◉ Please enter the path to libapp.so\n(or press Enter to use the default path): \033[0m").strip()
  39.     if not path:
  40.         path = "/storage/emulated/0/MT2/apks/libapp.so"
  41.         print("\033[93m\n☛ Default path selected: /storage/emulated/0/MT2/apks/libapp.so\n\033[0m")
  42.     return path
  43.  
  44. def get_string_address():
  45.     str_addr = input("\033[1;36m◉ Please enter the string address from pp.txt file: \033[0m").strip()
  46.     return str_addr
  47.    
  48. def reg_choice():
  49.     choices = '''
  50. \033[35mWhat do you want to search for (choose by number) ?
  51. [1] add x0, x22, 0x30 (specified)
  52. [2] add reg1, reg2, 0x30 (global)
  53. \033[0m'''
  54.     choice = input(choices).strip()
  55.     if choice == '1':
  56.         return r'add\s+x0,\s+x22,\s+0x30'
  57.     elif choice == '2':
  58.         return r'add\s+x\d+,\s+x\d+,\s+0x30'
  59.     else:
  60.         print('\033[91m\n⚠ Wrong Choice\033[0m')
  61.         return None
  62.  
  63. def run_pptool(app_so, str_addr):
  64.     cmd = f"pptool -cd {app_so} {str_addr}"
  65.     result = os.popen(cmd).read()
  66.     return result
  67.  
  68. def get_func_addr(ppout):
  69.     pattern = r'・\d+\s+(0x[0-9a-fA-F]+)'
  70.     return re.findall(pattern, ppout)
  71.  
  72. def analyze(r2, funcs_addrs, regex):
  73.     results = []
  74.     for addr in funcs_addrs:
  75.         try:
  76.             r2.cmd(f's {addr}')
  77.             r2.cmd('af')
  78.             instruction_srch = r2.cmd("pdr")
  79.             for line in instruction_srch.splitlines():
  80.                 if re.search(regex, line):
  81.                     instruction_addr_match = re.search(r"0x[0-9A-Fa-f]+", line)
  82.                     if instruction_addr_match:
  83.                         instruction_addr = instruction_addr_match.group().replace("0x00", "0x", 1)
  84.                         results.append((addr, instruction_addr))
  85.         except Exception as err:
  86.             print(f'\033[91m\n⚠ An error occurred during analysis: {err}\033[0m')
  87.     return results
  88.  
  89. def main():
  90.     app_so = get_app_so_path()
  91.     str_addr = get_string_address()
  92.     ppout = run_pptool(app_so, str_addr)
  93.     funcs_offsets = get_func_addr(ppout)
  94.     regex = reg_choice()
  95.  
  96.     if regex is None:
  97.         return
  98.  
  99.     if not funcs_offsets:
  100.         print("\n\033[4;91m\n⚠ No valid offsets found in pptool output.\033[4;0m")
  101.         return
  102.    
  103.     try:
  104.         r2 = r2pipe.open(app_so, flags=['-2', '-w', '-e bin.cache=true'])
  105.     except Exception as e:
  106.         print(f"\n\033[91m\n⚠ Failed to open the binary with r2pipe: {e}\033[0m")
  107.         return
  108.    
  109.     results = analyze(r2, funcs_offsets, regex)
  110.     if results:
  111.         print("\n\033[92m➩ Matching Instructions:\033[0m")
  112.         for addr, instr in results:
  113.             print(f"➢ \033[92mFunction Address:\033[0m {addr}, \033[92mInstruction:\033[0m {instr}")
  114.     else:
  115.         print("\n\033[91m⚠ No matching instructions found.\033[0m")
  116.  
  117. if __name__ == "__main__":
  118.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement