Remove eprintfs (part 1) and rz-bin -X (#2558)
* Removed eprintfs from librz/bin/bfile.c * Removed rz_bin_package and rz-bin -X because untested and not implemented * Removed eprintfs from librz/bin/bin.c * Be verbose on clang-format and not on command execution * Removed eprintfs from librz/bin/bobj.c * Removed eprintfs from librz/bin/dwarf.c * Removed eprintfs from librz/bin/format/coff/coff.c * Removed eprintfs from librz/bin/format/dmp/dmp64.c * Removed eprintfs from librz/bin/format/luac/luac_bin.c * Removed eprintf from librz/bin/format/luac/luac_common.c and refactoring * Removed eprintf from librz/bin/format/luac/v53/parse_53.c * Removed eprintf from librz/bin/format/mach0/coresymbolication.c * Removed eprintf from librz/bin/format/mach0/dyldcache.c * Removed eprintf from librz/bin/format/luac/v54/parse_54.c * Removed eprintf from librz/bin/format/mach0/dyldcache_rebase.c * Removed eprintf from librz/bin/format/mach0/fatmach0.c * Removed eprintf from librz/bin/format/mdmp/mdmp.c * Removed eprintf from librz/bin/format/mz/mz.c * Removed eprintf from nso/nxo bin format * Removed eprintf from librz/bin/format/objc/mach0_classes.c * Removed eprintf from librz/bin/format/omf/omf.c * Removed eprintf & bprintf from librz/bin/format/pe/pe.c * Removed eprintf from librz/bin/format/pe/pemixed.c * Fixed luac test
This commit is contained in:
parent
3cbde10260
commit
5e09c02109
28 changed files with 370 additions and 558 deletions
|
|
@ -499,7 +499,7 @@ RZ_IPI RzBinFile *rz_bin_file_xtr_load_buffer(RzBin *bin, RzBinXtrPlugin *xtr, c
|
|||
} else if (xtr->extractall_from_bytes) {
|
||||
ut64 sz = 0;
|
||||
const ut8 *bytes = rz_buf_data(buf, &sz);
|
||||
eprintf("TODO: Implement extractall_from_buffer in '%s' xtr.bin plugin\n", xtr->name);
|
||||
RZ_LOG_INFO("TODO: Implement extractall_from_buffer in '%s' xtr.bin plugin\n", xtr->name);
|
||||
bf->xtr_data = xtr->extractall_from_bytes(bin, bytes, sz);
|
||||
}
|
||||
if (bf->xtr_data) {
|
||||
|
|
@ -654,7 +654,7 @@ static inline bool add_file_hash(RzMsgDigest *md, const char *name, RzList *list
|
|||
|
||||
RzBinFileHash *fh = RZ_NEW0(RzBinFileHash);
|
||||
if (!fh) {
|
||||
eprintf("Cannot allocate file hash\n");
|
||||
RZ_LOG_ERROR("Cannot allocate RzBinFileHash\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -685,19 +685,19 @@ RZ_API RZ_OWN RzList *rz_bin_file_compute_hashes(RzBin *bin, RzBinFile *bf, ut64
|
|||
buf_len = rz_io_desc_size(iod);
|
||||
if (buf_len > limit) {
|
||||
if (bin->verbose) {
|
||||
eprintf("Warning: rz_bin_file_hash: file exceeds bin.hashlimit\n");
|
||||
RZ_LOG_WARN("rz_bin_file_hash: file exceeds bin.hashlimit\n");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
buf = malloc(blocksize);
|
||||
if (!buf) {
|
||||
eprintf("Cannot allocate computation buffer\n");
|
||||
RZ_LOG_ERROR("Cannot allocate buffer for hash computation\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
file_hashes = rz_list_newf((RzListFree)rz_bin_file_hash_free);
|
||||
if (!file_hashes) {
|
||||
eprintf("Cannot allocate list\n");
|
||||
RZ_LOG_ERROR("Cannot allocate file hash list\n");
|
||||
goto rz_bin_file_compute_hashes_bad;
|
||||
}
|
||||
|
||||
|
|
@ -830,7 +830,7 @@ RZ_API RzBinSymbol *rz_bin_file_add_method(RzBinFile *bf, const char *klass, con
|
|||
|
||||
RzBinClass *c = rz_bin_file_add_class(bf, klass, NULL, 0);
|
||||
if (!c) {
|
||||
eprintf("Cannot allocate class %s\n", klass);
|
||||
RZ_LOG_ERROR("Cannot allocate RzBinClass for '%s'\n", klass);
|
||||
return NULL;
|
||||
}
|
||||
RzBinSymbol *sym = __getMethod(bf, klass, method);
|
||||
|
|
@ -846,12 +846,6 @@ RZ_API RzBinSymbol *rz_bin_file_add_method(RzBinFile *bf, const char *klass, con
|
|||
return sym;
|
||||
}
|
||||
|
||||
RZ_API RzBinField *rz_bin_file_add_field(RzBinFile *binfile, const char *classname, const char *name) {
|
||||
// TODO: add_field into class
|
||||
// eprintf ("TODO add field: %s \n", name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RZ_API RzList *rz_bin_file_get_trycatch(RzBinFile *bf) {
|
||||
rz_return_val_if_fail(bf && bf->o && bf->o->plugin, NULL);
|
||||
if (bf->o->plugin->trycatch) {
|
||||
|
|
|
|||
101
librz/bin/bin.c
101
librz/bin/bin.c
|
|
@ -235,7 +235,7 @@ RZ_API RzBinFile *rz_bin_open(RzBin *bin, const char *file, RzBinOptions *opt) {
|
|||
opt->fd = iob->fd_open(iob->io, file, RZ_PERM_R, 0644);
|
||||
}
|
||||
if (opt->fd < 0) {
|
||||
eprintf("Couldn't open bin for file '%s'\n", file);
|
||||
RZ_LOG_ERROR("Couldn't open bin for file '%s'\n", file);
|
||||
return NULL;
|
||||
}
|
||||
opt->sz = 0;
|
||||
|
|
@ -283,7 +283,7 @@ RZ_API RzBinFile *rz_bin_open_buf(RzBin *bin, RzBuffer *buf, RzBinOptions *opt)
|
|||
// <xtr_name>:<bin_type_name>
|
||||
rz_list_foreach (bin->binxtrs, it, xtr) {
|
||||
if (!xtr->check_buffer) {
|
||||
eprintf("Missing check_buffer callback for '%s'\n", xtr->name);
|
||||
RZ_LOG_ERROR("Missing check_buffer callback for '%s'\n", xtr->name);
|
||||
continue;
|
||||
}
|
||||
if (xtr->check_buffer(buf)) {
|
||||
|
|
@ -577,7 +577,7 @@ RZ_API bool rz_bin_list_plugin(RzBin *bin, const char *name, PJ *pj, int json) {
|
|||
return true;
|
||||
}
|
||||
|
||||
eprintf("Cannot find plugin %s\n", name);
|
||||
RZ_LOG_ERROR("Cannot find plugin %s\n", name);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -599,25 +599,17 @@ RZ_API void rz_bin_set_baddr(RzBin *bin, ut64 baddr) {
|
|||
rz_return_if_fail(bin);
|
||||
RzBinFile *bf = rz_bin_cur(bin);
|
||||
RzBinObject *o = rz_bin_cur_object(bin);
|
||||
if (o) {
|
||||
if (!o->plugin || !o->plugin->baddr) {
|
||||
return;
|
||||
}
|
||||
ut64 file_baddr = o->plugin->baddr(bf);
|
||||
if (baddr == UT64_MAX) {
|
||||
o->opts.baseaddr = file_baddr;
|
||||
o->baddr_shift = 0; // o->baddr; // - file_baddr;
|
||||
} else {
|
||||
if (file_baddr != UT64_MAX) {
|
||||
o->opts.baseaddr = baddr;
|
||||
o->baddr_shift = baddr - file_baddr;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
eprintf("Warning: This should be an assert probably.\n");
|
||||
if (!o || !o->plugin || !o->plugin->baddr) {
|
||||
return;
|
||||
}
|
||||
ut64 file_baddr = o->plugin->baddr(bf);
|
||||
if (baddr == UT64_MAX) {
|
||||
o->opts.baseaddr = file_baddr;
|
||||
o->baddr_shift = 0; // o->baddr; // - file_baddr;
|
||||
} else if (file_baddr != UT64_MAX) {
|
||||
o->opts.baseaddr = baddr;
|
||||
o->baddr_shift = baddr - file_baddr;
|
||||
}
|
||||
// XXX - update all the infos?
|
||||
// maybe in RzBinFile.rebase() ?
|
||||
}
|
||||
|
||||
// XXX: those accessors are redundant
|
||||
|
|
@ -902,73 +894,6 @@ RZ_API RzBuffer *rz_bin_create(RzBin *bin, const char *p,
|
|||
return plugin->create(bin, code, codelen, data, datalen, opt);
|
||||
}
|
||||
|
||||
RZ_API RzBuffer *rz_bin_package(RzBin *bin, const char *type, const char *file, RzList *files) {
|
||||
if (!strcmp(type, "zip")) {
|
||||
// XXX: implement me
|
||||
rz_warn_if_reached();
|
||||
} else if (!strcmp(type, "fat")) {
|
||||
// XXX: this should be implemented in the fat plugin, not here
|
||||
// XXX should pick the callback from the plugin list
|
||||
const char *f;
|
||||
RzListIter *iter;
|
||||
ut32 num;
|
||||
ut8 *num8 = (ut8 *)#
|
||||
RzBuffer *buf = rz_buf_new_file(file, O_RDWR | O_CREAT, 0644);
|
||||
if (!buf) {
|
||||
eprintf("Cannot open file %s - Permission Denied.\n", file);
|
||||
return NULL;
|
||||
}
|
||||
rz_buf_write_at(buf, 0, (const ut8 *)"\xca\xfe\xba\xbe", 4);
|
||||
int count = rz_list_length(files);
|
||||
|
||||
num = rz_read_be32(&count);
|
||||
ut64 from = 0x1000;
|
||||
rz_buf_write_at(buf, 4, num8, 4);
|
||||
int off = 12;
|
||||
int item = 0;
|
||||
rz_list_foreach (files, iter, f) {
|
||||
size_t f_len = 0;
|
||||
ut8 *f_buf = (ut8 *)rz_file_slurp(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);
|
||||
continue;
|
||||
}
|
||||
item++;
|
||||
/* CPU */
|
||||
num8[0] = f_buf[7];
|
||||
num8[1] = f_buf[6];
|
||||
num8[2] = f_buf[5];
|
||||
num8[3] = f_buf[4];
|
||||
rz_buf_write_at(buf, off - 4, num8, 4);
|
||||
/* SUBTYPE */
|
||||
num8[0] = f_buf[11];
|
||||
num8[1] = f_buf[10];
|
||||
num8[2] = f_buf[9];
|
||||
num8[3] = f_buf[8];
|
||||
rz_buf_write_at(buf, off, num8, 4);
|
||||
ut32 from32 = from;
|
||||
/* FROM */
|
||||
num = rz_read_be32(&from32);
|
||||
rz_buf_write_at(buf, off + 4, num8, 4);
|
||||
rz_buf_write_at(buf, from, f_buf, f_len);
|
||||
/* SIZE */
|
||||
num = rz_read_be32(&f_len);
|
||||
rz_buf_write_at(buf, off + 8, num8, 4);
|
||||
off += 20;
|
||||
from += f_len + (f_len % 0x1000);
|
||||
free(f_buf);
|
||||
}
|
||||
rz_buf_free(buf);
|
||||
return NULL;
|
||||
} else {
|
||||
eprintf("Usage: rz-bin -X [fat|zip] [filename] [files ...]\n");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RZ_API RzList * /*<RzBinClass>*/ rz_bin_get_classes(RzBin *bin) {
|
||||
rz_return_val_if_fail(bin, NULL);
|
||||
RzBinObject *o = rz_bin_cur_object(bin);
|
||||
|
|
|
|||
|
|
@ -226,7 +226,6 @@ static RzList *classes_from_symbols(RzBinFile *bf) {
|
|||
char *dn = sym->dname;
|
||||
char *fn = swiftField(dn, cn);
|
||||
if (fn) {
|
||||
// eprintf ("FIELD %s %s\n", cn, fn);
|
||||
RzBinField *f = rz_bin_field_new(sym->paddr, sym->vaddr, sym->size, fn, NULL, NULL, false);
|
||||
rz_list_append(c->fields, f);
|
||||
free(fn);
|
||||
|
|
@ -272,7 +271,7 @@ RZ_IPI RzBinObject *rz_bin_object_new(RzBinFile *bf, RzBinPlugin *plugin, RzBinO
|
|||
if (plugin && plugin->load_buffer) {
|
||||
if (!plugin->load_buffer(bf, o, bf->buf, sdb)) {
|
||||
if (bf->rbin->verbose) {
|
||||
eprintf("Error in rz_bin_object_new: load_buffer failed for %s plugin\n", plugin->name);
|
||||
RZ_LOG_ERROR("rz_bin_object_new: load_buffer failed for %s plugin\n", plugin->name);
|
||||
}
|
||||
sdb_free(o->kv);
|
||||
free(o);
|
||||
|
|
@ -330,22 +329,22 @@ static void filter_classes(RzBinFile *bf, RzList *list) {
|
|||
}
|
||||
int namepad_len = strlen(cls->name) + 32;
|
||||
char *namepad = malloc(namepad_len + 1);
|
||||
if (namepad) {
|
||||
char *p;
|
||||
strcpy(namepad, cls->name);
|
||||
p = rz_bin_filter_name(bf, db, cls->index, namepad);
|
||||
if (p) {
|
||||
namepad = p;
|
||||
if (!namepad) {
|
||||
RZ_LOG_ERROR("Cannot allocate %d byte(s)\n", namepad_len);
|
||||
break;
|
||||
}
|
||||
|
||||
strcpy(namepad, cls->name);
|
||||
char *p = rz_bin_filter_name(bf, db, cls->index, namepad);
|
||||
if (p) {
|
||||
namepad = p;
|
||||
}
|
||||
free(cls->name);
|
||||
cls->name = namepad;
|
||||
rz_list_foreach (cls->methods, iter2, sym) {
|
||||
if (sym->name) {
|
||||
rz_bin_filter_sym(bf, ht, sym->vaddr, sym);
|
||||
}
|
||||
free(cls->name);
|
||||
cls->name = namepad;
|
||||
rz_list_foreach (cls->methods, iter2, sym) {
|
||||
if (sym->name) {
|
||||
rz_bin_filter_sym(bf, ht, sym->vaddr, sym);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
eprintf("Cannot alloc %d byte(s)\n", namepad_len);
|
||||
}
|
||||
}
|
||||
ht_pu_free(db);
|
||||
|
|
|
|||
|
|
@ -452,7 +452,7 @@ static inline ut64 dwarf_read_address(size_t size, bool big_endian, const ut8 **
|
|||
default:
|
||||
result = 0;
|
||||
*buf += size;
|
||||
eprintf("Weird dwarf address size: %zu.", size);
|
||||
RZ_LOG_WARN("Weird dwarf address size: %zu.", size);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
@ -1483,7 +1483,7 @@ static const ut8 *parse_attr_value(const ut8 *obuf, int obuf_len,
|
|||
value->address = READ64(buf);
|
||||
break;
|
||||
default:
|
||||
eprintf("DWARF: Unexpected pointer size: %u\n", (unsigned)hdr->address_size);
|
||||
RZ_LOG_ERROR("DWARF: Unexpected pointer size: %u\n", (unsigned)hdr->address_size);
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
|
|
@ -1701,7 +1701,7 @@ static const ut8 *parse_attr_value(const ut8 *obuf, int obuf_len,
|
|||
buf = rz_uleb128(buf, buf_end - buf, &value->address, NULL);
|
||||
break;
|
||||
default:
|
||||
eprintf("Unknown DW_FORM 0x%02" PFMT64x "\n", def->attr_form);
|
||||
RZ_LOG_ERROR("Unknown DW_FORM 0x%02" PFMT64x "\n", def->attr_form);
|
||||
value->uconstant = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -1937,7 +1937,7 @@ static RzBinDwarfDebugInfo *parse_info_raw(RzBinDwarfDebugAbbrev *da,
|
|||
}
|
||||
|
||||
if (da->decls->count >= da->capacity) {
|
||||
eprintf("WARNING: malformed dwarf have not enough buckets for decls.\n");
|
||||
RZ_LOG_WARN("malformed dwarf have not enough buckets for decls.\n");
|
||||
}
|
||||
rz_warn_if_fail(da->count <= da->capacity);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,10 +6,6 @@
|
|||
|
||||
#include "coff.h"
|
||||
|
||||
#define bprintf \
|
||||
if (obj->verbose) \
|
||||
eprintf
|
||||
|
||||
RZ_API bool rz_coff_supported_arch(const ut8 *buf) {
|
||||
ut16 arch = *(ut16 *)buf;
|
||||
switch (arch) {
|
||||
|
|
@ -248,20 +244,20 @@ static int rz_bin_coff_init(struct rz_bin_coff_obj *obj, RzBuffer *buf, bool ver
|
|||
obj->imp_ht = ht_up_new0();
|
||||
obj->imp_index = ht_uu_new0();
|
||||
if (!rz_bin_coff_init_hdr(obj)) {
|
||||
bprintf("Warning: failed to init hdr\n");
|
||||
RZ_LOG_ERROR("failed to init hdr\n");
|
||||
return false;
|
||||
}
|
||||
rz_bin_coff_init_opt_hdr(obj);
|
||||
if (!rz_bin_coff_init_scn_hdr(obj)) {
|
||||
bprintf("Warning: failed to init section header\n");
|
||||
RZ_LOG_ERROR("failed to init section header\n");
|
||||
return false;
|
||||
}
|
||||
if (!rz_bin_coff_init_scn_va(obj)) {
|
||||
bprintf("Warning: failed to init section VA table\n");
|
||||
RZ_LOG_ERROR("failed to init section VA table\n");
|
||||
return false;
|
||||
}
|
||||
if (!rz_bin_coff_init_symtable(obj)) {
|
||||
bprintf("Warning: failed to init symtable\n");
|
||||
RZ_LOG_ERROR("failed to init symtable\n");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -50,12 +50,12 @@ static int rz_bin_dmp64_init_memory_runs(struct rz_bin_dmp64_obj_t *obj) {
|
|||
int i, j;
|
||||
dmp64_p_memory_desc *mem_desc = &obj->header->PhysicalMemoryBlock;
|
||||
if (!memcmp(mem_desc, DMP_UNUSED_MAGIC, 4)) {
|
||||
eprintf("Warning: Invalid PhysicalMemoryDescriptor\n");
|
||||
RZ_LOG_ERROR("Invalid PhysicalMemoryDescriptor magic\n");
|
||||
return false;
|
||||
}
|
||||
ut64 num_runs = mem_desc->NumberOfRuns;
|
||||
if (num_runs * sizeof(dmp_p_memory_run) >= rz_offsetof(dmp64_header, ContextRecord)) {
|
||||
eprintf("Warning: Invalid PhysicalMemoryDescriptor\n");
|
||||
RZ_LOG_ERROR("Invalid PhysicalMemoryDescriptor offset\n");
|
||||
return false;
|
||||
}
|
||||
obj->pages = rz_list_newf(free);
|
||||
|
|
@ -65,7 +65,7 @@ static int rz_bin_dmp64_init_memory_runs(struct rz_bin_dmp64_obj_t *obj) {
|
|||
dmp_p_memory_run *runs = calloc(num_runs, sizeof(dmp_p_memory_run));
|
||||
ut64 num_runs_offset = rz_offsetof(dmp64_header, PhysicalMemoryBlockBuffer) + rz_offsetof(dmp64_p_memory_desc, NumberOfRuns);
|
||||
if (rz_buf_read_at(obj->b, num_runs_offset, (ut8 *)runs, num_runs * sizeof(dmp_p_memory_run)) < 0) {
|
||||
eprintf("Warning: read memory runs\n");
|
||||
RZ_LOG_ERROR("Cannot read memory runs value from dmp64.\n");
|
||||
free(runs);
|
||||
return false;
|
||||
};
|
||||
|
|
@ -87,7 +87,7 @@ static int rz_bin_dmp64_init_memory_runs(struct rz_bin_dmp64_obj_t *obj) {
|
|||
}
|
||||
}
|
||||
if (mem_desc->NumberOfPages != num_page) {
|
||||
eprintf("Warning: Number of Pages not matches\n");
|
||||
RZ_LOG_WARN("The number of pages in the structure does not match with the counted one.\n");
|
||||
}
|
||||
|
||||
free(runs);
|
||||
|
|
@ -96,11 +96,11 @@ static int rz_bin_dmp64_init_memory_runs(struct rz_bin_dmp64_obj_t *obj) {
|
|||
|
||||
static int rz_bin_dmp64_init_header(struct rz_bin_dmp64_obj_t *obj) {
|
||||
if (!(obj->header = RZ_NEW0(dmp64_header))) {
|
||||
rz_sys_perror("RZ_NEW0 (header)");
|
||||
RZ_LOG_ERROR("Cannot allocate dmp64_header.\n");
|
||||
return false;
|
||||
}
|
||||
if (rz_buf_read_at(obj->b, 0, (ut8 *)obj->header, sizeof(dmp64_header)) < 0) {
|
||||
eprintf("Warning: read header\n");
|
||||
RZ_LOG_ERROR("cannot read dmp64 header\n");
|
||||
return false;
|
||||
}
|
||||
obj->dtb = obj->header->DirectoryTableBase;
|
||||
|
|
@ -244,7 +244,7 @@ static int rz_bin_dmp64_init_bmp_pages(struct rz_bin_dmp64_obj_t *obj) {
|
|||
create_new_page = false;
|
||||
}
|
||||
if (obj->bmp_header->TotalPresentPages != num_bitset) {
|
||||
eprintf("Warning: TotalPresentPages not matched\n");
|
||||
RZ_LOG_ERROR("The total present pages number in the header does not match with the counted one.\n");
|
||||
rz_bitmap_free(bitmap);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -255,22 +255,22 @@ static int rz_bin_dmp64_init_bmp_pages(struct rz_bin_dmp64_obj_t *obj) {
|
|||
|
||||
static int rz_bin_dmp64_init_bmp_header(struct rz_bin_dmp64_obj_t *obj) {
|
||||
if (!(obj->bmp_header = RZ_NEW0(dmp_bmp_header))) {
|
||||
rz_sys_perror("RZ_NEW0 (dmp_bmp_header)");
|
||||
RZ_LOG_ERROR("Cannot allocate dmp_bmp_header.\n");
|
||||
return false;
|
||||
}
|
||||
if (rz_buf_read_at(obj->b, sizeof(dmp64_header), (ut8 *)obj->bmp_header, rz_offsetof(dmp_bmp_header, Bitmap)) < 0) {
|
||||
eprintf("Warning: read bmp_header\n");
|
||||
RZ_LOG_ERROR("Cannot read bmp_header\n");
|
||||
return false;
|
||||
}
|
||||
if (memcmp(obj->bmp_header, DMP_BMP_MAGIC, 8) &&
|
||||
memcmp(obj->bmp_header, DMP_BMP_FULL_MAGIC, 8)) {
|
||||
eprintf("Warning: Invalid Bitmap Magic\n");
|
||||
RZ_LOG_ERROR("Invalid Bitmap Magic\n");
|
||||
return false;
|
||||
}
|
||||
ut64 bitmapsize = obj->bmp_header->Pages / 8;
|
||||
obj->bitmap = calloc(1, bitmapsize);
|
||||
if (rz_buf_read_at(obj->b, sizeof(dmp64_header) + rz_offsetof(dmp_bmp_header, Bitmap), obj->bitmap, bitmapsize) < 0) {
|
||||
eprintf("Warning: read bitmap\n");
|
||||
RZ_LOG_ERROR("Cannot read bitmap\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -279,7 +279,7 @@ static int rz_bin_dmp64_init_bmp_header(struct rz_bin_dmp64_obj_t *obj) {
|
|||
|
||||
static int rz_bin_dmp64_init(struct rz_bin_dmp64_obj_t *obj) {
|
||||
if (!rz_bin_dmp64_init_header(obj)) {
|
||||
eprintf("Warning: Invalid Kernel Dump x64 Format\n");
|
||||
RZ_LOG_ERROR("Invalid Kernel Dump x64 Format\n");
|
||||
return false;
|
||||
}
|
||||
switch (obj->header->DumpType) {
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ static void free_rz_addr(RzBinAddr *addr) {
|
|||
|
||||
LuacBinInfo *luac_build_info(LuaProto *proto) {
|
||||
if (!proto) {
|
||||
eprintf("Warning : Broken luac file\n");
|
||||
RZ_LOG_ERROR("Invalid luac file\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,129 +38,82 @@ LuaConstEntry *lua_new_const_entry() {
|
|||
LuaProto *lua_new_proto_entry() {
|
||||
LuaProto *proto = RZ_NEW0(LuaProto);
|
||||
if (!proto) {
|
||||
RZ_LOG_ERROR("Cannot allocate LuaProto\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
proto->const_entries = rz_list_new();
|
||||
if (proto->const_entries == NULL) {
|
||||
eprintf("Init Const Entry List Failed\n");
|
||||
RZ_FREE(proto);
|
||||
return NULL;
|
||||
proto->const_entries = rz_list_newf((RzListFree)lua_free_const_entry);
|
||||
if (!proto->const_entries) {
|
||||
RZ_LOG_ERROR("Cannot allocate Const Entry List\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
proto->upvalue_entries = rz_list_new();
|
||||
if (proto->upvalue_entries == NULL) {
|
||||
eprintf("Init Upvalue Entry List Failed\n");
|
||||
rz_list_free(proto->const_entries);
|
||||
RZ_FREE(proto);
|
||||
return NULL;
|
||||
proto->upvalue_entries = rz_list_newf(free);
|
||||
if (!proto->upvalue_entries) {
|
||||
RZ_LOG_ERROR("Cannot allocate Upvalue Entry List\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
proto->proto_entries = rz_list_new();
|
||||
if (proto->proto_entries == NULL) {
|
||||
eprintf("Init Proto Entry List Failed\n");
|
||||
rz_list_free(proto->const_entries);
|
||||
rz_list_free(proto->upvalue_entries);
|
||||
RZ_FREE(proto);
|
||||
return NULL;
|
||||
proto->proto_entries = rz_list_newf((RzListFree)lua_free_proto_entry);
|
||||
if (!proto->proto_entries) {
|
||||
RZ_LOG_ERROR("Cannot allocate Proto Entry List\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
proto->line_info_entries = rz_list_new();
|
||||
if (proto->line_info_entries == NULL) {
|
||||
eprintf("Init Debug Line Info Failed\n");
|
||||
rz_list_free(proto->const_entries);
|
||||
rz_list_free(proto->upvalue_entries);
|
||||
rz_list_free(proto->proto_entries);
|
||||
RZ_FREE(proto);
|
||||
return NULL;
|
||||
proto->line_info_entries = rz_list_newf(free);
|
||||
if (!proto->line_info_entries) {
|
||||
RZ_LOG_ERROR("Cannot allocate Debug Line Info\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
proto->abs_line_info_entries = rz_list_new();
|
||||
if (proto->abs_line_info_entries == NULL) {
|
||||
eprintf("Init Abs Line Info Failed\n");
|
||||
rz_list_free(proto->const_entries);
|
||||
rz_list_free(proto->upvalue_entries);
|
||||
rz_list_free(proto->proto_entries);
|
||||
rz_list_free(proto->line_info_entries);
|
||||
RZ_FREE(proto);
|
||||
return NULL;
|
||||
proto->abs_line_info_entries = rz_list_newf(free);
|
||||
if (!proto->abs_line_info_entries) {
|
||||
RZ_LOG_ERROR("Cannot allocate Abs Line Info\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
proto->local_var_info_entries = rz_list_new();
|
||||
if (proto->local_var_info_entries == NULL) {
|
||||
eprintf("Init Local Var Failed\n");
|
||||
rz_list_free(proto->const_entries);
|
||||
rz_list_free(proto->upvalue_entries);
|
||||
rz_list_free(proto->proto_entries);
|
||||
rz_list_free(proto->line_info_entries);
|
||||
rz_list_free(proto->abs_line_info_entries);
|
||||
RZ_FREE(proto);
|
||||
return NULL;
|
||||
proto->local_var_info_entries = rz_list_newf((RzListFree)lua_free_local_var_entry);
|
||||
if (!proto->local_var_info_entries) {
|
||||
RZ_LOG_ERROR("Cannot allocate Local Var\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
proto->dbg_upvalue_entries = rz_list_new();
|
||||
if (proto->dbg_upvalue_entries == NULL) {
|
||||
eprintf("Init Debug Upvalues Failed\n");
|
||||
rz_list_free(proto->const_entries);
|
||||
rz_list_free(proto->upvalue_entries);
|
||||
rz_list_free(proto->proto_entries);
|
||||
rz_list_free(proto->line_info_entries);
|
||||
rz_list_free(proto->abs_line_info_entries);
|
||||
rz_list_free(proto->dbg_upvalue_entries);
|
||||
RZ_FREE(proto);
|
||||
return NULL;
|
||||
proto->dbg_upvalue_entries = rz_list_newf((RzListFree)lua_free_dbg_upvalue_entry);
|
||||
if (!proto->dbg_upvalue_entries) {
|
||||
RZ_LOG_ERROR("Cannot allocate Debug Upvalues\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* set free functions */
|
||||
proto->const_entries->free = (RzListFree)&lua_free_const_entry;
|
||||
proto->upvalue_entries->free = (RzListFree)&lua_free_upvalue_entry;
|
||||
proto->line_info_entries->free = (RzListFree)&lua_free_lineinfo_entry;
|
||||
proto->abs_line_info_entries->free = (RzListFree)&lua_free_abs_lineinfo_entry;
|
||||
proto->local_var_info_entries->free = (RzListFree)&lua_free_local_var_entry;
|
||||
proto->dbg_upvalue_entries->free = (RzListFree)&lua_free_dbg_upvalue_entry;
|
||||
proto->proto_entries->free = (RzListFree)&lua_free_proto_entry;
|
||||
|
||||
return proto;
|
||||
|
||||
fail:
|
||||
lua_free_proto_entry(proto);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void lua_free_dbg_upvalue_entry(LuaDbgUpvalueEntry *entry) {
|
||||
rz_return_if_fail(entry);
|
||||
if (entry->upvalue_name != NULL) {
|
||||
RZ_FREE(entry->upvalue_name);
|
||||
if (!entry) {
|
||||
return;
|
||||
}
|
||||
free(entry->upvalue_name);
|
||||
// leave entry to rz_list_free
|
||||
RZ_FREE(entry);
|
||||
free(entry);
|
||||
}
|
||||
|
||||
void lua_free_local_var_entry(LuaLocalVarEntry *entry) {
|
||||
rz_return_if_fail(entry);
|
||||
if (entry->varname != NULL) {
|
||||
RZ_FREE(entry->varname);
|
||||
if (!entry) {
|
||||
return;
|
||||
}
|
||||
RZ_FREE(entry);
|
||||
free(entry->varname);
|
||||
free(entry);
|
||||
}
|
||||
|
||||
void lua_free_const_entry(LuaConstEntry *entry) {
|
||||
rz_return_if_fail(entry);
|
||||
if (entry->data != NULL) {
|
||||
RZ_FREE(entry->data);
|
||||
if (!entry) {
|
||||
return;
|
||||
}
|
||||
RZ_FREE(entry);
|
||||
}
|
||||
|
||||
void lua_free_abs_lineinfo_entry(LuaAbsLineinfoEntry *entry) {
|
||||
rz_return_if_fail(entry);
|
||||
RZ_FREE(entry);
|
||||
}
|
||||
|
||||
void lua_free_lineinfo_entry(LuaLineinfoEntry *entry) {
|
||||
rz_return_if_fail(entry);
|
||||
RZ_FREE(entry);
|
||||
}
|
||||
|
||||
void lua_free_upvalue_entry(LuaUpvalueEntry *entry) {
|
||||
rz_return_if_fail(entry);
|
||||
RZ_FREE(entry);
|
||||
free(entry->data);
|
||||
free(entry);
|
||||
}
|
||||
|
||||
void lua_free_proto_entry(LuaProto *proto) {
|
||||
|
|
@ -170,26 +123,19 @@ void lua_free_proto_entry(LuaProto *proto) {
|
|||
|
||||
/* free constants entries */
|
||||
rz_list_free(proto->const_entries);
|
||||
proto->const_entries = NULL;
|
||||
|
||||
/* free upvalue entries */
|
||||
rz_list_free(proto->upvalue_entries);
|
||||
proto->upvalue_entries = NULL;
|
||||
|
||||
/* free debug */
|
||||
rz_list_free(proto->line_info_entries);
|
||||
rz_list_free(proto->abs_line_info_entries);
|
||||
rz_list_free(proto->local_var_info_entries);
|
||||
rz_list_free(proto->dbg_upvalue_entries);
|
||||
proto->line_info_entries = NULL;
|
||||
proto->abs_line_info_entries = NULL;
|
||||
proto->local_var_info_entries = NULL;
|
||||
proto->dbg_upvalue_entries = NULL;
|
||||
|
||||
/* recursively free protos */
|
||||
rz_list_free(proto->proto_entries);
|
||||
proto->proto_entries = NULL;
|
||||
|
||||
RZ_FREE(proto->proto_name);
|
||||
RZ_FREE(proto);
|
||||
free(proto->proto_name);
|
||||
free(proto);
|
||||
}
|
||||
|
|
@ -180,9 +180,6 @@ LuaProto *lua_new_proto_entry();
|
|||
|
||||
void lua_free_dbg_upvalue_entry(LuaDbgUpvalueEntry *);
|
||||
void lua_free_local_var_entry(LuaLocalVarEntry *);
|
||||
void lua_free_abs_lineinfo_entry(LuaAbsLineinfoEntry *);
|
||||
void lua_free_lineinfo_entry(LuaLineinfoEntry *);
|
||||
void lua_free_upvalue_entry(LuaUpvalueEntry *);
|
||||
void lua_free_const_entry(LuaConstEntry *);
|
||||
void lua_free_proto_entry(LuaProto *);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@
|
|||
// SPDX-FileCopyrightText: 2021 Heersin <teablearcher@gmail.com>
|
||||
|
||||
#include "luac_specs_53.h"
|
||||
|
||||
static void lua_load_block(RzBuffer *buffer, void *dest, size_t size, ut64 offset, ut64 data_size) {
|
||||
if (offset + size > data_size) {
|
||||
eprintf("Bad Luac File : Truncated load block at 0x%llx\n", offset);
|
||||
RZ_LOG_ERROR("Truncated load block at 0x%llx\n", offset);
|
||||
return;
|
||||
}
|
||||
rz_buf_read_at(buffer, offset, dest, size);
|
||||
|
|
@ -91,7 +92,7 @@ static ut64 lua_parse_string(RzBuffer *buffer, ut8 **dest, int *str_len, ut64 of
|
|||
*dest = ret;
|
||||
*str_len = len;
|
||||
} else {
|
||||
eprintf("cannot store string\n");
|
||||
RZ_LOG_ERROR("Cannot store string\n");
|
||||
}
|
||||
|
||||
return offset + len - base_offset;
|
||||
|
|
@ -114,7 +115,7 @@ static ut64 lua_parse_code(LuaProto *proto, RzBuffer *buffer, ut64 offset, ut64
|
|||
total_size = code_size * 4 + size_offset;
|
||||
|
||||
if (total_size + offset > data_size) {
|
||||
eprintf("Bad Luac File : Truncated Code at [0x%llx]\n", offset);
|
||||
RZ_LOG_ERROR("Truncated Code at [0x%llx]\n", offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -409,7 +410,6 @@ LuaProto *lua_parse_body_53(RzBuffer *buffer, ut64 base_offset, ut64 data_size)
|
|||
|
||||
LuaProto *ret_proto = lua_new_proto_entry();
|
||||
if (!ret_proto) {
|
||||
eprintf("unable to init proto\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -486,7 +486,7 @@ RzBinInfo *lua_parse_header_53(RzBinFile *bf, st32 major, st32 minor) {
|
|||
|
||||
st64 reat = bf->size;
|
||||
if (reat < LUAC_53_HDRSIZE) {
|
||||
eprintf("Truncated Header\n");
|
||||
RZ_LOG_ERROR("Truncated header\n");
|
||||
return NULL;
|
||||
}
|
||||
buffer = bf->buf;
|
||||
|
|
@ -547,17 +547,16 @@ RzBinInfo *lua_parse_header_53(RzBinFile *bf, st32 major, st32 minor) {
|
|||
(number_size != sizeof(LUA_NUMBER)) ||
|
||||
(int_size != sizeof(LUA_INT)) ||
|
||||
(sizet_size != sizeof(size_t))) {
|
||||
eprintf("Size Definition not matched\n");
|
||||
RZ_LOG_ERROR("Size definition does not match with the expected size\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Check endian */
|
||||
if (integer_valid != LUAC_53_INT_VALIDATION) {
|
||||
eprintf("Integer Format Not Matched\n");
|
||||
RZ_LOG_ERROR("Integer format does not match with the expected integer\n");
|
||||
return ret;
|
||||
}
|
||||
if (number_valid != LUAC_53_NUMBER_VALIDATION) {
|
||||
eprintf("Number Format Not Matched\n");
|
||||
} else if (number_valid != LUAC_53_NUMBER_VALIDATION) {
|
||||
RZ_LOG_ERROR("Number format does not match with the expected number\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
static void lua_load_block(RzBuffer *buffer, void *dest, size_t size, ut64 offset, ut64 data_size) {
|
||||
if (offset + size > data_size) {
|
||||
eprintf("Bad Luac File : Truncated load block at 0x%llx\n", offset);
|
||||
RZ_LOG_ERROR("Truncated load block at 0x%llx\n", offset);
|
||||
return;
|
||||
}
|
||||
rz_buf_read_at(buffer, offset, dest, size);
|
||||
|
|
@ -34,7 +34,7 @@ static ut64 lua_parse_szint(RzBuffer *buffer, int *size, ut64 offset, ut64 data_
|
|||
|
||||
// 1 byte at least
|
||||
if (offset + 1 > data_size) {
|
||||
eprintf("Bad Luac File : Truncated read size at 0x%llx\n", offset);
|
||||
RZ_LOG_ERROR("Truncated integer size at 0x%llx\n", offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ static ut64 lua_parse_szint(RzBuffer *buffer, int *size, ut64 offset, ut64 data_
|
|||
|
||||
i += 1;
|
||||
if (x >= limit) {
|
||||
eprintf("integer overflow\n");
|
||||
RZ_LOG_ERROR("integer overflow while decoding integer size\n");
|
||||
return 0;
|
||||
}
|
||||
x = (x << 7) | (b & 0x7f);
|
||||
|
|
@ -88,7 +88,7 @@ static ut64 lua_parse_string(RzBuffer *buffer, ut8 **dest, int *str_len, ut64 of
|
|||
*dest = ret;
|
||||
*str_len = string_len;
|
||||
} else {
|
||||
eprintf("cannot store string\n");
|
||||
RZ_LOG_ERROR("cannot store string\n");
|
||||
}
|
||||
|
||||
total_offset = size_offset + string_len;
|
||||
|
|
@ -130,7 +130,7 @@ static ut64 lua_parse_code(LuaProto *proto, RzBuffer *buffer, ut64 offset, ut64
|
|||
total_size = code_size * 4 + size_offset;
|
||||
|
||||
if (total_size + offset > data_size) {
|
||||
eprintf("Bad Luac File : Truncated Code at [0x%llx]\n", offset);
|
||||
RZ_LOG_ERROR("Truncated Code at [0x%llx]\n", offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -487,7 +487,7 @@ RzBinInfo *lua_parse_header_54(RzBinFile *bf, st32 major, st32 minor) {
|
|||
|
||||
st64 reat = bf->size;
|
||||
if (reat < LUAC_54_HDRSIZE) {
|
||||
eprintf("Truncated Header\n");
|
||||
RZ_LOG_ERROR("Truncated Header\n");
|
||||
return NULL;
|
||||
}
|
||||
buffer = bf->buf;
|
||||
|
|
@ -541,17 +541,16 @@ RzBinInfo *lua_parse_header_54(RzBinFile *bf, st32 major, st32 minor) {
|
|||
if ((instruction_size != sizeof(LUA_INSTRUCTION)) ||
|
||||
(integer_size != sizeof(LUA_INTEGER)) ||
|
||||
(number_size != sizeof(LUA_NUMBER))) {
|
||||
eprintf("Size Definition not matched\n");
|
||||
RZ_LOG_ERROR("Size definition does not match with the expected size\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Check endian */
|
||||
if (int_valid != LUAC_54_INT_VALIDATION) {
|
||||
eprintf("Integer Format Not Matched\n");
|
||||
RZ_LOG_ERROR("Integer format does not match with the expected integer\n");
|
||||
return ret;
|
||||
}
|
||||
if (number_valid != LUAC_54_NUMBER_VALIDATION) {
|
||||
eprintf("Number Format Not Matched\n");
|
||||
} else if (number_valid != LUAC_54_NUMBER_VALIDATION) {
|
||||
RZ_LOG_ERROR("Number format does not match with the expected number\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -144,11 +144,11 @@ RzCoreSymCacheElement *rz_coresym_cache_element_new(RzBinFile *bf, RzBuffer *buf
|
|||
return NULL;
|
||||
}
|
||||
if (hdr->version != 1) {
|
||||
eprintf("Unsupported CoreSymbolication cache version (%d)\n", hdr->version);
|
||||
RZ_LOG_ERROR("Unsupported CoreSymbolication cache version (%d)\n", hdr->version);
|
||||
goto beach;
|
||||
}
|
||||
if (hdr->size == 0 || hdr->size > rz_buf_size(buf) - off) {
|
||||
eprintf("Corrupted CoreSymbolication header: size out of bounds (0x%x)\n", hdr->size);
|
||||
RZ_LOG_ERROR("Corrupted CoreSymbolication header: size out of bounds (0x%x)\n", hdr->size);
|
||||
goto beach;
|
||||
}
|
||||
result = RZ_NEW0(RzCoreSymCacheElement);
|
||||
|
|
|
|||
|
|
@ -821,7 +821,7 @@ static RzDyldRebaseInfo *get_rebase_info(RzDyldCache *cache, ut64 slideInfoOffse
|
|||
if (slide == UT64_MAX) {
|
||||
rebase_info->slide = estimate_slide(cache, 0x7ffffffffffffULL, 0);
|
||||
if (rebase_info->slide) {
|
||||
eprintf("dyldcache is slid: 0x%" PFMT64x "\n", rebase_info->slide);
|
||||
RZ_LOG_INFO("dyldcache is slid: 0x%" PFMT64x "\n", rebase_info->slide);
|
||||
}
|
||||
} else {
|
||||
rebase_info->slide = slide;
|
||||
|
|
@ -898,7 +898,7 @@ static RzDyldRebaseInfo *get_rebase_info(RzDyldCache *cache, ut64 slideInfoOffse
|
|||
if (slide == UT64_MAX) {
|
||||
rebase_info->slide = estimate_slide(cache, rebase_info->value_mask, rebase_info->value_add);
|
||||
if (rebase_info->slide) {
|
||||
eprintf("dyldcache is slid: 0x%" PFMT64x "\n", rebase_info->slide);
|
||||
RZ_LOG_INFO("dyldcache is slid: 0x%" PFMT64x "\n", rebase_info->slide);
|
||||
}
|
||||
} else {
|
||||
rebase_info->slide = slide;
|
||||
|
|
@ -969,7 +969,7 @@ static RzDyldRebaseInfo *get_rebase_info(RzDyldCache *cache, ut64 slideInfoOffse
|
|||
if (slide == UT64_MAX) {
|
||||
rebase_info->slide = estimate_slide(cache, UT64_MAX, 0);
|
||||
if (rebase_info->slide) {
|
||||
eprintf("dyldcache is slid: 0x%" PFMT64x "\n", rebase_info->slide);
|
||||
RZ_LOG_INFO("dyldcache is slid: 0x%" PFMT64x "\n", rebase_info->slide);
|
||||
}
|
||||
} else {
|
||||
rebase_info->slide = slide;
|
||||
|
|
@ -977,7 +977,7 @@ static RzDyldRebaseInfo *get_rebase_info(RzDyldCache *cache, ut64 slideInfoOffse
|
|||
|
||||
return (RzDyldRebaseInfo *)rebase_info;
|
||||
} else {
|
||||
eprintf("unsupported slide info version %d\n", slide_info_version);
|
||||
RZ_LOG_ERROR("Unsupported slide info version %d\n", slide_info_version);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -1118,7 +1118,7 @@ RZ_API void rz_dyldcache_symbols_from_locsym(RzDyldCache *cache, RzDyldBinImage
|
|||
|
||||
if (bin->nlist_start_index >= locsym->nlists_count ||
|
||||
bin->nlist_start_index + bin->nlist_count > locsym->nlists_count) {
|
||||
eprintf("dyldcache: malformed local symbol entry\n");
|
||||
RZ_LOG_ERROR("dyldcache: malformed local symbol entry\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1260,11 +1260,11 @@ static RzDyldLocSym *rz_dyld_locsym_new(RzDyldCache *cache) {
|
|||
goto beach;
|
||||
}
|
||||
if (rz_buf_fread_at(cache->buf, hdr->localSymbolsOffset, (ut8 *)info, "6i", 1) != info_size) {
|
||||
eprintf("locsym err 01\n");
|
||||
RZ_LOG_ERROR("Cannot read cache_locsym_info_t from header\n");
|
||||
goto beach;
|
||||
}
|
||||
if (info->entriesCount != cache->hdr->imagesCount) {
|
||||
eprintf("locsym err 02\n");
|
||||
RZ_LOG_ERROR("The number of entries count differs from cache header image count\n");
|
||||
goto beach;
|
||||
}
|
||||
|
||||
|
|
@ -1277,7 +1277,7 @@ static RzDyldLocSym *rz_dyld_locsym_new(RzDyldCache *cache) {
|
|||
}
|
||||
if (rz_buf_fread_at(cache->buf, hdr->localSymbolsOffset + info->entriesOffset, (ut8 *)large_entries, "lii",
|
||||
info->entriesCount) != entries_size) {
|
||||
eprintf("locsym err 03\n");
|
||||
RZ_LOG_ERROR("Cannot read cache_locsym_entry_large_t\n");
|
||||
goto beach;
|
||||
}
|
||||
entries = large_entries;
|
||||
|
|
@ -1289,7 +1289,7 @@ static RzDyldLocSym *rz_dyld_locsym_new(RzDyldCache *cache) {
|
|||
}
|
||||
if (rz_buf_fread_at(cache->buf, hdr->localSymbolsOffset + info->entriesOffset, (ut8 *)regular_entries, "iii",
|
||||
info->entriesCount) != entries_size) {
|
||||
eprintf("locsym err 04\n");
|
||||
RZ_LOG_ERROR("Cannot read cache_locsym_entry_t\n");
|
||||
goto beach;
|
||||
}
|
||||
entries = regular_entries;
|
||||
|
|
@ -1316,7 +1316,7 @@ static RzDyldLocSym *rz_dyld_locsym_new(RzDyldCache *cache) {
|
|||
free(info);
|
||||
free(entries);
|
||||
|
||||
eprintf("dyldcache: malformed local symbols metadata\n");
|
||||
RZ_LOG_ERROR("dyldcache: malformed local symbols metadata\n");
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -224,7 +224,7 @@ static st64 buf_read(RzBuffer *b, ut8 *buf, ut64 len) {
|
|||
if (rounded_count > rebase_info->page_size) {
|
||||
internal_buf = malloc(rounded_count);
|
||||
if (!internal_buf) {
|
||||
eprintf("Cannot allocate memory for 'internal_buf'\n");
|
||||
RZ_LOG_ERROR("Cannot allocate memory for 'internal_buf'\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -235,7 +235,7 @@ static st64 buf_read(RzBuffer *b, ut8 *buf, ut64 len) {
|
|||
result = RZ_MIN(len, internal_result);
|
||||
memcpy(buf, internal_buf + page_offset, result);
|
||||
} else {
|
||||
eprintf("ERROR rebasing\n");
|
||||
RZ_LOG_ERROR("Cannot rebase\n");
|
||||
result = rz_buf_read_at(cache->buf, ctx->off, buf, len);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ static int rz_bin_fatmach0_init(struct rz_bin_fatmach0_obj_t *bin) {
|
|||
ut8 hdrbytes[sizeof(struct fat_header)] = { 0 };
|
||||
int len = rz_buf_read_at(bin->b, 0, &hdrbytes[0], sizeof(struct fat_header));
|
||||
if (len != sizeof(struct fat_header)) {
|
||||
perror("read (fat_header)");
|
||||
RZ_LOG_ERROR("Cannot read fat_header\n");
|
||||
return false;
|
||||
}
|
||||
bin->hdr.magic = rz_read_be32(&hdrbytes[0]);
|
||||
|
|
@ -22,7 +22,7 @@ static int rz_bin_fatmach0_init(struct rz_bin_fatmach0_obj_t *bin) {
|
|||
return false;
|
||||
}
|
||||
if (bin->hdr.magic != FAT_MAGIC || !bin->nfat_arch || bin->nfat_arch < 1) {
|
||||
eprintf("Endian FAT_MAGIC failed (?)\n");
|
||||
RZ_LOG_ERROR("Invalid FAT_MAGIC\n");
|
||||
return false;
|
||||
}
|
||||
size = bin->nfat_arch * sizeof(struct fat_arch);
|
||||
|
|
@ -30,14 +30,14 @@ static int rz_bin_fatmach0_init(struct rz_bin_fatmach0_obj_t *bin) {
|
|||
return false;
|
||||
}
|
||||
if (!(bin->archs = malloc(size))) {
|
||||
perror("malloc (fat_arch)");
|
||||
RZ_LOG_ERROR("Cannot allocate fat_arch with size %u bytes\n", size);
|
||||
return false;
|
||||
}
|
||||
for (i = 0; i < bin->nfat_arch; i++) {
|
||||
ut8 archbytes[sizeof(struct fat_arch)] = { 0 };
|
||||
len = rz_buf_read_at(bin->b, 8 + i * sizeof(struct fat_arch), &archbytes[0], sizeof(struct fat_arch));
|
||||
if (len != sizeof(struct fat_arch)) {
|
||||
perror("read (fat_arch)");
|
||||
RZ_LOG_ERROR("Cannot read fat_arch\n");
|
||||
RZ_FREE(bin->archs);
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -414,17 +414,17 @@ static bool rz_bin_mdmp_init_hdr(struct rz_bin_mdmp_obj *obj) {
|
|||
read_hdr(obj->b, obj->hdr);
|
||||
|
||||
if (obj->hdr->number_of_streams == 0) {
|
||||
eprintf("[WARN] No streams present!\n");
|
||||
RZ_LOG_WARN("No streams present!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj->hdr->stream_directory_rva < sizeof(struct minidump_header)) {
|
||||
eprintf("[ERROR] RVA for directory resides in the header!\n");
|
||||
RZ_LOG_ERROR("RVA for directory resides in the header!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj->hdr->check_sum) {
|
||||
eprintf("[INFO] Checksum present but needs validating!\n");
|
||||
RZ_LOG_INFO("Checksum present but needs validating!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -681,7 +681,7 @@ static bool rz_bin_mdmp_init_directory_entry(struct rz_bin_mdmp_obj *obj, struct
|
|||
/* We could confirm data sizes but a malcious MDMP will always get around
|
||||
** this! But we can ensure that the data is not outside of the file */
|
||||
if ((ut64)entry->location.rva + entry->location.data_size > rz_buf_size(obj->b)) {
|
||||
eprintf("[ERROR] Size Mismatch - Stream data is larger than file size!\n");
|
||||
RZ_LOG_ERROR("Size Mismatch - Stream data is larger than file size!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -1142,7 +1142,7 @@ static bool rz_bin_mdmp_init_directory_entry(struct rz_bin_mdmp_obj *obj, struct
|
|||
/* Silently ignore reserved streams */
|
||||
break;
|
||||
default:
|
||||
eprintf("[WARN] Invalid or unsupported enumeration encountered %d\n", entry->stream_type);
|
||||
RZ_LOG_WARN("Invalid or unsupported enumeration encountered %d\n", entry->stream_type);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
|
|
@ -1198,7 +1198,7 @@ static bool rz_bin_mdmp_init_directory(struct rz_bin_mdmp_obj *obj) {
|
|||
ut64 bytes_left = rvadir < obj->size ? obj->size - rvadir : 0;
|
||||
size_t max_entries = RZ_MIN(obj->hdr->number_of_streams, bytes_left / sizeof(struct minidump_directory));
|
||||
if (max_entries < obj->hdr->number_of_streams) {
|
||||
eprintf("[ERROR] Number of streams = %u is greater than is supportable by bin size\n",
|
||||
RZ_LOG_ERROR("Number of streams = %u is greater than is supportable by bin size\n",
|
||||
obj->hdr->number_of_streams);
|
||||
}
|
||||
/* Parse each entry in the directory */
|
||||
|
|
@ -1369,17 +1369,17 @@ static int rz_bin_mdmp_init(struct rz_bin_mdmp_obj *obj) {
|
|||
rz_bin_mdmp_init_parsing(obj);
|
||||
|
||||
if (!rz_bin_mdmp_init_hdr(obj)) {
|
||||
eprintf("[ERROR] Failed to initialise header\n");
|
||||
RZ_LOG_ERROR("Failed to initialise header\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!rz_bin_mdmp_init_directory(obj)) {
|
||||
eprintf("[ERROR] Failed to initialise directory structures!\n");
|
||||
RZ_LOG_ERROR("Failed to initialise directory structures!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!rz_bin_mdmp_init_pe_bins(obj)) {
|
||||
eprintf("[ERROR] Failed to initialise pe binaries!\n");
|
||||
RZ_LOG_ERROR("Failed to initialise pe binaries!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ RzBinAddr *rz_bin_mz_get_entrypoint(const struct rz_bin_mz_obj_t *bin) {
|
|||
la = rz_bin_mz_va_to_la(mz->cs, mz->ip);
|
||||
la &= 0xfffff;
|
||||
if (la >= bin->load_module_size) {
|
||||
eprintf("Error: entry point outside load module\n");
|
||||
RZ_LOG_ERROR("The entry point is outside the load module size\n");
|
||||
return NULL;
|
||||
}
|
||||
entrypoint = RZ_NEW0(RzBinAddr);
|
||||
|
|
@ -154,7 +154,7 @@ RzList *rz_bin_mz_get_segments(const struct rz_bin_mz_obj_t *bin) {
|
|||
return seg_list;
|
||||
|
||||
err_out:
|
||||
eprintf("Error: alloc (RzBinSection)\n");
|
||||
RZ_LOG_ERROR("Failed to get segment list\n");
|
||||
rz_list_free(seg_list);
|
||||
|
||||
return NULL;
|
||||
|
|
@ -167,7 +167,7 @@ struct rz_bin_mz_reloc_t *rz_bin_mz_get_relocs(const struct rz_bin_mz_obj_t *bin
|
|||
|
||||
struct rz_bin_mz_reloc_t *relocs = calloc(num_relocs + 1, sizeof(*relocs));
|
||||
if (!relocs) {
|
||||
eprintf("Error: calloc (struct rz_bin_mz_reloc_t)\n");
|
||||
RZ_LOG_ERROR("Cannot allocate struct rz_bin_mz_reloc_t\n");
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0, j = 0; i < num_relocs; i++) {
|
||||
|
|
@ -202,13 +202,13 @@ static int rz_bin_mz_init_hdr(struct rz_bin_mz_obj_t *bin) {
|
|||
int relocations_size, dos_file_size;
|
||||
MZ_image_dos_header *mz;
|
||||
if (!(mz = RZ_NEW0(MZ_image_dos_header))) {
|
||||
rz_sys_perror("malloc (MZ_image_dos_header)");
|
||||
RZ_LOG_ERROR("Cannot allocate MZ_image_dos_header");
|
||||
return false;
|
||||
}
|
||||
bin->dos_header = mz;
|
||||
// TODO: read field by field to avoid endian and alignment issues
|
||||
if (rz_buf_read_at(bin->b, 0, (ut8 *)mz, sizeof(*mz)) == -1) {
|
||||
eprintf("Error: read (MZ_image_dos_header)\n");
|
||||
RZ_LOG_ERROR("Cannot read MZ_image_dos_header\n");
|
||||
return false;
|
||||
}
|
||||
// dos_header is not endian safe here in this point
|
||||
|
|
@ -246,25 +246,25 @@ static int rz_bin_mz_init_hdr(struct rz_bin_mz_obj_t *bin) {
|
|||
if (bin->dos_extended_header_size > 0) {
|
||||
if (!(bin->dos_extended_header =
|
||||
malloc(bin->dos_extended_header_size))) {
|
||||
rz_sys_perror("malloc (dos extended header)");
|
||||
RZ_LOG_ERROR("Cannot allocate dos extended header");
|
||||
return false;
|
||||
}
|
||||
if (rz_buf_read_at(bin->b, sizeof(MZ_image_dos_header),
|
||||
(ut8 *)bin->dos_extended_header,
|
||||
bin->dos_extended_header_size) == -1) {
|
||||
eprintf("Error: read (dos extended header)\n");
|
||||
RZ_LOG_ERROR("Cannot read dos extended header\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (relocations_size > 0) {
|
||||
if (!(bin->relocation_entries = malloc(relocations_size))) {
|
||||
rz_sys_perror("malloc (dos relocation entries)");
|
||||
RZ_LOG_ERROR("Cannot allocate dos relocation entries");
|
||||
return false;
|
||||
}
|
||||
if (rz_buf_read_at(bin->b, bin->dos_header->reloc_table_offset,
|
||||
(ut8 *)bin->relocation_entries, relocations_size) == -1) {
|
||||
eprintf("Error: read (dos relocation entries)\n");
|
||||
RZ_LOG_ERROR("Cannot read dos relocation entries\n");
|
||||
RZ_FREE(bin->relocation_entries);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -278,7 +278,7 @@ static bool rz_bin_mz_init(struct rz_bin_mz_obj_t *bin) {
|
|||
bin->relocation_entries = NULL;
|
||||
bin->kv = sdb_new0();
|
||||
if (!rz_bin_mz_init_hdr(bin)) {
|
||||
eprintf("Warning: File is not MZ\n");
|
||||
RZ_LOG_WARN("File is not MZ\n");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
@ -333,7 +333,7 @@ RzBinAddr *rz_bin_mz_get_main_vaddr(struct rz_bin_mz_obj_t *bin) {
|
|||
}
|
||||
ZERO_FILL(b);
|
||||
if (rz_buf_read_at(bin->b, entry->paddr, b, sizeof(b)) < 0) {
|
||||
eprintf("Warning: Cannot read entry at 0x%16" PFMT64x "\n", (ut64)entry->paddr);
|
||||
RZ_LOG_ERROR("Cannot read entry at 0x%16" PFMT64x "\n", (ut64)entry->paddr);
|
||||
free(entry);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ static void walkSymbols(RzBuffer *buf, RzBinNXOObj *bin, ut64 symtab, ut64 strta
|
|||
}
|
||||
sym->paddr = pltSym - 8;
|
||||
sym->vaddr = sym->paddr + baddr;
|
||||
eprintf("f sym.imp.%s @ 0x%" PFMT64x "\n", symName, pltSym - 8);
|
||||
RZ_LOG_INFO("f sym.imp.%s @ 0x%" PFMT64x "\n", symName, pltSym - 8);
|
||||
} else {
|
||||
sym->name = symName;
|
||||
if (!sym->name) {
|
||||
|
|
@ -114,7 +114,7 @@ static void walkSymbols(RzBuffer *buf, RzBinNXOObj *bin, ut64 symtab, ut64 strta
|
|||
}
|
||||
sym->paddr = addr;
|
||||
sym->vaddr = sym->paddr + baddr;
|
||||
eprintf("f sym.%s %" PFMT64u " @ 0x%" PFMT64x "\n", symName, size, addr);
|
||||
RZ_LOG_INFO("f sym.%s %" PFMT64u " @ 0x%" PFMT64x "\n", symName, size, addr);
|
||||
}
|
||||
rz_list_append(bin->methods_list, sym);
|
||||
i += 8 - 1;
|
||||
|
|
@ -133,9 +133,9 @@ void parseMod(RzBuffer *buf, RzBinNXOObj *bin, ut32 mod0, ut64 baddr) {
|
|||
return;
|
||||
}
|
||||
|
||||
eprintf("magic %x at 0x%x\n", ptr, mod0);
|
||||
RZ_LOG_INFO("magic %x at 0x%x\n", ptr, mod0);
|
||||
if (ptr == 0x30444f4d) { // MOD0
|
||||
eprintf("is mode0\n");
|
||||
RZ_LOG_INFO("is mode0\n");
|
||||
MODHeader mh = { 0 };
|
||||
if (!rz_buf_read_le32_at(buf, mod0, &mh.magic) ||
|
||||
!rz_buf_read_le32_at(buf, mod0 + 4, &mh.dynamic) ||
|
||||
|
|
@ -147,12 +147,12 @@ void parseMod(RzBuffer *buf, RzBinNXOObj *bin, ut32 mod0, ut64 baddr) {
|
|||
return;
|
||||
}
|
||||
mh.mod_object += mod0;
|
||||
eprintf("magic 0x%x\n", mh.magic);
|
||||
eprintf("dynamic 0x%x\n", mh.dynamic);
|
||||
eprintf("bss 0x%x 0x%x\n", mh.bss_start, mh.bss_end);
|
||||
eprintf("unwind 0x%x 0x%x\n", mh.unwind_start, mh.unwind_end);
|
||||
eprintf("-------------\n");
|
||||
eprintf("mod 0x%x\n", mh.mod_object);
|
||||
RZ_LOG_INFO("magic 0x%x\n", mh.magic);
|
||||
RZ_LOG_INFO("dynamic 0x%x\n", mh.dynamic);
|
||||
RZ_LOG_INFO("bss 0x%x 0x%x\n", mh.bss_start, mh.bss_end);
|
||||
RZ_LOG_INFO("unwind 0x%x 0x%x\n", mh.unwind_start, mh.unwind_end);
|
||||
RZ_LOG_INFO("-------------\n");
|
||||
RZ_LOG_INFO("mod 0x%x\n", mh.mod_object);
|
||||
#define MO_(x) rz_buf_read_le64_at(buf, mh.mod_object + rz_offsetof(MODObject, x), &mo.x)
|
||||
MODObject mo = { 0 };
|
||||
if (!MO_(next) || !MO_(prev) || !MO_(relplt) || !MO_(reldyn) ||
|
||||
|
|
@ -162,15 +162,15 @@ void parseMod(RzBuffer *buf, RzBinNXOObj *bin, ut32 mod0, ut64 baddr) {
|
|||
!MO_(symtab) || !MO_(strtab_size)) {
|
||||
return;
|
||||
};
|
||||
eprintf("next 0x%" PFMT64x "\n", mo.next);
|
||||
eprintf("prev 0x%" PFMT64x "\n", mo.prev);
|
||||
eprintf("base 0x%" PFMT64x "\n", mo.base);
|
||||
eprintf("init 0x%" PFMT64x "\n", mo.init);
|
||||
eprintf("fini 0x%" PFMT64x "\n", mo.fini);
|
||||
eprintf("relplt 0x%" PFMT64x "\n", mo.relplt - mo.base);
|
||||
eprintf("symtab = 0x%" PFMT64x "\n", mo.symtab - mo.base);
|
||||
eprintf("strtab = 0x%" PFMT64x "\n", mo.strtab - mo.base);
|
||||
eprintf("strtabsz = 0x%" PFMT64x "\n", mo.strtab_size);
|
||||
RZ_LOG_INFO("next 0x%" PFMT64x "\n", mo.next);
|
||||
RZ_LOG_INFO("prev 0x%" PFMT64x "\n", mo.prev);
|
||||
RZ_LOG_INFO("base 0x%" PFMT64x "\n", mo.base);
|
||||
RZ_LOG_INFO("init 0x%" PFMT64x "\n", mo.init);
|
||||
RZ_LOG_INFO("fini 0x%" PFMT64x "\n", mo.fini);
|
||||
RZ_LOG_INFO("relplt 0x%" PFMT64x "\n", mo.relplt - mo.base);
|
||||
RZ_LOG_INFO("symtab = 0x%" PFMT64x "\n", mo.symtab - mo.base);
|
||||
RZ_LOG_INFO("strtab = 0x%" PFMT64x "\n", mo.strtab - mo.base);
|
||||
RZ_LOG_INFO("strtabsz = 0x%" PFMT64x "\n", mo.strtab_size);
|
||||
// ut32 modo = mh.mod_object;
|
||||
ut64 strtab = mo.strtab - mo.base;
|
||||
ut64 symtab = mo.symtab - mo.base;
|
||||
|
|
|
|||
|
|
@ -147,8 +147,6 @@ static mach0_ut va2pa(mach0_ut p, ut32 *offset, ut32 *left, RzBinFile *bf) {
|
|||
if (!sctns) {
|
||||
sctns = rz_bin_plugin_mach.sections(bf);
|
||||
if (!sctns) {
|
||||
// retain just for debug
|
||||
// eprintf ("there is no sections\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -206,7 +204,7 @@ static void get_ivar_list_t(mach0_ut p, RzBinFile *bf, RzBuffer *buf, RzBinClass
|
|||
ut8 offs[sizeof(mach0_ut)] = { 0 };
|
||||
|
||||
if (!bf || !bf->o || !bf->o->bin_obj || !bf->o->info) {
|
||||
eprintf("uncorrect RzBinFile pointer\n");
|
||||
RZ_LOG_ERROR("Invalid RzBinFile pointer\n");
|
||||
return;
|
||||
}
|
||||
bigendian = bf->o->info->big_endian;
|
||||
|
|
@ -288,7 +286,7 @@ static void get_ivar_list_t(mach0_ut p, RzBinFile *bf, RzBuffer *buf, RzBinClass
|
|||
if (offset_at != 0 && left >= sizeof(mach0_ut)) {
|
||||
len = rz_buf_read_at(buf, offset_at, offs, sizeof(mach0_ut));
|
||||
if (len != sizeof(mach0_ut)) {
|
||||
eprintf("Error reading\n");
|
||||
RZ_LOG_ERROR("Cannot read mach0_ut\n");
|
||||
goto error;
|
||||
}
|
||||
ivar_offset = rz_read_ble(offs, bigendian, 8 * sizeof(mach0_ut));
|
||||
|
|
@ -312,7 +310,7 @@ static void get_ivar_list_t(mach0_ut p, RzBinFile *bf, RzBuffer *buf, RzBinClass
|
|||
name = malloc(name_len + 1);
|
||||
len = rz_buf_read_at(buf, r, (ut8 *)name, name_len);
|
||||
if (len < 1) {
|
||||
eprintf("Error reading\n");
|
||||
RZ_LOG_ERROR("Cannot read class name from buffer\n");
|
||||
RZ_FREE(name);
|
||||
goto error;
|
||||
}
|
||||
|
|
@ -387,7 +385,7 @@ static void get_objc_property_list(mach0_ut p, RzBinFile *bf, RzBuffer *buf, RzB
|
|||
ut8 sop[sizeof(struct MACH0_(SObjcProperty))] = { 0 };
|
||||
|
||||
if (!bf || !bf->o || !bf->o->bin_obj || !bf->o->info) {
|
||||
eprintf("uncorrect RzBinFile pointer\n");
|
||||
RZ_LOG_ERROR("Invalid RzBinFile pointer\n");
|
||||
return;
|
||||
}
|
||||
bigendian = bf->o->info->big_endian;
|
||||
|
|
@ -428,8 +426,6 @@ static void get_objc_property_list(mach0_ut p, RzBinFile *bf, RzBuffer *buf, RzB
|
|||
}
|
||||
|
||||
if (!(property = RZ_NEW0(RzBinField))) {
|
||||
// retain just for debug
|
||||
// eprintf("RzBinClass allocation error\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -530,7 +526,7 @@ static void get_method_list_t(mach0_ut p, RzBinFile *bf, RzBuffer *buf, char *cl
|
|||
|
||||
RzBinSymbol *method = NULL;
|
||||
if (!bf || !bf->o || !bf->o->bin_obj || !bf->o->info) {
|
||||
eprintf("incorrect RzBinFile pointer\n");
|
||||
RZ_LOG_ERROR("Invalid RzBinFile pointer\n");
|
||||
return;
|
||||
}
|
||||
bigendian = bf->o->info->big_endian;
|
||||
|
|
@ -583,8 +579,6 @@ static void get_method_list_t(mach0_ut p, RzBinFile *bf, RzBuffer *buf, char *cl
|
|||
}
|
||||
|
||||
if (!(method = RZ_NEW0(RzBinSymbol))) {
|
||||
// retain just for debug
|
||||
// eprintf ("RzBinClass allocation error\n");
|
||||
return;
|
||||
}
|
||||
struct MACH0_(SMethod) m;
|
||||
|
|
@ -705,7 +699,6 @@ static void get_method_list_t(mach0_ut p, RzBinFile *bf, RzBuffer *buf, char *cl
|
|||
if (method->vaddr & 1) {
|
||||
method->vaddr >>= 1;
|
||||
method->vaddr <<= 1;
|
||||
// eprintf ("0x%08llx METHOD %s\n", method->vaddr, method->name);
|
||||
}
|
||||
}
|
||||
rz_list_append(klass->methods, method);
|
||||
|
|
@ -734,7 +727,7 @@ static void get_protocol_list_t(mach0_ut p, RzBinFile *bf, RzBuffer *buf, RzBinC
|
|||
ut8 sptr[sizeof(mach0_ut)] = { 0 };
|
||||
|
||||
if (!bf || !bf->o || !bf->o->bin_obj || !bf->o->info) {
|
||||
eprintf("get_protocol_list_t: Invalid RzBinFile pointer\n");
|
||||
RZ_LOG_ERROR("Invalid RzBinFile pointer\n");
|
||||
return;
|
||||
}
|
||||
bigendian = bf->o->info->big_endian;
|
||||
|
|
@ -925,7 +918,7 @@ static char *get_class_name(mach0_ut p, RzBinFile *bf, RzBuffer *buf) {
|
|||
const ut32 ptr_size = sizeof(mach0_ut);
|
||||
|
||||
if (!bf || !bf->o || !bf->o->bin_obj || !bf->o->info) {
|
||||
eprintf("Invalid RzBinFile pointer\n");
|
||||
RZ_LOG_ERROR("Invalid RzBinFile pointer\n");
|
||||
return NULL;
|
||||
}
|
||||
if (!p) {
|
||||
|
|
@ -1020,13 +1013,12 @@ static void get_class_ro_t(mach0_ut p, RzBinFile *bf, RzBuffer *buf, ut32 *is_me
|
|||
ut8 scro[sizeof(struct MACH0_(SClassRoT))] = { 0 };
|
||||
|
||||
if (!bf || !bf->o || !bf->o->bin_obj || !bf->o->info) {
|
||||
eprintf("Invalid RzBinFile pointer\n");
|
||||
RZ_LOG_ERROR("Invalid RzBinFile pointer\n");
|
||||
return;
|
||||
}
|
||||
bigendian = bf->o->info->big_endian;
|
||||
bin = (struct MACH0_(obj_t) *)bf->o->bin_obj;
|
||||
if (!(r = va2pa(p, &offset, &left, bf))) {
|
||||
// eprintf ("No pointer\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1042,7 +1034,7 @@ static void get_class_ro_t(mach0_ut p, RzBinFile *bf, RzBuffer *buf, ut32 *is_me
|
|||
|
||||
// TODO: use rz_buf_fread to avoid endianness issues
|
||||
if (left < sizeof(cro)) {
|
||||
eprintf("Not enough data for SClassRoT\n");
|
||||
RZ_LOG_ERROR("Not enough data for SClassRoT\n");
|
||||
return;
|
||||
}
|
||||
len = rz_buf_read_at(buf, r, scro, sizeof(cro));
|
||||
|
|
@ -1098,7 +1090,6 @@ static void get_class_ro_t(mach0_ut p, RzBinFile *bf, RzBuffer *buf, ut32 *is_me
|
|||
free(name);
|
||||
}
|
||||
}
|
||||
// eprintf ("0x%x %s\n", s, klass->name);
|
||||
sdb_num_set(bin->kv, sdb_fmt("objc_class_%s.offset", klass->name), s, 0);
|
||||
}
|
||||
#ifdef RZ_BIN_MACH064
|
||||
|
|
@ -1161,7 +1152,7 @@ void MACH0_(get_class_t)(mach0_ut p, RzBinFile *bf, RzBuffer *buf, RzBinClass *k
|
|||
return;
|
||||
}
|
||||
if (left < size) {
|
||||
eprintf("Cannot parse obj class info out of bounds\n");
|
||||
RZ_LOG_ERROR("Cannot parse obj class info (out of bounds)\n");
|
||||
return;
|
||||
}
|
||||
len = rz_buf_read_at(buf, r, sc, size);
|
||||
|
|
@ -1201,7 +1192,7 @@ void MACH0_(get_class_t)(mach0_ut p, RzBinFile *bf, RzBuffer *buf, RzBinClass *k
|
|||
|
||||
#if SWIFT_SUPPORT
|
||||
if (q(c.data + n_value) & 7) {
|
||||
eprintf("This is a Swift class");
|
||||
RZ_LOG_INFO("This is a Swift class");
|
||||
}
|
||||
#endif
|
||||
if (!is_meta_class && !dupe) {
|
||||
|
|
@ -1309,36 +1300,36 @@ RzList *MACH0_(parse_classes)(RzBinFile *bf, objc_cache_opt_info *oi) {
|
|||
|
||||
if (!is_found) {
|
||||
// retain just for debug
|
||||
// eprintf ("there is no section __objc_classlist\n");
|
||||
// RZ_LOG_ERROR("there is no section __objc_classlist\n");
|
||||
goto get_classes_error;
|
||||
}
|
||||
// end of seaching of section with name __objc_classlist
|
||||
|
||||
if (!ret && !(ret = rz_list_newf((RzListFree)rz_bin_class_free))) {
|
||||
// retain just for debug
|
||||
// eprintf ("RzList<RzBinClass> allocation error\n");
|
||||
// RZ_LOG_ERROR("RzList<RzBinClass> allocation error\n");
|
||||
goto get_classes_error;
|
||||
}
|
||||
// start of getting information about each class in file
|
||||
for (i = 0; i < s_size; i += sizeof(mach0_ut)) {
|
||||
left = s_size - i;
|
||||
if (left < sizeof(mach0_ut)) {
|
||||
eprintf("Chopped classlist data\n");
|
||||
RZ_LOG_ERROR("Truncated classlist data\n");
|
||||
break;
|
||||
}
|
||||
if (!(klass = RZ_NEW0(RzBinClass))) {
|
||||
// retain just for debug
|
||||
// eprintf ("RzBinClass allocation error\n");
|
||||
// RZ_LOG_ERROR("RzBinClass allocation error\n");
|
||||
goto get_classes_error;
|
||||
}
|
||||
if (!(klass->methods = rz_list_new())) {
|
||||
// retain just for debug
|
||||
// eprintf ("RzList<RzBinField> allocation error\n");
|
||||
// RZ_LOG_ERROR("RzList<RzBinField> allocation error\n");
|
||||
goto get_classes_error;
|
||||
}
|
||||
if (!(klass->fields = rz_list_new())) {
|
||||
// retain just for debug
|
||||
// eprintf ("RzList<RzBinSymbol> allocation error\n");
|
||||
// RZ_LOG_ERROR("RzList<RzBinSymbol> allocation error\n");
|
||||
goto get_classes_error;
|
||||
}
|
||||
size = sizeof(mach0_ut);
|
||||
|
|
@ -1418,7 +1409,7 @@ static RzList *MACH0_(parse_categories)(RzBinFile *bf, RzBuffer *buf, RzSkipList
|
|||
mach0_ut p;
|
||||
|
||||
if ((s_size - i) < ptr_size) {
|
||||
eprintf("Chopped catlist data\n");
|
||||
RZ_LOG_ERROR("Truncated catlist data\n");
|
||||
break;
|
||||
}
|
||||
if (!(klass = RZ_NEW0(RzBinClass))) {
|
||||
|
|
@ -1476,7 +1467,7 @@ void MACH0_(get_category_t)(mach0_ut p, RzBinFile *bf, RzBuffer *buf, RzBinClass
|
|||
return;
|
||||
}
|
||||
if (left < size) {
|
||||
eprintf("Cannot parse obj category info out of bounds\n");
|
||||
RZ_LOG_ERROR("Cannot parse obj category info out of bounds\n");
|
||||
return;
|
||||
}
|
||||
len = rz_buf_read_at(buf, r, sc, size);
|
||||
|
|
@ -1616,7 +1607,7 @@ static char *read_str(RzBinFile *bf, RzBuffer *buf, mach0_ut p, ut32 *offset, ut
|
|||
char *name = calloc(1, name_len + 1);
|
||||
int len = rz_buf_read_at(buf, paddr, (ut8 *)name, name_len);
|
||||
if (len < name_len) {
|
||||
eprintf("Error reading\n");
|
||||
RZ_LOG_ERROR("Cannot read string\n");
|
||||
RZ_FREE(name);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ static bool is_valid_omf_type(ut8 type) {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
// eprintf ("Invalid record type\n");
|
||||
// RZ_LOG_ERROR("Invalid record type\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -32,12 +32,12 @@ bool rz_bin_checksum_omf_ok(const ut8 *buf, ut64 buf_size) {
|
|||
ut8 checksum = 0;
|
||||
|
||||
if (buf_size < 3) {
|
||||
eprintf("Invalid record (too short)\n");
|
||||
RZ_LOG_ERROR("Invalid record (too short)\n");
|
||||
return false;
|
||||
}
|
||||
size = rz_read_le16(buf + 1);
|
||||
if (buf_size < size + 3) {
|
||||
eprintf("Invalid record (too short)\n");
|
||||
RZ_LOG_ERROR("Invalid record (too short)\n");
|
||||
return false;
|
||||
}
|
||||
// Some compiler set checksum to 0
|
||||
|
|
@ -47,13 +47,13 @@ bool rz_bin_checksum_omf_ok(const ut8 *buf, ut64 buf_size) {
|
|||
size += 3;
|
||||
for (; size; size--) {
|
||||
if (buf_size < size) {
|
||||
eprintf("Invalid record (too short)\n");
|
||||
RZ_LOG_ERROR("Invalid record (too short)\n");
|
||||
return false;
|
||||
}
|
||||
checksum += buf[size - 1];
|
||||
}
|
||||
if (checksum) {
|
||||
// eprintf ("Invalid record checksum\n");
|
||||
// RZ_LOG_ERROR("Invalid record checksum\n");
|
||||
}
|
||||
return !checksum ? true : false;
|
||||
}
|
||||
|
|
@ -110,7 +110,7 @@ static bool load_omf_lnames(OMF_record *record, const ut8 *buf, ut64 buf_size) {
|
|||
tmp_size = 0;
|
||||
while ((int)tmp_size < (int)(record->size - 1)) {
|
||||
if (ct_name >= ret->nb_elem) {
|
||||
eprintf("load_omf_lnames: prevent overflow\n");
|
||||
RZ_LOG_ERROR("Invalid number of element (overflow)\n");
|
||||
break;
|
||||
}
|
||||
// sometimes there is a name with a null size so we just skip it
|
||||
|
|
@ -121,7 +121,7 @@ static bool load_omf_lnames(OMF_record *record, const ut8 *buf, ut64 buf_size) {
|
|||
continue;
|
||||
}
|
||||
if (record->size + 3 < tmp_size + cb) {
|
||||
eprintf("Invalid Lnames record (bad size)\n");
|
||||
RZ_LOG_ERROR("Invalid Lnames record (bad size)\n");
|
||||
free(ret);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -148,14 +148,14 @@ static int load_omf_segdef(OMF_record *record, const ut8 *buf, ut64 buf_size) {
|
|||
record->content = ret;
|
||||
|
||||
if (record->size < 2) {
|
||||
eprintf("Invalid Segdef record (bad size)\n");
|
||||
RZ_LOG_ERROR("Invalid Segdef record (bad size)\n");
|
||||
return false;
|
||||
}
|
||||
off_add = buf[3] & 0xe ? 0 : 3;
|
||||
|
||||
if (record->type == OMF_SEGDEF32) {
|
||||
if (record->size < 5 + off_add) {
|
||||
eprintf("Invalid Segdef record (bad size)\n");
|
||||
RZ_LOG_ERROR("Invalid Segdef record (bad size)\n");
|
||||
return false;
|
||||
}
|
||||
ret->name_idx = omf_get_idx(buf + 8 + off_add, buf_size - 8 - off_add);
|
||||
|
|
@ -166,7 +166,7 @@ static int load_omf_segdef(OMF_record *record, const ut8 *buf, ut64 buf_size) {
|
|||
}
|
||||
} else {
|
||||
if (record->size < 3 + off_add) {
|
||||
eprintf("Invalid Segdef record (bad size)\n");
|
||||
RZ_LOG_ERROR("Invalid Segdef record (bad size)\n");
|
||||
return false;
|
||||
}
|
||||
ret->name_idx = omf_get_idx(buf + 6 + off_add, buf_size - 6 - off_add);
|
||||
|
|
@ -210,20 +210,20 @@ static int load_omf_symb(OMF_record *record, ut32 ct, const ut8 *buf, int buf_si
|
|||
symbol = ((OMF_symbol *)((OMF_multi_datas *)record->content)->elems) + nb_symb;
|
||||
|
||||
if (record->size - 1 < ct - 2) {
|
||||
eprintf("Invalid Pubdef record (bad size)\n");
|
||||
RZ_LOG_ERROR("Invalid Pubdef record (bad size)\n");
|
||||
return false;
|
||||
}
|
||||
str_size = buf[ct];
|
||||
|
||||
if (bits == 32) {
|
||||
if (ct + 1 + str_size + 4 - 3 > record->size) {
|
||||
eprintf("Invalid Pubdef record (bad size)\n");
|
||||
RZ_LOG_ERROR("Invalid Pubdef record (bad size)\n");
|
||||
return false;
|
||||
}
|
||||
symbol->offset = rz_read_le32(buf + ct + 1 + str_size);
|
||||
} else {
|
||||
if (ct + 1 + str_size + 2 - 3 > record->size) {
|
||||
eprintf("Invalid Pubdef record (bad size)\n");
|
||||
RZ_LOG_ERROR("Invalid Pubdef record (bad size)\n");
|
||||
return false;
|
||||
}
|
||||
symbol->offset = rz_read_le16(buf + ct + 1 + str_size);
|
||||
|
|
@ -258,7 +258,7 @@ static int load_omf_pubdef(OMF_record *record, const ut8 *buf, int buf_size) {
|
|||
ut16 base_grp;
|
||||
|
||||
if (record->size < 2) {
|
||||
eprintf("Invalid Pubdef record (bad size)\n");
|
||||
RZ_LOG_ERROR("Invalid Pubdef record (bad size)\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -271,7 +271,7 @@ static int load_omf_pubdef(OMF_record *record, const ut8 *buf, int buf_size) {
|
|||
}
|
||||
|
||||
if (record->size < ct - 2) {
|
||||
eprintf("Invalid Pubdef record (bad size)\n");
|
||||
RZ_LOG_ERROR("Invalid Pubdef record (bad size)\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -287,7 +287,7 @@ static int load_omf_pubdef(OMF_record *record, const ut8 *buf, int buf_size) {
|
|||
ct += 2;
|
||||
}
|
||||
if (record->size < ct - 2) {
|
||||
eprintf("Invalid Pubdef record (bad size)\n");
|
||||
RZ_LOG_ERROR("Invalid Pubdef record (bad size)\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -330,13 +330,13 @@ static int load_omf_data(const ut8 *buf, int buf_size, OMF_record *record, ut64
|
|||
OMF_data *ret;
|
||||
|
||||
if ((!(record->type & 1) && record->size < 4) || (record->size < 6)) {
|
||||
eprintf("Invalid Ledata record (bad size)\n");
|
||||
RZ_LOG_ERROR("Invalid Ledata record (bad size)\n");
|
||||
return false;
|
||||
}
|
||||
seg_idx = omf_get_idx(buf + 3, buf_size - 3);
|
||||
if (seg_idx & 0xff00) {
|
||||
if ((!(record->type & 1) && record->size < 5) || (record->size < 7)) {
|
||||
eprintf("Invalid Ledata record (bad size)\n");
|
||||
RZ_LOG_ERROR("Invalid Ledata record (bad size)\n");
|
||||
return false;
|
||||
}
|
||||
ct++;
|
||||
|
|
@ -378,7 +378,7 @@ static int load_omf_content(OMF_record *record, const ut8 *buf, ut64 global_ct,
|
|||
}
|
||||
// generic loader just copy data from buf to content
|
||||
if (!record->size) {
|
||||
eprintf("Invalid record (size to short)\n");
|
||||
RZ_LOG_ERROR("Invalid record (size to short)\n");
|
||||
return false;
|
||||
}
|
||||
if (!(record->content = RZ_NEWS0(char, record->size))) {
|
||||
|
|
@ -400,7 +400,7 @@ static OMF_record_handler *load_record_omf(const ut8 *buf, ut64 global_ct, ut64
|
|||
|
||||
// at least a record have a type a size and a checksum
|
||||
if (((OMF_record *)new)->size > buf_size - 3 || buf_size < 4) {
|
||||
eprintf("Invalid record (too short)\n");
|
||||
RZ_LOG_ERROR("Invalid record (too short)\n");
|
||||
RZ_FREE(new);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -544,7 +544,7 @@ static int get_omf_data_info(rz_bin_omf_obj *obj) {
|
|||
|
||||
while ((tmp = get_next_omf_record_type(tmp, OMF_LEDATA))) {
|
||||
if (((OMF_data *)((OMF_record *)tmp)->content)->seg_idx - 1 >= obj->nb_section) {
|
||||
eprintf("Invalid Ledata record (bad segment index)\n");
|
||||
RZ_LOG_ERROR("Invalid Ledata record (bad segment index)\n");
|
||||
return false;
|
||||
}
|
||||
OMF_segment *os = obj->sections[((OMF_data *)((OMF_record *)tmp)->content)->seg_idx - 1];
|
||||
|
|
@ -709,7 +709,7 @@ bool rz_bin_omf_get_entry(rz_bin_omf_obj *obj, RzBinAddr *addr) {
|
|||
while (ct_sym < obj->nb_symbol) {
|
||||
if (!strcmp(obj->symbols[ct_sym]->name, "_start")) {
|
||||
if (obj->symbols[ct_sym]->seg_idx - 1 > obj->nb_section) {
|
||||
eprintf("Invalid segment index for symbol _start\n");
|
||||
RZ_LOG_ERROR("Invalid segment index for symbol _start\n");
|
||||
return false;
|
||||
}
|
||||
addr->vaddr = obj->sections[obj->symbols[ct_sym]->seg_idx - 1]->vaddr + obj->symbols[ct_sym]->offset + OMF_BASE_ADDR;
|
||||
|
|
@ -799,7 +799,7 @@ ut64 rz_bin_omf_get_vaddr_sym(rz_bin_omf_obj *obj, OMF_symbol *sym) {
|
|||
return 0LL;
|
||||
}
|
||||
if (sym->seg_idx >= obj->nb_section) {
|
||||
eprintf("Invalid segment index for symbol %s\n", sym->name);
|
||||
RZ_LOG_ERROR("Invalid segment index for symbol %s\n", sym->name);
|
||||
return 0;
|
||||
}
|
||||
if (sym->seg_idx == 0) {
|
||||
|
|
|
|||
|
|
@ -13,10 +13,7 @@
|
|||
#include <time.h>
|
||||
#include <ht_uu.h>
|
||||
|
||||
#define MAX_METADATA_STRING_LENGTH 256
|
||||
#define bprintf \
|
||||
if (bin->verbose) \
|
||||
eprintf
|
||||
#define MAX_METADATA_STRING_LENGTH 256
|
||||
#define COFF_SYMBOL_SIZE 18
|
||||
#define PE_READ_STRUCT_FIELD(var, struct_type, field, size) var->field = rz_read_le##size(buf + offsetof(struct_type, field))
|
||||
|
||||
|
|
@ -88,7 +85,7 @@ struct rz_bin_pe_addr_t *PE_(check_msvcseh)(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
struct rz_bin_pe_addr_t *entry = PE_(rz_bin_pe_get_entrypoint)(bin);
|
||||
ZERO_FILL(b);
|
||||
if (rz_buf_read_at(bin->b, entry->paddr, b, sizeof(b)) < 0) {
|
||||
bprintf("Warning: Cannot read entry at 0x%08" PFMT64x "\n", entry->paddr);
|
||||
RZ_LOG_INFO("Cannot read entry at 0x%08" PFMT64x "\n", entry->paddr);
|
||||
free(entry);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -291,7 +288,7 @@ struct rz_bin_pe_addr_t *PE_(check_mingw)(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
entry = PE_(rz_bin_pe_get_entrypoint)(bin);
|
||||
ZERO_FILL(b);
|
||||
if (rz_buf_read_at(bin->b, entry->paddr, b, sizeof(b)) < 0) {
|
||||
bprintf("Warning: Cannot read entry at 0x%08" PFMT64x "\n", entry->paddr);
|
||||
RZ_LOG_INFO("Cannot read entry at 0x%08" PFMT64x "\n", entry->paddr);
|
||||
free(entry);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -347,7 +344,7 @@ struct rz_bin_pe_addr_t *PE_(check_unknow)(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
entry = PE_(rz_bin_pe_get_entrypoint)(bin);
|
||||
// option2: /x 8bff558bec83ec20
|
||||
if (rz_buf_read_at(bin->b, entry->paddr, b, 512) < 1) {
|
||||
bprintf("Warning: Cannot read entry at 0x%08" PFMT64x "\n", entry->paddr);
|
||||
RZ_LOG_INFO("Cannot read entry at 0x%08" PFMT64x "\n", entry->paddr);
|
||||
free(entry);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -470,7 +467,7 @@ static int bin_pe_parse_imports(struct PE_(rz_bin_pe_obj_t) * bin,
|
|||
break;
|
||||
}
|
||||
if (!RZ_BUF_READ_PE_DWORD_AT(bin->b, off + i * sizeof(PE_DWord), &import_table)) {
|
||||
bprintf("Warning: read (import table)\n");
|
||||
RZ_LOG_INFO("read (import table)\n");
|
||||
goto error;
|
||||
} else if (import_table) {
|
||||
if (import_table & ILT_MASK1) {
|
||||
|
|
@ -516,24 +513,24 @@ static int bin_pe_parse_imports(struct PE_(rz_bin_pe_obj_t) * bin,
|
|||
RZ_FREE(symname);
|
||||
}
|
||||
} else {
|
||||
bprintf("Cannot find %s\n", filename);
|
||||
RZ_LOG_INFO("Cannot find %s\n", filename);
|
||||
}
|
||||
RZ_FREE(filename);
|
||||
} else {
|
||||
import_ordinal++;
|
||||
const ut64 off = bin_pe_rva_to_paddr(bin, import_table);
|
||||
if (off > bin->size || (off + sizeof(PE_Word)) > bin->size) {
|
||||
bprintf("Warning: off > bin->size\n");
|
||||
RZ_LOG_INFO("off > bin->size\n");
|
||||
goto error;
|
||||
}
|
||||
if (!rz_buf_read_le16_at(bin->b, off, &import_hint)) {
|
||||
bprintf("Warning: read import hint at 0x%08" PFMT64x "\n", off);
|
||||
RZ_LOG_INFO("read import hint at 0x%08" PFMT64x "\n", off);
|
||||
goto error;
|
||||
}
|
||||
name[0] = '\0';
|
||||
len = rz_buf_read_at(bin->b, off + sizeof(PE_Word), (ut8 *)name, PE_NAME_LENGTH);
|
||||
if (len < 1) {
|
||||
bprintf("Warning: read (import name)\n");
|
||||
RZ_LOG_INFO("read (import name)\n");
|
||||
goto error;
|
||||
} else if (!*name) {
|
||||
break;
|
||||
|
|
@ -541,7 +538,7 @@ static int bin_pe_parse_imports(struct PE_(rz_bin_pe_obj_t) * bin,
|
|||
name[PE_NAME_LENGTH] = '\0';
|
||||
int len = snprintf(import_name, sizeof(import_name), "%s", name);
|
||||
if (len >= sizeof(import_name)) {
|
||||
eprintf("Import name '%s' has been truncated.\n", import_name);
|
||||
RZ_LOG_WARN("Import name '%s' has been truncated.\n", import_name);
|
||||
}
|
||||
}
|
||||
struct rz_bin_pe_import_t *new_importp = realloc(*importp, (*nimp + 1) * sizeof(struct rz_bin_pe_import_t));
|
||||
|
|
@ -704,7 +701,7 @@ static int bin_pe_init_hdr(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
return false;
|
||||
}
|
||||
if (!PE_(read_dos_header)(bin->b, bin->dos_header)) {
|
||||
bprintf("Warning: read (dos header)\n");
|
||||
RZ_LOG_INFO("read (dos header)\n");
|
||||
return false;
|
||||
}
|
||||
sdb_num_set(bin->kv, "pe_dos_header.offset", 0, 0);
|
||||
|
|
@ -714,7 +711,7 @@ static int bin_pe_init_hdr(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
" e_oeminfo e_res2 e_lfanew",
|
||||
0);
|
||||
if (bin->dos_header->e_lfanew > (unsigned int)bin->size) {
|
||||
bprintf("Invalid e_lfanew field\n");
|
||||
RZ_LOG_INFO("Invalid e_lfanew field\n");
|
||||
return false;
|
||||
}
|
||||
if (!(bin->nt_headers = malloc(sizeof(PE_(image_nt_headers))))) {
|
||||
|
|
@ -723,7 +720,7 @@ static int bin_pe_init_hdr(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
}
|
||||
bin->nt_header_offset = bin->dos_header->e_lfanew;
|
||||
if (!PE_(read_nt_headers)(bin->b, bin->dos_header->e_lfanew, bin->nt_headers)) {
|
||||
bprintf("Warning: read (nt header)\n");
|
||||
RZ_LOG_INFO("read (nt header)\n");
|
||||
return false;
|
||||
}
|
||||
sdb_set(bin->kv, "pe_magic.cparse", "enum pe_magic { IMAGE_NT_OPTIONAL_HDR32_MAGIC=0x10b, IMAGE_NT_OPTIONAL_HDR64_MAGIC=0x20b, IMAGE_ROM_OPTIONAL_HDR_MAGIC=0x107 };", 0);
|
||||
|
|
@ -870,7 +867,7 @@ static struct rz_bin_pe_export_t *parse_symbol_table(struct PE_(rz_bin_pe_obj_t)
|
|||
break;
|
||||
}
|
||||
memcpy(&sr, buf + i, sizeof(sr));
|
||||
// bprintf ("SECNUM %d\n", sr.secnum);
|
||||
// RZ_LOG_INFO("SECNUM %d\n", sr.secnum);
|
||||
if (sr.secnum == textn) {
|
||||
if (sr.symtype == 32) {
|
||||
char shortname[9];
|
||||
|
|
@ -948,7 +945,7 @@ static int bin_pe_init_sections(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
sections_size = bin->size;
|
||||
bin->num_sections = bin->size / sizeof(PE_(image_section_header));
|
||||
// massage this to make corkami happy
|
||||
// bprintf ("Invalid NumberOfSections value\n");
|
||||
// RZ_LOG_INFO("Invalid NumberOfSections value\n");
|
||||
// goto out_error;
|
||||
}
|
||||
if (!(bin->section_header = malloc(sections_size))) {
|
||||
|
|
@ -961,7 +958,7 @@ static int bin_pe_init_sections(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
for (i = 0; i < bin->num_sections; i++) {
|
||||
if (!PE_(read_image_section_header)(bin->b, bin->section_header_offset + i * sizeof(PE_(image_section_header)),
|
||||
bin->section_header + i)) {
|
||||
bprintf("Warning: read (sections)\n");
|
||||
RZ_LOG_INFO("read (sections)\n");
|
||||
RZ_FREE(bin->section_header);
|
||||
goto out_error;
|
||||
}
|
||||
|
|
@ -1277,7 +1274,7 @@ static int bin_pe_init_metadata_hdr(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
|
||||
rr = rz_buf_read_at(bin->b, metadata_directory + 16, (ut8 *)(metadata->VersionString), len);
|
||||
if (rr != len) {
|
||||
eprintf("Warning: read (metadata header) - cannot parse version string\n");
|
||||
RZ_LOG_ERROR("read (metadata header) - cannot parse version string\n");
|
||||
free(metadata->VersionString);
|
||||
free(metadata);
|
||||
return 0;
|
||||
|
|
@ -1344,7 +1341,7 @@ static int bin_pe_init_metadata_hdr(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
bin->streams = streams;
|
||||
return 1;
|
||||
fail:
|
||||
eprintf("Warning: read (metadata header)\n");
|
||||
RZ_LOG_ERROR("read (metadata header)\n");
|
||||
free(metadata);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1493,7 +1490,7 @@ static int bin_pe_init_imports(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
RZ_FREE(bin->import_directory);
|
||||
if (import_dir_paddr != 0) {
|
||||
if (import_dir_size < 1 || import_dir_size > maxidsz) {
|
||||
bprintf("Warning: Invalid import directory size: 0x%x is now 0x%x\n", import_dir_size, maxidsz);
|
||||
RZ_LOG_INFO("Invalid import directory size: 0x%x is now 0x%x\n", import_dir_size, maxidsz);
|
||||
import_dir_size = maxidsz;
|
||||
}
|
||||
bin->import_directory_offset = import_dir_offset;
|
||||
|
|
@ -1510,7 +1507,7 @@ static int bin_pe_init_imports(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
new_import_dir = NULL;
|
||||
curr_import_dir = import_dir + indx;
|
||||
if (read_image_import_directory(bin->b, import_dir_offset + indx * dir_size, curr_import_dir) <= 0) {
|
||||
bprintf("Warning: read (import directory)\n");
|
||||
RZ_LOG_INFO("read (import directory)\n");
|
||||
RZ_FREE(import_dir);
|
||||
break; // return false;
|
||||
}
|
||||
|
|
@ -1536,7 +1533,7 @@ static int bin_pe_init_imports(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
indx++;
|
||||
off = indx * delay_import_size;
|
||||
if (off >= rz_buf_size(bin->b)) {
|
||||
bprintf("Warning: Cannot find end of import symbols\n");
|
||||
RZ_LOG_INFO("Cannot find end of import symbols\n");
|
||||
break;
|
||||
}
|
||||
new_delay_import_dir = (PE_(image_delay_import_directory) *)realloc(
|
||||
|
|
@ -1551,7 +1548,7 @@ static int bin_pe_init_imports(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
rr = read_image_delay_import_directory(bin->b, delay_import_dir_offset + (indx - 1) * delay_import_size,
|
||||
curr_delay_import_dir);
|
||||
if (rr != dir_size) {
|
||||
bprintf("Warning: read (delay import directory)\n");
|
||||
RZ_LOG_INFO("read (delay import directory)\n");
|
||||
goto fail;
|
||||
}
|
||||
} while (curr_delay_import_dir->Name != 0);
|
||||
|
|
@ -1594,17 +1591,17 @@ static int bin_pe_init_exports(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
PE_DWord export_dir_paddr = bin_pe_rva_to_paddr(bin, data_dir_export->VirtualAddress);
|
||||
if (!export_dir_paddr) {
|
||||
// This export-dir-paddr should only appear in DLL files
|
||||
// bprintf ("Warning: Cannot find the paddr of the export directory\n");
|
||||
// RZ_LOG_INFO("Warning: Cannot find the paddr of the export directory\n");
|
||||
return false;
|
||||
}
|
||||
// sdb_setn (DB, "hdr.exports_directory", export_dir_paddr);
|
||||
// bprintf ("Pexports paddr at 0x%"PFMT64x"\n", export_dir_paddr);
|
||||
// RZ_LOG_INFO("Pexports paddr at 0x%"PFMT64x"\n", export_dir_paddr);
|
||||
if (!(bin->export_directory = malloc(sizeof(PE_(image_export_directory))))) {
|
||||
rz_sys_perror("malloc (export directory)");
|
||||
return false;
|
||||
}
|
||||
if (read_image_export_directory(bin->b, export_dir_paddr, bin->export_directory) < 0) {
|
||||
bprintf("Warning: read (export directory)\n");
|
||||
RZ_LOG_INFO("read (export directory)\n");
|
||||
RZ_FREE(bin->export_directory);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1668,7 +1665,7 @@ static int bin_pe_init_resource(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
return false;
|
||||
}
|
||||
if (read_image_resource_directory(bin->b, resource_dir_paddr, bin->resource_directory) < 0) {
|
||||
bprintf("Warning: read (resource directory)\n");
|
||||
RZ_LOG_INFO("read (resource directory)\n");
|
||||
RZ_FREE(bin->resource_directory);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1684,7 +1681,7 @@ static void bin_pe_store_tls_callbacks(struct PE_(rz_bin_pe_obj_t) * bin, PE_DWo
|
|||
|
||||
while (addressOfTLSCallback != 0) {
|
||||
if (!RZ_BUF_READ_PE_DWORD_AT(bin->b, callbacks, &addressOfTLSCallback)) {
|
||||
bprintf("Warning: read (tls_callback)\n");
|
||||
RZ_LOG_INFO("read (tls_callback)\n");
|
||||
return;
|
||||
}
|
||||
if (!addressOfTLSCallback) {
|
||||
|
|
@ -1746,7 +1743,7 @@ static int bin_pe_init_tls(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
|
||||
image_tls_directory = RZ_NEW0(PE_(image_tls_directory));
|
||||
if (read_tls_directory(bin->b, tls_paddr, image_tls_directory) < 0) {
|
||||
bprintf("Warning: read (image_tls_directory)\n");
|
||||
RZ_LOG_INFO("read (image_tls_directory)\n");
|
||||
free(image_tls_directory);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1839,65 +1836,65 @@ void PE_(free_VS_VERSIONINFO)(PE_VS_VERSIONINFO *vs_VersionInfo) {
|
|||
static Var *Pe_r_bin_pe_parse_var(struct PE_(rz_bin_pe_obj_t) * bin, PE_DWord *curAddr) {
|
||||
Var *var = calloc(1, sizeof(*var));
|
||||
if (!var) {
|
||||
bprintf("Warning: calloc (Var)\n");
|
||||
RZ_LOG_INFO("calloc (Var)\n");
|
||||
return NULL;
|
||||
}
|
||||
if (!rz_buf_read_le16_at(bin->b, *curAddr, &var->wLength)) {
|
||||
bprintf("Warning: read (Var wLength)\n");
|
||||
RZ_LOG_INFO("read (Var wLength)\n");
|
||||
free_Var(var);
|
||||
return NULL;
|
||||
}
|
||||
*curAddr += sizeof(var->wLength);
|
||||
if (!rz_buf_read_le16_at(bin->b, *curAddr, &var->wValueLength)) {
|
||||
bprintf("Warning: read (Var wValueLength)\n");
|
||||
RZ_LOG_INFO("read (Var wValueLength)\n");
|
||||
free_Var(var);
|
||||
return NULL;
|
||||
}
|
||||
*curAddr += sizeof(var->wValueLength);
|
||||
if (!rz_buf_read_le16_at(bin->b, *curAddr, &var->wType)) {
|
||||
bprintf("Warning: read (Var wType)\n");
|
||||
RZ_LOG_INFO("read (Var wType)\n");
|
||||
free_Var(var);
|
||||
return NULL;
|
||||
}
|
||||
*curAddr += sizeof(var->wType);
|
||||
if (var->wType != 0 && var->wType != 1) {
|
||||
bprintf("Warning: check (Var wType)\n");
|
||||
RZ_LOG_INFO("check (Var wType)\n");
|
||||
free_Var(var);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
var->szKey = (ut16 *)malloc(UT16_ALIGN(TRANSLATION_UTF_16_LEN)); // L"Translation"
|
||||
if (!var->szKey) {
|
||||
bprintf("Warning: malloc (Var szKey)\n");
|
||||
RZ_LOG_INFO("malloc (Var szKey)\n");
|
||||
free_Var(var);
|
||||
return NULL;
|
||||
}
|
||||
if (rz_buf_read_at(bin->b, *curAddr, (ut8 *)var->szKey, TRANSLATION_UTF_16_LEN) < 1) {
|
||||
bprintf("Warning: read (Var szKey)\n");
|
||||
RZ_LOG_INFO("read (Var szKey)\n");
|
||||
free_Var(var);
|
||||
return NULL;
|
||||
}
|
||||
*curAddr += TRANSLATION_UTF_16_LEN;
|
||||
if (memcmp(var->szKey, TRANSLATION_UTF_16, TRANSLATION_UTF_16_LEN)) {
|
||||
bprintf("Warning: check (Var szKey)\n");
|
||||
RZ_LOG_INFO("check (Var szKey)\n");
|
||||
free_Var(var);
|
||||
return NULL;
|
||||
}
|
||||
align32(*curAddr);
|
||||
var->numOfValues = var->wValueLength / 4;
|
||||
if (!var->numOfValues) {
|
||||
bprintf("Warning: check (Var numOfValues)\n");
|
||||
RZ_LOG_INFO("check (Var numOfValues)\n");
|
||||
free_Var(var);
|
||||
return NULL;
|
||||
}
|
||||
var->Value = (ut32 *)malloc(var->wValueLength);
|
||||
if (!var->Value) {
|
||||
bprintf("Warning: malloc (Var Value)\n");
|
||||
RZ_LOG_INFO("malloc (Var Value)\n");
|
||||
free_Var(var);
|
||||
return NULL;
|
||||
}
|
||||
if (rz_buf_read_at(bin->b, *curAddr, (ut8 *)var->Value, var->wValueLength) != var->wValueLength) {
|
||||
bprintf("Warning: read (Var Value)\n");
|
||||
RZ_LOG_INFO("read (Var Value)\n");
|
||||
free_Var(var);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -1908,58 +1905,58 @@ static Var *Pe_r_bin_pe_parse_var(struct PE_(rz_bin_pe_obj_t) * bin, PE_DWord *c
|
|||
static VarFileInfo *Pe_r_bin_pe_parse_var_file_info(struct PE_(rz_bin_pe_obj_t) * bin, PE_DWord *curAddr) {
|
||||
VarFileInfo *varFileInfo = calloc(1, sizeof(*varFileInfo));
|
||||
if (!varFileInfo) {
|
||||
bprintf("Warning: calloc (VarFileInfo)\n");
|
||||
RZ_LOG_INFO("calloc (VarFileInfo)\n");
|
||||
return NULL;
|
||||
}
|
||||
PE_DWord startAddr = *curAddr;
|
||||
if (!rz_buf_read_le16_at(bin->b, *curAddr, &varFileInfo->wLength)) {
|
||||
bprintf("Warning: read (VarFileInfo wLength)\n");
|
||||
RZ_LOG_INFO("read (VarFileInfo wLength)\n");
|
||||
free_VarFileInfo(varFileInfo);
|
||||
return NULL;
|
||||
}
|
||||
*curAddr += sizeof(varFileInfo->wLength);
|
||||
|
||||
if (!rz_buf_read_le16_at(bin->b, *curAddr, &varFileInfo->wValueLength)) {
|
||||
bprintf("Warning: read (VarFileInfo wValueLength)\n");
|
||||
RZ_LOG_INFO("read (VarFileInfo wValueLength)\n");
|
||||
free_VarFileInfo(varFileInfo);
|
||||
return NULL;
|
||||
}
|
||||
*curAddr += sizeof(varFileInfo->wValueLength);
|
||||
|
||||
if (varFileInfo->wValueLength != 0) {
|
||||
bprintf("Warning: check (VarFileInfo wValueLength)\n");
|
||||
RZ_LOG_INFO("check (VarFileInfo wValueLength)\n");
|
||||
free_VarFileInfo(varFileInfo);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!rz_buf_read_le16_at(bin->b, *curAddr, &varFileInfo->wType)) {
|
||||
bprintf("Warning: read (VarFileInfo wType)\n");
|
||||
RZ_LOG_INFO("read (VarFileInfo wType)\n");
|
||||
free_VarFileInfo(varFileInfo);
|
||||
return NULL;
|
||||
}
|
||||
*curAddr += sizeof(varFileInfo->wType);
|
||||
if (varFileInfo->wType && varFileInfo->wType != 1) {
|
||||
bprintf("Warning: check (VarFileInfo wType)\n");
|
||||
RZ_LOG_INFO("check (VarFileInfo wType)\n");
|
||||
free_VarFileInfo(varFileInfo);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
varFileInfo->szKey = (ut16 *)malloc(UT16_ALIGN(VARFILEINFO_UTF_16_LEN)); // L"VarFileInfo"
|
||||
if (!varFileInfo->szKey) {
|
||||
bprintf("Warning: malloc (VarFileInfo szKey)\n");
|
||||
RZ_LOG_INFO("malloc (VarFileInfo szKey)\n");
|
||||
free_VarFileInfo(varFileInfo);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (rz_buf_read_at(bin->b, *curAddr, (ut8 *)varFileInfo->szKey, VARFILEINFO_UTF_16_LEN) != VARFILEINFO_UTF_16_LEN) {
|
||||
bprintf("Warning: read (VarFileInfo szKey)\n");
|
||||
RZ_LOG_INFO("read (VarFileInfo szKey)\n");
|
||||
free_VarFileInfo(varFileInfo);
|
||||
return NULL;
|
||||
}
|
||||
*curAddr += VARFILEINFO_UTF_16_LEN;
|
||||
|
||||
if (memcmp(varFileInfo->szKey, VARFILEINFO_UTF_16, VARFILEINFO_UTF_16_LEN)) {
|
||||
bprintf("Warning: check (VarFileInfo szKey)\n");
|
||||
RZ_LOG_INFO("check (VarFileInfo szKey)\n");
|
||||
free_VarFileInfo(varFileInfo);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -1967,13 +1964,13 @@ static VarFileInfo *Pe_r_bin_pe_parse_var_file_info(struct PE_(rz_bin_pe_obj_t)
|
|||
while (startAddr + varFileInfo->wLength > *curAddr) {
|
||||
Var **tmp = (Var **)realloc(varFileInfo->Children, (varFileInfo->numOfChildren + 1) * sizeof(*varFileInfo->Children));
|
||||
if (!tmp) {
|
||||
bprintf("Warning: realloc (VarFileInfo Children)\n");
|
||||
RZ_LOG_INFO("realloc (VarFileInfo Children)\n");
|
||||
free_VarFileInfo(varFileInfo);
|
||||
return NULL;
|
||||
}
|
||||
varFileInfo->Children = tmp;
|
||||
if (!(varFileInfo->Children[varFileInfo->numOfChildren] = Pe_r_bin_pe_parse_var(bin, curAddr))) {
|
||||
bprintf("Warning: bad parsing Var\n");
|
||||
RZ_LOG_INFO("bad parsing Var\n");
|
||||
free_VarFileInfo(varFileInfo);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -1989,7 +1986,7 @@ static String *Pe_r_bin_pe_parse_string(struct PE_(rz_bin_pe_obj_t) * bin, PE_DW
|
|||
int len_value = 0;
|
||||
int i = 0;
|
||||
if (!string) {
|
||||
bprintf("Warning: calloc (String)\n");
|
||||
RZ_LOG_INFO("calloc (String)\n");
|
||||
return NULL;
|
||||
}
|
||||
if (begAddr > bin->size || begAddr + sizeof(string->wLength) > bin->size) {
|
||||
|
|
@ -1997,7 +1994,7 @@ static String *Pe_r_bin_pe_parse_string(struct PE_(rz_bin_pe_obj_t) * bin, PE_DW
|
|||
return NULL;
|
||||
}
|
||||
if (!rz_buf_read_le16_at(bin->b, *curAddr, &string->wLength)) {
|
||||
bprintf("Warning: read (String wLength)\n");
|
||||
RZ_LOG_INFO("read (String wLength)\n");
|
||||
goto out_error;
|
||||
}
|
||||
*curAddr += sizeof(string->wLength);
|
||||
|
|
@ -2005,7 +2002,7 @@ static String *Pe_r_bin_pe_parse_string(struct PE_(rz_bin_pe_obj_t) * bin, PE_DW
|
|||
goto out_error;
|
||||
}
|
||||
if (!rz_buf_read_le16_at(bin->b, *curAddr, &string->wValueLength)) {
|
||||
bprintf("Warning: read (String wValueLength)\n");
|
||||
RZ_LOG_INFO("read (String wValueLength)\n");
|
||||
goto out_error;
|
||||
}
|
||||
*curAddr += sizeof(string->wValueLength);
|
||||
|
|
@ -2014,12 +2011,12 @@ static String *Pe_r_bin_pe_parse_string(struct PE_(rz_bin_pe_obj_t) * bin, PE_DW
|
|||
goto out_error;
|
||||
}
|
||||
if (!rz_buf_read_le16_at(bin->b, *curAddr, &string->wType)) {
|
||||
bprintf("Warning: read (String wType)\n");
|
||||
RZ_LOG_INFO("read (String wType)\n");
|
||||
goto out_error;
|
||||
}
|
||||
*curAddr += sizeof(string->wType);
|
||||
if (string->wType != 0 && string->wType != 1) {
|
||||
bprintf("Warning: check (String wType)\n");
|
||||
RZ_LOG_INFO("check (String wType)\n");
|
||||
goto out_error;
|
||||
}
|
||||
|
||||
|
|
@ -2030,12 +2027,12 @@ static String *Pe_r_bin_pe_parse_string(struct PE_(rz_bin_pe_obj_t) * bin, PE_DW
|
|||
goto out_error;
|
||||
}
|
||||
if (rz_buf_read_at(bin->b, *curAddr, (ut8 *)&utf16_char, sizeof(ut16)) != sizeof(ut16)) {
|
||||
bprintf("Warning: check (String szKey)\n");
|
||||
RZ_LOG_INFO("check (String szKey)\n");
|
||||
goto out_error;
|
||||
}
|
||||
tmpKey = (ut16 *)realloc(string->szKey, (i + 1) * sizeof(ut16));
|
||||
if (!tmpKey) {
|
||||
bprintf("Warning: realloc (String szKey)\n");
|
||||
RZ_LOG_INFO("realloc (String szKey)\n");
|
||||
goto out_error;
|
||||
}
|
||||
string->szKey = tmpKey;
|
||||
|
|
@ -2054,14 +2051,14 @@ static String *Pe_r_bin_pe_parse_string(struct PE_(rz_bin_pe_obj_t) * bin, PE_DW
|
|||
}
|
||||
string->Value = (ut16 *)calloc(len_value + 1, 1);
|
||||
if (!string->Value) {
|
||||
bprintf("Warning: malloc (String Value)\n");
|
||||
RZ_LOG_INFO("malloc (String Value)\n");
|
||||
goto out_error;
|
||||
}
|
||||
if (*curAddr > bin->size || *curAddr + len_value > bin->size) {
|
||||
goto out_error;
|
||||
}
|
||||
if (rz_buf_read_at(bin->b, *curAddr, (ut8 *)string->Value, len_value) != len_value) {
|
||||
bprintf("Warning: read (String Value)\n");
|
||||
RZ_LOG_INFO("read (String Value)\n");
|
||||
goto out_error;
|
||||
}
|
||||
*curAddr += len_value;
|
||||
|
|
@ -2074,51 +2071,51 @@ out_error:
|
|||
static StringTable *Pe_r_bin_pe_parse_string_table(struct PE_(rz_bin_pe_obj_t) * bin, PE_DWord *curAddr) {
|
||||
StringTable *stringTable = calloc(1, sizeof(*stringTable));
|
||||
if (!stringTable) {
|
||||
bprintf("Warning: calloc (stringTable)\n");
|
||||
RZ_LOG_INFO("calloc (stringTable)\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PE_DWord startAddr = *curAddr;
|
||||
if (!rz_buf_read_le16_at(bin->b, *curAddr, &stringTable->wLength)) {
|
||||
bprintf("Warning: read (StringTable wLength)\n");
|
||||
RZ_LOG_INFO("read (StringTable wLength)\n");
|
||||
free_StringTable(stringTable);
|
||||
return NULL;
|
||||
}
|
||||
*curAddr += sizeof(stringTable->wLength);
|
||||
|
||||
if (!rz_buf_read_le16_at(bin->b, *curAddr, &stringTable->wValueLength)) {
|
||||
bprintf("Warning: read (StringTable wValueLength)\n");
|
||||
RZ_LOG_INFO("read (StringTable wValueLength)\n");
|
||||
free_StringTable(stringTable);
|
||||
return NULL;
|
||||
}
|
||||
*curAddr += sizeof(stringTable->wValueLength);
|
||||
|
||||
if (stringTable->wValueLength) {
|
||||
bprintf("Warning: check (StringTable wValueLength)\n");
|
||||
RZ_LOG_INFO("check (StringTable wValueLength)\n");
|
||||
free_StringTable(stringTable);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!rz_buf_read_le16_at(bin->b, *curAddr, &stringTable->wType)) {
|
||||
bprintf("Warning: read (StringTable wType)\n");
|
||||
RZ_LOG_INFO("read (StringTable wType)\n");
|
||||
free_StringTable(stringTable);
|
||||
return NULL;
|
||||
}
|
||||
*curAddr += sizeof(stringTable->wType);
|
||||
if (stringTable->wType && stringTable->wType != 1) {
|
||||
bprintf("Warning: check (StringTable wType)\n");
|
||||
RZ_LOG_INFO("check (StringTable wType)\n");
|
||||
free_StringTable(stringTable);
|
||||
return NULL;
|
||||
}
|
||||
stringTable->szKey = (ut16 *)malloc(UT16_ALIGN(EIGHT_HEX_DIG_UTF_16_LEN)); // EIGHT_HEX_DIG_UTF_16_LEN
|
||||
if (!stringTable->szKey) {
|
||||
bprintf("Warning: malloc (stringTable szKey)\n");
|
||||
RZ_LOG_INFO("malloc (stringTable szKey)\n");
|
||||
free_StringTable(stringTable);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (rz_buf_read_at(bin->b, *curAddr, (ut8 *)stringTable->szKey, EIGHT_HEX_DIG_UTF_16_LEN) != EIGHT_HEX_DIG_UTF_16_LEN) {
|
||||
bprintf("Warning: read (StringTable szKey)\n");
|
||||
RZ_LOG_INFO("read (StringTable szKey)\n");
|
||||
free_StringTable(stringTable);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -2127,13 +2124,13 @@ static StringTable *Pe_r_bin_pe_parse_string_table(struct PE_(rz_bin_pe_obj_t) *
|
|||
while (startAddr + stringTable->wLength > *curAddr) {
|
||||
String **tmp = (String **)realloc(stringTable->Children, (stringTable->numOfChildren + 1) * sizeof(*stringTable->Children));
|
||||
if (!tmp) {
|
||||
bprintf("Warning: realloc (StringTable Children)\n");
|
||||
RZ_LOG_INFO("realloc (StringTable Children)\n");
|
||||
free_StringTable(stringTable);
|
||||
return NULL;
|
||||
}
|
||||
stringTable->Children = tmp;
|
||||
if (!(stringTable->Children[stringTable->numOfChildren] = Pe_r_bin_pe_parse_string(bin, curAddr))) {
|
||||
bprintf("Warning: bad parsing String\n");
|
||||
RZ_LOG_INFO("bad parsing String\n");
|
||||
free_StringTable(stringTable);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -2142,7 +2139,7 @@ static StringTable *Pe_r_bin_pe_parse_string_table(struct PE_(rz_bin_pe_obj_t) *
|
|||
}
|
||||
|
||||
if (!stringTable->numOfChildren) {
|
||||
bprintf("Warning: check (StringTable numOfChildren)\n");
|
||||
RZ_LOG_INFO("check (StringTable numOfChildren)\n");
|
||||
free_StringTable(stringTable);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -2153,61 +2150,61 @@ static StringTable *Pe_r_bin_pe_parse_string_table(struct PE_(rz_bin_pe_obj_t) *
|
|||
static StringFileInfo *Pe_r_bin_pe_parse_string_file_info(struct PE_(rz_bin_pe_obj_t) * bin, PE_DWord *curAddr) {
|
||||
StringFileInfo *stringFileInfo = calloc(1, sizeof(*stringFileInfo));
|
||||
if (!stringFileInfo) {
|
||||
bprintf("Warning: calloc (StringFileInfo)\n");
|
||||
RZ_LOG_INFO("calloc (StringFileInfo)\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PE_DWord startAddr = *curAddr;
|
||||
|
||||
if (!rz_buf_read_le16_at(bin->b, *curAddr, &stringFileInfo->wLength)) {
|
||||
bprintf("Warning: read (StringFileInfo wLength)\n");
|
||||
RZ_LOG_INFO("read (StringFileInfo wLength)\n");
|
||||
free_StringFileInfo(stringFileInfo);
|
||||
return NULL;
|
||||
}
|
||||
*curAddr += sizeof(stringFileInfo->wLength);
|
||||
|
||||
if (!rz_buf_read_le16_at(bin->b, *curAddr, &stringFileInfo->wValueLength)) {
|
||||
bprintf("Warning: read (StringFileInfo wValueLength)\n");
|
||||
RZ_LOG_INFO("read (StringFileInfo wValueLength)\n");
|
||||
free_StringFileInfo(stringFileInfo);
|
||||
return NULL;
|
||||
}
|
||||
*curAddr += sizeof(stringFileInfo->wValueLength);
|
||||
|
||||
if (stringFileInfo->wValueLength) {
|
||||
bprintf("Warning: check (StringFileInfo wValueLength)\n");
|
||||
RZ_LOG_INFO("check (StringFileInfo wValueLength)\n");
|
||||
free_StringFileInfo(stringFileInfo);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!rz_buf_read_le16_at(bin->b, *curAddr, &stringFileInfo->wType)) {
|
||||
bprintf("Warning: read (StringFileInfo wType)\n");
|
||||
RZ_LOG_INFO("read (StringFileInfo wType)\n");
|
||||
free_StringFileInfo(stringFileInfo);
|
||||
return NULL;
|
||||
}
|
||||
*curAddr += sizeof(stringFileInfo->wType);
|
||||
|
||||
if (stringFileInfo->wType && stringFileInfo->wType != 1) {
|
||||
bprintf("Warning: check (StringFileInfo wType)\n");
|
||||
RZ_LOG_INFO("check (StringFileInfo wType)\n");
|
||||
free_StringFileInfo(stringFileInfo);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
stringFileInfo->szKey = (ut16 *)malloc(UT16_ALIGN(STRINGFILEINFO_UTF_16_LEN)); // L"StringFileInfo"
|
||||
if (!stringFileInfo->szKey) {
|
||||
bprintf("Warning: malloc (StringFileInfo szKey)\n");
|
||||
RZ_LOG_INFO("malloc (StringFileInfo szKey)\n");
|
||||
free_StringFileInfo(stringFileInfo);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (rz_buf_read_at(bin->b, *curAddr, (ut8 *)stringFileInfo->szKey, STRINGFILEINFO_UTF_16_LEN) != STRINGFILEINFO_UTF_16_LEN) {
|
||||
bprintf("Warning: read (StringFileInfo szKey)\n");
|
||||
RZ_LOG_INFO("read (StringFileInfo szKey)\n");
|
||||
free_StringFileInfo(stringFileInfo);
|
||||
return NULL;
|
||||
}
|
||||
*curAddr += STRINGFILEINFO_UTF_16_LEN;
|
||||
|
||||
if (memcmp(stringFileInfo->szKey, STRINGFILEINFO_UTF_16, STRINGFILEINFO_UTF_16_LEN) != 0) {
|
||||
bprintf("Warning: check (StringFileInfo szKey)\n");
|
||||
RZ_LOG_INFO("check (StringFileInfo szKey)\n");
|
||||
free_StringFileInfo(stringFileInfo);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -2217,13 +2214,13 @@ static StringFileInfo *Pe_r_bin_pe_parse_string_file_info(struct PE_(rz_bin_pe_o
|
|||
while (startAddr + stringFileInfo->wLength > *curAddr) {
|
||||
StringTable **tmp = (StringTable **)realloc(stringFileInfo->Children, (stringFileInfo->numOfChildren + 1) * sizeof(*stringFileInfo->Children));
|
||||
if (!tmp) {
|
||||
bprintf("Warning: realloc (StringFileInfo Children)\n");
|
||||
RZ_LOG_INFO("realloc (StringFileInfo Children)\n");
|
||||
free_StringFileInfo(stringFileInfo);
|
||||
return NULL;
|
||||
}
|
||||
stringFileInfo->Children = tmp;
|
||||
if (!(stringFileInfo->Children[stringFileInfo->numOfChildren] = Pe_r_bin_pe_parse_string_table(bin, curAddr))) {
|
||||
bprintf("Warning: bad parsing StringTable\n");
|
||||
RZ_LOG_INFO("bad parsing StringTable\n");
|
||||
free_StringFileInfo(stringFileInfo);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -2232,7 +2229,7 @@ static StringFileInfo *Pe_r_bin_pe_parse_string_file_info(struct PE_(rz_bin_pe_o
|
|||
}
|
||||
|
||||
if (!stringFileInfo->numOfChildren) {
|
||||
bprintf("Warning: check (StringFileInfo numOfChildren)\n");
|
||||
RZ_LOG_INFO("check (StringFileInfo numOfChildren)\n");
|
||||
free_StringFileInfo(stringFileInfo);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -2260,36 +2257,36 @@ static PE_VS_VERSIONINFO *Pe_r_bin_pe_parse_version_info(struct PE_(rz_bin_pe_ob
|
|||
sz = sizeof(ut16);
|
||||
EXIT_ON_OVERFLOW(sz);
|
||||
if (!rz_buf_read_le16_at(bin->b, curAddr, &vs_VersionInfo->wLength)) {
|
||||
bprintf("Warning: read (VS_VERSIONINFO wLength)\n");
|
||||
RZ_LOG_INFO("read (VS_VERSIONINFO wLength)\n");
|
||||
goto out_error;
|
||||
}
|
||||
curAddr += sz;
|
||||
EXIT_ON_OVERFLOW(sz);
|
||||
if (!rz_buf_read_le16_at(bin->b, curAddr, &vs_VersionInfo->wValueLength)) {
|
||||
bprintf("Warning: read (VS_VERSIONINFO wValueLength)\n");
|
||||
RZ_LOG_INFO("read (VS_VERSIONINFO wValueLength)\n");
|
||||
goto out_error;
|
||||
}
|
||||
curAddr += sz;
|
||||
EXIT_ON_OVERFLOW(sz);
|
||||
if (!rz_buf_read_le16_at(bin->b, curAddr, &vs_VersionInfo->wType)) {
|
||||
bprintf("Warning: read (VS_VERSIONINFO wType)\n");
|
||||
RZ_LOG_INFO("read (VS_VERSIONINFO wType)\n");
|
||||
goto out_error;
|
||||
}
|
||||
curAddr += sz;
|
||||
if (vs_VersionInfo->wType && vs_VersionInfo->wType != 1) {
|
||||
bprintf("Warning: check (VS_VERSIONINFO wType)\n");
|
||||
RZ_LOG_INFO("check (VS_VERSIONINFO wType)\n");
|
||||
goto out_error;
|
||||
}
|
||||
|
||||
vs_VersionInfo->szKey = (ut16 *)malloc(UT16_ALIGN(VS_VERSION_INFO_UTF_16_LEN)); // L"VS_VERSION_INFO"
|
||||
if (!vs_VersionInfo->szKey) {
|
||||
bprintf("Warning: malloc (VS_VERSIONINFO szKey)\n");
|
||||
RZ_LOG_INFO("malloc (VS_VERSIONINFO szKey)\n");
|
||||
goto out_error;
|
||||
}
|
||||
sz = VS_VERSION_INFO_UTF_16_LEN;
|
||||
EXIT_ON_OVERFLOW(sz);
|
||||
if (rz_buf_read_at(bin->b, curAddr, (ut8 *)vs_VersionInfo->szKey, sz) != sz) {
|
||||
bprintf("Warning: read (VS_VERSIONINFO szKey)\n");
|
||||
RZ_LOG_INFO("read (VS_VERSIONINFO szKey)\n");
|
||||
goto out_error;
|
||||
}
|
||||
curAddr += sz;
|
||||
|
|
@ -2299,24 +2296,24 @@ static PE_VS_VERSIONINFO *Pe_r_bin_pe_parse_version_info(struct PE_(rz_bin_pe_ob
|
|||
align32(curAddr);
|
||||
if (vs_VersionInfo->wValueLength) {
|
||||
if (vs_VersionInfo->wValueLength != sizeof(*vs_VersionInfo->Value)) {
|
||||
bprintf("Warning: check (VS_VERSIONINFO wValueLength != sizeof PE_VS_FIXEDFILEINFO)\n");
|
||||
RZ_LOG_INFO("check (VS_VERSIONINFO wValueLength != sizeof PE_VS_FIXEDFILEINFO)\n");
|
||||
goto out_error;
|
||||
}
|
||||
|
||||
vs_VersionInfo->Value = (PE_VS_FIXEDFILEINFO *)malloc(sizeof(*vs_VersionInfo->Value));
|
||||
if (!vs_VersionInfo->Value) {
|
||||
bprintf("Warning: malloc (VS_VERSIONINFO Value)\n");
|
||||
RZ_LOG_INFO("malloc (VS_VERSIONINFO Value)\n");
|
||||
goto out_error;
|
||||
}
|
||||
sz = sizeof(PE_VS_FIXEDFILEINFO);
|
||||
EXIT_ON_OVERFLOW(sz);
|
||||
if (rz_buf_read_at(bin->b, curAddr, (ut8 *)vs_VersionInfo->Value, sz) != sz) {
|
||||
bprintf("Warning: read (VS_VERSIONINFO Value)\n");
|
||||
RZ_LOG_INFO("read (VS_VERSIONINFO Value)\n");
|
||||
goto out_error;
|
||||
}
|
||||
|
||||
if (vs_VersionInfo->Value->dwSignature != 0xFEEF04BD) {
|
||||
bprintf("Warning: check (PE_VS_FIXEDFILEINFO signature) 0x%08x\n", vs_VersionInfo->Value->dwSignature);
|
||||
RZ_LOG_INFO("check (PE_VS_FIXEDFILEINFO signature) 0x%08x\n", vs_VersionInfo->Value->dwSignature);
|
||||
goto out_error;
|
||||
}
|
||||
curAddr += sz;
|
||||
|
|
@ -2329,22 +2326,22 @@ static PE_VS_VERSIONINFO *Pe_r_bin_pe_parse_version_info(struct PE_(rz_bin_pe_ob
|
|||
goto out_error;
|
||||
}
|
||||
if (rz_buf_read_at(bin->b, curAddr + 3 * sizeof(ut16), (ut8 *)&t, 1) != 1) {
|
||||
bprintf("Warning: read (VS_VERSIONINFO Children V or S)\n");
|
||||
RZ_LOG_INFO("read (VS_VERSIONINFO Children V or S)\n");
|
||||
goto out_error;
|
||||
}
|
||||
if (!(t == 'S' || t == 'V')) {
|
||||
bprintf("Warning: bad type (VS_VERSIONINFO Children)\n");
|
||||
RZ_LOG_INFO("bad type (VS_VERSIONINFO Children)\n");
|
||||
goto out_error;
|
||||
}
|
||||
if (t == 'S') {
|
||||
if (!(vs_VersionInfo->stringFileInfo = Pe_r_bin_pe_parse_string_file_info(bin, &curAddr))) {
|
||||
bprintf("Warning: bad parsing (VS_VERSIONINFO StringFileInfo)\n");
|
||||
RZ_LOG_INFO("bad parsing (VS_VERSIONINFO StringFileInfo)\n");
|
||||
goto out_error;
|
||||
}
|
||||
}
|
||||
if (t == 'V') {
|
||||
if (!(vs_VersionInfo->varFileInfo = Pe_r_bin_pe_parse_var_file_info(bin, &curAddr))) {
|
||||
bprintf("Warning: bad parsing (VS_VERSIONINFO VarFileInfo)\n");
|
||||
RZ_LOG_INFO("bad parsing (VS_VERSIONINFO VarFileInfo)\n");
|
||||
goto out_error;
|
||||
}
|
||||
}
|
||||
|
|
@ -2354,17 +2351,17 @@ static PE_VS_VERSIONINFO *Pe_r_bin_pe_parse_version_info(struct PE_(rz_bin_pe_ob
|
|||
if (startAddr + vs_VersionInfo->wLength > curAddr) {
|
||||
if (t == 'V') {
|
||||
if (!(vs_VersionInfo->stringFileInfo = Pe_r_bin_pe_parse_string_file_info(bin, &curAddr))) {
|
||||
bprintf("Warning: bad parsing (VS_VERSIONINFO StringFileInfo)\n");
|
||||
RZ_LOG_INFO("bad parsing (VS_VERSIONINFO StringFileInfo)\n");
|
||||
goto out_error;
|
||||
}
|
||||
} else if (t == 'S') {
|
||||
if (!(vs_VersionInfo->varFileInfo = Pe_r_bin_pe_parse_var_file_info(bin, &curAddr))) {
|
||||
bprintf("Warning: bad parsing (VS_VERSIONINFO VarFileInfo)\n");
|
||||
RZ_LOG_INFO("bad parsing (VS_VERSIONINFO VarFileInfo)\n");
|
||||
goto out_error;
|
||||
}
|
||||
}
|
||||
if (startAddr + vs_VersionInfo->wLength > curAddr) {
|
||||
bprintf("Warning: bad parsing (VS_VERSIONINFO wLength left)\n");
|
||||
RZ_LOG_INFO("bad parsing (VS_VERSIONINFO wLength left)\n");
|
||||
goto out_error;
|
||||
}
|
||||
}
|
||||
|
|
@ -3054,7 +3051,7 @@ static void _parse_resource_directory(struct PE_(rz_bin_pe_obj_t) * bin, Pe_imag
|
|||
break;
|
||||
}
|
||||
if (read_image_resource_directory_entry(bin->b, off, &entry) < 0) {
|
||||
eprintf("Warning: read resource entry\n");
|
||||
RZ_LOG_ERROR("read resource entry\n");
|
||||
break;
|
||||
}
|
||||
if (entry.u1.Name >> 31) {
|
||||
|
|
@ -3085,7 +3082,7 @@ static void _parse_resource_directory(struct PE_(rz_bin_pe_obj_t) * bin, Pe_imag
|
|||
off = rsrc_base + OffsetToDirectory;
|
||||
int len = read_image_resource_directory(bin->b, off, &identEntry);
|
||||
if (len < 1 || len != sizeof(Pe_image_resource_directory)) {
|
||||
eprintf("Warning: parsing resource directory\n");
|
||||
RZ_LOG_ERROR("parsing resource directory\n");
|
||||
}
|
||||
_parse_resource_directory(bin, &identEntry, OffsetToDirectory, type, entry.u1.Name & 0xffff, dirs, resourceEntryName);
|
||||
RZ_FREE(resourceEntryName);
|
||||
|
|
@ -3103,7 +3100,7 @@ static void _parse_resource_directory(struct PE_(rz_bin_pe_obj_t) * bin, Pe_imag
|
|||
break;
|
||||
}
|
||||
if (read_image_resource_data_entry(bin->b, off, data) != sizeof(*data)) {
|
||||
eprintf("Warning: read (resource data entry)\n");
|
||||
RZ_LOG_ERROR("read (resource data entry)\n");
|
||||
free(data);
|
||||
break;
|
||||
}
|
||||
|
|
@ -3118,14 +3115,14 @@ static void _parse_resource_directory(struct PE_(rz_bin_pe_obj_t) * bin, Pe_imag
|
|||
}
|
||||
PE_DWord data_paddr = bin_pe_rva_to_paddr(bin, data->OffsetToData);
|
||||
if (!data_paddr) {
|
||||
bprintf("Warning: bad RVA in resource data entry\n");
|
||||
RZ_LOG_INFO("bad RVA in resource data entry\n");
|
||||
free(data);
|
||||
sdb_free(sdb);
|
||||
continue;
|
||||
}
|
||||
PE_DWord cur_paddr = data_paddr;
|
||||
if ((cur_paddr & 0x3) != 0) {
|
||||
bprintf("Warning: not aligned version info address\n");
|
||||
RZ_LOG_INFO("not aligned version info address\n");
|
||||
free(data);
|
||||
sdb_free(sdb);
|
||||
continue;
|
||||
|
|
@ -3218,7 +3215,7 @@ RZ_API void PE_(bin_pe_parse_resource)(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
curRes = rs_directory->NumberOfNamedEntries;
|
||||
totalRes = curRes + rs_directory->NumberOfIdEntries;
|
||||
if (totalRes > RZ_PE_MAX_RESOURCES) {
|
||||
eprintf("Error parsing resource directory\n");
|
||||
RZ_LOG_ERROR("Cannot parse resource directory\n");
|
||||
ht_uu_free(dirs);
|
||||
return;
|
||||
}
|
||||
|
|
@ -3230,7 +3227,7 @@ RZ_API void PE_(bin_pe_parse_resource)(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
break;
|
||||
}
|
||||
if (read_image_resource_directory_entry(bin->b, off, &typeEntry) < 0) {
|
||||
eprintf("Warning: read resource directory entry\n");
|
||||
RZ_LOG_ERROR("read resource directory entry\n");
|
||||
break;
|
||||
}
|
||||
if (typeEntry.u2.OffsetToData >> 31) {
|
||||
|
|
@ -3239,7 +3236,7 @@ RZ_API void PE_(bin_pe_parse_resource)(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
off = rsrc_base + OffsetToDirectory;
|
||||
int len = read_image_resource_directory(bin->b, off, &identEntry);
|
||||
if (len != sizeof(identEntry)) {
|
||||
eprintf("Warning: parsing resource directory\n");
|
||||
RZ_LOG_ERROR("parsing resource directory\n");
|
||||
}
|
||||
(void)_parse_resource_directory(bin, &identEntry, OffsetToDirectory, typeEntry.u1.Name & 0xffff, 0, dirs, NULL);
|
||||
}
|
||||
|
|
@ -3259,7 +3256,7 @@ static int bin_pe_init_security(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
PE_DWord paddr = data_dir_security->VirtualAddress;
|
||||
ut32 size = data_dir_security->Size;
|
||||
if (size < 8 || paddr > bin->size || paddr + size > bin->size) {
|
||||
bprintf("Invalid certificate table");
|
||||
RZ_LOG_INFO("Invalid certificate table");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -3286,7 +3283,7 @@ static int bin_pe_init_security(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
}
|
||||
cert->dwLength += (8 - (cert->dwLength & 7)) & 7; // align32
|
||||
if (offset + cert->dwLength > paddr + size) {
|
||||
bprintf("Invalid certificate entry");
|
||||
RZ_LOG_INFO("Invalid certificate entry");
|
||||
RZ_FREE(cert);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -3299,7 +3296,7 @@ static int bin_pe_init_security(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
return false;
|
||||
}
|
||||
if (cert->dwLength < 6) {
|
||||
eprintf("Cert.dwLength must be > 6\n");
|
||||
RZ_LOG_ERROR("Invalid cert.dwLength (must be > 6)\n");
|
||||
RZ_FREE(cert);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -3360,11 +3357,11 @@ static int bin_pe_init(struct PE_(rz_bin_pe_obj_t) * bin) {
|
|||
bin->cms = NULL;
|
||||
bin->spcinfo = NULL;
|
||||
if (!bin_pe_init_hdr(bin)) {
|
||||
eprintf("Warning: File is not PE\n");
|
||||
RZ_LOG_ERROR("File is not PE\n");
|
||||
return false;
|
||||
}
|
||||
if (!bin_pe_init_sections(bin)) {
|
||||
eprintf("Warning: Cannot initialize sections\n");
|
||||
RZ_LOG_ERROR("Cannot initialize sections\n");
|
||||
return false;
|
||||
}
|
||||
bin->sections = PE_(rz_bin_pe_get_sections)(bin);
|
||||
|
|
@ -3453,8 +3450,8 @@ struct rz_bin_pe_addr_t *PE_(rz_bin_pe_get_entrypoint)(struct PE_(rz_bin_pe_obj_
|
|||
struct rz_bin_pe_section_t *sections = bin->sections;
|
||||
ut64 paddr = 0;
|
||||
if (!debug) {
|
||||
bprintf("Warning: Invalid entrypoint ... "
|
||||
"trying to fix it but i do not promise nothing\n");
|
||||
RZ_LOG_INFO("Invalid entrypoint ... "
|
||||
"trying to fix it but i do not promise nothing\n");
|
||||
}
|
||||
for (i = 0; i < bin->num_sections; i++) {
|
||||
if (sections[i].perm & PE_IMAGE_SCN_MEM_EXECUTE) {
|
||||
|
|
@ -3485,7 +3482,7 @@ struct rz_bin_pe_addr_t *PE_(rz_bin_pe_get_entrypoint)(struct PE_(rz_bin_pe_obj_
|
|||
}
|
||||
if (!entry->paddr) {
|
||||
if (!debug) {
|
||||
bprintf("Warning: NULL entrypoint\n");
|
||||
RZ_LOG_INFO("NULL entrypoint\n");
|
||||
}
|
||||
struct rz_bin_pe_section_t *sections = bin->sections;
|
||||
for (i = 0; i < bin->num_sections; i++) {
|
||||
|
|
@ -3547,7 +3544,7 @@ struct rz_bin_pe_export_t *PE_(rz_bin_pe_get_exports)(struct PE_(rz_bin_pe_obj_t
|
|||
}
|
||||
if (rz_buf_read_at(bin->b, bin_pe_rva_to_paddr(bin, bin->export_directory->Name), (ut8 *)dll_name, PE_NAME_LENGTH) < 1) {
|
||||
// we dont stop if dll name cant be read, we set dllname to null and continue
|
||||
bprintf("Warning: read (dll name)\n");
|
||||
RZ_LOG_INFO("read (dll name)\n");
|
||||
dll_name[0] = '\0';
|
||||
}
|
||||
functions_paddr = bin_pe_rva_to_paddr(bin, bin->export_directory->AddressOfFunctions);
|
||||
|
|
@ -3593,7 +3590,7 @@ struct rz_bin_pe_export_t *PE_(rz_bin_pe_get_exports)(struct PE_(rz_bin_pe_obj_t
|
|||
// get the name of the Export
|
||||
name_paddr = bin_pe_rva_to_paddr(bin, name_vaddr);
|
||||
if (rz_buf_read_at(bin->b, name_paddr, (ut8 *)function_name, PE_NAME_LENGTH) < 1) {
|
||||
bprintf("Warning: read (function name)\n");
|
||||
RZ_LOG_INFO("read (function name)\n");
|
||||
exports[i].last = 1;
|
||||
return exports;
|
||||
}
|
||||
|
|
@ -3693,7 +3690,7 @@ static int get_debug_info(struct PE_(rz_bin_pe_obj_t) * bin, PE_(image_debug_dir
|
|||
SCV_RSDS_HEADER rsds_hdr;
|
||||
init_rsdr_hdr(&rsds_hdr);
|
||||
if (!get_rsds(dbg_data, dbg_data_len, &rsds_hdr)) {
|
||||
bprintf("Warning: Cannot read PE debug info\n");
|
||||
RZ_LOG_INFO("Cannot read PE debug info\n");
|
||||
return 0;
|
||||
}
|
||||
snprintf(res->guidstr, GUIDSTR_LEN,
|
||||
|
|
@ -3716,7 +3713,7 @@ static int get_debug_info(struct PE_(rz_bin_pe_obj_t) * bin, PE_(image_debug_dir
|
|||
rsds_hdr.free((struct SCV_RSDS_HEADER *)&rsds_hdr);
|
||||
} else if (strncmp((const char *)dbg_data, "NB10", 4) == 0) {
|
||||
if (dbg_data_len < 20) {
|
||||
eprintf("Truncated NB10 entry, not enough data to parse\n");
|
||||
RZ_LOG_ERROR("Truncated NB10 entry, not enough data to parse\n");
|
||||
return 0;
|
||||
}
|
||||
SCV_NB10_HEADER nb10_hdr = { { 0 } };
|
||||
|
|
@ -3731,12 +3728,12 @@ static int get_debug_info(struct PE_(rz_bin_pe_obj_t) * bin, PE_(image_debug_dir
|
|||
res->file_name[sizeof(res->file_name) - 1] = 0;
|
||||
nb10_hdr.free((struct SCV_NB10_HEADER *)&nb10_hdr);
|
||||
} else {
|
||||
bprintf("CodeView section not NB10 or RSDS\n");
|
||||
RZ_LOG_INFO("CodeView section not NB10 or RSDS\n");
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// bprintf("get_debug_info(): not supported type\n");
|
||||
// RZ_LOG_INFO("get_debug_info(): not supported type\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -3843,7 +3840,7 @@ struct rz_bin_pe_import_t *PE_(rz_bin_pe_get_imports)(struct PE_(rz_bin_pe_obj_t
|
|||
}
|
||||
if (off + bin->import_directory_size > bin->size) {
|
||||
// why chopping instead of returning and cleaning?
|
||||
bprintf("Warning: read (import directory too big)\n");
|
||||
RZ_LOG_INFO("read (import directory too big)\n");
|
||||
bin->import_directory_size = bin->size - bin->import_directory_offset;
|
||||
}
|
||||
last = bin->import_directory_offset + bin->import_directory_size;
|
||||
|
|
@ -3953,7 +3950,7 @@ struct rz_bin_pe_lib_t *PE_(rz_bin_pe_get_libs)(struct PE_(rz_bin_pe_obj_t) * bi
|
|||
}
|
||||
|
||||
if (bin->import_directory_offset + bin->import_directory_size > bin->size) {
|
||||
bprintf("import directory offset bigger than file\n");
|
||||
RZ_LOG_INFO("import directory offset bigger than file\n");
|
||||
goto out_error;
|
||||
}
|
||||
lib_map = sdb_ht_new();
|
||||
|
|
@ -3975,7 +3972,7 @@ struct rz_bin_pe_lib_t *PE_(rz_bin_pe_get_libs)(struct PE_(rz_bin_pe_obj_t) * bi
|
|||
goto next;
|
||||
}
|
||||
if (len < 2 || libs[index].name[0] == 0) { // minimum string length
|
||||
bprintf("Warning: read (libs - import dirs) %d\n", len);
|
||||
RZ_LOG_INFO("read (libs - import dirs) %d\n", len);
|
||||
break;
|
||||
}
|
||||
libs[index].name[len - 1] = '\0';
|
||||
|
|
@ -4018,7 +4015,7 @@ struct rz_bin_pe_lib_t *PE_(rz_bin_pe_get_libs)(struct PE_(rz_bin_pe_obj_t) * bi
|
|||
}
|
||||
len = rz_buf_read_at(bin->b, name_off, (ut8 *)libs[index].name, PE_STRING_LENGTH);
|
||||
if (len != PE_STRING_LENGTH) {
|
||||
bprintf("Warning: read (libs - delay import dirs)\n");
|
||||
RZ_LOG_INFO("read (libs - delay import dirs)\n");
|
||||
break;
|
||||
}
|
||||
libs[index].name[len - 1] = '\0';
|
||||
|
|
@ -4228,7 +4225,7 @@ void PE_(rz_bin_pe_check_sections)(struct PE_(rz_bin_pe_obj_t) * bin, struct rz_
|
|||
if (addr_beg <= entry->vaddr || entry->vaddr < addr_end) {
|
||||
if (!(sections[j].perm & PE_IMAGE_SCN_MEM_EXECUTE)) {
|
||||
if (bin->verbose) {
|
||||
eprintf("Warning: Found entrypoint in non-executable section.\n");
|
||||
RZ_LOG_ERROR("Found entrypoint in non-executable section.\n");
|
||||
}
|
||||
sections[j].perm |= PE_IMAGE_SCN_MEM_EXECUTE;
|
||||
}
|
||||
|
|
@ -4453,7 +4450,7 @@ static struct rz_bin_pe_section_t *PE_(rz_bin_pe_get_sections)(struct PE_(rz_bin
|
|||
sections[j].vsize += sa - diff;
|
||||
}
|
||||
if (sections[j].vaddr % sa) {
|
||||
bprintf("Warning: section %s not aligned to SectionAlignment.\n",
|
||||
RZ_LOG_INFO("section %s not aligned to SectionAlignment.\n",
|
||||
sections[j].name);
|
||||
}
|
||||
}
|
||||
|
|
@ -4461,7 +4458,7 @@ static struct rz_bin_pe_section_t *PE_(rz_bin_pe_get_sections)(struct PE_(rz_bin
|
|||
if (fa) {
|
||||
const ut64 diff = sections[j].paddr % fa;
|
||||
if (diff) {
|
||||
bprintf("Warning: section %s not aligned to FileAlignment.\n", sections[j].name);
|
||||
RZ_LOG_INFO("section %s not aligned to FileAlignment.\n", sections[j].name);
|
||||
sections[j].paddr -= diff;
|
||||
sections[j].size += diff;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ struct PE_(rz_bin_pe_obj_t) * rz_bin_pemixed_init_dos(struct PE_(rz_bin_pe_obj_t
|
|||
}
|
||||
|
||||
if ((rz_buf_read_at(pe_bin->b, 0, tmp_buf, pe_hdr_off)) == -1) {
|
||||
eprintf("Error reading to buffer\n");
|
||||
RZ_LOG_ERROR("Cannot read buffer\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ struct PE_(rz_bin_pe_obj_t) * rz_bin_pemixed_init_native(struct PE_(rz_bin_pe_ob
|
|||
// copy pe_bin->b and assign to sub_bin_native
|
||||
|
||||
// if (!(tmp_buf = malloc (b_size))) {
|
||||
// eprintf("bad malloc\n");
|
||||
// RZ_LOG_ERROR("bad malloc\n");
|
||||
// };
|
||||
|
||||
// if (!(rz_buf_read_at (pe_bin->b, 0, tmp_buf, b_size))) {
|
||||
|
|
@ -76,7 +76,7 @@ struct PE_(rz_bin_pe_obj_t) * rz_bin_pemixed_init_native(struct PE_(rz_bin_pe_ob
|
|||
|
||||
if (!(sub_bin_native->b = rz_buf_new_with_buf(pe_bin->b))) {
|
||||
free(sub_bin_native);
|
||||
eprintf("failed\n");
|
||||
RZ_LOG_ERROR("failed to create new buffer\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +95,7 @@ struct PE_(rz_bin_pe_obj_t) * rz_bin_pemixed_init_native(struct PE_(rz_bin_pe_ob
|
|||
}
|
||||
|
||||
if (rz_buf_write_at(sub_bin_native->b, dotnet_offset, zero_out, sizeof(PE_(image_data_directory))) < -1) {
|
||||
eprintf("Zeroing out dotnet offset failed\n");
|
||||
RZ_LOG_ERROR("Zeroing out dotnet offset failed\n");
|
||||
rz_buf_free(sub_bin_native->b);
|
||||
free(sub_bin_native);
|
||||
free(zero_out);
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ static bool load_buffer(RzBinFile *bf, RzBinObject *obj, RzBuffer *buf, Sdb *sdb
|
|||
goto another_castle;
|
||||
}
|
||||
|
||||
eprintf("MOD Offset = 0x%" PFMT64x "\n", (ut64)modoff);
|
||||
RZ_LOG_INFO("MOD Offset = 0x%" PFMT64x "\n", (ut64)modoff);
|
||||
parseMod(bin->decompressed, bin, modoff, ba);
|
||||
obj->bin_obj = bin;
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -973,7 +973,6 @@ RZ_API bool rz_bin_select(RzBin *bin, const char *arch, int bits, const char *na
|
|||
RZ_API bool rz_bin_select_bfid(RzBin *bin, ut32 bf_id);
|
||||
RZ_API bool rz_bin_use_arch(RzBin *bin, const char *arch, int bits, const char *name);
|
||||
RZ_API RzBuffer *rz_bin_create(RzBin *bin, const char *plugin_name, const ut8 *code, int codelen, const ut8 *data, int datalen, RzBinArchOptions *opt);
|
||||
RZ_API RzBuffer *rz_bin_package(RzBin *bin, const char *type, const char *file, RzList *files);
|
||||
|
||||
RZ_API RZ_BORROW const char *rz_bin_string_type(int type);
|
||||
RZ_API const char *rz_bin_entry_type_string(int etype);
|
||||
|
|
@ -989,7 +988,6 @@ RZ_API ut64 rz_bin_file_get_vaddr(RzBinFile *bf, ut64 paddr, ut64 vaddr);
|
|||
// RzBinFile.add
|
||||
RZ_API RzBinClass *rz_bin_file_add_class(RzBinFile *binfile, const char *name, const char *super, int view);
|
||||
RZ_API RzBinSymbol *rz_bin_file_add_method(RzBinFile *bf, const char *classname, const char *name, int nargs);
|
||||
RZ_API RzBinField *rz_bin_file_add_field(RzBinFile *binfile, const char *classname, const char *name);
|
||||
// RzBinFile.find
|
||||
RZ_API RzBinFile *rz_bin_file_find_by_arch_bits(RzBin *bin, const char *arch, int bits);
|
||||
RZ_API RzBinFile *rz_bin_file_find_by_id(RzBin *bin, ut32 bin_id);
|
||||
|
|
|
|||
|
|
@ -914,7 +914,6 @@ RZ_API int rz_main_rz_bin(int argc, const char **argv) {
|
|||
case 'R': set_action(RZ_BIN_REQ_RELOCS); break;
|
||||
case 'Y': set_action(RZ_BIN_REQ_BASEFIND); break;
|
||||
case 'x': set_action(RZ_BIN_REQ_EXTRACT); break;
|
||||
case 'X': set_action(RZ_BIN_REQ_PACKAGE); break;
|
||||
case 'O':
|
||||
op = opt.arg;
|
||||
set_action(RZ_BIN_REQ_OPERATION);
|
||||
|
|
@ -1148,39 +1147,8 @@ RZ_API int rz_main_rz_bin(int argc, const char **argv) {
|
|||
rz_core_fini(&core);
|
||||
return 0;
|
||||
}
|
||||
if (action & RZ_BIN_REQ_PACKAGE) {
|
||||
RzList *files = rz_list_newf(NULL);
|
||||
const char *format = argv[opt.ind];
|
||||
const char *file = argv[opt.ind + 1];
|
||||
int i, rc = 0;
|
||||
|
||||
if (opt.ind + 3 > argc) {
|
||||
eprintf("Usage: rz-bin -X [fat|zip] foo.zip a b c\n");
|
||||
rz_core_fini(&core);
|
||||
return 1;
|
||||
}
|
||||
|
||||
eprintf("FMT %s\n", format);
|
||||
eprintf("PKG %s\n", file);
|
||||
for (i = opt.ind + 2; i < argc; i++) {
|
||||
eprintf("ADD %s\n", argv[i]);
|
||||
rz_list_append(files, (void *)argv[i]);
|
||||
}
|
||||
RzBuffer *buf = rz_bin_package(core.bin, format, file, files);
|
||||
/* TODO: return bool or something to catch errors\n") */
|
||||
if (buf) {
|
||||
bool ret = rz_buf_dump(buf, file);
|
||||
rz_buf_free(buf);
|
||||
if (!ret) {
|
||||
rc = 1;
|
||||
}
|
||||
}
|
||||
rz_core_fini(&core);
|
||||
rz_list_free(files);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (file && *file) {
|
||||
if (RZ_STR_ISNOTEMPTY(file)) {
|
||||
if ((fh = rz_core_file_open(&core, file, RZ_PERM_R, 0))) {
|
||||
fd = rz_io_fd_get_current(core.io);
|
||||
if (fd == -1) {
|
||||
|
|
|
|||
|
|
@ -68,20 +68,22 @@ def get_edited_files(args):
|
|||
yield filename
|
||||
|
||||
|
||||
def build_command(check, filenames):
|
||||
def build_command(check, filenames, verbose):
|
||||
cmd = ["clang-format", "--style=file"]
|
||||
if verbose:
|
||||
cmd += ["--verbose"]
|
||||
if check:
|
||||
return ["clang-format", "--style=file", "--Werror", "--dry-run"] + filenames
|
||||
|
||||
return ["clang-format", "--style=file", "-i"] + filenames
|
||||
cmd += ["--Werror", "--dry-run"]
|
||||
else:
|
||||
cmd += ["-i"]
|
||||
return cmd + filenames
|
||||
|
||||
|
||||
def format_files(args, files):
|
||||
if len(files) == 0:
|
||||
print("No C files to format.")
|
||||
sys.exit(0)
|
||||
cmd = build_command(args.check, files)
|
||||
if args.verbose:
|
||||
print(cmd)
|
||||
cmd = build_command(args.check, files, args.verbose)
|
||||
r = subprocess.run(cmd, check=False)
|
||||
sys.exit(r.returncode)
|
||||
|
||||
|
|
|
|||
|
|
@ -144,10 +144,11 @@ EOF
|
|||
EXPECT=<<EOF
|
||||
EOF
|
||||
REGEXP_FILTER_ERR=<<EOF
|
||||
Bad Luac File : .*\]
|
||||
ERROR:.+
|
||||
EOF
|
||||
EXPECT_ERR=<<EOF
|
||||
Bad Luac File : Truncated Code at [0x2f]
|
||||
ERROR: Truncated Code at [0x2f]
|
||||
ERROR: Invalid luac file
|
||||
EOF
|
||||
RUN
|
||||
|
||||
|
|
|
|||
|
|
@ -116,10 +116,10 @@ EOF
|
|||
EXPECT=<<EOF
|
||||
EOF
|
||||
REGEXP_FILTER_ERR=<<EOF
|
||||
Warning.*file
|
||||
ERROR:.+
|
||||
EOF
|
||||
EXPECT_ERR=<<EOF
|
||||
Warning : Broken luac file
|
||||
ERROR: Invalid luac file
|
||||
EOF
|
||||
RUN
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue