• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ r_hex_str2bin函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: haret__read

static int haret__read(RIO *io, RIODesc *fd, ut8 *buf, int count) {
	char tmp[1024];
	int i = 0;
	ut64 off;
	st64 j;
	RSocket *s = HARET_FD (fd);

	off = io->off & -4;
	sprintf (tmp, "pdump 0x%"PFMT64x" %i\r\n", off, count+4);
	r_socket_write (s, tmp, strlen (tmp));
	r_socket_read_block (s, (unsigned char *) tmp, strlen (tmp)+1);
	j = (io->off - off)*2;
	while (i<count && j >= 0) {
		r_socket_read_block (s, (ut8*) tmp, 11);
		r_socket_read_block (s, (ut8*) tmp, 35);
		if (i+16 < count || (io->off-off) == 0) {
			tmp[35] = 0;
			i += r_hex_str2bin (tmp+j, buf+i);
			r_socket_read_block (s, (unsigned char *) tmp, 21);
		} else {
			tmp[(io->off - off)*2] = 0;
			i += r_hex_str2bin (tmp+j, buf+i);
		}
		j = 0;
	}
	haret_wait_until_prompt (s);
	return i;
}
开发者ID:Chelwin,项目名称:radare2-extras,代码行数:28,代码来源:io_haret.c


示例2: encrypt_or_decrypt_block

static bool encrypt_or_decrypt_block(RCore *core, const char *algo, const char *key, int direction, const char *iv) {
	//TODO: generalise no_key_mode for all non key encoding/decoding.
	int keylen = 0;
	bool no_key_mode = !strcmp ("base64", algo) || !strcmp ("base91", algo) || !strcmp ("punycode", algo);
	ut8 *binkey = NULL;
	if (!strncmp (key, "s:", 2)) {
		binkey = (ut8*)strdup (key + 2);
		keylen = strlen (key + 2);
	} else {
		binkey = (ut8 *)strdup (key);
		keylen = r_hex_str2bin (key, binkey);
	}
	if (!no_key_mode && keylen < 1) {
		eprintf ("%s key not defined. Use -S [key]\n", ((!direction) ? "Encryption" : "Decryption"));
		return false;
	}
	RCrypto *cry = r_crypto_new ();
	if (r_crypto_use (cry, algo)) {
		if (!binkey) {
			eprintf ("Cannot allocate %d byte(s)\n", keylen);
			r_crypto_free (cry);
			return false;
		}
		if (r_crypto_set_key (cry, binkey, keylen, 0, direction)) {
			if (iv) {
				ut8 *biniv = malloc (strlen (iv) + 1);
				int ivlen = r_hex_str2bin (iv, biniv);
				if (ivlen < 1) {
					ivlen = strlen(iv);
					strcpy ((char *)biniv, iv);
				}
				if (!r_crypto_set_iv (cry, biniv, ivlen)) {
					eprintf ("Invalid IV.\n");
					return 0;
				}
			}
			r_crypto_update (cry, (const ut8*)core->block, core->blocksize);
			r_crypto_final (cry, NULL, 0);

			int result_size = 0;
			ut8 *result = r_crypto_get_output (cry, &result_size);
			if (result) {
				r_io_write_at (core->io, core->offset, result, result_size);
				eprintf ("Written %d byte(s)\n", result_size);
				free (result);
			}
		} else {
			eprintf ("Invalid key\n");
		}
		free (binkey);
		r_crypto_free (cry);
		return 0;
	} else {
		eprintf ("Unknown %s algorithm '%s'\n", ((!direction) ? "encryption" : "decryption") ,algo);
	}
	r_crypto_free (cry);
	return 1;
}
开发者ID:agatti,项目名称:radare2,代码行数:58,代码来源:cmd_write.c


示例3: visual_search

