# Path: stoq/data_classes.py
# class ExtractedPayload:
#     def __init__(
#         self, content: bytes, payload_meta: Optional[PayloadMeta] = None
#     ) -> None:
#         """
# 
#         Object to store extracted payloads for further analysis
# 
#         :param content: Raw bytes of extracted payload
#         :param payload_meta: ``PayloadMeta`` object containing metadata about extracted payload
# 
#         >>> from stoq import PayloadMeta, ExtractedPayload
#         >>> src = '/tmp/bad.exe'
#         >>> data = open(src, 'rb').read()
#         >>> extra_data = {'source': src}
#         >>> extracted_meta = PayloadMeta(should_archive=True, extra_data=extra_data)
#         >>> extracted_payload = ExtractedPayload(content=data, payload_meta=extracted_meta)
# 
#         """
# 
#         self.content = content
#         self.payload_meta: PayloadMeta = PayloadMeta() if payload_meta is None else payload_meta
# 
# class Payload:
#     def __init__(
#         self,
#         content: Union[bytes, str],
#         payload_meta: Optional[PayloadMeta] = None,
#         extracted_by: Optional[Union[str, List[str]]] = None,
#         extracted_from: Optional[Union[str, List[str]]] = None,
#         payload_id: Optional[str] = None,
#     ) -> None:
#         """
# 
#         Object to store payload and related information
# 
#         :param content: Raw bytes to be scanned
#         :param payload_meta: Metadata pertaining to originating source
#         :param extracted_by: Name of plugin that extracted the payload
#         :param extracted_from: Unique payload ID the payload was extracted from
#         :param payload_id: Unique ID of payload
# 
#         >>> from stoq import PayloadMeta, Payload
#         >>> content = b'This is a raw payload'
#         >>> payload_meta = PayloadMeta(should_archive=True)
#         >>> payload = Payload(content, payload_meta=payload_meta)
# 
#         """
#         self.content = content if isinstance(content, bytes) else content.encode()
#         self.dispatch_meta: Dict[str, Dict] = {}
#         self.results = PayloadResults(
#             payload_id=payload_id,
#             size=len(content),
#             payload_meta=payload_meta,
#             extracted_from=extracted_from,
#             extracted_by=extracted_by,
#         )
# 
#     def __repr__(self):
#         return repr(self.__dict__)
# 
# class Request:
#     def __init__(
#         self,
#         payloads: Optional[List[Payload]] = None,
#         request_meta: Optional[RequestMeta] = None,
#         errors: Optional[List[Error]] = None,
#     ):
#         """
# 
#         Object that contains the state of a ``Stoq`` scan. This object is accessible within 
#         all archiver, dispatcher, and worker plugins.
# 
#         :param payloads: All payloads that are being processed, to include extracted payloads
#         :param request_meta: Original ``RequestMeta`` object
#         :param errors: All errors that have been generated by plugins or ``Stoq``
# 
#         """
# 
#         self.payloads = payloads or []
#         self.request_meta = request_meta or RequestMeta()
#         self.errors = errors or []
# 
#     def __str__(self) -> str:
#         return helpers.dumps(self)
# 
#     def __repr__(self):
#         return repr(self.__dict__)
# 
# class WorkerResponse:
#     def __init__(
#         self,
#         results: Optional[Dict] = None,
#         extracted: Optional[List[ExtractedPayload]] = None,
#         errors: Optional[List[Error]] = None,
#         dispatch_to: Optional[List[str]] = None,
#     ) -> None:
#         """
# 
#         Object containing response from worker plugins
# 
#         :param results: Results from worker scan
#         :param extracted: ``ExtractedPayload`` objects of extracted payloads from scan
#         :param errors: Errors that occurred
# 
#         >>> from stoq import WorkerResponse, ExtractedPayload
#         >>> results = {'is_bad': True, 'filetype': 'executable'}
#         >>> extracted_payload = [ExtractedPayload(content=data, payload_meta=extracted_meta)]
#         >>> response = WorkerResponse(results=results, extracted=extracted_payload)
# 
#         """
#         self.results = results
#         self.extracted = extracted or []
#         self.errors = errors or []
#         self.dispatch_to = dispatch_to or []
# 
#     def __str__(self) -> str:
#         return helpers.dumps(self)
# 
#     def __repr__(self):
#         return repr(self.__dict__)
# 
# Path: stoq/plugins/worker.py
# class WorkerPlugin(BasePlugin, ABC):
#     def __init__(self, config: StoqConfigParser) -> None:
#         super().__init__(config)
#         self.required_workers = config.getset(
#             'options', 'required_workers', fallback=set()
#         )
# 
#     @abstractmethod
#     async def scan(
#         self, payload: Payload, request: Request
#     ) -> Optional[WorkerResponse]:
#         pass


import os
from typing import Optional
from stoq.data_classes import ExtractedPayload, Payload, Request, WorkerResponse
from stoq.plugins import WorkerPlugin
#!/usr/bin/env python3

#   Copyright 2014-2018 PUNCH Cyber Analytics Group
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.




class ExtractPayload(WorkerPlugin):
    EXTRACTED_PAYLOAD = None

    async def scan(

# Path: stoq/data_classes.py
# class ExtractedPayload:
#     def __init__(
#         self, content: bytes, payload_meta: Optional[PayloadMeta] = None
#     ) -> None:
#         """
# 
#         Object to store extracted payloads for further analysis
# 
#         :param content: Raw bytes of extracted payload
#         :param payload_meta: ``PayloadMeta`` object containing metadata about extracted payload
# 
#         >>> from stoq import PayloadMeta, ExtractedPayload
#         >>> src = '/tmp/bad.exe'
#         >>> data = open(src, 'rb').read()
#         >>> extra_data = {'source': src}
#         >>> extracted_meta = PayloadMeta(should_archive=True, extra_data=extra_data)
#         >>> extracted_payload = ExtractedPayload(content=data, payload_meta=extracted_meta)
# 
#         """
# 
#         self.content = content
#         self.payload_meta: PayloadMeta = PayloadMeta() if payload_meta is None else payload_meta
# 
# class Payload:
#     def __init__(
#         self,
#         content: Union[bytes, str],
#         payload_meta: Optional[PayloadMeta] = None,
#         extracted_by: Optional[Union[str, List[str]]] = None,
#         extracted_from: Optional[Union[str, List[str]]] = None,
#         payload_id: Optional[str] = None,
#     ) -> None:
#         """
# 
#         Object to store payload and related information
# 
#         :param content: Raw bytes to be scanned
#         :param payload_meta: Metadata pertaining to originating source
#         :param extracted_by: Name of plugin that extracted the payload
#         :param extracted_from: Unique payload ID the payload was extracted from
#         :param payload_id: Unique ID of payload
# 
#         >>> from stoq import PayloadMeta, Payload
#         >>> content = b'This is a raw payload'
#         >>> payload_meta = PayloadMeta(should_archive=True)
#         >>> payload = Payload(content, payload_meta=payload_meta)
# 
#         """
#         self.content = content if isinstance(content, bytes) else content.encode()
#         self.dispatch_meta: Dict[str, Dict] = {}
#         self.results = PayloadResults(
#             payload_id=payload_id,
#             size=len(content),
#             payload_meta=payload_meta,
#             extracted_from=extracted_from,
#             extracted_by=extracted_by,
#         )
# 
#     def __repr__(self):
#         return repr(self.__dict__)
# 
# class Request:
#     def __init__(
#         self,
#         payloads: Optional[List[Payload]] = None,
#         request_meta: Optional[RequestMeta] = None,
#         errors: Optional[List[Error]] = None,
#     ):
#         """
# 
#         Object that contains the state of a ``Stoq`` scan. This object is accessible within 
#         all archiver, dispatcher, and worker plugins.
# 
#         :param payloads: All payloads that are being processed, to include extracted payloads
#         :param request_meta: Original ``RequestMeta`` object
#         :param errors: All errors that have been generated by plugins or ``Stoq``
# 
#         """
# 
#         self.payloads = payloads or []
#         self.request_meta = request_meta or RequestMeta()
#         self.errors = errors or []
# 
#     def __str__(self) -> str:
#         return helpers.dumps(self)
# 
#     def __repr__(self):
#         return repr(self.__dict__)
# 
# class WorkerResponse:
#     def __init__(
#         self,
#         results: Optional[Dict] = None,
#         extracted: Optional[List[ExtractedPayload]] = None,
#         errors: Optional[List[Error]] = None,
#         dispatch_to: Optional[List[str]] = None,
#     ) -> None:
#         """
# 
#         Object containing response from worker plugins
# 
#         :param results: Results from worker scan
#         :param extracted: ``ExtractedPayload`` objects of extracted payloads from scan
#         :param errors: Errors that occurred
# 
#         >>> from stoq import WorkerResponse, ExtractedPayload
#         >>> results = {'is_bad': True, 'filetype': 'executable'}
#         >>> extracted_payload = [ExtractedPayload(content=data, payload_meta=extracted_meta)]
#         >>> response = WorkerResponse(results=results, extracted=extracted_payload)
# 
#         """
#         self.results = results
#         self.extracted = extracted or []
#         self.errors = errors or []
#         self.dispatch_to = dispatch_to or []
# 
#     def __str__(self) -> str:
#         return helpers.dumps(self)
# 
#     def __repr__(self):
#         return repr(self.__dict__)
# 
# Path: stoq/plugins/worker.py
# class WorkerPlugin(BasePlugin, ABC):
#     def __init__(self, config: StoqConfigParser) -> None:
#         super().__init__(config)
#         self.required_workers = config.getset(
#             'options', 'required_workers', fallback=set()
#         )
# 
#     @abstractmethod
#     async def scan(
#         self, payload: Payload, request: Request
#     ) -> Optional[WorkerResponse]:
#         pass


# Path: stoq/tests/data/plugins/worker/extract_payload/extract_payload.py
import os
from typing import Optional
from stoq.data_classes import ExtractedPayload, Payload, Request, WorkerResponse
from stoq.plugins import WorkerPlugin

#!/usr/bin/env python3

#   Copyright 2014-2018 PUNCH Cyber Analytics Group
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.




class ExtractPayload(WorkerPlugin):
    EXTRACTED_PAYLOAD = None

    async def scan(

        self, payload: Payload, request: Request