mirror of
https://github.com/dobin/avred
synced 2026-06-08 13:54:13 +00:00
53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
|
|
import copy
|
|
import logging
|
|
|
|
from reducer import scanData
|
|
from packers import PackerWord
|
|
from utils import *
|
|
from file_office import FileOffice
|
|
|
|
|
|
def analyzeFileWord(filepath, scanner, verify=True):
|
|
fileOffice = FileOffice()
|
|
fileOffice.loadFromFile(filepath)
|
|
makroData = fileOffice.data
|
|
|
|
packer = PackerWord(fileOffice)
|
|
scanner.setPacker(packer)
|
|
|
|
matches = scanData(scanner, makroData, fileOffice.filename, 0, len(makroData))
|
|
printMatches(makroData, matches)
|
|
|
|
if verify:
|
|
verifyFile(fileOffice, matches, scanner)
|
|
|
|
return makroData, matches
|
|
|
|
|
|
def verifyFile(officeFile, matches, scanner, patchSize=None):
|
|
print("Patching file with results...")
|
|
logging.info("Patching file with results...")
|
|
|
|
officeFile = copy.deepcopy(officeFile)
|
|
data = copy.copy(officeFile.data)
|
|
|
|
for i in matches:
|
|
size = i.end - i.begin
|
|
if patchSize is not None:
|
|
size = patchSize
|
|
|
|
print(f"Patch: {i.begin}-{i.end} size {size}")
|
|
logging.info(f"Patch: {i.begin}-{i.end} size {size}")
|
|
|
|
data = patchData(data, i.begin, size)
|
|
|
|
if not scanner.scan(officeFile.getPatchedByReplacement(data), officeFile.filename):
|
|
print("Success, not detected!")
|
|
logging.info("Success, not detected!")
|
|
return
|
|
|
|
print("Still detected? :-(")
|
|
logging.info("Still detected? :-(")
|
|
|