Rizin
unix-like reverse engineering framework and cli tools
ctypes.c File Reference
#include <string.h>
#include <rz_types.h>
#include <rz_list.h>
#include <rz_core.h>
#include <rz_type.h>
#include "core_private.h"

Go to the source code of this file.

Classes

struct  TLAnalysisContext
 
struct  coremodepj
 

Functions

RZ_IPI void rz_core_types_calling_conventions_print (RzCore *core, RzOutputMode mode)
 
RZ_IPI void rz_core_types_enum_print (RzCore *core, const RzBaseType *btype, RzOutputMode mode, PJ *pj)
 
RZ_IPI void rz_core_types_enum_print_all (RzCore *core, RzOutputMode mode)
 
RZ_IPI RZ_OWN char * rz_core_types_enum_as_c (RzTypeDB *typedb, const RzBaseType *btype, bool multiline)
 
RZ_IPI RZ_OWN char * rz_core_types_enum_as_c_all (RzTypeDB *typedb, bool multiline)
 
RZ_IPI void rz_core_types_union_print (RzCore *core, const RzBaseType *btype, RzOutputMode mode, PJ *pj)
 
RZ_IPI void rz_core_types_union_print_all (RzCore *core, RzOutputMode mode)
 
RZ_IPI RZ_OWN char * rz_core_types_union_as_c (RzTypeDB *typedb, const RzBaseType *btype, bool multiline)
 
RZ_IPI RZ_OWN char * rz_core_types_union_as_c_all (RzTypeDB *typedb, bool multiline)
 
RZ_IPI void rz_core_types_struct_print (RzCore *core, const RzBaseType *btype, RzOutputMode mode, PJ *pj)
 
RZ_IPI void rz_core_types_struct_print_all (RzCore *core, RzOutputMode mode)
 
RZ_IPI RZ_OWN char * rz_core_types_struct_as_c (RzTypeDB *typedb, const RzBaseType *btype, bool multiline)
 
RZ_IPI RZ_OWN char * rz_core_types_struct_as_c_all (RzTypeDB *typedb, bool multiline)
 
RZ_IPI void rz_core_types_typedef_print (RzCore *core, const RzBaseType *btype, RzOutputMode mode, PJ *pj)
 
RZ_IPI void rz_core_types_typedef_print_all (RzCore *core, RzOutputMode mode)
 
RZ_IPI RZ_OWN char * rz_core_types_typedef_as_c (RzTypeDB *typedb, const RzBaseType *btype)
 
RZ_IPI RZ_OWN char * rz_core_types_typedef_as_c_all (RzTypeDB *typedb)
 
RZ_IPI RZ_OWN char * rz_core_base_type_as_c (RzCore *core, RZ_NONNULL RzBaseType *type, bool multiline)
 
