当前位置: 首页>>代码示例>>C++>>正文


C++ r_mem_copyendian函数代码示例

本文整理汇总了C++中r_mem_copyendian函数的典型用法代码示例。如果您正苦于以下问题:C++ r_mem_copyendian函数的具体用法?C++ r_mem_copyendian怎么用?C++ r_mem_copyendian使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了r_mem_copyendian函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: rap__read

static int rap__read(struct r_io_t *io, RIODesc *fd, ut8 *buf, int count) {
	RSocket *s = RIORAP_FD (fd);
	int ret;
	int i = (int)count;
	ut8 tmp[5];

	if (count>RMT_MAX)
		count = RMT_MAX;
	// send
	tmp[0] = RMT_READ;
	r_mem_copyendian (tmp+1, (ut8*)&count, 4, ENDIAN);
	r_socket_write (s, tmp, 5);
	r_socket_flush (s);
	// recv
	ret = r_socket_read_block (s, tmp, 5);
	if (ret != 5 || tmp[0] != (RMT_READ|RMT_REPLY)) {
		eprintf ("rap__read: Unexpected rap read reply "
			"(%d=0x%02x) expected (%d=0x%02x)\n",
			ret, tmp[0], 2, (RMT_READ|RMT_REPLY));
		return -1;
	}
	r_mem_copyendian ((ut8*)&i, tmp+1, 4, ENDIAN);
	if (i>count) {
		eprintf ("rap__read: Unexpected data size %d\n", i);
		return -1;
	}
	r_socket_read_block (s, buf, i);
	return count;
}
开发者ID:AitorATuin,项目名称:radare2,代码行数:29,代码来源:io_rap.c

示例2: check_bytes

static int check_bytes(const ut8* bytes, ut64 sz) {
	const ut8 *h;
	ut8 buf[4];
	int off, ret = R_FALSE;

	if (!bytes || sz < 0x300) {
		return R_FALSE;
	}
	memcpy (&off, bytes+4*sizeof (int), sizeof (int));
	r_mem_copyendian ((ut8*)&off, (ut8*)&off, sizeof(int), !LIL_ENDIAN);

	h = bytes;
	if (sz>=0x300 && !memcmp (h, "\xca\xfe\xba\xbe", 4)) {
		memcpy (&off, h+4*sizeof (int), sizeof (int));
		r_mem_copyendian ((ut8*)&off, (ut8*)&off, sizeof(int), !LIL_ENDIAN);
		if (off > 0 && off < sz) {
			memcpy (buf, h+off, 4);
			if (!memcmp (buf, "\xce\xfa\xed\xfe", 4) ||
				!memcmp (buf, "\xfe\xed\xfa\xce", 4) ||
				!memcmp (buf, "\xfe\xed\xfa\xcf", 4) ||
				!memcmp (buf, "\xcf\xfa\xed\xfe", 4))
				ret = R_TRUE;
		}
	}
	return ret;
}
开发者ID:CodingFree,项目名称:radare2,代码行数:26,代码来源:bin_xtr_fatmach0.c

示例3: r_buf_fcpy_at

static int r_buf_fcpy_at (RBuffer *b, ut64 addr, ut8 *buf, const char *fmt, int n, int write) {
	ut64 len, check_len;
	int i, j, k, tsize, endian, m = 1;
	if (!b || b->empty) return 0;
	if (addr == R_BUF_CUR)
		addr = b->cur;
	else addr -= b->base;
	if (addr == UT64_MAX || addr > b->length)
		return -1;
	tsize = 2;
	for (i = len = 0; i < n; i++)
	for (j = 0; fmt[j]; j++) {
		switch (fmt[j]) {
		case '0'...'9':
			if (m == 1)
				m = r_num_get (NULL, &fmt[j]);
			continue;
		case 's': tsize = 2; endian = 1; break;
		case 'S': tsize = 2; endian = 0; break;
		case 'i': tsize = 4; endian = 1; break;
		case 'I': tsize = 4; endian = 0; break;
		case 'l': tsize = 8; endian = 1; break;
		case 'L': tsize = 8; endian = 0; break;
		case 'c': tsize = 1; endian = 1; break;
		default: return -1;
		}

		/* Avoid read/write out of bound.
		   tsize and m are not user controled, then don't
		   need to check possible overflow.
		 */
		if (!UT64_ADD (&check_len, len, tsize*m))
			return -1;
		if (!UT64_ADD (&check_len, check_len, addr))
			return -1;
		if (check_len > b->length) {
			return check_len;
			// return -1;
		}

		for (k = 0; k < m; k++) {
			if (write) {
				r_mem_copyendian (
				(ut8*)&buf[addr+len+(k*tsize)],
				(ut8*)&b->buf[len+(k*tsize)],
				tsize, endian);
			} else {
				r_mem_copyendian (
				(ut8*)&buf[len+(k*tsize)],
				(ut8*)&b->buf[addr+len+(k*tsize)],
				tsize, endian);
			}
		}
		len += tsize*m;
		m = 1;
	}
	b->cur = addr + len;
	return len;
}
开发者ID:8500616886,项目名称:radare2,代码行数:59,代码来源:buf.c

