Example #1
0
 def _get_module(state, pid, pc):
     try:
         return state.modules.get(pid, pc)
     except Exception as e:
         logger.error(e)
         mod = Module()
         mod.pid = pid
         return mod
Example #2
0
def _make_json_entry(header, item, state):
    """
    Combine a trace entry header and item into a single JSON-serializable
    entry. Return this entry as a ``dict``.

    Some things to note:
        * The header's ``size`` field is removed - it is not required in the
          JSON
        * Enums are replaced by their numerical value (so that they can be
          written to JSON)
    """

    # If the entry is a fork, then we have to make the child traces
    # JSON-serializable as well
    if header.type == TraceEntries_pb2.TRACE_FORK:
        children = {}
        for state_id, trace in item.children.items():
            new_state = state.clone()
            children[state_id] = _make_json_trace(trace, new_state)
        item = TraceEntryFork(children)
    elif header.type == TraceEntries_pb2.TRACE_OSINFO:
        state.modules.kernel_start = item.kernel_start
    elif header.type == TraceEntries_pb2.TRACE_MOD_LOAD:
        state.modules.add(Module(item))
    elif header.type == TraceEntries_pb2.TRACE_MOD_UNLOAD:
        try:
            state.modules.remove(Module(item))
        except Exception:
            pass

    header_dict = protobuf_to_dict(header, use_enum_labels=True)

    entry = header_dict.copy()

    if isinstance(item, TraceEntryFork):
        entry.update({'children': item.children})
    else:
        entry.update(protobuf_to_dict(item, use_enum_labels=True))

    try:
        mod = state.modules.get(header.pid, header.pc)
        rel_pc = mod.to_native(header.pc)
        if rel_pc:
            entry.update({'module': {'name': mod.path, 'pc': rel_pc}})
    except Exception as e:
        logger.debug('Error while computing module: %s', e)

    return entry
Example #3
0
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

import os
from unittest import TestCase
from s2e_env.execution_trace.modules import Module, ModuleMap, SectionDescriptor

sec11 = SectionDescriptor(None)
sec11.name = '.text'
sec11.runtime_load_base = 0x123000
sec11.native_load_base = 0xbadf000
sec11.size = 0x1234

mod1 = Module()
mod1.name = 'test1.exe'
mod1.path = r'c:\windows\test1.exe'
mod1.pid = 123
mod1.sections = [sec11]


class ModulesTestCase(TestCase):
    def test_module_add_remove(self):
        map = ModuleMap()

        map.add(mod1)
        actual_mod = map.get(123, 0x123000 + 1234)
        self.assertEqual(actual_mod, mod1)

        map1 = map.clone()
Example #4
0
 def _get_module(state, pid, pc):
     try:
         return state.modules.get(pid, pc)
     except Exception:
         return Module('<unknown>', '<unknown>', 0, 0, 0xffffffffffffffff, pid)