RZ_API RZ_OWN char * rz_core_types_as_c (RZ_NONNULL RzCore *core, RZ_NONNULL const char *name, bool multiline)
 Get a type string by name (. More...
 
RZ_API RZ_OWN char * rz_core_types_as_c_all (RZ_NONNULL RzCore *core, bool multiline)
 Get all types with pretty printing. More...
 
RZ_IPI void rz_core_types_function_print (RzTypeDB *typedb, const char *function, RzOutputMode mode, PJ *pj)
 
RZ_IPI void rz_core_types_function_print_all (RzCore *core, RzOutputMode mode)
 
static bool nonreturn_print (RzCore *core, RzList *noretl)
 
static bool nonreturn_print_json (RzCore *core, RzList *noretl)
 
RZ_IPI void rz_core_types_function_noreturn_print (RzCore *core, RzOutputMode mode)
 
RZ_IPI void rz_core_types_show_format (RzCore *core, const char *name, RzOutputMode mode)
 
RZ_IPI void rz_core_types_struct_print_format_all (RzCore *core)
 
RZ_IPI void rz_core_types_union_print_format_all (RzCore *core)
 
static void set_retval (RzCore *core, ut64 at)
 
static void set_offset_hint (RzCore *core, RzAnalysisOp *op, RZ_BORROW RzTypePath *tpath, ut64 laddr, ut64 at, int offimm)
 
static void resolve_type_links (RzCore *core, ut64 at, struct TLAnalysisContext *ctx, int ret, bool *resolved)
 
RZ_API void rz_core_link_stroff (RzCore *core, RzAnalysisFunction *fcn)
 
RZ_IPI void rz_core_types_link_print (RzCore *core, RzType *type, ut64 addr, RzOutputMode mode, PJ *pj)
 
static bool typelink_print_cb (void *user, ut64 k, const void *v)
 
RZ_IPI void rz_core_types_link_print_all (RzCore *core, RzOutputMode mode)
 
RZ_API void rz_core_types_link (RzCore *core, const char *typestr, ut64 addr)
 Link an address addr to the type referenced by typestr. More...
 
RZ_IPI void rz_core_types_link_show (RzCore *core, ut64 addr)
 
RZ_IPI void rz_core_types_print_all (RzCore *core, RzOutputMode mode)
 
RZ_IPI void rz_types_define (RzCore *core, const char *type)
 
RZ_IPI bool rz_types_open_file (RzCore *core, const char *path)
 
RZ_IPI bool rz_types_open_editor (RzCore *core, RZ_NONNULL const char *name)
 

Function Documentation

◆ nonreturn_print()

static bool nonreturn_print ( RzCore core,
RzList noretl 
)
static

Definition at line 530 of file ctypes.c.

530  {
531  RzListIter *it;
532  char *s;
533  rz_list_foreach (noretl, it, s) {
535  }
536  return true;
537 }
RZ_API void rz_cons_println(const char *str)
Definition: cons.c:233
static RzSocket * s
Definition: rtr.c:28

References rz_cons_println(), and s.

Referenced by rz_core_types_function_noreturn_print().

◆ nonreturn_print_json()

static bool nonreturn_print_json ( RzCore core,
RzList noretl 
)
static

Definition at line 539 of file ctypes.c.

539  {
540  RzListIter *it;
541  char *s;
542  PJ *pj = pj_new();
543  pj_a(pj);
544  rz_list_foreach (noretl, it, s) {
545  pj_s(pj, s);
546  }
547  pj_end(pj);
549  pj_free(pj);
550  return true;
551 }
RZ_API PJ * pj_new(void)
Definition: pj.c:25
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API const char * pj_string(PJ *pj)
Definition: pj.c:57
RZ_API void pj_free(PJ *j)
Definition: pj.c:34
RZ_API PJ * pj_s(PJ *j, const char *k)
Definition: pj.c:197
RZ_API PJ * pj_a(PJ *j)
Definition: pj.c:81
Definition: rz_pj.h:12

References pj_a(), pj_end(), pj_free(), pj_new(), pj_s(), pj_string(), rz_cons_println(), and s.

Referenced by rz_core_types_function_noreturn_print().

◆ resolve_type_links()

static void resolve_type_links ( RzCore core,
ut64  at,
struct TLAnalysisContext ctx,
int  ret,
bool resolved 
)
static

Definition at line 681 of file ctypes.c.

681  {
682  // At first we check if there are links to the corresponding addresses
683  RzList *slinks = rz_analysis_type_paths_by_address(core->analysis, ctx->src_addr);
684  RzList *dlinks = rz_analysis_type_paths_by_address(core->analysis, ctx->dst_addr);
685  RzList *vlinks = rz_analysis_type_paths_by_address(core->analysis, ctx->src_addr + ctx->src_imm);
686  // TODO: Handle register based arg for struct offset propgation
687  if (vlinks && rz_list_length(vlinks) && ctx->var && ctx->var->kind != 'r') {
688  RzTypePath *vlink = rz_list_get_top(vlinks);
689  // FIXME: For now we only propagate simple type identifiers,
690  // no pointers or arrays
691  if (vlink->typ->kind == RZ_TYPE_KIND_IDENTIFIER) {
692  if (!vlink->typ->identifier.name) {
694  return;
695  }
696  RzBaseType *varbtype = rz_type_db_get_base_type(core->analysis->typedb, vlink->typ->identifier.name);
697  if (varbtype) {
698  // if a var addr matches with struct , change it's type and name
699  // var int local_e0h --> var struct foo
700  // if (strcmp(var->name, vlink) && !*resolved) {
701  if (!*resolved) {
702  *resolved = true;
703  rz_analysis_var_set_type(ctx->var, vlink->typ, true);
704  rz_analysis_var_rename(ctx->var, vlink->typ->identifier.name, false);
705  }
706  }
707  }
708  } else if (slinks && rz_list_length(slinks)) {
709  RzTypePath *slink = rz_list_get_top(slinks);
710  set_offset_hint(core, ctx->aop, slink, ctx->src_addr, at - ret, ctx->src_imm);
711  } else if (dlinks && rz_list_length(dlinks)) {
712  RzTypePath *dlink = rz_list_get_top(dlinks);
713  set_offset_hint(core, ctx->aop, dlink, ctx->dst_addr, at - ret, ctx->dst_imm);
714  }
715 }
RZ_API RZ_BORROW RzBaseType * rz_type_db_get_base_type(const RzTypeDB *typedb, RZ_NONNULL const char *name)
Searches for the RzBaseType in the types database given the name.
Definition: base.c:57
static void set_offset_hint(RzCore *core, RzAnalysisOp *op, RZ_BORROW RzTypePath *tpath, ut64 laddr, ut64 at, int offimm)
Definition: ctypes.c:650
RZ_API RZ_BORROW void * rz_list_get_top(RZ_NONNULL const RzList *list)
Returns the last element of the list.
Definition: list.c:457
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
Definition: list.c:109
#define rz_warn_if_reached()
Definition: rz_assert.h:29
@ RZ_TYPE_KIND_IDENTIFIER
Definition: rz_type.h:128
RzTypeDB * typedb
Definition: rz_analysis.h:602
RzAnalysis * analysis
Definition: rz_core.h:322
RzType * typ
Definition: rz_type.h:175
RzTypeKind kind
Definition: rz_type.h:155
struct rz_type_t::@292::@294 identifier
RZ_API bool rz_analysis_var_rename(RzAnalysisVar *var, const char *new_name, bool verbose)
Definition: var.c:348
RZ_API void rz_analysis_var_set_type(RzAnalysisVar *var, RZ_OWN RzType *type, bool resolve_overlaps)
Definition: var.c:170

References rz_core_t::analysis, rz_type_t::identifier, rz_type_t::kind, rz_analysis_type_paths_by_address(), rz_analysis_var_rename(), rz_analysis_var_set_type(), rz_list_get_top(), rz_list_length(), rz_type_db_get_base_type(), RZ_TYPE_KIND_IDENTIFIER, rz_warn_if_reached, set_offset_hint(), rz_type_path_t::typ, and rz_analysis_t::typedb.

Referenced by rz_core_link_stroff().

◆ rz_core_base_type_as_c()

RZ_IPI RZ_OWN char* rz_core_base_type_as_c ( RzCore core,
RZ_NONNULL RzBaseType type,
bool  multiline 
)

Definition at line 408 of file ctypes.c.

408  {
410 
411  unsigned int multiline_opt = 0;
412  if (multiline) {
413  multiline_opt = RZ_TYPE_PRINT_MULTILINE;
414  }
416 }
RZ_API RZ_OWN char * rz_type_db_base_type_as_pretty_string(RZ_NONNULL const RzTypeDB *typedb, RZ_NONNULL const RzBaseType *btype, unsigned int opts, int unfold_level)
Returns C representation as string of RzBaseType.
Definition: base.c:219
#define NULL
Definition: cris-opc.c:27
int type
Definition: mipsasm.c:17
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
@ RZ_TYPE_PRINT_END_NEWLINE
Definition: rz_type.h:222
@ RZ_TYPE_PRINT_MULTILINE
Definition: rz_type.h:216
@ RZ_TYPE_PRINT_ANONYMOUS
Definition: rz_type.h:221

References rz_core_t::analysis, NULL, rz_return_val_if_fail, rz_type_db_base_type_as_pretty_string(), RZ_TYPE_PRINT_ANONYMOUS, RZ_TYPE_PRINT_END_NEWLINE, RZ_TYPE_PRINT_MULTILINE, type, and rz_analysis_t::typedb.

Referenced by rz_core_types_as_c(), and rz_types_open_editor().

◆ rz_core_link_stroff()

RZ_API void rz_core_link_stroff ( RzCore core,
RzAnalysisFunction fcn 
)

Definition at line 717 of file ctypes.c.

717  {
718  rz_return_if_fail(core && core->analysis && fcn);
719  RzAnalysisBlock *bb;
720  RzListIter *it;
721  RzAnalysisOp aop = { 0 };
722  bool ioCache = rz_config_get_i(core->config, "io.cache");
723  bool stack_set = false;
724  bool resolved = false;
725  int dbg_follow = rz_config_get_i(core->config, "dbg.follow");
726  RzAnalysisEsil *esil;
727  int iotrap = rz_config_get_i(core->config, "esil.iotrap");
728  int stacksize = rz_config_get_i(core->config, "esil.stack.depth");
729  unsigned int addrsize = rz_config_get_i(core->config, "esil.addr.size");
730  const char *pc_name = rz_reg_get_name(core->analysis->reg, RZ_REG_NAME_PC);
731  const char *sp_name = rz_reg_get_name(core->analysis->reg, RZ_REG_NAME_SP);
732  RzRegItem *pc = rz_reg_get(core->analysis->reg, pc_name, -1);
733 
734  if (!(esil = rz_analysis_esil_new(stacksize, iotrap, addrsize))) {
735  return;
736  }
737  rz_analysis_esil_setup(esil, core->analysis, 0, 0, 0);
738  int i, ret, bsize = RZ_MAX(64, core->blocksize);
739  const int mininstrsz = rz_analysis_archinfo(core->analysis, RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE);
740  const int maxinstrsz = rz_analysis_archinfo(core->analysis, RZ_ANALYSIS_ARCHINFO_MAX_OP_SIZE);
741  const int minopcode = RZ_MAX(1, mininstrsz);
742  ut8 *buf = malloc(bsize);
743  if (!buf) {
744  free(buf);
745  rz_analysis_esil_free(esil);
746  return;
747  }
749  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_ANY, true);
750  ut64 spval = rz_reg_getv(esil->analysis->reg, sp_name);
751  if (spval) {
752  // reset stack pointer to initial value
753  RzRegItem *sp = rz_reg_get(esil->analysis->reg, sp_name, -1);
754  ut64 curpc = rz_reg_getv(esil->analysis->reg, pc_name);
755  int stacksz = rz_core_get_stacksz(core, fcn->addr, curpc);
756  if (stacksz > 0) {
757  rz_reg_arena_zero(esil->analysis->reg, RZ_REG_TYPE_ANY); // clear prev reg values
758  rz_reg_set_value(esil->analysis->reg, sp, spval + stacksz);
759  }
760  } else {
761  // initialize stack
763  stack_set = true;
764  }
765  rz_config_set_i(core->config, "io.cache", 1);
766  rz_config_set_i(core->config, "dbg.follow", 0);
767  ut64 oldoff = core->offset;
769  // TODO: The algorithm can be more accurate if blocks are followed by their jmp/fail, not just by address
770  rz_list_sort(fcn->bbs, bb_cmpaddr);
771  rz_list_foreach (fcn->bbs, it, bb) {
772  ut64 at = bb->addr;
773  ut64 to = bb->addr + bb->size;
774  rz_reg_set_value(esil->analysis->reg, pc, at);
775  for (i = 0; at < to; i++) {
776  if (rz_cons_is_breaked()) {
777  goto beach;
778  }
779  if (at < bb->addr) {
780  break;
781  }
782  if (i >= (bsize - maxinstrsz)) {
783  i = 0;
784  }
785  if (!i) {
786  rz_io_read_at(core->io, at, buf, bsize);
787  }
788  ret = rz_analysis_op(core->analysis, &aop, at, buf + i, bsize - i, RZ_ANALYSIS_OP_MASK_VAL);
789  if (ret <= 0) {
790  i += minopcode;
791  at += minopcode;
792  rz_analysis_op_fini(&aop);
793  continue;
794  }
795  i += ret - 1;
796  at += ret;
797  int j, src_imm = -1, dst_imm = -1;
798  ut64 src_addr = UT64_MAX;
799  ut64 dst_addr = UT64_MAX;
800  for (j = 0; j < 3; j++) {
801  if (aop.src[j]) {
802  if (aop.src[j]->type == RZ_ANALYSIS_VAL_REG) {
803  if (aop.src[j]->reg && aop.src[j]->reg->name) {
804  src_addr = rz_reg_getv(esil->analysis->reg, aop.src[j]->reg->name);
805  }
806  src_imm = 0;
807  } else if (aop.src[j]->type == RZ_ANALYSIS_VAL_MEM) {
808  if (aop.src[j]->reg && aop.src[j]->reg->name) {
809  src_addr = rz_reg_getv(esil->analysis->reg, aop.src[j]->reg->name);
810  if (aop.src[j]->regdelta && aop.src[j]->regdelta->name) {
811  src_addr += rz_reg_getv(esil->analysis->reg, aop.src[j]->regdelta->name) * aop.src[j]->mul;
812  }
813  }
814  src_imm = aop.src[j]->base + aop.src[j]->delta;
815  } else if (aop.src[j]->type == RZ_ANALYSIS_VAL_IMM) {
816  src_addr = aop.src[j]->imm;
817  src_imm = 0;
818  }
819  }
820  }
821  if (aop.dst) {
822  if (aop.dst->type == RZ_ANALYSIS_VAL_REG) {
823  if (aop.dst->reg && aop.dst->reg->name) {
824  dst_addr = rz_reg_getv(esil->analysis->reg, aop.dst->reg->name);
825  }
826  dst_imm = 0;
827  } else if (aop.dst->type == RZ_ANALYSIS_VAL_MEM) {
828  if (aop.dst->reg && aop.dst->reg->name) {
829  dst_addr = rz_reg_getv(esil->analysis->reg, aop.dst->reg->name);
830  if (aop.dst->regdelta && aop.dst->regdelta->name) {
831  dst_addr += rz_reg_getv(esil->analysis->reg, aop.dst->regdelta->name) * aop.dst->mul;
832  }
833  }
834  dst_imm = aop.dst->base + aop.dst->delta;
835  } else if (aop.dst->type == RZ_ANALYSIS_VAL_IMM) {
836  dst_addr = aop.dst->imm;
837  dst_imm = 0;
838  }
839  }
841  if (false) { // src_addr != UT64_MAX || dst_addr != UT64_MAX) {
842  // if (src_addr == UT64_MAX && dst_addr == UT64_MAX) {
843  rz_analysis_op_fini(&aop);
844  continue;
845  }
846  struct TLAnalysisContext ctx = {
847  .aop = &aop,
848  .var = var,
849  .src_addr = src_addr,
850  .dst_addr = dst_addr,
851  .src_imm = src_imm,
852  .dst_imm = dst_imm
853  };
854  resolve_type_links(core, at, &ctx, ret, &resolved);
856  rz_reg_set_value(esil->analysis->reg, pc, at);
857  set_retval(core, at - ret);
858  } else {
859  rz_core_esil_step(core, UT64_MAX, NULL, NULL, false);
860  }
862  }
863  }
864 beach:
865  rz_io_cache_reset(core->io, core->io->cached); // drop cache writes
866  rz_config_set_i(core->config, "io.cache", ioCache);
867  rz_config_set_i(core->config, "dbg.follow", dbg_follow);
868  if (stack_set) {
870  }
871  rz_core_seek(core, oldoff, true);
872  rz_analysis_esil_free(esil);
873  rz_reg_arena_pop(core->analysis->reg);
876  free(buf);
877 }
RZ_API int rz_analysis_archinfo(RzAnalysis *analysis, int query)
Definition: analysis.c:449
static int bb_cmpaddr(const void *_a, const void *_b)
Definition: analysis_tp.c:530
lzma_index ** i
Definition: index.h:629
RZ_API int rz_reg_arena_push(RzReg *reg)
Definition: arena.c:236
RZ_API void rz_reg_arena_pop(RzReg *reg)
Definition: arena.c:216
RZ_API void rz_reg_arena_zero(RzReg *reg, RzRegisterType type)
Definition: arena.c:261
RZ_API int rz_core_get_stacksz(RzCore *core, ut64 from, ut64 to)
Definition: canalysis.c:6582
RZ_API void rz_core_analysis_esil_init_mem(RZ_NONNULL RzCore *core, RZ_NULLABLE const char *name, ut64 addr, ut32 size)
Definition: cil.c:149
RZ_API void rz_core_analysis_esil_init_mem_del(RZ_NONNULL RzCore *core, RZ_NULLABLE const char *name, ut64 addr, ut32 size)
Remove ESIL VM stack.
Definition: cil.c:241
RZ_API int rz_core_esil_step(RzCore *core, ut64 until_addr, const char *until_expr, ut64 *prev_addr, bool stepOver)
Definition: cmd_analysis.c:860
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
RZ_API RzConfigNode * rz_config_set_i(RzConfig *cfg, RZ_NONNULL const char *name, const ut64 i)
Definition: config.c:419
RZ_API void rz_cons_break_pop(void)
Definition: cons.c:361
RZ_API void rz_cons_break_push(RzConsBreak cb, void *user)
Definition: cons.c:357
RZ_API bool rz_cons_is_breaked(void)
Definition: cons.c:373
RZ_API void rz_core_reg_update_flags(RzCore *core)
Update or create flags for all registers where it makes sense.
Definition: creg.c:106
static void resolve_type_links(RzCore *core, ut64 at, struct TLAnalysisContext *ctx, int ret, bool *resolved)
Definition: ctypes.c:681
static void set_retval(RzCore *core, ut64 at)
Definition: ctypes.c:626
RZ_API int rz_debug_reg_sync(RzDebug *dbg, int type, int write)
Definition: dreg.c:9
RZ_API RzAnalysisEsil * rz_analysis_esil_new(int stacksize, int iotrap, unsigned int addrsize)
Definition: esil.c:85
RZ_API bool rz_analysis_esil_setup(RzAnalysisEsil *esil, RzAnalysis *analysis, int romem, int stats, int nonull)
Definition: esil.c:3298
RZ_API void rz_analysis_esil_free(RzAnalysisEsil *esil)
Definition: esil.c:163
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
RZ_API void rz_list_sort(RZ_NONNULL RzList *list, RZ_NONNULL RzListComparator cmp)
Sorts via merge sort or via insertion sort a list.
Definition: list.c:743
void * malloc(size_t size)
Definition: malloc.c:123
RZ_API bool rz_analysis_op_fini(RzAnalysisOp *op)
Definition: op.c:37
RZ_API bool rz_analysis_op_nonlinear(int t)
Definition: op.c:177
RZ_API int rz_analysis_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *data, int len, RzAnalysisOpMask mask)
Definition: op.c:96
RZ_API ut64 rz_reg_getv(RzReg *reg, const char *name)
Definition: reg.c:332
RZ_API RzRegItem * rz_reg_get(RzReg *reg, const char *name, int type)
Definition: reg.c:344
RZ_API const char * rz_reg_get_name(RzReg *reg, int role)
Definition: reg.c:147
RZ_API bool rz_reg_set_value(RzReg *reg, RzRegItem *item, ut64 value)
Definition: rvalue.c:186
@ RZ_ANALYSIS_VAL_IMM
Definition: rz_analysis.h:770
@ RZ_ANALYSIS_VAL_REG
Definition: rz_analysis.h:768
@ RZ_ANALYSIS_VAL_MEM
Definition: rz_analysis.h:769
#define RZ_ANALYSIS_ARCHINFO_MAX_OP_SIZE
Definition: rz_analysis.h:99
@ RZ_ANALYSIS_OP_MASK_VAL
Definition: rz_analysis.h:442
#define RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE
Definition: rz_analysis.h:98
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
RZ_API bool rz_io_read_at(RzIO *io, ut64 addr, ut8 *buf, int len)
Definition: io.c:300
RZ_API void rz_io_cache_reset(RzIO *io, int set)
Definition: io_cache.c:57
@ RZ_REG_TYPE_ANY
Definition: rz_reg.h:35
@ RZ_REG_NAME_SP
Definition: rz_reg.h:44
@ RZ_REG_NAME_PC
Definition: rz_reg.h:43
#define UT32_MAX
Definition: rz_types_base.h:99
#define RZ_MAX(x, y)
#define UT64_MAX
Definition: rz_types_base.h:86
RZ_API bool rz_core_seek(RzCore *core, ut64 addr, bool rb)
Seek to addr.
Definition: seek.c:116
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr socklen_t static fromlen const void const struct sockaddr to
Definition: sfsocketcall.h:125
RzAnalysisOp * aop
Definition: ctypes.c:672
RzAnalysisVar * var
Definition: ctypes.c:673
RzAnalysis * analysis
Definition: rz_analysis.h:1043
RzAnalysisValue * dst
Definition: rz_analysis.h:840
RzAnalysisValue * src[3]
Definition: rz_analysis.h:839
RzAnalysisValueType type
Definition: rz_analysis.h:775
RzRegItem * regdelta
Definition: rz_analysis.h:785
ut64 offset
Definition: rz_core.h:301
RzDebug * dbg
Definition: rz_core.h:329
RzIO * io
Definition: rz_core.h:313
ut32 blocksize
Definition: rz_core.h:303
RzConfig * config
Definition: rz_core.h:300
int cached
Definition: rz_io.h:69
char * name
Definition: rz_reg.h:118
RZ_DEPRECATE RZ_API RzAnalysisVar * rz_analysis_get_used_function_var(RzAnalysis *analysis, ut64 addr)
Definition: var.c:398
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int sp
Definition: z80asm.c:91
static int addr
Definition: z80asm.c:58

