本文整理汇总了C++中r_str_newf函数的典型用法代码示例。如果您正苦于以下问题:C++ r_str_newf函数的具体用法?C++ r_str_newf怎么用?C++ r_str_newf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了r_str_newf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: cmd_load_theme
static bool cmd_load_theme(RCore *core, const char *_arg) {
bool failed = false;
char *path;
if (!_arg || !*_arg) {
return false;
}
char *arg = strdup (_arg);
char *tmp = r_str_newf (R_JOIN_2_PATHS (R2_HOME_THEMES, "%s"), arg);
char *home = tmp ? r_str_home (tmp) : NULL;
free (tmp);
tmp = r_str_newf (R_JOIN_2_PATHS (R2_THEMES, "%s"), arg);
path = tmp ? r_str_r2_prefix (tmp) : NULL;
free (tmp);
if (!load_theme (core, home)) {
if (load_theme (core, path)) {
curtheme = r_str_dup (curtheme, arg);
} else {
if (load_theme (core, arg)) {
curtheme = r_str_dup (curtheme, arg);
} else {
char *absfile = r_file_abspath (arg);
eprintf ("eco: cannot open colorscheme profile (%s)\n", absfile);
free (absfile);
failed = true;
}
}
}
free (home);
free (path);
free (arg);
return !failed;
}
开发者ID:nmatt0,项目名称:radare2,代码行数:35,代码来源:cmd_eval.c
示例2: r_syscall_setup
// TODO: should be renamed to r_syscall_use();
R_API bool r_syscall_setup(RSyscall *s, const char *arch, int bits, const char *cpu, const char *os) {
if (!os || !*os) {
os = R_SYS_OS;
}
if (!arch) {
arch = R_SYS_ARCH;
}
free (s->os);
s->os = strdup (os);
if (!strcmp (os, "any")) { // ignored
return true;
}
if (!strcmp (arch, "mips")) {
s->regs = fastcall_mips;
} else if (!strcmp (arch, "avr")) {
s->sysport = sysport_avr;
} else if (!strcmp (os, "osx") || !strcmp (os, "macos")) {
os = "darwin";
} else if (!strcmp (arch,"sh")) {
s->regs = fastcall_sh;
} else if (!strcmp (arch, "arm")) {
switch (bits) {
case 16:
case 32:
s->regs = fastcall_arm;
break;
case 64:
s->regs = fastcall_arm64;
break;
}
} else if (!strcmp (arch, "x86")) {
s->sysport = sysport_x86;
switch (bits) {
case 8:
s->regs = fastcall_x86_8;
break;
case 32:
s->regs = fastcall_x86_32;
break;
case 64:
s->regs = fastcall_x86_64;
break;
}
}
char *dbName = r_str_newf ("syscall/%s-%s-%d", os, arch, bits);
s->db = openDatabase (s->db, dbName);
free (dbName);
dbName = r_str_newf ("sysregs/%s-%d-%s", arch, bits, cpu ? cpu: arch);
s->srdb = openDatabase (s->srdb, dbName);
free (dbName);
if (s->fd) {
fclose (s->fd);
}
s->fd = NULL;
return true;
}
开发者ID:dtrecherel,项目名称:radare2,代码行数:61,代码来源:syscall.c
示例3: r_egg_Cfile_parseCompiled
static bool r_egg_Cfile_parseCompiled(const char *file) {
char *fileExt = r_str_newf ("%s.tmp", file);
char *buffer = r_file_slurp (fileExt, NULL);
buffer = r_str_replace (buffer, "rdata", "text", false);
buffer = r_str_replace (buffer, "rodata", "text", false);
buffer = r_str_replace (buffer, "get_pc_thunk.bx", "__getesp__", true);
const char *words[] = {".cstring", "size", "___main", "section", "__alloca", "zero", "cfi"};
size_t i;
for (i = 0; i < 7; i++) {
r_str_stripLine (buffer, words[i]);
}
free (fileExt);
fileExt = r_str_newf ("%s.s", file);
if (!r_file_dump (fileExt, (const ut8*) buffer, strlen (buffer), true)) {
eprintf ("Error while opening %s.s\n", file);
goto fail;
}
free (buffer);
free (fileExt);
return true;
fail:
free (buffer);
free (fileExt);
return false;
}
开发者ID:agatti,项目名称:radare2,代码行数:30,代码来源:egg_Cfile.c
示例4: r_list_foreach
r_list_foreach (bpargs, iter, var) {
char *tmpf = NULL;
if (var->delta < 10) {
tmpf = "%d(%s)";
} else if (var->delta > 0) {
tmpf = "0x%x(%s)";
} else {
tmpf = "-0x%x(%s)";
}
oldstr = r_str_newf (tmpf, r_num_abs (var->delta),
anal->reg->name[R_REG_NAME_BP]);
if (ucase) {
char *comma = strchr (oldstr, ',');
if (comma) {
*comma = 0;
r_str_case (oldstr, true);
*comma = ',';
}
}
if (strstr (tstr, oldstr)) {
char *newstr = (p->localvar_only) ? r_str_newf ("(%s)", var->name):
r_str_newf ("%s%s(%s)", var->delta > 0 ? "" : "-",
var->name, anal->reg->name[R_REG_NAME_SP]);
tstr = r_str_replace (tstr, oldstr, newstr, 1);
free (newstr);
free (oldstr);
break;
}
free (oldstr);
}
开发者ID:radare,项目名称:radare2,代码行数:30,代码来源:parse_mips_pseudo.c
示例5: cs_insn_name
static char *mnemonics(RAsm *a, int id, bool json) {
int i;
a->cur->disassemble (a, NULL, NULL, -1);
if (id != -1) {
const char *name = cs_insn_name (cd, id);
if (json) {
return name? r_str_newf ("[\"%s\"]\n", name): NULL;
}
return name? r_str_newf ("%s", name): NULL;
}
RStrBuf *buf = r_strbuf_new ("");
if (json) {
r_strbuf_append (buf, "[");
}
for (i = 1; ; i++) {
const char *op = cs_insn_name (cd, i);
if (!op) {
break;
}
if (json) {
r_strbuf_append (buf, "\"");
}
r_strbuf_append (buf, op);
if (json) {
if (cs_insn_name (cd, i + 1)) {
r_strbuf_append (buf, "\",");
} else {
r_strbuf_append (buf, "\"]\n");
}
} else {
r_strbuf_append (buf, "\n");
}
}
return r_strbuf_drain (buf);
}
开发者ID:radare,项目名称:radare2,代码行数:35,代码来源:cs_mnemonics.c
示例6: libs
static RList* libs(RBinFile *arch) {
r_bin_xbe_obj_t *obj;
xbe_lib lib;
RList *ret;
char *s;
int i;
if (!arch || !arch->o)
return NULL;
obj = arch->o->bin_obj;
ret = r_list_new ();
if (!ret) return NULL;
ret->free = free;
r_buf_read_at (arch->buf, obj->header->kernel_lib_addr - obj->header->base,
(ut8 *)&lib, sizeof(xbe_lib));
s = r_str_newf ("%s %i.%i.%i", lib.name, lib.major, lib.minor, lib.build);
if (s) r_list_append (ret, s);
r_buf_read_at (arch->buf, obj->header->xapi_lib_addr - obj->header->base,
(ut8 *)&lib, sizeof(xbe_lib));
s = r_str_newf ("%s %i.%i.%i", lib.name, lib.major, lib.minor, lib.build);
if (s) r_list_append (ret, s);
for (i = 0; i < obj->header->lib_versions; i++) {
r_buf_read_at (arch->buf, obj->header->lib_versions_addr - \
obj->header->base + (i * sizeof (xbe_lib)),
(ut8 *)&lib, sizeof (xbe_lib));
s = r_str_newf ("%s %i.%i.%i", lib.name,
lib.major, lib.minor, lib.build);
if (s) r_list_append(ret, s);
}
return ret;
}
开发者ID:DePierre,项目名称:radare2,代码行数:34,代码来源:bin_xbe.c
示例7: R_NEW0
static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
char *out;
int rlen, code;
if (__plugin_open (io, pathname, 0)) {
RIOR2Web *mal = R_NEW0 (RIOR2Web);
if (!mal) return NULL;
char *url = r_str_newf ("http://%s/?V", pathname+8);
//eprintf ("URL:(%s)\n", url);
out = r_socket_http_get (url, &code, &rlen);
//eprintf ("RES %d %d\n", code, rlen);
//eprintf ("OUT(%s)\n", out);
if (out && rlen>0) {
mal->fd = getmalfd (mal);
mal->url = r_str_newf ("http://%s", pathname+8);
free (out);
free (url);
return r_io_desc_new (&r_io_plugin_r2web,
mal->fd, pathname, rw, mode, mal);
}
free (url);
free (mal);
free (out);
}
return NULL;
}
开发者ID:Darredevil,项目名称:radare2,代码行数:25,代码来源:io_r2web.c
示例8: __read
static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) {
if (!fd || !fd->data) {
return -1;
}
int wordSize = 4;
ut32 *w = (ut32*)buf;
int i;
memset (buf, 0xff, count);
int words = count / wordSize; // XXX must pad align to 4
for (i = 0; i < words ; i++) {
ut64 addr = io->off + (i * wordSize);
char *cmd = r_str_newf ("x 0x%"PFMT64x, addr);
char *res = runcmd (cmd);
sscanf (res, "%x", &w[i]);
free (res);
free (cmd);
}
int left = count % wordSize;
if (left > 0) {
ut32 n = 0xff;
ut8 *wn = (ut8*)&n;
ut64 addr = io->off + (i * wordSize);
char *cmd = r_str_newf ("x 0x%"PFMT64x, addr);
char *res = runcmd (cmd);
sscanf (res, "%x", &n);
free (res);
free (cmd);
memcpy (buf + (words * wordSize), wn, left);
}
return count;
}
开发者ID:dtrecherel,项目名称:radare2,代码行数:32,代码来源:io_winedbg.c
示例9: printPadded
static void printPadded(RCore *core, int pad) {
if (pad < 1) {
pad = 8;
}
char *fmt = r_str_newf ("0x%%0%d" PFMT64x, pad);
char *off = r_str_newf (fmt, core->offset);
r_cons_printf ("%s\n", off);
free (off);
free (fmt);
}
开发者ID:P4N74,项目名称:radare2,代码行数:10,代码来源:cmd_seek.c
示例10: r_core_project_delete
R_API int r_core_project_delete(RCore *core, const char *prjfile) {
if (r_sandbox_enable (0)) {
eprintf ("Cannot delete project in sandbox mode\n");
return 0;
}
char *path = projectScriptPath (core, prjfile);
if (!path) {
eprintf ("Invalid project name '%s'\n", prjfile);
return false;
}
if (r_core_is_project (core, prjfile)) {
char *prjDir = r_file_dirname (path);
if (!prjDir) {
eprintf ("Cannot resolve directory\n");
free (path);
return false;
}
// rm project file
if (r_file_exists (path)) {
r_file_rm (path);
eprintf ("rm %s\n", path);
}
//rm notes.txt file
char *notes_txt = r_str_newf ("%s%s%s", prjDir, R_SYS_DIR, "notes.txt");
if (r_file_exists (notes_txt)) {
r_file_rm (notes_txt);
eprintf ("rm %s\n", notes_txt);
}
free(notes_txt);
char *rop_d = r_str_newf ("%s%s%s", prjDir, R_SYS_DIR, "rop.d");
if (r_file_is_directory (rop_d)) {
char *f;
RListIter *iter;
RList *files = r_sys_dir (rop_d);
r_list_foreach (files, iter, f) {
char *filepath = r_str_append (strdup (rop_d), R_SYS_DIR);
filepath = r_str_append (filepath, f);
if (!r_file_is_directory (filepath)) {
eprintf ("rm %s\n", filepath);
r_file_rm (filepath);
}
free (filepath);
}
r_file_rm (rop_d);
eprintf ("rm %s\n", rop_d);
r_list_free (files);
}
free (rop_d);
// remove directory only if it's empty
r_file_rm (prjDir);
free (prjDir);
}
开发者ID:csarn,项目名称:radare2,代码行数:55,代码来源:project.c
示例11: main
int main(int argc, char **argv) {
char *file;
RRunProfile *p;
int i, ret;
if (argc == 1 || !strcmp (argv[1], "-h")) {
eprintf ("Usage: rarun2 [-v] [script.rr2] [directive ..]\n");
printf ("%s", r_run_help ());
return 1;
}
if (!strcmp (argv[1], "-v")) {
printf ("rarun2 "R2_VERSION"\n");
return 0;
}
file = argv[1];
if (*file && !strchr (file, '=')) {
p = r_run_new (file);
} else {
bool noMoreDirectives = false;
int directiveIndex = 0;
p = r_run_new (NULL);
for (i = *file ? 1 : 2; i < argc; i++) {
if (!strcmp (argv[i], "--")) {
noMoreDirectives = true;
continue;
}
if (noMoreDirectives) {
const char *word = argv[i];
char *line = directiveIndex
? r_str_newf ("arg%d=%s", directiveIndex, word)
: r_str_newf ("program=%s", word);
r_run_parseline (p, line);
directiveIndex ++;
free (line);
} else {
r_run_parseline (p, argv[i]);
}
}
}
if (!p) return 1;
ret = r_run_config_env (p);
if (ret) {
printf("error while configuring the environment.\n");
return 1;
}
ret = r_run_start (p);
r_run_free (p);
return ret;
}
开发者ID:AmesianX,项目名称:radare2,代码行数:49,代码来源:rarun2.c
示例12: R_NEW0
static RBinInfo *info(RBinFile *arch) {
RBinInfo *ret = R_NEW0 (RBinInfo);
if (!ret)
return NULL;
ret->file = strdup (arch->file);
ret->type = r_str_newf ("Python %s%s byte-compiled file", version.version,
version.unicode ? " Unicode" : "");
ret->bclass = strdup ("Python byte-compiled file");
ret->rclass = strdup ("pyc");
ret->machine = r_str_newf ("Python %s VM (rev %s)", version.version,
version.revision);
ret->os = strdup ("any");
ret->bits = 32;
return ret;
}
开发者ID:radare,项目名称:radare2-extras,代码行数:15,代码来源:bin_pyc.c
示例13: libs
static RList* libs(RBinFile *arch) {
r_bin_xbe_obj_t *obj;
int i, off, libs, r;
xbe_lib lib;
RList *ret;
char *s;
if (!arch || !arch->o)
return NULL;
obj = arch->o->bin_obj;
ret = r_list_new ();
if (!ret) return NULL;
ret->free = free;
if ( obj->header->kernel_lib_addr < obj->header->base) {
off = 0;
} else {
off = obj->header->kernel_lib_addr - obj->header->base;
}
r = r_buf_read_at (arch->buf, off, (ut8 *)&lib, sizeof(xbe_lib));
if (r == 0 || r == -1) return NULL;
s = r_str_newf ("%s %i.%i.%i", lib.name, lib.major, lib.minor, lib.build);
if (s) r_list_append (ret, s);
if (obj->header->xapi_lib_addr < obj->header->base) {
off = 0;
} else {
off = obj->header->xapi_lib_addr - obj->header->base;
}
r = r_buf_read_at (arch->buf, off, (ut8 *)&lib, sizeof(xbe_lib));
if (r == 0 || r == -1) return NULL;
s = r_str_newf ("%s %i.%i.%i", lib.name, lib.major, lib.minor, lib.build);
if (s) r_list_append (ret, s);
libs = obj->header->lib_versions;
if (libs<1) libs = 0;
for (i = 0; i < libs; i++) {
r = r_buf_read_at (arch->buf, obj->header->lib_versions_addr - \
obj->header->base + (i * sizeof (xbe_lib)),
(ut8 *)&lib, sizeof (xbe_lib));
if (r == 0 || r == -1) continue;
s = r_str_newf ("%s %i.%i.%i", lib.name,
lib.major, lib.minor, lib.build);
if (s) r_list_append(ret, s);
}
return ret;
}
开发者ID:13572293130,项目名称:radare2,代码行数:48,代码来源:bin_xbe.c
示例14: build_flags_format_and_members_field
int build_flags_format_and_members_field(R_PDB *pdb, ELeafType lt, char *name, char *type,
int i, int *pos, int offset, char *format_flags_field, char **members_field) {
switch (lt) {
case eLF_STRUCTURE:
case eLF_UNION:
members_field[i] = (char *) malloc(sizeof(char) * strlen(name) + 1);
if (!members_field[i]) return 0;
strcpy(members_field[i], name);
if (build_format_flags (pdb, type, *pos, format_flags_field, &members_field[i]) == 0) {
return 0;
}
*pos = *pos + 1;
break;
case eLF_ENUM:
members_field[i] = r_str_newf ("%s=%08x", name, offset);
#if 0
members_field[i] = (char *) malloc(sizeof(char) * strlen(name) + 8 + 1 + 1); // 8 - hex int, 1 - =
if (!members_field[i]) {
return 0;
}
sprintf (members_field[i], "%s=%08X", name, offset);
#endif
break;
default:
return 0;
}
return 1;
}
开发者ID:EliaGeretto,项目名称:radare2,代码行数:29,代码来源:pdb.c
示例15: bbPanels
static int bbPanels (RCore *core, Panel **n) {
int i;
Panel *panels = calloc (sizeof (Panel), LIMIT); //(r_list_length (fcn->bbs)+1));
if (!panels)
return 0;
i = 0;
panels[i].text = strdup ("");
panels[i].addr = core->offset;
panels[i].type = PANEL_TYPE_FLOAT;
menu_pos = i;
i++;
panels[i].text = strdup ("Disassembly");
panels[i].cmd = r_str_newf ("pd $r-2");
panels[i].addr = core->offset;
panels[i].type = PANEL_TYPE_FRAME;
i++;
panels[i].text = strdup ("Symbols");
panels[i].cmd = strdup ("isq");
panels[i].addr = core->offset;
panels[i].type = PANEL_TYPE_FRAME;
i++;
n_panels = 2;
free (*n);
*n = panels;
panels[i].text = NULL;
Layout_run (panels);
return i;
}
开发者ID:8500616886,项目名称:radare2,代码行数:32,代码来源:panels.c
示例16: r_meta_set_string
// TODO: Add APIs to resize meta? nope, just del and add
R_API int r_meta_set_string(RAnal *a, int type, ut64 addr, const char *s) {
char key[100], val[2048], *e_str;
int ret;
ut64 size;
int space_idx = a->meta_spaces.space_idx;
meta_type_add (a, type, addr);
snprintf (key, sizeof (key)-1, "meta.%c.0x%"PFMT64x, type, addr);
size = sdb_array_get_num (DB, key, 0, 0);
if (!size) {
size = strlen (s);
meta_inrange_add (a, addr, size);
ret = true;
} else {
ret = false;
}
if (a->log) {
char *msg = r_str_newf (":C%c %s @ 0x%"PFMT64x, type, s, addr);
a->log (a, msg);
free (msg);
}
e_str = sdb_encode ((const void*)s, -1);
snprintf (val, sizeof (val)-1, "%d,%d,%s", (int)size, space_idx, e_str);
sdb_set (DB, key, val, 0);
free ((void*)e_str);
return ret;
}
开发者ID:skuater,项目名称:radare2,代码行数:28,代码来源:meta.c
示例17: r_type_get_enum
R_API RList* r_type_get_enum (Sdb *TDB, const char *name) {
char *p, var[130];
int n;
if (r_type_kind (TDB, name) != R_TYPE_ENUM) {
return NULL;
}
RList *res = r_list_new ();
snprintf (var, sizeof (var), "enum.%s", name);
for (n = 0; (p = sdb_array_get (TDB, var, n, NULL)); n++) {
RTypeEnum *member = R_NEW0 (RTypeEnum);
if (member) {
char *var2 = r_str_newf ("%s.%s", var, p);
if (var2) {
char *val = sdb_array_get (TDB, var2, 0, NULL);
if (val) {
member->name = p;
member->val = val;
r_list_append (res, member);
} else {
free (member);
free (var2);
}
} else {
free (member);
}
}
}
return res;
}
开发者ID:csarn,项目名称:radare2,代码行数:30,代码来源:ctype.c
示例18: r_socket_spawn
R_API int r_socket_spawn (RSocket *s, const char *cmd, unsigned int timeout) {
// XXX TODO: dont use sockets, we can achieve the same with pipes
const int port = 2000 + r_num_rand (2000);
int childPid = r_sys_fork();
if (childPid == 0) {
char *a = r_str_replace (strdup (cmd), "\\", "\\\\", true);
r_sys_cmdf ("rarun2 system=\"%s\" listen=%d", a, port);
free (a);
#if 0
// TODO: use the api
char *profile = r_str_newf (
"system=%s\n"
"listen=%d\n", cmd, port);
RRunProfile *rp = r_run_new (profile);
r_run_start (rp);
r_run_free (rp);
free (profile);
#endif
eprintf ("r_socket_spawn: %s is dead\n", cmd);
exit (0);
}
r_sys_sleep (1);
r_sys_usleep (timeout);
char aport[32];
sprintf (aport, "%d", port);
// redirect stdin/stdout/stderr
return r_socket_connect (s, "127.0.0.1", aport, R_SOCKET_PROTO_TCP, 2000);
}
开发者ID:PankajKataria,项目名称:radare2,代码行数:28,代码来源:socket.c
示例19: extract_sections
static bool extract_sections(pyc_object *obj, RList *sections, char *prefix) {
RListIter *i;
pyc_code_object *cobj;
RBinSection *section;
if (!obj || (obj->type != TYPE_CODE_v1))
return false;
cobj = obj->data;
if (!cobj || !cobj->name)
return false;
if (cobj->name->type != TYPE_ASCII && cobj->name->type != TYPE_STRING)
return false;
if (!cobj->name->data)
return false;
section = R_NEW0 (RBinSection);
prefix = r_str_newf ("%s%s%s", prefix ? prefix : "",
prefix ? "." : "", cobj->name->data);
if (!prefix || !section)
goto fail;
if (!strncpy ((char*)§ion->name, prefix, R_BIN_SIZEOF_STRINGS))
goto fail;
if (!r_list_append (sections, section))
goto fail;
if (cobj->consts->type != TYPE_TUPLE)
return false;
r_list_foreach (((RList*)(cobj->consts->data)), i, obj)
extract_sections (obj, sections, prefix);
free (prefix);
return true;
fail:
free (section);
free (prefix);
return false;
}
开发者ID:Chelwin,项目名称:radare2-extras,代码行数:34,代码来源:marshal.c
示例20: r_str_newf
/* swap color from foreground to background, returned value must be freed */
R_API char *r_cons_swap_ground(const char *col) {
if (!strncmp (col, "\x1b[48;5;", 7)) {
/* rgb background */
return r_str_newf ("\x1b[38;5;%s", col+7);
} else if (!strncmp (col, "\x1b[38;5;", 7)) {
/* rgb foreground */
return r_str_newf ("\x1b[48;5;%s", col+7);
} else if (!strncmp (col, "\x1b[4", 3)) {
/* is background */
return r_str_newf ("\x1b[3%s", col+3);
} else if (!strncmp (col, "\x1b[3", 3)) {
/* is foreground */
return r_str_newf ("\x1b[4%s", col+3);
}
return strdup (col);
}
开发者ID:NightOfTwelve,项目名称:radare2,代码行数:17,代码来源:cons.c
注:本文中的r_str_newf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论