(self)
load the state of the processor and analysis from the segments.

        the processor object may not be re-created, so we do our initializiation here.
        initialize the following fields:

          - self.buf
          - self.sections
          - self.functions
          - self.function_offsets
          - self.function_ranges
          - self.globals
          - self.branch_targets
load the state of the processor and analysis from the segments.
load the state of the processor and analysis from the segments .
def load(self):
        '''
        load the state of the processor and analysis from the segments.

        the processor object may not be re-created, so we do our initializiation here.
        initialize the following fields:

          - self.buf
          - self.sections
          - self.functions
          - self.function_offsets
          - self.function_ranges
          - self.globals
          - self.branch_targets
        '''
        logger.info('parsing sections')
        buf = []
        for ea in idautils.Segments():
            # assume all the segments are contiguous, which is what our loader does
            buf.append(idc.GetManyBytes(idc.SegStart(ea), idc.SegEnd(ea) - idc.SegStart(ea)))

        self.buf = b''.join(buf)
        self.sections = list(wasm.decode.decode_module(self.buf))

        logger.info('parsing types')
        self.types = self._parse_types()

        logger.info('parsing globals')
        self.globals = self._parse_globals()

        logger.info('parsing functions')
        self.functions = self._parse_functions()

        # map from function offset to function object
        self.function_offsets = {f['offset']: f for f in self.functions.values() if 'offset' in f}

        # map from (function start, function end) to function object
        self.function_ranges = {
            (f['offset'], f['offset'] + f['size']): f
            for f in self.functions.values()
            if 'offset' in f
        }

        logger.info('computing branch targets')
        self.branch_targets = self._compute_branch_targets()

        self.deferred_noflows = {}
        self.deferred_flows = {}

        for function in self.functions.values():
            name = function['name'].encode('utf-8')
            if 'offset' in function:
                idc.MakeName(function['offset'], name)
                # notify_emu will be invoked from here.
                idc.MakeCode(function['offset'])
                idc.MakeFunction(function['offset'], function['offset'] + function['size'])

            if function.get('exported'):
                # TODO: this should really be done in the loader.
                # though, at the moment, we do a lot more analysis here in the processor.
                idc.add_entry(function['index'], function['offset'], name, True)
def load ( self ) : logger . info ( 'parsing sections' ) buf = [ ] for ea in idautils . Segments ( ) : # assume all the segments are contiguous, which is what our loader does buf . append ( idc . GetManyBytes ( idc . SegStart ( ea ) , idc . SegEnd ( ea ) - idc . SegStart ( ea ) ) ) self . buf = b'' . join ( buf ) self . sections = list ( wasm . decode . decode_module ( self . buf ) ) logger . info ( 'parsing types' ) self . types = self . _parse_types ( ) logger . info ( 'parsing globals' ) self . globals = self . _parse_globals ( ) logger . info ( 'parsing functions' ) self . functions = self . _parse_functions ( ) # map from function offset to function object self . function_offsets = { f [ 'offset' ] : f for f in self . functions . values ( ) if 'offset' in f } # map from (function start, function end) to function object self . function_ranges = { ( f [ 'offset' ] , f [ 'offset' ] + f [ 'size' ] ) : f for f in self . functions . values ( ) if 'offset' in f } logger . info ( 'computing branch targets' ) self . branch_targets = self . _compute_branch_targets ( ) self . deferred_noflows = { } self . deferred_flows = { } for function in self . functions . values ( ) : name = function [ 'name' ] . encode ( 'utf-8' ) if 'offset' in function : idc . MakeName ( function [ 'offset' ] , name ) # notify_emu will be invoked from here. idc . MakeCode ( function [ 'offset' ] ) idc . MakeFunction ( function [ 'offset' ] , function [ 'offset' ] + function [ 'size' ] ) if function . get ( 'exported' ) : # TODO: this should really be done in the loader. # though, at the moment, we do a lot more analysis here in the processor. idc . add_entry ( function [ 'index' ] , function [ 'offset' ] , name , True )