Rizin
unix-like reverse engineering framework and cli tools
bin_vsf.c File Reference
#include <rz_bin.h>
#include "vsf/vsf_specs.h"

Go to the source code of this file.

Macros

#define VICE_MAGIC_LEN   sizeof(VICE_MAGIC) - 1
 
#define CMP_MODULE(x)   memcmp(module.module_name, x, sizeof(x) - 1)
 

Functions

static Sdbget_sdb (RzBinFile *bf)
 
static bool check_buffer (RzBuffer *b)
 
static bool load_buffer (RzBinFile *bf, RzBinObject *obj, RzBuffer *b, Sdb *sdb)
 
static RzListmem (RzBinFile *bf)
 
static RzListsections (RzBinFile *bf)
 
static RzBinInfoinfo (RzBinFile *bf)
 
static RzListsymbols (RzBinFile *bf)
 
static void destroy (RzBinFile *bf)
 
static RzListentries (RzBinFile *bf)
 

Variables

static const char VICE_MAGIC [] = "VICE Snapshot File\032"
 
static const char VICE_MAINCPU [] = "MAINCPU"
 
static const char VICE_C64MEM [] = "C64MEM"
 
static const char VICE_C64ROM [] = "C64ROM"
 
static const char VICE_C128MEM [] = "C128MEM"
 
static const char VICE_C128ROM [] = "C128ROM"
 
struct {
   const char *   name
 
   const char *   desc
 
   const int   offset_mem
 
