Rizin
unix-like reverse engineering framework and cli tools
serialize_typelink.c File Reference
#include <rz_util/rz_serialize.h>
#include <rz_list.h>
#include <rz_vector.h>
#include <rz_analysis.h>
#include <sdb.h>

Go to the source code of this file.

Classes

struct  analysis_sdb
 

Functions

static bool typelinks_load_sdb (RzAnalysis *analysis, Sdb *sdb)
 
static void save_typelink (const RzAnalysis *analysis, Sdb *sdb, const RzType *type, ut64 addr)
 
static bool export_typelink_cb (void *user, ut64 k, const void *v)
 
static bool typelinks_export_sdb (RZ_NONNULL Sdb *db, RZ_NONNULL const RzAnalysis *analysis)
 
RZ_API void rz_serialize_typelinks_save (RZ_NONNULL Sdb *db, RZ_NONNULL const RzAnalysis *analysis)
 Saves the type links into SDB. More...
 
RZ_API bool rz_serialize_typelinks_load (RZ_NONNULL Sdb *db, RZ_NONNULL RzAnalysis *analysis, RZ_NULLABLE RzSerializeResultInfo *res)
 Loads the type links from SDB. More...
 

Function Documentation

◆ export_typelink_cb()

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

Definition at line 48 of file serialize_typelink.c.

48  {
49  struct analysis_sdb *s = user;
50  RzType *type = (RzType *)v;
51  save_typelink(s->analysis, s->sdb, type, k);
52  return true;
53 }
const char * k
Definition: dsignal.c:11
const char * v
Definition: dsignal.c:12
int type
Definition: mipsasm.c:17
static RzSocket * s
Definition: rtr.c:28

References k, s, save_typelink(), type, and v.

Referenced by typelinks_export_sdb().

◆ rz_serialize_typelinks_load()

RZ_API bool rz_serialize_typelinks_load ( RZ_NONNULL Sdb db,
RZ_NONNULL RzAnalysis analysis,
RZ_NULLABLE RzSerializeResultInfo res 
)

Loads the type links from SDB.

Parameters
dbA SDB database object
analysisRzAnalysis instance
resA structure where the result is stored

Definition at line 80 of file serialize_typelink.c.

80  {
81  rz_return_val_if_fail(db && analysis, false);
82  return typelinks_load_sdb(analysis, db);
83 }
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108

References analysis_sdb::analysis, rz_return_val_if_fail, and typelinks_load_sdb().

Referenced by rz_serialize_analysis_typelinks_load().

◆ rz_serialize_typelinks_save()

RZ_API void rz_serialize_typelinks_save ( RZ_NONNULL Sdb db,
RZ_NONNULL const RzAnalysis analysis 
)

Saves the type links into SDB.

Parameters
dbA SDB database object
analysisRzAnalysis instance

Definition at line 68 of file serialize_typelink.c.

68  {
69  rz_return_if_fail(db && analysis);
70  typelinks_export_sdb(db, analysis);
71 }
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100

References analysis_sdb::analysis, rz_return_if_fail, and typelinks_export_sdb().

Referenced by rz_serialize_analysis_typelinks_save().

◆ save_typelink()

static void save_typelink ( const RzAnalysis analysis,
Sdb sdb,
const RzType type,
ut64  addr 
)
static

Definition at line 30 of file serialize_typelink.c.

30  {
31  rz_return_if_fail(analysis && sdb && type);
32  /*
33  Sdb:
34  addr=type
35  */
36 
37  // addr=type
38  char *key = rz_str_newf("0x%08" PFMT64x, addr);
39  char *type_str = rz_type_as_string(analysis->typedb, type);
40  sdb_set(sdb, key, type_str, 0);
41 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len key
Definition: sflib.h:118
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define PFMT64x
Definition: rz_types.h:393
RZ_API int sdb_set(Sdb *s, const char *key, const char *val, ut32 cas)
Definition: sdb.c:611
RzTypeDB * typedb
Definition: rz_analysis.h:602
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
static int addr
Definition: z80asm.c:58

References addr, key, PFMT64x, rz_return_if_fail, rz_str_newf(), rz_type_as_string(), sdb_set(), type, and rz_analysis_t::typedb.

Referenced by export_typelink_cb().

◆ typelinks_export_sdb()

static bool typelinks_export_sdb ( RZ_NONNULL Sdb db,
RZ_NONNULL const RzAnalysis analysis 
)
static

Definition at line 55 of file serialize_typelink.c.

55  {
56  rz_return_val_if_fail(db && analysis, false);
57  struct analysis_sdb tdb = { analysis, db };
58  ht_up_foreach(analysis->type_links, export_typelink_cb, &tdb);
59  return true;
60 }
const RzAnalysis * analysis
HtUP * type_links
Definition: rz_analysis.h:603

References analysis_sdb::analysis, export_typelink_cb(), rz_return_val_if_fail, and rz_analysis_t::type_links.

Referenced by rz_serialize_typelinks_save().

◆ typelinks_load_sdb()

static bool typelinks_load_sdb ( RzAnalysis analysis,
Sdb sdb 
)
static

Definition at line 10 of file serialize_typelink.c.

10  {
11  rz_return_val_if_fail(analysis && sdb, false);
12  RzType *type;
13  SdbKv *kv;
15  SdbList *l = sdb_foreach_list(sdb, false);
16  ls_foreach (l, iter, kv) {
18  if (addr > 0) {
19  char *error_msg = NULL;
20  type = rz_type_parse_string_single(analysis->typedb->parser, sdbkv_value(kv), &error_msg);
21  if (type) {
22  ht_up_insert(analysis->type_links, addr, type);
23  }
24  free(error_msg);
25  }
26  }
27  return true;
28 }
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
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
#define ls_foreach(list, it, pos)
Definition: ls.h:31
RZ_API ut64 rz_num_get(RzNum *num, const char *str)
Definition: unum.c:172
RZ_API SdbList * sdb_foreach_list(Sdb *s, bool sorted)
Definition: sdb.c:630
static char * sdbkv_key(const SdbKv *kv)
Definition: sdbht.h:21
static char * sdbkv_value(const SdbKv *kv)
Definition: sdbht.h:25
Definition: ls.h:17
Definition: ls.h:22
RzTypeParser * parser
Definition: rz_type.h:37
Definition: sdbht.h:14
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References addr, free(), ls_foreach, NULL, rz_type_db_t::parser, rz_num_get(), rz_return_val_if_fail, rz_type_parse_string_single(), sdb_foreach_list(), sdbkv_key(), sdbkv_value(), type, rz_analysis_t::type_links, rz_analysis_t::typedb, and ut64().

Referenced by rz_serialize_typelinks_load().