Rizin
unix-like reverse engineering framework and cli tools
platform_target_index.c File Reference
#include <rz_platform.h>
#include <string.h>

Go to the source code of this file.

Functions

RZ_API RZ_OWN RzPlatformItemrz_platform_item_new (RZ_NULLABLE const char *name)
 Creates a new RzPlatformItem type. More...
 
RZ_API RZ_OWN RzPlatformTargetIndexrz_platform_target_index_new ()
 Creates a new RzPlatformTargetIndex type. More...
 
RZ_API void rz_platform_target_index_free (RzPlatformTargetIndex *target)
 Frees an RzPlatformTargetIndex type. More...
 
RZ_API void rz_platform_item_free (RzPlatformItem *item)
 Frees an RzPlatformItem type. More...
 
static bool sdb_load_platform_profile (RZ_NONNULL RzPlatformTargetIndex *t, RZ_NONNULL Sdb *sdb)
 
static bool sdb_load_arch_platform_by_path (RZ_NONNULL RzPlatformTargetIndex *t, RZ_NONNULL const char *path)
 
RZ_API bool rz_platform_target_index_load_sdb (RZ_NONNULL RzPlatformTargetIndex *t, RZ_NONNULL const char *path)
 Loads the contents of the Platform Profile to the RzPlatformTargetIndex. More...
 
RZ_API bool rz_platform_target_index_init (RzPlatformTargetIndex *t, RZ_NONNULL const char *arch, RZ_NONNULL const char *cpu, const char *platform, RZ_NONNULL const char *platforms_dir)
 Initialize Platform Profiles by setting the path to the corresponding SDB file. More...
 

Function Documentation

◆ rz_platform_item_free()

RZ_API void rz_platform_item_free ( RzPlatformItem item)

Frees an RzPlatformItem type.

Definition at line 51 of file platform_target_index.c.

