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

Go to the source code of this file.

Functions

struct rz_bin_zimg_obj_trz_bin_zimg_new_buf (RzBuffer *buf)
 

Function Documentation

◆ rz_bin_zimg_new_buf()

struct rz_bin_zimg_obj_t* rz_bin_zimg_new_buf ( RzBuffer buf)

Definition at line 8 of file zimg.c.

8  {
10  if (!bin) {
11  goto fail;
12  }
13  bin->size = rz_buf_size(buf);
14  bin->b = rz_buf_ref(buf);
15  if (rz_buf_size(bin->b) < sizeof(struct zimg_header_t)) {
16  goto fail;
17  }
18  rz_buf_read_at(bin->b, 0, (ut8 *)&bin->header, sizeof(bin->header));
19  return bin;
20 
21 fail:
22  if (bin) {
23  rz_buf_free(bin->b);
24  free(bin);
25  }
26  return NULL;
27 }
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
RZ_API RzBuffer * rz_buf_ref(RzBuffer *b)
Increment the reference count of the buffer.
Definition: buf.c:668
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 void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
Definition: buf.c:1253
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
#define RZ_NEW0(x)
Definition: rz_types.h:284
Definition: malloc.c:26
#define fail(test)
Definition: tests.h:29

References fail, free(), NULL, rz_buf_free(), rz_buf_read_at(), rz_buf_ref(), rz_buf_size(), and RZ_NEW0.

Referenced by load_buffer().