Skip to content

Commit

Permalink
Fix #9595 (#9673)
Browse files Browse the repository at this point in the history
* Added an address mask inside the RAnalEsil struct in order to be sure that the address accessed is relevant with the asm.bits of the file + Changed the calls to r_anal_esil_new

* Corrected the addrmask in r_anal_esil_new

* RTTI: Read MSVC Complete Object Locator

* RTTI: Read MSVC Class Hierarchy Descriptor

* VTable End on Reference

* RTTI: Read MSVC Type Descriptor

* RTTI: Read MSVC Base Class Array, Better Printing

* Add anal.cpp.abi

* Minor Code Style Changes in RTTI

* Fix rahash2 entropy to show non truncated double (#9629)

* Anal - whitespace fixes

* Honor CFLAGS on the static build test compilation (#9677)

* change coding style tab width to 4 (#9670)

* Meson: use more built-in options (#9678)

* Add support for extended regex in asm search (#9675)

* Fix #9665 - Backwardly handle scr.color={bool}

* Fix #9676 - Infinite loop in ecs with scr.color=2

* Adding help for redirection (#9679)

* Refactores function r_str_split_list to receive the character to split by (#9672)

* Fix #9666 - lines with comments do not use Unicode reflines

* Fix uninitialized optypes_list issue in cmd_debug

* update asan.sh to actually take the env for ASAN

* removed incorrect return (#9685)

* Fix UB in ESIL

* Initial import of the CoreUndo API and uc command

* Initial implementation of cmd.pdc to select pseudo-decompiler

* Handle recursive pdc calls

* Fix RPrint.strconv_mode memleak

* Fix leaks in RSyscall.srdb

* Use r_syscall_ref to avoid dblfree-or-leak issue

* Arm thumb/thumb selector for the armass (#9681)

* added function to translate number to imm12
* added function to get thumb shifts easily
* added selector, newfangled implementation of adc
* add bitmask for command suffixes
* added new routine for parsing suffixes to opcodes. Error check added in getnum. Bugfixes.

* Few improvements to 8051 memory mapping (#9686)

* update memory map when idata/sfr/xdata regs change
* set address space name on map
* fix regression, remove debug output
* fix regression, enable map name

* Some fixups for #9682 (#9688)

* Fix: coredump generation for huge programs (#9680)

* Refix #9666 - lines with comments do not use Unicode reflines

* Removed code unnecessary due to dcf3db0

* Fixed free const warning

* Fix another memleak in RSyscall

* Fix more memleaks

* Fix leak in RConsPal.rainbow

* Fix 18K leak in anal.x86.cs

* Fix some more memleaks in disasm and fix issue in str overlap

* Fix memleak in RCore.anal_refs and fix regression

* Revert "Fix some more memleaks in disasm and fix issue in str overlap"

This reverts commit a902df8.

* Fix memleak regressions

* Bring back another memleak fix

* Fix an undefined behaviour in RParse.filter

* Fix memleaks in disasm.c

* Add cundo.c to Meson (#9694)

* Bring back an ugly buffer pack access issue to make it work

* Cast to void * in R_FREE (#9692)

* Set anal.cpp.abi to msvc for pe

* Add better help for av

* Split avr into avr and avra

* Make av, avr and avra breakable

* Add RTTI struct specific print functions

* RTTI: Support MSVC x86_64

* PE: Fix too short section name.

* PDB: define a constant to store the max length of a section name and use id.

* PDB: dump the size of structure and union in JSON mode.

* Fix cast issue in eprintf for debug.core.linux

* Move the asm and anal plugins for x86.udis to extras

Available via r2pm -ci udis86

* Remove more udis86 references

* Fix warnings

* fix pcache ptr-fuckup

* Fix defragger theme

* Fix crash in asl and fix its behaviour

* Fix memory leak in blaze anal and silent a warning

* Implement ?q to be like ?v but in quiet mode

* Fix Meson build

* Add missing 8, 16, 32 bit registers (and flags) for the linux-arm64 debugger reg profile

* Fix 'Cannot find function at UT64_MAX message'

* Add some Pingu to fortunes.fun

* Loading Core (x86, x86_64, aarch64) (#9669)

* Ragg2-cc -> Ragg2 merge (#9658)

- change of 'access' function for 'r_file_exists' for windows portability
- several changes in the way ragg2.c is done, see PR #9658 pancake comments
- change function for the remove of 'file'.text
- open changed for r_file_dump
- some elt of cEnv_t are now const
- skip all the pointers verification in set_cEnv but do them in check_cEnv instead
- add 2 r_str_sanitize for file and CC in parseCFile
- rewrite the removal of .o, .tmp, .bin, .s files, with cleaner code
- changed the long command with sed and grep to 2 C functions.
  - The function parseCompiled that basically does what the command was doing
  - And r_str_stripLines that is equivalent to "grep -v" (maybe we should put this one in str.c ?)
- simplify a bit getCompiler function with a const char* array
- add ternary operator for armOrMips condition
- use r_file_path for finding path to compilers
- new file created in libr/egg which contains all the C file parser
- modifications of 2 files to match the change :
  - libr/egg/r_egg.h
  - libr/egg/Makefile
- the function r_str_stripLine is simplier (the mallocs wasn't needed)
- the function r_str_stripLine is moved to libr/util/str.c
- libr/include/r_util/r_str.h is changed accordingly

* Revert bd3465c9a3fbeddf83980dc07eaac588320f7d (warning remains fixed)

This reverts commit titled "Fixed free const warning".

* Added an address mask inside the RAnalEsil struct in order to be sure that the address accessed is relevant with the asm.bits of the file + Changed the calls to r_anal_esil_new

* Corrected the addrmask in r_anal_esil_new

* Cleanup expressions in esil.c (addr &=...)

* Corrected r_anal_esil_new definition in r_anal.h

* Added an address size max in the ESIL config (maximum address size reachable by the ESIL VM)
  • Loading branch information
redmed666 authored and radare committed Mar 16, 2018
1 parent 0f275ea commit 24e076e
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 18 deletions.
9 changes: 8 additions & 1 deletion libr/anal/esil.c
Expand Up @@ -78,7 +78,7 @@ static bool popRN(RAnalEsil *esil, ut64 *n) {

/* R_ANAL_ESIL API */

R_API RAnalEsil *r_anal_esil_new(int stacksize, int iotrap) {
R_API RAnalEsil *r_anal_esil_new(int stacksize, int iotrap, unsigned int addrsize) {
RAnalEsil *esil = R_NEW0 (RAnalEsil);
if (!esil) {
return NULL;
Expand All @@ -98,6 +98,7 @@ R_API RAnalEsil *r_anal_esil_new(int stacksize, int iotrap) {
esil->iotrap = iotrap;
esil->interrupts = sdb_new0 ();
esil->sessions = r_list_newf (r_anal_esil_session_free);
esil->addrmask = genmask (addrsize - 1);
return esil;
}

Expand Down Expand Up @@ -238,6 +239,7 @@ static bool alignCheck(RAnalEsil *esil, ut64 addr) {
}

static int internal_esil_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
addr &= esil->addrmask;
if (!esil || !esil->anal || !esil->anal->iob.io) {
return 0;
}
Expand Down Expand Up @@ -270,6 +272,7 @@ static int internal_esil_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len)
}

static int internal_esil_mem_read_no_null(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
addr &= esil->addrmask;
if (!esil || !esil->anal || !esil->anal->iob.io || !addr) {
return 0;
}
Expand All @@ -293,6 +296,7 @@ static int internal_esil_mem_read_no_null(RAnalEsil *esil, ut64 addr, ut8 *buf,

R_API int r_anal_esil_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
int i, ret = 0;
addr &= esil->addrmask;
if (!buf || !esil) {
return 0;
}
Expand Down Expand Up @@ -325,6 +329,7 @@ R_API int r_anal_esil_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {

static int internal_esil_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
int ret = 0;
addr &= esil->addrmask;
if (!esil || !esil->anal || !esil->anal->iob.io || esil->nowrite) {
return 0;
}
Expand Down Expand Up @@ -359,6 +364,7 @@ static int internal_esil_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, i

static int internal_esil_mem_write_no_null(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
int ret = 0;
addr &= esil->addrmask;
if (!esil || !esil->anal || !esil->anal->iob.io || !addr) {
return 0;
}
Expand All @@ -381,6 +387,7 @@ static int internal_esil_mem_write_no_null(RAnalEsil *esil, ut64 addr, const ut8

R_API int r_anal_esil_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
int i, ret = 0;
addr &= esil->addrmask;
if (!buf || !esil) {
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions libr/core/cconfig.c
Expand Up @@ -2360,6 +2360,7 @@ R_API int r_core_config_init(RCore *core) {
SETI ("esil.stack.size", 0xf0000, "Number of elements that can be pushed on the esilstack");
SETI ("esil.stack.addr", 0x100000, "Number of elements that can be pushed on the esilstack");
SETPREF ("esil.stack.pattern", "0", "Specify fill pattern to initialize the stack (0, w, d, i)");
SETI ("esil.addr.size", 64, "Maximum address size in accessed by the ESIL VM");

/* asm */
//asm.os needs to be first, since other asm.* depend on it
Expand Down
30 changes: 20 additions & 10 deletions libr/core/cmd_anal.c
Expand Up @@ -1267,6 +1267,8 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int
RAnalOp op;
ut64 addr;
bool isFirst = true;
unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size");


// Variables required for setting up ESIL to REIL conversion
if (use_color) {
Expand All @@ -1278,7 +1280,7 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int
break;
case 'r':
// Setup for ESIL to REIL conversion
esil = r_anal_esil_new (stacksize, iotrap);
esil = r_anal_esil_new (stacksize, iotrap, addrsize);
if (!esil) {
return;
}
Expand Down Expand Up @@ -3082,7 +3084,8 @@ static ut64 initializeEsil(RCore *core) {
int exectrap = r_config_get_i (core->config, "esil.exectrap");
int stacksize = r_config_get_i (core->config, "esil.stack.depth");
int noNULL = r_config_get_i (core->config, "esil.noNULL");
if (!(core->anal->esil = r_anal_esil_new (stacksize, iotrap))) {
unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size");
if (!(core->anal->esil = r_anal_esil_new (stacksize, iotrap, addrsize))) {
return UT64_MAX;
}
ut64 addr;
Expand Down Expand Up @@ -3122,7 +3125,8 @@ R_API int r_core_esil_step(RCore *core, ut64 until_addr, const char *until_expr,
int stats = r_config_get_i (core->config, "esil.stats");
int noNULL = r_config_get_i (core->config, "esil.noNULL");
int verbose = r_config_get_i (core->config, "esil.verbose");
if (!(esil = r_anal_esil_new (stacksize, iotrap))) {
unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size");
if (!(esil = r_anal_esil_new (stacksize, iotrap, addrsize))) {
return 0;
}
r_anal_esil_setup (esil, core->anal, romem, stats, noNULL); // setup io
Expand Down Expand Up @@ -3438,7 +3442,8 @@ static void cmd_esil_mem(RCore *core, const char *input) {
int stats = r_config_get_i (core->config, "esil.stats");
int noNULL = r_config_get_i (core->config, "esil.noNULL");
int verbose = r_config_get_i (core->config, "esil.verbose");
if (!(esil = r_anal_esil_new (stacksize, iotrap))) {
unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size");
if (!(esil = r_anal_esil_new (stacksize, iotrap, addrsize))) {
return;
}
r_anal_esil_setup (esil, core->anal, romem, stats, noNULL); // setup io
Expand Down Expand Up @@ -3593,7 +3598,8 @@ static void esil_init (RCore *core) {
if (!core->anal->esil) {
int iotrap = r_config_get_i (core->config, "esil.iotrap");
ut64 stackSize = r_config_get_i (core->config, "esil.stack.size");
if (!(core->anal->esil = r_anal_esil_new (stackSize, iotrap))) {
unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size");
if (!(core->anal->esil = r_anal_esil_new (stackSize, iotrap, addrsize))) {
R_FREE (regstate);
return;
}
Expand Down Expand Up @@ -3787,7 +3793,8 @@ static bool cmd_aea(RCore* core, int mode, ut64 addr, int length) {
int romem = r_config_get_i (core->config, "esil.romem");
int stats1 = r_config_get_i (core->config, "esil.stats");
int noNULL = r_config_get_i (core->config, "esil.noNULL");
esil = r_anal_esil_new (stacksize, iotrap);
unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size");
esil = r_anal_esil_new (stacksize, iotrap, addrsize);
r_anal_esil_setup (esil, core->anal, romem, stats1, noNULL); // setup io
# define hasNext(x) (x&1) ? (addr<addr_end) : (ops<ops_end)

Expand Down Expand Up @@ -3907,9 +3914,10 @@ static void cmd_aespc(RCore *core, ut64 addr, int off) {
RRegItem *r = r_reg_get (core->dbg->reg, pc, -1);
int stacksize = r_config_get_i (core->config, "esil.stack.depth");
int iotrap = r_config_get_i (core->config, "esil.iotrap");
unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size");

if (!esil) {
if (!(esil = r_anal_esil_new (stacksize, iotrap))) {
if (!(esil = r_anal_esil_new (stacksize, iotrap, addrsize))) {
return;
}
}
Expand Down Expand Up @@ -3961,6 +3969,8 @@ static void cmd_anal_esil(RCore *core, const char *input) {
int stats = r_config_get_i (core->config, "esil.stats");
int noNULL = r_config_get_i (core->config, "esil.noNULL");
ut64 until_addr = UT64_MAX;
unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size");

const char *until_expr = NULL;
RAnalOp *op;

Expand Down Expand Up @@ -4008,7 +4018,7 @@ static void cmd_anal_esil(RCore *core, const char *input) {
case ' ':
//r_anal_esil_eval (core->anal, input+1);
if (!esil) {
if (!(core->anal->esil = esil = r_anal_esil_new (stacksize, iotrap)))
if (!(core->anal->esil = esil = r_anal_esil_new (stacksize, iotrap, addrsize)))
return;
}
r_anal_esil_setup (esil, core->anal, romem, stats, noNULL); // setup io
Expand Down Expand Up @@ -4174,7 +4184,7 @@ static void cmd_anal_esil(RCore *core, const char *input) {
r_core_cmd0 (core, "ar PC=$$");
}
}
if (!(esil = core->anal->esil = r_anal_esil_new (stacksize, iotrap))) {
if (!(esil = core->anal->esil = r_anal_esil_new (stacksize, iotrap, addrsize))) {
return;
}
r_anal_esil_setup (esil, core->anal, romem, stats, noNULL); // setup io
Expand Down Expand Up @@ -4261,7 +4271,7 @@ static void cmd_anal_esil(RCore *core, const char *input) {
case 'r': // "aetr"
{
// anal ESIL to REIL.
RAnalEsil *esil = r_anal_esil_new (stacksize, iotrap);
RAnalEsil *esil = r_anal_esil_new (stacksize, iotrap, addrsize);
if (!esil)
return;
r_anal_esil_to_reil_setup (esil, core->anal, romem, stats);
Expand Down
3 changes: 2 additions & 1 deletion libr/core/cmd_debug.c
Expand Up @@ -4186,7 +4186,8 @@ static int cmd_debug(void *data, const char *input) {
int stats = r_config_get_i (core->config, "esil.stats");
int iotrap = r_config_get_i (core->config, "esil.iotrap");
int nonull = r_config_get_i (core->config, "esil.nonull");
if (!(core->anal->esil = r_anal_esil_new (stacksize, iotrap))) {
unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size");
if (!(core->anal->esil = r_anal_esil_new (stacksize, iotrap, addrsize))) {
return 0;
}
r_anal_esil_setup (core->anal->esil,
Expand Down
6 changes: 4 additions & 2 deletions libr/core/cmd_search.c
Expand Up @@ -1537,8 +1537,9 @@ static void do_esil_search(RCore *core, struct search_parameters *param, const c
ut64 nres, addr;
ut64 from = map->itv.addr;
ut64 to = r_itv_end (map->itv);
unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size");
if (!core->anal->esil) {
core->anal->esil = r_anal_esil_new (stacksize, iotrap);
core->anal->esil = r_anal_esil_new (stacksize, iotrap, addrsize);
}
/* hook addrinfo */
core->anal->esil->cb.user = core;
Expand Down Expand Up @@ -1691,8 +1692,9 @@ static void do_syscall_search(RCore *core, struct search_parameters *param) {
int align = core->search->align;
int stacksize = r_config_get_i (core->config, "esil.stack.depth");
int iotrap = r_config_get_i (core->config, "esil.iotrap");
unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size");

if (!(esil = r_anal_esil_new (stacksize, iotrap))) {
if (!(esil = r_anal_esil_new (stacksize, iotrap, addrsize))) {
return;
}
int *previnstr = calloc (MAXINSTR + 1, sizeof (int));
Expand Down
4 changes: 3 additions & 1 deletion libr/core/disasm.c
Expand Up @@ -3711,7 +3711,9 @@ static void ds_print_esil_anal_init(RDisasmState *ds) {
if (!core->anal->esil) {
int iotrap = r_config_get_i (core->config, "esil.iotrap");
int esd = r_config_get_i (core->config, "esil.stack.depth");
if (!(core->anal->esil = r_anal_esil_new (esd, iotrap))) {
unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size");

if (!(core->anal->esil = r_anal_esil_new (esd, iotrap, addrsize))) {
R_FREE (ds->esil_regstate);
return;
}
Expand Down
3 changes: 2 additions & 1 deletion libr/core/vmenus.c
Expand Up @@ -139,12 +139,13 @@ R_API bool r_core_visual_esil(RCore *core) {
RAsmOp asmop;
RAnalOp analop;
ut8 buf[sizeof (ut64)];
unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size");

if (core->blocksize < sizeof (ut64)) {
return false;
}
memcpy (buf, core->block, sizeof (ut64));
esil = r_anal_esil_new (20, 0);
esil = r_anal_esil_new (20, 0, addrsize);
esil->anal = core->anal;
r_anal_esil_set_pc (esil, core->offset);
for (;;) {
Expand Down
2 changes: 1 addition & 1 deletion libr/debug/esil.c
Expand Up @@ -212,7 +212,7 @@ R_API int r_debug_esil_stepi (RDebug *d) {
int ret = 1;
dbg = d;
if (!ESIL) {
ESIL = r_anal_esil_new (32, true);
ESIL = r_anal_esil_new (32, true, 64);
// TODO setup something?
if (!ESIL) {
return 0;
Expand Down
3 changes: 2 additions & 1 deletion libr/include/r_anal.h
Expand Up @@ -1046,6 +1046,7 @@ typedef struct r_anal_esil_callbacks_t {
typedef struct r_anal_esil_t {
RAnal *anal;
char **stack;
ut64 addrmask;
int stacksize;
int stackptr;
int skip;
Expand Down Expand Up @@ -1306,7 +1307,7 @@ R_API RAnalOp *r_anal_op_hexstr(RAnal *anal, ut64 addr,
const char *hexstr);
R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op);

R_API RAnalEsil *r_anal_esil_new (int stacksize, int iotrap);
R_API RAnalEsil *r_anal_esil_new (int stacksize, int iotrap, unsigned int addrsize);
R_API void r_anal_esil_trace (RAnalEsil *esil, RAnalOp *op);
R_API void r_anal_esil_trace_list (RAnalEsil *esil);
R_API void r_anal_esil_trace_show (RAnalEsil *esil, int idx);
Expand Down

0 comments on commit 24e076e

Please sign in to comment.