本文整理汇总了C++中r_hex_str2bin函数的典型用法代码示例。如果您正苦于以下问题:C++ r_hex_str2bin函数的具体用法?C++ r_hex_str2bin怎么用?C++ r_hex_str2bin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了r_hex_str2bin函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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 ();
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}