   const int   ram_size
 
_machines []
 
static const int MACHINES_MAX = sizeof(_machines) / sizeof(_machines[0])
 
RzBinPlugin rz_bin_plugin_vsf
 
RZ_API RzLibStruct rizin_plugin
 

Macro Definition Documentation

◆ CMP_MODULE

#define CMP_MODULE (   x)    memcmp(module.module_name, x, sizeof(x) - 1)

◆ VICE_MAGIC_LEN

#define VICE_MAGIC_LEN   sizeof(VICE_MAGIC) - 1

Definition at line 10 of file bin_vsf.c.

Function Documentation

◆ check_buffer()

static bool check_buffer ( RzBuffer b)
static

Definition at line 34 of file bin_vsf.c.

34  {
35  ut8 magic[VICE_MAGIC_LEN];
36  if (rz_buf_read_at(b, 0, magic, VICE_MAGIC_LEN) == VICE_MAGIC_LEN) {
37  return !memcmp(magic, VICE_MAGIC, VICE_MAGIC_LEN);
38  }
39  return false;
40 }
static const char VICE_MAGIC[]
Definition: bin_vsf.c:9
#define VICE_MAGIC_LEN
Definition: bin_vsf.c:10
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
#define b(i)
Definition: sha256.c:42

References b, rz_buf_read_at(), VICE_MAGIC, and VICE_MAGIC_LEN.

Referenced by load_buffer().

◆ destroy()

static void destroy ( RzBinFile bf)
static

Definition at line 498 of file bin_vsf.c.

498  {
499  struct rz_bin_vsf_obj *obj = (struct rz_bin_vsf_obj *)bf->o->bin_obj;
500  free(obj->maincpu);
501  free(obj);
502 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RzBinObject * o
Definition: rz_bin.h:305
void * bin_obj
Definition: rz_bin.h:293
struct vsf_maincpu * maincpu
Definition: vsf_specs.h:77

References rz_bin_object_t::bin_obj, free(), rz_bin_vsf_obj::maincpu, and rz_bin_file_t::o.

◆ entries()

static RzList* entries ( RzBinFile bf)
static

Definition at line 504 of file bin_vsf.c.

504  {
505  struct rz_bin_vsf_obj *vsf_obj = (struct rz_bin_vsf_obj *)bf->o->bin_obj;
506  if (!vsf_obj) {
507  return NULL;
508  }
509  const int m_idx = vsf_obj->machine_idx;
510 
511  RzList *ret;
512  RzBinAddr *ptr = NULL;
513  if (!(ret = rz_list_new())) {
514  return NULL;
515  }
516  int offset = _machines[m_idx].offset_mem;
517  // PC
518  if (!(ptr = RZ_NEW0(RzBinAddr))) {
519  return ret;
520  }
521  ptr->paddr = vsf_obj->mem + offset;
522  ptr->vaddr = vsf_obj->maincpu ? vsf_obj->maincpu->pc : 0;
523  rz_list_append(ret, ptr);
524 
525  // IRQ: 0xFFFE or 0x0314 ?
526  // if (!(ptr = RZ_NEW0 (RzBinAddr)))
527  // return ret;
528  // ptr->paddr = (vsf_obj->mem + offset) - (void*) bf->buf->buf;
529  // ptr->vaddr = 0x314; // or 0xfffe ?
530  // rz_list_append (ret, ptr);
531 
532  return ret;
533 }
static const struct @207 _machines[]
#define NULL
Definition: cris-opc.c:27
voidpf uLong offset
Definition: ioapi.h:144
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
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
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4

References _machines, rz_bin_object_t::bin_obj, if(), rz_bin_vsf_obj::machine_idx, rz_bin_vsf_obj::maincpu, rz_bin_vsf_obj::mem, NULL, rz_bin_file_t::o, rz_bin_addr_t::paddr, rz_list_append(), rz_list_new(), RZ_NEW0, and rz_bin_addr_t::vaddr.

◆ get_sdb()

static Sdb* get_sdb ( RzBinFile bf)
static

Definition at line 28 of file bin_vsf.c.

28  {
29  rz_return_val_if_fail(bf && bf->o && bf->o->bin_obj, NULL);
30  struct rz_bin_vsf_obj *bin = (struct rz_bin_vsf_obj *)bf->o->bin_obj;
31  return bin->kv;
32 }
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
Definition: malloc.c:26

References rz_bin_object_t::bin_obj, NULL, rz_bin_file_t::o, and rz_return_val_if_fail.

◆ info()

static RzBinInfo* info ( RzBinFile bf)
static

Definition at line 288 of file bin_vsf.c.

288  {
289 
290  struct rz_bin_vsf_obj *vsf_obj = (struct rz_bin_vsf_obj *)bf->o->bin_obj;
291  if (!vsf_obj) {
292  return NULL;
293  }
294 
295  const int m_idx = vsf_obj->machine_idx;
296 
297  RzBinInfo *ret = NULL;
298  struct vsf_hdr hdr;
299  memset(&hdr, 0, sizeof(hdr));
300  int read = rz_buf_read_at(bf->buf, 0, (ut8 *)&hdr, sizeof(hdr));
301  if (read != sizeof(hdr)) {
302  eprintf("Truncated Header\n");
303  return NULL;
304  }
305  if (!(ret = RZ_NEW0(RzBinInfo))) {
306  return NULL;
307  }
308  ret->file = strdup(bf->file);
309  ret->type = strdup("Snapshot");
310  ret->machine = strdup(_machines[m_idx].desc);
311  ret->os = strdup(_machines[m_idx].name);
312  ret->arch = strdup("6502");
313  ret->bits = 8;
314  ret->has_va = true;
315 
316  if (!vsf_obj->maincpu) {
317  // safe to return, sdb will not be populated
318  return ret;
319  }
320 
321  sdb_num_set(vsf_obj->kv, "vsf.reg_a", vsf_obj->maincpu->ac, 0);
322  sdb_num_set(vsf_obj->kv, "vsf.reg_x", vsf_obj->maincpu->xr, 0);
323  sdb_num_set(vsf_obj->kv, "vsf.reg_y", vsf_obj->maincpu->yr, 0);
324  sdb_num_set(vsf_obj->kv, "vsf.reg_sp", vsf_obj->maincpu->sp, 0);
325  sdb_num_set(vsf_obj->kv, "vsf.reg_pc", vsf_obj->maincpu->pc, 0);
326  sdb_num_set(vsf_obj->kv, "vsf.reg_st", vsf_obj->maincpu->st, 0);
327  sdb_num_set(vsf_obj->kv, "vsf.clock", vsf_obj->maincpu->clk, 0);
328 
329  return ret;
330 }
const char * desc
Definition: bin_vsf.c:19
return memset(p, 0, total)
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 int sdb_num_set(Sdb *s, const char *key, ut64 v, ut32 cas)
Definition: num.c:25
#define eprintf(x, y...)
Definition: rlcc.c:7
Definition: z80asm.h:102
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
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
int read(izstream &zs, T *x, Items items)
Definition: zstream.h:115

References _machines, rz_bin_info_t::arch, rz_bin_object_t::bin_obj, rz_bin_info_t::bits, rz_bin_file_t::buf, desc, eprintf, rz_bin_info_t::file, rz_bin_file_t::file, rz_bin_info_t::has_va, if(), rz_bin_vsf_obj::kv, rz_bin_info_t::machine, rz_bin_vsf_obj::machine_idx, rz_bin_vsf_obj::maincpu, memset(), NULL, rz_bin_file_t::o, rz_bin_info_t::os, read(), rz_buf_read_at(), RZ_NEW0, sdb_num_set(), strdup(), and rz_bin_info_t::type.

◆ load_buffer()

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

Definition at line 43 of file bin_vsf.c.

43  {
44  ut64 offset = 0;
45  struct rz_bin_vsf_obj *res = NULL;
46  if (check_buffer(bf->buf)) {
47  int i = 0;
48  if (!(res = RZ_NEW0(struct rz_bin_vsf_obj))) {
49  return false;
50  }
51  offset = rz_offsetof(struct vsf_hdr, machine);
52  if (offset > bf->size) {
53  free(res);
54  return false;
55  }
56  char machine[20];
57  int l = rz_buf_read_at(bf->buf, offset, (ut8 *)machine, sizeof(machine));
58  if (l < 0) {
59  free(res);
60  return false;
61  }
62  for (; i < MACHINES_MAX; i++) {
63  if (offset + strlen(_machines[i].name) > bf->size) {
64  free(res);
65  return false;
66  }
67  if (!strncmp(machine, _machines[i].name, strlen(_machines[i].name))) {
68  res->machine_idx = i;
69  break;
70  }
71  }
72  if (i >= MACHINES_MAX) {
73  eprintf("Unsupported machine type\n");
74  free(res);
75  return false;
76  }
77  // read all VSF modules
78  offset = sizeof(struct vsf_hdr);
79  ut64 sz = rz_buf_size(bf->buf);
80  while (offset < sz) {
81  struct vsf_module module;
82  int read = rz_buf_fread_at(bf->buf, offset, (ut8 *)&module, "16ccci", 1);
83  if (read != sizeof(module)) {
84  eprintf("Truncated Header\n");
85  free(res);
86  return false;
87  }
88 #define CMP_MODULE(x) memcmp(module.module_name, x, sizeof(x) - 1)
89  if (!CMP_MODULE(VICE_C64MEM) && !module.major) {
90  res->mem = offset + read;
91  } else if (!CMP_MODULE(VICE_C64ROM) && !module.major) {
92  res->rom = offset + read;
93  } else if (!CMP_MODULE(VICE_C128MEM) && !module.major) {
94  res->mem = offset + read;
95  } else if (!CMP_MODULE(VICE_C128ROM) && !module.major) {
96  res->rom = offset + read;
97  } else if (!CMP_MODULE(VICE_MAINCPU) && module.major == 1) {
98  res->maincpu = RZ_NEW(struct vsf_maincpu);
99  rz_buf_read_at(bf->buf, offset + read, (ut8 *)res->maincpu, sizeof(*res->maincpu));
100  }
101 #undef CMP_MODULE
102  offset += module.length;
103  if (module.length == 0) {
104  eprintf("Malformed VSF module with length 0\n");
105  break;
106  }
107  }
108  }
109  if (res) {
110  res->kv = sdb_new0();
111  sdb_ns_set(sdb, "info", res->kv);
112  }
113  obj->bin_obj = res;
114  return true;
115 }
lzma_index ** i
Definition: index.h:629
static const int MACHINES_MAX
Definition: bin_vsf.c:26
static const char VICE_C64MEM[]
Definition: bin_vsf.c:12
static const char VICE_MAINCPU[]
Definition: bin_vsf.c:11
static const char VICE_C128MEM[]
Definition: bin_vsf.c:14
static bool check_buffer(RzBuffer *b)
Definition: bin_vsf.c:34
#define CMP_MODULE(x)
static const char VICE_C64ROM[]
Definition: bin_vsf.c:13
static const char VICE_C128ROM[]
Definition: bin_vsf.c:15
RZ_API int sdb_ns_set(Sdb *s, const char *name, Sdb *r)
Definition: ns.c:156
RZ_API st64 rz_buf_fread_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL ut8 *buf, RZ_NONNULL const char *fmt, int n)
...
Definition: buf.c:1001
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
#define RZ_NEW(x)
Definition: rz_types.h:285
#define rz_offsetof(type, member)
Definition: rz_types.h:360
RZ_API Sdb * sdb_new0(void)
Definition: sdb.c:43
Definition: sftypes.h:77
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References _machines, rz_bin_object_t::bin_obj, rz_bin_file_t::buf, check_buffer(), CMP_MODULE, eprintf, free(), i, rz_bin_vsf_obj::kv, rz_bin_vsf_obj::machine_idx, MACHINES_MAX, rz_bin_vsf_obj::maincpu, rz_bin_vsf_obj::mem, NULL, read(), rz_bin_vsf_obj::rom, rz_buf_fread_at(), rz_buf_read_at(), rz_buf_size(), RZ_NEW, RZ_NEW0, rz_offsetof, sdb_new0(), sdb_ns_set(), rz_bin_file_t::size, ut64(), VICE_C128MEM, VICE_C128ROM, VICE_C64MEM, VICE_C64ROM, and VICE_MAINCPU.

◆ mem()

static RzList* mem ( RzBinFile bf)
static

Definition at line 117 of file bin_vsf.c.

117  {
118  // FIXME: What does Mem do? Should I remove it ?
119  struct rz_bin_vsf_obj *vsf_obj = (struct rz_bin_vsf_obj *)bf->o->bin_obj;
120  if (!vsf_obj) {
121  return NULL;
122  }
123  RzList *ret;
124  RzBinMem *m;
125  if (!(ret = rz_list_new())) {
126  return NULL;
127  }
128  ret->free = free;
129  if (!(m = RZ_NEW0(RzBinMem))) {
130  rz_list_free(ret);
131  return NULL;
132  }
133  m->name = strdup("RAM");
134  m->addr = 0; // start address
135  m->size = _machines[vsf_obj->machine_idx].ram_size;
136  m->perms = rz_str_rwx("rwx");
137  rz_list_append(ret, m);
138  return ret;
139 }
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
RZ_API int rz_str_rwx(const char *str)
Definition: str.c:318
RzListFree free
Definition: rz_list.h:21

References _machines, rz_bin_object_t::bin_obj, rz_list_t::free, free(), if(), regress::m, rz_bin_vsf_obj::machine_idx, NULL, rz_bin_file_t::o, rz_list_append(), rz_list_free(), rz_list_new(), RZ_NEW0, rz_str_rwx(), and strdup().

◆ sections()

static RzList* sections ( RzBinFile bf)
static

Definition at line 141 of file bin_vsf.c.

141  {
142  struct rz_bin_vsf_obj *vsf_obj = (struct rz_bin_vsf_obj *)bf->o->bin_obj;
143  if (!vsf_obj) {
144  return NULL;
145  }
146 
147  RzList *ret = NULL;
148  RzBinSection *ptr = NULL;
149  if (!(ret = rz_list_new())) {
150  return NULL;
151  }
152  const int m_idx = vsf_obj->machine_idx;
153  // Rizin doesn't support BANK switching.
154  // But by adding the ROM sections first, and then the RAM
155  // it kind of simulate bank switching since users can remove existing sections
156  // and the RAM section won't overwrite the ROM since it was added last.
157  if (vsf_obj->rom) {
158  if (!vsf_obj->machine_idx) {
159  // Commodore 64 ROMS
160  // BASIC (0xa000 - 0xbfff)
161  if (!(ptr = RZ_NEW0(RzBinSection))) {
162  return ret;
163  }
164  ptr->name = strdup("BASIC");
165  ptr->paddr = vsf_obj->rom + rz_offsetof(struct vsf_c64rom, basic);
166  ptr->size = 1024 * 8; // (8k)
167  ptr->vaddr = 0xa000;
168  ptr->vsize = 1024 * 8; // BASIC size (8k)
169  ptr->perm = RZ_PERM_RX;
170  rz_list_append(ret, ptr);
171 
172  // KERNAL (0xe000 - 0xffff)
173  if (!(ptr = RZ_NEW0(RzBinSection))) {
174  return ret;
175  }
176  ptr->name = strdup("KERNAL");
177  ptr->paddr = vsf_obj->rom + rz_offsetof(struct vsf_c64rom, kernal);
178  ptr->size = 1024 * 8; // (8k)
179  ptr->vaddr = 0xe000;
180  ptr->vsize = 1024 * 8; // KERNAL size (8k)
181  ptr->perm = RZ_PERM_RX;
182  rz_list_append(ret, ptr);
183 
184  // CHARGEN section ignored
185  } else {
186  // Commodore 128 ROMS
187  // BASIC (0x4000 - 0xafff)
188  if (!(ptr = RZ_NEW0(RzBinSection))) {
189  return ret;
190  }
191  ptr->name = strdup("BASIC");
192  ptr->paddr = vsf_obj->rom + rz_offsetof(struct vsf_c128rom, basic);
193  ptr->size = 1024 * 28; // (28k)
194  ptr->vaddr = 0x4000;
195  ptr->vsize = 1024 * 28; // BASIC size (28k)
196  ptr->perm = RZ_PERM_RX;
197  rz_list_append(ret, ptr);
198 
199  // MONITOR (0xb000 - 0xbfff)
200  if (!(ptr = RZ_NEW0(RzBinSection))) {
201  return ret;
202  }
203  ptr->name = strdup("MONITOR");
204  // skip first 28kb since "BASIC" and "MONITOR" share the same section in VSF
205  ptr->paddr = vsf_obj->rom + rz_offsetof(struct vsf_c128rom, basic) + 1024 * 28;
206  ptr->size = 1024 * 4; // (4k)
207  ptr->vaddr = 0xb000;
208  ptr->vsize = 1024 * 4; // BASIC size (4k)
209  ptr->perm = RZ_PERM_RX;
210  rz_list_append(ret, ptr);
211 
212  // EDITOR (0xc000 - 0xcfff)
213  if (!(ptr = RZ_NEW0(RzBinSection))) {
214  return ret;
215  }
216  ptr->name = strdup("EDITOR");
217  ptr->paddr = vsf_obj->rom + rz_offsetof(struct vsf_c128rom, editor);
218  ptr->size = 1024 * 4; // (4k)
219  ptr->vaddr = 0xc000;
220  ptr->vsize = 1024 * 4; // BASIC size (4k)
221  ptr->perm = RZ_PERM_RX;
222  rz_list_append(ret, ptr);
223 
224  // KERNAL (0xe000 - 0xffff)
225  if (!(ptr = RZ_NEW0(RzBinSection))) {
226  return ret;
227  }
228  ptr->name = strdup("KERNAL");
229  ptr->paddr = vsf_obj->rom + rz_offsetof(struct vsf_c128rom, kernal);
230  ptr->size = 1024 * 8; // (8k)
231  ptr->vaddr = 0xe000;
232  ptr->vsize = 1024 * 8; // KERNAL size (8k)
233  ptr->perm = RZ_PERM_RX;
234  rz_list_append(ret, ptr);
235 
236  // CHARGEN section ignored
237  }
238  }
239 
240  if (vsf_obj->mem) {
241  int offset = _machines[m_idx].offset_mem;
242  if (!vsf_obj->machine_idx) {
243  // RAM C64 (0x0000 - 0xffff)
244  int size = _machines[m_idx].ram_size;
245  if (!(ptr = RZ_NEW0(RzBinSection))) {
246  return ret;
247  }
248  ptr->name = strdup("RAM");
249  ptr->paddr = vsf_obj->mem + offset;
250  ptr->size = size;
251  ptr->vaddr = 0x0;
252  ptr->vsize = size;
253  ptr->perm = RZ_PERM_RWX;
254  rz_list_append(ret, ptr);
255  } else {
256  // RAM C128 (0x0000 - 0xffff): Bank 0
257  // RAM C128 (0x0000 - 0xffff): Bank 1
258 
259  // size of each bank: 64k
260  int size = 1024 * 64;
261  if (!(ptr = RZ_NEW0(RzBinSection))) {
262  return ret;
263  }
264  ptr->name = strdup("RAM BANK 0");
265  ptr->paddr = vsf_obj->mem + offset;
266  ptr->size = size;
267  ptr->vaddr = 0x0;
268  ptr->vsize = size;
269  ptr->perm = RZ_PERM_RWX;
270  rz_list_append(ret, ptr);
271 
272  if (!(ptr = RZ_NEW0(RzBinSection))) {
273  return ret;
274  }
275  ptr->name = strdup("RAM BANK 1");
276  ptr->paddr = vsf_obj->mem + offset + size;
277  ptr->size = size;
278  ptr->vaddr = 0x0;
279  ptr->vsize = size;
280  ptr->perm = RZ_PERM_RWX;
281  rz_list_append(ret, ptr);
282  }
283  }
284 
285  return ret;
286 }
voidpf void uLong size
Definition: ioapi.h:138
#define RZ_PERM_RX
Definition: rz_types.h:97
#define RZ_PERM_RWX
Definition: rz_types.h:98
char * name
Definition: rz_bin.h:619

References _machines, rz_bin_object_t::bin_obj, if(), rz_bin_vsf_obj::machine_idx, rz_bin_vsf_obj::mem, rz_bin_section_t::name, NULL, rz_bin_file_t::o, rz_bin_section_t::paddr, rz_bin_section_t::perm, rz_bin_vsf_obj::rom, rz_list_append(), rz_list_new(), RZ_NEW0, rz_offsetof, RZ_PERM_RWX, RZ_PERM_RX, rz_bin_section_t::size, strdup(), rz_bin_section_t::vaddr, and rz_bin_section_t::vsize.

◆ symbols()

static RzList* symbols ( RzBinFile bf)
static

Definition at line 332 of file bin_vsf.c.

332  {
333 
334  static const struct {
335  const ut16 address;
336  const char *symbol_name;
337  } _symbols[] = {
338  // {0xfffa, "NMI_VECTOR_LSB"},
339  // {0xfffb, "NMI_VECTOR_MSB"},
340  // {0xfffe, "IRQ_VECTOR_LSB"},
341  // {0xffff, "IRQ_VECTOR_MSB"},
342 
343  // Defines taken from c64.inc from cc65
344  // I/O: VIC
345  { 0xd000, "VIC_SPR0_X" },
346  { 0xd001, "VIC_SPR0_Y" },
347  { 0xd002, "VIC_SPR1_X" },
348  { 0xd003, "VIC_SPR1_Y" },
349  { 0xd004, "VIC_SPR2_X" },
350  { 0xd005, "VIC_SPR2_Y" },
351  { 0xd006, "VIC_SPR3_X" },
352  { 0xd007, "VIC_SPR3_Y" },
353  { 0xd008, "VIC_SPR4_X" },
354  { 0xd009, "VIC_SPR4_Y" },
355  { 0xd00a, "VIC_SPR5_X" },
356  { 0xd00b, "VIC_SPR5_Y" },
357  { 0xd00c, "VIC_SPR6_X" },
358  { 0xd00d, "VIC_SPR6_Y" },
359  { 0xd00e, "VIC_SPR7_X" },
360  { 0xd00f, "VIC_SPR7_Y" },
361  { 0xd010, "VIC_SPR_HI_X" },
362  { 0xd015, "VIC_SPR_ENA" },
363  { 0xd017, "VIC_SPR_EXP_Y" },
364  { 0xd01d, "VIC_SPR_EXP_X" },
365  { 0xd01c, "VIC_SPR_MCOLOR" },
366  { 0xd01b, "VIC_SPR_BG_PRzIO" },
367 
368  { 0xd025, "VIC_SPR_MCOLOR0" },
369  { 0xd026, "VIC_SPR_MCOLOR1" },
370 
371  { 0xd027, "VIC_SPR0_COLOR" },
372  { 0xd028, "VIC_SPR1_COLOR" },
373  { 0xd029, "VIC_SPR2_COLOR" },
374  { 0xd02A, "VIC_SPR3_COLOR" },
375  { 0xd02B, "VIC_SPR4_COLOR" },
376  { 0xd02C, "VIC_SPR5_COLOR" },
377  { 0xd02D, "VIC_SPR6_COLOR" },
378  { 0xd02E, "VIC_SPR7_COLOR" },
379 
380  { 0xd011, "VIC_CTRL1" },
381  { 0xd016, "VIC_CTRL2" },
382 
383  { 0xd012, "VIC_HLINE" },
384 
385  { 0xd013, "VIC_LPEN_X" },
386  { 0xd014, "VIC_LPEN_Y" },
387 
388  { 0xd018, "VIC_VIDEO_ADR" },
389 
390  { 0xd019, "VIC_IRR" },
391  { 0xd01a, "VIC_IMR" },
392 
393  { 0xd020, "VIC_BORDERCOLOR" },
394  { 0xd021, "VIC_BG_COLOR0" },
395  { 0xd022, "VIC_BG_COLOR1" },
396  { 0xd023, "VIC_BG_COLOR2" },
397  { 0xd024, "VIC_BG_COLOR3" },
398 
399  // 128 stuff
400  { 0xd02F, "VIC_KBD_128" },
401  { 0xd030, "VIC_CLK_128" },
402 
403  // I/O: SID
404  { 0xD400, "SID_S1Lo" },
405  { 0xD401, "SID_S1Hi" },
406  { 0xD402, "SID_PB1Lo" },
407  { 0xD403, "SID_PB1Hi" },
408  { 0xD404, "SID_Ctl1" },
409  { 0xD405, "SID_AD1" },
410  { 0xD406, "SID_SUR1" },
411 
412  { 0xD407, "SID_S2Lo" },
413  { 0xD408, "SID_S2Hi" },
414  { 0xD409, "SID_PB2Lo" },
415  { 0xD40A, "SID_PB2Hi" },
416  { 0xD40B, "SID_Ctl2" },
417  { 0xD40C, "SID_AD2" },
418  { 0xD40D, "SID_SUR2" },
419 
420  { 0xD40E, "SID_S3Lo" },
421  { 0xD40F, "SID_S3Hi" },
422  { 0xD410, "SID_PB3Lo" },
423  { 0xD411, "SID_PB3Hi" },
424  { 0xD412, "SID_Ctl3" },
425  { 0xD413, "SID_AD3" },
426  { 0xD414, "SID_SUR3" },
427 
428  { 0xD415, "SID_FltLo" },
429  { 0xD416, "SID_FltHi" },
430  { 0xD417, "SID_FltCtl" },
431  { 0xD418, "SID_Amp" },
432  { 0xD419, "SID_ADConv1" },
433  { 0xD41A, "SID_ADConv2" },
434  { 0xD41B, "SID_Noise" },
435  { 0xD41C, "SID_Read3" },
436 
437  // I/O: VDC (128 only)
438  { 0xd600, "VDC_INDEX" },
439  { 0xd601, "VDC_DATA" },
440 
441  // I/O: CIAs
442  { 0xDC00, "CIA1_PRA" },
443  { 0xDC01, "CIA1_PRB" },
444  { 0xDC02, "CIA1_DDRA" },
445  { 0xDC03, "CIA1_DDRB" },
446  { 0xDC08, "CIA1_TOD10" },
447  { 0xDC09, "CIA1_TODSEC" },
448  { 0xDC0A, "CIA1_TODMIN" },
449  { 0xDC0B, "CIA1_TODHR" },
450  { 0xDC0D, "CIA1_ICR" },
451  { 0xDC0E, "CIA1_CRA" },
452  { 0xDC0F, "CIA1_CRB" },
453 
454  { 0xDD00, "CIA2_PRA" },
455  { 0xDD01, "CIA2_PRB" },
456  { 0xDD02, "CIA2_DDRA" },
457  { 0xDD03, "CIA2_DDRB" },
458  { 0xDD08, "CIA2_TOD10" },
459  { 0xDD09, "CIA2_TODSEC" },
460  { 0xDD0A, "CIA2_TODMIN" },
461  { 0xDD0B, "CIA2_TODHR" },
462  { 0xDD0D, "CIA2_ICR" },
463  { 0xDD0E, "CIA2_CRA" },
464  { 0xDD0F, "CIA2_CRB" },
465  };
466  static const int SYMBOLS_MAX = sizeof(_symbols) / sizeof(_symbols[0]);
467  struct rz_bin_vsf_obj *vsf_obj = (struct rz_bin_vsf_obj *)bf->o->bin_obj;
468  if (!vsf_obj) {
469  return NULL;
470  }
471  const int m_idx = vsf_obj->machine_idx;
472  int offset = _machines[m_idx].offset_mem;
473  RzList *ret = NULL;
474  RzBinSymbol *ptr;
475  if (!(ret = rz_list_newf((RzListFree)rz_bin_symbol_free))) {
476  return NULL;
477  }
478 
479  int i;
480  for (i = 0; i < SYMBOLS_MAX; i++) {
481  if (!(ptr = RZ_NEW0(RzBinSymbol))) {
482  return ret;
483  }
484  if (!ptr->name) {
485  ptr->name = calloc(1, RZ_BIN_SIZEOF_STRINGS);
486  }
487  strncpy(ptr->name, _symbols[i].symbol_name, RZ_BIN_SIZEOF_STRINGS);
488  ptr->vaddr = _symbols[i].address;
489  ptr->size = 2;
490  ptr->paddr = vsf_obj->mem + offset + _symbols[i].address;
491  ptr->ordinal = i;
492  rz_list_append(ret, ptr);
493  }
494 
495  return ret;
496 }
RZ_API void rz_bin_symbol_free(RzBinSymbol *sym)
Definition: bin.c:175
uint16_t ut16
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
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
#define RZ_BIN_SIZEOF_STRINGS
Definition: rz_bin.h:40
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
char * name
Definition: rz_bin.h:675
ut32 ordinal
Definition: rz_bin.h:692

References _machines, rz_bin_object_t::bin_obj, calloc(), i, if(), rz_bin_vsf_obj::machine_idx, rz_bin_vsf_obj::mem, rz_bin_symbol_t::name, NULL, rz_bin_file_t::o, rz_bin_symbol_t::ordinal, rz_bin_symbol_t::paddr, RZ_BIN_SIZEOF_STRINGS, rz_bin_symbol_free(), rz_list_append(), rz_list_newf(), RZ_NEW0, rz_bin_symbol_t::size, and rz_bin_symbol_t::vaddr.

Variable Documentation

◆ 

const { ... } _machines[]
Initial value:
= {
{ "C64", "Commodore 64", rz_offsetof(struct vsf_c64mem, ram), 64 * 1024 },
{ "C128", "Commodore 128", rz_offsetof(struct vsf_c128mem, ram), 128 * 1024 },
}

Referenced by entries(), info(), load_buffer(), mem(), sections(), and symbols().

◆ desc

const char* desc

Definition at line 19 of file bin_vsf.c.

Referenced by __close(), __desc_cache_cleanup_cb(), __desc_cache_commit_cb(), __desc_fini_cb(), __file_history_down(), __file_history_up(), __lseek(), __open(), __rap_accept(), __read(), __resize(), __write(), _io_malloc_buf(), _io_malloc_off(), _io_malloc_set_buf(), _io_malloc_set_off(), _io_malloc_set_sz(), _io_malloc_sz(), add_map(), basefind_new_bin_file(), bsd_desc_list(), build_tree(), close_but_cb(), core_file_do_load_for_debug(), cpu_memory_map(), desc_fini_cb(), desc_list_cb(), desc_list_json_cb(), desc_list_quiet_cb(), desc_list_table_cb(), desc_list_visual_cb(), do_autocmplt_cmdidentifier(), ds_print_comments_right(), ds_show_comments_describe(), file_save(), file_save_cb(), filecb(), find_apk_binary(), find_autocomplete(), find_reusable_file(), gen_bitlen(), get_filename(), hash_context_create_desc_io_stdin(), hash_context_create_desc_io_string(), hash_context_run(), ihex_write(), info(), init_desc_list_visual_cb(), io_create_mem_map(), io_default_get_buf(), io_desc_new(), io_map_add(), iob_read(), iob_write(), isValidAddress(), kd_read_packet(), kd_send_ctrl_packet(), kd_send_data_packet(), lh5801_decode(), lh5801_print_insn(), linux_desc_list(), map_cpu_memory(), map_multi_dex(), open_nobin_file(), print_reg(), read_desc(), recursive_help(), recursive_help_go(), reopen_in_malloc_cb(), reopen_nobin_headers(), resolve_import_cb(), rz_analysis_xrefs_from_list_handler(), rz_bin_java_class_as_source_code(), rz_bin_java_class_const_pool_as_symbols(), rz_bin_java_class_methods_as_symbols(), rz_bin_mdmp_init_directory_entry(), rz_cmd_alias(), rz_config_desc(), rz_config_node_desc(), rz_core_bin_apply_maps(), rz_core_bin_load(), rz_core_bin_set_arch_bits(), rz_core_bin_whole_strings(), rz_core_file_binlist(), rz_core_file_close(), rz_core_file_find_by_name(), rz_core_file_info_print(), rz_core_file_io_desc_closed(), rz_core_file_open_load(), rz_core_file_open_many(), rz_core_file_print(), rz_core_file_reopen_debug(), rz_core_file_reopen_remote_debug(), rz_core_io_pcache_print(), rz_core_raw_file_print(), rz_core_rtr_gdb_cb(), rz_core_sysenv_begin(), rz_core_vfile_bin_file_deleted(), rz_core_visual_config(), rz_core_visual_title(), rz_debug_desc_new(), rz_debug_dmp_init(), rz_debug_gdb_detach(), rz_debug_gdb_reg_read(), rz_debug_winkd_attach(), rz_diff_io_open(), rz_io_ar_open_many(), rz_io_desc_add(), rz_io_desc_cache_cleanup(), rz_io_desc_cache_commit(), rz_io_desc_cache_fini(), rz_io_desc_cache_init(), rz_io_desc_cache_list(), rz_io_desc_cache_read(), rz_io_desc_cache_write(), rz_io_desc_close(), rz_io_desc_del(), rz_io_desc_exchange(), rz_io_desc_free(), rz_io_desc_get_base(), rz_io_desc_get_buf(), rz_io_desc_get_next(), rz_io_desc_get_pid(), rz_io_desc_get_prev(), rz_io_desc_get_tid(), rz_io_desc_is_blockdevice(), rz_io_desc_is_chardevice(), rz_io_desc_is_dbg(), rz_io_desc_new(), rz_io_desc_open(), rz_io_desc_open_plugin(), rz_io_desc_read(), rz_io_desc_read_at(), rz_io_desc_resize(), rz_io_desc_seek(), rz_io_desc_size(), rz_io_desc_write(), rz_io_desc_write_at(), rz_io_fd_get_base(), rz_io_fd_get_name(), rz_io_fd_get_pid(), rz_io_fd_get_tid(), rz_io_fd_is_dbg(), rz_io_fd_open(), rz_io_fd_read(), rz_io_fd_read_at(), rz_io_fd_write(), rz_io_fd_write_at(), rz_io_open(), rz_io_open_at(), rz_io_open_buffer(), rz_io_open_many(), rz_io_open_nomap(), rz_io_plugin_read(), rz_io_plugin_read_at(), rz_io_plugin_write(), rz_io_plugin_write_at(), rz_io_use_fd(), rz_lib_add_handler(), rz_list_mne_handler(), rz_main_rizin(), rz_open_binary_add_handler(), rz_open_binary_file_handler(), rz_open_malloc_handler(), rz_open_maps_all_fd_handler(), rz_open_maps_map_fd_handler(), rz_open_maps_map_handler(), rz_open_show_current_handler(), rz_write_pcache_commit_handler(), rz_write_pcache_list_handler(), showreg(), spp_help(), vf_open(), w32_desc_list(), winkd_kdctx_free(), and winkd_kdctx_new().

◆ MACHINES_MAX

const int MACHINES_MAX = sizeof(_machines) / sizeof(_machines[0])
static

Definition at line 26 of file bin_vsf.c.

Referenced by load_buffer().

◆ name

const char* name

Definition at line 18 of file bin_vsf.c.

◆ offset_mem

const int offset_mem

Definition at line 20 of file bin_vsf.c.

◆ ram_size

const int ram_size

Definition at line 21 of file bin_vsf.c.

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_BIN,
}
RzBinPlugin rz_bin_plugin_vsf
Definition: bin_vsf.c:535
@ 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 552 of file bin_vsf.c.