// TODO: integrate in '/' command with search.inblock ?
static void visual_search (RCore *core) {
	const ut8 *p;
	int len, d = cursor;
	char str[128], buf[258];

	r_line_set_prompt ("search byte/string in block: ");
	r_cons_fgets (str, sizeof (str), 0, NULL);
	len = r_hex_str2bin (str, (ut8*)buf);
	if (*str=='"') {
		char *e = strncpy (buf, str+1, sizeof (buf)-1);
		if (e) { --e; if (*e=='"') *e=0; }
		len = strlen (buf);
	} else
	if (len<1) {
		strncpy (buf, str, sizeof (buf)-1);
		len = strlen (str);
	}
	p = r_mem_mem (core->block+d, core->blocksize-d,
		(const ut8*)buf, len);
	if (p) {
		cursor = (int)(size_t)(p-core->block);
		if (len>1) {
			ocursor = cursor+len-1;
		} else ocursor = -1;
		showcursor (core, true);
		eprintf ("FOUND IN %d\n", cursor);
		r_cons_any_key (NULL);
	} else {
		eprintf ("Cannot find bytes\n");
		r_cons_any_key (NULL);
		r_cons_clear00 ();
	}
}
开发者ID:xuwenbo,项目名称:radare2,代码行数:34,代码来源:visual.c


示例4: R_NEW

static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
	if (__plugin_open (io, pathname,0)) {
		RIOMalloc *mal = R_NEW (RIOMalloc);
		mal->fd = -2; /* causes r_io_desc_new() to set the correct fd */
		if (!strncmp (pathname, "hex://", 6)) {
			mal->size = strlen (pathname);
			mal->buf = malloc (mal->size+1);
			mal->offset = 0;
			memset (mal->buf, 0, mal->size);
			mal->size = r_hex_str2bin (pathname+6, mal->buf);
			if ((int)mal->size<1) {
				free (mal->buf);
				mal->buf = NULL;
			}
		} else {
			mal->size = r_num_math (NULL, pathname+9);
			if (((int)mal->size) <= 0) {
				free (mal);
				eprintf ("Cannot allocate (%s) 0 bytes\n", pathname+9);
				return NULL;
			}
			mal->offset = 0;
			mal->buf = calloc (1, mal->size+1);
		}
		if (mal->buf != NULL) {
			RETURN_IO_DESC_NEW (&r_io_plugin_malloc,
				mal->fd, pathname, rw, mode,mal);
		}
		eprintf ("Cannot allocate (%s) %d bytes\n", pathname+9, mal->size);
		free (mal);
	}
	return NULL;
}
开发者ID:13572293130,项目名称:radare2,代码行数:33,代码来源:io_malloc.c


示例5: R_NEW

static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
	if (__plugin_open (io, pathname, 0)) {
		const char *hostport = pathname + 6;
		RIOKdp *mal = R_NEW (RIOKdp);
		mal->fd = -2; /* causes r_io_desc_new() to set the correct fd */
		eprintf ("HOST:PORT = %s", hostport);
		//mal->sock = r_socket_new();
		mal->size = strlen (pathname);
		mal->buf = malloc (mal->size+1);
		mal->offset = 0;
		memset (mal->buf, 0, mal->size);
		mal->size = r_hex_str2bin (hostport, mal->buf);
		if ((int)mal->size<1) {
			free (mal->buf);
			mal->buf = NULL;
		}
		if (mal->buf != NULL) {
			RETURN_IO_DESC_NEW (&r_io_plugin_kdp,
				mal->fd, pathname, rw, mode,mal);
		}
		eprintf ("Cannot connect to %s\n", hostport);
		free (mal);
	}
	return NULL;
}
开发者ID:Chelwin,项目名称:radare2-extras,代码行数:25,代码来源:io_kdp.c


示例6: R_NEW

