Skip to content

Commit

Permalink
work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
mmguero committed Oct 31, 2024
1 parent 1905171 commit 77b5e67
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/maltest/maltest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
import signal
import sys

from maltest.utils import MalcolmVM, MalcolmTestCollection, ShuttingDown, set_malcolm_vm_info
from maltest.utils import (
MalcolmVM,
MalcolmTestCollection,
ShuttingDown,
set_malcolm_vm_info,
shakey_file_hash,
)

###################################################################################################
script_name = os.path.basename(__file__)
Expand Down Expand Up @@ -321,9 +327,13 @@ def main():
for pcapFile in pcaps:
# TODO: would it be better to use SFTP for this? or even the upload interface?
# TODO: Assuming the Malcolm directory like this might not be very robust
malcolmVm.CopyFile(
pcapFile, f'/home/{args.vmImageUsername}/Malcolm/pcap/upload/', tolerateFailure=True
)
pcapFileParts = os.path.splitext(pcapFile)
if pcapHash := shakey_file_hash(pcapFile):
malcolmVm.CopyFile(
pcapFile,
f'/home/{args.vmImageUsername}/Malcolm/pcap/upload/{pcapHash}{pcapFileParts[1]}',
tolerateFailure=True,
)

# TODO: wait until all data has been processed (no new documents are being indexed for X amount of time)

Expand Down
10 changes: 10 additions & 0 deletions src/maltest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ast
import glob
import hashlib
import json
import mmguero
import os
Expand Down Expand Up @@ -31,6 +32,15 @@
)


###################################################################################################
def shakey_file_hash(filename, digest_len=8):
try:
with open(filename, 'rb', buffering=0) as f:
return hashlib.file_digest(f, 'shake_256').hexdigest(digest_len)
except:
return None


###################################################################################################
def set_malcolm_vm_info(info):
global MalcolmVmInfo
Expand Down

0 comments on commit 77b5e67

Please sign in to comment.