◆ rz_bin_plugin_vsf

RzBinPlugin rz_bin_plugin_vsf
Initial value:
= {
.name = "vsf",
.desc = "VICE Snapshot File",
.license = "LGPL3",
.get_sdb = &get_sdb,
.load_buffer = &load_buffer,
.check_buffer = &check_buffer,
.entries = &entries,
.sections = sections,
.symbols = &symbols,
.info = &info,
.destroy = &destroy,
.mem = &mem,
}
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 *b, Sdb *sdb)
Definition: bin_vsf.c:43
static RzList * mem(RzBinFile *bf)
Definition: bin_vsf.c:117
static Sdb * get_sdb(RzBinFile *bf)
Definition: bin_vsf.c:28
static RzList * symbols(RzBinFile *bf)
Definition: bin_vsf.c:332
static void destroy(RzBinFile *bf)
Definition: bin_vsf.c:498
static RzBinInfo * info(RzBinFile *bf)
Definition: bin_vsf.c:288
static RzList * entries(RzBinFile *bf)
Definition: bin_vsf.c:504
static RzList * sections(RzBinFile *bf)
Definition: bin_vsf.c:141

Definition at line 535 of file bin_vsf.c.

◆ VICE_C128MEM

const char VICE_C128MEM[] = "C128MEM"
static

Definition at line 14 of file bin_vsf.c.

Referenced by load_buffer().

◆ VICE_C128ROM

const char VICE_C128ROM[] = "C128ROM"
static

Definition at line 15 of file bin_vsf.c.

Referenced by load_buffer().

◆ VICE_C64MEM

const char VICE_C64MEM[] = "C64MEM"
static

Definition at line 12 of file bin_vsf.c.

Referenced by load_buffer().

◆ VICE_C64ROM

const char VICE_C64ROM[] = "C64ROM"
static

Definition at line 13 of file bin_vsf.c.

Referenced by load_buffer().

◆ VICE_MAGIC

const char VICE_MAGIC[] = "VICE Snapshot File\032"
static

Definition at line 9 of file bin_vsf.c.

Referenced by check_buffer().

◆ VICE_MAINCPU

const char VICE_MAINCPU[] = "MAINCPU"
static

Definition at line 11 of file bin_vsf.c.

Referenced by load_buffer().