Rizin
unix-like reverse engineering framework and cli tools
rz_buf.h
Go to the documentation of this file.
1 #ifndef RZ_BUF_H
2 #define RZ_BUF_H
3 #include <rz_util/rz_mem.h>
4 #include <rz_types.h>
5 #include <rz_list.h>
6 #include <rz_util/rz_assert.h>
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 // TODO: choose whether the _at operations should preserve the current seek or not
13 
14 #define RZ_BUF_SET 0
15 #define RZ_BUF_CUR 1
16 #define RZ_BUF_END 2
17 
18 typedef struct rz_buf_t RzBuffer;
19 
20 typedef bool (*RzBufferInit)(RzBuffer *b, const void *user);
21 typedef bool (*RzBufferFini)(RzBuffer *b);
23 typedef st64 (*RzBufferWrite)(RzBuffer *b, const ut8 *buf, ut64 len);
25 typedef bool (*RzBufferResize)(RzBuffer *b, ut64 newsize);
26 typedef st64 (*RzBufferSeek)(RzBuffer *b, st64 addr, int whence);
27 typedef ut8 *(*RzBufferGetWholeBuf)(RzBuffer *b, ut64 *sz);
28 typedef void (*RzBufferFreeWholeBuf)(RzBuffer *b);
29 typedef RzList *(*RzBufferNonEmptyList)(RzBuffer *b);
30 
31 typedef struct rz_buffer_methods_t {
42 
43 struct rz_buf_t {
45  void *priv;
47  bool readonly;
49  int refctr;
50  int fd;
51 };
52 
53 typedef struct rz_buf_sparse_chunk_t {
55  ut64 to;
56  ut8 *data;
58 
59 typedef enum {
63 
64 /* utils */
65 
67 static inline ut64 rz_seek_offset(ut64 cur, ut64 length, st64 addr, int whence) {
68  switch (whence) {
69  case RZ_BUF_CUR:
70  return cur + (ut64)addr;
71  case RZ_BUF_SET:
72  return addr;
73  case RZ_BUF_END:
74  return length + (ut64)addr;
75  default:
77  return cur;
78  }
79 }
80 
81 /* constructors */
83 RZ_API RZ_OWN RzBuffer *rz_buf_new_file(const char *file, int perm, int mode);
84 RZ_API RZ_OWN RzBuffer *rz_buf_new_mmap(const char *file, int flags, int mode);
91 RZ_API RZ_OWN RzBuffer *rz_buf_new_with_io_fd(RZ_NONNULL void /* RzIOBind */ *iob, int fd);
92 RZ_API RZ_OWN RzBuffer *rz_buf_new_with_io(RZ_NONNULL void /* RzIOBind */ *iob);
96 
97 /* methods */
98 
115 RZ_API bool rz_buf_resize(RZ_NONNULL RzBuffer *b, ut64 newsize);
122 RZ_API st64 rz_buf_fwrite(RZ_NONNULL RzBuffer *b, RZ_NONNULL const ut8 *buf, RZ_NONNULL const char *fmt, int n);
135 
138 
141 
144  return rz_buf_uleb128(b, v);
145 }
148  return rz_buf_sleb128(b, v);
149 }
150 
151 /* generated methods */
152 
153 #define DEFINE_RZ_BUF_READ_BLE(size) \
154  static inline bool rz_buf_read_ble##size(RZ_NONNULL RzBuffer *b, RZ_NONNULL RZ_OUT ut##size *result, bool big_endian) { \
155  rz_return_val_if_fail(b &&result, false); \
156 \
157  ut8 tmp[sizeof(ut##size)]; \
158  if (rz_buf_read(b, tmp, sizeof(tmp)) != sizeof(tmp)) { \
159  return false; \
160  } \
161 \
162  *result = rz_read_ble##size(tmp, big_endian); \
163  return true; \
164  } \
165 \
166  static inline bool rz_buf_read_ble##size##_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL RZ_OUT ut##size *result, bool big_endian) { \
167  rz_return_val_if_fail(b &&result, false); \
168 \
169  ut8 tmp[sizeof(ut##size)]; \
170  if (rz_buf_read_at(b, addr, tmp, sizeof(tmp)) != sizeof(tmp)) { \
171  return false; \
172  } \
173 \
174  *result = rz_read_ble##size(tmp, big_endian); \
175  return true; \
176  }
177 
178 #define DEFINE_RZ_BUF_WRITE_BLE(size) \
179  static inline bool rz_buf_write_ble##size(RZ_NONNULL RzBuffer *b, ut##size value, bool big_endian) { \
180  ut8 tmp[sizeof(ut##size)]; \
181  rz_write_ble##size(tmp, value, big_endian); \
182 \
183  return rz_buf_write(b, tmp, sizeof(tmp)) == sizeof(tmp); \
184  } \
185 \
186  static inline bool rz_buf_write_ble##size##_at(RZ_NONNULL RzBuffer *b, ut64 addr, ut##size value, bool big_endian) { \
187  ut8 tmp[sizeof(ut##size)]; \
188  rz_write_ble##size(tmp, value, big_endian); \
189 \
190  return rz_buf_write_at(b, addr, tmp, sizeof(tmp)) == sizeof(tmp); \
191  }
192 
204 
216 
217 #define DEFINE_RZ_BUF_READ_OFFSET_BLE(size) \
218  static inline bool rz_buf_read_ble##size##_offset(RZ_NONNULL RzBuffer *b, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT ut##size *result, bool big_endian) { \
219  rz_return_val_if_fail(b &&offset &&result, false); \
220  if (!rz_buf_read_ble##size##_at(b, *offset, result, big_endian)) { \
221  return false; \
222  } \
223  *offset += sizeof(*result); \
224  return true; \
225  }
226 
227 #define DEFINE_RZ_BUF_WRITE_OFFSET_BLE(size) \
228  static inline bool rz_buf_write_ble##size##_offset(RZ_NONNULL RzBuffer *b, RZ_NONNULL RZ_INOUT ut64 *offset, ut##size value, bool big_endian) { \
229  rz_return_val_if_fail(b &&offset, false); \
230  if (!rz_buf_write_ble##size##_at(b, *offset, value, big_endian)) { \
231  return false; \
232  } \
233  *offset += sizeof(value); \
234  return true; \
235  }
236 
237 #define rz_buf_read_ble8_at(b, addr, result, endian) rz_buf_read8_at(b, addr, result)
238 #define rz_buf_write_ble8_at(b, addr, value, endian) rz_buf_write8_at(b, addr, value)
239 
252 
265 
266 #define rz_buf_read_le16(b, result) rz_buf_read_ble16(b, result, false)
267 #define rz_buf_read_le32(b, result) rz_buf_read_ble32(b, result, false)
268 #define rz_buf_read_le64(b, result) rz_buf_read_ble64(b, result, false)
269 
270 #define rz_buf_read_le16_at(b, addr, result) rz_buf_read_ble16_at(b, addr, result, false)
271 #define rz_buf_read_le32_at(b, addr, result) rz_buf_read_ble32_at(b, addr, result, false)
272 #define rz_buf_read_le64_at(b, addr, result) rz_buf_read_ble64_at(b, addr, result, false)
273 
274 #define rz_buf_read8_offset(b, offset, result) rz_buf_read_ble8_offset(b, offset, result, false)
275 
276 #define rz_buf_read_le16_offset(b, offset, result) rz_buf_read_ble16_offset(b, offset, result, false)
277 #define rz_buf_read_le32_offset(b, offset, result) rz_buf_read_ble32_offset(b, offset, result, false)
278 #define rz_buf_read_le64_offset(b, offset, result) rz_buf_read_ble64_offset(b, offset, result, false)
279 
280 #define rz_buf_read_be16(b, result) rz_buf_read_ble16(b, result, true)
281 #define rz_buf_read_be32(b, result) rz_buf_read_ble32(b, result, true)
282 #define rz_buf_read_be64(b, result) rz_buf_read_ble64(b, result, true)
283 
284 #define rz_buf_read_be16_at(b, addr, result) rz_buf_read_ble16_at(b, addr, result, true)
285 #define rz_buf_read_be32_at(b, addr, result) rz_buf_read_ble32_at(b, addr, result, true)
286 #define rz_buf_read_be64_at(b, addr, result) rz_buf_read_ble64_at(b, addr, result, true)
287 
288 #define rz_buf_read_be16_offset(b, offset, result) rz_buf_read_ble16_offset(b, offset, result, true)
289 #define rz_buf_read_be32_offset(b, offset, result) rz_buf_read_ble32_offset(b, offset, result, true)
290 #define rz_buf_read_be64_offset(b, offset, result) rz_buf_read_ble64_offset(b, offset, result, true)
291 
292 #define rz_buf_write_le16(b, value) rz_buf_write_ble16(b, value, false)
293 #define rz_buf_write_le32(b, value) rz_buf_write_ble32(b, value, false)
294 #define rz_buf_write_le64(b, value) rz_buf_write_ble64(b, value, false)
295 
296 #define rz_buf_write_le16_at(b, addr, value) rz_buf_write_ble16_at(b, addr, value, false)
297 #define rz_buf_write_le32_at(b, addr, value) rz_buf_write_ble32_at(b, addr, value, false)
298 #define rz_buf_write_le64_at(b, addr, value) rz_buf_write_ble64_at(b, addr, value, false)
299 
300 #define rz_buf_write8_offset(b, offset, value) rz_buf_write_ble8_offset(b, offset, value, false)
301 
302 #define rz_buf_write_le16_offset(b, offset, value) rz_buf_write_ble16_offset(b, offset, value, false)
303 #define rz_buf_write_le32_offset(b, offset, value) rz_buf_write_ble32_offset(b, offset, value, false)
304 #define rz_buf_write_le64_offset(b, offset, value) rz_buf_write_ble64_offset(b, offset, value, false)
305 
306 #define rz_buf_write_be16(b, value) rz_buf_write_ble16(b, value, true)
307 #define rz_buf_write_be32(b, value) rz_buf_write_ble32(b, value, true)
308 #define rz_buf_write_be64(b, value) rz_buf_write_ble64(b, value, true)
309 
310 #define rz_buf_write_be16_at(b, addr, value) rz_buf_write_ble16_at(b, addr, value, true)
311 #define rz_buf_write_be32_at(b, addr, value) rz_buf_write_ble32_at(b, addr, value, true)
312 #define rz_buf_write_be64_at(b, addr, value) rz_buf_write_ble64_at(b, addr, value, true)
313 
314 #define rz_buf_write_be16_offset(b, offset, value) rz_buf_write_ble16_offset(b, offset, value, true)
315 #define rz_buf_write_be32_offset(b, offset, value) rz_buf_write_ble32_offset(b, offset, value, true)
316 #define rz_buf_write_be64_offset(b, offset, value) rz_buf_write_ble64_offset(b, offset, value, true)
317 
318 #undef DEFINE_RZ_BUF_READ_BLE
319 #undef DEFINE_RZ_BUF_WRITE_BLE
320 #undef DEFINE_RZ_BUF_READ_OFFSET_BLE
321 #undef DEFINE_RZ_BUF_WRITE_OFFSET_BLE
322 
323 // sparse-specific
324 
328 
329 RZ_API bool rz_deflatew_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed, int wbits);
330 RZ_API bool rz_deflate_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed);
331 RZ_API bool rz_inflatew_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed, int wbits);
332 RZ_API bool rz_inflate_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed);
333 RZ_API bool rz_lzma_dec_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed);
334 RZ_API bool rz_lzma_enc_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed);
335 
336 #ifdef __cplusplus
337 }
338 #endif
339 
340 #endif // RZ_BUF_H
size_t len
Definition: 6502dis.c:15
lzma_index * src
Definition: index.h:567
static ut8 bytes[32]
Definition: asm_arc.c:23
static int value
Definition: cmd_api.c:93
#define RZ_API
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 count
Definition: sflib.h:98
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 static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void start
Definition: sflib.h:133
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 static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
uint16_t ut16
uint32_t ut32
const char * v
Definition: dsignal.c:12
voidpf void uLong size
Definition: ioapi.h:138
voidpf uLong offset
Definition: ioapi.h:144
const char int mode
Definition: ioapi.h:137
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
char * dst
Definition: lz4.h:724
int n
Definition: mipsasm.c:19
#define rz_warn_if_reached()
Definition: rz_assert.h:29
RZ_API bool rz_buf_sparse_populated_in(RzBuffer *b, ut64 from, ut64 to)
Definition: buf_sparse.c:339
RZ_API bool rz_buf_prepend_bytes(RZ_NONNULL RzBuffer *b, RZ_NONNULL const ut8 *buf, ut64 len)
Prepend an array of bytes to the buffer.
Definition: buf.c:846
RZ_API bool rz_inflate_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed)
inflate compressed data in RzBbuffer, use MAX_WBITS as the window size logarithm.
Definition: compression.c:360
RZ_API ut64 rz_buf_tell(RZ_NONNULL RzBuffer *b)
Return the current cursor position.
Definition: buf.c:1238
RZ_API void rz_buf_sparse_set_write_mode(RzBuffer *b, RzBufferSparseWriteMode mode)
Only for sparse RzBuffers.
Definition: buf_sparse.c:325
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_methods(RZ_NONNULL const RzBufferMethods *methods, void *init_user)
Creates a new buffer with a specific back end.
Definition: buf.c:525
ut64(* RzBufferFwdScan)(RZ_BORROW RZ_NONNULL const ut8 *buf, ut64 len, RZ_NULLABLE void *user)
Definition: rz_buf.h:136
RZ_API RZ_OWN char * rz_buf_get_nstring(RZ_NONNULL RzBuffer *b, ut64 addr, size_t size)
Get a string with a max length from the buffer.
Definition: buf.c:585
ut64(* RzBufferGetSize)(RzBuffer *b)
Definition: rz_buf.h:24
RZ_API bool rz_buf_resize(RZ_NONNULL RzBuffer *b, ut64 newsize)
Resize the buffer size.
Definition: buf.c:890
#define DEFINE_RZ_BUF_WRITE_OFFSET_BLE(size)
Definition: rz_buf.h:227
RZ_API bool rz_buf_append_bytes(RZ_NONNULL RzBuffer *b, RZ_NONNULL const ut8 *buf, ut64 len)
Append an array of bytes to the buffer.
Definition: buf.c:732
RZ_API bool rz_buf_append_nbytes(RZ_NONNULL RzBuffer *b, ut64 len)
Extend the size of the buffer.
Definition: buf.c:748
RZ_API bool rz_buf_append_ut32(RZ_NONNULL RzBuffer *b, ut32 n)
Add a ut32 number at the end of the buffer.
Definition: buf.c:776
RZ_API st64 rz_buf_fwrite_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL const ut8 *buf, RZ_NONNULL const char *fmt, int n)
...
Definition: buf.c:1056
RZ_API st64 rz_buf_seek(RZ_NONNULL RzBuffer *b, st64 addr, int whence)
Modify the current cursor position in the buffer.
Definition: buf.c:1166
RZ_API st64 rz_buf_fread(RZ_NONNULL RzBuffer *b, RZ_NONNULL ut8 *buf, RZ_NONNULL const char *fmt, int n)
...
Definition: buf.c:978
RZ_API bool rz_buf_append_ut64(RZ_NONNULL RzBuffer *b, ut64 n)
Add a ut64 number at the end of the buffer.
Definition: buf.c:790
#define RZ_BUF_CUR
Definition: rz_buf.h:15
RZ_API RZ_OWN char * rz_buf_get_string(RZ_NONNULL RzBuffer *b, ut64 addr)
Get a string from the buffer.
Definition: buf.c:628
bool(* RzBufferResize)(RzBuffer *b, ut64 newsize)
Definition: rz_buf.h:25
st64(* RzBufferSeek)(RzBuffer *b, st64 addr, int whence)
Definition: rz_buf.h:26
static ut64 rz_seek_offset(ut64 cur, ut64 length, st64 addr, int whence)
change cur according to addr and whence (RZ_BUF_SET/RZ_BUF_CUR/RZ_BUF_END)
Definition: rz_buf.h:67
RZ_API st64 rz_buf_fwrite(RZ_NONNULL RzBuffer *b, RZ_NONNULL const ut8 *buf, RZ_NONNULL const char *fmt, int n)
...
Definition: buf.c:1033
RZ_API bool rz_buf_fini(RzBuffer *b)
Free all internal data hold by the buffer.
Definition: buf.c:822
st64(* RzBufferWrite)(RzBuffer *b, const ut8 *buf, ut64 len)
Definition: rz_buf.h:23
RZ_API st64 rz_buf_write_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL const ut8 *buf, ut64 len)
Write len bytes of the buffer at the specified address.
Definition: buf.c:1197
RZ_API RzBuffer * rz_buf_ref(RzBuffer *b)
Increment the reference count of the buffer.
Definition: buf.c:668
RZ_API bool rz_lzma_enc_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed)
Compress the src buffer with LZMA algorithm and put the compressed data in dst.
Definition: compression.c:474
st64(* RzBufferRead)(RzBuffer *b, ut8 *buf, ut64 len)
Definition: rz_buf.h:22
struct rz_buf_sparse_chunk_t RzBufferSparseChunk
RZ_API RZ_OWN RzBuffer * rz_buf_new_mmap(const char *file, int flags, int mode)
Creates a new buffer from a file using rz_file_mmap.
Definition: buf.c:339
RZ_API bool rz_deflate_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed)
deflate uncompressed data in RzBbuffer to zlib or gzipped, use MAX_WBITS as the window size logarithm...
Definition: compression.c:350
RZ_API bool rz_buf_read8_at(RzBuffer *b, ut64 addr, RZ_NONNULL RZ_OUT ut8 *result)
Read a byte at the specified address in the buffer.
Definition: buf.c:876
RZ_API RZ_OWN RzBuffer * rz_buf_new_slurp(const char *file)
Creates a new buffer from a file.
Definition: buf.c:384
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_buf(RzBuffer *b)
Creates a new buffer from a source buffer.
Definition: buf.c:448
RZ_API st64 rz_buf_read_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL RZ_OUT ut8 *buf, ut64 len)
Read len bytes of the buffer at the specified address.
Definition: buf.c:1136
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_io_fd(RZ_NONNULL void *iob, int fd)
Creates a new buffer wrapping a file descriptor accessed through RzIOBind.
Definition: buf.c:490
#define DEFINE_RZ_BUF_WRITE_BLE(size)
Definition: rz_buf.h:178
RZ_API st64 rz_buf_uleb128(RZ_NONNULL RzBuffer *buffer, RZ_NONNULL ut64 *value)
Decodes ULEB128 from RzBuffer.
Definition: buf.c:1353
static st64 rz_buf_uleb128_at(RzBuffer *b, ut64 addr, ut64 *v)
Definition: rz_buf.h:142
#define DEFINE_RZ_BUF_READ_BLE(size)
Definition: rz_buf.h:153
#define RZ_BUF_END
Definition: rz_buf.h:16
RZ_API st64 rz_buf_append_string(RZ_NONNULL RzBuffer *b, RZ_NONNULL const char *str)
Append a string to the buffer.
Definition: buf.c:962
RZ_API bool rz_buf_read8(RZ_NONNULL RzBuffer *b, RZ_NONNULL RZ_OUT ut8 *result)
Read a byte at the cursor in the buffer.
Definition: buf.c:860
#define DEFINE_RZ_BUF_READ_OFFSET_BLE(size)
Read a big endian or little endian (ut16, ut32, ut64) at the specified address or cursor in the buffe...
Definition: rz_buf.h:217
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_pointers(const ut8 *bytes, ut64 len, bool steal)
Creates a new buffer with a bytes array.
Definition: buf.c:552
RZ_API st64 rz_buf_fread_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL ut8 *buf, RZ_NONNULL const char *fmt, int n)
...
Definition: buf.c:1001
RZ_API bool rz_buf_write8_at(RZ_NONNULL RzBuffer *b, ut64 addr, ut8 value)
Write a byte at the specified address in the buffer.
Definition: buf.c:948
void(* RzBufferFreeWholeBuf)(RzBuffer *b)
Definition: rz_buf.h:28
RZ_API st64 rz_buf_write(RZ_NONNULL RzBuffer *b, RZ_NONNULL const ut8 *buf, ut64 len)
Write len bytes of the buffer at the cursor.
Definition: buf.c:1181
RZ_API st64 rz_buf_insert_bytes(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL const ut8 *buf, ut64 len)
Insert an array of bytes in the buffer.
Definition: buf.c:1087
RzBufferSparseWriteMode
Definition: rz_buf.h:59
@ RZ_BUF_SPARSE_WRITE_MODE_SPARSE
all writes are performed in the sparse overlay
Definition: rz_buf.h:60
@ RZ_BUF_SPARSE_WRITE_MODE_THROUGH
all writes are performed in the underlying base buffer
Definition: rz_buf.h:61
RZ_API const RzBufferSparseChunk * rz_buf_sparse_get_chunks(RzBuffer *b, RZ_NONNULL size_t *count)
Only for sparse RzBuffers, get all sparse data chunks currently populated.
Definition: buf_sparse.c:313
RZ_API bool rz_buf_write8(RZ_NONNULL RzBuffer *b, ut8 value)
Write a byte at the cursor in the buffer.
Definition: buf.c:931
#define RZ_BUF_SET
Definition: rz_buf.h:14
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_string(RZ_NONNULL const char *msg)
Creates a new buffer from a string.
Definition: buf.c:570
RZ_API bool rz_buf_dump(RZ_NONNULL RzBuffer *buf, RZ_NONNULL const char *file)
Dump the content of the buffer to a file.
Definition: buf.c:806
bool(* RzBufferFini)(RzBuffer *b)
Definition: rz_buf.h:21
ut8 *(* RzBufferGetWholeBuf)(RzBuffer *b, ut64 *sz)
Definition: rz_buf.h:27
RZ_API bool rz_buf_append_ut16(RZ_NONNULL RzBuffer *b, ut16 n)
Add a ut16 number at the end of the buffer.
Definition: buf.c:762
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
Definition: buf.c:1253
RZ_API bool rz_inflatew_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed, int wbits)
Definition: compression.c:331
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_io(RZ_NONNULL void *iob)
Creates a new buffer wrapping the memory map exposed by RzIOBind.
Definition: buf.c:509
RZ_API bool rz_buf_append_buf(RZ_NONNULL RzBuffer *b, RZ_NONNULL RzBuffer *a)
Append the content of the buffer a to the buffer b.
Definition: buf.c:685
RZ_API RZ_OWN RzBuffer * rz_buf_new_empty(ut64 len)
Creates a new empty buffer with a predefined size;.
Definition: buf.c:285
RZ_API RZ_OWN RzBuffer * rz_buf_new_slice(RzBuffer *b, ut64 offset, ut64 size)
Creates a new buffer from a slice of another buffer.
Definition: buf.c:364
RZ_API RZ_OWN RzBuffer * rz_buf_new_sparse(ut8 Oxff)
Creates a sparse buffer.
Definition: buf.c:408
RZ_API bool rz_buf_set_bytes(RZ_NONNULL RzBuffer *b, RZ_NONNULL const ut8 *buf, ut64 len)
Replace the content of the buffer with the bytes array.
Definition: buf.c:905
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_bytes(RZ_NULLABLE RZ_BORROW const ut8 *bytes, ut64 len)
Creates a new buffer with a bytes array.
Definition: buf.c:465
bool(* RzBufferInit)(RzBuffer *b, const void *user)
Definition: rz_buf.h:20
RZ_API ut64 rz_buf_fwd_scan(RZ_NONNULL RzBuffer *b, ut64 start, ut64 amount, RZ_NONNULL RzBufferFwdScan fwd_scan, RZ_NULLABLE void *user)
Scans buffer linearly in chunks calling fwd_scan for each chunk.
Definition: buf.c:1303
RZ_API st64 rz_buf_read(RZ_NONNULL RzBuffer *b, RZ_NONNULL RZ_OUT ut8 *buf, ut64 len)
struct rz_buffer_methods_t RzBufferMethods
RZ_DEPRECATE RZ_API RZ_BORROW ut8 * rz_buf_data(RZ_NONNULL RzBuffer *b, RZ_NONNULL RZ_OUT ut64 *size)
Return a borrowed array of bytes representing the buffer data.
Definition: buf.c:1287
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
RZ_API RZ_OWN RzBuffer * rz_buf_new_file(const char *file, int perm, int mode)
Creates a new buffer from a file.
Definition: buf.c:317
RZ_API void rz_buf_set_overflow_byte(RZ_NONNULL RzBuffer *b, ut8 Oxff)
Change the overflow byte used in the RZ_BUFFER_SPARSE.
Definition: buf.c:1272
static st64 rz_buf_sleb128_at(RzBuffer *b, ut64 addr, st64 *v)
Definition: rz_buf.h:146
RZ_API bool rz_deflatew_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed, int wbits)
Definition: compression.c:327
RZ_API bool rz_lzma_dec_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed)
Decompress the src buffer with LZMA algorithm and put the decompressed data in dst.
Definition: compression.c:462
RZ_API RZ_OWN char * rz_buf_to_string(RZ_NONNULL RzBuffer *b)
Stringify the buffer.
Definition: buf.c:642
RZ_API RZ_OWN RzBuffer * rz_buf_new_sparse_overlay(RzBuffer *b, RzBufferSparseWriteMode write_mode)
Creates a sparse buffer from a already populated buffer.
Definition: buf.c:426
RZ_API st64 rz_buf_sleb128(RZ_NONNULL RzBuffer *buffer, RZ_NONNULL st64 *value)
Decodes SLEB128 from RzBuffer.
Definition: buf.c:1384
RZ_API bool rz_buf_append_buf_slice(RZ_NONNULL RzBuffer *b, RZ_NONNULL RzBuffer *a, ut64 offset, ut64 size)
Append a slice of the buffer a to the buffer b.
Definition: buf.c:705
#define RZ_NULLABLE
Definition: rz_types.h:65
#define RZ_OWN
Definition: rz_types.h:62
#define RZ_OUT
Definition: rz_types.h:51
#define RZ_NONNULL
Definition: rz_types.h:64
#define RZ_BORROW
Definition: rz_types.h:63
#define RZ_DEPRECATE
Definition: rz_types.h:66
#define st64
Definition: rz_types_base.h:10
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
Definition: sfsocketcall.h:123
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr socklen_t static fromlen const void const struct sockaddr to
Definition: sfsocketcall.h:125
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
static struct sockaddr static addrlen static backlog const void msg
Definition: sfsocketcall.h:119
#define b(i)
Definition: sha256.c:42
#define a(i)
Definition: sha256.c:41
Definition: buffer.h:15
Definition: gzappend.c:170
ut8 * data
size == to - from + 1
Definition: rz_buf.h:56
ut64 from
inclusive
Definition: rz_buf.h:54
ut64 to
inclusive, there can't be chunks with size == 0
Definition: rz_buf.h:55
int fd
Definition: rz_buf.h:50
const RzBufferMethods * methods
Definition: rz_buf.h:44
int refctr
Definition: rz_buf.h:49
void * priv
Definition: rz_buf.h:45
ut8 * whole_buf
Definition: rz_buf.h:46
bool readonly
Definition: rz_buf.h:47
ut8 Oxff_priv
Definition: rz_buf.h:48
RzBufferWrite write
Definition: rz_buf.h:35
RzBufferInit init
Definition: rz_buf.h:32
RzBufferSeek seek
Definition: rz_buf.h:38
RzBufferGetSize get_size
Definition: rz_buf.h:36
RzBufferFreeWholeBuf free_whole_buf
Definition: rz_buf.h:40
RzBufferGetWholeBuf get_whole_buf
Definition: rz_buf.h:39
RzBufferRead read
Definition: rz_buf.h:34
RzBufferFini fini
Definition: rz_buf.h:33
RzBufferResize resize
Definition: rz_buf.h:37
#define bool
Definition: sysdefs.h:146
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static const z80_opcode fd[]
Definition: z80_tab.h:997
static int addr
Definition: z80asm.c:58