module documentation
Module that provide util functions
Class |
|
Undocumented |
Class |
|
Undocumented |
Function | collate |
A helper function to iterate over multiple iterables yielding the same type of elements in a sorted way. |
Function | parse |
Takes a string input that is "format_spec"-like and parses it to its constituent. |
Variable | _ |
Undocumented |
Variable | _ |
Undocumented |
Variable | _ |
Undocumented |
def collate(iterables, key=(lambda a: a), reverse=False):
A helper function to iterate over multiple iterables yielding the same type of elements in a sorted way.
Examples
This is very useful to iterate over search results from multiple search queries. For example, iterating over all contexts where the associated symbol name contains 'acpi'.
>>> acpi_iterables = [reven_server.trace.search.symbol(symbol) for symbol in reven_server.ossi.symbols('acpi')] >>> for ctx in collate(acpi_iterables): ... print('#{}: {}'.format(ctx.transition_after().id, ctx.ossi.location().symbol)) #1471900994: HalAcpiGetTableDispatch #1471900999: HalpAcpiGetTable #1471901083: HalpAcpiGetTableWork #1471901099: HalpAcpiGetCachedTable #1471901168: HalpAcpiGetTableFromBios #1471903841: HalAcpiGetTableDispatch #1471903846: HalpAcpiGetTable #1471903930: HalpAcpiGetTableWork #1471903946: HalpAcpiGetCachedTable #1471903989: HalpAcpiIsCachedTableCompromised ...
Alternatively, using a kind of tag on iterable elements.
>>> from itertools import repeat >>> acpi_iterables = [zip(reven_server.trace.search.symbol(symbol), repeat(symbol.name)) for symbol in reven_server.ossi.symbols('acpi')] >>> for ctx, symbol in collate(acpi_iterables, key=lambda ctx_symbol: ctx_symbol[0]): ... print('#{}: {}'.format(ctx.transition_after().id, symbol)) #1471900994: HalAcpiGetTableDispatch #1471900999: HalpAcpiGetTable #1471901083: HalpAcpiGetTableWork #1471901099: HalpAcpiGetCachedTable #1471901168: HalpAcpiGetTableFromBios #1471903841: HalAcpiGetTableDispatch #1471903846: HalpAcpiGetTable #1471903930: HalpAcpiGetTableWork #1471903946: HalpAcpiGetCachedTable #1471903989: HalpAcpiIsCachedTableCompromised ...
Information
Parameters | |
iterables:_Iterable[ | A list of iterable yielding the same type of elements. |
key:_Callable[ | A lambda function that defines the key used to sort iterable elements. |
reverse:bool | Whether increasing or decreasing order. |
Returns | |
_Iterator[ | A generator of sorted iterable elements. |
def parse_colon_separated_key_values(values):
Takes a string input that is "format_spec"-like and parses it to its constituent.
The currently expected format is the following:
- The string is colon (":") separated at the top level.
- Each substring is itself composed of a key (an identifier) and a value, separated by the equal sign ("=").
- The key and value can be composed of any character except a colon or an equal sign.
Examples
>>> parse_colon_separated_key_values("toto=titi") {'toto': 'titi'} >>> parse_colon_separated_key_values("((x{~22=[{'{[##") {'((x{~22': "[{'{[##"} >>> parse_colon_separated_key_values("max_depth=1:current_depth=0") {'max_depth': '1', 'current_depth': '0'}
Parameters | |
values:str | Undocumented |
Returns | |
_Dict[ | Undocumented |