From aebbc56160bf63eda7762860250983fe3e4bcefb Mon Sep 17 00:00:00 2001 From: Dobin Date: Tue, 20 Dec 2022 19:33:36 +0100 Subject: [PATCH] refactor: fix plain file --- analyzer.py | 2 -- analyzer_plain.py | 10 ---------- avred.py | 28 ++++++++++++++++++---------- plugins/analyzer_plain.py | 6 ++++++ plugins/file_pe.py | 2 +- plugins/file_plain.py | 17 +++++++++++++++++ 6 files changed, 42 insertions(+), 23 deletions(-) delete mode 100644 analyzer.py delete mode 100644 analyzer_plain.py create mode 100644 plugins/analyzer_plain.py create mode 100644 plugins/file_plain.py diff --git a/analyzer.py b/analyzer.py deleted file mode 100644 index b48e5a0..0000000 --- a/analyzer.py +++ /dev/null @@ -1,2 +0,0 @@ -import os - diff --git a/analyzer_plain.py b/analyzer_plain.py deleted file mode 100644 index d1aa869..0000000 --- a/analyzer_plain.py +++ /dev/null @@ -1,10 +0,0 @@ -import os -from reducer import scanData - -# no PE file, just check its content -def analyzeFilePlain(filename, scanner): - data = None - with open(filename, "rb") as file: - data = file.read() - matches = scanData(scanner, data, os.path.basename(filename), 0, len(data)) - return data, matches diff --git a/avred.py b/avred.py index 30ef639..9780495 100755 --- a/avred.py +++ b/avred.py @@ -2,21 +2,25 @@ import argparse from scanner import ScannerRest -from plugins.analyzer_office import analyzeFileWord, augmentFileWord -from plugins.analyzer_pe import analyzeFileExe, augmentFilePe -from analyzer_plain import analyzeFilePlain -from config import Config -import logging -from utils import saveMatchesToFile -from verifier import verify -from plugins.file_pe import FilePe -from model.model import FileData + import pickle -from plugins.file_office import FileOffice import os import sys +import logging + +from config import Config +from utils import saveMatchesToFile +from verifier import verify +from model.model import FileData from model.model import Match +from plugins.analyzer_office import analyzeFileWord, augmentFileWord +from plugins.analyzer_pe import analyzeFileExe, augmentFilePe +from plugins.analyzer_plain import analyzeFilePlain +from plugins.file_pe import FilePe +from plugins.file_office import FileOffice +from plugins.file_plain import FilePlain + log_format = '[%(levelname)-8s][%(asctime)s][%(filename)s:%(lineno)3d] %(funcName)s() :: %(message)s' @@ -105,6 +109,10 @@ def scanFile(args, scanner): analyzerOptions["remove"] = args.remove analyzerOptions["ignoreText"] = args.ignoreText + else: + logging.error("File ending not supported") + os.exit(1) + # matches if os.path.exists(filenameMatches): logging.info("Loading matches from file") diff --git a/plugins/analyzer_plain.py b/plugins/analyzer_plain.py new file mode 100644 index 0000000..b70d0c2 --- /dev/null +++ b/plugins/analyzer_plain.py @@ -0,0 +1,6 @@ +from reducer import scanData + +# no PE file, just check its content +def analyzeFilePlain(filePlain, scanner): + matchesIntervalTree = scanData(scanner, filePlain.data, filePlain.filename, 0, len(filePlain.data)) + return matchesIntervalTree diff --git a/plugins/file_pe.py b/plugins/file_pe.py index 49f331b..ce84eea 100644 --- a/plugins/file_pe.py +++ b/plugins/file_pe.py @@ -1,5 +1,4 @@ import logging -import pefile import os from dataclasses import dataclass import copy @@ -99,6 +98,7 @@ class FilePe(): return "" + def printSections(self): for section in self.sections: print(f"Section {section.name}\t addr: {hex(section.addr)} size: {section.size} ") diff --git a/plugins/file_plain.py b/plugins/file_plain.py new file mode 100644 index 0000000..8717fc3 --- /dev/null +++ b/plugins/file_plain.py @@ -0,0 +1,17 @@ +import logging +import os + + +class FilePlain(): + def __init__(self): + self.filepath = None + self.filename = None + self.data = b"" + + + def loadFromFile(self, filepath: str): + self.filepath = filepath + self.filename = os.path.basename(filepath) + + with open(self.filepath, "rb") as f: + self.data = f.read()