Rizin
unix-like reverse engineering framework and cli tools
num.c File Reference
#include "sdb.h"
#include <rz_types.h>

Go to the source code of this file.

Functions

RZ_API bool sdb_num_exists (Sdb *s, const char *key)
 
RZ_API ut64 sdb_num_get (Sdb *s, const char *key, ut32 *cas)
 
RZ_API int sdb_num_add (Sdb *s, const char *key, ut64 v, ut32 cas)
 
RZ_API int sdb_num_set (Sdb *s, const char *key, ut64 v, ut32 cas)
 
RZ_API ut64 sdb_num_inc (Sdb *s, const char *key, ut64 n2, ut32 cas)
 
RZ_API ut64 sdb_num_dec (Sdb *s, const char *key, ut64 n2, ut32 cas)
 
RZ_API int sdb_num_min (Sdb *db, const char *k, ut64 n, ut32 cas)
 
RZ_API int sdb_num_max (Sdb *db, const char *k, ut64 n, ut32 cas)
 
RZ_API int sdb_bool_set (Sdb *db, const char *str, bool v, ut32 cas)
 
RZ_API bool sdb_bool_get (Sdb *db, const char *str, ut32 *cas)
 
RZ_API int sdb_ptr_set (Sdb *db, const char *key, void *p, ut32 cas)
 
RZ_API void * sdb_ptr_get (Sdb *db, const char *key, ut32 *cas)
 

Function Documentation

◆ sdb_bool_get()

RZ_API bool sdb_bool_get ( Sdb db,
const char *  str,
ut32 cas 
)

Definition at line 76 of file num.c.

76  {
77  const char *b = sdb_const_get(db, str, cas);
78  return b && (!strcmp(b, "1") || !strcmp(b, "true"));
79 }
RZ_API const char * sdb_const_get(Sdb *s, const char *key, ut32 *cas)
Definition: sdb.c:279
#define b(i)
Definition: sha256.c:42

References b, sdb_const_get(), and cmd_descs_generate::str.

Referenced by get_callable_type(), rz_analysis_is_noreturn(), and rz_analysis_noreturn_at_addr().

◆ sdb_bool_set()

RZ_API int sdb_bool_set ( Sdb db,
const char *  str,
bool  v,
ut32  cas 
)

Definition at line 72 of file num.c.

72  {
73  return sdb_set(db, str, v ? "true" : "false", cas);
74 }
const char * v
Definition: dsignal.c:12
RZ_API int sdb_set(Sdb *s, const char *key, const char *val, ut32 cas)
Definition: sdb.c:611

References sdb_set(), cmd_descs_generate::str, and v.

Referenced by agraph_sdb_init(), rz_analysis_noreturn_add(), and save_callable().

◆ sdb_num_add()

RZ_API int sdb_num_add ( Sdb s,
const char *  key,
ut64  v,
ut32  cas 
)

Definition at line 18 of file num.c.

18  {
19  char *val, b[SDB_NUM_BUFSZ];
20  int numbase = sdb_num_base(sdb_const_get(s, key, NULL));
21  val = sdb_itoa(v, b, numbase);
22  return sdb_add(s, key, val, cas);
23 }
ut16 val
Definition: armass64_const.h:6
#define NULL
Definition: cris-opc.c:27
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
static RzSocket * s
Definition: rtr.c:28
RZ_API int sdb_add(Sdb *s, const char *key, const char *val, ut32 cas)
Definition: sdb.c:351
RZ_API char * sdb_itoa(ut64 n, char *s, int base)
Definition: util.c:38
#define SDB_NUM_BUFSZ
Definition: sdb.h:51
RZ_API int sdb_num_base(const char *s)
Definition: util.c:221

References b, key, NULL, s, sdb_add(), sdb_const_get(), sdb_itoa(), sdb_num_base(), SDB_NUM_BUFSZ, v, and val.

Referenced by rz_core_bin_apply_all_info().

◆ sdb_num_dec()

