Skip to content

Commit

Permalink
Merge pull request #76 from james-acsc/fix/collector-compat
Browse files Browse the repository at this point in the history
fix: resolve runtime collector failure
  • Loading branch information
cccs-rs authored Jan 3, 2025
2 parents 0c8da7c + 8d44412 commit c63f091
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
26 changes: 23 additions & 3 deletions maco/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import logging.handlers
import os
import sys
from multiprocessing import Manager, Process, Queue
from tempfile import NamedTemporaryFile
from types import ModuleType
from typing import Any, BinaryIO, Dict, List, Union
from typing import Any, BinaryIO, Dict, List, TypedDict, Union

from multiprocess import Manager, Process, Queue
from pydantic import BaseModel

from maco import extractor, model, utils, yara
Expand Down Expand Up @@ -40,6 +40,26 @@ def _verify_response(resp: Union[BaseModel, dict]) -> Dict:
return resp.model_dump(exclude_defaults=True)


class ExtractorMetadata(TypedDict):
"""Extractor-supplied metadata."""

author: str
family: str
last_modified: str
sharing: str
description: str


class ExtractorRegistration(TypedDict):
"""Registration collected by the collector for a single extractor."""

venv: str
module_path: str
module_name: str
extractor_class: str
metadata: ExtractorMetadata


class Collector:
def __init__(
self,
Expand All @@ -60,7 +80,7 @@ def __init__(

path_extractors = os.path.realpath(path_extractors)
self.path: str = path_extractors
self.extractors: Dict[str, Dict[str, str]] = {}
self.extractors: Dict[str, ExtractorRegistration] = {}

with Manager() as manager:
extractors = manager.dict()
Expand Down
5 changes: 3 additions & 2 deletions maco/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import json
import logging
import logging.handlers
import multiprocessing
import os
import re
import shutil
import subprocess
import sys
import tempfile

from multiprocess import Queue

from maco import yara

if sys.version_info >= (3, 11):
Expand Down Expand Up @@ -390,7 +391,7 @@ def register_extractors(
break


def proxy_logging(queue: multiprocessing.Queue, callback: Callable[[ModuleType, str], None], *args, **kwargs):
def proxy_logging(queue: Queue, callback: Callable[[ModuleType, str], None], *args, **kwargs):
"""Ensures logging is set up correctly for a child process and then executes the callback."""
logger = logging.getLogger()
qh = logging.handlers.QueueHandler(queue)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ tomli >= 1.1.0 ; python_version < "3.11"
uv
yara-python
yara-x==0.11.0
multiprocess>=0.70.17

0 comments on commit c63f091

Please sign in to comment.