References addr, rz_analysis_function_t::addr, rz_analysis_op_t::addr, rz_analysis_bb_t::addr, rz_analysis_esil_t::analysis, rz_core_t::analysis, TLAnalysisContext::aop, rz_analysis_value_t::base, bb_cmpaddr(), rz_analysis_function_t::bbs, rz_core_t::blocksize, rz_io_t::cached, rz_core_t::config, rz_core_t::dbg, rz_analysis_value_t::delta, rz_analysis_op_t::dst, TLAnalysisContext::dst_addr, TLAnalysisContext::dst_imm, free(), i, rz_analysis_value_t::imm, rz_core_t::io, malloc(), rz_analysis_value_t::mul, rz_reg_item_t::name, NULL, rz_core_t::offset, pc, rz_analysis_t::reg, rz_analysis_value_t::reg, rz_analysis_value_t::regdelta, resolve_type_links(), rz_analysis_archinfo(), RZ_ANALYSIS_ARCHINFO_MAX_OP_SIZE, RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE, rz_analysis_esil_free(), rz_analysis_esil_new(), rz_analysis_esil_setup(), rz_analysis_get_used_function_var(), rz_analysis_op(), rz_analysis_op_fini(), RZ_ANALYSIS_OP_MASK_VAL, rz_analysis_op_nonlinear(), RZ_ANALYSIS_VAL_IMM, RZ_ANALYSIS_VAL_MEM, RZ_ANALYSIS_VAL_REG, rz_config_get_i(), rz_config_set_i(), rz_cons_break_pop(), rz_cons_break_push(), rz_cons_is_breaked(), rz_core_analysis_esil_init_mem(), rz_core_analysis_esil_init_mem_del(), rz_core_esil_step(), rz_core_get_stacksz(), rz_core_reg_update_flags(), rz_core_seek(), rz_debug_reg_sync(), rz_io_cache_reset(), rz_io_read_at(), rz_list_sort(), RZ_MAX, rz_reg_arena_pop(), rz_reg_arena_push(), rz_reg_arena_zero(), rz_reg_get(), rz_reg_get_name(), rz_reg_getv(), RZ_REG_NAME_PC, RZ_REG_NAME_SP, rz_reg_set_value(), RZ_REG_TYPE_ANY, rz_return_if_fail, set_retval(), rz_analysis_bb_t::size, sp, rz_analysis_op_t::src, TLAnalysisContext::src_addr, TLAnalysisContext::src_imm, to, rz_analysis_value_t::type, rz_analysis_op_t::type, UT32_MAX, ut64(), UT64_MAX, and TLAnalysisContext::var.

Referenced by rz_analyze_function_linked_offsets_handler(), and rz_core_types_link().

◆ rz_core_types_as_c()

RZ_API RZ_OWN char* rz_core_types_as_c ( RZ_NONNULL RzCore core,
RZ_NONNULL const char *  name,
bool  multiline 
)

Get a type string by name (.

See also
rz_type_db_base_type_as_pretty_string)
Parameters
coreRzCore reference
nameType name
multilinePretty printing with RZ_TYPE_PRINT_MULTILINE

Definition at line 424 of file ctypes.c.

424  {
425  rz_return_val_if_fail(core && core->analysis, NULL);
426 
427  RzBaseType *btype = rz_type_db_get_base_type(core->analysis->typedb, name);
428  if (!btype) {
429  return NULL;
430  }
431  return rz_core_base_type_as_c(core, btype, multiline);
432 }
RZ_IPI RZ_OWN char * rz_core_base_type_as_c(RzCore *core, RZ_NONNULL RzBaseType *type, bool multiline)
Definition: ctypes.c:408
Definition: z80asm.h:102

References NULL, rz_core_base_type_as_c(), rz_return_val_if_fail, and rz_type_db_get_base_type().

Referenced by rz_type_list_c_handler(), and rz_type_list_c_nl_handler().

◆ rz_core_types_as_c_all()

RZ_API RZ_OWN char* rz_core_types_as_c_all ( RZ_NONNULL RzCore core,
bool  multiline 
)

Get all types with pretty printing.

Parameters
coreRzCore reference
multilinePretty printing with RZ_TYPE_PRINT_MULTILINE

Definition at line 439 of file ctypes.c.

439  {
440  rz_return_val_if_fail(core && core->analysis, NULL);
441 
442  RzStrBuf *buf = rz_strbuf_new("");
443  // List all unions in the C format with newlines
444  char *str = rz_core_types_union_as_c_all(core->analysis->typedb, multiline);
445  if (str) {
447  free(str);
448  }
449  // List all structures in the C format with newlines
450  str = rz_core_types_struct_as_c_all(core->analysis->typedb, multiline);
451  if (str) {
453  free(str);
454  }
455  // List all typedefs in the C format with newlines
456  str = rz_core_types_typedef_as_c_all(core->analysis->typedb);
457  if (str) {
459  free(str);
460  }
461  // List all enums in the C format with newlines
462  str = rz_core_types_enum_as_c_all(core->analysis->typedb, multiline);
463  if (str) {
465  free(str);
466  }
467  return rz_strbuf_drain(buf);
468 }
RZ_IPI RZ_OWN char * rz_core_types_struct_as_c_all(RzTypeDB *typedb, bool multiline)
Definition: ctypes.c:320
RZ_IPI RZ_OWN char * rz_core_types_typedef_as_c_all(RzTypeDB *typedb)
Definition: ctypes.c:392
RZ_IPI RZ_OWN char * rz_core_types_enum_as_c_all(RzTypeDB *typedb, bool multiline)
Definition: ctypes.c:134
RZ_IPI RZ_OWN char * rz_core_types_union_as_c_all(RzTypeDB *typedb, bool multiline)
Definition: ctypes.c:228
RZ_API RZ_OWN char * rz_strbuf_drain(RzStrBuf *sb)
Definition: strbuf.c:342
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
Definition: strbuf.c:222
RZ_API RzStrBuf * rz_strbuf_new(const char *s)
Definition: strbuf.c:8

References free(), NULL, rz_core_types_enum_as_c_all(), rz_core_types_struct_as_c_all(), rz_core_types_typedef_as_c_all(), rz_core_types_union_as_c_all(), rz_return_val_if_fail, rz_strbuf_append(), rz_strbuf_drain(), rz_strbuf_new(), and cmd_descs_generate::str.

Referenced by type_list_c_all(), and type_list_c_all_nl().