RZ_API ut64 sdb_num_dec ( Sdb s,
const char *  key,
ut64  n2,
ut32  cas 
)

Definition at line 43 of file num.c.

43  {
44  ut32 c;
45  ut64 n = sdb_num_get(s, key, &c);
46  if (cas && c != cas) {
47  return 0LL;
48  }
49  if (n2 > n) {
50  sdb_set(s, key, "0", cas);
51  return 0LL; // XXX must be -1LL?
52  }
53  n -= n2;
54  sdb_num_set(s, key, n, cas);
55  return n;
56 }
uint32_t ut32
int n
Definition: mipsasm.c:19
RZ_API int sdb_num_set(Sdb *s, const char *key, ut64 v, ut32 cas)
Definition: num.c:25
RZ_API ut64 sdb_num_get(Sdb *s, const char *key, ut32 *cas)
Definition: num.c:13
#define c(i)
Definition: sha256.c:43
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References c, key, n, s, sdb_num_get(), sdb_num_set(), sdb_set(), and ut64().

Referenced by sdb_querys().

◆ sdb_num_exists()

RZ_API bool sdb_num_exists ( Sdb s,
const char *  key 
)

Definition at line 8 of file num.c.

8  {
9  const char *o = sdb_const_get(s, key, NULL);
10  return o ? (*o >= '0' && *o <= '9') : false;
11 }

References key, NULL, s, and sdb_const_get().

◆ sdb_num_get()

◆ sdb_num_inc()

RZ_API ut64 sdb_num_inc ( Sdb s,
const char *  key,
ut64  n2,
ut32  cas 
)

Definition at line 32 of file num.c.

32  {
33  ut32 c;
34  ut64 n = sdb_num_get(s, key, &c);
35  ut64 res = n + n2;
36  if ((cas && c != cas) || res < n) {
37  return 0LL;
38  }
39  sdb_num_set(s, key, res, cas);
40  return res;
41 }

References c, key, n, s, sdb_num_get(), sdb_num_set(), and ut64().

Referenced by sdb_querys(), and ssa_set().

◆ sdb_num_max()

RZ_API int sdb_num_max ( Sdb db,
const char *  k,
ut64  n,
ut32  cas 
)

Definition at line 65 of file num.c.

65  {
66  const char *a = sdb_const_get(db, k, NULL);
67  return (!a || n > sdb_atoi(a))
68  ? sdb_num_set(db, k, n, cas)
69  : 0;
70 }
const char * k
Definition: dsignal.c:11
#define a(i)
Definition: sha256.c:41

References a, k, n, NULL, sdb_atoi(), sdb_const_get(), and sdb_num_set().

◆ sdb_num_min()

RZ_API int sdb_num_min ( Sdb db,
const char *  k,
ut64  n,
ut32  cas 
)

Definition at line 58 of file num.c.

58  {
59  const char *a = sdb_const_get(db, k, NULL);
60  return (!a || n < sdb_atoi(a))
61  ? sdb_num_set(db, k, n, cas)
62  : 0;
63 }

References a, k, n, NULL, sdb_atoi(), sdb_const_get(), and sdb_num_set().

◆ sdb_num_set()

◆ sdb_ptr_get()

RZ_API void* sdb_ptr_get ( Sdb db,
const char *  key,
ut32 cas 
)

Definition at line 87 of file num.c.

87  {
88  return (void *)(size_t)sdb_num_get(db, key, cas);
89 }
int size_t
Definition: sftypes.h:40

References key, and sdb_num_get().

Referenced by __create_almighty(), __exec_almighty(), __set_rcb(), and rz_analysis_esil_fire_trap().

◆ sdb_ptr_set()

RZ_API int sdb_ptr_set ( Sdb db,
const char *  key,
void *  p,
ut32  cas 
)

Definition at line 83 of file num.c.

83  {
84  return sdb_num_set(db, key, (ut64)(size_t)p, cas);
85 }
void * p
Definition: libc.cpp:67

References key, p, sdb_num_set(), and ut64().

Referenced by __init_almighty_db(), and __init_rotate_db().