summaryrefslogtreecommitdiff
path: root/includes/binary.h
diff options
context:
space:
mode:
Diffstat (limited to 'includes/binary.h')
-rw-r--r--includes/binary.h226
1 files changed, 226 insertions, 0 deletions
diff --git a/includes/binary.h b/includes/binary.h
new file mode 100644
index 0000000..576f7e8
--- /dev/null
+++ b/includes/binary.h
@@ -0,0 +1,226 @@
+/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002-2005 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: binary.h,v 1.1 2005-12-02 11:28:26 pixel Exp $ */
+#ifndef __BINARY_H__
+#define __BINARY_H__
+
+#define LOCAL 0
+#define GLOBAL 1
+#define WEAK 2
+
+enum elf_mips_reloc_type {
+ R_MIPS_NONE = 0,
+ R_MIPS_16,
+ R_MIPS_32,
+ R_MIPS_REL32,
+ R_MIPS_26,
+ R_MIPS_HI16,
+ R_MIPS_LO16,
+ R_MIPS_GPREL16,
+ R_MIPS_LITERAL,
+ R_MIPS_GOT16,
+ R_MIPS_PC16,
+ R_MIPS_CALL16,
+ R_MIPS_GPREL32,
+ elf_mips_reloc_type_size
+};
+
+#include <vector>
+
+#include <Exceptions.h>
+#include <BString.h>
+#include <Handle.h>
+
+class Section;
+class Export : public Base {
+ public:
+ Export(Section *, const String &, Uint32 offset, int bind);
+ ~Export();
+ static Export * GetFirst(const Section * parent = 0);
+ Export * GetNext(const Section * parent = 0) const;
+ static Export * GetLast(const Section * parent = 0);
+ Export * GetPrev(const Section * parent = 0) const;
+ String GetName() const;
+ Uint32 get_offset() const;
+ bool is_absolute() const;
+ bool is_relative() const;
+ Uint32 get_absolute_offset() const;
+ static Export * find_export(const String &, int bind = -1);
+ Section * GetParent() const;
+ private:
+ Section * parent;
+ String name;
+ Uint32 offset;
+ int bind;
+ Export * next, * prev;
+ static Export * head;
+ static Export * tail;
+};
+class Import : public Base {
+ public:
+ Import(Section *, const String &, Uint32 offset, int reloc);
+ ~Import();
+ static Import * GetFirst(const Section * parent = 0);
+ Import * GetNext(const Section * parent = 0) const;
+ static Import * GetLast(const Section * parent = 0);
+ Import * GetPrev(const Section * parent = 0) const;
+ String GetName() const;
+ Uint32 get_offset() const;
+ bool is_absolute() const;
+ bool is_relative() const;
+ static void fix_relocs() throw (GeneralException);
+ Section * GetParent() const;
+ private:
+ Section * parent;
+ String name;
+ Uint32 offset;
+ int reloc;
+ Import * next, * prev;
+ static Import * head;
+ static Import * tail;
+};
+class Internal : public Base {
+ public:
+ Internal(Section *, Section *, Uint32 offset, int reloc);
+ ~Internal();
+ static Internal * GetFirst(const Section * parent = 0);
+ Internal * GetNext(const Section * parent = 0) const;
+ static Internal * GetLast(const Section * parent = 0);
+ Internal * GetPrev(const Section * parent = 0) const;
+ Section * getDest() const;
+ Uint32 get_offset() const;
+ bool is_absolute() const;
+ bool is_relative() const;
+ static void fix_relocs() throw (GeneralException);
+ Section * GetParent() const;
+ private:
+ Section * parent;
+ Section * dest;
+ Uint32 offset;
+ int reloc;
+ Internal * next, * prev;
+ static Internal * head;
+ static Internal * tail;
+};
+
+class Binary;
+class Section : public Base {
+ public:
+ Section(Binary * parent, Uint32 size, Uint32 offset, bool bss = false) throw (GeneralException);
+ ~Section();
+ char * get_bytes() const;
+ Uint32 get_size() const;
+ Uint32 get_offset() const;
+ Uint32 get_end_offset() const;
+ bool is_in(Uint32) const;
+ bool is_bss() const;
+ bool is_absolute() const;
+ bool is_relative() const;
+ Export * add_export(const String & name, Uint32 offset, int bind);
+ Import * add_import(const String & name, Uint32 offset, int reloc);
+ Internal * add_internal(Section *, Uint32 offset, int reloc);
+ static Section * GetFirst(const Binary * parent = 0);
+ Section * GetNext(const Binary * parent = 0) const;
+ static Section * GetLast(const Binary * parent = 0);
+ Section * GetPrev(const Binary * parent = 0) const;
+ Export * GetFirstExport() const;
+ Export * GetNextExport(const Export *) const;
+ Export * GetLastExport() const;
+ Export * GetPrevExport(const Export *) const;
+ Import * GetFirstImport() const;
+ Import * GetNextImport(const Import *) const;
+ Import * GetLastImport() const;
+ Import * GetPrevImport(const Import *) const;
+ Internal * GetFirstInternal() const;
+ Internal * GetNextInternal(const Internal *) const;
+ Internal * GetLastInternal() const;
+ Internal * GetPrevInternal(const Internal *) const;
+ static bool solve_constraints();
+ void fix_reloc(Uint32 from, Uint32 to, int reloc);
+ Binary * GetParent() const;
+ private:
+ Export * find_export(const String &);
+ void solve_constraints_r(Section *);
+ Binary * parent;
+ Uint32 size, offset;
+ char * bytes;
+ Section * next, * prev;
+ static Section * head;
+ static Section * tail;
+};
+
+class Binary : public Base {
+ public:
+ Section * add_section(Uint32 size, Uint32 offset);
+ Section * add_bss(Uint32 size, Uint32 offset);
+ Section * GetFirstSection() const;
+ Section * GetNextSection(const Section *) const;
+ Section * GetLastSection() const;
+ Section * GetPrevSection(const Section *) const;
+ Export * add_export(const String & name, Uint32 offset, int bind) throw (GeneralException);
+ Uint32 getEntryPoint() const;
+ String GetName() const;
+ void loadSymbolMap(Handle * map);
+ void create_jhook(Uint32 from, Uint32 to, int size = 0);
+ void create_jhook(Uint32 from, const String & to, int size = 0);
+ void create_jhook(const String & from, Uint32 to, int size = 0);
+ void create_jhook(const String & from, const String & to, int size = 0);
+ void create_jalhook(Uint32 from, Uint32 to, int size = 0);
+ void create_jalhook(Uint32 from, const String & to, int size = 0);
+ void create_jalhook(const String & from, Uint32 to, int size = 0);
+ void create_jalhook(const String & from, const String & to, int size = 0);
+ protected:
+ Binary(const String &);
+ void setEntryPoint(Uint32);
+ private:
+ Section * create_hook(Uint32, int);
+ String name;
+ Binary * next, * prev;
+ static Binary * head;
+ static Binary * tail;
+ Uint32 EntryPoint;
+};
+
+class Binary_elf : public Binary {
+ public:
+ Binary_elf(Handle * elf) throw (GeneralException);
+};
+
+#ifdef s_addr
+#undef s_addr
+#endif
+
+struct psyq_header_t {
+ struct psyq_details_t {
+ Uint8 id[8];
+ Uint32 text, data, pc0, gp0, t_addr, t_size;
+ Uint32 d_addr, d_size, b_addr, b_size, s_addr, s_size;
+ Uint32 sp, fp, gp, ra, s0;
+ } details;
+ Uint8 psyqhead[0x800];
+};
+
+class Binary_psexe : public Binary {
+ public:
+ Binary_psexe(Handle * psexe) throw (GeneralException);
+ static struct psyq_header_t header;
+};
+
+#endif