Rizin
unix-like reverse engineering framework and cli tools
bin_psxexe.c File Reference
#include <string.h>
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_bin.h>
#include "../i/private.h"
#include "psxexe/psxexe.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 *b, Sdb *sdb)
 
static RzBinInfoinfo (RzBinFile *bf)
 
static RzListsections (RzBinFile *bf)
 
static RzListentries (RzBinFile *bf)
 
static RzListstrings (RzBinFile *bf)
 

Variables

RzBinPlugin rz_bin_plugin_psxexe
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ check_buffer()

static bool check_buffer ( RzBuffer b)
static

Definition at line 12 of file bin_psxexe.c.

12  {
13  ut8 magic[PSXEXE_ID_LEN];
14  if (rz_buf_read_at(b, 0, magic, sizeof(magic)) == PSXEXE_ID_LEN) {
15  return !memcmp(magic, PSXEXE_ID, PSXEXE_ID_LEN);
16  }
17  return false;
18 }
uint8_t ut8
Definition: lh5801.h:11
#define PSXEXE_ID
Definition: psxexe.h:7
#define PSXEXE_ID_LEN
Definition: psxexe.h:8
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, PSXEXE_ID, PSXEXE_ID_LEN, and rz_buf_read_at().

Referenced by load_buffer().

◆ entries()

static RzList* entries ( RzBinFile bf)
static

Definition at line 83 of file bin_psxexe.c.

83  {
84  RzList *ret = NULL;
85  RzBinAddr *addr = NULL;
86  psxexe_header psxheader;
87 
88  if (!(ret = rz_list_new())) {
89  return NULL;
90  }
91 
92  if (!(addr = RZ_NEW0(RzBinAddr))) {
93  rz_list_free(ret);
94  return NULL;
95  }
96 
97  if (rz_buf_fread_at(bf->buf, 0, (ut8 *)&psxheader, "8c17i", 1) < sizeof(psxexe_header)) {
98  RZ_LOG_ERROR("Truncated Header\n");
99  rz_list_free(ret);
100  free(addr);
101  return NULL;
102  }
103 
104  addr->paddr = (psxheader.pc0 - psxheader.t_addr) + PSXEXE_TEXTSECTION_OFFSET;
105  addr->vaddr = psxheader.pc0;
106 
107  rz_list_append(ret, addr);
108  return ret;
109 }
#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_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
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
#define PSXEXE_TEXTSECTION_OFFSET
Definition: psxexe.h:9
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
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
#define RZ_NEW0(x)
Definition: rz_types.h:284
RzBuffer * buf
Definition: rz_bin.h:303
static int addr
Definition: z80asm.c:58

References addr, rz_bin_file_t::buf, free(), NULL, psxexe_header::pc0, PSXEXE_TEXTSECTION_OFFSET, rz_buf_fread_at(), rz_list_append(), rz_list_free(), rz_list_new(), RZ_LOG_ERROR, RZ_NEW0, and psxexe_header::t_addr.

◆ info()

static RzBinInfo* info ( RzBinFile bf)
static

Definition at line 24 of file bin_psxexe.c.

24  {
25  RzBinInfo *ret = NULL;
26  psxexe_header psxheader;
27 
28  if (rz_buf_read_at(bf->buf, 0, (ut8 *)&psxheader, sizeof(psxexe_header)) < sizeof(psxexe_header)) {
29  RZ_LOG_ERROR("Truncated Header\n");
30  return NULL;
31  }
32 
33  if (!(ret = RZ_NEW0(RzBinInfo))) {
34  return NULL;
35  }
36 
37  ret->file = strdup(bf->file);
38  ret->type = strdup("Sony PlayStation 1 Executable");
39  ret->machine = strdup("Sony PlayStation 1");
40  ret->os = strdup("psx");
41  ret->arch = strdup("mips");
42  ret->bits = 32;
43  ret->has_va = true;
44  return ret;
45 }
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_file_t::buf, 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_buf_read_at(), RZ_LOG_ERROR, RZ_NEW0, 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 20 of file bin_psxexe.c.

