Rizin
unix-like reverse engineering framework and cli tools
rz_platform.h File Reference
#include <rz_config.h>
#include <rz_flag.h>
#include <rz_il.h>
#include <sdb.h>

Go to the source code of this file.

Classes

struct  rz_platform_profile_t
 
struct  rz_platform_target_t
 
struct  rz_platform_item_t
 
struct  rz_platform_target_index_t
 

Typedefs

typedef struct rz_platform_profile_t RzPlatformProfile
 
typedef struct rz_platform_target_t RzPlatformTarget
 
typedef struct rz_platform_item_t RzPlatformItem
 
typedef struct rz_platform_target_index_t RzPlatformTargetIndex
 

Functions

RZ_API RZ_OWN RzPlatformProfilerz_platform_profile_new ()
 Creates a new RzPlatformProfile type. More...
 
RZ_API RZ_OWN RzPlatformTargetrz_platform_target_new ()
 Creates a new RzPlatformTarget type. More...
 
RZ_API void rz_platform_profile_free (RzPlatformProfile *profile)
 Frees an RzPlatformProfile type. More...
 
RZ_API void rz_platform_target_free (RzPlatformTarget *target)
 Frees an RzPlatformTarget type. More...
 
RZ_API bool rz_platform_profiles_init (RzPlatformTarget *c, const char *cpu, const char *arch, const char *cpus_dir)
 Initializes RzPlatformProfile by loading the path to the SDB file of the CPU profile. More...
 
RZ_API void rz_platform_profile_add_flag_every_io (RzPlatformProfile *profile, RzFlag *flags)
 Adds the IO and extended IO registers from the CPU profiles as flags. More...
 
RZ_API bool rz_platform_load_profile_sdb (RzPlatformTarget *t, const char *path)
 Loads the contents of the CPU Profile to the RzPlatformProfile. More...
 
RZ_API RZ_BORROW const char * rz_platform_profile_resolve_mmio (RZ_NONNULL RzPlatformProfile *profile, ut64 address)
 Resolves an address and returns the linked mmio. More...
 
RZ_API RZ_BORROW const char * rz_platform_profile_resolve_extended_register (RZ_NONNULL RzPlatformProfile *profile, ut64 address)
 Resolves an address and returns the linked extended register. More...
 
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...
 
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...
 

Typedef Documentation

◆ RzPlatformItem

◆ RzPlatformProfile

◆ RzPlatformTarget

◆ RzPlatformTargetIndex

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_load_profile_sdb()

RZ_API bool rz_platform_load_profile_sdb ( RzPlatformTarget t,
const char *  path 
)

Loads the contents of the CPU Profile to the RzPlatformProfile.

Parameters
treference to RzPlatformTarget
pathreference to path of the SDB file

Definition at line 168 of file platform_profile.c.

168  {
169  if (!rz_file_exists(path)) {
170  return false;
171  }
173 }
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
static bool sdb_load_arch_profile_by_path(RZ_NONNULL RzPlatformTarget *t, const char *path)
RZ_API bool rz_file_exists(const char *str)
Definition: file.c:192

References path, rz_file_exists(), and sdb_load_arch_profile_by_path().

Referenced by rz_platform_profiles_init().

◆ rz_platform_profile_add_flag_every_io()

RZ_API void rz_platform_profile_add_flag_every_io ( RzPlatformProfile profile,
RzFlag flags 
)

Adds the IO and extended IO registers from the CPU profiles as flags.

Parameters
profilereference to RzPlatformProfile
flagsreference to RzFlag

Definition at line 5236 of file canalysis.c.

5236  {
5239  ht_up_foreach(profile->registers_mmio, add_mmio_flag_cb, flags);
5240  ht_up_foreach(profile->registers_extended, add_mmio_extended_flag_cb, flags);
5241 }
static bool add_mmio_extended_flag_cb(void *user, const ut64 addr, const void *v)
Definition: canalysis.c:5222
static bool add_mmio_flag_cb(void *user, const ut64 addr, const void *v)
Definition: canalysis.c:5213
RZ_API void rz_flag_unset_all_in_space(RzFlag *f, const char *space_name)
Unset all flag items in the space with the given name.
Definition: flag.c:692
#define RZ_FLAGS_FS_MMIO_REGISTERS_EXTENDED
Definition: rz_core.h:71
#define RZ_FLAGS_FS_MMIO_REGISTERS
Definition: rz_core.h:70
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123

References add_mmio_extended_flag_cb(), add_mmio_flag_cb(), flags, rz_platform_profile_t::registers_extended, rz_platform_profile_t::registers_mmio, rz_flag_unset_all_in_space(), RZ_FLAGS_FS_MMIO_REGISTERS, and RZ_FLAGS_FS_MMIO_REGISTERS_EXTENDED.

Referenced by rz_core_analysis_all().

◆ rz_platform_profile_free()

RZ_API void rz_platform_profile_free ( RzPlatformProfile p)

Frees an RzPlatformProfile type.

Frees the hashtables used for MMIO and extended
registers

Definition at line 13 of file platform_profile.c.

13  {
14  if (!p) {
15  return;
16  }
17  ht_up_free(p->registers_mmio);
18  ht_up_free(p->registers_extended);
19  free(p);
20 }
void * p
Definition: libc.cpp:67

References free(), and p.

Referenced by rz_platform_target_free(), and sdb_load_arch_profile().

◆ rz_platform_profile_new()

RZ_API RZ_OWN RzPlatformProfile* rz_platform_profile_new ( )

Creates a new RzPlatformProfile type.

Definition at line 29 of file platform_profile.c.

29  {
31  if (!profile) {
32  return NULL;
33  }
34  profile->registers_mmio = ht_up_new((HtUPDupValue)strdup, free_mmio_kv, (HtUPCalcSizeV)strlen);
35  if (!profile->registers_mmio) {
36  free(profile);
37  return NULL;
38  }
39  profile->registers_extended = ht_up_new((HtUPDupValue)strdup, free_mmio_kv, (HtUPCalcSizeV)strlen);
40  if (!profile->registers_extended) {
41  ht_up_free(profile->registers_mmio);
42  free(profile);
43  return NULL;
44  }
45  return profile;
46 }
static void free_mmio_kv(HtUPKv *kv)

References free(), free_mmio_kv(), NULL, rz_platform_profile_t::registers_extended, rz_platform_profile_t::registers_mmio, RZ_NEW0, and strdup().

Referenced by rz_platform_target_new(), and sdb_load_arch_profile().

◆ rz_platform_profile_resolve_extended_register()

RZ_API RZ_BORROW const char* rz_platform_profile_resolve_extended_register ( RZ_NONNULL RzPlatformProfile profile,
ut64  address 
)

Resolves an address and returns the linked extended register.

Definition at line 91 of file platform_profile.c.

91  {
92  rz_return_val_if_fail(profile, NULL);
93 
94  return ht_up_find(profile->registers_extended, (ut64)address, NULL);
95 }
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References NULL, rz_return_val_if_fail, and ut64().

Referenced by ds_build_op_str().

◆ rz_platform_profile_resolve_mmio()

RZ_API RZ_BORROW const char* rz_platform_profile_resolve_mmio ( RZ_NONNULL RzPlatformProfile profile,
ut64  address 
)

Resolves an address and returns the linked mmio.

Definition at line 82 of file platform_profile.c.

82  {
83  rz_return_val_if_fail(profile, NULL);
84 
85  return ht_up_find(profile->registers_mmio, (ut64)address, NULL);
86 }

References NULL, rz_return_val_if_fail, and ut64().

Referenced by ds_build_op_str(), and resolve_mmio().

◆ rz_platform_profiles_init()

RZ_API bool rz_platform_profiles_init ( RzPlatformTarget t,
const char *  cpu,
const char *  arch,
const char *  cpus_dir 
)

Initializes RzPlatformProfile by loading the path to the SDB file of the CPU profile.

Parameters
treference to RzPlatformTarget
cpureference to the selected CPU (value of asm.cpu)
archreference to the selected architecture (value of asm.arch)
cpus_dirreference to the directory containing cpu files

Definition at line 221 of file platform_profile.c.

221  {
222  if (!cpu_reload_needed(t, cpu, arch)) {
223  return false;
224  }
225  if (!cpus_dir || !arch || !cpu) {
226  return false;
227  }
228  char buf[50];
229  char *path = rz_file_path_join(cpus_dir, rz_strf(buf, "%s-%s.sdb", arch, cpu));
230  if (!path) {
231  return false;
232  }
233  if (!is_cpu_valid(cpus_dir, cpu)) {
234  if (!strcmp(arch, "avr")) {
235  free(path);
236  path = rz_file_path_join(cpus_dir, "avr-ATmega8.sdb");
237  }
238  }
239  free(t->cpu);
240  free(t->arch);
241  t->cpu = strdup(cpu);
242  t->arch = strdup(arch);
244  free(path);
245  return true;
246 }
static ut32 cpu[32]
Definition: analysis_or1k.c:21
cs_arch arch
Definition: cstool.c:13
voidpf void * buf
Definition: ioapi.h:138
static bool is_cpu_valid(const char *cpu_dir, const char *cpu)
static bool cpu_reload_needed(RzPlatformTarget *c, const char *cpu, const char *arch)
RZ_API bool rz_platform_load_profile_sdb(RzPlatformTarget *t, const char *path)
Loads the contents of the CPU Profile to the RzPlatformProfile.
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_strf(buf,...)
Convenience macro for local temporary strings.
Definition: rz_str.h:59

References rz_platform_target_t::arch, arch, cpu, rz_platform_target_t::cpu, cpu_reload_needed(), free(), is_cpu_valid(), path, rz_file_path_join(), rz_platform_load_profile_sdb(), rz_strf, and strdup().

Referenced by cb_asmarch(), and cb_asmcpu().

◆ rz_platform_target_free()

RZ_API void rz_platform_target_free ( RzPlatformTarget t)

Frees an RzPlatformTarget type.

Frees the pointer to the SDB and the RzPlatformProfile

Definition at line 69 of file platform_profile.c.

69  {
70  if (!t) {
71  return;
72  }
74  free(t->cpu);
75  free(t->arch);
76  free(t);
77 }
RZ_API void rz_platform_profile_free(RzPlatformProfile *p)
Frees an RzPlatformProfile type.
RzPlatformProfile * profile
Definition: rz_platform.h:34

References rz_platform_target_t::arch, rz_platform_target_t::cpu, free(), rz_platform_target_t::profile, and rz_platform_profile_free().

Referenced by rz_analysis_free().

◆ 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 }
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_STR_ISEMPTY(x)
Definition: rz_str.h:67

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)

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().

◆ rz_platform_target_new()

RZ_API RZ_OWN RzPlatformTarget* rz_platform_target_new ( )

Creates a new RzPlatformTarget type.

Definition at line 51 of file platform_profile.c.

51  {
53  if (!profile) {
54  return NULL;
55  }
56  profile->profile = rz_platform_profile_new();
57  if (!profile->profile) {
58  free(profile);
59  return NULL;
60  }
61  return profile;
62 }
RZ_API RZ_OWN RzPlatformProfile * rz_platform_profile_new()
Creates a new RzPlatformProfile type.

References free(), NULL, rz_platform_target_t::profile, RZ_NEW0, and rz_platform_profile_new().

Referenced by rz_analysis_new().