◆ rz_core_types_calling_conventions_print()

RZ_IPI void rz_core_types_calling_conventions_print ( RzCore core,
RzOutputMode  mode 
)

Definition at line 19 of file ctypes.c.

19  {
22  const char *cc;
23  switch (mode) {
25  rz_list_foreach (list, iter, cc) {
26  rz_cons_println(cc);
27  }
28  } break;
29  case RZ_OUTPUT_MODE_JSON: {
30  PJ *pj = pj_new();
31  pj_a(pj);
32  rz_list_foreach (list, iter, cc) {
33  rz_core_analysis_cc_print(core, cc, pj);
34  }
35  pj_end(pj);
36  rz_cons_printf("%s\n", pj_string(pj));
37  pj_free(pj);
38  } break;
39  case RZ_OUTPUT_MODE_LONG: {
40  rz_list_foreach (list, iter, cc) {
41  char *ccexpr = rz_analysis_cc_get(core->analysis, cc);
42  rz_cons_printf("%s\n", ccexpr);
43  free(ccexpr);
44  }
45  } break;
46  case RZ_OUTPUT_MODE_RIZIN: {
47  rz_list_foreach (list, iter, cc) {
48  char *ccexpr = rz_analysis_cc_get(core->analysis, cc);
49  rz_cons_printf("tcc \"%s\"\n", ccexpr);
50  free(ccexpr);
51  }
52  } break;
53  case RZ_OUTPUT_MODE_SDB:
54  rz_core_kuery_print(core, "analysis/cc/*");
55  break;
56  default:
58  break;
59  }
61 }
RZ_IPI void rz_core_analysis_cc_print(RzCore *core, RZ_NONNULL const char *cc, RZ_NULLABLE PJ *pj)
Print Calling Convention info.
Definition: canalysis.c:6686
RZ_API char * rz_analysis_cc_get(RzAnalysis *analysis, const char *name)
Definition: cc.c:75
RZ_API RzList * rz_analysis_calling_conventions(RzAnalysis *analysis)
Definition: cc.c:226
RZ_IPI void rz_core_kuery_print(RzCore *core, const char *k)
Definition: cmd.c:634
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
const char int mode
Definition: ioapi.h:137
static void list(RzEgg *egg)
Definition: rz-gg.c:52
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
@ RZ_OUTPUT_MODE_LONG
Definition: rz_types.h:44
@ RZ_OUTPUT_MODE_JSON
Definition: rz_types.h:40
@ RZ_OUTPUT_MODE_SDB
Definition: rz_types.h:43
@ RZ_OUTPUT_MODE_RIZIN
Definition: rz_types.h:41
@ RZ_OUTPUT_MODE_STANDARD
Definition: rz_types.h:39

References rz_core_t::analysis, free(), list(), pj_a(), pj_end(), pj_free(), pj_new(), pj_string(), rz_analysis_calling_conventions(), rz_analysis_cc_get(), rz_cons_printf(), rz_cons_println(), rz_core_analysis_cc_print(), rz_core_kuery_print(), rz_list_free(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_LONG, RZ_OUTPUT_MODE_RIZIN, RZ_OUTPUT_MODE_SDB, RZ_OUTPUT_MODE_STANDARD, and rz_warn_if_reached.

Referenced by cb_analysiscc(), cb_analysissyscc(), rz_analysis_function_cc_list_handler(), and rz_type_cc_list_handler().

◆ rz_core_types_enum_as_c()

RZ_IPI RZ_OWN char* rz_core_types_enum_as_c ( RzTypeDB typedb,
const RzBaseType btype,
bool  multiline 
)

Definition at line 123 of file ctypes.c.

123  {
124  rz_return_val_if_fail(btype, NULL);
126 
127  unsigned int multiline_opt = 0;
128  if (multiline) {
129  multiline_opt = RZ_TYPE_PRINT_MULTILINE;
130  }
132 }
@ RZ_BASE_TYPE_KIND_ENUM
Definition: rz_type.h:75
RzBaseTypeKind kind
Definition: rz_type.h:115

References rz_base_type_t::kind, NULL, RZ_BASE_TYPE_KIND_ENUM, rz_return_val_if_fail, rz_type_db_base_type_as_pretty_string(), RZ_TYPE_PRINT_ANONYMOUS, RZ_TYPE_PRINT_END_NEWLINE, and RZ_TYPE_PRINT_MULTILINE.

Referenced by rz_core_types_enum_as_c_all(), rz_type_enum_c_handler(), and rz_type_enum_c_nl_handler().

◆ rz_core_types_enum_as_c_all()

RZ_IPI RZ_OWN char* rz_core_types_enum_as_c_all ( RzTypeDB typedb,
bool  multiline 
)

Definition at line 134 of file ctypes.c.

134  {
136  RzListIter *it;
137  RzBaseType *btype;
138  RzStrBuf *buf = rz_strbuf_new("");
139  rz_list_foreach (enumlist, it, btype) {
140  char *str = rz_core_types_enum_as_c(typedb, btype, multiline);
141  if (str) {
143  }
144  free(str);
145  }
146  rz_list_free(enumlist);
147  return rz_strbuf_drain(buf);
148 }
RZ_API RZ_OWN RzList * rz_type_db_get_base_types_of_kind(const RzTypeDB *typedb, RzBaseTypeKind kind)
Returns the list of all basic types of the chosen kind.
Definition: base.c:100
RZ_IPI RZ_OWN char * rz_core_types_enum_as_c(RzTypeDB *typedb, const RzBaseType *btype, bool multiline)
Definition: ctypes.c:123

References free(), RZ_BASE_TYPE_KIND_ENUM, rz_core_types_enum_as_c(), rz_list_free(), rz_strbuf_append(), rz_strbuf_drain(), rz_strbuf_new(), rz_type_db_get_base_types_of_kind(), and cmd_descs_generate::str.

Referenced by rz_core_types_as_c_all(), rz_type_enum_c_handler(), and rz_type_enum_c_nl_handler().

◆ rz_core_types_enum_print()

RZ_IPI void rz_core_types_enum_print ( RzCore core,
const RzBaseType btype,
RzOutputMode  mode,
PJ pj 
)

Definition at line 65 of file ctypes.c.

65  {
66  rz_return_if_fail(core && btype);
68 
69  switch (mode) {
70  case RZ_OUTPUT_MODE_JSON: {
72  pj_o(pj);
73  if (btype && !rz_vector_empty(&btype->enum_data.cases)) {
74  pj_ks(pj, "name", btype->name);
75  pj_k(pj, "values");
76  pj_o(pj);
77  RzTypeEnumCase *cas;
78  rz_vector_foreach(&btype->enum_data.cases, cas) {
79  pj_kn(pj, cas->name, cas->val);
80  }
81  pj_end(pj);
82  }
83  pj_end(pj);
84  break;
85  }
87  if (btype && !rz_vector_empty(&btype->enum_data.cases)) {
88  RzTypeEnumCase *cas;
89  rz_vector_foreach(&btype->enum_data.cases, cas) {
90  rz_cons_printf("%s = 0x%" PFMT64x "\n", cas->name, cas->val);
91  }
92  }
93  break;
94  }
96  rz_cons_println(btype->name);
97  break;
98  default:
100  break;
101  }
102 }
RZ_API PJ * pj_k(PJ *j, const char *k)
Definition: pj.c:104
RZ_API PJ * pj_o(PJ *j)
Definition: pj.c:75
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
RZ_API PJ * pj_kn(PJ *j, const char *k, ut64 n)
Definition: pj.c:121
@ RZ_OUTPUT_MODE_QUIET
Definition: rz_types.h:42
#define PFMT64x
Definition: rz_types.h:393
#define rz_vector_foreach(vec, it)
Definition: rz_vector.h:169
static bool rz_vector_empty(const RzVector *vec)
Definition: rz_vector.h:74
RzVector cases
Definition: rz_type.h:108
char * name
Definition: rz_type.h:112
RzBaseTypeEnum enum_data
Definition: rz_type.h:119

