Пример #1
0
    def vfprintf(self, uc, FILE, format, va_list):
        # int vfprintf ( FILE * stream, const char * format, va_list arg );
        struct_FILE = memory_helpers.read_byte_array(uc, FILE, 18)
        c_string = memory_helpers.read_utf8(uc, format)

        args = []
        result_string = ""
        for i in range(0, len(c_string)):
            if c_string[i] == '%':
                if c_string[i + 1] == "d":
                    args.append(memory_helpers.read_uints(uc, va_list, 1)[0])
                elif c_string[i + 1] == "c":
                    args.append(
                        chr(memory_helpers.read_byte_array(uc, va_list, 1)[0]))
                elif c_string[i + 1] == "s":
                    s_addr = memory_helpers.read_ptr(uc, va_list)
                    args.append(memory_helpers.read_cString(uc, s_addr)[0])
                else:
                    result_string += c_string[i:i + 2]
                    # TODO more format support
                va_list += 4
                result_string += "{0[" + str(len(args) - 1) + "]}"
                continue
            if i >= 1:
                if c_string[i - 1] == '%' or c_string[i] == '%':
                    continue
            result_string += c_string[i]

        result_string = result_string.format(args)
        logger.debug("Called vfprintf(%r)" % result_string)
 def __process_vm_readv(self, mu, pid, local_iov, liovcnt, remote_iov, riovcnt, flag):
     '''
     struct iovec {
         void  *iov_base;    /* Starting address */
         size_t iov_len;     /* Number of bytes to transfer */
     };
     '''
     if (pid != self._getpid(mu)):
         raise NotImplementedError("__process_vm_readv return other process not support...")
     off_r = remote_iov
     b = b''
     for i in range(0, riovcnt):
         rbase = memory_helpers.read_ptr(mu, off_r)
         iov_len = memory_helpers.read_ptr(mu, off_r+4)
         tmp = memory_helpers.read_byte_array(mu, rbase, iov_len)
         b+=tmp
         #for j in range(0, liovcnt)
         off_r+=8
     #
     off_l = local_iov
     has_read = 0
     for j in range(0, liovcnt):
         lbase = memory_helpers.read_ptr(mu, off_l)
         liov_len = memory_helpers.read_ptr(mu, off_l+4)
         tmp = b[has_read:liov_len]
         has_read += len(tmp)
         off_l += 8
     #
     print(b)
     return has_read
    def _handle_write(self, mu, fd, buffer, count):
        if fd <= 2:
            raise NotImplementedError("Unsupported read operation for file descriptor %d." % fd)

        if fd not in self._file_descriptors:
            # TODO: Return valid error.
            raise NotImplementedError()

        file = self._file_descriptors[fd]
        data = memory_helpers.read_byte_array(mu, buffer, count)
        return os.write(file.descriptor, data)