Rizin
unix-like reverse engineering framework and cli tools
zimg.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2009-2015 ninjahacker <wardjm@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_types.h>
5 #include <rz_util.h>
6 #include "zimg.h"
7 
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
struct rz_bin_zimg_obj_t * rz_bin_zimg_new_buf(RzBuffer *buf)
Definition: zimg.c:8