Skip to content

Commit

Permalink
models:file - use match classes as identifiers for actions
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoCampinoti94 committed Nov 20, 2023
1 parent aa5c04a commit df92e5f
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions acacore/models/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from acacore.siegfried.siegfried import Siegfried
from acacore.siegfried.siegfried import SiegfriedFile
from acacore.siegfried.siegfried import TSiegfriedClass
from acacore.utils.functions import file_checksum
from acacore.utils.functions import get_bof
from acacore.utils.functions import get_eof
Expand Down Expand Up @@ -101,15 +102,17 @@ def from_file(
root=root,
processed=processed,
)
match_classes: list[TSiegfriedClass] = []

if siegfried:
file.identify(siegfried, set_match=True)
siegfried_match = file.identify(siegfried, set_match=True).best_match()
match_classes.extend(siegfried_match.match_class if siegfried_match else [])

if custom_signatures and not file.puid:
file.identify_custom(custom_signatures, set_match=True)

if actions:
file.get_action(actions)
file.get_action(actions, match_classes)

if custom_signatures and file.action == "reidentify":
custom_match = file.identify_custom(custom_signatures)
Expand All @@ -120,7 +123,7 @@ def from_file(
if custom_match.extension and file.suffix != custom_match.extension:
file.warning.append("extension mismatch")
file.warning = file.warning or None
file.get_action(actions)
file.get_action(actions, match_classes)
elif file.action_data.reidentify and file.action_data.reidentify.onfail:
file.action = file.action_data.reidentify.onfail
else:
Expand Down Expand Up @@ -216,8 +219,29 @@ def identify_custom(

return signature

def get_action(self, actions: dict[str, Action]) -> Optional[Action]:
action: Optional[Action] = actions.get(self.puid)
def get_action(
self,
actions: dict[str, Action],
match_classes: Optional[list[TSiegfriedClass]] = None,
) -> Optional[Action]:
action: Optional[Action] = None

identifiers: list[str] = [
self.puid,
*(match_classes or []),
]
if self.suffix:
identifiers.append(f"!ext={''.join(self.get_absolute_path().suffixes)}")
if self.is_binary:
identifiers.append("!binary")
if not self.size:
identifiers.append("!empty")

for identifier in identifiers:
action = actions.get(identifier)
if action:
break

self.action, self.action_data = action.action if action else None, action.action_data if action else None
return action

Expand Down

0 comments on commit df92e5f

Please sign in to comment.