Rizin
unix-like reverse engineering framework and cli tools
bin_any.c File Reference
#include <rz_types.h>
#include <rz_util.h>
#include <rz_lib.h>
#include <rz_bin.h>
#include <rz_magic.h>

Go to the source code of this file.

Functions

static char * get_filetype (RzBuffer *b)
 
static RzBinInfoinfo (RzBinFile *bf)
 
static bool load_buffer (RzBinFile *bf, RzBinObject *obj, RzBuffer *buf, Sdb *sdb)
 
static void destroy (RzBinFile *bf)
 
static ut64 baddr (RzBinFile *bf)
 

Variables

RzBinPlugin rz_bin_plugin_any
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ baddr()

◆ destroy()

static void destroy ( RzBinFile bf)
static

Definition at line 54 of file bin_any.c.

54  {
55  rz_buf_free(bf->o->bin_obj);
56 }
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
Definition: buf.c:1253
RzBinObject * o
Definition: rz_bin.h:305
void * bin_obj
Definition: rz_bin.h:293

References rz_bin_object_t::bin_obj, rz_bin_file_t::o, and rz_buf_free().

◆ get_filetype()

static char* get_filetype ( RzBuffer b)
static

Definition at line 11 of file bin_any.c.

11  {
12  ut8 buf[4096] = { 0 };
13  char *res = NULL;
14  RzMagic *ck = rz_magic_new(0);
15  if (!ck) {
16  return NULL;
17  }
18  const char *tmp = NULL;
19  // TODO: dir.magic not honored here
20  char *m = rz_path_system(RZ_SDB_MAGIC);
21  rz_magic_load(ck, m);
22  free(m);
23  rz_buf_read_at(b, 0, buf, sizeof(buf));
24  tmp = rz_magic_buffer(ck, buf, sizeof(buf));
25  if (tmp) {
26  res = strdup(tmp);
27  }
29  return res;
30 }
static RzMagic * ck
Definition: cmd_magic.c:8
#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
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")
RZ_API const char * rz_magic_buffer(RzMagic *ms, const void *buf, size_t nb)
Definition: magic.c:308
RZ_API RzMagic * rz_magic_new(int flags)
Definition: magic.c:235
RZ_API bool rz_magic_load(RzMagic *ms, const char *magicfile)
Definition: magic.c:278
RZ_API void rz_magic_free(RzMagic *ms)
Definition: magic.c:254
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 char * rz_path_system(RZ_NULLABLE const char *path)
Return the full system path of the given subpath path.
Definition: path.c:162
#define RZ_SDB_MAGIC
Definition: rz_userconf.h:86
#define b(i)
Definition: sha256.c:42

References b, ck, free(), regress::m, NULL, rz_buf_read_at(), rz_magic_buffer(), rz_magic_free(), rz_magic_load(), rz_magic_new(), rz_path_system(), RZ_SDB_MAGIC, strdup(), and autogen_x86imm::tmp.

Referenced by info().

◆ info()

static RzBinInfo* info ( RzBinFile bf)
static

Definition at line 32 of file bin_any.c.

32  {
33  RzBinInfo *ret = RZ_NEW0(RzBinInfo);
34  if (!ret) {
35  return NULL;
36  }
37  ret->lang = "";
38  ret->file = bf->file ? strdup(bf->file) : NULL;
39  ret->type = get_filetype(bf->buf);
40  ret->has_pi = 0;
41  ret->has_canary = 0;
42  ret->has_retguard = -1;
43  ret->big_endian = 0;
44  ret->has_va = 0;
45  ret->has_nx = 0;
46  ret->dbg_info = 0;
47  return ret;
48 }
static char * get_filetype(RzBuffer *b)
Definition: bin_any.c:11
#define RZ_NEW0(x)
Definition: rz_types.h:284
char * file
Definition: rz_bin.h:299
RzBuffer * buf
Definition: rz_bin.h:303
int has_va
Definition: rz_bin.h:228
char * type
Definition: rz_bin.h:211
int has_canary
Definition: rz_bin.h:230
int has_pi
Definition: rz_bin.h:229
int has_nx
Definition: rz_bin.h:234
const char * lang
Definition: rz_bin.h:224
char * file
Definition: rz_bin.h:210
ut64 dbg_info
Definition: rz_bin.h:240
int has_retguard
Definition: rz_bin.h:231
int big_endian
Definition: rz_bin.h:235

References rz_bin_info_t::big_endian, rz_bin_file_t::buf, rz_bin_info_t::dbg_info, rz_bin_info_t::file, rz_bin_file_t::file, get_filetype(), rz_bin_info_t::has_canary, rz_bin_info_t::has_nx, rz_bin_info_t::has_pi, rz_bin_info_t::has_retguard, rz_bin_info_t::has_va, rz_bin_info_t::lang, NULL, RZ_NEW0, strdup(), and rz_bin_info_t::type.

◆ load_buffer()

static bool load_buffer ( RzBinFile bf,
RzBinObject obj,
RzBuffer buf,
Sdb sdb 
)
static

Definition at line 50 of file bin_any.c.

50  {
51  return true;
52 }

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_BIN,
}
RzBinPlugin rz_bin_plugin_any
Definition: bin_any.c:62
@ RZ_LIB_TYPE_BIN
Definition: rz_lib.h:75
#define RZ_VERSION
Definition: rz_version.h:8
char * version
Definition: rz_bin.h:512

Definition at line 74 of file bin_any.c.

◆ rz_bin_plugin_any

RzBinPlugin rz_bin_plugin_any
Initial value:
= {
.name = "any",
.desc = "Dummy format rz_bin plugin",
.license = "LGPL3",
.load_buffer = &load_buffer,
.destroy = &destroy,
.baddr = &baddr,
.info = info,
.minstrlen = 0,
}
static bool load_buffer(RzBinFile *bf, RzBinObject *obj, RzBuffer *buf, Sdb *sdb)
Definition: bin_any.c:50
static void destroy(RzBinFile *bf)
Definition: bin_any.c:54
static RzBinInfo * info(RzBinFile *bf)
Definition: bin_any.c:32
static ut64 baddr(RzBinFile *bf)
Definition: bin_any.c:58

Definition at line 62 of file bin_any.c.