static RIODesc *__open(struct r_io_t *io, const char *pathname, int rw, int mode) {
	if (__plugin_open (io, pathname)) {
		RIOMalloc *mal = R_NEW (RIOMalloc);
		mal->fd = -2; /* causes r_io_desc_new() to set the correct fd */
		if (!memcmp (pathname, "hex://", 6)) {
			mal->size = strlen (pathname);
			mal->buf = malloc (mal->size);
			memset (mal->buf, 0, mal->size);
			mal->size = r_hex_str2bin (pathname+6, mal->buf);
		} else {
			mal->size = r_num_math (NULL, pathname+9);
			if ((mal->size)>0) {
				mal->buf = malloc (mal->size);
				memset (mal->buf, '\0', mal->size);
			} else {
				eprintf ("Cannot allocate (%s) 0 bytes\n", pathname+9);
				return NULL;
			}
		}
		if (mal->buf != NULL) {
			RETURN_IO_DESC_NEW(&r_io_plugin_malloc, mal->fd, pathname, rw, mode,mal);
			//return r_io_desc_new (&r_io_plugin_malloc, mal->fd, pathname, rw, mode, mal);
		}
		eprintf ("Cannot allocate (%s) %d bytes\n", pathname+9,
			mal->size);
		free (mal);
	}
	return NULL;
}
开发者ID:digdugg,项目名称:radare2,代码行数:29,代码来源:io_malloc.c


示例7: do_hash_seed

static void do_hash_seed(const char *seed) {
	const char *sptr = seed;
	if (!seed) {
		_s = NULL;
		return;
	}
	_s = &s;
	s.buf = (ut8*)malloc (strlen (seed)+128);
	if (!s.buf) {
		_s = NULL;
		return;
	}
	if (*seed=='^') {
		s.prefix = 1;
		sptr++;
	} else s.prefix = 0;
	if (!strncmp (sptr, "s:", 2)) {
		strcpy ((char*)s.buf, sptr+2);
		s.len = strlen (sptr+2);
	} else {
		s.len = r_hex_str2bin (sptr, s.buf);
		if (s.len<1) {
			strcpy ((char*)s.buf, sptr);
			s.len = strlen (sptr);
		}
	}
}
开发者ID:haoa193,项目名称:radare2,代码行数:27,代码来源:rahash2.c


示例8: r_hex_str2binmask

R_API int r_hex_str2binmask(const char *in, ut8 *out, ut8 *mask) {
	ut8 *ptr;
	int len, ilen = strlen (in)+1;
	int has_nibble = 0;
	memcpy (out, in, ilen);
	for (ptr=out; *ptr; ptr++) if (*ptr=='.') *ptr = '0';
	len = r_hex_str2bin ((char*)out, out);
	if (len<0) { has_nibble = 1; len = -len; }
	if (len != -1) {
		memcpy (mask, in, ilen);
		if (has_nibble)
			memcpy (mask+ilen, "f0", 3);
		for (ptr=mask; *ptr; ptr++) *ptr = (*ptr=='.')?'0':'f';
		len = r_hex_str2bin ((char*)mask, mask);
	}
	return len;
}
开发者ID:17twenty,项目名称:radare2,代码行数:17,代码来源:hex.c


示例9: r_search_keyword_new_hex

R_API RSearchKeyword* r_search_keyword_new_hex(const char *kwstr, const char *bmstr, const char *data) {
	RSearchKeyword *ks = NULL;
	ut8 *kw, *bm;
	int bmlen, kwlen;
	if (kwstr != NULL) {
		kw = malloc (strlen (kwstr)+1);
		bm = malloc (strlen (bmstr)+1);
		if (kw != NULL && bm != NULL) {
			bmlen = r_hex_str2bin (bmstr, (ut8*)bm);
			kwlen = r_hex_str2bin (kwstr, (ut8*)kw);
			if (bmlen>=0 && kwlen>0)
				ks = r_search_keyword_new (kw, kwlen, bm, bmlen, data);
		}
		free (kw);
		free (bm);
	}
	return ks;
}
开发者ID:codepongo,项目名称:radare2,代码行数:18,代码来源:keyword.c


示例10: __read