51  {
52  if (!item) {
53  return;
54  }
55  free(item->name);
56  free(item->comment);
57  free(item);
58 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130

References rz_platform_item_t::comment, free(), and rz_platform_item_t::name.

Referenced by sdb_load_platform_profile().

◆ rz_platform_item_new()

RZ_API RZ_OWN RzPlatformItem* rz_platform_item_new ( RZ_NULLABLE const char *  name)

Creates a new RzPlatformItem type.

Definition at line 10 of file platform_target_index.c.

10  {
12  if (!item) {
13  return NULL;
14  }
15  item->name = name ? strdup(name) : NULL;
16  item->comment = NULL;
17  return item;
18 }
#define NULL
Definition: cris-opc.c:27
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")
#define RZ_NEW0(x)
Definition: rz_types.h:284
Definition: z80asm.h:102

References rz_platform_item_t::comment, rz_platform_item_t::name, NULL, RZ_NEW0, and strdup().

Referenced by sdb_load_platform_profile().

◆ rz_platform_target_index_free()

RZ_API void rz_platform_target_index_free ( RzPlatformTargetIndex target)

Frees an RzPlatformTargetIndex type.

Definition at line 39 of file platform_target_index.c.

39  {
40  if (!target) {
41  return;
42  }
43  ht_up_free(target->platforms);
44  free(target->path);
45  free(target);
46 }
char * path
Path used to load the platforms, used to avoid reloading.
Definition: rz_platform.h:44

References free(), rz_platform_target_index_t::path, and rz_platform_target_index_t::platforms.

Referenced by rz_analysis_free().

◆ rz_platform_target_index_init()

RZ_API bool rz_platform_target_index_init ( RzPlatformTargetIndex t,
RZ_NONNULL const char *  arch,
RZ_NONNULL const char *  cpu,
const char *  platform,
RZ_NONNULL const char *  platforms_dir 
)

Initialize Platform Profiles by setting the path to the corresponding SDB file.

Parameters
treference to RzPlatformTargetIndex
archreference to the selected architecture (value of asm.arch
platformreference to the selected platform (value of asm.platform)
platforms_dirreference to the directory containing platform files

Definition at line 134 of file platform_target_index.c.

135  {
136  if (RZ_STR_ISEMPTY(platform)) {
137  return true;
138  }
139  rz_return_val_if_fail(arch && cpu && platforms_dir, false);
140 
141  char buf[50];
142  char *path = rz_file_path_join(platforms_dir, rz_strf(buf, "%s-%s-%s.sdb", arch, cpu, platform));
143  if (!path) {
144  return false;
145  }
146  if (t->path && !strcmp(t->path, path)) {
147  free(path);
148  return true;
149  }
150  free(t->path);
151  t->path = path;
153 }
static ut32 cpu[32]
Definition: analysis_or1k.c:21
cs_arch arch
Definition: cstool.c:13
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
voidpf void * buf
Definition: ioapi.h:138
RZ_API bool rz_platform_target_index_load_sdb(RZ_NONNULL RzPlatformTargetIndex *t, RZ_NONNULL const char *path)
Loads the contents of the Platform Profile to the RzPlatformTargetIndex.
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API RZ_OWN char * rz_file_path_join(RZ_NONNULL const char *s1, RZ_NULLABLE const char *s2)
Concatenate two paths to create a new one with s1+s2 with the correct path separator.
Definition: file.c:1312
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67
#define rz_strf(buf,...)
Convenience macro for local temporary strings.
Definition: rz_str.h:59

References arch, cpu, free(), rz_platform_target_index_t::path, path, rz_file_path_join(), rz_platform_target_index_load_sdb(), rz_return_val_if_fail, RZ_STR_ISEMPTY, and rz_strf.

Referenced by cb_asmarch(), cb_asmcpu(), and cb_asmplatform().

◆ rz_platform_target_index_load_sdb()

RZ_API bool rz_platform_target_index_load_sdb ( RZ_NONNULL RzPlatformTargetIndex t,
RZ_NONNULL const char *  path 
)

Loads the contents of the Platform Profile to the RzPlatformTargetIndex.

Parameters
treference to RzPlatformTargetIndex
pathreference to path of the SDB file

Definition at line 115 of file platform_target_index.c.

115  {
116  rz_return_val_if_fail(t && path, false);
117  if (!path) {
118  return false;
119  }
120  if (!rz_file_exists(path)) {
121  return false;
122  }
124 }
static bool sdb_load_arch_platform_by_path(RZ_NONNULL RzPlatformTargetIndex *t, RZ_NONNULL const char *path)
RZ_API bool rz_file_exists(const char *str)
Definition: file.c:192

References path, rz_file_exists(), rz_return_val_if_fail, and sdb_load_arch_platform_by_path().

Referenced by rz_platform_target_index_init().

◆ rz_platform_target_index_new()

RZ_API RZ_OWN RzPlatformTargetIndex* rz_platform_target_index_new ( )

Creates a new RzPlatformTargetIndex type.

Definition at line 23 of file platform_target_index.c.

23  {
25  if (!target) {
26  return NULL;
27  }
28  target->platforms = ht_up_new0();
29  if (!target->platforms) {
30  free(target);
31  return NULL;
32  }
33  return target;
34 }

References free(), NULL, rz_platform_target_index_t::platforms, and RZ_NEW0.

Referenced by rz_analysis_new().

◆ sdb_load_arch_platform_by_path()

static bool sdb_load_arch_platform_by_path ( RZ_NONNULL RzPlatformTargetIndex t,
RZ_NONNULL const char *  path 
)
static

Definition at line 94 of file platform_target_index.c.

94  {
95  rz_return_val_if_fail(t && path, false);
96  if (!path) {
97  return false;
98  }
99  Sdb *db = sdb_new(0, path, 0);
100  if (!db) {
101  return false;
102  }
103  bool result = sdb_load_platform_profile(t, db);
104  sdb_close(db);
105  sdb_free(db);
106  return result;
107 }
static bool sdb_load_platform_profile(RZ_NONNULL RzPlatformTargetIndex *t, RZ_NONNULL Sdb *sdb)
RZ_API Sdb * sdb_new(const char *path, const char *name, int lock)
Definition: sdb.c:47
RZ_API void sdb_close(Sdb *s)
Definition: sdb.c:416
RZ_API bool sdb_free(Sdb *s)
Definition: sdb.c:206
Definition: sdb.h:63

References path, rz_return_val_if_fail, sdb_close(), sdb_free(), sdb_load_platform_profile(), and sdb_new().

Referenced by rz_platform_target_index_load_sdb().

◆ sdb_load_platform_profile()

static bool sdb_load_platform_profile ( RZ_NONNULL RzPlatformTargetIndex t,
RZ_NONNULL Sdb sdb 
)
static

Definition at line 60 of file platform_target_index.c.

60  {
61  rz_return_val_if_fail(t && sdb, false);
62  SdbKv *kv;
64  SdbList *l = sdb_foreach_list(sdb, false);
65  char *argument_key, *comment, *name;
66  ls_foreach (l, iter, kv) {
67  if (!strcmp(sdbkv_value(kv), "name")) {
68  name = sdbkv_key(kv);
69 
71 
72  argument_key = rz_str_newf("%s.address", item->name);
73  if (!argument_key) {
75  return false;
76  }
77  ut64 address = sdb_num_get(sdb, argument_key, NULL);
78  if (!address) {
80  return false;
81  }
82 
83  argument_key = rz_str_newf("%s.comment", item->name);
84  comment = sdb_get(sdb, argument_key, NULL);
85  if (comment) {
86  item->comment = comment;
87  }
88  ht_up_insert(t->platforms, address, item);
89  }
90  }
91  return true;
92 }
#define ls_foreach(list, it, pos)
Definition: ls.h:31
RZ_API ut64 sdb_num_get(Sdb *s, const char *key, ut32 *cas)
Definition: num.c:13
const char * name
Definition: op.c:541
RZ_API void rz_platform_item_free(RzPlatformItem *item)
Frees an RzPlatformItem type.
RZ_API RZ_OWN RzPlatformItem * rz_platform_item_new(RZ_NULLABLE const char *name)
Creates a new RzPlatformItem type.
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * sdb_get(Sdb *s, const char *key, ut32 *cas)
Definition: sdb.c:290
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
Definition: sdbht.h:14
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References rz_platform_item_t::comment, ls_foreach, name, rz_platform_item_t::name, NULL, rz_platform_item_free(), rz_platform_item_new(), rz_return_val_if_fail, rz_str_newf(), sdb_foreach_list(), sdb_get(), sdb_num_get(), sdbkv_key(), sdbkv_value(), and ut64().

Referenced by sdb_load_arch_platform_by_path().