20  {
21  return check_buffer(b);
22 }
static bool check_buffer(RzBuffer *b)
Definition: bin_psxexe.c:12

References b, and check_buffer().

◆ sections()

static RzList* sections ( RzBinFile bf)
static

Definition at line 47 of file bin_psxexe.c.

47  {
48  RzList *ret = NULL;
49  RzBinSection *sect = NULL;
50  psxexe_header psxheader;
51  ut64 sz = 0;
52 
53  if (!(ret = rz_list_new())) {
54  return NULL;
55  }
56 
57  if (!(sect = RZ_NEW0(RzBinSection))) {
58  rz_list_free(ret);
59  return NULL;
60  }
61 
62  if (rz_buf_fread_at(bf->buf, 0, (ut8 *)&psxheader, "8c17i", 1) < sizeof(psxexe_header)) {
63  RZ_LOG_ERROR("Truncated Header\n");
64  free(sect);
65  rz_list_free(ret);
66  return NULL;
67  }
68 
69  sz = rz_buf_size(bf->buf);
70 
71  sect->name = strdup("TEXT");
73  sect->size = sz - PSXEXE_TEXTSECTION_OFFSET;
74  sect->vaddr = psxheader.t_addr;
75  sect->vsize = psxheader.t_size;
76  sect->perm = RZ_PERM_RX;
77  sect->has_strings = true;
78 
79  rz_list_append(ret, sect);
80  return ret;
81 }
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
#define RZ_PERM_RX
Definition: rz_types.h:97
char * name
Definition: rz_bin.h:619
bool has_strings
Definition: rz_bin.h:632
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References rz_bin_file_t::buf, free(), rz_bin_section_t::has_strings, rz_bin_section_t::name, NULL, rz_bin_section_t::paddr, rz_bin_section_t::perm, PSXEXE_TEXTSECTION_OFFSET, rz_buf_fread_at(), rz_buf_size(), rz_list_append(), rz_list_free(), rz_list_new(), RZ_LOG_ERROR, RZ_NEW0, RZ_PERM_RX, rz_bin_section_t::size, strdup(), psxexe_header::t_addr, psxexe_header::t_size, ut64(), rz_bin_section_t::vaddr, and rz_bin_section_t::vsize.

◆ strings()

static RzList* strings ( RzBinFile bf)
static

Definition at line 111 of file bin_psxexe.c.

111  {
112  // hardcode minstrlen = 20
113  return rz_bin_file_strings(bf, 20, true);
114 }
RZ_API RZ_OWN RzList * rz_bin_file_strings(RZ_NONNULL RzBinFile *bf, size_t min_length, bool raw_strings)
Generates a RzList struct containing RzBinString from a given RzBinFile.
Definition: bfile_string.c:325

References rz_bin_file_strings().

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_BIN,
}
RzBinPlugin rz_bin_plugin_psxexe
Definition: bin_psxexe.c:116
@ 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 130 of file bin_psxexe.c.

◆ rz_bin_plugin_psxexe

RzBinPlugin rz_bin_plugin_psxexe
Initial value:
= {
.name = "psxexe",
.desc = "Sony PlayStation 1 Executable",
.license = "LGPL3",
.load_buffer = &load_buffer,
.check_buffer = &check_buffer,
.info = &info,
.sections = &sections,
.entries = &entries,
.strings = &strings,
}
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_psxexe.c:20
static RzList * strings(RzBinFile *bf)
Definition: bin_psxexe.c:111
static RzBinInfo * info(RzBinFile *bf)
Definition: bin_psxexe.c:24
static RzList * entries(RzBinFile *bf)
Definition: bin_psxexe.c:83
static RzList * sections(RzBinFile *bf)
Definition: bin_psxexe.c:47

Definition at line 116 of file bin_psxexe.c.