forked from c3r34lk1ll3r/BinRida
-
Notifications
You must be signed in to change notification settings - Fork 3
/
helper.py
42 lines (33 loc) · 1.18 KB
/
helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from pathlib import Path
from typing import Callable, Optional
import binaryninja as bn
import frida
from .log import *
from .settings import HOOK_TAG_TYPE, HOOK_TAG_TYPE_ICON, SETTINGS
PLUGIN_PATH = Path(bn.user_plugin_path()) / "frinja"
mgr = bn.RepositoryManager()
for repo in mgr.repositories:
if any([x.path == "dzervas_frinja" and x.installed for x in repo.plugins]):
PLUGIN_PATH = Path(repo.full_path) / "dzervas_frinja"
break
def get_functions_by_tag(bv: bn.BinaryView, tag: str):
if not bv.get_tag_type(HOOK_TAG_TYPE):
bv.create_tag_type(HOOK_TAG_TYPE, HOOK_TAG_TYPE_ICON)
return [f for f in bv.functions if f.get_function_tags(False, tag)]
def needs_settings(func: Callable):
def wrapper(bv: bn.BinaryView, *args, **kwargs):
SETTINGS.restore(bv)
func(bv, *args, **kwargs)
return wrapper
def message_handler(func: Callable):
def wrapper(*args, **kwargs):
def inner(msg: frida.core.ScriptMessage, data: Optional[bytes]):
# TODO: What to do with the data?
if msg["type"] == "error":
if msg["stack"]:
error(msg["stack"])
error("\n".join(msg["description"].split("\\n")))
return
func(msg["payload"], data, *args, **kwargs)
return inner
return wrapper