Make size arg of r_file_slurp() size_t (#16221)

This commit is contained in:
Florian Märkl 2020-03-15 23:34:38 +01:00 committed by GitHub
parent 778c42cfa7
commit 0b5e78e923
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 157 additions and 126 deletions

View File

@ -155,13 +155,13 @@ static inline int r_asm_pseudo_fill(RAsmOp *op, char *input) {
}
static inline int r_asm_pseudo_incbin(RAsmOp *op, char *input) {
int bytes_read = 0;
size_t bytes_read = 0;
r_str_replace_char (input, ',', ' ');
// int len = r_str_word_count (input);
r_str_word_set0 (input);
//const char *filename = r_str_word_get0 (input, 0);
int skip = (int)r_num_math (NULL, r_str_word_get0 (input, 1));
int count = (int)r_num_math (NULL,r_str_word_get0 (input, 2));
size_t skip = (size_t)r_num_math (NULL, r_str_word_get0 (input, 1));
size_t count = (size_t)r_num_math (NULL,r_str_word_get0 (input, 2));
char *content = r_file_slurp (input, &bytes_read);
if (!content) {
eprintf ("Could not open '%s'.\n", input);

View File

@ -1205,10 +1205,10 @@ R_API RBuffer *r_bin_package(RBin *bin, const char *type, const char *file, RLis
int off = 12;
int item = 0;
r_list_foreach (files, iter, f) {
int f_len = 0;
size_t f_len = 0;
ut8 *f_buf = (ut8 *)r_file_slurp (f, &f_len);
if (f_buf && f_len >= 0) {
eprintf ("ADD %s %d\n", f, f_len);
if (f_buf) {
eprintf ("ADD %s %"PFMT64u"\n", f, (ut64)f_len);
} else {
eprintf ("Cannot open %s\n", f);
free (f_buf);

View File

@ -257,12 +257,14 @@ void r_bin_dydlcache_get_libname(struct r_bin_dyldcache_lib_t *lib, char **libna
struct r_bin_dyldcache_obj_t* r_bin_dyldcache_new(const char* file) {
struct r_bin_dyldcache_obj_t *bin;
ut8 *buf;
if (!(bin = R_NEW0 (struct r_bin_dyldcache_obj_t))) {
return NULL;
}
bin->file = file;
if (!(buf = (ut8*)r_file_slurp (file, &bin->size))) {
size_t binsz;
ut8 *buf = (ut8 *)r_file_slurp (file, &binsz);
bin->size = binsz;
if (!buf) {
return r_bin_dyldcache_free (bin);
}
bin->b = r_buf_new ();

View File

@ -86,13 +86,15 @@ void* r_bin_fatmach0_free(struct r_bin_fatmach0_obj_t* bin) {
}
struct r_bin_fatmach0_obj_t* r_bin_fatmach0_new(const char* file) {
ut8 *buf;
struct r_bin_fatmach0_obj_t *bin = R_NEW0 (struct r_bin_fatmach0_obj_t);
if (!bin) {
return NULL;
}
bin->file = file;
if (!(buf = (ut8*)r_file_slurp (file, &bin->size))) {
size_t binsz;
ut8 *buf = (ut8 *)r_file_slurp (file, &binsz);
bin->size = binsz;
if (!buf) {
return r_bin_fatmach0_free (bin);
}
bin->b = r_buf_new ();

View File

@ -1941,8 +1941,10 @@ struct MACH0_(obj_t) *MACH0_(mach0_new)(const char *file, struct MACH0_(opts_t)
bin->header_at = options->header_at;
}
bin->file = file;
ut8 *buf;
if (!(buf = (ut8*)r_file_slurp (file, &bin->size))) {
size_t binsz;
ut8 *buf = (ut8 *)r_file_slurp (file, &binsz);
bin->size = binsz;
if (!buf) {
return MACH0_(mach0_free)(bin);
}
bin->b = r_buf_new ();

View File

@ -281,13 +281,15 @@ static bool r_bin_mz_init(struct r_bin_mz_obj_t *bin) {
}
struct r_bin_mz_obj_t *r_bin_mz_new (const char *file) {
const ut8 *buf;
struct r_bin_mz_obj_t *bin = R_NEW0 (struct r_bin_mz_obj_t);
if (!bin) {
return NULL;
}
bin->file = file;
if (!(buf = (ut8 *)r_file_slurp (file, &bin->size))) {
size_t binsz;
ut8 *buf = (ut8*)r_file_slurp (file, &binsz);
bin->size = binsz;
if (!buf) {
return r_bin_mz_free (bin);
}
bin->b = r_buf_new ();

View File

@ -3967,13 +3967,15 @@ void* PE_(r_bin_pe_free)(struct PE_(r_bin_pe_obj_t)* bin) {
}
struct PE_(r_bin_pe_obj_t)* PE_(r_bin_pe_new)(const char* file, bool verbose) {
ut8* buf;
struct PE_(r_bin_pe_obj_t)* bin = R_NEW0 (struct PE_(r_bin_pe_obj_t));
if (!bin) {
return NULL;
}
bin->file = file;
if (!(buf = (ut8*) r_file_slurp (file, &bin->size))) {
size_t binsz;
ut8 *buf = (ut8*)r_file_slurp (file, &binsz);
bin->size = binsz;
if (!buf) {
return PE_(r_bin_pe_free)(bin);
}
bin->b = r_buf_new ();

View File

@ -414,13 +414,15 @@ void* r_bin_te_free(struct r_bin_te_obj_t* bin) {
}
struct r_bin_te_obj_t* r_bin_te_new(const char* file) {
ut8 *buf;
struct r_bin_te_obj_t *bin = R_NEW0 (struct r_bin_te_obj_t);
if (!bin) {
return NULL;
}
bin->file = file;
if (!(buf = (ut8 *)r_file_slurp (file, &bin->size))) {
size_t binsz;
ut8 *buf = (ut8*)r_file_slurp (file, &binsz);
bin->size = binsz;
if (!buf) {
return r_bin_te_free (bin);
}
bin->b = r_buf_new ();

View File

@ -83,7 +83,9 @@ R_API char *r_cons_editor(const char *file, const char *str) {
if (file) {
path = strdup (file);
bytes = 0;
lines = r_file_slurp (file, &bytes);
size_t sz = 0;
lines = r_file_slurp (file, &sz);
bytes = (int)sz;
if (!lines) {
eprintf ("Failed to load '%s'.\n", file);
R_FREE (path);

View File

@ -3309,7 +3309,8 @@ escape_backtick:
char *tmpasm = NULL;
bool flgspc_changed = false;
int tmpfd = -1;
int sz, len;
size_t sz;
int len;
ut8 *buf;
*ptr++ = '\0';
@ -3391,7 +3392,7 @@ repeat_arroba:
f = r_file_slurp (ptr + 2, &sz);
if (f) {
{
RBuffer *b = r_buf_new_with_bytes ((const ut8*)f, sz);
RBuffer *b = r_buf_new_with_bytes ((const ut8*)f, (ut64)sz);
RIODesc *d = r_io_open_buffer (core->io, b, R_PERM_RWX, 0);
if (d) {
if (tmpdesc) {
@ -5386,7 +5387,7 @@ DEFINE_HANDLE_TS_FCN(tmp_file_command) {
TSNode command = ts_node_named_child (node, 0);
TSNode arg = ts_node_named_child (node, 1);
char *arg_str = ts_node_handle_arg (state, node, arg, 1);
int sz;
size_t sz;
bool res = false;
char *f = r_file_slurp (arg_str, &sz);
@ -5395,7 +5396,7 @@ DEFINE_HANDLE_TS_FCN(tmp_file_command) {
goto out;
}
res = handle_tmp_desc (state, command, (ut8 *)f, sz);
res = handle_tmp_desc (state, command, (ut8 *)f, (int)sz);
free (f);
out:

View File

@ -1277,7 +1277,7 @@ static int cmd_debug_map_snapshot(RCore *core, const char *input) {
snap = r_debug_snap_get (core->dbg, core->offset);
}
if (snap) {
int fsz = 0;
size_t fsz = 0;
char *data = r_file_slurp (file, &fsz);
if (data) {
if (fsz >= snap->size) {
@ -1659,7 +1659,7 @@ static int cmd_debug_map(RCore *core, const char *input) {
r_debug_map_sync (core->dbg); // update process memory maps
r_list_foreach (core->dbg->maps, iter, map) {
if (addr >= map->addr && addr < map->addr_end) {
int sz;
size_t sz;
char *buf = r_file_slurp (input + 2, &sz);
//TODO: use mmap here. we need a portable implementation
if (!buf) {
@ -1668,10 +1668,10 @@ static int cmd_debug_map(RCore *core, const char *input) {
}
r_io_write_at (core->io, map->addr, (const ut8*)buf, sz);
if (sz != map->size)
eprintf ("File size differs from region size (%d vs %"PFMT64d")\n",
sz, map->size);
eprintf ("Loaded %d byte(s) into the map region at 0x%08"PFMT64x"\n",
sz, map->addr);
eprintf ("File size differs from region size (%"PFMT64u" vs %"PFMT64d")\n",
(ut64)sz, map->size);
eprintf ("Loaded %"PFMT64u" byte(s) into the map region at 0x%08"PFMT64x"\n",
(ut64)sz, map->addr);
free (buf);
return true;
}

View File

@ -179,12 +179,12 @@ static int cmd_project(void *data, const char *input) {
break;
case 'j': // "Pnj"
if (!input[2]) {
int len = 0;
size_t len = 0;
/* get base64 string */
char *str = r_core_project_notes_file (core, fileproject);
if (str) {
char *data = r_file_slurp (str, &len);
char *res = r_base64_encode_dyn (data, len);
char *res = r_base64_encode_dyn (data, (int)len);
if (res) {
r_cons_println (res);
free (res);

View File

@ -3741,7 +3741,7 @@ reread:
char **args = r_str_argv (input + param_offset, &n_args);
ut8 *buf = NULL;
ut64 offset = 0;
int size;
size_t size;
buf = (ut8 *)r_file_slurp (args[0], &size);
if (!buf) {
eprintf ("Cannot open '%s'\n", args[0]);

View File

@ -527,7 +527,7 @@ static void cmd_write_value (RCore *core, const char *input) {
static bool cmd_wff(RCore *core, const char *input) {
ut8 *buf;
int size;
size_t size;
// XXX: file names cannot contain spaces
const char *arg = input + ((input[1] == ' ') ? 2 : 1);
int wseek = r_config_get_i (core->config, "cfg.wseek");
@ -553,8 +553,8 @@ static bool cmd_wff(RCore *core, const char *input) {
}
if ((buf = (ut8*) r_file_slurp (a, &size))) {
int u_offset = 0;
int u_size = r_num_math (core->num, p);
if (u_size < 1) u_size = size;
ut64 u_size = r_num_math (core->num, p);
if (u_size < 1) u_size = (ut64)size;
if (p) {
*p++ = 0;
u_offset = r_num_math (core->num, p);
@ -565,7 +565,7 @@ static bool cmd_wff(RCore *core, const char *input) {
}
}
r_io_use_fd (core->io, core->file->fd);
if (!r_io_write_at (core->io, core->offset, buf + u_offset, u_size)) {
if (!r_io_write_at (core->io, core->offset, buf + u_offset, (int)u_size)) {
eprintf ("r_io_write_at failed at 0x%08"PFMT64x"\n", core->offset);
}
WSEEK (core, size);

View File

@ -3475,7 +3475,7 @@ R_API char *r_core_editor(const RCore *core, const char *file, const char *str)
const bool interactive = r_cons_is_interactive ();
const char *editor = r_config_get (core->config, "cfg.editor");
char *name = NULL, *ret = NULL;
int len, fd;
int fd;
if (!interactive || !editor || !*editor) {
return NULL;
@ -3515,6 +3515,7 @@ R_API char *r_core_editor(const RCore *core, const char *file, const char *str)
r_sys_cmdf ("%s '%s'", editor, name);
}
}
size_t len = 0;
ret = name? r_file_slurp (name, &len): 0;
if (ret) {
if (len && ret[len - 1] == '\n') {

View File

@ -102,8 +102,7 @@ static int r_core_rtr_http_run(RCore *core, int launch, int browse, const char *
return 1;
}
int sz;
pfile = r_file_slurp (httpauthfile, &sz);
pfile = r_file_slurp (httpauthfile, NULL);
if (pfile) {
so.authtokens = r_str_split_list (pfile, "\n", 0);
@ -266,10 +265,10 @@ static int r_core_rtr_http_run(RCore *core, int launch, int browse, const char *
} else {
char *path = r_file_root (uproot, rs->path + 4);
if (r_file_exists (path)) {
int sz = 0;
size_t sz = 0;
char *f = r_file_slurp (path, &sz);
if (f) {
r_socket_http_response (rs, 200, f, sz, headers);
r_socket_http_response (rs, 200, f, (int)sz, headers);
free (f);
} else {
r_socket_http_response (rs, 403, "Permission denied", 0, headers);
@ -417,7 +416,7 @@ static int r_core_rtr_http_run(RCore *core, int launch, int browse, const char *
}
}
if (r_file_exists (path)) {
int sz = 0;
size_t sz = 0;
char *f = r_file_slurp (path, &sz);
if (f) {
const char *ct = NULL;
@ -431,7 +430,7 @@ static int r_core_rtr_http_run(RCore *core, int launch, int browse, const char *
ct = "Content-Type: text/html\n";
}
char *hdr = r_str_newf ("%s%s", ct, headers);
r_socket_http_response (rs, 200, f, sz, hdr);
r_socket_http_response (rs, 200, f, (int)sz, hdr);
free (hdr);
free (f);
} else {

View File

@ -3393,7 +3393,7 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) {
// TODO autocomplete filenames
prompt_read ("load from file: ", buf, sizeof (buf));
if (buf[0]) {
int sz;
size_t sz;
char *data = r_file_slurp (buf, &sz);
if (data) {
int cur;
@ -3404,7 +3404,7 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) {
}
ut64 from = core->offset + cur;
ut64 size = R_ABS (core->print->cur - core->print->ocur) + 1;
ut64 s = R_MIN (size, sz);
ut64 s = R_MIN (size, (ut64)sz);
r_io_write_at (core->io, from, (const ut8*)data, s);
}
}

View File

@ -78,7 +78,7 @@ static prpsinfo_t *linux_get_prpsinfo(RDebug *dbg, proc_per_process_t *proc_data
char *buffer, *pfname = NULL, *ppsargs = NULL, *file = NULL;
prpsinfo_t *p;
pid_t mypid;
int len;
size_t len;
p = R_NEW0 (prpsinfo_t);
if (!p) {
@ -102,7 +102,7 @@ static prpsinfo_t *linux_get_prpsinfo(RDebug *dbg, proc_per_process_t *proc_data
basename = r_file_basename (pfname);
strncpy (p->pr_fname, basename, sizeof (p->pr_fname));
p->pr_fname[sizeof (p->pr_fname) - 1] = 0;
ppsargs = prpsinfo_get_psargs (buffer, len);
ppsargs = prpsinfo_get_psargs (buffer, (int)len);
if (!ppsargs) {
goto error;
}
@ -133,7 +133,7 @@ error:
static proc_per_thread_t *get_proc_thread_content(int pid, int tid) {
char *temp_p_sigpend, *temp_p_sighold, *p_sigpend, *p_sighold;
int size;
size_t size;
const char * file = sdb_fmt ("/proc/%d/task/%d/stat", pid, tid);
char *buff = r_file_slurp (file, &size);
@ -482,7 +482,7 @@ static linux_map_entry_t *linux_get_mapped_files(RDebug *dbg, ut8 filter_flags)
RDebugMap *map;
bool is_anonymous = false, is_deleted = false, ret = 0;
char *file = NULL, *buff_maps= NULL, *buff_smaps = NULL;
int size_file = 0;
size_t size_file = 0;
file = r_str_newf ("/proc/%d/smaps", dbg->pid);
buff_smaps = r_file_slurp (file, &size_file);
@ -563,7 +563,7 @@ static auxv_buff_t *linux_get_auxv(RDebug *dbg) {
char *buff = NULL;
auxv_buff_t *auxv = NULL;
int auxv_entries;
int size;
size_t size;
const char *file = sdb_fmt ("/proc/%d/auxv", dbg->pid);
buff = r_file_slurp (file, &size);
@ -579,7 +579,7 @@ static auxv_buff_t *linux_get_auxv(RDebug *dbg) {
return NULL;
}
auxv->size = size;
auxv->data = r_mem_dup (buff, size);
auxv->data = r_mem_dup (buff, (int)size);
if (!auxv->data) {
free (buff);
free (auxv);
@ -788,7 +788,7 @@ static proc_per_process_t *get_proc_process_content (RDebug *dbg) {
ut16 filter_flags, default_filter_flags = 0x33;
char *buff;
const char *file = sdb_fmt ("/proc/%d/stat", dbg->pid);
int size;
size_t size;
buff = r_file_slurp (file, &size);
if (!buff) {

View File

@ -163,7 +163,7 @@ R_API int r_egg_setup(REgg *egg, const char *arch, int bits, int endian, const c
}
R_API int r_egg_include(REgg *egg, const char *file, int format) {
int sz;
size_t sz;
const ut8 *foo = (const ut8 *)r_file_slurp (file, &sz);
if (!foo) {
return 0;
@ -171,13 +171,13 @@ R_API int r_egg_include(REgg *egg, const char *file, int format) {
// XXX: format breaks compiler layers
switch (format) {
case 'r': // raw
r_egg_raw (egg, foo, sz);
r_egg_raw (egg, foo, (int)sz);
break;
case 'a': // assembly
r_buf_append_bytes (egg->buf, foo, sz);
r_buf_append_bytes (egg->buf, foo, (ut64)sz);
break;
default:
r_buf_append_bytes (egg->src, foo, sz);
r_buf_append_bytes (egg->src, foo, (ut64)sz);
}
free ((void *)foo);
return 1;

View File

@ -29,7 +29,7 @@ R_API char *r_file_abspath(const char *file);
R_API ut8 *r_inflate(const ut8 *src, int srcLen, int *srcConsumed, int *dstLen);
R_API ut8 *r_file_gzslurp(const char *str, int *outlen, int origonfail);
R_API char *r_stdin_slurp(int *sz);
R_API char *r_file_slurp(const char *str, int *usz);
R_API char *r_file_slurp(const char *str, R_NULLABLE size_t *usz);
//R_API char *r_file_slurp_range(const char *str, ut64 off, ut64 sz);
R_API char *r_file_slurp_range(const char *str, ut64 off, int sz, int *osz);
R_API char *r_file_slurp_random_line(const char *file);

View File

@ -157,7 +157,6 @@ static inline int getmalfd (RIOBfdbg *mal) {
static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
char *out;
int rlen;
if (__plugin_open (io, pathname, 0)) {
RIOBind iob;
RIOBfdbg *mal = R_NEW0 (RIOBfdbg);
@ -171,13 +170,14 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
free (mal);
return NULL;
}
size_t rlen;
out = r_file_slurp (pathname+8, &rlen);
if (!out || rlen < 1) {
free (mal);
free (out);
return NULL;
}
mal->size = rlen;
mal->size = (ut32)rlen;
mal->buf = malloc (mal->size+1);
if (mal->buf != NULL) {
memcpy (mal->buf, out, rlen);
@ -185,7 +185,7 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
return r_io_desc_new (io, &r_io_plugin_bfdbg,
pathname, rw, mode, mal);
}
eprintf ("Cannot allocate (%s) %d byte(s)\n",
eprintf ("Cannot allocate (%s) %"PFMT32u" byte(s)\n",
pathname+9, mal->size);
free (mal);
free (out);

View File

@ -163,10 +163,10 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
if (!mal) {
return NULL;
}
int len;
ut8 *data = (ut8*)r_file_slurp (pathname+7, &len); //memleak here?
size_t len;
ut8 *data = (ut8 *)r_file_slurp (pathname+7, &len); //memleak here?
int *size = (int*)&mal->size;
mal->buf = r_inflate (data, len, NULL, size);
mal->buf = r_inflate (data, (int)len, NULL, size);
if (mal->buf) {
return r_io_desc_new (io, &r_io_plugin_gzip, pathname, rw, mode, mal);
}

View File

@ -211,16 +211,17 @@ R_API int r_lang_run_string(RLang *lang, const char *code) {
}
R_API int r_lang_run_file(RLang *lang, const char *file) {
int len, ret = false;
int ret = false;
if (lang->cur) {
if (!lang->cur->run_file) {
if (lang->cur->run) {
size_t len;
char *code = r_file_slurp (file, &len);
if (!code) {
eprintf ("Could not open '%s'.\n", file);
return 0;
}
ret = lang->cur->run (lang, code, len);
ret = lang->cur->run (lang, code, (int)len);
free (code);
}
} else {

View File

@ -84,7 +84,7 @@ R_API int r_main_r2agent(int argc, char **argv) {
return usage (0);
}
int sz;
size_t sz;
pfile = r_file_slurp (httpauthfile, &sz);
if (pfile) {
so.authtokens = r_str_split_list (pfile, "\n", 0);

View File

@ -693,7 +693,7 @@ static void handle_sha256(const ut8 *block, int len) {
r_hash_free (ctx);
}
static ut8 *slurp(RCore **c, const char *file, int *sz) {
static ut8 *slurp(RCore **c, const char *file, size_t *sz) {
RIODesc *d;
RIO *io;
if (c && file && strstr (file, "://")) {
@ -917,7 +917,8 @@ R_API int r_main_radiff2(int argc, char **argv) {
RCore *c = NULL, *c2 = NULL;
RDiff *d;
ut8 *bufa = NULL, *bufb = NULL;
int o, sza, szb, /*diffmode = 0,*/ delta = 0;
int o, /*diffmode = 0,*/ delta = 0;
ut64 sza, szb;
int mode = MODE_DIFF;
int gmode = GRAPH_DEFAULT_MODE;
int diffops = 0;
@ -1099,11 +1100,11 @@ R_API int r_main_radiff2(int argc, char **argv) {
ut64 addra = r_num_math (c->num, addr);
bufa = (ut8 *) r_core_cmd_strf (c, "af;pdc @ 0x%08"PFMT64x, addra);
sza = strlen ((const char *) bufa);
sza = (ut64)strlen ((const char *) bufa);
ut64 addrb = r_num_math (c2->num, addr);
bufb = (ut8 *) r_core_cmd_strf (c2, "af;pdc @ 0x%08"PFMT64x, addrb);
szb = strlen ((const char *) bufb);
szb = (ut64)strlen ((const char *) bufb);
mode = MODE_DIFF;
} else if (mode == MODE_GRAPH) {
int depth = r_config_get_i (c->config, "anal.depth");
@ -1140,11 +1141,17 @@ R_API int r_main_radiff2(int argc, char **argv) {
r_core_diff_show (c, c2);
}
} else if (mode == MODE_DIFF_IMPORTS) {
bufa = get_imports (c, &sza);
bufb = get_imports (c2, &szb);
int sz;
bufa = get_imports (c, &sz);
sza = sz;
bufb = get_imports (c2, &sz);
szb = sz;
} else if (mode == MODE_DIFF_STRS) {
bufa = get_strings (c, &sza);
bufb = get_strings (c2, &szb);
int sz;
bufa = get_strings (c, &sz);
sza = sz;
bufb = get_strings (c2, &sz);
szb = sz;
}
if (mode == MODE_CODE || mode == MODE_GRAPH) {
r_cons_flush ();
@ -1156,23 +1163,27 @@ R_API int r_main_radiff2(int argc, char **argv) {
return 0;
}
break;
default:
bufa = slurp (&c, file, &sza);
default: {
size_t fsz;
bufa = slurp (&c, file, &fsz);
sza = fsz;
if (!bufa) {
eprintf ("radiff2: Cannot open %s\n", r_str_get (file));
return 1;
}
bufb = slurp (&c, file2, &szb);
bufb = slurp (&c, file2, &fsz);
szb = fsz;
if (!bufb) {
eprintf ("radiff2: Cannot open: %s\n", r_str_get (file2));
free (bufa);
return 1;
}
if (sza != szb) {
eprintf ("File size differs %d vs %d\n", sza, szb);
eprintf ("File size differs %"PFMT64u" vs %"PFMT64u"\n", (ut64)sza, (ut64)szb);
}
break;
}
}
// initialize RCons
(void)r_cons_new ();
@ -1182,13 +1193,13 @@ R_API int r_main_radiff2(int argc, char **argv) {
if (!c && !r_list_empty (evals)) {
c = opencore (NULL);
}
dump_cols_hexii (bufa, sza, bufb, szb, (r_cons_get_size (NULL) > 112)? 16: 8);
dump_cols_hexii (bufa, (int)sza, bufb, (int)szb, (r_cons_get_size (NULL) > 112)? 16: 8);
break;
case MODE_COLS:
if (!c && !r_list_empty (evals)) {
c = opencore (NULL);
}
dump_cols (bufa, sza, bufb, szb, (r_cons_get_size (NULL) > 112)? 16: 8);
dump_cols (bufa, (int)sza, bufb, (int)szb, (r_cons_get_size (NULL) > 112)? 16: 8);
break;
case MODE_DIFF:
case MODE_DIFF_STRS:
@ -1196,10 +1207,10 @@ R_API int r_main_radiff2(int argc, char **argv) {
d = r_diff_new ();
r_diff_set_delta (d, delta);
if (diffmode == 'j') {
printf ("{\"files\":[{\"filename\":\"%s\", \"size\":%d, \"sha256\":\"", file, sza);
handle_sha256 (bufa, sza);
printf ("\"},\n{\"filename\":\"%s\", \"size\":%d, \"sha256\":\"", file2, szb);
handle_sha256 (bufb, szb);
printf ("{\"files\":[{\"filename\":\"%s\", \"size\":%"PFMT64u", \"sha256\":\"", file, sza);
handle_sha256 (bufa, (int)sza);
printf ("\"},\n{\"filename\":\"%s\", \"size\":%"PFMT64u", \"sha256\":\"", file2, szb);
handle_sha256 (bufb, (int)szb);
printf ("\"}],\n");
printf ("\"changes\":[");
}
@ -1208,16 +1219,16 @@ R_API int r_main_radiff2(int argc, char **argv) {
write (1, "\x04", 1);
}
if (diffmode == 'U') {
char * res = r_diff_buffers_unified (d, bufa, sza, bufb, szb);
char * res = r_diff_buffers_unified (d, bufa, (int)sza, bufb, (int)szb);
printf ("%s", res);
free (res);
} else if (diffmode == 'B') {
r_diff_set_callback (d, &bcb, 0);
r_diff_buffers (d, bufa, sza, bufb, szb);
r_diff_buffers (d, bufa, (ut32)sza, bufb, (ut32)szb);
write (1, "\x00", 1);
} else {
r_diff_set_callback (d, &cb, 0); // (void *)(size_t)diffmode);
r_diff_buffers (d, bufa, sza, bufb, szb);
r_diff_buffers (d, bufa, (ut32)sza, bufb, (ut32)szb);
}
if (diffmode == 'j') {
printf ("]\n");
@ -1238,7 +1249,7 @@ R_API int r_main_radiff2(int argc, char **argv) {
} else {
d->type = 0;
}
r_diff_buffers_distance (d, bufa, sza, bufb, szb, &count, &sim);
r_diff_buffers_distance (d, bufa, (ut32)sza, bufb, (ut32)szb, &count, &sim);
r_diff_free (d);
}
}

View File

@ -378,10 +378,10 @@ R_API int r_main_ragg2(int argc, char **argv) {
goto fail;
}
int l;
size_t l;
char *buf = r_file_slurp (textFile, &l);
if (buf && l > 0) {
r_egg_raw (egg, (const ut8*)buf, l);
r_egg_raw (egg, (const ut8*)buf, (int)l);
} else {
eprintf ("Error loading '%s'\n", textFile);
}
@ -423,10 +423,10 @@ R_API int r_main_ragg2(int argc, char **argv) {
// add raw file
if (contents) {
int l;
size_t l;
char *buf = r_file_slurp (contents, &l);
if (buf && l > 0) {
r_egg_raw (egg, (const ut8*)buf, l);
r_egg_raw (egg, (const ut8*)buf, (int)l);
} else {
eprintf ("Error loading '%s'\n", contents);
}

View File

@ -42,7 +42,9 @@ static void do_hash_seed(const char *seed) {
return;
}
if (seed[0] == '@') {
s.buf = (ut8 *)r_file_slurp (seed + 1, &s.len);
size_t len;
s.buf = (ut8 *)r_file_slurp (seed + 1, &len);
s.len = (size_t)len;
return;
}
s.buf = (ut8 *) malloc (strlen (seed) + 128);
@ -374,10 +376,15 @@ static int encrypt_or_decrypt_file(const char *algo, int direction, char *filena
RCrypto *cry = r_crypto_new ();
if (r_crypto_use (cry, algo)) {
if (r_crypto_set_key (cry, s.buf, s.len, 0, direction)) {
int file_size;
ut8 *buf = strcmp (filename, "-")
? (ut8 *) r_file_slurp (filename, &file_size)
: (ut8 *) r_stdin_slurp (&file_size);
size_t file_size;
ut8 *buf;
if (strcmp (filename, "-") == 0) {
int sz;
buf = (ut8 *)r_stdin_slurp (&sz);
file_size = (size_t)sz;
} else {
buf = (ut8 *)r_file_slurp (filename, &file_size);
}
if (!buf) {
eprintf ("rahash2: Cannot open '%s'\n", filename);
return -1;

View File

@ -742,7 +742,7 @@ R_API int r_main_rasm2(int argc, char *argv[]) {
if (file) {
char *content;
int length = 0;
size_t length = 0;
if (!strcmp (file, "-")) {
int sz = 0;
ut8 *buf = (ut8 *)r_stdin_slurp (&sz);
@ -770,7 +770,7 @@ R_API int r_main_rasm2(int argc, char *argv[]) {
} else {
content = r_file_slurp (file, &length);
if (content) {
if (length < 0) {
if (length > ST32_MAX) {
eprintf ("rasm2: File %s is too big\n", file);
ret = 1;
} else {

View File

@ -220,7 +220,7 @@ R_API RBuffer *r_buf_new_file(const char *file, int perm, int mode) {
// TODO: rename to new_from_file ?
R_API RBuffer *r_buf_new_slurp(const char *file) {
int len;
size_t len;
char *tmp = r_file_slurp (file, &len);
if (!tmp) {
return NULL;
@ -228,7 +228,7 @@ R_API RBuffer *r_buf_new_slurp(const char *file) {
struct buf_bytes_user u = { 0 };
u.data_steal = (ut8 *)tmp;
u.length = len;
u.length = (ut64)len;
u.steal = true;
return new_buffer (R_BUFFER_BYTES, &u);
}

View File

@ -342,7 +342,7 @@ R_API char *r_stdin_slurp (int *sz) {
#endif
}
R_API char *r_file_slurp(const char *str, int *usz) {
R_API char *r_file_slurp(const char *str, R_NULLABLE size_t *usz) {
size_t rsz;
char *ret;
FILE *fd;
@ -390,26 +390,26 @@ R_API char *r_file_slurp(const char *str, int *usz) {
fclose (fd);
ret[sz] = '\0';
if (usz) {
*usz = (int)sz;
*usz = sz;
}
return ret;
}
R_API ut8 *r_file_gzslurp(const char *str, int *outlen, int origonfail) {
int sz;
ut8 *in, *out;
if (outlen) {
*outlen = 0;
}
size_t sz;
in = (ut8*)r_file_slurp (str, &sz);
if (!in) {
return NULL;
}
out = r_inflate (in, sz, NULL, outlen);
out = r_inflate (in, (int)sz, NULL, outlen);
if (!out && origonfail) {
// if uncompression fails, return orig buffer ?
if (outlen) {
*outlen = sz;
*outlen = (int)sz;
}
in[sz] = 0;
return in;
@ -494,9 +494,9 @@ R_API char *r_file_slurp_random_line(const char *file) {
R_API char *r_file_slurp_random_line_count(const char *file, int *line) {
/* Reservoir Sampling */
char *ptr = NULL, *str;
int sz, i, lines, selection = -1;
size_t i, lines, selection = -1;
int start = *line;
if ((str = r_file_slurp (file, &sz))) {
if ((str = r_file_slurp (file, NULL))) {
r_num_irand ();
for (i = 0; str[i]; i++) {
if (str[i] == '\n') {
@ -535,7 +535,7 @@ R_API char *r_file_slurp_random_line_count(const char *file, int *line) {
R_API char *r_file_slurp_line(const char *file, int line, int context) {
int i, lines = 0;
int sz;
size_t sz;
char *ptr = NULL, *str = r_file_slurp (file, &sz);
// TODO: Implement context
if (str) {
@ -569,7 +569,7 @@ R_API char *r_file_slurp_line(const char *file, int line, int context) {
R_API char *r_file_slurp_lines_from_bottom(const char *file, int line) {
int i, lines = 0;
int sz;
size_t sz;
char *ptr = NULL, *str = r_file_slurp (file, &sz);
// TODO: Implement context
if (str) {
@ -596,7 +596,7 @@ R_API char *r_file_slurp_lines_from_bottom(const char *file, int line) {
R_API char *r_file_slurp_lines(const char *file, int line, int count) {
int i, lines = 0;
int sz;
size_t sz;
char *ptr = NULL, *str = r_file_slurp (file, &sz);
// TODO: Implement context
if (str) {

View File

@ -569,9 +569,8 @@ R_API bool r_sys_aslr(int val) {
R_API int r_sys_thp_mode(void) {
#if __linux__
const char *thp = "/sys/kernel/mm/transparent_hugepage/enabled";
int sz;
int ret = 0;
char *val = r_file_slurp (thp, &sz);
char *val = r_file_slurp (thp, NULL);
if (val) {
if (strstr (val, "[madvise]")) {
ret = 1;

View File

@ -256,7 +256,6 @@ static int cmpstr (const void *_a, const void *_b) {
}
R_API char *r_syscmd_sort(const char *file) {
int sz;
const char *p = NULL;
RList *list = NULL;
if (file) {
@ -269,7 +268,7 @@ R_API char *r_syscmd_sort(const char *file) {
if (p && *p) {
char *filename = strdup (p);
r_str_trim (filename);
char *data = r_file_slurp (filename, &sz);
char *data = r_file_slurp (filename, NULL);
if (!data) {
eprintf ("No such file or directory\n");
} else {
@ -335,7 +334,6 @@ R_API char *r_syscmd_tail(const char *file, int count) {
}
R_API char *r_syscmd_uniq(const char *file) {
int sz;
const char *p = NULL;
RList *list = NULL;
if (file) {
@ -348,7 +346,7 @@ R_API char *r_syscmd_uniq(const char *file) {
if (p && *p) {
char *filename = strdup (p);
r_str_trim (filename);
char *data = r_file_slurp (filename, &sz);
char *data = r_file_slurp (filename, NULL);
if (!data) {
eprintf ("No such file or directory\n");
} else {
@ -367,7 +365,6 @@ R_API char *r_syscmd_uniq(const char *file) {
}
R_API char *r_syscmd_join(const char *file1, const char *file2) {
int sz1, sz2;
const char *p1 = NULL, *p2 = NULL;
RList *list1, *list2, *list = r_list_newf (NULL);
if (!list) {
@ -392,8 +389,8 @@ R_API char *r_syscmd_join(const char *file1, const char *file2) {
char *filename2 = strdup (p2);
r_str_trim (filename1);
r_str_trim (filename2);
char *data1 = r_file_slurp (filename1, &sz1);
char *data2 = r_file_slurp (filename2, &sz2);
char *data1 = r_file_slurp (filename1, NULL);
char *data2 = r_file_slurp (filename2, NULL);
char *data = NULL;
RListIter *iter1, *iter2;
if (!data1 && !data2) {
@ -439,7 +436,6 @@ R_API char *r_syscmd_join(const char *file1, const char *file2) {
}
R_API char *r_syscmd_cat(const char *file) {
int sz;
const char *p = NULL;
if (file) {
if ((p = strchr (file, ' '))) {
@ -451,7 +447,7 @@ R_API char *r_syscmd_cat(const char *file) {
if (p && *p) {
char *filename = strdup (p);
r_str_trim (filename);
char *data = r_file_slurp (filename, &sz);
char *data = r_file_slurp (filename, NULL);
if (!data) {
eprintf ("No such file or directory\n");
}

View File

@ -8065,13 +8065,15 @@ R_API ut64 r_bin_java_get_main(RBinJavaObj *bin) {
}
R_API RBinJavaObj *r_bin_java_new(const char *file, ut64 loadaddr, Sdb *kv) {
ut8 *buf;
RBinJavaObj *bin = R_NEW0 (RBinJavaObj);
if (!bin) {
return NULL;
}
bin->file = strdup (file);
if (!(buf = (ut8 *) r_file_slurp (file, &bin->size))) {
size_t sz;
ut8 *buf = (ut8 *)r_file_slurp (file, &sz);
bin->size = sz;
if (!buf) {
return r_bin_java_free (bin);
}
if (!r_bin_java_new_bin (bin, loadaddr, kv, buf, bin->size)) {

View File

@ -3,9 +3,9 @@
#define F "/etc/services"
int main () {
int len;
size_t len;
char *out= r_file_slurp (F, &len);
r_file_dump ("a", out, len);
r_file_dump ("a", out, (int)len);
system ("md5 "F);
system ("md5 a");
return 0;