Advertisement
tojik_proof_93

FindInst_V1.0

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