Rizin
unix-like reverse engineering framework and cli tools
bin_cgc.c File Reference
#include "bin_elf.inc"

Go to the source code of this file.

Macros

#define RZ_BIN_CGC   1
 
#define B(x, y)   rz_buf_append_bytes(buf, (const ut8 *)(x), y)
 
#define D(x)   rz_buf_append_ut32(buf, x)
 
#define H(x)   rz_buf_append_ut16(buf, x)
 
#define Z(x)   rz_buf_append_nbytes(buf, x)
 
#define W(x, y, z)   rz_buf_write_at(buf, x, (const ut8 *)(y), z)
 
#define WZ(x, y)
 

Functions

static bool check_buffer (RzBuffer *buf)
 
static RzBuffercreate (RzBin *bin, const ut8 *code, int codelen, const ut8 *data, int datalen, RzBinArchOptions *opt)
 

Variables

struct rz_bin_dbginfo_t rz_bin_dbginfo_elf
 
RzBinPlugin rz_bin_plugin_cgc
 

Macro Definition Documentation

◆ B

#define B (   x,
 
)    rz_buf_append_bytes(buf, (const ut8 *)(x), y)

◆ D

#define D (   x)    rz_buf_append_ut32(buf, x)

◆ H

#define H (   x)    rz_buf_append_ut16(buf, x)

◆ RZ_BIN_CGC

#define RZ_BIN_CGC   1

Definition at line 5 of file bin_cgc.c.

◆ W

#define W (   x,
  y,
 
)    rz_buf_write_at(buf, x, (const ut8 *)(y), z)

◆ WZ

#define WZ (   x,
 
)
Value:
p_tmp = rz_buf_size(buf); \
Z(x); \
W(p_tmp, y, strlen(y))
voidpf void * buf
Definition: ioapi.h:138
int x
Definition: mipsasm.c:20
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225

◆ Z

#define Z (   x)    rz_buf_append_nbytes(buf, x)

Function Documentation

◆ check_buffer()

static bool check_buffer ( RzBuffer buf)
static

Definition at line 10 of file bin_cgc.c.

10  {
11  ut8 tmp[SCGCMAG + 1];
12  int r = rz_buf_read_at(buf, 0, tmp, sizeof(tmp));
13  return r > SCGCMAG && !memcmp(tmp, CGCMAG, SCGCMAG) && tmp[4] != 2;
14 }
#define r
Definition: crypto_rc6.c:12
#define CGCMAG
Definition: elf_specs.h:82
#define SCGCMAG
Definition: elf_specs.h:83
uint8_t ut8
Definition: lh5801.h:11
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

References CGCMAG, r, rz_buf_read_at(), SCGCMAG, and autogen_x86imm::tmp.

◆ create()

static RzBuffer* create ( RzBin bin,
const ut8 code,
int  codelen,
const ut8 data,
int  datalen,
RzBinArchOptions opt 
)
static

Definition at line 16 of file bin_cgc.c.

16  {
17  ut32 filesize, code_va, code_pa, phoff;
18  ut32 p_start, p_phoff, p_phdr;
19  ut32 p_ehdrsz, p_phdrsz;
20  ut16 ehdrsz, phdrsz;
21  ut32 p_vaddr, p_paddr, p_fs, p_fs2;
22  ut32 baddr = 0x8048000;
24 
25 #define B(x, y) rz_buf_append_bytes(buf, (const ut8 *)(x), y)
26 #define D(x) rz_buf_append_ut32(buf, x)
27 #define H(x) rz_buf_append_ut16(buf, x)
28 #define Z(x) rz_buf_append_nbytes(buf, x)
29 #define W(x, y, z) rz_buf_write_at(buf, x, (const ut8 *)(y), z)
30 #define WZ(x, y) \
31  p_tmp = rz_buf_size(buf); \
32  Z(x); \
33  W(p_tmp, y, strlen(y))
34 
35  B("\x7F"
36  "CGC"
37  "\x01\x01\x01\x43",
38  8);
39  Z(8);
40  H(2); // ET_EXEC
41  H(3); // e_machne = EM_I386
42 
43  D(1);
44  p_start = rz_buf_size(buf);
45  D(-1); // _start
46  p_phoff = rz_buf_size(buf);
47  D(-1); // phoff -- program headers offset
48  D(0); // shoff -- section headers offset
49  D(0); // flags
50  p_ehdrsz = rz_buf_size(buf);
51  H(-1); // ehdrsz
52  p_phdrsz = rz_buf_size(buf);
53  H(-1); // phdrsz
54  H(1);
55  H(0);
56  H(0);
57  H(0);
58  // phdr:
59  p_phdr = rz_buf_size(buf);
60  D(1);
61  D(0);
62  p_vaddr = rz_buf_size(buf);
63  D(-1); // vaddr = $$
64  p_paddr = rz_buf_size(buf);
65  D(-1); // paddr = $$
66  p_fs = rz_buf_size(buf);
67  D(-1); // filesize
68  p_fs2 = rz_buf_size(buf);
69  D(-1); // filesize
70  D(5); // flags
71  D(0x1000); // align
72 
73  ehdrsz = p_phdr;
74  phdrsz = rz_buf_size(buf) - p_phdr;
75  code_pa = rz_buf_size(buf);
76  code_va = code_pa + baddr;
77  phoff = 0x34; // p_phdr ;
78  filesize = code_pa + codelen + datalen;
79 
80  W(p_start, &code_va, 4);
81  W(p_phoff, &phoff, 4);
82  W(p_ehdrsz, &ehdrsz, 2);
83  W(p_phdrsz, &phdrsz, 2);
84 
85  code_va = baddr; // hack
86  W(p_vaddr, &code_va, 4);
87  code_pa = baddr; // hack
88  W(p_paddr, &code_pa, 4);
89 
90  W(p_fs, &filesize, 4);
91  W(p_fs2, &filesize, 4);
92 
93  B(code, codelen);
94 
95  if (data && datalen > 0) {
96  // ut32 data_section = buf->length;
97  RZ_LOG_WARN("DATA section not support for ELF yet\n");
98  B(data, datalen);
99  }
100  return buf;
101 }
static ut64 baddr(RzBinFile *bf)
Definition: bin_any.c:58
#define W(x, y, z)
#define H(x)
#define Z(x)
#define B(x, y)
#define D(x)
#define NULL
Definition: cris-opc.c:27
uint16_t ut16
uint32_t ut32
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_bytes(RZ_NULLABLE RZ_BORROW const ut8 *bytes, ut64 len)
Creates a new buffer with a bytes array.
Definition: buf.c:465
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
Definition: inftree9.h:24

References B, baddr(), D, H, NULL, rz_buf_new_with_bytes(), rz_buf_size(), RZ_LOG_WARN, W, and Z.

Referenced by rz_main_rz_bin(), sdb_ns(), and sdb_ns_path().

Variable Documentation

◆ rz_bin_dbginfo_elf

struct rz_bin_dbginfo_t rz_bin_dbginfo_elf
extern

◆ rz_bin_plugin_cgc

RzBinPlugin rz_bin_plugin_cgc
Initial value:
= {
.name = "cgc",
.desc = "CGC format rz_bin plugin",
.license = "LGPL3",
.get_sdb = &get_sdb,
.load_buffer = load_buffer,
.check_buffer = &check_buffer,
.baddr = &baddr,
.boffset = &boffset,
.binsym = &binsym,
.entries = &entries,
.virtual_files = &virtual_files,
.maps = &maps,
.sections = &sections,
.symbols = &symbols,
.minstrlen = 4,
.imports = &imports,
.strings = &strings,
.info = &info,
.fields = &fields,
.size = &size,
.libs = &libs,
.relocs = &relocs,
.create = &create,
.file_type = get_file_type,
.regstate = regstate,
.section_type_to_string = &Elf_(rz_bin_elf_section_type_to_string),
.section_flag_to_rzlist = &Elf_(rz_bin_elf_section_flag_to_rzlist),
.destroy = destroy
}
const aarch64_field fields[]
Definition: aarch64-opc.c:205
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 Sdb * get_sdb(RzBinFile *bf)
Definition: bin_art.c:60
static RzList * maps(RzBinFile *bf)
Definition: bin_bf.c:116
static RzList * virtual_files(RzBinFile *bf)
Definition: bin_bflt.c:167
static RzBuffer * create(RzBin *bin, const ut8 *code, int codelen, const ut8 *data, int datalen, RzBinArchOptions *opt)
Definition: bin_cgc.c:16
static bool check_buffer(RzBuffer *buf)
Definition: bin_cgc.c:10
static RzBinAddr * binsym(RzBinFile *bf, RzBinSpecialSymbol sym)
Definition: bin_coff.c:47
static RzList * libs(RzBinFile *bf)
Definition: bin_coff.c:379
static char * regstate(RzBinFile *bf)
Definition: bin_dmp64.c:252
RzList * entries(RzBinFile *bf)
Definition: bin_ne.c:98
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
RzList * symbols(RzBinFile *bf)
Definition: bin_ne.c:102
RzList * imports(RzBinFile *bf)
Definition: bin_ne.c:106
RzList * sections(RzBinFile *bf)
Definition: bin_ne.c:110
RzList * relocs(RzBinFile *bf)
Definition: bin_ne.c:114
static ut64 boffset(RzBinFile *bf)
Definition: bin_ninds.c:39
RZ_OWN char *Elf_() rz_bin_elf_section_type_to_string(ut64 type)
Return a string representing the elf type.
Definition: elf_sections.c:422
RZ_OWN RzList *Elf_() rz_bin_elf_section_flag_to_rzlist(ut64 flag)
Return a list of string representing flag options.
Definition: elf_sections.c:298
#define Elf_(name)
Definition: elf_specs.h:32
checking print the parsed form of the magic use in n conjunction with m to debug a new magic file n before installing it n output MIME type strings(--mime-type and\n" " --mime-encoding)\n") OPT('s'
voidpf void uLong size
Definition: ioapi.h:138

Definition at line 103 of file bin_cgc.c.