Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions src/forensic/analyzers/CodeSysV3/app_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import networkx as nx
from pathlib import Path

from networkx import add_path

from forensic.analyzers.CodeSysV3.file_format import CodesysV3FileFormat
from forensic.analyzers.CodeSysV3.memory_dynamic_format import CodesysV3MemoryDynamicFormat
from forensic.analyzers.CodeSysV3.memory_format import CodesysV3MemoryFormat
Expand Down Expand Up @@ -39,22 +41,34 @@ def dump_all(output_dir, g_entry_point, symbols, all_code_blocks, taskinfos, pro


def parse_app(app_fpath, output_dir):
with open(app_fpath, 'rb') as f:
try:
f = open(app_fpath, 'rb')
file_data = f.read()
cff = CodesysV3FileFormat()
all_tags = cff.parse(file_data)

cff = CodesysV3FileFormat()
all_tags = cff.parse(file_data)

cmf = CodesysV3MemoryFormat(file_data, all_tags)
br_memory = BinaryReader(cmf.memory_file)
cmf = CodesysV3MemoryFormat(file_data, all_tags)
br_memory = BinaryReader(cmf.memory_file)

# Check if we have memory symbols
if '@table_start' in cmf.imp_addr:
cmdf = CodesysV3MemoryDynamicFormat()
cmf.symbols.update(cmdf.parse(br_memory, cmf.imp_addr))
if '@table_start' in cmf.imp_addr:
cmdf = CodesysV3MemoryDynamicFormat()
cmf.symbols.update(cmdf.parse(br_memory, cmf.imp_addr))

# Make sure the architecture is supported
if cmdf.validate_supported_arch(br_memory, cmf.imp_addr):
cmdf.simulate_to_find_taskinfos(cmf.memory_file, cmf.symbols, cmf.imp_addr, cmf.all_code_blocks)

dump_all(output_dir, cmdf.g_entry_point, cmf.symbols, cmf.all_code_blocks, cmdf.taskinfos, cmf.project_info)

except FileNotFoundError:
print(f"Error: File {app_fpath} not found")
except PermissionError:
print(f"Error: Insufficient permission to read {app_fpath}.")
except Exception as e:
print(f"There is another Error here.")
finally:
f.close()



5 changes: 5 additions & 0 deletions src/forensic/interfaces/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,10 @@ def from_json(json: Dict) -> AnalyzerConfig:
name=json["name"],
parameters=json["parameters"]
)
def validate_config(self):
if not isinstance(self.name, str) or not self.name.strip:
raise ValueError("Analyzer name must not be a empty string.")
if not isinstance(self.parameters, dict):
raise ValueError("The Parameter must be a dictonary.")