Esempio n. 1
0
    def pointer(self, arch, t, const=None, volatile=None, ref_type=None):
        if const is None:
            const = BoolWithConfidence(False, confidence=0)
        elif not isinstance(const, BoolWithConfidence):
            const = BoolWithConfidence(const)

        if volatile is None:
            volatile = BoolWithConfidence(False, confidence=0)
        elif not isinstance(volatile, BoolWithConfidence):
            volatile = BoolWithConfidence(volatile)

        if ref_type is None:
            ref_type = ReferenceType.PointerReferenceType

        type_conf = core.BNTypeWithConfidence()
        type_conf.type = t.handle
        type_conf.confidence = t.confidence

        const_conf = core.BNBoolWithConfidence()
        const_conf.value = const.value
        const_conf.confidence = const.confidence

        volatile_conf = core.BNBoolWithConfidence()
        volatile_conf.value = volatile.value
        volatile_conf.confidence = volatile.confidence

        return Type(
            core.BNCreatePointerType(arch.handle, type_conf, const_conf,
                                     volatile_conf, ref_type))
Esempio n. 2
0
	def replace(self, i, t, name = "", overwriteExisting = True):
		if not self._mutable:
			raise AttributeError("Finalized Structure object is immutable, use mutable_copy()")
		tc = core.BNTypeWithConfidence()
		tc.type = t.handle
		tc.confidence = t.confidence
		core.BNReplaceStructureBuilderMember(self._handle, i, tc, name, overwriteExisting)
Esempio n. 3
0
	def append(self, t, name = ""):
		if not self._mutable:
			raise AttributeError("Finalized Structure object is immutable, use mutable_copy()")
		tc = core.BNTypeWithConfidence()
		tc.type = t.handle
		tc.confidence = t.confidence
		core.BNAddStructureBuilderMember(self._handle, tc, name)
Esempio n. 4
0
    def function(self,
                 ret,
                 params,
                 calling_convention=None,
                 variable_arguments=None,
                 stack_adjust=None):
        """
		``function`` class method for creating an function Type.

		:param Type ret: width of the integer in bytes
		:param list(Type) params: list of parameter Types
		:param CallingConvention calling_convention: optional argument for function calling convention
		:param bool variable_arguments: optional argument for functions that have a variable number of arguments
		"""
        param_buf = (core.BNFunctionParameter * len(params))()
        for i in range(0, len(params)):
            if isinstance(params[i], Type):
                param_buf[i].name = ""
                param_buf[i].type = params[i].handle
                param_buf[i].typeConfidence = params[i].confidence
                param_buf[i].defaultLocation = True
            elif isinstance(params[i], FunctionParameter):
                param_buf[i].name = params[i].name
                param_buf[i].type = params[i].type.handle
                param_buf[i].typeConfidence = params[i].type.confidence
                if params[i].location is None:
                    param_buf[i].defaultLocation = True
                else:
                    param_buf[i].defaultLocation = False
                    param_buf[i].location.type = params[i].location.type
                    param_buf[i].location.index = params[i].location.index
                    param_buf[i].location.storage = params[i].location.storage
            else:
                param_buf[i].name = params[i][1]
                param_buf[i].type = params[i][0].handle
                param_buf[i].typeConfidence = params[i][0].confidence
                param_buf[i].defaultLocation = True

        ret_conf = core.BNTypeWithConfidence()
        ret_conf.type = ret.handle
        ret_conf.confidence = ret.confidence

        conv_conf = core.BNCallingConventionWithConfidence()
        if calling_convention is None:
            conv_conf.convention = None
            conv_conf.confidence = 0
        else:
            conv_conf.convention = calling_convention.handle
            conv_conf.confidence = calling_convention.confidence

        if variable_arguments is None:
            variable_arguments = BoolWithConfidence(False, confidence=0)
        elif not isinstance(variable_arguments, BoolWithConfidence):
            variable_arguments = BoolWithConfidence(variable_arguments)

        vararg_conf = core.BNBoolWithConfidence()
        vararg_conf.value = variable_arguments.value
        vararg_conf.confidence = variable_arguments.confidence

        if stack_adjust is None:
            stack_adjust = SizeWithConfidence(0, confidence=0)
        elif not isinstance(stack_adjust, SizeWithConfidence):
            stack_adjust = SizeWithConfidence(stack_adjust)

        stack_adjust_conf = core.BNOffsetWithConfidence()
        stack_adjust_conf.value = stack_adjust.value
        stack_adjust_conf.confidence = stack_adjust.confidence

        return Type(
            core.BNCreateFunctionType(ret_conf, conv_conf, param_buf,
                                      len(params), vararg_conf,
                                      stack_adjust_conf))
Esempio n. 5
0
 def array(self, t, count):
     type_conf = core.BNTypeWithConfidence()
     type_conf.type = t.handle
     type_conf.confidence = t.confidence
     return Type(core.BNCreateArrayType(type_conf, count))
Esempio n. 6
0
 def replace(self, i, t, name=""):
     tc = core.BNTypeWithConfidence()
     tc.type = t.handle
     tc.confidence = t.confidence
     core.BNReplaceStructureMember(self.handle, i, tc, name)
Esempio n. 7
0
 def insert(self, offset, t, name=""):
     tc = core.BNTypeWithConfidence()
     tc.type = t.handle
     tc.confidence = t.confidence
     core.BNAddStructureMemberAtOffset(self.handle, tc, name, offset)
Esempio n. 8
0
 def append(self, t, name=""):
     tc = core.BNTypeWithConfidence()
     tc.type = t.handle
     tc.confidence = t.confidence
     core.BNAddStructureMember(self.handle, tc, name)