References rz_base_type_enum_t::cases, rz_base_type_t::enum_data, rz_base_type_t::kind, rz_type_enum_case_t::name, rz_base_type_t::name, PFMT64x, pj_end(), pj_k(), pj_kn(), pj_ks(), pj_o(), RZ_BASE_TYPE_KIND_ENUM, rz_cons_printf(), rz_cons_println(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_STANDARD, rz_return_if_fail, rz_vector_empty(), rz_vector_foreach, rz_warn_if_reached, and rz_type_enum_case_t::val.

Referenced by rz_core_types_enum_print_all(), and rz_type_list_enum_handler().

◆ rz_core_types_enum_print_all()

RZ_IPI void rz_core_types_enum_print_all ( RzCore core,
RzOutputMode  mode 
)

Definition at line 104 of file ctypes.c.

104  {
106  RzListIter *it;
107  PJ *pj = (mode == RZ_OUTPUT_MODE_JSON) ? pj_new() : NULL;
108  if (mode == RZ_OUTPUT_MODE_JSON) {
109  pj_a(pj);
110  }
111  RzBaseType *btype;
112  rz_list_foreach (enumlist, it, btype) {
113  rz_core_types_enum_print(core, btype, mode, pj);
114  }
115  rz_list_free(enumlist);
116  if (mode == RZ_OUTPUT_MODE_JSON) {
117  pj_end(pj);
119  pj_free(pj);
120  }
121 }
RZ_IPI void rz_core_types_enum_print(RzCore *core, const RzBaseType *btype, RzOutputMode mode, PJ *pj)
Definition: ctypes.c:65

References rz_core_t::analysis, NULL, pj_a(), pj_end(), pj_free(), pj_new(), pj_string(), RZ_BASE_TYPE_KIND_ENUM, rz_cons_println(), rz_core_types_enum_print(), rz_list_free(), RZ_OUTPUT_MODE_JSON, rz_type_db_get_base_types_of_kind(), and rz_analysis_t::typedb.

Referenced by rz_type_list_enum_handler().

◆ rz_core_types_function_noreturn_print()

RZ_IPI void rz_core_types_function_noreturn_print ( RzCore core,
RzOutputMode  mode 
)

Definition at line 553 of file ctypes.c.

553  {
555  switch (mode) {
556  case RZ_OUTPUT_MODE_JSON:
557  nonreturn_print_json(core, noretl);
558  break;
559  default:
560  nonreturn_print(core, noretl);
561  break;
562  }
563  rz_list_free(noretl);
564 }
static bool nonreturn_print(RzCore *core, RzList *noretl)
Definition: ctypes.c:530
static bool nonreturn_print_json(RzCore *core, RzList *noretl)
Definition: ctypes.c:539
RZ_API RZ_OWN RzList * rz_type_noreturn_function_names(RzTypeDB *typedb)
Returns the list of all noreturn function type names.
Definition: function.c:588

References rz_core_t::analysis, nonreturn_print(), nonreturn_print_json(), rz_list_free(), RZ_OUTPUT_MODE_JSON, rz_type_noreturn_function_names(), and rz_analysis_t::typedb.

Referenced by rz_type_list_noreturn_handler().

◆ rz_core_types_function_print()

RZ_IPI void rz_core_types_function_print ( RzTypeDB typedb,
const char *  function,
RzOutputMode  mode,
PJ pj 
)

Definition at line 472 of file ctypes.c.

472  {
473  rz_return_if_fail(function);
474  RzCallable *callable = rz_type_func_get(typedb, function);
475  if (!callable) {
476  return;
477  }
478  char *ret = callable->ret ? rz_type_as_string(typedb, callable->ret) : NULL;
479  void **it;
480  switch (mode) {
481  case RZ_OUTPUT_MODE_JSON: {
482  rz_return_if_fail(pj);
483  pj_o(pj);
484  pj_ks(pj, "name", function);
485  pj_ks(pj, "ret", ret);
486  pj_k(pj, "args");
487  pj_a(pj);
488  rz_pvector_foreach (callable->args, it) {
489  RzCallableArg *arg = (RzCallableArg *)*it;
490  char *typestr = rz_type_as_string(typedb, arg->type);
491  pj_o(pj);
492  pj_ks(pj, "type", rz_str_get_null(typestr));
493  pj_ks(pj, "name", rz_str_get_null(arg->name));
494  pj_end(pj);
495  free(typestr);
496  }
497  pj_end(pj);
498  pj_end(pj);
499  } break;
500  default: {
501  char *str = rz_type_callable_as_string(typedb, callable);
502  rz_cons_printf("%s;\n", str);
503  free(str);
504  } break;
505  }
506  free(ret);
507 }
static const char * rz_str_get_null(const char *str)
Definition: rz_str.h:190
#define rz_pvector_foreach(vec, it)
Definition: rz_vector.h:334
const char * name
Definition: sparc-opc.c:1838
RzPVector * args
optional for the time being
Definition: rz_type.h:149
RZ_NULLABLE RzType * ret
Definition: rz_type.h:148
RZ_API RZ_BORROW RzCallable * rz_type_func_get(RzTypeDB *typedb, RZ_NONNULL const char *name)
Returns the RzCallable from the database by name.
Definition: function.c:162
RZ_API RZ_OWN char * rz_type_callable_as_string(const RzTypeDB *typedb, RZ_NONNULL const RzCallable *callable)
Returns the callable C representation.
Definition: function.c:487
RZ_API RZ_OWN char * rz_type_as_string(const RzTypeDB *typedb, RZ_NONNULL const RzType *type)
Returns the type C representation.
Definition: type.c:817

References rz_callable_at::args, free(), arg::name, NULL, pj_a(), pj_end(), pj_k(), pj_ks(), pj_o(), rz_callable_at::ret, rz_cons_printf(), RZ_OUTPUT_MODE_JSON, rz_pvector_foreach, rz_return_if_fail, rz_str_get_null(), rz_type_as_string(), rz_type_callable_as_string(), rz_type_func_get(), and cmd_descs_generate::str.

Referenced by rz_core_types_function_print_all(), and rz_type_list_function_handler().

◆ rz_core_types_function_print_all()

RZ_IPI void rz_core_types_function_print_all ( RzCore core,
RzOutputMode  mode 
)

Definition at line 509 of file ctypes.c.

509  {
510  PJ *pj = (mode == RZ_OUTPUT_MODE_JSON) ? pj_new() : NULL;
511  if (mode == RZ_OUTPUT_MODE_JSON) {
512  pj_a(pj);
513  }
515  RzListIter *iter;
516  char *name;
517  rz_list_foreach (l, iter, name) {
519  }
520  rz_list_free(l);
521  if (mode == RZ_OUTPUT_MODE_JSON) {
522  pj_end(pj);
524  pj_free(pj);
525  }
526 }
RZ_IPI void rz_core_types_function_print(RzTypeDB *typedb, const char *function, RzOutputMode mode, PJ *pj)
Definition: ctypes.c:472
const char * name
Definition: op.c:541
RZ_API RZ_OWN RzList * rz_type_function_names(RzTypeDB *typedb)
Returns the list of all function type names.
Definition: function.c:567

References rz_core_t::analysis, name, NULL, pj_a(), pj_end(), pj_free(), pj_new(), pj_string(), rz_cons_println(), rz_core_types_function_print(), rz_list_free(), RZ_OUTPUT_MODE_JSON, rz_type_function_names(), and rz_analysis_t::typedb.

Referenced by rz_type_list_function_handler().

◆ rz_core_types_link()

RZ_API void rz_core_types_link ( RzCore core,
const char *  typestr,
ut64  addr 
)

Link an address addr to the type referenced by typestr.

NOTE: This is likely going to be deprecated with the use of global variables.

Parameters
coreRzCore reference
typestrName of the type that should be defined at addr
addrAddress where the type should be used

Definition at line 954 of file ctypes.c.

954  {
955  char *error_msg = NULL;
956  RzType *type = rz_type_parse_string_single(core->analysis->typedb->parser, typestr, &error_msg);
957  if (!type || error_msg) {
958  if (error_msg) {
959  eprintf("%s", error_msg);
960  }
961  free(error_msg);
962  return;
963  }
965  RzList *fcns = rz_analysis_get_functions_in(core->analysis, core->offset);
966  if (rz_list_length(fcns) > 1) {
967  eprintf("Multiple functions found in here.\n");
968  } else if (rz_list_length(fcns) == 1) {
969  RzAnalysisFunction *fcn = rz_list_first(fcns);
970  rz_core_link_stroff(core, fcn);
971  }
972  rz_list_free(fcns);
973 }
RZ_API RzList * rz_analysis_get_functions_in(RzAnalysis *analysis, ut64 addr)
Definition: function.c:20
RZ_API RZ_OWN RzType * rz_type_parse_string_single(RzTypeParser *parser, const char *code, char **error_msg)
Parses the single C type definition.
Definition: c_cpp_parser.c:309
RZ_API void rz_core_link_stroff(RzCore *core, RzAnalysisFunction *fcn)
Definition: ctypes.c:717
RZ_API RZ_BORROW void * rz_list_first(RZ_NONNULL const RzList *list)
Returns the first element of the list.
Definition: list.c:77
#define eprintf(x, y...)
Definition: rlcc.c:7
RzTypeParser * parser
Definition: rz_type.h:37

References addr, rz_core_t::analysis, coremodepj::core, eprintf, free(), NULL, rz_core_t::offset, rz_type_db_t::parser, rz_analysis_get_functions_in(), rz_analysis_type_set_link(), rz_core_link_stroff(), rz_list_first(), rz_list_free(), rz_list_length(), rz_type_parse_string_single(), type, and rz_analysis_t::typedb.

Referenced by rz_type_link_handler().

◆ rz_core_types_link_print()

RZ_IPI void rz_core_types_link_print ( RzCore core,
RzType type,
ut64  addr,
RzOutputMode  mode,
PJ pj 
)

Definition at line 879 of file ctypes.c.

879  {
881  char *typestr = rz_type_as_string(core->analysis->typedb, type);
882  if (!typestr) {
883  return;
884  }
885  switch (mode) {
886  case RZ_OUTPUT_MODE_JSON: {
887  rz_return_if_fail(pj);
888  pj_o(pj);
889  char *saddr = rz_str_newf("0x%08" PFMT64x, addr);
890  pj_ks(pj, saddr, typestr);
891  pj_end(pj);
892  free(saddr);
893  break;
894  }
896  rz_cons_printf("0x%08" PFMT64x " = %s\n", addr, typestr);
897  break;
899  rz_cons_printf("tl \"%s\" 0x%" PFMT64x "\n", typestr, addr);
900  break;
901  case RZ_OUTPUT_MODE_LONG: {
902  char *fmt = rz_type_as_format(core->analysis->typedb, type);
903  if (!fmt) {
904  eprintf("Can't fint type %s", typestr);
905  }
906  rz_cons_printf("(%s)\n", typestr);
907  rz_core_cmdf(core, "pf %s @ 0x%" PFMT64x "\n", fmt, addr);
908  free(fmt);
909  break;
910  }
911  default:
913  break;
914  }
915  free(typestr);
916 }
RZ_API int rz_core_cmdf(RzCore *core, const char *fmt,...)
Definition: cmd.c:5413
RZ_API RZ_OWN char * rz_type_as_format(const RzTypeDB *typedb, RZ_NONNULL RzType *type)
Represents the RzType as a pf format string.
Definition: format.c:3005
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1

References addr, rz_core_t::analysis, eprintf, free(), PFMT64x, pj_end(), pj_ks(), pj_o(), rz_cons_printf(), rz_core_cmdf(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_LONG, RZ_OUTPUT_MODE_RIZIN, RZ_OUTPUT_MODE_STANDARD, rz_return_if_fail, rz_str_newf(), rz_type_as_format(), rz_type_as_string(), rz_warn_if_reached, type, and rz_analysis_t::typedb.

Referenced by rz_core_types_link_show(), and typelink_print_cb().

◆ rz_core_types_link_print_all()

RZ_IPI void rz_core_types_link_print_all ( RzCore core,
RzOutputMode  mode 
)

Definition at line 931 of file ctypes.c.

931  {
932  PJ *pj = (mode == RZ_OUTPUT_MODE_JSON) ? pj_new() : NULL;
933  if (mode == RZ_OUTPUT_MODE_JSON) {
934  pj_a(pj);
935  }
936  struct coremodepj c = { core, mode, pj };
937  ht_up_foreach(core->analysis->type_links, typelink_print_cb, &c);
938  if (mode == RZ_OUTPUT_MODE_JSON) {
939  pj_end(pj);
941  pj_free(pj);
942  }
943 }
static bool typelink_print_cb(void *user, ut64 k, const void *v)
Definition: ctypes.c:924
#define c(i)
Definition: sha256.c:43
RzCore * core
Definition: ctypes.c:919
PJ * pj
Definition: ctypes.c:921
HtUP * type_links
Definition: rz_analysis.h:603

References rz_core_t::analysis, c, coremodepj::core, NULL, coremodepj::pj, pj_a(), pj_end(), pj_free(), pj_new(), pj_string(), rz_cons_println(), RZ_OUTPUT_MODE_JSON, rz_analysis_t::type_links, and typelink_print_cb().

Referenced by rz_type_link_handler().

◆ rz_core_types_link_show()

RZ_IPI void rz_core_types_link_show ( RzCore core,
ut64  addr 
)

Definition at line 975 of file ctypes.c.

975  {
977  if (link) {
979  }
980 }
RZ_IPI void rz_core_types_link_print(RzCore *core, RzType *type, ut64 addr, RzOutputMode mode, PJ *pj)
Definition: ctypes.c:879
static static fork const void static count static fd link
Definition: sflib.h:33

References addr, rz_core_t::analysis, coremodepj::core, link, NULL, rz_analysis_type_link_at(), rz_core_types_link_print(), and RZ_OUTPUT_MODE_LONG.

Referenced by rz_type_link_show_handler().

◆ rz_core_types_print_all()

RZ_IPI void rz_core_types_print_all ( RzCore core,
RzOutputMode  mode 
)

Definition at line 984 of file ctypes.c.

984  {
985  RzListIter *it;
986  RzBaseType *btype;
988  switch (mode) {
989  case RZ_OUTPUT_MODE_JSON: {
990  PJ *pj = pj_new();
991  if (!pj) {
992  return;
993  }
994  pj_a(pj);
995  rz_list_foreach (types, it, btype) {
996  pj_o(pj);
997  // rz_str_trim(format_s);
998  pj_ks(pj, "type", btype->name);
999  pj_ki(pj, "size", btype->size);
1000  // pj_ks(pj, "format", format_s);
1001  pj_end(pj);
1002  }
1003  pj_end(pj);
1005  pj_free(pj);
1006  break;
1007  }
1009  rz_list_foreach (types, it, btype) {
1010  rz_cons_println(btype->name);
1011  }
1012  break;
1013  case RZ_OUTPUT_MODE_RIZIN:
1014  rz_list_foreach (types, it, btype) {
1015  char *fmt = rz_type_format(core->analysis->typedb, btype->name);
1016  if (fmt) {
1017  rz_cons_printf("pf.%s %s\n", btype->name, fmt);
1018  free(fmt);
1019  }
1020  }
1021  break;
1022  default:
1024  break;
1025  }
1027 }
RZ_API RZ_OWN RzList * rz_type_db_get_base_types(const RzTypeDB *typedb)
Returns the list of all basic types.
Definition: base.c:120
RZ_API RZ_OWN char * rz_type_format(RZ_NONNULL const RzTypeDB *typedb, RZ_NONNULL const char *name)
Represents the RzBaseType as a pf format string.
Definition: format.c:2965
insn_type_descr_t types[]
Definition: or1k_disas.c:7
RZ_API PJ * pj_ki(PJ *j, const char *k, int d)
Definition: pj.c:149

References rz_core_t::analysis, coremodepj::core, free(), rz_base_type_t::name, coremodepj::pj, pj_a(), pj_end(), pj_free(), pj_ki(), pj_ks(), pj_new(), pj_o(), pj_string(), rz_cons_printf(), rz_cons_println(), rz_list_free(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_RIZIN, RZ_OUTPUT_MODE_STANDARD, rz_type_db_get_base_types(), rz_type_format(), rz_warn_if_reached, rz_base_type_t::size, rz_analysis_t::typedb, and types.

Referenced by rz_type_handler().

◆ rz_core_types_show_format()

RZ_IPI void rz_core_types_show_format ( RzCore core,
const char *  name,
RzOutputMode  mode 
)

Definition at line 568 of file ctypes.c.

568  {
569  char *fmt = rz_type_format(core->analysis->typedb, name);
570  if (fmt) {
571  switch (mode) {
572  case RZ_OUTPUT_MODE_JSON: {
573  PJ *pj = pj_new();
574  if (!pj) {
575  free(fmt);
576  return;
577  }
578  pj_o(pj);
579  pj_ks(pj, "name", name);
580  pj_ks(pj, "format", fmt);
581  pj_end(pj);
582  rz_cons_printf("%s", pj_string(pj));
583  pj_free(pj);
584  } break;
585  case RZ_OUTPUT_MODE_RIZIN: {
586  rz_cons_printf("pf.%s %s\n", name, fmt);
587  } break;
589  // FIXME: Not really a standard format
590  // We should think about better representation by default here
591  rz_cons_printf("pf %s\n", fmt);
592  } break;
593  default:
594  break;
595  }
596  free(fmt);
597  } else {
598  eprintf("Cannot find '%s' type\n", name);
599  }
600 }

References rz_core_t::analysis, eprintf, free(), pj_end(), pj_free(), pj_ks(), pj_new(), pj_o(), pj_string(), rz_cons_printf(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_RIZIN, RZ_OUTPUT_MODE_STANDARD, rz_type_format(), and rz_analysis_t::typedb.

Referenced by rz_core_types_struct_print_format_all(), rz_core_types_union_print_format_all(), rz_type_handler(), rz_type_list_structure_handler(), and rz_type_list_union_handler().

◆ rz_core_types_struct_as_c()

RZ_IPI RZ_OWN char* rz_core_types_struct_as_c ( RzTypeDB typedb,
const RzBaseType btype,
bool  multiline 
)

◆ rz_core_types_struct_as_c_all()

RZ_IPI RZ_OWN char* rz_core_types_struct_as_c_all ( RzTypeDB typedb,
bool  multiline 
)

Definition at line 320 of file ctypes.c.

320  {
322  RzListIter *it;
323  RzBaseType *btype;
324  RzStrBuf *buf = rz_strbuf_new("");
325  rz_list_foreach (structlist, it, btype) {
326  char *str = rz_core_types_struct_as_c(typedb, btype, multiline);
327  if (str) {
329  }
330  free(str);
331  }
332  rz_list_free(structlist);
333  return rz_strbuf_drain(buf);
334 }
RZ_IPI RZ_OWN char * rz_core_types_struct_as_c(RzTypeDB *typedb, const RzBaseType *btype, bool multiline)
Definition: ctypes.c:312

References free(), RZ_BASE_TYPE_KIND_STRUCT, rz_core_types_struct_as_c(), rz_list_free(), rz_strbuf_append(), rz_strbuf_drain(), rz_strbuf_new(), rz_type_db_get_base_types_of_kind(), and cmd_descs_generate::str.

Referenced by rz_core_types_as_c_all(), rz_type_structure_c_handler(), and rz_type_structure_c_nl_handler().

◆ rz_core_types_struct_print()

RZ_IPI void rz_core_types_struct_print ( RzCore core,
const RzBaseType btype,
RzOutputMode  mode,
PJ pj 
)

Definition at line 246 of file ctypes.c.

246  {
247  rz_return_if_fail(core && btype);
249 
250  switch (mode) {
251  case RZ_OUTPUT_MODE_JSON: {
252  rz_return_if_fail(pj);
253  pj_o(pj);
254  pj_ks(pj, "name", btype->name);
255  pj_k(pj, "members");
256  pj_o(pj);
257  RzTypeStructMember *memb;
258  rz_vector_foreach(&btype->struct_data.members, memb) {
259  char *mtype = rz_type_as_string(core->analysis->typedb, memb->type);
260  pj_ks(pj, memb->name, mtype);
261  free(mtype);
262  }
263  pj_end(pj);
264  pj_end(pj);
265  break;
266  }
267  case RZ_OUTPUT_MODE_LONG: {
268  rz_cons_printf("struct %s:\n", btype->name);
269  if (btype && !rz_vector_empty(&btype->union_data.members)) {
270  RzTypeStructMember *memb;
271  ut64 offset = 0;
272  rz_vector_foreach(&btype->struct_data.members, memb) {
273  char *mtype = rz_type_as_string(core->analysis->typedb, memb->type);
274  ut64 size = rz_type_db_get_bitsize(core->analysis->typedb, memb->type) / 8;
275  rz_cons_printf("\t%s: %s (size = %" PFMT64d ", offset = %" PFMT64d ")\n",
276  memb->name, mtype, size, offset);
277  offset += size;
278  free(mtype);
279  }
280  }
281  break;
282  }
285  rz_cons_println(btype->name);
286  break;
287  default:
289  break;
290  }
291 }
voidpf void uLong size
Definition: ioapi.h:138
voidpf uLong offset
Definition: ioapi.h:144
#define PFMT64d
Definition: rz_types.h:394
RzBaseTypeStruct struct_data
Definition: rz_type.h:118
RzBaseTypeUnion union_data
Definition: rz_type.h:120
RzVector members
Definition: rz_type.h:104
RZ_API ut64 rz_type_db_get_bitsize(const RzTypeDB *typedb, RZ_NONNULL RzType *type)
Returns the type size in bits (target dependent)
Definition: type.c:779

References rz_core_t::analysis, free(), rz_base_type_t::kind, rz_base_type_struct_t::members, rz_base_type_union_t::members, rz_type_struct_member_t::name, rz_base_type_t::name, PFMT64d, pj_end(), pj_k(), pj_ks(), pj_o(), RZ_BASE_TYPE_KIND_STRUCT, rz_cons_printf(), rz_cons_println(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_LONG, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_STANDARD, rz_return_if_fail, rz_type_as_string(), rz_type_db_get_bitsize(), rz_vector_empty(), rz_vector_foreach, rz_warn_if_reached, rz_base_type_t::struct_data, rz_type_struct_member_t::type, rz_analysis_t::typedb, rz_base_type_t::union_data, and ut64().

Referenced by rz_core_types_struct_print_all(), and rz_type_list_structure_handler().

◆ rz_core_types_struct_print_all()

RZ_IPI void rz_core_types_struct_print_all ( RzCore core,
RzOutputMode  mode 
)

Definition at line 293 of file ctypes.c.

293  {
295  RzListIter *it;
296  PJ *pj = (mode == RZ_OUTPUT_MODE_JSON) ? pj_new() : NULL;
297  if (mode == RZ_OUTPUT_MODE_JSON) {
298  pj_a(pj);
299  }
300  RzBaseType *btype;
301  rz_list_foreach (structlist, it, btype) {
302  rz_core_types_struct_print(core, btype, mode, pj);
303  }
304  rz_list_free(structlist);
305  if (mode == RZ_OUTPUT_MODE_JSON) {
306  pj_end(pj);
308  pj_free(pj);
309  }
310 }
RZ_IPI void rz_core_types_struct_print(RzCore *core, const RzBaseType *btype, RzOutputMode mode, PJ *pj)
Definition: ctypes.c:246

References rz_core_t::analysis, NULL, pj_a(), pj_end(), pj_free(), pj_new(), pj_string(), RZ_BASE_TYPE_KIND_STRUCT, rz_cons_println(), rz_core_types_struct_print(), rz_list_free(), RZ_OUTPUT_MODE_JSON, rz_type_db_get_base_types_of_kind(), and rz_analysis_t::typedb.

Referenced by rz_type_list_structure_handler().

◆ rz_core_types_struct_print_format_all()

RZ_IPI void rz_core_types_struct_print_format_all ( RzCore core)

Definition at line 602 of file ctypes.c.

602  {
603  RzTypeDB *typedb = core->analysis->typedb;
605  RzListIter *it;
606  RzBaseType *btype;
607  rz_list_foreach (structlist, it, btype) {
609  }
610  rz_list_free(structlist);
611 }
RZ_IPI void rz_core_types_show_format(RzCore *core, const char *name, RzOutputMode mode)
Definition: ctypes.c:568

References rz_core_t::analysis, rz_base_type_t::name, RZ_BASE_TYPE_KIND_STRUCT, rz_core_types_show_format(), rz_list_free(), RZ_OUTPUT_MODE_RIZIN, rz_type_db_get_base_types_of_kind(), and rz_analysis_t::typedb.

Referenced by rz_type_list_structure_handler().

◆ rz_core_types_typedef_as_c()

◆ rz_core_types_typedef_as_c_all()

RZ_IPI RZ_OWN char* rz_core_types_typedef_as_c_all ( RzTypeDB typedb)

Definition at line 392 of file ctypes.c.

392  {
394  RzListIter *it;
395  RzBaseType *btype;
396  RzStrBuf *buf = rz_strbuf_new("");
397  rz_list_foreach (typedeflist, it, btype) {
398  char *str = rz_core_types_typedef_as_c(typedb, btype);
399  if (str) {
401  }
402  free(str);
403  }
404  rz_list_free(typedeflist);
405  return rz_strbuf_drain(buf);
406 }
RZ_IPI RZ_OWN char * rz_core_types_typedef_as_c(RzTypeDB *typedb, const RzBaseType *btype)
Definition: ctypes.c:385

References free(), RZ_BASE_TYPE_KIND_TYPEDEF, rz_core_types_typedef_as_c(), rz_list_free(), rz_strbuf_append(), rz_strbuf_drain(), rz_strbuf_new(), rz_type_db_get_base_types_of_kind(), and cmd_descs_generate::str.

Referenced by rz_core_types_as_c_all(), and rz_type_typedef_c_handler().

◆ rz_core_types_typedef_print()

RZ_IPI void rz_core_types_typedef_print ( RzCore core,
const RzBaseType btype,
RzOutputMode  mode,
PJ pj 
)

Definition at line 338 of file ctypes.c.

338  {
339  rz_return_if_fail(core && btype);
341 
342  char *typestr = rz_type_as_string(core->analysis->typedb, btype->type);
343  switch (mode) {
344  case RZ_OUTPUT_MODE_JSON: {
345  rz_return_if_fail(pj);
346  pj_o(pj);
347  pj_ks(pj, "name", btype->name);
348  pj_ks(pj, "type", typestr);
349  pj_end(pj);
350  break;
351  }
353  rz_cons_printf("%s = %s\n", btype->name, typestr);
354  break;
355  }
357  rz_cons_println(btype->name);
358  break;
359  default:
361  break;
362  }
363  free(typestr);
364 }
RzType * type
Definition: rz_type.h:113

References rz_core_t::analysis, free(), rz_base_type_t::kind, rz_base_type_t::name, pj_end(), pj_ks(), pj_o(), RZ_BASE_TYPE_KIND_TYPEDEF, rz_cons_printf(), rz_cons_println(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_STANDARD, rz_return_if_fail, rz_type_as_string(), rz_warn_if_reached, rz_base_type_t::type, and rz_analysis_t::typedb.

Referenced by rz_core_types_typedef_print_all(), and rz_type_list_typedef_handler().

◆ rz_core_types_typedef_print_all()

RZ_IPI void rz_core_types_typedef_print_all ( RzCore core,
RzOutputMode  mode 
)

Definition at line 366 of file ctypes.c.

366  {
368  RzListIter *it;
369  PJ *pj = (mode == RZ_OUTPUT_MODE_JSON) ? pj_new() : NULL;
370  if (mode == RZ_OUTPUT_MODE_JSON) {
371  pj_a(pj);
372  }
373  RzBaseType *btype;
374  rz_list_foreach (typedeflist, it, btype) {
375  rz_core_types_typedef_print(core, btype, mode, pj);
376  }
377  rz_list_free(typedeflist);
378  if (mode == RZ_OUTPUT_MODE_JSON) {
379  pj_end(pj);
381  pj_free(pj);
382  }
383 }
RZ_IPI void rz_core_types_typedef_print(RzCore *core, const RzBaseType *btype, RzOutputMode mode, PJ *pj)
Definition: ctypes.c:338

References rz_core_t::analysis, NULL, pj_a(), pj_end(), pj_free(), pj_new(), pj_string(), RZ_BASE_TYPE_KIND_TYPEDEF, rz_cons_println(), rz_core_types_typedef_print(), rz_list_free(), RZ_OUTPUT_MODE_JSON, rz_type_db_get_base_types_of_kind(), and rz_analysis_t::typedb.

Referenced by rz_type_list_typedef_handler().

◆ rz_core_types_union_as_c()

RZ_IPI RZ_OWN char* rz_core_types_union_as_c ( RzTypeDB typedb,
const RzBaseType btype,
bool  multiline 
)

Definition at line 217 of file ctypes.c.

217  {
218  rz_return_val_if_fail(btype, NULL);
220 
221  unsigned int multiline_opt = 0;
222  if (multiline) {
223  multiline_opt = RZ_TYPE_PRINT_MULTILINE;
224  }
226 }
@ RZ_BASE_TYPE_KIND_UNION
Definition: rz_type.h:74

References rz_base_type_t::kind, NULL, RZ_BASE_TYPE_KIND_UNION, rz_return_val_if_fail, rz_type_db_base_type_as_pretty_string(), RZ_TYPE_PRINT_ANONYMOUS, RZ_TYPE_PRINT_END_NEWLINE, and RZ_TYPE_PRINT_MULTILINE.

Referenced by rz_core_types_union_as_c_all(), rz_type_union_c_handler(), and rz_type_union_c_nl_handler().

◆ rz_core_types_union_as_c_all()

RZ_IPI RZ_OWN char* rz_core_types_union_as_c_all ( RzTypeDB typedb,
bool  multiline 
)

Definition at line 228 of file ctypes.c.

228  {
230  RzListIter *it;
231  RzBaseType *btype;
232  RzStrBuf *buf = rz_strbuf_new("");
233  rz_list_foreach (unionlist, it, btype) {
234  char *str = rz_core_types_union_as_c(typedb, btype, multiline);
235  if (str) {
237  }
238  free(str);
239  }
240  rz_list_free(unionlist);
241  return rz_strbuf_drain(buf);
242 }
RZ_IPI RZ_OWN char * rz_core_types_union_as_c(RzTypeDB *typedb, const RzBaseType *btype, bool multiline)
Definition: ctypes.c:217

References free(), RZ_BASE_TYPE_KIND_UNION, rz_core_types_union_as_c(), rz_list_free(), rz_strbuf_append(), rz_strbuf_drain(), rz_strbuf_new(), rz_type_db_get_base_types_of_kind(), and cmd_descs_generate::str.

Referenced by rz_core_types_as_c_all(), rz_type_union_c_handler(), and rz_type_union_c_nl_handler().

◆ rz_core_types_union_print()

RZ_IPI void rz_core_types_union_print ( RzCore core,
const RzBaseType btype,
RzOutputMode  mode,
PJ pj 
)

Definition at line 152 of file ctypes.c.

152  {
153  rz_return_if_fail(core && btype);
155 
156  switch (mode) {
157  case RZ_OUTPUT_MODE_JSON: {
158  rz_return_if_fail(pj);
159  pj_o(pj);
160  if (btype && !rz_vector_empty(&btype->union_data.members)) {
161  pj_ks(pj, "name", btype->name);
162  pj_k(pj, "members");
163  pj_o(pj);
164  RzTypeUnionMember *memb;
165  rz_vector_foreach(&btype->union_data.members, memb) {
166  char *mtype = rz_type_as_string(core->analysis->typedb, memb->type);
167  pj_ks(pj, memb->name, mtype);
168  free(mtype);
169  }
170  pj_end(pj);
171  }
172  pj_end(pj);
173  break;
174  }
175  case RZ_OUTPUT_MODE_LONG: {
176  rz_cons_printf("union %s:\n", btype->name);
177  if (btype && !rz_vector_empty(&btype->union_data.members)) {
178  RzTypeUnionMember *memb;
179  rz_vector_foreach(&btype->union_data.members, memb) {
180  char *mtype = rz_type_as_string(core->analysis->typedb, memb->type);
181  ut64 size = rz_type_db_get_bitsize(core->analysis->typedb, memb->type) / 8;
182  rz_cons_printf("\t%s: %s (size = %" PFMT64d ")\n", memb->name, mtype, size);
183  free(mtype);
184  }
185  }
186  break;
187  }
190  rz_cons_println(btype->name);
191  break;
192  default:
194  break;
195  }
196 }

References rz_core_t::analysis, free(), rz_base_type_t::kind, rz_base_type_union_t::members, rz_type_union_member_t::name, rz_base_type_t::name, PFMT64d, pj_end(), pj_k(), pj_ks(), pj_o(), RZ_BASE_TYPE_KIND_UNION, rz_cons_printf(), rz_cons_println(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_LONG, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_STANDARD, rz_return_if_fail, rz_type_as_string(), rz_type_db_get_bitsize(), rz_vector_empty(), rz_vector_foreach, rz_warn_if_reached, rz_type_union_member_t::type, rz_analysis_t::typedb, rz_base_type_t::union_data, and ut64().

Referenced by rz_core_types_union_print_all(), and rz_type_list_union_handler().

◆ rz_core_types_union_print_all()

RZ_IPI void rz_core_types_union_print_all ( RzCore core,
RzOutputMode  mode 
)

Definition at line 198 of file ctypes.c.

198  {
200  RzListIter *it;
201  PJ *pj = (mode == RZ_OUTPUT_MODE_JSON) ? pj_new() : NULL;
202  if (mode == RZ_OUTPUT_MODE_JSON) {
203  pj_a(pj);
204  }
205  RzBaseType *btype;
206  rz_list_foreach (unionlist, it, btype) {
207  rz_core_types_union_print(core, btype, mode, pj);
208  }
209  rz_list_free(unionlist);
210  if (mode == RZ_OUTPUT_MODE_JSON) {
211  pj_end(pj);
213  pj_free(pj);
214  }
215 }
RZ_IPI void rz_core_types_union_print(RzCore *core, const RzBaseType *btype, RzOutputMode mode, PJ *pj)
Definition: ctypes.c:152

References rz_core_t::analysis, NULL, pj_a(), pj_end(), pj_free(), pj_new(), pj_string(), RZ_BASE_TYPE_KIND_UNION, rz_cons_println(), rz_core_types_union_print(), rz_list_free(), RZ_OUTPUT_MODE_JSON, rz_type_db_get_base_types_of_kind(), and rz_analysis_t::typedb.

Referenced by rz_type_list_union_handler().

◆ rz_core_types_union_print_format_all()

RZ_IPI void rz_core_types_union_print_format_all ( RzCore core)

Definition at line 613 of file ctypes.c.

613  {
614  RzTypeDB *typedb = core->analysis->typedb;
616  RzListIter *it;
617  RzBaseType *btype;
618  rz_list_foreach (unionlist, it, btype) {
620  }
621  rz_list_free(unionlist);
622 }

References rz_core_t::analysis, rz_base_type_t::name, RZ_BASE_TYPE_KIND_UNION, rz_core_types_show_format(), rz_list_free(), RZ_OUTPUT_MODE_RIZIN, rz_type_db_get_base_types_of_kind(), and rz_analysis_t::typedb.

Referenced by rz_type_list_union_handler().

◆ rz_types_define()

RZ_IPI void rz_types_define ( RzCore core,
const char *  type 
)

Definition at line 1029 of file ctypes.c.

1029  {
1030  // Add trailing semicolon to force the valid C syntax
1031  // It allows us to skip the trailing semicolon in the input
1032  // to reduce the unnecessary typing
1033  char *tmp = rz_str_newf("%s;", type);
1034  if (!tmp) {
1035  return;
1036  }
1037  char *error_msg = NULL;
1038  RzTypeDB *typedb = core->analysis->typedb;
1039  int result = rz_type_parse_string_stateless(typedb->parser, tmp, &error_msg);
1040  if (result && error_msg) {
1041  eprintf("%s", error_msg);
1042  free(error_msg);
1043  }
1044 }
RZ_API int rz_type_parse_string_stateless(RzTypeParser *parser, const char *code, char **error_msg)
Parses the C type string reusing the existing parser state.
Definition: c_cpp_parser.c:227

References rz_core_t::analysis, coremodepj::core, eprintf, free(), NULL, rz_type_db_t::parser, rz_str_newf(), rz_type_parse_string_stateless(), autogen_x86imm::tmp, type, and rz_analysis_t::typedb.

Referenced by rz_type_define_handler().

◆ rz_types_open_editor()

RZ_IPI bool rz_types_open_editor ( RzCore core,
RZ_NONNULL const char *  name 
)

Definition at line 1075 of file ctypes.c.

1075  {
1076  rz_return_val_if_fail(name, false);
1077  RzTypeDB *typedb = core->analysis->typedb;
1079  if (!t) {
1080  return false;
1081  }
1082  char *str = rz_core_base_type_as_c(core, t, true);
1083  if (!str) {
1084  RZ_LOG_ERROR("Cannot generate C representation of type \"%s\"\n", name);
1085  return false;
1086  }
1087  bool result = false;
1088  char *tmp = rz_core_editor(core, NULL, str);
1089  if (tmp) {
1090  result = rz_type_db_edit_base_type(typedb, t->name, tmp);
1091  free(tmp);
1092  }
1093  free(str);
1094  return result;
1095 }
RZ_API RZ_BORROW RzBaseType * rz_type_db_get_compound_type(const RzTypeDB *typedb, RZ_NONNULL const char *name)
Searches for the compound RzBaseType in the types database given the name.
Definition: base.c:234
RZ_API RZ_OWN char * rz_core_editor(const RzCore *core, RZ_NULLABLE const char *file, RZ_NULLABLE const char *str)
Definition: core.c:3214
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API bool rz_type_db_edit_base_type(RzTypeDB *typedb, RZ_NONNULL const char *name, RZ_NONNULL const char *typestr)
Edits the existing base type given the new C code.
Definition: type.c:1305

References rz_core_t::analysis, coremodepj::core, free(), rz_base_type_t::name, NULL, rz_core_base_type_as_c(), rz_core_editor(), RZ_LOG_ERROR, rz_return_val_if_fail, rz_type_db_edit_base_type(), rz_type_db_get_compound_type(), cmd_descs_generate::str, autogen_x86imm::tmp, and rz_analysis_t::typedb.

Referenced by rz_type_open_editor_handler().

◆ rz_types_open_file()

RZ_IPI bool rz_types_open_file ( RzCore core,
const char *  path 
)

Definition at line 1046 of file ctypes.c.

1046  {
1047  const char *dir = rz_config_get(core->config, "dir.types");
1048  RzTypeDB *typedb = core->analysis->typedb;
1049  if (!strcmp(path, "-")) {
1050  char *tmp = rz_core_editor(core, "*.h", "");
1051  if (tmp) {
1052  char *error_msg = NULL;
1053  int result = rz_type_parse_string_stateless(typedb->parser, tmp, &error_msg);
1054  if (result && error_msg) {
1055  RZ_LOG_ERROR("%s", error_msg);
1056  free(error_msg);
1057  }
1058  free(tmp);
1059  }
1060  } else {
1061  if (!rz_file_exists(path)) {
1062  RZ_LOG_ERROR("File \"%s\" does not exist\n", path);
1063  return false;
1064  }
1065  char *error_msg = NULL;
1066  int result = rz_type_parse_file_stateless(typedb->parser, path, dir, &error_msg);
1067  if (result && error_msg) {
1068  RZ_LOG_ERROR("%s", error_msg);
1069  free(error_msg);
1070  }
1071  }
1072  return true;
1073 }
RZ_API int rz_type_parse_file_stateless(RzTypeParser *parser, const char *path, const char *dir, char **error_msg)
Parses the C types file reusing the existing parser state.
Definition: c_cpp_parser.c:239
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:75
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
RZ_API bool rz_file_exists(const char *str)
Definition: file.c:192

References rz_core_t::analysis, rz_core_t::config, coremodepj::core, free(), NULL, rz_type_db_t::parser, path, rz_config_get(), rz_core_editor(), rz_file_exists(), RZ_LOG_ERROR, rz_type_parse_file_stateless(), rz_type_parse_string_stateless(), autogen_x86imm::tmp, and rz_analysis_t::typedb.

Referenced by rz_type_open_file_handler().

◆ set_offset_hint()

static void set_offset_hint ( RzCore core,
RzAnalysisOp op,
RZ_BORROW RzTypePath tpath,
ut64  laddr,
ut64  at,
int  offimm 
)
static

Definition at line 650 of file ctypes.c.

650  {
651  rz_return_if_fail(core && op && tpath);
652  if (tpath->typ->kind != RZ_TYPE_KIND_IDENTIFIER) {
653  return;
654  }
655  char *cmt = (offimm == 0) ? strdup(tpath->path) : rz_type_as_string(core->analysis->typedb, tpath->typ);
656  if (offimm > 0) {
657  // Set only the type path as the analysis hint
658  // only and only if the types are the exact match between
659  // possible member offset and the type linked to the laddr
660  RzList *paths = rz_analysis_type_paths_by_address(core->analysis, laddr + offimm);
661  if (paths && rz_list_length(paths)) {
662  RzTypePath *link = rz_list_get_top(paths);
663  rz_analysis_hint_set_offset(core->analysis, at, link->path);
664  }
665  } else if (cmt && rz_analysis_op_ismemref(op->type)) {
667  }
668  free(cmt);
669 }
RZ_API void rz_analysis_hint_set_offset(RzAnalysis *a, ut64 addr, const char *typeoff)
Definition: hint.c:203
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
RZ_API bool rz_meta_set_string(RzAnalysis *a, RzAnalysisMetaType type, ut64 addr, const char *s)
Definition: meta.c:141
RZ_API bool rz_analysis_op_ismemref(int t)
Definition: op.c:208
@ RZ_META_TYPE_VARTYPE
Definition: rz_analysis.h:297
Definition: dis.c:32

References rz_core_t::analysis, free(), link, rz_analysis_hint_set_offset(), rz_analysis_op_ismemref(), rz_analysis_type_paths_by_address(), rz_list_get_top(), rz_list_length(), rz_meta_set_string(), RZ_META_TYPE_VARTYPE, rz_return_if_fail, rz_type_as_string(), RZ_TYPE_KIND_IDENTIFIER, strdup(), and rz_analysis_t::typedb.

Referenced by resolve_type_links().

◆ set_retval()

static void set_retval ( RzCore core,
ut64  at 
)
static

Definition at line 626 of file ctypes.c.

626  {
627  RzAnalysis *analysis = core->analysis;
628  RzAnalysisHint *hint = rz_analysis_hint_get(analysis, at);
629  RzAnalysisFunction *fcn = rz_analysis_get_fcn_in(analysis, at, 0);
630 
631  if (!hint || !fcn || !fcn->name) {
632  goto beach;
633  }
634  if (hint->ret == UT64_MAX) {
635  goto beach;
636  }
637  const char *cc = rz_analysis_cc_func(core->analysis, fcn->name);
638  const char *regname = rz_analysis_cc_ret(analysis, cc);
639  if (regname) {
640  RzRegItem *reg = rz_reg_get(analysis->reg, regname, -1);
641  if (reg) {
642  rz_reg_set_value(analysis->reg, reg, hint->ret);
643  }
644  }
645 beach:
646  rz_analysis_hint_free(hint);
647  return;
648 }
RZ_API const char * rz_analysis_cc_func(RzAnalysis *analysis, const char *func_name)
Definition: cc.c:220
RZ_API const char * rz_analysis_cc_ret(RzAnalysis *analysis, const char *convention)
Definition: cc.c:194
RZ_DEPRECATE RZ_API RzAnalysisFunction * rz_analysis_get_fcn_in(RzAnalysis *analysis, ut64 addr, int type)
Definition: fcn.c:1687
RZ_API RzAnalysisHint * rz_analysis_hint_get(RzAnalysis *a, ut64 addr)
Definition: hint.c:506
RZ_API void rz_analysis_hint_free(RzAnalysisHint *h)
Definition: hint.c:371
#define reg(n)
static char * regname(int reg)
Definition: dis.c:71

References rz_core_t::analysis, rz_analysis_function_t::name, reg, rz_analysis_t::reg, regname(), rz_analysis_hint_t::ret, rz_analysis_cc_func(), rz_analysis_cc_ret(), rz_analysis_get_fcn_in(), rz_analysis_hint_free(), rz_analysis_hint_get(), rz_reg_get(), rz_reg_set_value(), and UT64_MAX.

Referenced by rz_core_link_stroff().

◆ typelink_print_cb()

static bool typelink_print_cb ( void *  user,
ut64  k,
const void *  v 
)
static

Definition at line 924 of file ctypes.c.

924  {
925  rz_return_val_if_fail(user && v, false);
926  struct coremodepj *c = user;
927  rz_core_types_link_print(c->core, (RzType *)v, k, c->mode, c->pj);
928  return true;
929 }
const char * k
Definition: dsignal.c:11
const char * v
Definition: dsignal.c:12

References c, k, rz_core_types_link_print(), rz_return_val_if_fail, and v.

Referenced by rz_core_types_link_print_all().