Rizin
unix-like reverse engineering framework and cli tools
rz_api.h File Reference

Go to the source code of this file.

Macros

#define RZ_FREE(x)   { free(x); x = NULL; }
 
#define RZ_NEW0(x)   (x*)calloc(1,sizeof(x))
 

Functions

void out_printf (Output *out, char *str,...) __attribute__((format(printf
 
void SStrBufrz_strbuf_new (const char *s)
 
bool rz_strbuf_set (SStrBuf *sb, const char *s)
 
bool rz_strbuf_append (SStrBuf *sb, const char *s)
 
char * rz_strbuf_get (SStrBuf *sb)
 
char * rz_strbuf_drain (SStrBuf *sb)
 
void rz_strbuf_free (SStrBuf *sb)
 
void rz_strbuf_fini (SStrBuf *sb)
 
void rz_strbuf_init (SStrBuf *sb)
 
int rz_sys_setenv (const char *key, const char *value)
 Set an environment variable in the calling process. More...
 
char * rz_sys_getenv (const char *key)
 Get the value of an environment variable named key or NULL if none exists. More...
 
int rz_sys_getpid (void)
 

Macro Definition Documentation

◆ RZ_FREE

#define RZ_FREE (   x)    { free(x); x = NULL; }

Definition at line 5 of file rz_api.h.

◆ RZ_NEW0

#define RZ_NEW0 (   x)    (x*)calloc(1,sizeof(x))

Definition at line 8 of file rz_api.h.

Function Documentation

◆ out_printf()

void out_printf ( Output out,
char *  str,
  ... 
)

Referenced by PUT_CALLBACK(), and TAG_CALLBACK().

◆ rz_strbuf_append()

bool rz_strbuf_append ( SStrBuf sb,
const char *  s 
)

Definition at line 47 of file rz_api.c.

47  {
48  int l = strlen (s);
49  if (l < 1) {
50  return false;
51  }
52  if ((sb->len + l + 1) < sizeof (sb->buf)) {
53  memcpy (sb->buf + sb->len, s, l + 1);
54  RZ_FREE (sb->ptr);
55  } else {
56  int newlen = sb->len + l + 128;
57  char *p = sb->ptr;
58  bool allocated = true;
59  if (!sb->ptr) {
60  p = malloc (newlen);
61  if (p && sb->len > 0) {
62  memcpy (p, sb->buf, sb->len);
63  }
64  } else if (sb->len + l + 1 > sb->ptrlen) {
65  p = realloc (sb->ptr, newlen);
66  } else {
67  allocated = false;
68  }
69  if (allocated) {
70  if (!p) return false;
71  sb->ptr = p;
72  sb->ptrlen = newlen;
73  }
74  memcpy (p + sb->len, s, l + 1);
75  }
76  sb->len += l;
77  return true;
78 }
static SblHeader sb
Definition: bin_mbn.c:26
void * p
Definition: libc.cpp:67
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void * realloc(void *ptr, size_t size)
Definition: malloc.c:144
void * malloc(size_t size)
Definition: malloc.c:123
static RzSocket * s
Definition: rtr.c:28
#define RZ_FREE(x)
Definition: rz_types.h:369

References malloc(), memcpy(), p, realloc(), RZ_FREE, s, and sb.

◆ rz_strbuf_drain()

char* rz_strbuf_drain ( SStrBuf sb)

Definition at line 84 of file rz_api.c.

84  {
85  char *res = sb->ptr? sb->ptr: strdup (sb->buf);
86  sb->ptr = NULL;
88  free (sb);
89  return res;
90 }
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
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")
void rz_strbuf_fini(SStrBuf *sb)
Definition: rz_api.c:97

References free(), NULL, rz_strbuf_fini(), sb, and strdup().

◆ rz_strbuf_fini()

void rz_strbuf_fini ( SStrBuf sb)

Definition at line 97 of file rz_api.c.

97  {
98  if (sb && sb->ptr)
99  RZ_FREE (sb->ptr);
100 }

References RZ_FREE, and sb.

Referenced by rz_strbuf_drain(), and rz_strbuf_free().

◆ rz_strbuf_free()

void rz_strbuf_free ( SStrBuf sb)

Definition at line 92 of file rz_api.c.

92  {
94  free (sb);
95 }

References free(), rz_strbuf_fini(), and sb.

◆ rz_strbuf_get()

char* rz_strbuf_get ( SStrBuf sb)

Definition at line 80 of file rz_api.c.

80  {
81  return sb? (sb->ptr? sb->ptr: sb->buf) : NULL;
82 }

References NULL, and sb.

◆ rz_strbuf_init()

void rz_strbuf_init ( SStrBuf sb)

Definition at line 18 of file rz_api.c.

18  {
19  memset (sb, 0, sizeof (SStrBuf));
20 }
return memset(p, 0, total)
Definition: spp.h:84

References memset(), and sb.

Referenced by rz_strbuf_set().

◆ rz_strbuf_new()

void SStrBuf* rz_strbuf_new ( const char *  s)

Definition at line 8 of file strbuf.c.

8  {
10  if (str) {
12  }
13  return s;
14 }
#define RZ_NEW0(x)
Definition: rz_types.h:284
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
Definition: strbuf.c:153

References RZ_NEW0, rz_strbuf_set(), s, and cmd_descs_generate::str.

◆ rz_strbuf_set()

bool rz_strbuf_set ( SStrBuf sb,
const char *  s 
)

Definition at line 22 of file rz_api.c.

22  {
23  int l;
24  if (!sb) return false;
25  if (!s) {
27  return true;
28  }
29  l = strlen (s);
30  if (l >= sizeof (sb->buf)) {
31  char *ptr = sb->ptr;
32  if (!ptr || l+1 > sb->ptrlen) {
33  ptr = malloc (l + 1);
34  if (!ptr) return false;
35  sb->ptrlen = l + 1;
36  sb->ptr = ptr;
37  }
38  memcpy (ptr, s, l+1);
39  } else {
40  sb->ptr = NULL;
41  memcpy (sb->buf, s, l+1);
42  }
43  sb->len = l;
44  return true;
45 }
void rz_strbuf_init(SStrBuf *sb)
Definition: rz_api.c:18

References malloc(), memcpy(), NULL, rz_strbuf_init(), s, and sb.

Referenced by rz_strbuf_new().

◆ rz_sys_getenv()

char* rz_sys_getenv ( const char *  key)

Get the value of an environment variable named key or NULL if none exists.

Definition at line 483 of file sys.c.

483  {
484 #if __WINDOWS__
485  if (!key) {
486  return NULL;
487  }
488  wchar_t *val;
489  wchar_t *wkey = rz_utf8_to_utf16(key);
490  if (_wdupenv_s(&val, NULL, wkey) || !val) {
491  free(wkey);
492  return NULL;
493  }
494  free(wkey);
495  char *ret = rz_utf16_to_utf8(val);
496  free(val);
497  return ret;
498 #else
499  char *b;
500  if (!key) {
501  return NULL;
502  }
503  b = getenv(key);
504  return b ? strdup(b) : NULL;
505 #endif
506 }
ut16 val
Definition: armass64_const.h:6
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
#define b(i)
Definition: sha256.c:42
char * getenv()

References b, DWORD, free(), getenv(), key, malloc(), NULL, realloc(), strdup(), and val.

Referenced by rz_sys_getenv_asbool().

◆ rz_sys_getpid()

int rz_sys_getpid ( void  )

Definition at line 1164 of file sys.c.

1164  {
1165 #if __UNIX__
1166  return getpid();
1167 #elif __WINDOWS__
1168  return GetCurrentProcessId();
1169 #else
1170 #warning rz_sys_getpid not implemented for this platform
1171  return -1;
1172 #endif
1173 }

◆ rz_sys_setenv()

int rz_sys_setenv ( const char *  key,
const char *  value 
)

Set an environment variable in the calling process.

Definition at line 405 of file sys.c.

405  {
406  if (!key) {
407  return 0;
408  }
409 #if __UNIX__
410  if (!value) {
411  unsetenv(key);
412  return 0;
413  }
414  return setenv(key, value, 1);
415 #elif __WINDOWS__
416  LPWSTR key_ = rz_utf8_to_utf16(key);
417  LPWSTR value_ = value ? rz_utf8_to_utf16(value) : L"";
418  bool ret = !_wputenv_s(key_, value_);
419  free(key_);
420  if (value) {
421  free(value_);
422  }
423  return ret ? 0 : -1;
424 #else
425 #warning rz_sys_setenv : unimplemented for this platform
426  return 0;
427 #endif
428 }
static int value
Definition: cmd_api.c:93
DWORD LPWSTR
#define L
Definition: zip_err_str.c:7

References key, and value.

Referenced by rz_sys_set_environ().