static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) {
	memset (buf, 0xff, count);
	if (RIOGDB_IS_VALID (fd)) {
		char *ptr = gdbwrap_readmem (RIOGDB_DESC (fd), (la32)io->off, count);
		if (ptr == NULL)
			return -1;
		return r_hex_str2bin (ptr, buf);
	}
	return -1;
}
开发者ID:jahrome,项目名称:radare2,代码行数:10,代码来源:io_gdb.c


示例11: r_core_write_op

R_API int r_core_write_op(RCore *core, const char *arg, char op) {
	char *str;
	ut8 *buf;
	int i, j, ret, len;

	// XXX we can work with config.block instead of dupping it
	buf = (ut8 *)malloc (core->blocksize);
	str = (char *)malloc (strlen(arg));
	if (buf == NULL || str == NULL) {
		free (buf);
		free (str);
		return R_FALSE;
	}
	memcpy (buf, core->block, core->blocksize);
	len = r_hex_str2bin (arg, (ut8 *)str);
	if (len==-1) {
		eprintf ("Invalid hexpair string\n");
		return R_FALSE;
	}

	if (op=='2' || op=='4') {
		op -= '0';
		for (i=0; i<core->blocksize; i+=op) {
			/* endian swap */
			ut8 tmp = buf[i];
			buf[i] = buf[i+3];
			buf[i+3] = tmp;
			if (op==4) {
				tmp = buf[i+1];
				buf[i+1] = buf[i+2];
				buf[i+2] = tmp;
			}
		}
	} else {
		for (i=j=0; i<core->blocksize; i++) {
			switch (op) {
			case 'x': buf[i] ^= str[j]; break;
			case 'a': buf[i] += str[j]; break;
			case 's': buf[i] -= str[j]; break;
			case 'm': buf[i] *= str[j]; break;
			case 'd': if (str[j]) buf[i] /= str[j];
				else buf[i] = 0; break;
			case 'r': buf[i] >>= str[j]; break;
			case 'l': buf[i] <<= str[j]; break;
			case 'o': buf[i] |= str[j]; break;
			case 'A': buf[i] &= str[j]; break;
			}
			j++; if (j>=len) j=0; /* cyclic key */
		}
	}

	ret = r_core_write_at (core, core->offset, buf, core->blocksize);
	free (buf);
	return ret;
}
开发者ID:ericfode,项目名称:radare2,代码行数:55,代码来源:io.c


示例12: rax

static int rax (char *str, int len, int last) {
	float f;
	char *p, *buf, out_mode = '0';
	int i;
	if (!len)
		len = strlen (str);

	if (*str=='-') {
		switch (str[1]) {
		case 's':
			flags ^= 1;
			break;
		case 'e':
			flags ^= 2;
			break;
		case 'S':
			flags ^= 4;
			break;
		case 'b':
			flags ^= 8;
			break;
		case 'x':
			flags ^= 16;
			break;
		case 'k':
			flags ^= 32;
			break;
		case 'v':
			printf ("rax2 v"R2_VERSION"\n");
			break;
		case '\0':
			return use_stdin ();
		default:
			printf ("Usage: rax2 [options] [expression]\n");
			return help ();
		}
		if (last)
			return use_stdin ();
		return R_TRUE;
	} else
	if (*str=='q')
		return R_FALSE;
	else
	if (*str=='h' || *str=='?')
		return help ();

	if (flags & 1) {
		ut64 n = ((strlen (str))>>1)+1;
		buf = malloc (sizeof (char) * n);
		memset (buf, '\0', n);
		n = r_hex_str2bin (str, (ut8*)buf);
		write (1, buf, n);
		free (buf);
		return R_TRUE;
	}
开发者ID:pixilla,项目名称:radare2,代码行数:55,代码来源:rax2.c


示例13: r_core_yank_hexpair

R_API bool r_core_yank_hexpair(RCore *core, const char *input) {
	if (!input || !*input) {
		return false;
	}
	char *out = strdup (input);
	int len = r_hex_str2bin (input, (ut8 *)out);
	if (len > 0) {
		r_core_yank_set (core, 0, (ut8 *)out, len);
	}
	free (out);
	return true;
}
开发者ID:csarn,项目名称:radare2,代码行数:12,代码来源:yank.c


示例14: switch

static char *getstr(const char *src) {
	int len;
	char *ret = NULL;

	switch (*src) {
	case '\'':
		ret = strdup (src+1);
		if (ret) {
			len = strlen (ret);
			if (len>0) {
				len--;
				if (ret[len]=='\'') {
					ret[len] = 0;
					return ret;
				} else eprintf ("Missing \"\n");
			}
			free (ret);
		}
		return NULL;
	case '"':
		ret = strdup (src+1);
		if (ret) {
			len = strlen (ret);
			if (len>0) {
				len--;
				if (ret[len]=='"') {
					ret[len] = 0;
					r_str_unescape (ret);
					return ret;
				} else eprintf ("Missing \"\n");
			}
			free (ret);
		}
		return NULL;
	case '@':
		// slurp file
		return r_file_slurp (src+1, NULL);
	case ':':
		// hexpairs
		ret = strdup (src);
		len = r_hex_str2bin (src+1, (ut8*)ret);
		if (len>0) {
			ret[len] = 0;
			return ret;
		} else {
			eprintf ("Invalid hexpair string\n");
			free (ret);
			return NULL;
		}
	}
	r_str_unescape ((ret = strdup (src)));
	return ret;
}
开发者ID:LucaBongiorni,项目名称:radare2,代码行数:53,代码来源:rarun2.c


示例15: r_asm_op_set_hex

R_API int r_asm_op_set_hex(RAsmOp *op, const char *str) {
	r_strbuf_set (&op->buf_hex, str);
	ut8 *bin = (ut8*)strdup (str);
	if (bin) {
		int len = r_hex_str2bin (str, bin);
		if (len > 0) {
			r_strbuf_setbin (&op->buf, bin, len);
		}
		free (bin);
		return len;
	}
	return 0;
}
开发者ID:aronsky,项目名称:radare2,代码行数:13,代码来源:op.c


示例16: r_search_keyword_new_hex

R_API RSearchKeyword* r_search_keyword_new_hex(const char *kwstr, const char *bmstr, const char *data) {
	RSearchKeyword *kw;
	ut8 *kwbuf, *bmbuf;
	int kwlen, bmlen = 0;

	if (!kwstr)
		return NULL;

	kwbuf = malloc (strlen (kwstr)+1);
	if (!kwbuf)
		return NULL;

	kwlen = r_hex_str2bin (kwstr, kwbuf);
	if (kwlen < 1) {
		free (kwbuf);
		return NULL;
	}

	bmbuf = NULL;
	if (bmstr) {
		bmbuf = malloc (strlen (bmstr)+1);
		if (!bmbuf) {
			free (kwbuf);
			return NULL;
		}
		bmlen = r_hex_str2bin (bmstr, bmbuf);
		if (bmlen < 1) {
			bmlen = -bmlen;
			free (bmbuf);
			free (kwbuf);
			return NULL;
		}
	}

	kw = r_search_keyword_new (kwbuf, kwlen, bmbuf, bmlen, data);
	free (kwbuf);
	free (bmbuf);
	return kw;
}
开发者ID:8500616886,项目名称:radare2,代码行数:39,代码来源:keyword.c


示例17: cmd_write_hexpair

R_API int cmd_write_hexpair(RCore* core, const char* pairs) {
	ut8 *buf = malloc (strlen (pairs));
	int len = r_hex_str2bin (pairs, buf);
	if (len != 0) {
		if (len < 0)
			len = -len + 1;
		if (len<core->blocksize)
			buf[len] = (core->block[len] & 0xf) | (buf[len] & 0xf0);
		r_core_write_at (core, core->offset, buf, len);
		if (r_config_get_i (core->config, "cfg.wseek"))
			r_core_seek_delta (core, len);
		r_core_block_read (core, 0);
	} else
		eprintf ("Error: invalid hexpair string\n");
	free (buf);

	return !!!len;
}
开发者ID:hidd3ncod3s,项目名称:radare2,代码行数:18,代码来源:cmd_write.c


示例18: encrypt_or_decrypt_block

static bool encrypt_or_decrypt_block(RCore *core, const char *algo, const char *key, int direction) {
	//TODO: generalise no_key_mode for all non key encoding/decoding.
	int keylen = key ? strlen (key): 0;
	bool no_key_mode = !strcmp ("base64", algo) || !strcmp ("base91", algo);
	if (no_key_mode || keylen > 0) {
		RCrypto *cry = r_crypto_new ();
		if (r_crypto_use (cry, algo)) {
			ut8 *binkey = malloc (keylen + 1);
			if (binkey) {
				int len = no_key_mode ? 1 : r_hex_str2bin (key, binkey);
				if (len < 1) {
					len = keylen;
					strcpy ((char *)binkey, key);
				} else {
					keylen = len;
				}
				if (r_crypto_set_key (cry, binkey, keylen, 0, direction)) {
					r_crypto_update (cry, (const ut8*)core->block, core->blocksize);
					r_crypto_final (cry, NULL, 0);

					int result_size = 0;
					ut8 *result = r_crypto_get_output (cry, &result_size);
					if (result) {
						r_io_write_at (core->io, core->offset, result, result_size);
						eprintf ("Written %d bytes\n", result_size);
						free (result);
					}
				} else {
					eprintf ("Invalid key\n");
				}
				free (binkey);
				return 0;
			} else {
				eprintf ("Cannot allocate %d bytes\n", keylen);
			}
		} else {
			eprintf ("Unknown %s algorithm '%s'\n", ((!direction) ? "encryption" : "decryption") ,algo);
		}
		r_crypto_free (cry);
	} else {
		eprintf ("%s key not defined. Use -S [key]\n", ((!direction) ? "Encryption" : "Decryption"));
	}
	return 1;
}
开发者ID:NaveenBoggarapu,项目名称:radare2,代码行数:44,代码来源:cmd_write.c


示例19: __read

static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) {
	int code, rlen;
	char *out, *url;
	int ret = 0;
	if (fd == NULL || fd->data == NULL)
		return -1;
	url = r_str_newf ("%s/p8%%20%[email protected]%"PFMT64d,
		rURL(fd), count, io->off);
	out = r_socket_http_get (url, &code, &rlen);
	if (out && rlen>0) {
		ut8 *tmp = malloc (rlen+1);
		ret = r_hex_str2bin (out, tmp);
		memcpy (buf, tmp, R_MIN (count, rlen));
		free (tmp);
		if (ret<0) ret = -ret;
	}
	free (out);
	free (url);
	return ret;
}
开发者ID:0x2F,项目名称:radare2,代码行数:20,代码来源:io_r2web.c


示例20: cmd_write_hexpair

R_API int cmd_write_hexpair(RCore* core, const char* pairs) {
	ut8 *buf = malloc (strlen (pairs) + 1);
	int len = r_hex_str2bin (pairs, buf);
	if (len != 0) {
		if (len < 0) {
			len = -len;
			if (len < core->blocksize) {
				buf[len-1] |= core->block[len-1] & 0xf;
			}
		}
		r_core_write_at (core, core->offset, buf, len);
		if (r_config_get_i (core->config, "cfg.wseek")) {
			r_core_seek_delta (core, len);
		}
		r_core_block_read (core);
	} else {
		eprintf ("Error: invalid hexpair string\n");
	}
	free (buf);
	return len;
}
开发者ID:jduck,项目名称:radare2,代码行数:21,代码来源:cmd_write.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ r_imag函数代码示例发布时间:2022-05-30
下一篇:
C++ r_has_type函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap