-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinary.py
More file actions
36 lines (27 loc) · 1.04 KB
/
Binary.py
File metadata and controls
36 lines (27 loc) · 1.04 KB
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
from abc import ABC, abstractmethod
from pathlib import Path
from elftools.elf.elffile import ELFFile
from stats.Symbol import Symbol
class Binary(ABC):
def __init__(self, bin_path: Path):
self.obj: ELFFile
self.has_debug_info: bool = False
self.symbols: dict[str, Symbol] = dict()
self.path: Path = bin_path
if not self.path.exists():
raise ValueError(f"Binary path '{self.path}' doesn't exist.")
self._load_obj()
@abstractmethod
def _load_obj(self):
raise NotImplementedError("_load_bin isn't implemented.")
@staticmethod
def can_load(bin_path: Path) -> bool:
raise NotImplementedError("_can_load isn't implemented.")
def init_binary(bin_path: Path) -> Binary:
if not bin_path.exists():
raise ValueError(f"Binary path '{bin_path}' doesn't exist.")
from ELFBinary import ELFBinary
if ELFBinary.can_load(bin_path):
return ELFBinary(bin_path)
else:
raise NotImplementedError(f"Found no binary handler for {bin_path}")