示例4: r_core_rtr_cmd

R_API void r_core_rtr_cmd(RCore *core, const char *input) {
	char bufw[1024], bufr[8];
	const char *cmd = NULL, *cmd_output = NULL;
	int i, cmd_len, fd = atoi (input);

	if (*input==':' && !strchr (input+1, ':')) {
		r_core_cmdf (core, "o rap://%s", input);
		return;
	}
	if (fd != 0) {
		if (rtr_host[rtr_n].fd)
			for (rtr_n = 0; rtr_host[rtr_n].fd->fd != fd
				&& rtr_n < RTR_MAX_HOSTS - 1; rtr_n++);
		if (!(cmd = strchr (input, ' '))) {
			eprintf ("Error\n");
			return;
		}
	} else cmd = input;

	if (!rtr_host[rtr_n].fd){
		eprintf ("Error: Unknown host\n");
		core->num->value = 1; // fail
		return;
	}

	if (!rtr_host[rtr_n].proto == RTR_PROT_RAP){
		eprintf ("Error: Not a rap:// host\n");
		return;
	}

	core->num->value = 0; // that's fine
	if (!strlen (cmd)) {
		// just check if we can connect
		r_socket_close (rtr_host[rtr_n].fd);
		return;
	}
	/* send */
	bufw[0] = RTR_RAP_CMD;
	i = strlen (cmd) + 1;
	r_mem_copyendian ((ut8*)bufw+1, (ut8*)&i, 4, endian);
	memcpy (bufw+5, cmd, i);
	r_socket_write (rtr_host[rtr_n].fd, bufw, 5+i);
	/* read */
	r_socket_read (rtr_host[rtr_n].fd, (ut8*)bufr, 5);
	if (bufr[0] != (char)(RTR_RAP_CMD|RTR_RAP_REPLY)) {
		eprintf ("Error: Wrong reply\n");
		return;
	}
	r_mem_copyendian ((ut8*)&cmd_len, (ut8*)bufr+1, 4, endian);
	cmd_output = malloc (cmd_len);
	if (!cmd_output) {
		eprintf ("Error: Allocating cmd output\n");
		return;
	}
	r_socket_read (rtr_host[rtr_n].fd, (ut8*)cmd_output, cmd_len);
	r_cons_printf ("%s\n", cmd_output);
	free ((void *)cmd_output);
}
开发者ID:dialeth,项目名称:radare2,代码行数:58,代码来源:rtr.c

示例5: rap__system

static int rap__system(RIO *io, RIODesc *fd, const char *command) {
	RSocket *s = RIORAP_FD (fd);
	ut8 buf[RMT_MAX];
	char *ptr;
	int op, ret, i, j = 0;

	// send
	if (*command=='!') {
		op = RMT_SYSTEM;
		command++;
	} else
		op = RMT_CMD;
	buf[0] = op;
	i = strlen (command)+1;
	if (i>RMT_MAX) {
		eprintf ("Command too long\n");
		return -1;
	}
	r_mem_copyendian (buf+1, (ut8*)&i, 4, ENDIAN);
	memcpy (buf+5, command, i);
	r_socket_write (s, buf, i+5);
	r_socket_flush (s);

	// read
	ret = r_socket_read_block (s, buf, 5);
	if (ret != 5)
		return -1;
	if (buf[0] != (op | RMT_REPLY)) {
		eprintf ("Unexpected system reply\n");
		return -1;
	}
	r_mem_copyendian ((ut8*)&i, buf+1, 4, ENDIAN);
	if (i == -1)
		return -1;
	ret = 0;
	ptr = (char *)malloc (i);
	if (ptr) {
		int ir, tr = 0;
		do {
			ir = r_socket_read_block (s, (ut8*)ptr+tr, i-tr);
			if (ir>0) tr += ir;
			else break;
		} while (tr<i);
		// TODO: use io->printf() with support for \x00
		ptr[i] = 0;
		if (io->printf) {
			io->printf ("%s", ptr);
			j = i;
		} else j = write (1, ptr, i);
		free (ptr);
	}
	/* Clean */
	if (ret > 0) {
		ret -= r_socket_read (s, (ut8*)buf, RMT_MAX);
	}
	return i-j;
}
开发者ID:jahrome,项目名称:radare2,代码行数:57,代码来源:io_rap.c

