diff options
| author | Brandon Miller <brandon@vector35.com> | 2024-04-29 07:49:33 -0400 |
|---|---|---|
| committer | Brandon Miller <bkmiller89@icloud.com> | 2024-04-30 10:17:45 -0400 |
| commit | 6b3165fba7c05a8b200215385ec4478609eb38d3 (patch) | |
| tree | 99a040182392edaeb18e9c71f7088e37bcf04c78 /python/basedetection.py | |
| parent | 81f6484d2a9f4214685516073fbd1beeb553d255 (diff) | |
Added Python example script for base detection
Diffstat (limited to 'python/basedetection.py')
| -rw-r--r-- | python/basedetection.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/python/basedetection.py b/python/basedetection.py index 72406346..b682705b 100644 --- a/python/basedetection.py +++ b/python/basedetection.py @@ -21,7 +21,7 @@ import os import ctypes -from typing import Optional, Union +from typing import Optional, Union, Literal from dataclasses import dataclass from .enums import BaseAddressDetectionPOIType, BaseAddressDetectionConfidence, BaseAddressDetectionPOISetting from .binaryview import BinaryView @@ -128,7 +128,7 @@ class BaseAddressDetection: return self._last_tested_base_address @property - def preferred_base_address(self) -> int: + def preferred_base_address(self) -> Optional[int]: """ ``preferred_base_address`` returns the candidate base address which contains the most amount of pointers that align with discovered points-of-interest in the binary @@ -161,7 +161,7 @@ class BaseAddressDetection: def detect_base_address( self, arch: Optional[str] = "", - analysis: Optional[str] = "basic", + analysis: Optional[str] = Literal["basic", "controlFlow", "full"], min_strlen: Optional[int] = 10, alignment: Optional[int] = 1024, low_boundary: Optional[int] = 0, @@ -261,11 +261,13 @@ class BaseAddressDetection: if count.value == 0: return [] - result = list() - for i in range(count.value): - result.append(BaseAddressDetectionReason(reasons[i].Pointer, reasons[i].POIOffset, reasons[i].POIType)) - core.BNFreeBaseAddressDetectionReasons(reasons) - return result + try: + result = list() + for i in range(count.value): + result.append(BaseAddressDetectionReason(reasons[i].Pointer, reasons[i].POIOffset, reasons[i].POIType)) + return result + finally: + core.BNFreeBaseAddressDetectionReasons(reasons) def _get_data_hits_by_type(self, base_address: int, poi_type: int) -> int: reasons = self.get_reasons(base_address) |
