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 dumps_static(extractor: StaticFeatureExtractor) -> str:
"""
serialize the given extractor to a string
"""
global_features: list[GlobalFeature] = []
for feature, _ in extractor.extract_global_features():
global_features.append(
GlobalFeature(
feature=feature_fr... |
serialize the given extractor to a string
| dumps_static | python | mandiant/capa | capa/features/freeze/__init__.py | https://github.com/mandiant/capa/blob/master/capa/features/freeze/__init__.py | Apache-2.0 |
def dumps_dynamic(extractor: DynamicFeatureExtractor) -> str:
"""
serialize the given extractor to a string
"""
global_features: list[GlobalFeature] = []
for feature, _ in extractor.extract_global_features():
global_features.append(
GlobalFeature(
feature=feature_... |
serialize the given extractor to a string
| dumps_dynamic | python | mandiant/capa | capa/features/freeze/__init__.py | https://github.com/mandiant/capa/blob/master/capa/features/freeze/__init__.py | Apache-2.0 |
def loads_static(s: str) -> StaticFeatureExtractor:
"""deserialize a set of features (as a NullStaticFeatureExtractor) from a string."""
freeze = Freeze.model_validate_json(s)
if freeze.version != CURRENT_VERSION:
raise ValueError(f"unsupported freeze format version: {freeze.version}")
assert f... | deserialize a set of features (as a NullStaticFeatureExtractor) from a string. | loads_static | python | mandiant/capa | capa/features/freeze/__init__.py | https://github.com/mandiant/capa/blob/master/capa/features/freeze/__init__.py | Apache-2.0 |
def loads_dynamic(s: str) -> DynamicFeatureExtractor:
"""deserialize a set of features (as a NullDynamicFeatureExtractor) from a string."""
freeze = Freeze.model_validate_json(s)
if freeze.version != CURRENT_VERSION:
raise ValueError(f"unsupported freeze format version: {freeze.version}")
asser... | deserialize a set of features (as a NullDynamicFeatureExtractor) from a string. | loads_dynamic | python | mandiant/capa | capa/features/freeze/__init__.py | https://github.com/mandiant/capa/blob/master/capa/features/freeze/__init__.py | Apache-2.0 |
def dumps(extractor: FeatureExtractor) -> str:
"""serialize the given extractor to a string."""
if isinstance(extractor, StaticFeatureExtractor):
doc = dumps_static(extractor)
elif isinstance(extractor, DynamicFeatureExtractor):
doc = dumps_dynamic(extractor)
else:
raise ValueErr... | serialize the given extractor to a string. | dumps | python | mandiant/capa | capa/features/freeze/__init__.py | https://github.com/mandiant/capa/blob/master/capa/features/freeze/__init__.py | Apache-2.0 |
def load(buf: bytes):
"""deserialize a set of features (as a NullFeatureExtractor) from a byte array."""
if not is_freeze(buf):
raise ValueError("missing magic header")
s = zlib.decompress(buf[len(MAGIC) :]).decode("utf-8")
return loads(s) | deserialize a set of features (as a NullFeatureExtractor) from a byte array. | load | python | mandiant/capa | capa/features/freeze/__init__.py | https://github.com/mandiant/capa/blob/master/capa/features/freeze/__init__.py | Apache-2.0 |
def create_namespace(namespace_str):
"""create new Ghidra namespace for each capa namespace"""
cmd = CreateNamespacesCmd(namespace_str, SourceType.USER_DEFINED)
cmd.applyTo(currentProgram()) # type: ignore [name-defined] # noqa: F821
return cmd.getNamespace() | create new Ghidra namespace for each capa namespace | create_namespace | python | mandiant/capa | capa/ghidra/capa_explorer.py | https://github.com/mandiant/capa/blob/master/capa/ghidra/capa_explorer.py | Apache-2.0 |
def create_label(ghidra_addr, name, capa_namespace):
"""custom label cmd to overlay symbols under capa-generated namespaces"""
# prevent duplicate labels under the same capa-generated namespace
symbol_table = currentProgram().getSymbolTable() # type: ignore [name-defined] # noqa: F821
for sym in symbo... | custom label cmd to overlay symbols under capa-generated namespaces | create_label | python | mandiant/capa | capa/ghidra/capa_explorer.py | https://github.com/mandiant/capa/blob/master/capa/ghidra/capa_explorer.py | Apache-2.0 |
def set_plate_comment(self, ghidra_addr):
"""set plate comments at matched functions"""
comment = getPlateComment(ghidra_addr) # type: ignore [name-defined] # noqa: F821
rule_path = self.namespace.replace(Namespace.DELIMITER, "/")
# 2 calls to avoid duplicate comments via subsequent scr... | set plate comments at matched functions | set_plate_comment | python | mandiant/capa | capa/ghidra/capa_explorer.py | https://github.com/mandiant/capa/blob/master/capa/ghidra/capa_explorer.py | Apache-2.0 |
def set_pre_comment(self, ghidra_addr, sub_type, description):
"""set pre comments at subscoped matches of main rules"""
comment = getPreComment(ghidra_addr) # type: ignore [name-defined] # noqa: F821
if comment is None:
comment = "capa: " + sub_type + "(" + description + ")" + ' ma... | set pre comments at subscoped matches of main rules | set_pre_comment | python | mandiant/capa | capa/ghidra/capa_explorer.py | https://github.com/mandiant/capa/blob/master/capa/ghidra/capa_explorer.py | Apache-2.0 |
def label_matches(self):
"""label findings at function scopes and comment on subscope matches"""
capa_namespace = create_namespace(self.namespace)
symbol_table = currentProgram().getSymbolTable() # type: ignore [name-defined] # noqa: F821
# handle function main scope of matched rule
... | label findings at function scopes and comment on subscope matches | label_matches | python | mandiant/capa | capa/ghidra/capa_explorer.py | https://github.com/mandiant/capa/blob/master/capa/ghidra/capa_explorer.py | Apache-2.0 |
def get_locations(match_dict):
"""recursively collect match addresses and associated nodes"""
for loc in match_dict.get("locations", {}):
# either an rva (absolute)
# or an offset into a file (file)
if loc.get("type", "") in ("absolute", "file"):
yield loc.get("value"), matc... | recursively collect match addresses and associated nodes | get_locations | python | mandiant/capa | capa/ghidra/capa_explorer.py | https://github.com/mandiant/capa/blob/master/capa/ghidra/capa_explorer.py | Apache-2.0 |
def parse_node(node_data):
"""pull match descriptions and sub features by parsing node dicts"""
node = node_data.get(node_data.get("type"))
if "description" in node:
yield "description", node.get("description")
data = node.get(node.get("type"))
if isinstance(data, (str, int)):
fea... | pull match descriptions and sub features by parsing node dicts | parse_node | python | mandiant/capa | capa/ghidra/capa_explorer.py | https://github.com/mandiant/capa/blob/master/capa/ghidra/capa_explorer.py | Apache-2.0 |
def is_func_start(ea):
"""check if function stat exists at virtual address"""
f = idaapi.get_func(ea)
return f and f.start_ea == ea | check if function stat exists at virtual address | is_func_start | python | mandiant/capa | capa/ida/helpers.py | https://github.com/mandiant/capa/blob/master/capa/ida/helpers.py | Apache-2.0 |
def load_and_verify_cached_results() -> Optional[rdoc.ResultDocument]:
"""verifies that cached results have valid (mapped) addresses for the current database"""
logger.debug("loading cached capa results from netnode '%s'", CAPA_NETNODE)
n = netnode.Netnode(CAPA_NETNODE)
doc = rdoc.ResultDocument.model_... | verifies that cached results have valid (mapped) addresses for the current database | load_and_verify_cached_results | python | mandiant/capa | capa/ida/helpers.py | https://github.com/mandiant/capa/blob/master/capa/ida/helpers.py | Apache-2.0 |
def OnCreate(self, form):
"""called when plugin form is created
load interface and install hooks but do not analyze database
"""
self.parent = self.FormToPyQtWidget(form)
pixmap = QtGui.QPixmap()
pixmap.loadFromData(ICON)
self.parent.setWindowIcon(QtGui.QIcon(p... | called when plugin form is created
load interface and install hooks but do not analyze database
| OnCreate | python | mandiant/capa | capa/ida/plugin/form.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/form.py | Apache-2.0 |
def Show(self):
"""creates form if not already create, else brings plugin to front"""
return super().Show(
self.form_title,
options=(
idaapi.PluginForm.WOPN_TAB
| idaapi.PluginForm.WOPN_RESTORE
| idaapi.PluginForm.WCLS_CLOSE_LATER
... | creates form if not already create, else brings plugin to front | Show | python | mandiant/capa | capa/ida/plugin/form.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/form.py | Apache-2.0 |
def ida_hook_rename(self, meta, post=False):
"""function hook for IDA "MakeName" and "EditFunction" actions
called twice, once before action and once after action completes
@param meta: dict of key/value pairs set when action first called (may be empty)
@param post: False if action fir... | function hook for IDA "MakeName" and "EditFunction" actions
called twice, once before action and once after action completes
@param meta: dict of key/value pairs set when action first called (may be empty)
@param post: False if action first call, True if action second call
| ida_hook_rename | python | mandiant/capa | capa/ida/plugin/form.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/form.py | Apache-2.0 |
def ida_hook_rebase(self, meta, post=False):
"""function hook for IDA "RebaseProgram" action
called twice, once before action and once after action completes
@param meta: dict of key/value pairs set when action first called (may be empty)
@param post: False if action first call, True i... | function hook for IDA "RebaseProgram" action
called twice, once before action and once after action completes
@param meta: dict of key/value pairs set when action first called (may be empty)
@param post: False if action first call, True if action second call
| ida_hook_rebase | python | mandiant/capa | capa/ida/plugin/form.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/form.py | Apache-2.0 |
def load_capa_rules(self):
"""load capa rules from directory specified by user, either using IDA UI or settings"""
if not self.ensure_capa_settings_rule_path():
return False
rule_path: Path = Path(settings.user.get(CAPA_SETTINGS_RULE_PATH, ""))
try:
def on_load_... | load capa rules from directory specified by user, either using IDA UI or settings | load_capa_rules | python | mandiant/capa | capa/ida/plugin/form.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/form.py | Apache-2.0 |
def load_capa_results(self, new_analysis, from_cache):
"""run capa analysis and render results in UI
note: this function must always return, exception or not, in order for plugin to safely close the IDA
wait box
"""
new_view_status: str = self.view_status_label.text()
se... | run capa analysis and render results in UI
note: this function must always return, exception or not, in order for plugin to safely close the IDA
wait box
| load_capa_results | python | mandiant/capa | capa/ida/plugin/form.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/form.py | Apache-2.0 |
def slot_progress_feature_extraction(text):
"""slot function to handle feature extraction progress updates"""
update_wait_box(f"{text} ({self.process_count} of {self.process_total})")
self.process_count += 1 | slot function to handle feature extraction progress updates | slot_progress_feature_extraction | python | mandiant/capa | capa/ida/plugin/form.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/form.py | Apache-2.0 |
def reset_view_tree(self):
"""reset tree view UI controls
called when user selects plugin reset from menu
"""
self.view_limit_results_by_function.setChecked(False)
# self.view_show_results_by_function.setChecked(False)
self.view_search_bar.setText("")
self.view_t... | reset tree view UI controls
called when user selects plugin reset from menu
| reset_view_tree | python | mandiant/capa | capa/ida/plugin/form.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/form.py | Apache-2.0 |
def slot_analyze(self):
"""run capa analysis and reload UI controls
called when user selects plugin reload from menu
"""
if self.view_tabs.currentIndex() == 0:
self.analyze_program()
elif self.view_tabs.currentIndex() == 1:
self.analyze_function() | run capa analysis and reload UI controls
called when user selects plugin reload from menu
| slot_analyze | python | mandiant/capa | capa/ida/plugin/form.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/form.py | Apache-2.0 |
def slot_reset(self):
"""reset UI elements
e.g. checkboxes and IDA highlighting
"""
if self.view_tabs.currentIndex() == 0:
self.reset_program_analysis_views()
elif self.view_tabs.currentIndex() == 1:
self.reset_function_analysis_views() | reset UI elements
e.g. checkboxes and IDA highlighting
| slot_reset | python | mandiant/capa | capa/ida/plugin/form.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/form.py | Apache-2.0 |
def slot_checkbox_limit_by_changed(self, state):
"""slot activated if checkbox clicked
if checked, configure function filter if screen location is located in function, otherwise clear filter
@param state: checked state
"""
if state == QtCore.Qt.Checked:
self.limit_r... | slot activated if checkbox clicked
if checked, configure function filter if screen location is located in function, otherwise clear filter
@param state: checked state
| slot_checkbox_limit_by_changed | python | mandiant/capa | capa/ida/plugin/form.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/form.py | Apache-2.0 |
def ask_user_directory(self):
"""create Qt dialog to ask user for a directory"""
return str(
QtWidgets.QFileDialog.getExistingDirectory(
self.parent, "Please select a capa rules directory", settings.user.get(CAPA_SETTINGS_RULE_PATH, "")
)
) | create Qt dialog to ask user for a directory | ask_user_directory | python | mandiant/capa | capa/ida/plugin/form.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/form.py | Apache-2.0 |
def __init__(self, screen_ea_changed_hook, action_hooks):
"""facilitate IDA UI hooks
@param screen_ea_changed_hook: function hook for IDA screen ea changed
@param action_hooks: dict of IDA action handles
"""
super().__init__()
self.screen_ea_changed_hook = screen_ea_cha... | facilitate IDA UI hooks
@param screen_ea_changed_hook: function hook for IDA screen ea changed
@param action_hooks: dict of IDA action handles
| __init__ | python | mandiant/capa | capa/ida/plugin/hooks.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/hooks.py | Apache-2.0 |
def preprocess_action(self, name):
"""called prior to action completed
@param name: name of action defined by idagui.cfg
@retval must be 0
"""
self.process_action_handle = self.process_action_hooks.get(name)
if self.process_action_handle:
self.process_actio... | called prior to action completed
@param name: name of action defined by idagui.cfg
@retval must be 0
| preprocess_action | python | mandiant/capa | capa/ida/plugin/hooks.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/hooks.py | Apache-2.0 |
def info_to_name(display):
"""extract root value from display name
e.g. function(my_function) => my_function
"""
try:
return display.split("(")[1].rstrip(")")
except IndexError:
return "" | extract root value from display name
e.g. function(my_function) => my_function
| info_to_name | python | mandiant/capa | capa/ida/plugin/item.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/item.py | Apache-2.0 |
def setIsEditable(self, isEditable=False):
"""modify item editable flags
@param isEditable: True, can edit, False cannot edit
"""
if isEditable:
self.flags |= QtCore.Qt.ItemIsEditable
else:
self.flags &= ~QtCore.Qt.ItemIsEditable | modify item editable flags
@param isEditable: True, can edit, False cannot edit
| setIsEditable | python | mandiant/capa | capa/ida/plugin/item.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/item.py | Apache-2.0 |
def data(self, column: int) -> Optional[str]:
"""get data at column
@param: column number
"""
try:
return self._data[column]
except IndexError:
return None | get data at column
@param: column number
| data | python | mandiant/capa | capa/ida/plugin/item.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/item.py | Apache-2.0 |
def location(self) -> Optional[int]:
"""return data stored in location column"""
try:
# address stored as str, convert to int before return
return int(self._data[1], 16)
except ValueError:
return None | return data stored in location column | location | python | mandiant/capa | capa/ida/plugin/item.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/item.py | Apache-2.0 |
def __init__(
self, parent: CapaExplorerDataItem, name: str, namespace: str, count: int, source: str, can_check=True
):
"""initialize item
@param parent: parent node
@param name: rule name
@param namespace: rule namespace
@param count: number of match for this rule
... | initialize item
@param parent: parent node
@param name: rule name
@param namespace: rule namespace
@param count: number of match for this rule
@param source: rule source (tooltip)
| __init__ | python | mandiant/capa | capa/ida/plugin/item.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/item.py | Apache-2.0 |
def __init__(self, parent: CapaExplorerDataItem, display: str, source=""):
"""initialize item
@param parent: parent node
@param display: text to display in UI
@param source: rule match source to display (tooltip)
"""
super().__init__(parent, [display, "", ""])
se... | initialize item
@param parent: parent node
@param display: text to display in UI
@param source: rule match source to display (tooltip)
| __init__ | python | mandiant/capa | capa/ida/plugin/item.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/item.py | Apache-2.0 |
def __init__(self, parent: CapaExplorerDataItem, location: Address, can_check=True):
"""initialize item
@param parent: parent node
@param location: virtual address of function as seen by IDA
"""
assert isinstance(location, AbsoluteVirtualAddress)
ea = int(location)
... | initialize item
@param parent: parent node
@param location: virtual address of function as seen by IDA
| __init__ | python | mandiant/capa | capa/ida/plugin/item.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/item.py | Apache-2.0 |
def __init__(self, parent: CapaExplorerDataItem, location: Address):
"""initialize item
@param parent: parent node
@param location: virtual address of basic block as seen by IDA
"""
assert isinstance(location, AbsoluteVirtualAddress)
ea = int(location)
super().__... | initialize item
@param parent: parent node
@param location: virtual address of basic block as seen by IDA
| __init__ | python | mandiant/capa | capa/ida/plugin/item.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/item.py | Apache-2.0 |
def __init__(
self, parent: CapaExplorerDataItem, display: str, details: str = "", location: Optional[Address] = None
):
"""initialize item
@param parent: parent node
@param display: text to display in UI
@param details: text to display in details section of UI
@para... | initialize item
@param parent: parent node
@param display: text to display in UI
@param details: text to display in details section of UI
@param location: virtual address as seen by IDA
| __init__ | python | mandiant/capa | capa/ida/plugin/item.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/item.py | Apache-2.0 |
def __init__(
self, parent: CapaExplorerDataItem, display: str, location: Optional[Address] = None, details: str = ""
):
"""initialize item
@param parent: parent node
@param display: text to display in UI
@param details: text to display in details section of UI
@para... | initialize item
@param parent: parent node
@param display: text to display in UI
@param details: text to display in details section of UI
@param location: virtual address as seen by IDA
| __init__ | python | mandiant/capa | capa/ida/plugin/item.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/item.py | Apache-2.0 |
def __init__(self, parent: CapaExplorerDataItem, display: str, location: Address):
"""initialize item
details section shows disassembly view for match
@param parent: parent node
@param display: text to display in UI
@param location: virtual address as seen by IDA
"""
... | initialize item
details section shows disassembly view for match
@param parent: parent node
@param display: text to display in UI
@param location: virtual address as seen by IDA
| __init__ | python | mandiant/capa | capa/ida/plugin/item.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/item.py | Apache-2.0 |
def __init__(self, parent: CapaExplorerDataItem, display: str, location: Address):
"""initialize item
details section shows byte preview for match
@param parent: parent node
@param display: text to display in UI
@param location: virtual address as seen by IDA
"""
... | initialize item
details section shows byte preview for match
@param parent: parent node
@param display: text to display in UI
@param location: virtual address as seen by IDA
| __init__ | python | mandiant/capa | capa/ida/plugin/item.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/item.py | Apache-2.0 |
def __init__(self, parent: CapaExplorerDataItem, display: str, location: Address, value: str):
"""initialize item
@param parent: parent node
@param display: text to display in UI
@param location: virtual address as seen by IDA
"""
assert isinstance(location, (AbsoluteVir... | initialize item
@param parent: parent node
@param display: text to display in UI
@param location: virtual address as seen by IDA
| __init__ | python | mandiant/capa | capa/ida/plugin/item.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/item.py | Apache-2.0 |
def reset(self):
"""reset UI elements (e.g. checkboxes, IDA color highlights)
called when view wants to reset UI display
"""
for idx in range(self.root_node.childCount()):
root_index = self.index(idx, 0, QtCore.QModelIndex())
for model_index in self.iterateChildr... | reset UI elements (e.g. checkboxes, IDA color highlights)
called when view wants to reset UI display
| reset | python | mandiant/capa | capa/ida/plugin/model.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/model.py | Apache-2.0 |
def columnCount(self, model_index):
"""return number of columns for the children of the given parent
@param model_index: QModelIndex
@retval column count
"""
if model_index.isValid():
return model_index.internalPointer().columnCount()
else:
retur... | return number of columns for the children of the given parent
@param model_index: QModelIndex
@retval column count
| columnCount | python | mandiant/capa | capa/ida/plugin/model.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/model.py | Apache-2.0 |
def data(self, model_index, role):
"""return data stored at given index by display role
this function is used to control UI elements (e.g. text font, color, etc.) based on column, item type, etc.
@param model_index: QModelIndex
@param role: QtCore.Qt.*
@retval data to be displ... | return data stored at given index by display role
this function is used to control UI elements (e.g. text font, color, etc.) based on column, item type, etc.
@param model_index: QModelIndex
@param role: QtCore.Qt.*
@retval data to be displayed
| data | python | mandiant/capa | capa/ida/plugin/model.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/model.py | Apache-2.0 |
def flags(self, model_index):
"""return item flags for given index
@param model_index: QModelIndex
@retval QtCore.Qt.ItemFlags
"""
if not model_index.isValid():
return QtCore.Qt.NoItemFlags
return model_index.internalPointer().flags | return item flags for given index
@param model_index: QModelIndex
@retval QtCore.Qt.ItemFlags
| flags | python | mandiant/capa | capa/ida/plugin/model.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/model.py | Apache-2.0 |
def headerData(self, section, orientation, role):
"""return data for the given role and section in the header with the specified orientation
@param section: int
@param orientation: QtCore.Qt.Orientation
@param role: QtCore.Qt.DisplayRole
@retval header data
"""
... | return data for the given role and section in the header with the specified orientation
@param section: int
@param orientation: QtCore.Qt.Orientation
@param role: QtCore.Qt.DisplayRole
@retval header data
| headerData | python | mandiant/capa | capa/ida/plugin/model.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/model.py | Apache-2.0 |
def index(self, row, column, parent):
"""return index of the item by row, column, and parent index
@param row: item row
@param column: item column
@param parent: QModelIndex of parent
@retval QModelIndex of item
"""
if not self.hasIndex(row, column, parent):
... | return index of the item by row, column, and parent index
@param row: item row
@param column: item column
@param parent: QModelIndex of parent
@retval QModelIndex of item
| index | python | mandiant/capa | capa/ida/plugin/model.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/model.py | Apache-2.0 |
def parent(self, model_index):
"""return parent index by child index
if the item has no parent, an invalid QModelIndex is returned
@param model_index: QModelIndex of child
@retval QModelIndex of parent
"""
if not model_index.isValid():
return QtCore.QModelI... | return parent index by child index
if the item has no parent, an invalid QModelIndex is returned
@param model_index: QModelIndex of child
@retval QModelIndex of parent
| parent | python | mandiant/capa | capa/ida/plugin/model.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/model.py | Apache-2.0 |
def iterateChildrenIndexFromRootIndex(self, model_index, ignore_root=True):
"""depth-first traversal of child nodes
@param model_index: QModelIndex of starting item
@param ignore_root: True, do not yield root index, False yield root index
@retval yield QModelIndex
"""
v... | depth-first traversal of child nodes
@param model_index: QModelIndex of starting item
@param ignore_root: True, do not yield root index, False yield root index
@retval yield QModelIndex
| iterateChildrenIndexFromRootIndex | python | mandiant/capa | capa/ida/plugin/model.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/model.py | Apache-2.0 |
def reset_ida_highlighting(self, item, checked):
"""reset IDA highlight for item
@param item: CapaExplorerDataItem
@param checked: True, item checked, False item not checked
"""
if not isinstance(
item,
(
CapaExplorerStringViewItem,
... | reset IDA highlight for item
@param item: CapaExplorerDataItem
@param checked: True, item checked, False item not checked
| reset_ida_highlighting | python | mandiant/capa | capa/ida/plugin/model.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/model.py | Apache-2.0 |
def setData(self, model_index, value, role):
"""set data at index by role
@param model_index: QModelIndex of item
@param value: value to set
@param role: QtCore.Qt.EditRole
"""
if not model_index.isValid():
return False
if (
role == QtCor... | set data at index by role
@param model_index: QModelIndex of item
@param value: value to set
@param role: QtCore.Qt.EditRole
| setData | python | mandiant/capa | capa/ida/plugin/model.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/model.py | Apache-2.0 |
def rowCount(self, model_index):
"""return number of rows under item by index
when the parent is valid it means that is returning the number of children of parent
@param model_index: QModelIndex
@retval row count
"""
if model_index.column() > 0:
return 0
... | return number of rows under item by index
when the parent is valid it means that is returning the number of children of parent
@param model_index: QModelIndex
@retval row count
| rowCount | python | mandiant/capa | capa/ida/plugin/model.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/model.py | Apache-2.0 |
def render_capa_doc_statement_node(
self,
parent: CapaExplorerDataItem,
match: rd.Match,
statement: rd.Statement,
locations: list[Address],
doc: rd.ResultDocument,
):
"""render capa statement read from doc
@param parent: parent to which new child is a... | render capa statement read from doc
@param parent: parent to which new child is assigned
@param statement: statement read from doc
@param locations: locations of children (applies to range only?)
@param doc: result doc
| render_capa_doc_statement_node | python | mandiant/capa | capa/ida/plugin/model.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/model.py | Apache-2.0 |
def render_capa_doc_match(self, parent: CapaExplorerDataItem, match: rd.Match, doc: rd.ResultDocument):
"""render capa match read from doc
@param parent: parent node to which new child is assigned
@param match: match read from doc
@param doc: result doc
"""
if not match.... | render capa match read from doc
@param parent: parent node to which new child is assigned
@param match: match read from doc
@param doc: result doc
| render_capa_doc_match | python | mandiant/capa | capa/ida/plugin/model.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/model.py | Apache-2.0 |
def render_capa_doc_by_function(self, doc: rd.ResultDocument):
"""render rule matches by function meaning each rule match is nested under function where it was found"""
matches_by_function: dict[AbsoluteVirtualAddress, tuple[CapaExplorerFunctionItem, set[str]]] = {}
for rule in rutils.capability... | render rule matches by function meaning each rule match is nested under function where it was found | render_capa_doc_by_function | python | mandiant/capa | capa/ida/plugin/model.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/model.py | Apache-2.0 |
def render_capa_doc(self, doc: rd.ResultDocument, by_function: bool):
"""render capa features specified in doc
@param doc: capa result doc
"""
# inform model that changes are about to occur
self.beginResetModel()
if by_function:
self.render_capa_doc_by_funct... | render capa features specified in doc
@param doc: capa result doc
| render_capa_doc | python | mandiant/capa | capa/ida/plugin/model.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/model.py | Apache-2.0 |
def capa_doc_feature_to_display(self, feature: frzf.Feature) -> str:
"""convert capa doc feature type string to display string for ui
@param feature: capa feature read from doc
"""
key = str(feature.type)
value = feature.dict(by_alias=True).get(feature.type)
if value:
... | convert capa doc feature type string to display string for ui
@param feature: capa feature read from doc
| capa_doc_feature_to_display | python | mandiant/capa | capa/ida/plugin/model.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/model.py | Apache-2.0 |
def render_capa_doc_feature_node(
self,
parent: CapaExplorerDataItem,
match: rd.Match,
feature: frzf.Feature,
locations: list[Address],
doc: rd.ResultDocument,
):
"""process capa doc feature node
@param parent: parent node to which child is assigned
... | process capa doc feature node
@param parent: parent node to which child is assigned
@param match: match information
@param feature: capa doc feature node
@param locations: locations identified for feature
@param doc: capa doc
| render_capa_doc_feature_node | python | mandiant/capa | capa/ida/plugin/model.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/model.py | Apache-2.0 |
def render_capa_doc_feature(
self,
parent: CapaExplorerDataItem,
match: rd.Match,
feature: frzf.Feature,
location: Address,
doc: rd.ResultDocument,
display="-",
):
"""render capa feature read from doc
@param parent: parent node to which new ch... | render capa feature read from doc
@param parent: parent node to which new child is assigned
@param match: match information
@param feature: feature read from doc
@param doc: capa feature doc
@param location: address of feature
@param display: text to display in plugin UI... | render_capa_doc_feature | python | mandiant/capa | capa/ida/plugin/model.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/model.py | Apache-2.0 |
def update_function_name(self, old_name, new_name):
"""update all instances of old function name with new function name
called when user updates function name using plugin UI
@param old_name: old function name
@param new_name: new function name
"""
# create empty root i... | update all instances of old function name with new function name
called when user updates function name using plugin UI
@param old_name: old function name
@param new_name: new function name
| update_function_name | python | mandiant/capa | capa/ida/plugin/model.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/model.py | Apache-2.0 |
def lessThan(self, left, right):
"""return True if left item is less than right item, else False
@param left: QModelIndex of left
@param right: QModelIndex of right
"""
ldata = left.internalPointer().data(left.column())
rdata = right.internalPointer().data(right.column()... | return True if left item is less than right item, else False
@param left: QModelIndex of left
@param right: QModelIndex of right
| lessThan | python | mandiant/capa | capa/ida/plugin/proxy.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/proxy.py | Apache-2.0 |
def filterAcceptsRow(self, row, parent):
"""return true if the item in the row indicated by the given row and parent should be included in the model;
otherwise return false
@param row: row number
@param parent: QModelIndex of parent
"""
if self.filter_accepts_row_self(ro... | return true if the item in the row indicated by the given row and parent should be included in the model;
otherwise return false
@param row: row number
@param parent: QModelIndex of parent
| filterAcceptsRow | python | mandiant/capa | capa/ida/plugin/proxy.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/proxy.py | Apache-2.0 |
def index_has_accepted_children(self, row, parent):
"""return True if parent has one or more children that match filter, else False
@param row: row number
@param parent: QModelIndex of parent
"""
model_index = self.sourceModel().index(row, 0, parent)
if model_index.isVa... | return True if parent has one or more children that match filter, else False
@param row: row number
@param parent: QModelIndex of parent
| index_has_accepted_children | python | mandiant/capa | capa/ida/plugin/proxy.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/proxy.py | Apache-2.0 |
def filter_accepts_row_self(self, row, parent):
"""return True if filter accepts row, else False
@param row: row number
@param parent: QModelIndex of parent
"""
# filter not set
if self.min_ea is None or self.max_ea is None:
return True
index = self.... | return True if filter accepts row, else False
@param row: row number
@param parent: QModelIndex of parent
| filter_accepts_row_self | python | mandiant/capa | capa/ida/plugin/proxy.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/proxy.py | Apache-2.0 |
def filterAcceptsRow(self, row, parent):
"""true if the item in the row indicated by the given row and parent
should be included in the model; otherwise returns false
@param row: int
@param parent: QModelIndex*
@retval True/False
"""
# this row matches, accept i... | true if the item in the row indicated by the given row and parent
should be included in the model; otherwise returns false
@param row: int
@param parent: QModelIndex*
@retval True/False
| filterAcceptsRow | python | mandiant/capa | capa/ida/plugin/proxy.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/proxy.py | Apache-2.0 |
def index_has_accepted_children(self, row, parent):
"""returns True if the given row or its children should be accepted"""
source_model = self.sourceModel()
model_index = source_model.index(row, 0, parent)
if model_index.isValid():
for idx in range(source_model.rowCount(mode... | returns True if the given row or its children should be accepted | index_has_accepted_children | python | mandiant/capa | capa/ida/plugin/proxy.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/proxy.py | Apache-2.0 |
def filter_accepts_row_self(self, row, parent):
"""returns True if the given row should be accepted"""
if self.query == "":
return True
source_model = self.sourceModel()
for column in (
CapaExplorerDataModel.COLUMN_INDEX_RULE_INFORMATION,
CapaExplore... | returns True if the given row should be accepted | filter_accepts_row_self | python | mandiant/capa | capa/ida/plugin/proxy.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/proxy.py | Apache-2.0 |
def count_previous_lines_from_block(self, block):
"""calculate number of lines preceding block"""
count = 0
while True:
block = block.previous()
if not block.isValid():
break
count += block.lineCount()
return count | calculate number of lines preceding block | count_previous_lines_from_block | python | mandiant/capa | capa/ida/plugin/view.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/view.py | Apache-2.0 |
def show_item_and_parents(_o):
"""iteratively show and expand an item and its' parents"""
while _o:
visited.append(_o)
if _o.isHidden():
_o.setHidden(False)
if _o.childCount() and not _o.isExpanded():
_o.setE... | iteratively show and expand an item and its' parents | show_item_and_parents | python | mandiant/capa | capa/ida/plugin/view.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/view.py | Apache-2.0 |
def reset_ui(self, should_sort=True):
"""reset user interface changes
called when view should reset UI display e.g. expand items, resize columns
@param should_sort: True, sort results after reset, False don't sort results after reset
"""
if should_sort:
self.sortByC... | reset user interface changes
called when view should reset UI display e.g. expand items, resize columns
@param should_sort: True, sort results after reset, False don't sort results after reset
| reset_ui | python | mandiant/capa | capa/ida/plugin/view.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/view.py | Apache-2.0 |
def map_index_to_source_item(self, model_index):
"""map proxy model index to source model item
@param model_index: QModelIndex
@retval QObject
"""
# assume that self.model here is either:
# - CapaExplorerDataModel, or
# - QSortFilterProxyModel subclass
... | map proxy model index to source model item
@param model_index: QModelIndex
@retval QObject
| map_index_to_source_item | python | mandiant/capa | capa/ida/plugin/view.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/view.py | Apache-2.0 |
def send_data_to_clipboard(self, data):
"""copy data to the clipboard
@param data: data to be copied
"""
clip = QtWidgets.QApplication.clipboard()
clip.clear(mode=clip.Clipboard)
clip.setText(data, mode=clip.Clipboard) | copy data to the clipboard
@param data: data to be copied
| send_data_to_clipboard | python | mandiant/capa | capa/ida/plugin/view.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/view.py | Apache-2.0 |
def new_action(self, display, data, slot):
"""create action for context menu
@param display: text displayed to user in context menu
@param data: data passed to slot
@param slot: slot to connect
@retval QAction
"""
action = QtWidgets.QAction(display, self.parent)... | create action for context menu
@param display: text displayed to user in context menu
@param data: data passed to slot
@param slot: slot to connect
@retval QAction
| new_action | python | mandiant/capa | capa/ida/plugin/view.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/view.py | Apache-2.0 |
def load_default_context_menu_actions(self, data):
"""yield actions specific to function custom context menu
@param data: tuple
@yield QAction
"""
default_actions = (
("Copy column", data, self.slot_copy_column),
("Copy row", data, self.slot_copy_row),
... | yield actions specific to function custom context menu
@param data: tuple
@yield QAction
| load_default_context_menu_actions | python | mandiant/capa | capa/ida/plugin/view.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/view.py | Apache-2.0 |
def load_function_context_menu_actions(self, data):
"""yield actions specific to function custom context menu
@param data: tuple
@yield QAction
"""
function_actions = (("Rename function", data, self.slot_rename_function),)
# add function actions
for action in f... | yield actions specific to function custom context menu
@param data: tuple
@yield QAction
| load_function_context_menu_actions | python | mandiant/capa | capa/ida/plugin/view.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/view.py | Apache-2.0 |
def load_default_context_menu(self, pos, item, model_index):
"""create default custom context menu
creates custom context menu containing default actions
@param pos: cursor position
@param item: CapaExplorerDataItem
@param model_index: QModelIndex
@retval QMenu
... | create default custom context menu
creates custom context menu containing default actions
@param pos: cursor position
@param item: CapaExplorerDataItem
@param model_index: QModelIndex
@retval QMenu
| load_default_context_menu | python | mandiant/capa | capa/ida/plugin/view.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/view.py | Apache-2.0 |
def load_function_item_context_menu(self, pos, item, model_index):
"""create function custom context menu
creates custom context menu with both default actions and function actions
@param pos: cursor position
@param item: CapaExplorerDataItem
@param model_index: QModelIndex
... | create function custom context menu
creates custom context menu with both default actions and function actions
@param pos: cursor position
@param item: CapaExplorerDataItem
@param model_index: QModelIndex
@retval QMenu
| load_function_item_context_menu | python | mandiant/capa | capa/ida/plugin/view.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/view.py | Apache-2.0 |
def slot_rename_function(self, action):
"""slot connected to custom context menu
allows user to select a edit a function name and push changes to IDA
@param action: QAction
"""
_, item, model_index = action.data()
# make item temporary edit, reset after user is finishe... | slot connected to custom context menu
allows user to select a edit a function name and push changes to IDA
@param action: QAction
| slot_rename_function | python | mandiant/capa | capa/ida/plugin/view.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/view.py | Apache-2.0 |
def slot_custom_context_menu_requested(self, pos):
"""slot connected to custom context menu request
displays custom context menu to user containing action relevant to the item selected
@param pos: cursor position
"""
model_index = self.indexAt(pos)
if not model_index.i... | slot connected to custom context menu request
displays custom context menu to user containing action relevant to the item selected
@param pos: cursor position
| slot_custom_context_menu_requested | python | mandiant/capa | capa/ida/plugin/view.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/view.py | Apache-2.0 |
def slot_double_click(self, model_index):
"""slot connected to double-click event
if address column clicked, navigate IDA to address, else un/expand item clicked
@param model_index: QModelIndex
"""
if not model_index.isValid():
return
item = self.map_index_... | slot connected to double-click event
if address column clicked, navigate IDA to address, else un/expand item clicked
@param model_index: QModelIndex
| slot_double_click | python | mandiant/capa | capa/ida/plugin/view.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/view.py | Apache-2.0 |
def init(self):
"""called when IDA is loading the plugin"""
logging.basicConfig(level=logging.INFO)
# do not load plugin unless hosted in idaq (IDA Qt)
if not idaapi.is_idaq():
# note: it does not appear that IDA calls "init" by default when hosted in idat; we keep this
... | called when IDA is loading the plugin | init | python | mandiant/capa | capa/ida/plugin/__init__.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/__init__.py | Apache-2.0 |
def run(self, arg):
"""
called when IDA is running the plugin as a script
args:
arg (int): bitflag. Setting LSB enables automatic analysis upon
loading. The other bits are currently undefined. See `form.Options`.
"""
if not self.form:
self.form = ... |
called when IDA is running the plugin as a script
args:
arg (int): bitflag. Setting LSB enables automatic analysis upon
loading. The other bits are currently undefined. See `form.Options`.
| run | python | mandiant/capa | capa/ida/plugin/__init__.py | https://github.com/mandiant/capa/blob/master/capa/ida/plugin/__init__.py | Apache-2.0 |
def width(s: str, character_count: int) -> str:
"""pad the given string to at least `character_count`"""
if len(s) < character_count:
return s + " " * (character_count - len(s))
else:
return s | pad the given string to at least `character_count` | width | python | mandiant/capa | capa/render/default.py | https://github.com/mandiant/capa/blob/master/capa/render/default.py | Apache-2.0 |
def find_subrule_matches(doc: rd.ResultDocument):
"""
collect the rule names that have been matched as a subrule match.
this way we can avoid displaying entries for things that are too specific.
"""
matches = set()
def rec(match: rd.Match):
if not match.success:
# there's pr... |
collect the rule names that have been matched as a subrule match.
this way we can avoid displaying entries for things that are too specific.
| find_subrule_matches | python | mandiant/capa | capa/render/default.py | https://github.com/mandiant/capa/blob/master/capa/render/default.py | Apache-2.0 |
def render_capabilities(doc: rd.ResultDocument, console: Console):
"""
example::
+-------------------------------------------------------+-------------------------------------------------+
| CAPABILITY | NAMESPACE ... |
example::
+-------------------------------------------------------+-------------------------------------------------+
| CAPABILITY | NAMESPACE |
|-------------------------------------------------------+-------... | render_capabilities | python | mandiant/capa | capa/render/default.py | https://github.com/mandiant/capa/blob/master/capa/render/default.py | Apache-2.0 |
def render_attack(doc: rd.ResultDocument, console: Console):
"""
example::
+------------------------+----------------------------------------------------------------------+
| ATT&CK Tactic | ATT&CK Technique |
|---------------... |
example::
+------------------------+----------------------------------------------------------------------+
| ATT&CK Tactic | ATT&CK Technique |
|------------------------+----------------------------------------------------------... | render_attack | python | mandiant/capa | capa/render/default.py | https://github.com/mandiant/capa/blob/master/capa/render/default.py | Apache-2.0 |
def render_maec(doc: rd.ResultDocument, console: Console):
"""
example::
+--------------------------+-----------------------------------------------------------+
| MAEC Category | MAEC Value |
|--------------------------+--------... |
example::
+--------------------------+-----------------------------------------------------------+
| MAEC Category | MAEC Value |
|--------------------------+-----------------------------------------------------------|
| ana... | render_maec | python | mandiant/capa | capa/render/default.py | https://github.com/mandiant/capa/blob/master/capa/render/default.py | Apache-2.0 |
def render_mbc(doc: rd.ResultDocument, console: Console):
"""
example::
+--------------------------+------------------------------------------------------------+
| MBC Objective | MBC Behavior |
|--------------------------+-------... |
example::
+--------------------------+------------------------------------------------------------+
| MBC Objective | MBC Behavior |
|--------------------------+------------------------------------------------------------|
| ... | render_mbc | python | mandiant/capa | capa/render/default.py | https://github.com/mandiant/capa/blob/master/capa/render/default.py | Apache-2.0 |
def capability_rules(doc: rd.ResultDocument) -> Iterator[rd.RuleMatches]:
"""enumerate the rules in (namespace, name) order that are 'capability' rules (not lib/subscope/disposition/etc)."""
for _, _, rule in sort_rules(doc.rules):
if rule.meta.lib:
continue
if (rule.meta.namespace o... | enumerate the rules in (namespace, name) order that are 'capability' rules (not lib/subscope/disposition/etc). | capability_rules | python | mandiant/capa | capa/render/utils.py | https://github.com/mandiant/capa/blob/master/capa/render/utils.py | Apache-2.0 |
def render_static_meta(console: Console, meta: rd.StaticMetadata):
"""
like:
md5 84882c9d43e23d63b82004fae74ebb61
sha1 c6fb3b50d946bec6f391aefa4e54478cf8607211
sha256 5eced7367ed63354b4ed5c556e2363514293f614c2c2eb187273381b2ef5f0f9
... |
like:
md5 84882c9d43e23d63b82004fae74ebb61
sha1 c6fb3b50d946bec6f391aefa4e54478cf8607211
sha256 5eced7367ed63354b4ed5c556e2363514293f614c2c2eb187273381b2ef5f0f9
path /tmp/suspicious.dll_
timestamp 202... | render_static_meta | python | mandiant/capa | capa/render/verbose.py | https://github.com/mandiant/capa/blob/master/capa/render/verbose.py | Apache-2.0 |
def render_dynamic_meta(console: Console, meta: rd.DynamicMetadata):
"""
like:
md5 84882c9d43e23d63b82004fae74ebb61
sha1 c6fb3b50d946bec6f391aefa4e54478cf8607211
sha256 5eced7367ed63354b4ed5c556e2363514293f614c2c2eb187273381b2ef5f0f9
... |
like:
md5 84882c9d43e23d63b82004fae74ebb61
sha1 c6fb3b50d946bec6f391aefa4e54478cf8607211
sha256 5eced7367ed63354b4ed5c556e2363514293f614c2c2eb187273381b2ef5f0f9
path /tmp/packed-report,jspn
timestamp ... | render_dynamic_meta | python | mandiant/capa | capa/render/verbose.py | https://github.com/mandiant/capa/blob/master/capa/render/verbose.py | Apache-2.0 |
def render_rules(console: Console, doc: rd.ResultDocument):
"""
like:
receive data (2 matches)
namespace communication
description all known techniques for receiving data from a potential C2 server
scope function
matches 0x10003A13
0x... |
like:
receive data (2 matches)
namespace communication
description all known techniques for receiving data from a potential C2 server
scope function
matches 0x10003A13
0x10003797
| render_rules | python | mandiant/capa | capa/render/verbose.py | https://github.com/mandiant/capa/blob/master/capa/render/verbose.py | Apache-2.0 |
def hanging_indent(s: str, indent: int) -> str:
"""
indent the given string, except the first line,
such as if the string finishes an existing line.
e.g.,
EXISTINGSTUFFHERE + hanging_indent("xxxx...", 1)
becomes:
EXISTINGSTUFFHERExxxxx
xxxxxx
xxxxxx
"""
... |
indent the given string, except the first line,
such as if the string finishes an existing line.
e.g.,
EXISTINGSTUFFHERE + hanging_indent("xxxx...", 1)
becomes:
EXISTINGSTUFFHERExxxxx
xxxxxx
xxxxxx
| hanging_indent | python | mandiant/capa | capa/render/vverbose.py | https://github.com/mandiant/capa/blob/master/capa/render/vverbose.py | Apache-2.0 |
def render_locations(
console: Console, layout: rd.Layout, locations: Iterable[frz.Address], indent: int, use_short_format: bool = False
):
"""
Render the given locations, such as virtual address or pid/tid/callid with process name.
If `use_short_format` is True:
render a small representation of th... |
Render the given locations, such as virtual address or pid/tid/callid with process name.
If `use_short_format` is True:
render a small representation of the given locations, such as just the call id,
assuming another region of output specified the full location details (like pid/tid).
In effect, ... | render_locations | python | mandiant/capa | capa/render/vverbose.py | https://github.com/mandiant/capa/blob/master/capa/render/vverbose.py | Apache-2.0 |
def collect_span_of_calls_locations(
match: rd.Match,
mode=MODE_SUCCESS,
):
"""
Find all the call locations used in a given span-of-calls match, recursively.
Useful to collect the events used to match a span-of-calls scoped rule.
"""
if not match.success:
return
for location in ... |
Find all the call locations used in a given span-of-calls match, recursively.
Useful to collect the events used to match a span-of-calls scoped rule.
| collect_span_of_calls_locations | python | mandiant/capa | capa/render/vverbose.py | https://github.com/mandiant/capa/blob/master/capa/render/vverbose.py | Apache-2.0 |
def render_rules(console: Console, doc: rd.ResultDocument):
"""
like:
## rules
check for OutputDebugString error
namespace anti-analysis/anti-debugging/debugger-detection
author michael.hunhoff@mandiant.com
static scope: function
dynamic scope: process
... |
like:
## rules
check for OutputDebugString error
namespace anti-analysis/anti-debugging/debugger-detection
author michael.hunhoff@mandiant.com
static scope: function
dynamic scope: process
mbc Anti-Behavioral Analysis::Detect Debugger::OutputD... | render_rules | python | mandiant/capa | capa/render/vverbose.py | https://github.com/mandiant/capa/blob/master/capa/render/vverbose.py | Apache-2.0 |
def cache_ruleset(cache_dir: Path, ruleset: capa.rules.RuleSet):
"""
cache the given ruleset to disk, using the given cache directory.
this can subsequently be reloaded via `load_cached_ruleset`,
assuming the capa version and rule content does not change.
callers should use this function to avoid t... |
cache the given ruleset to disk, using the given cache directory.
this can subsequently be reloaded via `load_cached_ruleset`,
assuming the capa version and rule content does not change.
callers should use this function to avoid the performance overhead
of validating rules on each run.
| cache_ruleset | python | mandiant/capa | capa/rules/cache.py | https://github.com/mandiant/capa/blob/master/capa/rules/cache.py | Apache-2.0 |
def load_cached_ruleset(cache_dir: Path, rule_contents: list[bytes]) -> Optional[capa.rules.RuleSet]:
"""
load a cached ruleset from disk, using the given cache directory.
the raw rule contents are required here to prove that the rules haven't changed
and to avoid stale cache entries.
callers shoul... |
load a cached ruleset from disk, using the given cache directory.
the raw rule contents are required here to prove that the rules haven't changed
and to avoid stale cache entries.
callers should use this function to avoid the performance overhead
of validating rules on each run.
| load_cached_ruleset | python | mandiant/capa | capa/rules/cache.py | https://github.com/mandiant/capa/blob/master/capa/rules/cache.py | Apache-2.0 |
def parse_range(s: str):
"""
parse a string "(0, 1)" into a range (min, max).
min and/or max may by None to indicate an unbound range.
"""
# we want to use `{` characters, but this is a dict in yaml.
if not s.startswith("("):
raise InvalidRule(f"invalid range: {s}")
if not s.endswit... |
parse a string "(0, 1)" into a range (min, max).
min and/or max may by None to indicate an unbound range.
| parse_range | python | mandiant/capa | capa/rules/__init__.py | https://github.com/mandiant/capa/blob/master/capa/rules/__init__.py | Apache-2.0 |
Subsets and Splits
Django Code with Docstrings
Filters Python code examples from Django repository that contain Django-related code, helping identify relevant code snippets for understanding Django framework usage patterns.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves specific code examples from the Flask repository but doesn't provide meaningful analysis or patterns beyond basic data retrieval.
HTTPX Repo Code and Docstrings
Retrieves specific code examples from the httpx repository, which is useful for understanding how particular libraries are used but doesn't provide broader analytical insights about the dataset.
Requests Repo Docstrings & Code
Retrieves code examples with their docstrings and file paths from the requests repository, providing basic filtering but limited analytical value beyond finding specific code samples.
Quart Repo Docstrings & Code
Retrieves code examples with their docstrings from the Quart repository, providing basic code samples but offering limited analytical value for understanding broader patterns or relationships in the dataset.