forked from M-Labs/nac3
1
0
Fork 0
nac3/nac3embedded/language.py

36 lines
890 B
Python
Raw Normal View History

2021-09-23 19:30:03 +08:00
from inspect import isclass
2020-12-18 23:44:45 +08:00
from functools import wraps
import nac3embedded
2021-09-24 11:39:26 +08:00
__all__ = ["syscall", "kernel"]
2020-12-18 23:44:45 +08:00
2021-09-23 19:30:03 +08:00
nac3 = nac3embedded.NAC3()
2021-09-24 11:39:26 +08:00
allow_object_registration = True
def syscall(function):
assert allow_object_registration
nac3.register_object(function)
return function
2020-12-18 23:44:45 +08:00
2021-09-23 19:30:03 +08:00
def kernel(function_or_class):
2021-09-24 11:39:26 +08:00
global allow_object_registration
2021-09-23 19:30:03 +08:00
if isclass(function_or_class):
2021-09-24 11:39:26 +08:00
assert allow_object_registration
nac3.register_object(function_or_class)
2021-09-23 19:30:03 +08:00
return function_or_class
else:
@wraps(function_or_class)
def run_on_core(self, *args, **kwargs):
2021-09-24 11:39:26 +08:00
global allow_object_registration
if allow_object_registration:
2021-09-23 19:30:03 +08:00
nac3.analyze()
2021-09-24 11:39:26 +08:00
allow_object_registration = False
2021-09-23 19:30:03 +08:00
nac3.compile_method(self.__class__.__name__, function_or_class.__name__)
return run_on_core