示例6: assemble

// XXX: This is wrong, some opcodes are 32bit in thumb mode
static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
	int opcode = armass_assemble (buf, a->pc, (a->bits==16)?1:0);
	if (opcode==-1)
		return -1;
	if (a->bits==32)
		r_mem_copyendian (op->buf, (void *)&opcode, 4, a->big_endian);
	else r_mem_copyendian (op->buf, (void *)&opcode, 2, a->big_endian);
	return (a->bits/8);
}
开发者ID:adamnemecek,项目名称:radare2,代码行数:10,代码来源:asm_arm.c

示例7: r_core_rtr_cmd

R_API void r_core_rtr_cmd(RCore *core, const char *input) {
	char bufw[1024], bufr[8];
	const char *cmd = NULL, *cmd_output = NULL;
	int i, cmd_len, fd = atoi (input);

	if (fd != 0) {
		if (rtr_host[rtr_n].fd)
			for (rtr_n = 0; rtr_host[rtr_n].fd->fd != fd
				&& rtr_n < RTR_MAX_HOSTS; rtr_n++);
		if (!(cmd = strchr (input, ' '))) {
			eprintf ("Error\n");
			return;
		}
	} else cmd = input;

	if (!rtr_host[rtr_n].fd){
		eprintf ("Error: Unknown host\n");
		return;
	}

	if (!rtr_host[rtr_n].proto == RTR_PROT_RAP){
		eprintf ("Error: Not a rap:// host\n");
		return;
	}

	/* send */
	bufw[0] = RTR_RAP_CMD;
	i = strlen (cmd) + 1;
	r_mem_copyendian ((ut8*)bufw+1, (ut8*)&i, 4, endian);
	memcpy (bufw+5, cmd, i);
	r_socket_write (rtr_host[rtr_n].fd, bufw, 5+i);
	/* read */
	r_socket_read (rtr_host[rtr_n].fd, (ut8*)bufr, 5);
	if (bufr[0] != (char)(RTR_RAP_CMD|RTR_RAP_REPLY)) {
		eprintf ("Error: Wrong reply\n");
		return;
	}
	r_mem_copyendian ((ut8*)&cmd_len, (ut8*)bufr+1, 4, endian);
	if (i == 0)
		return;
	if (i < 0) {
		eprintf ("Error: cmd length < 0\n");
		return;
	}
	cmd_output = malloc (cmd_len);
	if (!cmd_output) {
		eprintf ("Error: Allocating cmd output\n");
		return;
	}
	r_socket_read (rtr_host[rtr_n].fd, (ut8*)cmd_output, cmd_len);
	r_cons_printf ("%s\n", cmd_output);
	free ((void *)cmd_output);
}
开发者ID:moon2l,项目名称:radare2,代码行数:53,代码来源:rtr.c

示例8: rap__system

static int rap__system(RIO *io, RIODesc *fd, const char *command) {
	RSocket *s = RIORAP_FD (fd);
	ut8 buf[RMT_MAX];
	char *ptr;
	int op, ret, i, j = 0;

	// send
	if (*command=='!') {
		op = RMT_SYSTEM;
		command++;
	} else
		op = RMT_CMD;
	buf[0] = op;
	i = strlen (command);
	if (i>RMT_MAX) {
		eprintf ("Command too long\n");
		return -1;
	}
	r_mem_copyendian (buf+1, (ut8*)&i, 4, ENDIAN);
	memcpy (buf+5, command, i);
	r_socket_write (s, buf, i+5);
	r_socket_flush (s);

	// read
	ret = r_socket_read_block (s, buf, 5);
	if (ret != 5)
		return -1;
	if (buf[0] != (op | RMT_REPLY)) {
		eprintf ("Unexpected system reply\n");
		return -1;
	}
	r_mem_copyendian ((ut8*)&i, buf+1, 4, ENDIAN);
	if (i == -1)
		return -1;
	ret = 0;
	if (i>RMT_MAX) {
		ret = i-RMT_MAX;
		i = RMT_MAX;
	}
	ptr = (char *)malloc (i);
	if (ptr) {
		r_socket_read_block (s, (ut8*)ptr, i);
		j = write (1, ptr, i);
		free (ptr);
	}
	/* Clean */
	if (ret > 0) {
		ret -= r_socket_read (s, (ut8*)buf, RMT_MAX);
	}
	return i-j;
}
开发者ID:0xroot,项目名称:radare2,代码行数:51,代码来源:io_rap.c

示例9: r_reg_set_double

