Rizin
unix-like reverse engineering framework and cli tools
demangler_util.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2021 RizinOrg <info@rizin.re>
2 // SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
3 // SPDX-License-Identifier: LGPL-3.0-only
4 #ifndef RZ_LIBDEMANGLE_UTIL_H
5 #define RZ_LIBDEMANGLE_UTIL_H
6 
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <stdint.h>
11 
12 typedef int bool;
13 #define true 1
14 #define false 0
15 
16 #if defined(_MSC_VER)
17 #include <BaseTsd.h>
18 typedef SSIZE_T ssize_t;
19 #endif
20 
21 #define RZ_NEW0(x) (x *)calloc(1, sizeof(x))
22 #define RZ_NEW(x) (x *)malloc(sizeof(x))
23 #define RZ_FREE(x) \
24  { \
25  free((void *)x); \
26  x = NULL; \
27  }
28 
29 typedef uint8_t ut8;
30 typedef uint16_t ut16;
31 typedef uint32_t ut32;
32 
33 #if defined(__GNUC__) && __GNUC__ >= 4
34 #define RZ_API __attribute__((visibility("default")))
35 #elif defined(_MSC_VER)
36 #define RZ_API __declspec(dllexport)
37 #else
38 #define RZ_API
39 #endif
40 
41 #define IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
42 #define IS_DIGIT(x) ((x) >= '0' && (x) <= '9')
43 #define RZ_MIN(x, y) (((x) > (y)) ? (y) : (x))
44 #define RZ_STR_ISEMPTY(x) (!(x) || !*(x))
45 
46 char *dem_str_ndup(const char *ptr, int len);
47 char *dem_str_newf(const char *fmt, ...);
48 char *dem_str_append(char *ptr, const char *string);
49 void dem_str_replace_char(char *string, size_t size, char ch, char rp);
50 char *dem_str_replace(char *str, const char *key, const char *val, int g);
51 
52 typedef struct {
53  char *buf;
54  size_t len;
55 } DemString;
56 
57 void dem_string_free(DemString *ds);
59 char *dem_string_drain(DemString *ds);
60 bool dem_string_append(DemString *ds, const char *string);
61 bool dem_string_append_n(DemString *ds, const char *string, size_t size);
62 bool dem_string_appendf(DemString *ds, const char *fmt, ...);
63 
64 void dem_string_replace_char(DemString *ds, char ch, char rp);
65 
66 typedef void (*DemListFree)(void *ptr);
67 
68 typedef struct dem_list_iter_t {
69  void *data;
70  struct dem_list_iter_t *n, *p;
72 
73 typedef struct dem_list_t {
78  bool sorted;
80 
81 #define dem_list_foreach_prev(list, it, pos) \
82  if (list) \
83  for (it = list->tail; it && (pos = it->data, 1); it = it->p)
84 
85 #define dem_list_head(x) ((x) ? (x)->head : NULL)
86 
90 void *dem_list_get_n(const DemList *list, ut32 n);
92 
93 #endif /* RZ_LIBDEMANGLE_UTIL_H */
size_t len
Definition: 6502dis.c:15
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
void dem_list_free(DemList *list)
uint16_t ut16
char * dem_str_ndup(const char *ptr, int len)
int bool
DemListIter * dem_list_append(DemList *list, void *data)
char * dem_string_drain(DemString *ds)
char * dem_str_replace(char *str, const char *key, const char *val, int g)
ut32 dem_list_length(const DemList *list)
void * dem_list_get_n(const DemList *list, ut32 n)
void dem_string_free(DemString *ds)
DemString * dem_string_new()
char * dem_str_newf(const char *fmt,...)
void(* DemListFree)(void *ptr)
char * dem_str_append(char *ptr, const char *string)
bool dem_string_append(DemString *ds, const char *string)
bool dem_string_appendf(DemString *ds, const char *fmt,...)
uint8_t ut8
bool dem_string_append_n(DemString *ds, const char *string, size_t size)
DemList * dem_list_newf(DemListFree f)
struct dem_list_t DemList
uint32_t ut32
void dem_string_replace_char(DemString *ds, char ch, char rp)
struct dem_list_iter_t DemListIter
void dem_str_replace_char(char *string, size_t size, char ch, char rp)
struct @667 g
static char * rp[]
Definition: i8080dis.c:36
voidpf void uLong size
Definition: ioapi.h:138
static void list(RzEgg *egg)
Definition: rz-gg.c:52
int n
Definition: mipsasm.c:19
unsigned short uint16_t
Definition: sftypes.h:30
unsigned int uint32_t
Definition: sftypes.h:29
unsigned char uint8_t
Definition: sftypes.h:31
int ssize_t
Definition: sftypes.h:39
#define f(i)
Definition: sha256.c:46
size_t len
char * buf
struct dem_list_iter_t * n
struct dem_list_iter_t * p
DemListIter * tail
DemListIter * head
DemListFree free