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

Go to the source code of this file.

Functions

static bool check_buffer (RzBuffer *b)
 
static bool load_buffer (RzBinFile *bf, RzBinObject *obj, RzBuffer *buf, Sdb *sdb)
 
static ut64 baddr (RzBinFile *bf)
 
static RzBinInfoinfo (RzBinFile *bf)
 
static RzListsections (RzBinFile *bf)
 
static RzListentries (RzBinFile *bf)
 

Variables

RzBinPlugin rz_bin_plugin_prg
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ baddr()

static ut64 baddr ( RzBinFile bf)
static

Definition at line 16 of file bin_prg.c.

16  {
17  ut16 base;
18  if (!rz_buf_read_le16_at(bf->buf, 0, &base)) {
19  return 0;
20  }
21 
22  return base;
23 }
uint16_t ut16
#define rz_buf_read_le16_at(b, addr, result)
Definition: rz_buf.h:270
RzBuffer * buf
Definition: rz_bin.h:303

References rz_bin_file_t::buf, and rz_buf_read_le16_at.

Referenced by entries(), and sections().

◆ check_buffer()

static bool check_buffer ( RzBuffer b)
static

Definition at line 7 of file bin_prg.c.

7  {
8  // no magic
9  return false;
10 }

◆ entries()

static RzList* entries ( RzBinFile bf)
static

Definition at line 63 of file bin_prg.c.

63  {
64  RzList *ret = rz_list_newf(free);
65  if (!ret) {
66  return NULL;
67  }
68  RzBinAddr *binaddr = RZ_NEW0(RzBinAddr);
69  if (!binaddr) {
70  return ret;
71  }
72  binaddr->paddr = 2;
73  binaddr->vaddr = baddr(bf);
74  rz_list_append(ret, binaddr);
75  return ret;
76 }
static ut64 baddr(RzBinFile *bf)
Definition: bin_prg.c:16
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
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 RZ_NEW0(x)
Definition: rz_types.h:284
ut64 vaddr
Definition: rz_bin.h:186
ut64 paddr
Definition: rz_bin.h:187

References baddr(), free(), NULL, rz_bin_addr_t::paddr, rz_list_append(), rz_list_newf(), RZ_NEW0, and rz_bin_addr_t::vaddr.

◆ info()

static RzBinInfo* info ( RzBinFile bf)
static

Definition at line 25 of file bin_prg.c.

25  {
26  RzBinInfo *ret = RZ_NEW0(RzBinInfo);
27  if (!ret) {
28  return NULL;
29  }
30  ret->file = strdup(bf->file);
31  ret->type = strdup("PRG");
32  ret->machine = strdup("Commodore 64");
33  ret->os = strdup("c64");
34  ret->arch = strdup("6502");
35  ret->bits = 8;
36  ret->has_va = 1;
37  return ret;
38 }
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")
char * file
Definition: rz_bin.h:299
int has_va
Definition: rz_bin.h:228
char * type
Definition: rz_bin.h:211
char * os
Definition: rz_bin.h:219
char * machine
Definition: rz_bin.h:216
char * file
Definition: rz_bin.h:210
char * arch
Definition: rz_bin.h:214

References rz_bin_info_t::arch, rz_bin_info_t::bits, rz_bin_info_t::file, rz_bin_file_t::file, rz_bin_info_t::has_va, rz_bin_info_t::machine, NULL, rz_bin_info_t::os, 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 12 of file bin_prg.c.

12  {
13  return true;
14 }

◆ sections()

static RzList* sections ( RzBinFile bf)
static

Definition at line 40 of file bin_prg.c.

40  {
42  if (!ret) {
43  return NULL;
44  }
45  ut64 sz = rz_buf_size(bf->buf);
46  if (sz < 2) {
47  return ret;
48  }
50  if (!section) {
51  return ret;
52  }
53  section->name = strdup("prg");
54  section->paddr = 2;
55  section->size = sz - 2;
56  section->vaddr = baddr(bf);
57  section->vsize = sz - 2;
58  section->perm = RZ_PERM_RWX;
59  rz_list_append(ret, section);
60  return ret;
61 }
RZ_API void rz_bin_section_free(RzBinSection *bs)
Definition: bin.c:1116
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
#define RZ_PERM_RWX
Definition: rz_types.h:98
uint32_t size
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References baddr(), rz_bin_file_t::buf, NULL, rz_bin_section_free(), rz_buf_size(), rz_list_append(), rz_list_newf(), RZ_NEW0, RZ_PERM_RWX, section::size, strdup(), and ut64().

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_BIN,
}
RzBinPlugin rz_bin_plugin_prg
Definition: bin_prg.c:78
@ 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 92 of file bin_prg.c.

◆ rz_bin_plugin_prg

RzBinPlugin rz_bin_plugin_prg
Initial value:
= {
.name = "prg",
.desc = "C64 PRG",
.license = "LGPL3",
.load_buffer = load_buffer,
.baddr = baddr,
.check_buffer = check_buffer,
.entries = entries,
.sections = sections,
.info = info,
}
RZ_API RZ_OWN RzList * rz_bin_maps_of_file_sections(RZ_NONNULL RzBinFile *binfile)
Create a list of RzBinMap from RzBinSections queried from the given file.
Definition: bin.c:1040
static bool load_buffer(RzBinFile *bf, RzBinObject *obj, RzBuffer *buf, Sdb *sdb)
Definition: bin_prg.c:12
static bool check_buffer(RzBuffer *b)
Definition: bin_prg.c:7
static RzBinInfo * info(RzBinFile *bf)
Definition: bin_prg.c:25
static RzList * entries(RzBinFile *bf)
Definition: bin_prg.c:63
static RzList * sections(RzBinFile *bf)
Definition: bin_prg.c:40

Definition at line 78 of file bin_prg.c.