(self, va_arg)
return string
Implement printf - based on the stored format specifier information, format the values from the arg getter function `args` into a string.

        :param va_arg:          A function which takes a type and returns the next argument of that type
        :return:                The result formatted string
Implement printf - based on the stored format specifier information, format the values from the arg getter function `args` into a string.
Implement printf - based on the stored format specifier information format the values from the arg getter function args into a string .
def replace(self, va_arg):
        """
        Implement printf - based on the stored format specifier information, format the values from the arg getter function `args` into a string.

        :param va_arg:          A function which takes a type and returns the next argument of that type
        :return:                The result formatted string
        """

        string = None

        for component in self.components:
            # if this is just concrete data
            if isinstance(component, bytes):
                string = self._add_to_string(string, self.parser.state.solver.BVV(component))
            elif isinstance(component, str):
                raise Exception("this branch should be impossible?")
            elif isinstance(component, claripy.ast.BV):  # pylint:disable=isinstance-second-argument-not-valid-type
                string = self._add_to_string(string, component)
            else:
                # okay now for the interesting stuff
                # what type of format specifier is it?
                fmt_spec = component
                if fmt_spec.spec_type == b's':
                    if fmt_spec.length_spec == b".*":
                        str_length = va_arg('size_t')
                    else:
                        str_length = None
                    str_ptr = va_arg('char*')
                    string = self._add_to_string(string, self._get_str_at(str_ptr, max_length=str_length))
                # integers, for most of these we'll end up concretizing values..
                else:
                    # ummmmmmm this is a cheap translation but I think it should work
                    i_val = va_arg('void*')
                    c_val = int(self.parser.state.solver.eval(i_val))
                    c_val &= (1 << (fmt_spec.size * 8)) - 1
                    if fmt_spec.signed and (c_val & (1 << ((fmt_spec.size * 8) - 1))):
                        c_val -= (1 << fmt_spec.size * 8)

                    if fmt_spec.spec_type in (b'd', b'i'):
                        s_val = str(c_val)
                    elif fmt_spec.spec_type == b'u':
                        s_val = str(c_val)
                    elif fmt_spec.spec_type == b'c':
                        s_val = chr(c_val & 0xff)
                    elif fmt_spec.spec_type == b'x':
                        s_val = hex(c_val)[2:]
                    elif fmt_spec.spec_type == b'o':
                        s_val = oct(c_val)[2:]
                    elif fmt_spec.spec_type == b'p':
                        s_val = hex(c_val)
                    else:
                        raise SimProcedureError("Unimplemented format specifier '%s'" % fmt_spec.spec_type)

                    if isinstance(fmt_spec.length_spec, int):
                        s_val = s_val.rjust(fmt_spec.length_spec, fmt_spec.pad_chr)

                    string = self._add_to_string(string, self.parser.state.solver.BVV(s_val.encode()))

        return string
def replace ( self , va_arg ) : string = None for component in self . components : # if this is just concrete data if isinstance ( component , bytes ) : string = self . _add_to_string ( string , self . parser . state . solver . BVV ( component ) ) elif isinstance ( component , str ) : raise Exception ( "this branch should be impossible?" ) elif isinstance ( component , claripy . ast . BV ) : # pylint:disable=isinstance-second-argument-not-valid-type string = self . _add_to_string ( string , component ) else : # okay now for the interesting stuff # what type of format specifier is it? fmt_spec = component if fmt_spec . spec_type == b's' : if fmt_spec . length_spec == b".*" : str_length = va_arg ( 'size_t' ) else : str_length = None str_ptr = va_arg ( 'char*' ) string = self . _add_to_string ( string , self . _get_str_at ( str_ptr , max_length = str_length ) ) # integers, for most of these we'll end up concretizing values.. else : # ummmmmmm this is a cheap translation but I think it should work i_val = va_arg ( 'void*' ) c_val = int ( self . parser . state . solver . eval ( i_val ) ) c_val &= ( 1 << ( fmt_spec . size * 8 ) ) - 1 if fmt_spec . signed and ( c_val & ( 1 << ( ( fmt_spec . size * 8 ) - 1 ) ) ) : c_val -= ( 1 << fmt_spec . size * 8 ) if fmt_spec . spec_type in ( b'd' , b'i' ) : s_val = str ( c_val ) elif fmt_spec . spec_type == b'u' : s_val = str ( c_val ) elif fmt_spec . spec_type == b'c' : s_val = chr ( c_val & 0xff ) elif fmt_spec . spec_type == b'x' : s_val = hex ( c_val ) [ 2 : ] elif fmt_spec . spec_type == b'o' : s_val = oct ( c_val ) [ 2 : ] elif fmt_spec . spec_type == b'p' : s_val = hex ( c_val ) else : raise SimProcedureError ( "Unimplemented format specifier '%s'" % fmt_spec . spec_type ) if isinstance ( fmt_spec . length_spec , int ) : s_val = s_val . rjust ( fmt_spec . length_spec , fmt_spec . pad_chr ) string = self . _add_to_string ( string , self . parser . state . solver . BVV ( s_val . encode ( ) ) ) return string