Rizin
unix-like reverse engineering framework and cli tools
bin_xtr_pemixed.c File Reference
#include <rz_types.h>
#include <rz_util.h>
#include <rz_lib.h>
#include <rz_bin.h>
#include "pe/pemixed.h"

Go to the source code of this file.

Functions

static RzListoneshotall (RzBin *bin, const ut8 *buf, ut64 size)
 
static RzBinXtrDataoneshot (RzBin *bin, const ut8 *buf, ut64 size, int subbin_type)
 
static void free_xtr (void *xtr_obj)
 
static void destroy (RzBin *bin)
 
static bool check_buffer (RzBuffer *b)
 
static void fill_metadata_info_from_hdr (RzBinXtrMetadata *meta, void *foo)
 

Variables

RzBinXtrPlugin rz_bin_xtr_plugin_xtr_pemixed
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ check_buffer()

static bool check_buffer ( RzBuffer b)
static

Definition at line 21 of file bin_xtr_pemixed.c.

21  {
22  return false;
23 #if 0
24  if (!bytes) {
25  return false;
26  }
27  if (sz <= 0x3d) { //less than size of MS-DOS header which is 64bytes
28  return false;
29  }
30  ut32 idx = (bytes[0x3c] | (bytes[0x3d]<<8));
31  if (sz > idx + 0x18 + 2) {
32  /* Here PE signature for usual PE files
33  * and PL signature for Phar Lap TNT DOS extender 32bit executables
34  */
35  if (!memcmp (bytes, "MZ", 2)) {
36  if (!memcmp (bytes+idx, "PE", 2) &&
37  !memcmp (bytes+idx+0x18, "\x0b\x01", 2)) {
38  return true;
39  }
40  // TODO: Add one more indicator, to prevent false positives
41  if (!memcmp (bytes+idx, "PL", 2)) {
42  return true;
43  }
44  }
45  }
46  return false;
47 #endif
48 }
static ut8 bytes[32]
Definition: asm_arc.c:23
uint32_t ut32
int idx
Definition: setup.py:197

References bytes, and setup::idx.

◆ destroy()

static void destroy ( RzBin bin)
static

Definition at line 17 of file bin_xtr_pemixed.c.

17  {
18  free_xtr(bin->cur->xtr_obj);
19 }
static void free_xtr(void *xtr_obj)
Definition: malloc.c:26

References free_xtr().

◆ fill_metadata_info_from_hdr()

static void fill_metadata_info_from_hdr ( RzBinXtrMetadata meta,
void *  foo 
)
static

Definition at line 74 of file bin_xtr_pemixed.c.

74  { // struct Pe_32_rz_bin_pemixed_obj_t* pe_bin){
75  meta->arch = NULL;
76  meta->bits = 0;
77  meta->machine = NULL;
78  meta->type = NULL;
79  meta->libname = NULL;
80  meta->xtr_type = "net";
81  // strcpy (meta->xtr_type, "net");
82 }
#define NULL
Definition: cris-opc.c:27
const char * xtr_type
Definition: rz_bin.h:374

References rz_bin_xtr_metadata_t::arch, rz_bin_xtr_metadata_t::bits, rz_bin_xtr_metadata_t::libname, rz_bin_xtr_metadata_t::machine, NULL, rz_bin_xtr_metadata_t::type, and rz_bin_xtr_metadata_t::xtr_type.

Referenced by oneshot().

◆ free_xtr()

static void free_xtr ( void *  xtr_obj)
static

Definition at line 13 of file bin_xtr_pemixed.c.

13  {
14  rz_bin_pemixed_free((struct rz_bin_pemixed_obj_t *)xtr_obj);
15 }
void * rz_bin_pemixed_free(struct rz_bin_pemixed_obj_t *bin)
Definition: pemixed.c:137

References rz_bin_pemixed_free().

Referenced by destroy().

◆ oneshot()

static RzBinXtrData * oneshot ( RzBin bin,
const ut8 buf,
ut64  size,
int  subbin_type 
)
static

Definition at line 85 of file bin_xtr_pemixed.c.

85  {
86  rz_return_val_if_fail(bin && bin->cur && buf, false);
87 
88  if (!bin->cur->xtr_obj) {
89  bin->cur->xtr_obj = rz_bin_pemixed_from_bytes_new(buf, size);
90  }
91 
92  struct rz_bin_pemixed_obj_t *fb = bin->cur->xtr_obj;
93  // this function is prolly not nessescary
94  struct PE_(rz_bin_pe_obj_t) *pe = rz_bin_pemixed_extract(fb, sub_bin_type);
95  if (!pe) {
96  return NULL;
97  }
99  if (!metadata) {
100  return NULL;
101  }
102  fill_metadata_info_from_hdr(metadata, pe);
103  return rz_bin_xtrdata_new(pe->b, 0, pe->size, 3, metadata);
104 }
RZ_API RzBinXtrData * rz_bin_xtrdata_new(RzBuffer *buf, ut64 offset, ut64 size, ut32 file_count, RzBinXtrMetadata *metadata)
Definition: bin.c:47
static void fill_metadata_info_from_hdr(RzBinXtrMetadata *meta, void *foo)
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
struct rz_bin_pemixed_obj_t * rz_bin_pemixed_from_bytes_new(const ut8 *buf, ut64 size)
Definition: pemixed.c:159
RzBinPEObj * rz_bin_pemixed_extract(struct rz_bin_pemixed_obj_t *bin, int sub_bin)
Definition: pemixed.c:115
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#define RZ_NEW0(x)
Definition: rz_types.h:284

References fill_metadata_info_from_hdr(), NULL, rz_bin_pemixed_extract(), rz_bin_pemixed_from_bytes_new(), rz_bin_xtrdata_new(), RZ_NEW0, and rz_return_val_if_fail.

Referenced by oneshotall(), rz_core_task_enqueue_oneshot(), rz_core_task_schedule(), uv__signal_register_handler(), and uv__signal_start().

◆ oneshotall()

static RzList * oneshotall ( RzBin bin,
const ut8 buf,
ut64  size 
)
static

Definition at line 51 of file bin_xtr_pemixed.c.

51  {
52  // extract dos componenent first
54 
55  if (!data) {
56  return NULL;
57  }
58  // XXX - how do we validate a valid narch?
60  rz_list_append(res, data);
61 
62  if ((data = oneshot(bin, buf, size, SUB_BIN_NATIVE))) {
63  rz_list_append(res, data);
64  }
65 
66  if ((data = oneshot(bin, buf, size, SUB_BIN_NET))) {
67  rz_list_append(res, data);
68  }
69 
70  return res;
71 }
RZ_API void rz_bin_xtrdata_free(void *data_)
Definition: bin.c:61
static RzBinXtrData * oneshot(RzBin *bin, const ut8 *buf, ut64 size, int subbin_type)
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
#define SUB_BIN_NATIVE
Definition: pemixed.h:8
#define SUB_BIN_DOS
Definition: pemixed.h:7
#define SUB_BIN_NET
Definition: pemixed.h:9

References NULL, oneshot(), rz_bin_xtrdata_free(), rz_list_append(), rz_list_newf(), SUB_BIN_DOS, SUB_BIN_NATIVE, and SUB_BIN_NET.

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.data = &rz_bin_xtr_plugin_pemixed,
.version = RZ_VERSION
}
@ RZ_LIB_TYPE_BIN_XTR
Definition: rz_lib.h:76
#define RZ_VERSION
Definition: rz_version.h:8

Definition at line 120 of file bin_xtr_pemixed.c.

◆ rz_bin_xtr_plugin_xtr_pemixed

RzBinXtrPlugin rz_bin_xtr_plugin_xtr_pemixed
Initial value:
= {
.name = "xtr.pemixed",
.desc = "Extract sub-binaries in PE files",
.load = NULL,
.extract = NULL,
.extractall = NULL,
.destroy = &destroy,
.extract_from_bytes = &oneshot,
.extractall_from_bytes = &oneshotall,
.free_xtr = &free_xtr,
.check_buffer = &check_buffer,
}
static RzList * oneshotall(RzBin *bin, const ut8 *buf, ut64 size)
static void destroy(RzBin *bin)
static bool check_buffer(RzBuffer *b)

Definition at line 106 of file bin_xtr_pemixed.c.