Advertisement
drculun

bninja_loader.py

Jan 23rd, 2025
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. from binaryninja import *
  2. from json import load
  3.  
  4. view : BinaryView = bv
  5.  
  6. jsonPath = interaction.get_open_filename_input("dump json file", "*.json")
  7. if not jsonPath:
  8.     exit(0)
  9.  
  10. dump = {}
  11. with open(jsonPath, "r") as f:
  12.     dump = load(f)
  13.  
  14. base = view.start
  15.  
  16. def loadSymbols(s:dict[str, dict], symType: SymbolType):
  17.     if not isinstance(s, dict):
  18.         return
  19.     for name in s:
  20.         setSymbol(name, s[name], symType)
  21.  
  22. def setSymbol(name: str, offObj, symType: SymbolType):
  23.     offset = offObj["offset"]
  24.     if (len(view.get_symbols_by_name(name)) != 0):
  25.         return
  26.     print("defined: ", name)
  27.     view.define_auto_symbol(
  28.         Symbol(symType, base + offset, name)
  29.     )
  30.  
  31. loadSymbols(dump["subs"], SymbolType.FunctionSymbol)
  32. loadSymbols(dump["offsets"], SymbolType.DataSymbol)
  33.  
  34. refsCount = 0
  35. for ref in dump["refs"]:
  36.     if not isinstance(ref, list) or len(ref) != 2:
  37.         continue
  38.     view.add_user_data_ref(
  39.         base + ref[0],
  40.         base + ref[1]
  41.     )
  42.     refsCount+=1
  43. print(f"Added {refsCount} references")
  44.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement