code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def unpack(self, data: bytes, allow_truncated: bool = False, allow_exceeded: bool = False, ) -> typing.Mapping[str, DecodedSignal]: """Return OrderedDictionary with Signal Name: object decodedSignal (flat / without support for multiplexed frames) decodes ever...
Return OrderedDictionary with Signal Name: object decodedSignal (flat / without support for multiplexed frames) decodes every signal in signal-list. :param data: bytearray i.e. bytearray([0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8]) :param report_error: set to False to silence e...
unpack
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def _get_sub_multiplexer(self, parent_multiplexer_name, parent_multiplexer_value): """ get any sub-multiplexer in frame used for complex-multiplexed frame decoding :param parent_multiplexer_name: string with name of parent multiplexer :param parent_multiplexer_value: raw_value (...
get any sub-multiplexer in frame used for complex-multiplexed frame decoding :param parent_multiplexer_name: string with name of parent multiplexer :param parent_multiplexer_value: raw_value (int) of parent multiplexer :return: muxer signal or None
_get_sub_multiplexer
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def _filter_signals_for_multiplexer(self, multiplexer_name, multiplexer_value): """ filter a list of signals with given multiplexer (name and value) used for complex-multiplexed frame decoding :param multiplexer_name: string with name of parent multiplexer :param multiplexer_va...
filter a list of signals with given multiplexer (name and value) used for complex-multiplexed frame decoding :param multiplexer_name: string with name of parent multiplexer :param multiplexer_value: raw_value (int) of parent multiplexer :return: filtered array of canmatrix.Sig...
_filter_signals_for_multiplexer
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def decode(self, data): # type: (bytes) -> typing.Mapping[str, typing.Any] """Return OrderedDictionary with Signal Name: object decodedSignal (support for multiplexed frames) decodes only signals matching to muxgroup :param data: bytearray . i.e. bytearray([0xA1, 0xA2, 0xA3,...
Return OrderedDictionary with Signal Name: object decodedSignal (support for multiplexed frames) decodes only signals matching to muxgroup :param data: bytearray . i.e. bytearray([0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8]) :return: OrderedDictionary
decode
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def multiplex_signals(self): """Assign multiplexer to signals. When a multiplexor is in the frame.""" multiplexor = self.get_multiplexer if multiplexor is None: return for signal in self.signals: if signal.is_multiplexer or (signal.muxer_for_signal is not None): ...
Assign multiplexer to signals. When a multiplexor is in the frame.
multiplex_signals
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def __init__(self, definition): # type (str) -> None """Initialize Define object. :param str definition: definition string. Ex: "INT -5 10" """ definition = definition.strip() self.definition = definition self.type = None # type: typing.Optional[str] self.defau...
Initialize Define object. :param str definition: definition string. Ex: "INT -5 10"
__init__
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def safe_convert_str_to_int(inStr): # type: (str) -> int """Convert string to int safely. Check that it isn't float. :param str inStr: integer represented as string. :rtype: int """ out = int(defaultFloatFactory(inStr)) if out != defaultFloatFact...
Convert string to int safely. Check that it isn't float. :param str inStr: integer represented as string. :rtype: int
safe_convert_str_to_int
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def set_default(self, default): # type: (typing.Any) -> None """Set Definition default value. :param default: default value; number, str or quoted str ("value") """ if default is not None and len(default) > 1 and default[0] == '"' and default[-1] == '"': default = default[1...
Set Definition default value. :param default: default value; number, str or quoted str ("value")
set_default
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def update(self): # type: () -> None """Update definition string for type ENUM. For type ENUM rebuild the definition string from current values. Otherwise do nothing. """ if self.type != 'ENUM': return self.definition = 'ENUM "' + '","' .join(self.values) +'"'
Update definition string for type ENUM. For type ENUM rebuild the definition string from current values. Otherwise do nothing.
update
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def contains_j1939(self): # type: () -> bool """Check whether the Matrix contains any J1939 Frame.""" for frame in self.frames: if frame.is_j1939: return True return False
Check whether the Matrix contains any J1939 Frame.
contains_j1939
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def attribute(self, attributeName, default=None): # type(str, typing.Any) -> typing.Any """Return custom Matrix attribute by name. :param str attributeName: attribute name :param default: default value if given attribute doesn't exist :return: attribute value or default or None if no s...
Return custom Matrix attribute by name. :param str attributeName: attribute name :param default: default value if given attribute doesn't exist :return: attribute value or default or None if no such attribute found.
attribute
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def add_attribute(self, attribute, value): # type: (str, typing.Any) -> None """ Add attribute to Matrix attribute-list. :param str attribute: attribute name :param value: attribute value """ try: self.attributes[attribute] = str(value) except Unicod...
Add attribute to Matrix attribute-list. :param str attribute: attribute name :param value: attribute value
add_attribute
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def add_signal_defines(self, type, definition): """ Add signal-attribute definition to canmatrix. :param str type: signal type :param str definition: signal-attribute string definition, see class Define """ if type not in self.signal_defines: self.signal_defi...
Add signal-attribute definition to canmatrix. :param str type: signal type :param str definition: signal-attribute string definition, see class Define
add_signal_defines
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def add_frame_defines(self, name, definition): # type: (str, str) -> None """ Add frame-attribute definition to canmatrix. :param str name: frame type :param str definition: frame definition as string """ if name not in self.frame_defines: self.frame_defines...
Add frame-attribute definition to canmatrix. :param str name: frame type :param str definition: frame definition as string
add_frame_defines
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def add_ecu_defines(self, name, definition): # type: (str, str) -> None """ Add Boardunit-attribute definition to canmatrix. :param str name: Boardunit type :param str definition: BU definition as string """ if name not in self.ecu_defines: self.ecu_defines[...
Add Boardunit-attribute definition to canmatrix. :param str name: Boardunit type :param str definition: BU definition as string
add_ecu_defines
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def add_env_defines(self, name, definition): # type: (str, str) -> None """ Add enviroment variable-attribute definition to canmatrix. :param str name: enviroment variable type :param str definition: enviroment variable definition as string """ if name not in self.env_d...
Add enviroment variable-attribute definition to canmatrix. :param str name: enviroment variable type :param str definition: enviroment variable definition as string
add_env_defines
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def add_global_defines(self, name, definition): # type: (str, str) -> None """ Add global-attribute definition to canmatrix. :param str name: attribute type :param str definition: attribute definition as string """ if name not in self.global_defines: self.gl...
Add global-attribute definition to canmatrix. :param str name: attribute type :param str definition: attribute definition as string
add_global_defines
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def delete_obsolete_defines(self): # type: () -> None """Delete all unused Defines. Delete them from frame_defines, ecu_defines and signal_defines. """ defines_to_delete = set() # type: typing.Set[str] for frameDef in self.frame_defines: for frame in self.frames: ...
Delete all unused Defines. Delete them from frame_defines, ecu_defines and signal_defines.
delete_obsolete_defines
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def frame_by_id(self, arbitration_id): # type: (ArbitrationId) -> typing.Union[Frame, None] """Get Frame by its arbitration id. :param ArbitrationId arbitration_id: Frame id as canmatrix.ArbitrationId :rtype: Frame or None """ hash_name = f"{arbitration_id.id}_{arbitration_id.e...
Get Frame by its arbitration id. :param ArbitrationId arbitration_id: Frame id as canmatrix.ArbitrationId :rtype: Frame or None
frame_by_id
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def frame_by_header_id(self, header_id): # type: (HeaderId) -> typing.Union[Frame, None] """Get Frame by its Header id. :param HeaderId header_id: Header id as canmatrix.header_id :rtype: Frame or None """ for test in self.frames: if test.header_id == header_id: ...
Get Frame by its Header id. :param HeaderId header_id: Header id as canmatrix.header_id :rtype: Frame or None
frame_by_header_id
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def get_frame_by_id(self, id: int ) -> typing.Union[Frame, None]: """Get Frame by id. :param str name: Frame id to search for :rtype: Frame or None """ return self.frames_dict_id[id]
Get Frame by id. :param str name: Frame id to search for :rtype: Frame or None
get_frame_by_id
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def frame_by_pgn(self, pgn): # type: (int) -> typing.Union[Frame, None] """Get Frame by pgn (j1939). :param int pgn: pgn to search for :rtype: Frame or None """ for test in self.frames: if test.arbitration_id.pgn == canmatrix.ArbitrationId.from_pgn(pgn).pgn: ...
Get Frame by pgn (j1939). :param int pgn: pgn to search for :rtype: Frame or None
frame_by_pgn
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def frame_by_name(self, name): # type: (str) -> typing.Union[Frame, None] """Get Frame by name. :param str name: Frame name to search for :rtype: Frame or None """ for test in self.frames: if test.name == name: return test return None
Get Frame by name. :param str name: Frame name to search for :rtype: Frame or None
frame_by_name
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def glob_frames(self, globStr): # type: (str) -> typing.List[Frame] """Find Frames by given glob pattern. :param str globStr: glob pattern to filter Frames. See `fnmatch.fnmatchcase`. :rtype: list of Frame """ return_array = [] for test in self.frames: if fn...
Find Frames by given glob pattern. :param str globStr: glob pattern to filter Frames. See `fnmatch.fnmatchcase`. :rtype: list of Frame
glob_frames
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def ecu_by_name(self, name): # type: (str) -> typing.Union[Ecu, None] """ Returns Boardunit by Name. :param str name: BoardUnit name :rtype: Ecu or None """ for test in self.ecus: if test.name == name: return test return None
Returns Boardunit by Name. :param str name: BoardUnit name :rtype: Ecu or None
ecu_by_name
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def glob_ecus(self, globStr): # type: (str) -> typing.List[Ecu] """ Find ECUs by given glob pattern. :param globStr: glob pattern to filter BoardUnits. See `fnmatch.fnmatchcase`. :rtype: list of Ecu """ return_array = [] for test in self.ecus: if fnm...
Find ECUs by given glob pattern. :param globStr: glob pattern to filter BoardUnits. See `fnmatch.fnmatchcase`. :rtype: list of Ecu
glob_ecus
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def add_frame(self, frame): # type: (Frame) -> Frame """Add the Frame to the Matrix. :param Frame frame: Frame to add :return: the inserted Frame """ self.frames.append(frame) self._frames_dict_id_extend = {} self.frames_dict_name[frame.name] = frame if ...
Add the Frame to the Matrix. :param Frame frame: Frame to add :return: the inserted Frame
add_frame
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def remove_frame(self, frame): # type: (Frame) -> None """Remove the Frame from Matrix. :param Frame frame: frame to remove from CAN Matrix """ self.frames.remove(frame) self._frames_dict_id_extend = {}
Remove the Frame from Matrix. :param Frame frame: frame to remove from CAN Matrix
remove_frame
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def add_signal(self, signal): # type: (Signal) -> Signal """ Add Signal to Frame. :param Signal signal: Signal to be added. :return: the signal added. """ self.signals.append(signal) return self.signals[len(self.signals) - 1]
Add Signal to Frame. :param Signal signal: Signal to be added. :return: the signal added.
add_signal
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def delete_zero_signals(self): # type: () -> None """Delete all signals with zero bit width from all Frames.""" for frame in self.frames: for signal in frame.signals: if 0 == signal.size: frame.signals.remove(signal)
Delete all signals with zero bit width from all Frames.
delete_zero_signals
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def del_signal_attributes(self, unwanted_attributes): # type: (typing.Sequence[str]) -> None """Delete Signal attributes from all Signals of all Frames. :param list of str unwanted_attributes: List of attributes to remove """ for frame in self.frames: for signal in frame.si...
Delete Signal attributes from all Signals of all Frames. :param list of str unwanted_attributes: List of attributes to remove
del_signal_attributes
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def del_frame_attributes(self, unwanted_attributes): # type: (typing.Sequence[str]) -> None """Delete Frame attributes from all Frames. :param list of str unwanted_attributes: List of attributes to remove """ for frame in self.frames: for attrib in unwanted_attributes: ...
Delete Frame attributes from all Frames. :param list of str unwanted_attributes: List of attributes to remove
del_frame_attributes
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def recalc_dlc(self, strategy): # type: (str) -> None """Recompute DLC of all Frames. :param str strategy: selected strategy, "max" or "force". """ for frame in self.frames: if "max" == strategy: frame.calc_dlc() if "force" == strategy: ...
Recompute DLC of all Frames. :param str strategy: selected strategy, "max" or "force".
recalc_dlc
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def rename_ecu(self, ecu_or_name, new_name): # type: (typing.Union[Ecu, str], str) -> None """Rename ECU in the Matrix. Update references in all Frames. :param str or Ecu ecu_or_name: old name or ECU instance :param str new_name: new name """ ecu = ecu_or_name if isinstance(ecu...
Rename ECU in the Matrix. Update references in all Frames. :param str or Ecu ecu_or_name: old name or ECU instance :param str new_name: new name
rename_ecu
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def add_ecu(self, ecu): # type(Ecu) -> None # todo return Ecu? """Add new ECU to the Matrix. Do nothing if ecu with the same name already exists. :param Ecu ecu: ECU name to add """ for bu in self.ecus: if bu.name.strip() == ecu.name: return self.ec...
Add new ECU to the Matrix. Do nothing if ecu with the same name already exists. :param Ecu ecu: ECU name to add
add_ecu
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def del_ecu(self, ecu_or_glob): # type: (typing.Union[Ecu, str]) -> None """Remove ECU from Matrix and all Frames. :param str or Ecu ecu_or_glob: ECU instance or glob pattern to remove from list """ ecu_list = [ecu_or_glob] if isinstance(ecu_or_glob, Ecu) else self.glob_ecus(ecu_or_glo...
Remove ECU from Matrix and all Frames. :param str or Ecu ecu_or_glob: ECU instance or glob pattern to remove from list
del_ecu
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def update_ecu_list(self): # type: () -> None """Check all Frames and add unknown ECUs to the Matrix ECU list.""" for frame in self.frames: for transmit_ecu in frame.transmitters: self.add_ecu(Ecu(transmit_ecu)) frame.update_receiver() for signal in f...
Check all Frames and add unknown ECUs to the Matrix ECU list.
update_ecu_list
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def rename_frame(self, frame_or_name, new_name): # type: (typing.Union[Frame,str], str) -> None """Rename Frame. :param Frame or str frame_or_name: Old Frame instance or name or part of the name with '*' at the beginning or the end. :param str new_name: new Frame name, suffix or prefix ...
Rename Frame. :param Frame or str frame_or_name: Old Frame instance or name or part of the name with '*' at the beginning or the end. :param str new_name: new Frame name, suffix or prefix
rename_frame
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def del_frame(self, frame_or_name): # type: (typing.Union[Frame, str]) -> None """Delete Frame from Matrix. :param Frame or str frame_or_name: Frame or name to delete""" frame = frame_or_name if isinstance(frame_or_name, Frame) else self.frame_by_name(frame_or_name) if frame: ...
Delete Frame from Matrix. :param Frame or str frame_or_name: Frame or name to delete
del_frame
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def rename_signal(self, signal_or_name, new_name): # type: (typing.Union[Signal, str], str) -> None """Rename Signal. :param Signal or str signal_or_name: Old Signal instance or name or part of the name with '*' at the beginning or the end. :param str new_name: new Signal name, suffix or prefi...
Rename Signal. :param Signal or str signal_or_name: Old Signal instance or name or part of the name with '*' at the beginning or the end. :param str new_name: new Signal name, suffix or prefix
rename_signal
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def del_signal(self, signal): # type: (typing.Union[Signal, str]) -> None """Delete Signal from Matrix and all Frames. :param Signal or str signal: Signal instance or glob pattern to be deleted""" if isinstance(signal, Signal): for frame in self.frames: if signal in...
Delete Signal from Matrix and all Frames. :param Signal or str signal: Signal instance or glob pattern to be deleted
del_signal
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def add_signal_receiver(self, globFrame, globSignal, ecu): # type: (str, str, str) -> None """Add Receiver to all Frames and Signals by glob pattern. :param str globFrame: glob pattern for Frame name. :param str globSignal: glob pattern for Signal name. Only signals under globFrame are filtere...
Add Receiver to all Frames and Signals by glob pattern. :param str globFrame: glob pattern for Frame name. :param str globSignal: glob pattern for Signal name. Only signals under globFrame are filtered. :param str ecu: Receiver ECU name
add_signal_receiver
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def del_signal_receiver(self, globFrame, globSignal, ecu): # type: (str, str, str) -> None """Delete Receiver from all Frames by glob pattern. :param str globFrame: glob pattern for Frame name. :param str globSignal: glob pattern for Signal name. Only signals under globFrame are filtered. ...
Delete Receiver from all Frames by glob pattern. :param str globFrame: glob pattern for Frame name. :param str globSignal: glob pattern for Signal name. Only signals under globFrame are filtered. :param str ecu: Receiver ECU name
del_signal_receiver
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def add_frame_receiver(self, globFrame, ecu): # type: (str, str) -> None """Add Receiver to all Frames by glob pattern. :param str globFrame: glob pattern for Frame name. :param str ecu: Receiver ECU name """ frames = self.glob_frames(globFrame) for frame in frames: ...
Add Receiver to all Frames by glob pattern. :param str globFrame: glob pattern for Frame name. :param str ecu: Receiver ECU name
add_frame_receiver
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def merge(self, mergeArray): # type: (typing.Sequence[CanMatrix]) -> None """Merge multiple Matrices to this Matrix. Try to copy all Frames and all environment variables from source Matrices. Don't make duplicates. Log collisions. :param list of Matrix mergeArray: list of source CAN M...
Merge multiple Matrices to this Matrix. Try to copy all Frames and all environment variables from source Matrices. Don't make duplicates. Log collisions. :param list of Matrix mergeArray: list of source CAN Matrices to be merged to to self.
merge
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def set_fd_type(self) -> None: """Try to guess and set the CAN type for every frame. If a Frame is longer than 8 bytes, it must be Flexible Data Rate frame (CAN-FD). If not, the Frame type stays unchanged. """ for frame in self.frames: if frame.size > 8: ...
Try to guess and set the CAN type for every frame. If a Frame is longer than 8 bytes, it must be Flexible Data Rate frame (CAN-FD). If not, the Frame type stays unchanged.
set_fd_type
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def encode(self, frame_id: ArbitrationId, data: typing.Mapping[str, typing.Any] ) -> bytes: """Return a byte string containing the values from data packed according to the frame format. :param frame_id: frame id :param data: data dictionary ...
Return a byte string containing the values from data packed according to the frame format. :param frame_id: frame id :param data: data dictionary :return: A byte string of the packed values.
encode
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def decode_pycan(self, pycan_msg): """Return OrderedDictionary with Signal Name: object decodedSignal :param pycan_msg: python-can message :return: OrderedDictionary """ canmatrix_arbitration_id = canmatrix.ArbitrationId(pycan_msg.arbitration_id, extended=pycan_msg.is_extended_i...
Return OrderedDictionary with Signal Name: object decodedSignal :param pycan_msg: python-can message :return: OrderedDictionary
decode_pycan
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def decode(self, frame_id, data): # type: (ArbitrationId, bytes) -> typing.Mapping[str, typing.Any] """Return OrderedDictionary with Signal Name: object decodedSignal :param frame_id: frame id :param data: Iterable or bytes. i.e. (0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8) ...
Return OrderedDictionary with Signal Name: object decodedSignal :param frame_id: frame id :param data: Iterable or bytes. i.e. (0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8) :return: OrderedDictionary
decode
python
ebroecker/canmatrix
src/canmatrix/canmatrix.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/canmatrix.py
BSD-2-Clause
def copy_ecu(ecu_or_glob, source_db, target_db): # type: (typing.Union[canmatrix.Ecu, str], canmatrix.CanMatrix, canmatrix.CanMatrix) -> None """ Copy ECU(s) identified by Name or as Object from source CAN matrix to target CAN matrix. This function additionally copy all relevant Defines. :param ecu...
Copy ECU(s) identified by Name or as Object from source CAN matrix to target CAN matrix. This function additionally copy all relevant Defines. :param ecu_or_glob: Ecu instance or glob pattern for Ecu name :param source_db: Source CAN matrix :param target_db: Destination CAN matrix
copy_ecu
python
ebroecker/canmatrix
src/canmatrix/copy.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/copy.py
BSD-2-Clause
def copy_ecu_with_frames(ecu_or_glob, source_db, target_db, rx=True, tx=True, direct_ecu_only=True): # type: (typing.Union[canmatrix.Ecu, str], canmatrix.CanMatrix, canmatrix.CanMatrix, bool, bool, bool) -> None """ Copy ECU(s) identified by Name or as Object from source CAN matrix to target CAN matrix. ...
Copy ECU(s) identified by Name or as Object from source CAN matrix to target CAN matrix. This function additionally copy all relevant Frames and Defines. :param ecu_or_glob: Ecu instance or glob pattern for Ecu name :param source_db: Source CAN matrix :param target_db: Destination CAN matrix :...
copy_ecu_with_frames
python
ebroecker/canmatrix
src/canmatrix/copy.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/copy.py
BSD-2-Clause
def copy_signal(signal_glob, source_db, target_db): # type: (str, canmatrix.CanMatrix, canmatrix.CanMatrix) -> None """ Copy Signals identified by name from source CAN matrix to target CAN matrix. In target CanMatrix the signal is put without frame, just on top level. :param signal_glob: Signal glo...
Copy Signals identified by name from source CAN matrix to target CAN matrix. In target CanMatrix the signal is put without frame, just on top level. :param signal_glob: Signal glob pattern :param source_db: Source CAN matrix :param target_db: Destination CAN matrix
copy_signal
python
ebroecker/canmatrix
src/canmatrix/copy.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/copy.py
BSD-2-Clause
def copy_frame(frame_id, source_db, target_db): # type: (canmatrix.ArbitrationId, canmatrix.CanMatrix, canmatrix.CanMatrix) -> bool """ Copy a Frame identified by ArbitrationId from source CAN matrix to target CAN matrix. This function additionally copy all relevant ECUs and Defines. :param frame_i...
Copy a Frame identified by ArbitrationId from source CAN matrix to target CAN matrix. This function additionally copy all relevant ECUs and Defines. :param frame_id: Frame arbitration od :param source_db: Source CAN matrix :param target_db: Destination CAN matrix
copy_frame
python
ebroecker/canmatrix
src/canmatrix/copy.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/copy.py
BSD-2-Clause
def list_pgn(db): # type: (canmatrix.CanMatrix) -> typing.Tuple[typing.List[int], typing.List[canmatrix.ArbitrationId]] """ Get all PGN values for given frame. :param db: CanMatrix database :return: tuple of [pgn] and [arbitration_id] """ id_list = [x.arbitration_id for x in db.frames] ...
Get all PGN values for given frame. :param db: CanMatrix database :return: tuple of [pgn] and [arbitration_id]
list_pgn
python
ebroecker/canmatrix
src/canmatrix/join.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/join.py
BSD-2-Clause
def ids_sharing_same_pgn(id_x, pgn_x, id_y, pgn_y): # type: (typing.Sequence[canmatrix.ArbitrationId], typing.Sequence[int], typing.Sequence[canmatrix.ArbitrationId], typing.Sequence[int]) -> typing.Iterable[typing.Tuple[canmatrix.ArbitrationId, canmatrix.ArbitrationId]] """Yield arbitration ids which has the s...
Yield arbitration ids which has the same pgn.
ids_sharing_same_pgn
python
ebroecker/canmatrix
src/canmatrix/join.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/join.py
BSD-2-Clause
def setup_logger(): # type: () -> logging.Logger """Setup the root logger. Return the logger instance for possible further setting and use. To be used from CLI scripts only. """ formatter = logging.Formatter( fmt='%(levelname)s - %(module)s - %(message)s') handler = logging.StreamHandler(...
Setup the root logger. Return the logger instance for possible further setting and use. To be used from CLI scripts only.
setup_logger
python
ebroecker/canmatrix
src/canmatrix/log.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/log.py
BSD-2-Clause
def set_log_level(logger, level): # type: (logging.Logger, int) -> None """Dynamic reconfiguration of the log level""" if level > 2: level = 2 elif level < -1: level = -1 levels = { -1: logging.ERROR, 0: logging.WARN, 1: logging.INFO, 2: logging.DEBUG ...
Dynamic reconfiguration of the log level
set_log_level
python
ebroecker/canmatrix
src/canmatrix/log.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/log.py
BSD-2-Clause
def quote_aware_comma_split(string): # type: (str) -> typing.List[str] """ Split a string containing comma separated list of fields. Removing surrounding whitespace, to allow fields to be separated by ", ". Preserves double quotes within fields, but not double quotes surrounding fields. Suppresses ...
Split a string containing comma separated list of fields. Removing surrounding whitespace, to allow fields to be separated by ", ". Preserves double quotes within fields, but not double quotes surrounding fields. Suppresses comma separators which are within double quoted sections. :param string: ('...
quote_aware_comma_split
python
ebroecker/canmatrix
src/canmatrix/utils.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/utils.py
BSD-2-Clause
def guess_value(text_value): # type: (str) -> str """ Get string value for common strings. Method is far from complete but helping with odd arxml files. :param text_value: value in text like "true" :return: string for value like "1" """ if sys.version_info >= (3, 0): text_value = t...
Get string value for common strings. Method is far from complete but helping with odd arxml files. :param text_value: value in text like "true" :return: string for value like "1"
guess_value
python
ebroecker/canmatrix
src/canmatrix/utils.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/utils.py
BSD-2-Clause
def get_gcd(value1, value2): # type (int,int) -> (int) """ Get greatest common divisor of value1 and value2 :param value1: int value 1 :param value2: int value 2 :return: cvt of value 1 and value 2 """ if sys.version_info >= (3, 5): return math.gcd(value1, value2) else: ...
Get greatest common divisor of value1 and value2 :param value1: int value 1 :param value2: int value 2 :return: cvt of value 1 and value 2
get_gcd
python
ebroecker/canmatrix
src/canmatrix/utils.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/utils.py
BSD-2-Clause
def decode_number(value, float_factory): # type(string) -> (int) """ Decode string to integer and guess correct base :param value: string input value :return: integer """ if value is None: return 0 value = value.strip() if ('.' in value) or (value.lower() in ["inf", "+inf", "-i...
Decode string to integer and guess correct base :param value: string input value :return: integer
decode_number
python
ebroecker/canmatrix
src/canmatrix/utils.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/utils.py
BSD-2-Clause
def cli_compare(matrix1, matrix2, verbosity, silent, check_comments, check_attributes, ignore_valuetables, frames): """ canmatrix.cli.compare [options] matrix1 matrix2 matrixX can be any of *.dbc|*.dbf|*.kcd|*.arxml|*.xls(x)|*.sym """ import canmatrix.log root_logger = canmatrix.log.se...
canmatrix.cli.compare [options] matrix1 matrix2 matrixX can be any of *.dbc|*.dbf|*.kcd|*.arxml|*.xls(x)|*.sym
cli_compare
python
ebroecker/canmatrix
src/canmatrix/cli/compare.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/cli/compare.py
BSD-2-Clause
def cli_convert(infile, outfile, silent, verbosity, **options): """ canmatrix.cli.convert [options] import-file export-file import-file: *.dbc|*.dbf|*.kcd|*.arxml|*.json|*.xls(x)|*.sym export-file: *.dbc|*.dbf|*.kcd|*.arxml|*.json|*.xls(x)|*.sym|*.py """ root_logger = canmatrix.log.setup_logg...
canmatrix.cli.convert [options] import-file export-file import-file: *.dbc|*.dbf|*.kcd|*.arxml|*.json|*.xls(x)|*.sym export-file: *.dbc|*.dbf|*.kcd|*.arxml|*.json|*.xls(x)|*.sym|*.py
cli_convert
python
ebroecker/canmatrix
src/canmatrix/cli/convert.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/cli/convert.py
BSD-2-Clause
def get_child(self, parent, tag_name): # type: (_Element, _Element, str) -> typing.Optional[_Element] """Get first sub-child or referenced sub-child with given name.""" # logger.debug("get_child: " + tag_name) if parent is None: return None ret = self.find(tag_name, p...
Get first sub-child or referenced sub-child with given name.
get_child
python
ebroecker/canmatrix
src/canmatrix/formats/arxml.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/formats/arxml.py
BSD-2-Clause
def get_base_type_of_signal(signal): # type: (canmatrix.Signal) -> typing.Tuple[str, int] """Get signal arxml-type and size based on the Signal properties.""" if signal.is_float: if signal.size > 32: create_type = "double" size = 64 else: create_type = "si...
Get signal arxml-type and size based on the Signal properties.
get_base_type_of_signal
python
ebroecker/canmatrix
src/canmatrix/formats/arxml.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/formats/arxml.py
BSD-2-Clause
def get_signals(signal_array, frame, ea, multiplex_id, float_factory, bit_offset=0): # type: (typing.Sequence[_Element], typing.Union[canmatrix.Frame, canmatrix.Pdu], Earxml, int, typing.Callable, int) -> None """Add signals from xml to the Frame.""" group_id = 1 if signal_array is None: # Empty signa...
Add signals from xml to the Frame.
get_signals
python
ebroecker/canmatrix
src/canmatrix/formats/arxml.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/formats/arxml.py
BSD-2-Clause
def update_frame_with_pdu_triggerings(frame, ea, frame_triggering, float_factory): # type: (canmatrix.Frame, Earxml, _Element, typing.Callable) -> None """Update frame with signals from PDU Triggerings.""" pdu_trigs = ea.follow_all_ref(frame_triggering, "PDU-TRIGGERINGS-REF") if pdu_trigs is not None: ...
Update frame with signals from PDU Triggerings.
update_frame_with_pdu_triggerings
python
ebroecker/canmatrix
src/canmatrix/formats/arxml.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/formats/arxml.py
BSD-2-Clause
def dump(db, f, **options): # type: (canmatrix.CanMatrix, typing.IO, **typing.Any) -> None """ export canmatrix-object as .sym file (compatible to PEAK-Systems) """ sym_encoding = options.get('symExportEncoding', 'iso-8859-1') ignore_encoding_errors = options.get("ignoreEncodingErrors", "strict") ...
export canmatrix-object as .sym file (compatible to PEAK-Systems)
dump
python
ebroecker/canmatrix
src/canmatrix/formats/sym.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/formats/sym.py
BSD-2-Clause
def __init_yaml(): """Lazy init yaml because canmatrix might not be fully loaded when loading this format.""" global _yaml_initialized if not _yaml_initialized: _yaml_initialized = True yaml.add_constructor(u'tag:yaml.org,2002:Frame', _frame_constructor) yaml.add_constructor(u'tag:ya...
Lazy init yaml because canmatrix might not be fully loaded when loading this format.
__init_yaml
python
ebroecker/canmatrix
src/canmatrix/formats/yaml.py
https://github.com/ebroecker/canmatrix/blob/master/src/canmatrix/formats/yaml.py
BSD-2-Clause
def test_sym(): """Test signal and frame encoding based on a .sym file The symbol file was created using the PCAN Symbol Editor. The reference transmissions were created using PCAN Explorer. The result message bytes were observed in PCAN-View. PCAN Symbol Editor v3.1.6.342 PCAN Explorer v5.3...
Test signal and frame encoding based on a .sym file The symbol file was created using the PCAN Symbol Editor. The reference transmissions were created using PCAN Explorer. The result message bytes were observed in PCAN-View. PCAN Symbol Editor v3.1.6.342 PCAN Explorer v5.3.4.823 PCAN-View v4...
test_sym
python
ebroecker/canmatrix
tests/test_frame_encoding.py
https://github.com/ebroecker/canmatrix/blob/master/tests/test_frame_encoding.py
BSD-2-Clause
def test_export_with_jsonall(default_matrix): """Check the jsonExportAll doesn't raise and export some additional field.""" matrix = default_matrix out_file = io.BytesIO() canmatrix.formats.dump(matrix, out_file, "json", jsonExportAll=True) data = out_file.getvalue().decode("utf-8") assert "my_v...
Check the jsonExportAll doesn't raise and export some additional field.
test_export_with_jsonall
python
ebroecker/canmatrix
tests/test_json.py
https://github.com/ebroecker/canmatrix/blob/master/tests/test_json.py
BSD-2-Clause
def index_rule_matches(features: FeatureSet, rule: "capa.rules.Rule", locations: Iterable[Address]): """ record into the given featureset that the given rule matched at the given locations. naively, this is just adding a MatchedRule feature; however, we also want to record matches for the rule's namesp...
record into the given featureset that the given rule matched at the given locations. naively, this is just adding a MatchedRule feature; however, we also want to record matches for the rule's namespaces. updates `features` in-place. doesn't modify the remaining arguments.
index_rule_matches
python
mandiant/capa
capa/engine.py
https://github.com/mandiant/capa/blob/master/capa/engine.py
Apache-2.0
def match(rules: list["capa.rules.Rule"], features: FeatureSet, addr: Address) -> tuple[FeatureSet, MatchResults]: """ match the given rules against the given features, returning an updated set of features and the matches. the updated features are just like the input, but extended to include the ma...
match the given rules against the given features, returning an updated set of features and the matches. the updated features are just like the input, but extended to include the match features (e.g. names of rules that matched). the given feature set is not modified; an updated copy is returned. ...
match
python
mandiant/capa
capa/engine.py
https://github.com/mandiant/capa/blob/master/capa/engine.py
Apache-2.0
def hex(n: int) -> str: """render the given number using upper case hex, like: 0x123ABC""" if n < 0: return f"-0x{(-n):X}" else: return f"0x{(n):X}"
render the given number using upper case hex, like: 0x123ABC
hex
python
mandiant/capa
capa/helpers.py
https://github.com/mandiant/capa/blob/master/capa/helpers.py
Apache-2.0
def stdout_redirector(stream): """ Redirect stdout at the C runtime level, which lets us handle native libraries that spam stdout. *But*, this only works on Linux! Otherwise will silently still write to stdout. So, try to upstream the fix when possible. Via: https://eli.thegreenplace.net/2015...
Redirect stdout at the C runtime level, which lets us handle native libraries that spam stdout. *But*, this only works on Linux! Otherwise will silently still write to stdout. So, try to upstream the fix when possible. Via: https://eli.thegreenplace.net/2015/redirecting-all-kinds-of-stdout-in-py...
stdout_redirector
python
mandiant/capa
capa/helpers.py
https://github.com/mandiant/capa/blob/master/capa/helpers.py
Apache-2.0
def _redirect_stdout(to_fd): """Redirect stdout to the given file descriptor.""" # Flush the C-level buffer stdout LIBC.fflush(C_STDOUT) # Flush and close sys.stdout - also closes the file descriptor (fd) sys.stdout.close() # Make original_stdout_fd point to the same file...
Redirect stdout to the given file descriptor.
_redirect_stdout
python
mandiant/capa
capa/helpers.py
https://github.com/mandiant/capa/blob/master/capa/helpers.py
Apache-2.0
def is_running_standalone() -> bool: """ are we running from a PyInstaller'd executable? if so, then we'll be able to access `sys._MEIPASS` for the packaged resources. """ # typically we only expect capa.main to be packaged via PyInstaller. # therefore, this *should* be in capa.main; however, ...
are we running from a PyInstaller'd executable? if so, then we'll be able to access `sys._MEIPASS` for the packaged resources.
is_running_standalone
python
mandiant/capa
capa/helpers.py
https://github.com/mandiant/capa/blob/master/capa/helpers.py
Apache-2.0
def is_cache_newer_than_rule_code(cache_dir: Path) -> bool: """ basic check to prevent issues if the rules cache is older than relevant rules code args: cache_dir: the cache directory containing cache files returns: True if latest cache file is newer than relevant rule cache code """ ...
basic check to prevent issues if the rules cache is older than relevant rules code args: cache_dir: the cache directory containing cache files returns: True if latest cache file is newer than relevant rule cache code
is_cache_newer_than_rule_code
python
mandiant/capa
capa/helpers.py
https://github.com/mandiant/capa/blob/master/capa/helpers.py
Apache-2.0
def is_supported_format(sample: Path) -> bool: """ Return if this is a supported file based on magic header values """ taste = sample.open("rb").read(0x100) return len(list(capa.features.extractors.common.extract_format(taste))) == 1
Return if this is a supported file based on magic header values
is_supported_format
python
mandiant/capa
capa/loader.py
https://github.com/mandiant/capa/blob/master/capa/loader.py
Apache-2.0
def get_workspace(path: Path, input_format: str, sigpaths: list[Path]): """ load the program at the given path into a vivisect workspace using the given format. also apply the given FLIRT signatures. supported formats: - pe - elf - shellcode 32-bit - shellcode 64-bit - aut...
load the program at the given path into a vivisect workspace using the given format. also apply the given FLIRT signatures. supported formats: - pe - elf - shellcode 32-bit - shellcode 64-bit - auto this creates and analyzes the workspace; however, it does *not* save the...
get_workspace
python
mandiant/capa
capa/loader.py
https://github.com/mandiant/capa/blob/master/capa/loader.py
Apache-2.0
def compute_dynamic_layout( rules: RuleSet, extractor: DynamicFeatureExtractor, capabilities: MatchResults ) -> rdoc.DynamicLayout: """ compute a metadata structure that links threads to the processes in which they're found. only collect the threads at which some rule matched. otherwise, we may...
compute a metadata structure that links threads to the processes in which they're found. only collect the threads at which some rule matched. otherwise, we may pollute the json document with a large amount of un-referenced data.
compute_dynamic_layout
python
mandiant/capa
capa/loader.py
https://github.com/mandiant/capa/blob/master/capa/loader.py
Apache-2.0
def compute_static_layout(rules: RuleSet, extractor: StaticFeatureExtractor, capabilities) -> rdoc.StaticLayout: """ compute a metadata structure that links basic blocks to the functions in which they're found. only collect the basic blocks at which some rule matched. otherwise, we may pollute the ...
compute a metadata structure that links basic blocks to the functions in which they're found. only collect the basic blocks at which some rule matched. otherwise, we may pollute the json document with a large amount of un-referenced data.
compute_static_layout
python
mandiant/capa
capa/loader.py
https://github.com/mandiant/capa/blob/master/capa/loader.py
Apache-2.0
def get_default_root() -> Path: """ get the file system path to the default resources directory. under PyInstaller, this comes from _MEIPASS. under source, this is the root directory of the project. """ # we only expect capa.main to be packaged within PyInstaller, # so we don't put this in a...
get the file system path to the default resources directory. under PyInstaller, this comes from _MEIPASS. under source, this is the root directory of the project.
get_default_root
python
mandiant/capa
capa/main.py
https://github.com/mandiant/capa/blob/master/capa/main.py
Apache-2.0
def get_default_signatures() -> list[Path]: """ compute a list of file system paths to the default FLIRT signatures. """ sigs_path = get_default_root() / "sigs" logger.debug("signatures path: %s", sigs_path) ret = [] for file in sigs_path.rglob("*"): if file.is_file() and file.suffi...
compute a list of file system paths to the default FLIRT signatures.
get_default_signatures
python
mandiant/capa
capa/main.py
https://github.com/mandiant/capa/blob/master/capa/main.py
Apache-2.0
def simple_message_exception_handler( exctype: type[BaseException], value: BaseException, traceback: TracebackType | None ): """ prints friendly message on unexpected exceptions to regular users (debug mode shows regular stack trace) """ if exctype is KeyboardInterrupt: print("KeyboardInter...
prints friendly message on unexpected exceptions to regular users (debug mode shows regular stack trace)
simple_message_exception_handler
python
mandiant/capa
capa/main.py
https://github.com/mandiant/capa/blob/master/capa/main.py
Apache-2.0
def install_common_args(parser, wanted=None): """ register a common set of command line arguments for re-use by main & scripts. these are things like logging/coloring/etc. also enable callers to opt-in to common arguments, like specifying the input file. this routine lets many script use the same l...
register a common set of command line arguments for re-use by main & scripts. these are things like logging/coloring/etc. also enable callers to opt-in to common arguments, like specifying the input file. this routine lets many script use the same language for cli arguments. see `handle_common_arg...
install_common_args
python
mandiant/capa
capa/main.py
https://github.com/mandiant/capa/blob/master/capa/main.py
Apache-2.0
def handle_common_args(args): """ handle the global config specified by `install_common_args`, such as configuring logging/coloring/etc. the following fields will be overwritten when present: - rules: file system path to rule files. - signatures: file system path to signature files. the...
handle the global config specified by `install_common_args`, such as configuring logging/coloring/etc. the following fields will be overwritten when present: - rules: file system path to rule files. - signatures: file system path to signature files. the following fields may be added: ...
handle_common_args
python
mandiant/capa
capa/main.py
https://github.com/mandiant/capa/blob/master/capa/main.py
Apache-2.0
def ensure_input_exists_from_cli(args): """ args: args: The parsed command line arguments from `install_common_args`. raises: ShouldExitError: if the program is invoked incorrectly and should exit. """ try: _ = get_file_taste(args.input_file) except IOError as e: # p...
args: args: The parsed command line arguments from `install_common_args`. raises: ShouldExitError: if the program is invoked incorrectly and should exit.
ensure_input_exists_from_cli
python
mandiant/capa
capa/main.py
https://github.com/mandiant/capa/blob/master/capa/main.py
Apache-2.0
def get_input_format_from_cli(args) -> str: """ Determine the format of the input file. Note: this may not be the same as the format of the sample. Cape, Freeze, etc. formats describe a sample without being the sample itself. args: args: The parsed command line arguments from `install_common...
Determine the format of the input file. Note: this may not be the same as the format of the sample. Cape, Freeze, etc. formats describe a sample without being the sample itself. args: args: The parsed command line arguments from `install_common_args`. raises: ShouldExitError: if the ...
get_input_format_from_cli
python
mandiant/capa
capa/main.py
https://github.com/mandiant/capa/blob/master/capa/main.py
Apache-2.0
def get_backend_from_cli(args, input_format: str) -> str: """ Determine the backend that should be used for the given input file. Respects an override provided by the user, otherwise, use a good default. args: args: The parsed command line arguments from `install_common_args`. input_format:...
Determine the backend that should be used for the given input file. Respects an override provided by the user, otherwise, use a good default. args: args: The parsed command line arguments from `install_common_args`. input_format: The file format of the input file. raises: ShouldExit...
get_backend_from_cli
python
mandiant/capa
capa/main.py
https://github.com/mandiant/capa/blob/master/capa/main.py
Apache-2.0
def get_sample_path_from_cli(args, backend: str) -> Optional[Path]: """ Determine the path to the underlying sample, if it exists. Note: this may not be the same as the input file. Cape, Freeze, etc. formats describe a sample without being the sample itself. args: args: The parsed command li...
Determine the path to the underlying sample, if it exists. Note: this may not be the same as the input file. Cape, Freeze, etc. formats describe a sample without being the sample itself. args: args: The parsed command line arguments from `install_common_args`. backend: The backend that wi...
get_sample_path_from_cli
python
mandiant/capa
capa/main.py
https://github.com/mandiant/capa/blob/master/capa/main.py
Apache-2.0
def get_os_from_cli(args, backend) -> str: """ Determine the OS for the given sample. Respects an override provided by the user, otherwise, use heuristics and algorithms to detect the OS. args: args: The parsed command line arguments from `install_common_args`. backend: The backend that...
Determine the OS for the given sample. Respects an override provided by the user, otherwise, use heuristics and algorithms to detect the OS. args: args: The parsed command line arguments from `install_common_args`. backend: The backend that will handle the input file. raises: Sh...
get_os_from_cli
python
mandiant/capa
capa/main.py
https://github.com/mandiant/capa/blob/master/capa/main.py
Apache-2.0
def get_rules_from_cli(args) -> RuleSet: """ args: args: The parsed command line arguments from `install_common_args`. raises: ShouldExitError: if the program is invoked incorrectly and should exit. """ enable_cache: bool = True try: if capa.helpers.is_running_standalone() a...
args: args: The parsed command line arguments from `install_common_args`. raises: ShouldExitError: if the program is invoked incorrectly and should exit.
get_rules_from_cli
python
mandiant/capa
capa/main.py
https://github.com/mandiant/capa/blob/master/capa/main.py
Apache-2.0
def get_file_extractors_from_cli(args, input_format: str) -> list[FeatureExtractor]: """ args: args: The parsed command line arguments from `install_common_args`. input_format: The file format of the input file. raises: ShouldExitError: if the program is invoked incorrectly and should exi...
args: args: The parsed command line arguments from `install_common_args`. input_format: The file format of the input file. raises: ShouldExitError: if the program is invoked incorrectly and should exit.
get_file_extractors_from_cli
python
mandiant/capa
capa/main.py
https://github.com/mandiant/capa/blob/master/capa/main.py
Apache-2.0
def find_static_limitations_from_cli(args, rules: RuleSet, file_extractors: list[FeatureExtractor]) -> bool: """ args: args: The parsed command line arguments from `install_common_args`. Only file-scoped feature extractors like pefile are used. Dynamic feature extractors can handle packed samples...
args: args: The parsed command line arguments from `install_common_args`. Only file-scoped feature extractors like pefile are used. Dynamic feature extractors can handle packed samples and do not need to be considered here. raises: ShouldExitError: if the program is invoked incorrectly an...
find_static_limitations_from_cli
python
mandiant/capa
capa/main.py
https://github.com/mandiant/capa/blob/master/capa/main.py
Apache-2.0
def find_dynamic_limitations_from_cli(args, rules: RuleSet, file_extractors: list[FeatureExtractor]) -> bool: """ Does the dynamic analysis describe some trace that we may not support well? For example, .NET samples detonated in a sandbox, which may rely on different API patterns than we currently describe ...
Does the dynamic analysis describe some trace that we may not support well? For example, .NET samples detonated in a sandbox, which may rely on different API patterns than we currently describe in our rules. args: args: The parsed command line arguments from `install_common_args`. raises: ...
find_dynamic_limitations_from_cli
python
mandiant/capa
capa/main.py
https://github.com/mandiant/capa/blob/master/capa/main.py
Apache-2.0
def get_extractor_from_cli(args, input_format: str, backend: str) -> FeatureExtractor: """ args: args: The parsed command line arguments from `install_common_args`. input_format: The file format of the input file. backend: The backend that will handle the input file. raises: ShouldE...
args: args: The parsed command line arguments from `install_common_args`. input_format: The file format of the input file. backend: The backend that will handle the input file. raises: ShouldExitError: if the program is invoked incorrectly and should exit.
get_extractor_from_cli
python
mandiant/capa
capa/main.py
https://github.com/mandiant/capa/blob/master/capa/main.py
Apache-2.0
def find_call_capabilities( ruleset: RuleSet, extractor: DynamicFeatureExtractor, ph: ProcessHandle, th: ThreadHandle, ch: CallHandle ) -> CallCapabilities: """ find matches for the given rules for the given call. """ # all features found for the call. features: FeatureSet = collections.defaultd...
find matches for the given rules for the given call.
find_call_capabilities
python
mandiant/capa
capa/capabilities/dynamic.py
https://github.com/mandiant/capa/blob/master/capa/capabilities/dynamic.py
Apache-2.0
def find_thread_capabilities( ruleset: RuleSet, extractor: DynamicFeatureExtractor, ph: ProcessHandle, th: ThreadHandle ) -> ThreadCapabilities: """ find matches for the given rules within the given thread, which includes matches for all the spans and calls within it. """ # all features found wi...
find matches for the given rules within the given thread, which includes matches for all the spans and calls within it.
find_thread_capabilities
python
mandiant/capa
capa/capabilities/dynamic.py
https://github.com/mandiant/capa/blob/master/capa/capabilities/dynamic.py
Apache-2.0
def find_process_capabilities( ruleset: RuleSet, extractor: DynamicFeatureExtractor, ph: ProcessHandle ) -> ProcessCapabilities: """ find matches for the given rules within the given process. """ # all features found within this process, # includes features found within threads (and calls). ...
find matches for the given rules within the given process.
find_process_capabilities
python
mandiant/capa
capa/capabilities/dynamic.py
https://github.com/mandiant/capa/blob/master/capa/capabilities/dynamic.py
Apache-2.0