-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_logic.py
More file actions
74 lines (60 loc) · 2.49 KB
/
Copy pathtest_logic.py
File metadata and controls
74 lines (60 loc) · 2.49 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
"""
Test script to validate the core logic of the YaraBN plugin without UI dependencies.
"""
def test_instruction_data_class():
"""Test the InstructionData class"""
# Define the class here to avoid UI imports
class InstructionData:
def __init__(
self,
address: int,
raw_bytes: str,
wildcarded_bytes: str,
assembly_text: str,
) -> None:
self.address: int = address
self.raw_bytes: str = raw_bytes
self.wildcarded_bytes: str = wildcarded_bytes
self.assembly_text: str = assembly_text
self.is_wildcarded: bool = False
# Test creating instruction data
instruction = InstructionData(0x1000, "48 89 e5", "48 ?? ??", "mov rbp, rsp")
assert instruction.address == 0x1000
assert instruction.raw_bytes == "48 89 e5"
assert instruction.wildcarded_bytes == "48 ?? ??"
assert instruction.assembly_text == "mov rbp, rsp"
assert instruction.is_wildcarded == False
print("✓ InstructionData class works correctly")
def test_yara_template_loading():
"""Test the YARA template loading logic"""
import os
# Test loading template (should work if file exists)
try:
with open("yara_template.txt", "r", encoding="utf-8") as f:
template = f.read()
print(f"✓ YARA template loaded successfully ({len(template)} chars)")
# Check if it has the expected placeholder
if "{hex_content}" in template:
print("✓ Template contains expected {hex_content} placeholder")
else:
print("⚠ Template missing {hex_content} placeholder")
except FileNotFoundError:
print("⚠ yara_template.txt not found - fallback would be used")
def test_wildcarding_import():
"""Test that wildcarding module can be imported"""
try:
from wildcarding import create_wildcarded_bytes
print("✓ Wildcarding module imported successfully")
# Test basic functionality
test_bytes = b"\x48\x89\xe5" # mov rbp, rsp
result = create_wildcarded_bytes(test_bytes, "x86_64")
print(f"✓ Wildcarding test: {test_bytes.hex()} -> {result}")
except ImportError as e:
print(f"⚠ Could not import wildcarding: {e}")
if __name__ == "__main__":
print("Testing YaraBN plugin core logic...")
test_instruction_data_class()
test_yara_template_loading()
test_wildcarding_import()
print("Core logic tests completed!")