R_API int r_reg_set_double(RReg *reg, RRegItem *item, long double value) {
	long double vld = 0.0f;
	ut8 *src;

	if (!item) {
		eprintf ("r_reg_set_value: item is NULL\n");
		return R_FALSE;
	}
	switch (item->size) {
	case 80:
		r_mem_copyendian ( (ut8*)&vld, (ut8*)&value, 10, !reg->big_endian);
		src = (ut8*)&vld;
		break;
	default:
		eprintf ("r_reg_set_double : Bit size %d not supported\n", item->size);
		return R_FALSE;
	}
	if (reg->regset[item->type].arena->size - BITS2BYTES (item->offset) - BITS2BYTES(item->size)>=0) {
		r_mem_copybits (reg->regset[item->type].arena->bytes+
				BITS2BYTES (item->offset), src, item->size);
		return R_TRUE;
	}
	eprintf ("r_reg_set_value: Cannot set %s to %Lf\n", item->name, value);
	return R_FALSE;
}
开发者ID:Kakkoroid,项目名称:radare2,代码行数:25,代码来源:double.c

示例10: format_output

static int format_output (char mode, ut64 n) {
	char *str = (char*) &n;
	char strbits[65];

	if (flags & 2)
		r_mem_copyendian ((ut8*) str, (ut8*) str, 4, 0);
	switch (mode) {
	case 'I':
		printf ("%"PFMT64d"\n", n);
		break;
	case '0':
		printf ("0x%"PFMT64x"\n", n);
		break;
	case 'F':
		printf ("%ff\n", (float)(ut32)n);
		break;
	case 'B':
		if (n) {
			r_num_to_bits (strbits, n);
			printf ("%sb\n", strbits);
		} else printf ("0b\n");
		break;
	case 'O':
		printf ("%"PFMT64o"\n", n);
		break;
	}
	return R_TRUE;
}
开发者ID:pixilla,项目名称:radare2,代码行数:28,代码来源:rax2.c

示例11: assemble

static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
	int opcode = armass_assemble (buf, a->pc, true);
	if (opcode==-1)
		return -1;
	r_mem_copyendian (op->buf, (void *)&opcode, 2, a->big_endian);
	return armthumb_length (opcode);
}
开发者ID:P4N74,项目名称:radare2-extras,代码行数:7,代码来源:asm_armthumb.c

示例12: r_num_htonq

R_API ut64 r_num_htonq(ut64 value) {
        ut64 ret = value;
#if LIL_ENDIAN
        r_mem_copyendian ((ut8*)&ret, (ut8*)&value, 8, 0);
#endif
        return ret;
}
开发者ID:ReverseLab,项目名称:radare2,代码行数:7,代码来源:num.c

示例13: r_mem_get_num

R_API ut64 r_mem_get_num(const ut8 *b, int size, int endian) {
        ut16 n16;
        ut32 n32;
        ut64 n64;
        switch (size) {
        case 1: return b[0];
        case 2:
                r_mem_copyendian ((ut8*)&n16, b, 2, endian);
		return (ut64)n16;
        case 4:
                r_mem_copyendian ((ut8*)&n32, b, 4, endian);
		return (ut64)n32;
        case 8:
                r_mem_copyendian ((ut8*)&n64, b, 8, endian);
		return (ut64)n64;
        }
	return 0LL;
}
开发者ID:8500616886,项目名称:radare2,代码行数:18,代码来源:mem.c

示例14: r_mem_set_num

// TODO: SEE: R_API ut64 r_reg_get_value(RReg *reg, RRegItem *item) { .. dupped code?
R_API int r_mem_set_num (ut8 *dest, int dest_size, ut64 num, int endian) {
	int num4;
	short num2;
	switch (dest_size) {
	case 1: dest[0] = (ut8) num;
		break;
	case 2: num2 = (short)num;
		r_mem_copyendian (dest, (const ut8*)&num2, 2, endian);
		break;
	case 4: num4 = (int)num;
		r_mem_copyendian (dest, (const ut8*)&num4, 4, endian);
		break;
	case 8: r_mem_copyendian (dest, (const ut8*)&num, 8, endian);
		break;
	default:
		return R_FALSE;
	}
	return R_TRUE;
}
开发者ID:8500616886,项目名称:radare2,代码行数:20,代码来源:mem.c

示例15: format_output

static int format_output (char mode, const char *s) {
	ut64 n = r_num_math (num, s);
	const char *str = (char*) &n;
	char strbits[65];

	if (flags & 2) {
		/* swap endian */
		ut32 n2 = (n>>32)? 8:4;
		r_mem_copyendian ((ut8*) str, (ut8*) str, n2, 0);
	}
开发者ID:bigos,项目名称:radare2,代码行数:10,代码来源:rax2.c


注:本文中的r_mem_copyendian函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。