Rizin
unix-like reverse engineering framework and cli tools
bin_ne.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2009-2019 GustavoLCR <gugulcr@gmail.com>
2 // SPDX-FileCopyrightText: 2009-2019 nibble <nibble.ds@gmail.com>
3 // SPDX-FileCopyrightText: 2009-2019 pancake <pancake@nopcode.org>
4 // SPDX-FileCopyrightText: 2009-2019 alvarofe <alvaro.felipe91@gmail.com>
5 // SPDX-License-Identifier: LGPL-3.0-only
6 
7 #include <rz_bin.h>
8 #include "../i/private.h"
9 #include "../format/ne/ne.h"
10 
11 static bool check_buffer(RzBuffer *b) {
13  if (length <= 0x3d) {
14  return false;
15  }
16 
17  ut16 idx;
18  if (!rz_buf_read_le16_at(b, 0x3c, &idx)) {
19  return false;
20  }
21 
22  if ((ut64)idx + 26 < length) {
23  ut8 buf[2];
24  rz_buf_read_at(b, 0, buf, sizeof(buf));
25  if (!memcmp(buf, "MZ", 2)) {
26  rz_buf_read_at(b, idx, buf, sizeof(buf));
27  if (!memcmp(buf, "NE", 2)) {
28  return true;
29  }
30  }
31  }
32  return false;
33 }
34 
35 static bool load_buffer(RzBinFile *bf, RzBinObject *obj, RzBuffer *buf, Sdb *sdb) {
36  rz_return_val_if_fail(bf && obj && buf, false);
38  if (res) {
39  obj->bin_obj = res;
40  return true;
41  }
42  return false;
43 }
44 
45 static void destroy(RzBinFile *bf) {
46  rz_bin_ne_free(bf->o->bin_obj);
47 }
48 
49 static void header(RzBinFile *bf) {
50  struct rz_bin_t *rbin = bf->rbin;
51  rz_bin_ne_obj_t *ne = bf->o->bin_obj;
52  rbin->cb_printf("Signature: NE\n");
53  rbin->cb_printf("MajLinkerVersion: %d\n", ne->ne_header->MajLinkerVersion);
54  rbin->cb_printf("MinLinkerVersion: %d\n", ne->ne_header->MinLinkerVersion);
55  rbin->cb_printf("EntryTableOffset: 0x%04x\n", ne->ne_header->EntryTableOffset);
56  rbin->cb_printf("EntryTableLength: %d\n", ne->ne_header->EntryTableLength);
57  rbin->cb_printf("FileLoadCRC: %08x\n", ne->ne_header->FileLoadCRC);
58  rbin->cb_printf("ProgFlags: %d\n", ne->ne_header->ProgFlags);
59  rbin->cb_printf("ApplFlags: %d\n", ne->ne_header->ApplFlags);
60  rbin->cb_printf("AutoDataSegIndex: %d\n", ne->ne_header->AutoDataSegIndex);
61  rbin->cb_printf("InitHeapSize: %d\n", ne->ne_header->InitHeapSize);
62  rbin->cb_printf("InitStackSize: %d\n", ne->ne_header->InitStackSize);
63  rbin->cb_printf("EntryPointCSIndex: %d\n", ne->ne_header->csEntryPoint);
64  rbin->cb_printf("EntryPointIPOff: 0x%04x\n", ne->ne_header->ipEntryPoint);
65  rbin->cb_printf("InitStack: %d\n", ne->ne_header->InitStack);
66  rbin->cb_printf("SegCount: %d\n", ne->ne_header->SegCount);
67  rbin->cb_printf("ModuleRefsCount: %d\n", ne->ne_header->ModRefs);
68  rbin->cb_printf("NonResNamesTblSiz: 0x%x\n", ne->ne_header->NoResNamesTabSiz);
69  rbin->cb_printf("SegTableOffset: 0x%x\n", ne->ne_header->SegTableOffset);
70  rbin->cb_printf("ResourceTblOff: 0x%x\n", ne->ne_header->ResTableOffset);
71  rbin->cb_printf("ResidentNameTblOff: 0x%x\n", ne->ne_header->ResidNamTable);
72  rbin->cb_printf("ModuleRefTblOff: 0x%x\n", ne->ne_header->ModRefTable);
73  rbin->cb_printf("ImportNameTblOff: 0x%x\n", ne->ne_header->ImportNameTable);
74  rbin->cb_printf("OffStartNonResTab: %d\n", ne->ne_header->OffStartNonResTab);
75  rbin->cb_printf("MovEntryCount: %d\n", ne->ne_header->MovEntryCount);
76  rbin->cb_printf("FileAlnSzShftCnt: %d\n", ne->ne_header->FileAlnSzShftCnt);
77  rbin->cb_printf("nResTabEntries: %d\n", ne->ne_header->nResTabEntries);
78  rbin->cb_printf("OS: %s\n", ne->os);
79  rbin->cb_printf("OS2EXEFlags: %x\n", ne->ne_header->OS2EXEFlags);
80  rbin->cb_printf("retThunkOffset: %d\n", ne->ne_header->retThunkOffset);
81  rbin->cb_printf("segRefThunksOff: %d\n", ne->ne_header->segrefthunksoff);
82  rbin->cb_printf("mincodeswap: %d\n", ne->ne_header->mincodeswap);
83  rbin->cb_printf("winver: %d.%d\n", ne->ne_header->expctwinver[1], ne->ne_header->expctwinver[0]);
84 }
85 
87  rz_bin_ne_obj_t *ne = bf->o->bin_obj;
89  if (i) {
90  i->bits = 16;
91  i->arch = strdup("x86");
92  i->os = strdup(ne->os);
93  i->claimed_checksum = rz_str_newf("%08x", ne->ne_header->FileLoadCRC);
94  }
95  return i;
96 }
97 
99  return rz_bin_ne_get_entrypoints(bf->o->bin_obj);
100 }
101 
103  return rz_bin_ne_get_symbols(bf->o->bin_obj);
104 }
105 
107  return rz_bin_ne_get_imports(bf->o->bin_obj);
108 }
109 
111  return rz_bin_ne_get_segments(bf->o->bin_obj);
112 }
113 
115  return rz_bin_ne_get_relocs(bf->o->bin_obj);
116 }
117 
119  .name = "ne",
120  .desc = "NE format plugin",
121  .author = "GustavoLCR",
122  .license = "LGPL3",
123  .check_buffer = &check_buffer,
124  .load_buffer = &load_buffer,
125  .destroy = &destroy,
126  .header = &header,
127  .info = &info,
128  .entries = &entries,
129  .sections = &sections,
130  .symbols = &symbols,
131  .imports = &imports,
132  .relocs = &relocs,
133  .minstrlen = 4
134 };
135 
136 #ifndef RZ_PLUGIN_INCORE
139  .data = &rz_bin_plugin_ne,
141 };
142 #endif
lzma_index ** i
Definition: index.h:629
RzList * entries(RzBinFile *bf)
Definition: bin_ne.c:98
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
static bool load_buffer(RzBinFile *bf, RzBinObject *obj, RzBuffer *buf, Sdb *sdb)
Definition: bin_ne.c:35
RzList * symbols(RzBinFile *bf)
Definition: bin_ne.c:102
static void header(RzBinFile *bf)
Definition: bin_ne.c:49
static void destroy(RzBinFile *bf)
Definition: bin_ne.c:45
RZ_API RzLibStruct rizin_plugin
Definition: bin_ne.c:137
static bool check_buffer(RzBuffer *b)
Definition: bin_ne.c:11
RzList * imports(RzBinFile *bf)
Definition: bin_ne.c:106
RzList * sections(RzBinFile *bf)
Definition: bin_ne.c:110
RzBinPlugin rz_bin_plugin_ne
Definition: bin_ne.c:118
RzList * relocs(RzBinFile *bf)
Definition: bin_ne.c:114
#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 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
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")
int idx
Definition: setup.py:197
RzList * rz_bin_ne_get_symbols(rz_bin_ne_obj_t *bin)
Definition: ne.c:121
rz_bin_ne_obj_t * rz_bin_ne_new_buf(RzBuffer *buf, bool verbose)
Definition: ne.c:672
void rz_bin_ne_free(rz_bin_ne_obj_t *bin)
Definition: ne.c:659
RzList * rz_bin_ne_get_imports(rz_bin_ne_obj_t *bin)
Definition: ne.c:348
RzList * rz_bin_ne_get_entrypoints(rz_bin_ne_obj_t *bin)
Definition: ne.c:384
RzList * rz_bin_ne_get_segments(rz_bin_ne_obj_t *bin)
Definition: ne.c:78
RzList * rz_bin_ne_get_relocs(rz_bin_ne_obj_t *bin)
Definition: ne.c:457
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#define rz_buf_read_le16_at(b, addr, result)
Definition: rz_buf.h:270
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 ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
@ RZ_LIB_TYPE_BIN
Definition: rz_lib.h:75
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_VERSION
Definition: rz_version.h:8
#define b(i)
Definition: sha256.c:42
XX curplugin == o->plugin.
Definition: rz_bin.h:298
RzBinObject * o
Definition: rz_bin.h:305
struct rz_bin_t * rbin
Definition: rz_bin.h:316
void * bin_obj
Definition: rz_bin.h:293
char * name
Definition: rz_bin.h:509
char * version
Definition: rz_bin.h:512
PrintfCallback cb_printf
Definition: rz_bin.h:345
bool verbose
Definition: rz_bin.h:359
Definition: sdb.h:63
ut64(WINAPI *w32_GetEnabledXStateFeatures)()