示例#1
0
 def __call__(self,
              context: interfaces.context.ContextInterface,
              config_path: str,
              requirement: interfaces.configuration.RequirementInterface,
              progress_callback: constants.ProgressCallback = None) -> None:
     if requirement.unsatisfied(context, config_path):
         if "pdbscan" not in context.symbol_space:
             context.symbol_space.append(
                 native.NativeTable("pdbscan", native.std_ctypes))
         # TODO: check if this is a windows symbol requirement, otherwise ignore it
         self._symbol_requirements = self.find_requirements(
             context, config_path, requirement,
             requirements.SymbolTableRequirement)
         potential_layers = self.find_virtual_layers_from_req(
             context=context,
             config_path=config_path,
             requirement=requirement)
         for sub_config_path, symbol_req in self._symbol_requirements:
             parent_path = interfaces.configuration.parent_path(
                 sub_config_path)
             if symbol_req.unsatisfied(context, parent_path):
                 valid_kernels = self.determine_valid_kernels(
                     context, potential_layers, progress_callback)
                 if valid_kernels:
                     self.recurse_symbol_fulfiller(context, valid_kernels,
                                                   progress_callback)
                     self.set_kernel_virtual_offset(context, valid_kernels)
    def _read_header(self) -> None:
        """Checks the vmware header to make sure it's valid."""
        if "vmware" not in self._context.symbol_space:
            self._context.symbol_space.append(native.NativeTable("vmware", native.std_ctypes))

        meta_layer = self.context.layers.get(self._meta_layer, None)
        header_size = struct.calcsize(self.header_structure)
        data = meta_layer.read(0, header_size)
        magic, unknown, groupCount = struct.unpack(self.header_structure, data)
        if magic not in [b"\xD2\xBE\xD2\xBE"]:
            raise VmwareFormatException(self.name, "Wrong magic bytes for Vmware layer: {}".format(repr(magic)))

        # TODO: Change certain structure sizes based on the version
        version = magic[1] & 0xf

        group_size = struct.calcsize(self.group_structure)

        groups = {}
        for group in range(groupCount):
            name, tag_location, _unknown = struct.unpack(
                self.group_structure, meta_layer.read(header_size + (group * group_size), group_size))
            name = name.rstrip(b"\x00")
            groups[name] = tag_location
        memory = groups[b"memory"]

        tags_read = False
        offset = memory
        tags = {}
        index_len = self._context.symbol_space.get_type("vmware!unsigned int").size
        while not tags_read:
            flags = ord(meta_layer.read(offset, 1))
            name_len = ord(meta_layer.read(offset + 1, 1))
            tags_read = (flags == 0) and (name_len == 0)
            if not tags_read:
                name = self._context.object("vmware!string",
                                            layer_name = self._meta_layer,
                                            offset = offset + 2,
                                            max_length = name_len)
                indicies_len = (flags >> 6) & 3
                indicies = []
                for index in range(indicies_len):
                    indicies.append(
                        self._context.object("vmware!unsigned int",
                                             offset = offset + name_len + 2 + (index * index_len),
                                             layer_name = self._meta_layer))
                data = self._context.object("vmware!unsigned int",
                                            layer_name = self._meta_layer,
                                            offset = offset + 2 + name_len + (indicies_len * index_len))
                tags[(name, tuple(indicies))] = (flags, data)
                offset += 2 + name_len + (indicies_len *
                                          index_len) + self._context.symbol_space.get_type("vmware!unsigned int").size

        if tags[("regionsCount", ())][1] == 0:
            raise VmwareFormatException(self.name, "VMware VMEM is not split into regions")
        for region in range(tags[("regionsCount", ())][1]):
            offset = tags[("regionPPN", (region, ))][1] * self._page_size
            mapped_offset = tags[("regionPageNum", (region, ))][1] * self._page_size
            length = tags[("regionSize", (region, ))][1] * self._page_size
            self._segments.append((offset, mapped_offset, length))
 def _get_natives(self) -> Optional[interfaces.symbols.NativeTableInterface]:
     """Determines the appropriate native_types to use from the JSON
     data."""
     native_dict = {}
     base_types = self._json_object['base_types']
     for base_type in base_types:
         # Void are ignored because voids are not a volatility primitive, they are a specific Volatility object
         if base_type != 'void':
             current = base_types[base_type]
             # TODO: Fix up the typing of this, it bugs out because of the tuple assignment
             if current['kind'] not in self.format_mapping:
                 raise ValueError("Unsupported base kind")
             format_val = (current['size'], current['endian'], current['signed'])
             object_type = self.format_mapping[current['kind']]
             if base_type == 'pointer':
                 object_type = objects.Pointer
             native_dict[base_type] = (object_type, format_val)
     return native.NativeTable(name = "native", native_dictionary = native_dict)