Format Headers

Signed-off-by: Isaac Marovitz <isaacryu@icloud.com>
This commit is contained in:
Isaac Marovitz 2025-03-06 22:22:48 +00:00
parent 10b627e986
commit f9fbd822ff
No known key found for this signature in database
GPG Key ID: 97250B2B09A132E1
18 changed files with 534 additions and 507 deletions

View File

@ -13,29 +13,29 @@ struct Function
{
struct Block
{
size_t base{};
size_t size{};
size_t projectedSize{ static_cast<size_t>(-1) }; // scratch
DEBUG(size_t parent{});
size_t base {};
size_t size {};
size_t projectedSize { static_cast<size_t>(-1) }; // scratch
DEBUG(size_t parent {});
Block()
Block()
{
}
Block(size_t base, size_t size)
: base(base), size(size)
: base(base), size(size)
{
}
Block(size_t base, size_t size, size_t projectedSize)
Block(size_t base, size_t size, size_t projectedSize)
: base(base), size(size), projectedSize(projectedSize)
{
}
};
size_t base{};
size_t size{};
std::vector<Block> blocks{};
size_t base {};
size_t size {};
std::vector<Block> blocks {};
Function()
{
@ -45,7 +45,7 @@ struct Function
: base(base), size(size)
{
}
size_t SearchBlock(size_t address) const;
static Function Analyze(const void* code, size_t size, size_t base);
};

View File

@ -2,11 +2,12 @@
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <charconv>
#include <cstddef>
#include <disasm.h>
#include <file.h>
#include <filesystem>
#include <fmt/core.h>
#include <fstream>
#include <function.h>
#include <image.h>
@ -14,6 +15,5 @@
#include <unordered_map>
#include <unordered_set>
#include <xbox.h>
#include <xxhash.h>
#include <fmt/core.h>
#include <xmmintrin.h>
#include <xxhash.h>

View File

@ -5,17 +5,17 @@
struct RecompilerLocalVariables
{
bool ctr{};
bool xer{};
bool reserved{};
bool cr[8]{};
bool r[32]{};
bool f[32]{};
bool v[128]{};
bool env{};
bool temp{};
bool vTemp{};
bool ea{};
bool ctr {};
bool xer {};
bool reserved {};
bool cr[8] {};
bool r[32] {};
bool f[32] {};
bool v[128] {};
bool env {};
bool temp {};
bool vTemp {};
bool ea {};
};
enum class CSRState

View File

@ -5,6 +5,6 @@ struct TestRecompiler : Recompiler
{
void Analyse(const std::string_view& testName);
void Reset();
static void RecompileTests(const char* srcDirectoryPath, const char* dstDirectoryPath);
};

View File

@ -1,4 +1,4 @@
#pragma once
#pragma once
#include <cassert>

View File

@ -4,32 +4,32 @@
namespace ppc
{
struct DisassemblerEngine
{
disassemble_info info{};
DisassemblerEngine(const DisassemblerEngine&) = default;
DisassemblerEngine& operator=(const DisassemblerEngine&) = delete;
struct DisassemblerEngine
{
disassemble_info info {};
DisassemblerEngine(const DisassemblerEngine&) = default;
DisassemblerEngine& operator=(const DisassemblerEngine&) = delete;
DisassemblerEngine(bfd_endian endian, const char* options);
~DisassemblerEngine() = default;
DisassemblerEngine(bfd_endian endian, const char* options);
~DisassemblerEngine() = default;
/**
* \return Numbers of bytes decoded
*/
int Disassemble(const void* code, size_t size, uint64_t base, ppc_insn& out);
};
/**
* \return Numbers of bytes decoded
*/
int Disassemble(const void* code, size_t size, uint64_t base, ppc_insn& out);
};
thread_local extern DisassemblerEngine gBigEndianDisassembler;
thread_local extern DisassemblerEngine gBigEndianDisassembler;
static int Disassemble(const void* code, size_t size, uint64_t base, ppc_insn& out)
{
return gBigEndianDisassembler.Disassemble(code, size, base, out);
}
static int Disassemble(const void* code, uint64_t base, ppc_insn& out)
{
return Disassemble(code, 4, base, out);
}
static int Disassemble(const void* code, uint64_t base, ppc_insn* out, size_t nOut);
static int Disassemble(const void* code, size_t size, uint64_t base, ppc_insn& out)
{
return gBigEndianDisassembler.Disassemble(code, size, base, out);
}
static int Disassemble(const void* code, uint64_t base, ppc_insn& out)
{
return Disassemble(code, 4, base, out);
}
static int Disassemble(const void* code, uint64_t base, ppc_insn* out, size_t nOut);
} // namespace ppc

View File

@ -12,43 +12,42 @@ typedef unsigned long long __u64;
typedef signed long long __s64;
/* 32-bit ELF base types. */
typedef __u32 Elf32_Addr;
typedef __u16 Elf32_Half;
typedef __u32 Elf32_Off;
typedef __s32 Elf32_Sword;
typedef __u32 Elf32_Word;
typedef __u32 Elf32_Addr;
typedef __u16 Elf32_Half;
typedef __u32 Elf32_Off;
typedef __s32 Elf32_Sword;
typedef __u32 Elf32_Word;
/* 64-bit ELF base types. */
typedef __u64 Elf64_Addr;
typedef __u16 Elf64_Half;
typedef __s16 Elf64_SHalf;
typedef __u64 Elf64_Off;
typedef __s32 Elf64_Sword;
typedef __u32 Elf64_Word;
typedef __u64 Elf64_Xword;
typedef __s64 Elf64_Sxword;
typedef __u64 Elf64_Addr;
typedef __u16 Elf64_Half;
typedef __s16 Elf64_SHalf;
typedef __u64 Elf64_Off;
typedef __s32 Elf64_Sword;
typedef __u32 Elf64_Word;
typedef __u64 Elf64_Xword;
typedef __s64 Elf64_Sxword;
/* These constants are for the segment types stored in the image headers */
#define PT_NULL 0
#define PT_LOAD 1
#define PT_NULL 0
#define PT_LOAD 1
#define PT_DYNAMIC 2
#define PT_INTERP 3
#define PT_NOTE 4
#define PT_SHLIB 5
#define PT_PHDR 6
#define PT_TLS 7 /* Thread local storage segment */
#define PT_LOOS 0x60000000 /* OS-specific */
#define PT_HIOS 0x6fffffff /* OS-specific */
#define PT_LOPROC 0x70000000
#define PT_HIPROC 0x7fffffff
#define PT_GNU_EH_FRAME (PT_LOOS + 0x474e550)
#define PT_GNU_STACK (PT_LOOS + 0x474e551)
#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
#define PT_GNU_PROPERTY (PT_LOOS + 0x474e553)
#define PT_INTERP 3
#define PT_NOTE 4
#define PT_SHLIB 5
#define PT_PHDR 6
#define PT_TLS 7 /* Thread local storage segment */
#define PT_LOOS 0x60000000 /* OS-specific */
#define PT_HIOS 0x6fffffff /* OS-specific */
#define PT_LOPROC 0x70000000
#define PT_HIPROC 0x7fffffff
#define PT_GNU_EH_FRAME (PT_LOOS + 0x474e550)
#define PT_GNU_STACK (PT_LOOS + 0x474e551)
#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
#define PT_GNU_PROPERTY (PT_LOOS + 0x474e553)
/* ARM MTE memory tag segment type */
#define PT_AARCH64_MEMTAG_MTE (PT_LOPROC + 0x2)
#define PT_AARCH64_MEMTAG_MTE (PT_LOPROC + 0x2)
/*
* Extended Numbering
@ -72,91 +71,95 @@ typedef __s64 Elf64_Sxword;
*/
#define PN_XNUM 0xffff
/* These constants define the different elf file types */
#define ET_NONE 0
#define ET_REL 1
#define ET_EXEC 2
#define ET_DYN 3
#define ET_CORE 4
/* These constants define the different elf file types */
#define ET_NONE 0
#define ET_REL 1
#define ET_EXEC 2
#define ET_DYN 3
#define ET_CORE 4
#define ET_LOPROC 0xff00
#define ET_HIPROC 0xffff
/* This is the info that is needed to parse the dynamic section of the file */
#define DT_NULL 0
#define DT_NEEDED 1
#define DT_PLTRELSZ 2
#define DT_PLTGOT 3
#define DT_HASH 4
#define DT_STRTAB 5
#define DT_SYMTAB 6
#define DT_RELA 7
#define DT_RELASZ 8
#define DT_RELAENT 9
#define DT_STRSZ 10
#define DT_SYMENT 11
#define DT_INIT 12
#define DT_FINI 13
#define DT_SONAME 14
#define DT_RPATH 15
#define DT_SYMBOLIC 16
#define DT_REL 17
#define DT_RELSZ 18
#define DT_RELENT 19
#define DT_PLTREL 20
#define DT_DEBUG 21
#define DT_TEXTREL 22
#define DT_JMPREL 23
#define DT_ENCODING 32
#define OLD_DT_LOOS 0x60000000
#define DT_LOOS 0x6000000d
#define DT_HIOS 0x6ffff000
#define DT_VALRNGLO 0x6ffffd00
#define DT_VALRNGHI 0x6ffffdff
#define DT_ADDRRNGLO 0x6ffffe00
#define DT_ADDRRNGHI 0x6ffffeff
#define DT_VERSYM 0x6ffffff0
#define DT_RELACOUNT 0x6ffffff9
#define DT_RELCOUNT 0x6ffffffa
#define DT_FLAGS_1 0x6ffffffb
#define DT_VERDEF 0x6ffffffc
#define DT_VERDEFNUM 0x6ffffffd
#define DT_VERNEED 0x6ffffffe
#define DT_VERNEEDNUM 0x6fffffff
#define OLD_DT_HIOS 0x6fffffff
#define DT_LOPROC 0x70000000
#define DT_HIPROC 0x7fffffff
#define DT_NULL 0
#define DT_NEEDED 1
#define DT_PLTRELSZ 2
#define DT_PLTGOT 3
#define DT_HASH 4
#define DT_STRTAB 5
#define DT_SYMTAB 6
#define DT_RELA 7
#define DT_RELASZ 8
#define DT_RELAENT 9
#define DT_STRSZ 10
#define DT_SYMENT 11
#define DT_INIT 12
#define DT_FINI 13
#define DT_SONAME 14
#define DT_RPATH 15
#define DT_SYMBOLIC 16
#define DT_REL 17
#define DT_RELSZ 18
#define DT_RELENT 19
#define DT_PLTREL 20
#define DT_DEBUG 21
#define DT_TEXTREL 22
#define DT_JMPREL 23
#define DT_ENCODING 32
#define OLD_DT_LOOS 0x60000000
#define DT_LOOS 0x6000000d
#define DT_HIOS 0x6ffff000
#define DT_VALRNGLO 0x6ffffd00
#define DT_VALRNGHI 0x6ffffdff
#define DT_ADDRRNGLO 0x6ffffe00
#define DT_ADDRRNGHI 0x6ffffeff
#define DT_VERSYM 0x6ffffff0
#define DT_RELACOUNT 0x6ffffff9
#define DT_RELCOUNT 0x6ffffffa
#define DT_FLAGS_1 0x6ffffffb
#define DT_VERDEF 0x6ffffffc
#define DT_VERDEFNUM 0x6ffffffd
#define DT_VERNEED 0x6ffffffe
#define DT_VERNEEDNUM 0x6fffffff
#define OLD_DT_HIOS 0x6fffffff
#define DT_LOPROC 0x70000000
#define DT_HIPROC 0x7fffffff
/* This info is needed when parsing the symbol table */
#define STB_LOCAL 0
#define STB_LOCAL 0
#define STB_GLOBAL 1
#define STB_WEAK 2
#define STB_WEAK 2
#define STT_NOTYPE 0
#define STT_OBJECT 1
#define STT_FUNC 2
#define STT_NOTYPE 0
#define STT_OBJECT 1
#define STT_FUNC 2
#define STT_SECTION 3
#define STT_FILE 4
#define STT_COMMON 5
#define STT_TLS 6
#define STT_FILE 4
#define STT_COMMON 5
#define STT_TLS 6
#define ELF_ST_BIND(x) ((x) >> 4)
#define ELF_ST_TYPE(x) ((x) & 0xf)
#define ELF32_ST_BIND(x) ELF_ST_BIND(x)
#define ELF32_ST_TYPE(x) ELF_ST_TYPE(x)
#define ELF64_ST_BIND(x) ELF_ST_BIND(x)
#define ELF64_ST_TYPE(x) ELF_ST_TYPE(x)
#define ELF_ST_BIND(x) ((x) >> 4)
#define ELF_ST_TYPE(x) ((x) & 0xf)
#define ELF32_ST_BIND(x) ELF_ST_BIND(x)
#define ELF32_ST_TYPE(x) ELF_ST_TYPE(x)
#define ELF64_ST_BIND(x) ELF_ST_BIND(x)
#define ELF64_ST_TYPE(x) ELF_ST_TYPE(x)
typedef struct {
typedef struct
{
Elf32_Sword d_tag;
union {
Elf32_Sword d_val;
Elf32_Addr d_ptr;
union
{
Elf32_Sword d_val;
Elf32_Addr d_ptr;
} d_un;
} Elf32_Dyn;
typedef struct {
Elf64_Sxword d_tag; /* entry tag value */
union {
typedef struct
{
Elf64_Sxword d_tag; /* entry tag value */
union
{
Elf64_Xword d_val;
Elf64_Addr d_ptr;
} d_un;
@ -166,77 +169,84 @@ typedef struct {
#define ELF32_R_SYM(x) ((x) >> 8)
#define ELF32_R_TYPE(x) ((x) & 0xff)
#define ELF64_R_SYM(i) ((i) >> 32)
#define ELF64_R_TYPE(i) ((i) & 0xffffffff)
#define ELF64_R_SYM(i) ((i) >> 32)
#define ELF64_R_TYPE(i) ((i) & 0xffffffff)
typedef struct elf32_rel {
Elf32_Addr r_offset;
Elf32_Word r_info;
typedef struct elf32_rel
{
Elf32_Addr r_offset;
Elf32_Word r_info;
} Elf32_Rel;
typedef struct elf64_rel {
Elf64_Addr r_offset; /* Location at which to apply the action */
Elf64_Xword r_info; /* index and type of relocation */
typedef struct elf64_rel
{
Elf64_Addr r_offset; /* Location at which to apply the action */
Elf64_Xword r_info; /* index and type of relocation */
} Elf64_Rel;
typedef struct elf32_rela {
Elf32_Addr r_offset;
Elf32_Word r_info;
Elf32_Sword r_addend;
typedef struct elf32_rela
{
Elf32_Addr r_offset;
Elf32_Word r_info;
Elf32_Sword r_addend;
} Elf32_Rela;
typedef struct elf64_rela {
Elf64_Addr r_offset; /* Location at which to apply the action */
Elf64_Xword r_info; /* index and type of relocation */
Elf64_Sxword r_addend; /* Constant addend used to compute value */
typedef struct elf64_rela
{
Elf64_Addr r_offset; /* Location at which to apply the action */
Elf64_Xword r_info; /* index and type of relocation */
Elf64_Sxword r_addend; /* Constant addend used to compute value */
} Elf64_Rela;
typedef struct elf32_sym {
Elf32_Word st_name;
Elf32_Addr st_value;
Elf32_Word st_size;
unsigned char st_info;
unsigned char st_other;
Elf32_Half st_shndx;
typedef struct elf32_sym
{
Elf32_Word st_name;
Elf32_Addr st_value;
Elf32_Word st_size;
unsigned char st_info;
unsigned char st_other;
Elf32_Half st_shndx;
} Elf32_Sym;
typedef struct elf64_sym {
Elf64_Word st_name; /* Symbol name, index in string tbl */
unsigned char st_info; /* Type and binding attributes */
unsigned char st_other; /* No defined meaning, 0 */
Elf64_Half st_shndx; /* Associated section index */
Elf64_Addr st_value; /* Value of the symbol */
Elf64_Xword st_size; /* Associated symbol size */
typedef struct elf64_sym
{
Elf64_Word st_name; /* Symbol name, index in string tbl */
unsigned char st_info; /* Type and binding attributes */
unsigned char st_other; /* No defined meaning, 0 */
Elf64_Half st_shndx; /* Associated section index */
Elf64_Addr st_value; /* Value of the symbol */
Elf64_Xword st_size; /* Associated symbol size */
} Elf64_Sym;
#define EI_NIDENT 16
#define EI_NIDENT 16
typedef struct elf32_hdr {
unsigned char e_ident[EI_NIDENT];
Elf32_Half e_type;
Elf32_Half e_machine;
Elf32_Word e_version;
Elf32_Addr e_entry; /* Entry point */
Elf32_Off e_phoff;
Elf32_Off e_shoff;
Elf32_Word e_flags;
Elf32_Half e_ehsize;
Elf32_Half e_phentsize;
Elf32_Half e_phnum;
Elf32_Half e_shentsize;
Elf32_Half e_shnum;
Elf32_Half e_shstrndx;
typedef struct elf32_hdr
{
unsigned char e_ident[EI_NIDENT];
Elf32_Half e_type;
Elf32_Half e_machine;
Elf32_Word e_version;
Elf32_Addr e_entry; /* Entry point */
Elf32_Off e_phoff;
Elf32_Off e_shoff;
Elf32_Word e_flags;
Elf32_Half e_ehsize;
Elf32_Half e_phentsize;
Elf32_Half e_phnum;
Elf32_Half e_shentsize;
Elf32_Half e_shnum;
Elf32_Half e_shstrndx;
} Elf32_Ehdr;
typedef struct elf64_hdr {
unsigned char e_ident[EI_NIDENT]; /* ELF "magic number" */
typedef struct elf64_hdr
{
unsigned char e_ident[EI_NIDENT]; /* ELF "magic number" */
Elf64_Half e_type;
Elf64_Half e_machine;
Elf64_Word e_version;
Elf64_Addr e_entry; /* Entry point virtual address */
Elf64_Off e_phoff; /* Program header table file offset */
Elf64_Off e_shoff; /* Section header table file offset */
Elf64_Addr e_entry; /* Entry point virtual address */
Elf64_Off e_phoff; /* Program header table file offset */
Elf64_Off e_shoff; /* Section header table file offset */
Elf64_Word e_flags;
Elf64_Half e_ehsize;
Elf64_Half e_phentsize;
@ -248,127 +258,131 @@ typedef struct elf64_hdr {
/* These constants define the permissions on sections in the program
header, p_flags. */
#define PF_R 0x4
#define PF_W 0x2
#define PF_X 0x1
#define PF_R 0x4
#define PF_W 0x2
#define PF_X 0x1
typedef struct elf32_phdr {
Elf32_Word p_type;
Elf32_Off p_offset;
Elf32_Addr p_vaddr;
Elf32_Addr p_paddr;
Elf32_Word p_filesz;
Elf32_Word p_memsz;
Elf32_Word p_flags;
Elf32_Word p_align;
typedef struct elf32_phdr
{
Elf32_Word p_type;
Elf32_Off p_offset;
Elf32_Addr p_vaddr;
Elf32_Addr p_paddr;
Elf32_Word p_filesz;
Elf32_Word p_memsz;
Elf32_Word p_flags;
Elf32_Word p_align;
} Elf32_Phdr;
typedef struct elf64_phdr {
typedef struct elf64_phdr
{
Elf64_Word p_type;
Elf64_Word p_flags;
Elf64_Off p_offset; /* Segment file offset */
Elf64_Addr p_vaddr; /* Segment virtual address */
Elf64_Addr p_paddr; /* Segment physical address */
Elf64_Xword p_filesz; /* Segment size in file */
Elf64_Xword p_memsz; /* Segment size in memory */
Elf64_Xword p_align; /* Segment alignment, file & memory */
Elf64_Off p_offset; /* Segment file offset */
Elf64_Addr p_vaddr; /* Segment virtual address */
Elf64_Addr p_paddr; /* Segment physical address */
Elf64_Xword p_filesz; /* Segment size in file */
Elf64_Xword p_memsz; /* Segment size in memory */
Elf64_Xword p_align; /* Segment alignment, file & memory */
} Elf64_Phdr;
/* sh_type */
#define SHT_NULL 0
#define SHT_PROGBITS 1
#define SHT_SYMTAB 2
#define SHT_STRTAB 3
#define SHT_RELA 4
#define SHT_HASH 5
#define SHT_DYNAMIC 6
#define SHT_NOTE 7
#define SHT_NOBITS 8
#define SHT_REL 9
#define SHT_SHLIB 10
#define SHT_DYNSYM 11
#define SHT_NUM 12
#define SHT_LOPROC 0x70000000
#define SHT_HIPROC 0x7fffffff
#define SHT_LOUSER 0x80000000
#define SHT_HIUSER 0xffffffff
#define SHT_NULL 0
#define SHT_PROGBITS 1
#define SHT_SYMTAB 2
#define SHT_STRTAB 3
#define SHT_RELA 4
#define SHT_HASH 5
#define SHT_DYNAMIC 6
#define SHT_NOTE 7
#define SHT_NOBITS 8
#define SHT_REL 9
#define SHT_SHLIB 10
#define SHT_DYNSYM 11
#define SHT_NUM 12
#define SHT_LOPROC 0x70000000
#define SHT_HIPROC 0x7fffffff
#define SHT_LOUSER 0x80000000
#define SHT_HIUSER 0xffffffff
/* sh_flags */
#define SHF_WRITE 0x1
#define SHF_ALLOC 0x2
#define SHF_EXECINSTR 0x4
#define SHF_RELA_LIVEPATCH 0x00100000
#define SHF_RO_AFTER_INIT 0x00200000
#define SHF_MASKPROC 0xf0000000
#define SHF_WRITE 0x1
#define SHF_ALLOC 0x2
#define SHF_EXECINSTR 0x4
#define SHF_RELA_LIVEPATCH 0x00100000
#define SHF_RO_AFTER_INIT 0x00200000
#define SHF_MASKPROC 0xf0000000
/* special section indexes */
#define SHN_UNDEF 0
#define SHN_LORESERVE 0xff00
#define SHN_LOPROC 0xff00
#define SHN_HIPROC 0xff1f
#define SHN_LIVEPATCH 0xff20
#define SHN_ABS 0xfff1
#define SHN_COMMON 0xfff2
#define SHN_HIRESERVE 0xffff
#define SHN_UNDEF 0
#define SHN_LORESERVE 0xff00
#define SHN_LOPROC 0xff00
#define SHN_HIPROC 0xff1f
#define SHN_LIVEPATCH 0xff20
#define SHN_ABS 0xfff1
#define SHN_COMMON 0xfff2
#define SHN_HIRESERVE 0xffff
typedef struct elf32_shdr {
Elf32_Word sh_name;
Elf32_Word sh_type;
Elf32_Word sh_flags;
Elf32_Addr sh_addr;
Elf32_Off sh_offset;
Elf32_Word sh_size;
Elf32_Word sh_link;
Elf32_Word sh_info;
Elf32_Word sh_addralign;
Elf32_Word sh_entsize;
typedef struct elf32_shdr
{
Elf32_Word sh_name;
Elf32_Word sh_type;
Elf32_Word sh_flags;
Elf32_Addr sh_addr;
Elf32_Off sh_offset;
Elf32_Word sh_size;
Elf32_Word sh_link;
Elf32_Word sh_info;
Elf32_Word sh_addralign;
Elf32_Word sh_entsize;
} Elf32_Shdr;
typedef struct elf64_shdr {
Elf64_Word sh_name; /* Section name, index in string tbl */
Elf64_Word sh_type; /* Type of section */
Elf64_Xword sh_flags; /* Miscellaneous section attributes */
Elf64_Addr sh_addr; /* Section virtual addr at execution */
Elf64_Off sh_offset; /* Section file offset */
Elf64_Xword sh_size; /* Size of section in bytes */
Elf64_Word sh_link; /* Index of another section */
Elf64_Word sh_info; /* Additional section information */
Elf64_Xword sh_addralign; /* Section alignment */
Elf64_Xword sh_entsize; /* Entry size if section holds table */
typedef struct elf64_shdr
{
Elf64_Word sh_name; /* Section name, index in string tbl */
Elf64_Word sh_type; /* Type of section */
Elf64_Xword sh_flags; /* Miscellaneous section attributes */
Elf64_Addr sh_addr; /* Section virtual addr at execution */
Elf64_Off sh_offset; /* Section file offset */
Elf64_Xword sh_size; /* Size of section in bytes */
Elf64_Word sh_link; /* Index of another section */
Elf64_Word sh_info; /* Additional section information */
Elf64_Xword sh_addralign; /* Section alignment */
Elf64_Xword sh_entsize; /* Entry size if section holds table */
} Elf64_Shdr;
#define EI_MAG0 0 /* e_ident[] indexes */
#define EI_MAG1 1
#define EI_MAG2 2
#define EI_MAG3 3
#define EI_CLASS 4
#define EI_DATA 5
#define EI_VERSION 6
#define EI_OSABI 7
#define EI_PAD 8
#define EI_MAG0 0 /* e_ident[] indexes */
#define EI_MAG1 1
#define EI_MAG2 2
#define EI_MAG3 3
#define EI_CLASS 4
#define EI_DATA 5
#define EI_VERSION 6
#define EI_OSABI 7
#define EI_PAD 8
#define ELFMAG0 0x7f /* EI_MAG */
#define ELFMAG1 'E'
#define ELFMAG2 'L'
#define ELFMAG3 'F'
#define ELFMAG "\177ELF"
#define SELFMAG 4
#define ELFMAG0 0x7f /* EI_MAG */
#define ELFMAG1 'E'
#define ELFMAG2 'L'
#define ELFMAG3 'F'
#define ELFMAG "\177ELF"
#define SELFMAG 4
#define ELFCLASSNONE 0 /* EI_CLASS */
#define ELFCLASS32 1
#define ELFCLASS64 2
#define ELFCLASSNUM 3
#define ELFCLASSNONE 0 /* EI_CLASS */
#define ELFCLASS32 1
#define ELFCLASS64 2
#define ELFCLASSNUM 3
#define ELFDATANONE 0 /* e_ident[EI_DATA] */
#define ELFDATA2LSB 1
#define ELFDATA2MSB 2
#define ELFDATANONE 0 /* e_ident[EI_DATA] */
#define ELFDATA2LSB 1
#define ELFDATA2MSB 2
#define EV_NONE 0 /* e_version, EI_VERSION */
#define EV_CURRENT 1
#define EV_NUM 2
#define EV_NONE 0 /* e_version, EI_VERSION */
#define EV_CURRENT 1
#define EV_NUM 2
#define ELFOSABI_NONE 0
#define ELFOSABI_LINUX 3
#define ELFOSABI_NONE 0
#define ELFOSABI_LINUX 3
#ifndef ELF_OSABI
#define ELF_OSABI ELFOSABI_NONE
@ -381,108 +395,110 @@ typedef struct elf64_shdr {
* The note name for these types is "LINUX", except NT_PRFPREG that is named
* "CORE".
*/
#define NT_PRSTATUS 1
#define NT_PRFPREG 2
#define NT_PRPSINFO 3
#define NT_TASKSTRUCT 4
#define NT_AUXV 6
/*
* Note to userspace developers: size of NT_SIGINFO note may increase
* in the future to accomodate more fields, don't assume it is fixed!
*/
#define NT_SIGINFO 0x53494749
#define NT_FILE 0x46494c45
#define NT_PRXFPREG 0x46e62b7f /* copied from gdb5.1/include/elf/common.h */
#define NT_PPC_VMX 0x100 /* PowerPC Altivec/VMX registers */
#define NT_PPC_SPE 0x101 /* PowerPC SPE/EVR registers */
#define NT_PPC_VSX 0x102 /* PowerPC VSX registers */
#define NT_PPC_TAR 0x103 /* Target Address Register */
#define NT_PPC_PPR 0x104 /* Program Priority Register */
#define NT_PPC_DSCR 0x105 /* Data Stream Control Register */
#define NT_PPC_EBB 0x106 /* Event Based Branch Registers */
#define NT_PPC_PMU 0x107 /* Performance Monitor Registers */
#define NT_PPC_TM_CGPR 0x108 /* TM checkpointed GPR Registers */
#define NT_PPC_TM_CFPR 0x109 /* TM checkpointed FPR Registers */
#define NT_PPC_TM_CVMX 0x10a /* TM checkpointed VMX Registers */
#define NT_PPC_TM_CVSX 0x10b /* TM checkpointed VSX Registers */
#define NT_PPC_TM_SPR 0x10c /* TM Special Purpose Registers */
#define NT_PPC_TM_CTAR 0x10d /* TM checkpointed Target Address Register */
#define NT_PPC_TM_CPPR 0x10e /* TM checkpointed Program Priority Register */
#define NT_PPC_TM_CDSCR 0x10f /* TM checkpointed Data Stream Control Register */
#define NT_PPC_PKEY 0x110 /* Memory Protection Keys registers */
#define NT_PPC_DEXCR 0x111 /* PowerPC DEXCR registers */
#define NT_PPC_HASHKEYR 0x112 /* PowerPC HASHKEYR register */
#define NT_386_TLS 0x200 /* i386 TLS slots (struct user_desc) */
#define NT_386_IOPERM 0x201 /* x86 io permission bitmap (1=deny) */
#define NT_X86_XSTATE 0x202 /* x86 extended state using xsave */
/* Old binutils treats 0x203 as a CET state */
#define NT_X86_SHSTK 0x204 /* x86 SHSTK state */
#define NT_S390_HIGH_GPRS 0x300 /* s390 upper register halves */
#define NT_S390_TIMER 0x301 /* s390 timer register */
#define NT_S390_TODCMP 0x302 /* s390 TOD clock comparator register */
#define NT_S390_TODPREG 0x303 /* s390 TOD programmable register */
#define NT_S390_CTRS 0x304 /* s390 control registers */
#define NT_S390_PREFIX 0x305 /* s390 prefix register */
#define NT_S390_LAST_BREAK 0x306 /* s390 breaking event address */
#define NT_S390_SYSTEM_CALL 0x307 /* s390 system call restart data */
#define NT_S390_TDB 0x308 /* s390 transaction diagnostic block */
#define NT_S390_VXRS_LOW 0x309 /* s390 vector registers 0-15 upper half */
#define NT_S390_VXRS_HIGH 0x30a /* s390 vector registers 16-31 */
#define NT_S390_GS_CB 0x30b /* s390 guarded storage registers */
#define NT_S390_GS_BC 0x30c /* s390 guarded storage broadcast control block */
#define NT_S390_RI_CB 0x30d /* s390 runtime instrumentation */
#define NT_S390_PV_CPU_DATA 0x30e /* s390 protvirt cpu dump data */
#define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */
#define NT_ARM_TLS 0x401 /* ARM TLS register */
#define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */
#define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */
#define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */
#define NT_ARM_SVE 0x405 /* ARM Scalable Vector Extension registers */
#define NT_ARM_PAC_MASK 0x406 /* ARM pointer authentication code masks */
#define NT_ARM_PACA_KEYS 0x407 /* ARM pointer authentication address keys */
#define NT_ARM_PACG_KEYS 0x408 /* ARM pointer authentication generic key */
#define NT_ARM_TAGGED_ADDR_CTRL 0x409 /* arm64 tagged address control (prctl()) */
#define NT_ARM_PAC_ENABLED_KEYS 0x40a /* arm64 ptr auth enabled keys (prctl()) */
#define NT_ARM_SSVE 0x40b /* ARM Streaming SVE registers */
#define NT_ARM_ZA 0x40c /* ARM SME ZA registers */
#define NT_ARM_ZT 0x40d /* ARM SME ZT registers */
#define NT_ARM_FPMR 0x40e /* ARM floating point mode register */
#define NT_ARC_V2 0x600 /* ARCv2 accumulator/extra registers */
#define NT_VMCOREDD 0x700 /* Vmcore Device Dump Note */
#define NT_MIPS_DSP 0x800 /* MIPS DSP ASE registers */
#define NT_MIPS_FP_MODE 0x801 /* MIPS floating-point mode */
#define NT_MIPS_MSA 0x802 /* MIPS SIMD registers */
#define NT_RISCV_CSR 0x900 /* RISC-V Control and Status Registers */
#define NT_RISCV_VECTOR 0x901 /* RISC-V vector registers */
#define NT_LOONGARCH_CPUCFG 0xa00 /* LoongArch CPU config registers */
#define NT_LOONGARCH_CSR 0xa01 /* LoongArch control and status registers */
#define NT_LOONGARCH_LSX 0xa02 /* LoongArch Loongson SIMD Extension registers */
#define NT_LOONGARCH_LASX 0xa03 /* LoongArch Loongson Advanced SIMD Extension registers */
#define NT_LOONGARCH_LBT 0xa04 /* LoongArch Loongson Binary Translation registers */
#define NT_LOONGARCH_HW_BREAK 0xa05 /* LoongArch hardware breakpoint registers */
#define NT_LOONGARCH_HW_WATCH 0xa06 /* LoongArch hardware watchpoint registers */
#define NT_PRSTATUS 1
#define NT_PRFPREG 2
#define NT_PRPSINFO 3
#define NT_TASKSTRUCT 4
#define NT_AUXV 6
/*
* Note to userspace developers: size of NT_SIGINFO note may increase
* in the future to accomodate more fields, don't assume it is fixed!
*/
#define NT_SIGINFO 0x53494749
#define NT_FILE 0x46494c45
#define NT_PRXFPREG 0x46e62b7f /* copied from gdb5.1/include/elf/common.h */
#define NT_PPC_VMX 0x100 /* PowerPC Altivec/VMX registers */
#define NT_PPC_SPE 0x101 /* PowerPC SPE/EVR registers */
#define NT_PPC_VSX 0x102 /* PowerPC VSX registers */
#define NT_PPC_TAR 0x103 /* Target Address Register */
#define NT_PPC_PPR 0x104 /* Program Priority Register */
#define NT_PPC_DSCR 0x105 /* Data Stream Control Register */
#define NT_PPC_EBB 0x106 /* Event Based Branch Registers */
#define NT_PPC_PMU 0x107 /* Performance Monitor Registers */
#define NT_PPC_TM_CGPR 0x108 /* TM checkpointed GPR Registers */
#define NT_PPC_TM_CFPR 0x109 /* TM checkpointed FPR Registers */
#define NT_PPC_TM_CVMX 0x10a /* TM checkpointed VMX Registers */
#define NT_PPC_TM_CVSX 0x10b /* TM checkpointed VSX Registers */
#define NT_PPC_TM_SPR 0x10c /* TM Special Purpose Registers */
#define NT_PPC_TM_CTAR 0x10d /* TM checkpointed Target Address Register */
#define NT_PPC_TM_CPPR 0x10e /* TM checkpointed Program Priority Register */
#define NT_PPC_TM_CDSCR 0x10f /* TM checkpointed Data Stream Control Register */
#define NT_PPC_PKEY 0x110 /* Memory Protection Keys registers */
#define NT_PPC_DEXCR 0x111 /* PowerPC DEXCR registers */
#define NT_PPC_HASHKEYR 0x112 /* PowerPC HASHKEYR register */
#define NT_386_TLS 0x200 /* i386 TLS slots (struct user_desc) */
#define NT_386_IOPERM 0x201 /* x86 io permission bitmap (1=deny) */
#define NT_X86_XSTATE 0x202 /* x86 extended state using xsave */
/* Old binutils treats 0x203 as a CET state */
#define NT_X86_SHSTK 0x204 /* x86 SHSTK state */
#define NT_S390_HIGH_GPRS 0x300 /* s390 upper register halves */
#define NT_S390_TIMER 0x301 /* s390 timer register */
#define NT_S390_TODCMP 0x302 /* s390 TOD clock comparator register */
#define NT_S390_TODPREG 0x303 /* s390 TOD programmable register */
#define NT_S390_CTRS 0x304 /* s390 control registers */
#define NT_S390_PREFIX 0x305 /* s390 prefix register */
#define NT_S390_LAST_BREAK 0x306 /* s390 breaking event address */
#define NT_S390_SYSTEM_CALL 0x307 /* s390 system call restart data */
#define NT_S390_TDB 0x308 /* s390 transaction diagnostic block */
#define NT_S390_VXRS_LOW 0x309 /* s390 vector registers 0-15 upper half */
#define NT_S390_VXRS_HIGH 0x30a /* s390 vector registers 16-31 */
#define NT_S390_GS_CB 0x30b /* s390 guarded storage registers */
#define NT_S390_GS_BC 0x30c /* s390 guarded storage broadcast control block */
#define NT_S390_RI_CB 0x30d /* s390 runtime instrumentation */
#define NT_S390_PV_CPU_DATA 0x30e /* s390 protvirt cpu dump data */
#define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */
#define NT_ARM_TLS 0x401 /* ARM TLS register */
#define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */
#define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */
#define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */
#define NT_ARM_SVE 0x405 /* ARM Scalable Vector Extension registers */
#define NT_ARM_PAC_MASK 0x406 /* ARM pointer authentication code masks */
#define NT_ARM_PACA_KEYS 0x407 /* ARM pointer authentication address keys */
#define NT_ARM_PACG_KEYS 0x408 /* ARM pointer authentication generic key */
#define NT_ARM_TAGGED_ADDR_CTRL 0x409 /* arm64 tagged address control (prctl()) */
#define NT_ARM_PAC_ENABLED_KEYS 0x40a /* arm64 ptr auth enabled keys (prctl()) */
#define NT_ARM_SSVE 0x40b /* ARM Streaming SVE registers */
#define NT_ARM_ZA 0x40c /* ARM SME ZA registers */
#define NT_ARM_ZT 0x40d /* ARM SME ZT registers */
#define NT_ARM_FPMR 0x40e /* ARM floating point mode register */
#define NT_ARC_V2 0x600 /* ARCv2 accumulator/extra registers */
#define NT_VMCOREDD 0x700 /* Vmcore Device Dump Note */
#define NT_MIPS_DSP 0x800 /* MIPS DSP ASE registers */
#define NT_MIPS_FP_MODE 0x801 /* MIPS floating-point mode */
#define NT_MIPS_MSA 0x802 /* MIPS SIMD registers */
#define NT_RISCV_CSR 0x900 /* RISC-V Control and Status Registers */
#define NT_RISCV_VECTOR 0x901 /* RISC-V vector registers */
#define NT_LOONGARCH_CPUCFG 0xa00 /* LoongArch CPU config registers */
#define NT_LOONGARCH_CSR 0xa01 /* LoongArch control and status registers */
#define NT_LOONGARCH_LSX 0xa02 /* LoongArch Loongson SIMD Extension registers */
#define NT_LOONGARCH_LASX 0xa03 /* LoongArch Loongson Advanced SIMD Extension registers */
#define NT_LOONGARCH_LBT 0xa04 /* LoongArch Loongson Binary Translation registers */
#define NT_LOONGARCH_HW_BREAK 0xa05 /* LoongArch hardware breakpoint registers */
#define NT_LOONGARCH_HW_WATCH 0xa06 /* LoongArch hardware watchpoint registers */
/* Note types with note name "GNU" */
#define NT_GNU_PROPERTY_TYPE_0 5
#define NT_GNU_PROPERTY_TYPE_0 5
/* Note header in a PT_NOTE section */
typedef struct elf32_note {
Elf32_Word n_namesz; /* Name size */
Elf32_Word n_descsz; /* Content size */
Elf32_Word n_type; /* Content type */
typedef struct elf32_note
{
Elf32_Word n_namesz; /* Name size */
Elf32_Word n_descsz; /* Content size */
Elf32_Word n_type; /* Content type */
} Elf32_Nhdr;
/* Note header in a PT_NOTE section */
typedef struct elf64_note {
Elf64_Word n_namesz; /* Name size */
Elf64_Word n_descsz; /* Content size */
Elf64_Word n_type; /* Content type */
typedef struct elf64_note
{
Elf64_Word n_namesz; /* Name size */
Elf64_Word n_descsz; /* Content size */
Elf64_Word n_type; /* Content type */
} Elf64_Nhdr;
/* .note.gnu.property types for EM_AARCH64: */
#define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000
#define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000
/* Bits for GNU_PROPERTY_AARCH64_FEATURE_1_BTI */
#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1U << 0)
#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1U << 0)
#endif /* _UAPI_LINUX_ELF_H */
#endif /* _UAPI_LINUX_ELF_H */

View File

@ -18,7 +18,7 @@ inline std::vector<uint8_t> LoadFile(const std::filesystem::path& path)
std::vector<uint8_t> data;
data.resize(size);
stream.read((char *)(data.data()), size);
stream.read((char*)(data.data()), size);
if (stream.bad())
{
return {};

View File

@ -1,19 +1,19 @@
#pragma once
#include <memory>
#include <string>
#include <set>
#include <section.h>
#include "symbol_table.h"
#include <memory>
#include <section.h>
#include <set>
#include <string>
struct Image
{
std::unique_ptr<uint8_t[]> data{};
size_t base{};
uint32_t size{};
std::unique_ptr<uint8_t[]> data {};
size_t base {};
uint32_t size {};
size_t entry_point{};
std::set<Section, SectionComparer> sections{};
SymbolTable symbols{};
size_t entry_point {};
std::set<Section, SectionComparer> sections {};
SymbolTable symbols {};
/**
* \brief Map data to image by RVA

View File

@ -3,12 +3,13 @@
#include <filesystem>
#if defined(_WIN32)
# include <Windows.h>
#include <Windows.h>
#else
# include <sys/mman.h>
#include <sys/mman.h>
#endif
struct MemoryMappedFile {
struct MemoryMappedFile
{
#if defined(_WIN32)
HANDLE fileHandle = nullptr;
HANDLE fileMappingHandle = nullptr;
@ -16,17 +17,17 @@ struct MemoryMappedFile {
LARGE_INTEGER fileSize = {};
#else
int fileHandle = -1;
void *fileView = MAP_FAILED;
void* fileView = MAP_FAILED;
off_t fileSize = 0;
#endif
MemoryMappedFile();
MemoryMappedFile(const std::filesystem::path &path);
MemoryMappedFile(MemoryMappedFile &&other);
MemoryMappedFile(const std::filesystem::path& path);
MemoryMappedFile(MemoryMappedFile&& other);
~MemoryMappedFile();
bool open(const std::filesystem::path &path);
bool open(const std::filesystem::path& path);
void close();
bool isOpen() const;
uint8_t *data() const;
uint8_t* data() const;
size_t size() const;
};

View File

@ -17,8 +17,8 @@
#ifdef _WIN32
#include <intrin.h>
#else
#include <xmmintrin.h>
#include <smmintrin.h>
#include <xmmintrin.h>
#endif
#define PPC_JOIN(x, y) x##y
@ -27,7 +27,7 @@
#define PPC_FUNC(x) void x(PPCContext& __restrict ctx, uint8_t* base)
#define PPC_FUNC_IMPL(x) extern "C" PPC_FUNC(x)
#define PPC_EXTERN_FUNC(x) extern PPC_FUNC(x)
#define PPC_WEAK_FUNC(x) __attribute__((weak,noinline)) PPC_FUNC(x)
#define PPC_WEAK_FUNC(x) __attribute__((weak, noinline)) PPC_FUNC(x)
#define PPC_FUNC_PROLOGUE() __builtin_assume(((size_t)base & 0x1F) == 0)
@ -49,10 +49,10 @@
// TODO: Implement.
// These are currently unused. However, MMIO loads could possibly be handled statically with some profiling and a fallback.
// The fallback would be a runtime exception handler which will intercept reads from MMIO regions
// The fallback would be a runtime exception handler which will intercept reads from MMIO regions
// and log the PC for compiling to static code later.
#ifndef PPC_MM_LOAD_U8
#define PPC_MM_LOAD_U8(x) PPC_LOAD_U8 (x)
#define PPC_MM_LOAD_U8(x) PPC_LOAD_U8(x)
#endif
#ifndef PPC_MM_LOAD_U16
@ -86,19 +86,19 @@
// MMIO Store handling is completely reliant on being preeceded by eieio.
// TODO: Verify if that's always the case.
#ifndef PPC_MM_STORE_U8
#define PPC_MM_STORE_U8(x, y) PPC_STORE_U8 (x, y)
#define PPC_MM_STORE_U8(x, y) PPC_STORE_U8(x, y)
#endif
#ifndef PPC_MM_STORE_U16
#define PPC_MM_STORE_U16(x, y) PPC_STORE_U16(x, y)
#define PPC_MM_STORE_U16(x, y) PPC_STORE_U16(x, y)
#endif
#ifndef PPC_MM_STORE_U32
#define PPC_MM_STORE_U32(x, y) PPC_STORE_U32(x, y)
#define PPC_MM_STORE_U32(x, y) PPC_STORE_U32(x, y)
#endif
#ifndef PPC_MM_STORE_U64
#define PPC_MM_STORE_U64(x, y) PPC_STORE_U64(x, y)
#define PPC_MM_STORE_U64(x, y) PPC_STORE_U64(x, y)
#endif
#ifndef PPC_CALL_FUNC
@ -229,7 +229,7 @@ struct PPCFPSCRRegister
csr = _mm_getcsr();
return HostToGuest[(csr & _MM_ROUND_MASK) >> 13];
}
inline void storeFromGuest(uint32_t value) noexcept
{
csr &= ~_MM_ROUND_MASK;
@ -513,6 +513,8 @@ struct PPCContext
#endif
};
// clang-format off
inline uint8_t VectorMaskL[] =
{
0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
@ -593,7 +595,9 @@ inline uint8_t VectorShiftTableR[] =
0x10, 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
};
inline __m128i _mm_adds_epu32(__m128i a, __m128i b)
// clang-format on
inline __m128i _mm_adds_epu32(__m128i a, __m128i b)
{
return _mm_add_epi32(a, _mm_min_epu32(_mm_xor_si128(a, _mm_cmpeq_epi32(a, a)), b));
}

View File

@ -1,6 +1,6 @@
#pragma once
#include <string>
#include <cstdint>
#include <string>
enum SectionFlags : uint8_t
{
@ -11,11 +11,11 @@ enum SectionFlags : uint8_t
struct Section
{
std::string name{};
size_t base{};
uint32_t size{};
SectionFlags flags{};
uint8_t* data{};
std::string name {};
size_t base {};
uint32_t size {};
SectionFlags flags {};
uint8_t* data {};
bool operator<(size_t address) const
{

View File

@ -1,6 +1,6 @@
#pragma once
#include <string>
#include <cstdint>
#include <string>
enum SymbolType
{
@ -12,10 +12,10 @@ enum SymbolType
struct Symbol
{
mutable std::string name{};
size_t address{};
size_t size{};
mutable SymbolType type{};
mutable std::string name {};
size_t address {};
size_t size {};
mutable SymbolType type {};
Symbol()
{

View File

@ -4,7 +4,7 @@
class SymbolTable : public std::multiset<Symbol, SymbolComparer>
{
public:
public:
const_iterator find(size_t address) const
{
auto [beginIt, endIt] = equal_range(address);
@ -13,7 +13,7 @@ public:
return end();
}
size_t closest{ address - beginIt->address };
size_t closest { address - beginIt->address };
auto match = end();
for (auto it = beginIt; it != endIt; ++it)
{
@ -41,7 +41,7 @@ public:
return end();
}
size_t closest{ address - beginIt->address };
size_t closest { address - beginIt->address };
auto match = end();
for (auto it = beginIt; it != endIt; ++it)
{

View File

@ -1,12 +1,12 @@
#pragma once
#include <cstdint>
#include <type_traits>
#include <bit>
#include <string>
#include "byteswap.h"
#include <bit>
#include <cstdint>
#include <string>
#include <type_traits>
#ifdef _WIN32
#include <windows.h>
#include <windows.h>
#endif
// real win32 handles will never use the upper bits unless something goes really wrong
@ -15,7 +15,7 @@
#define HOST_HANDLE(HANDLE) ((HANDLE) & ~0x80000000)
// Return true to free the associated memory
typedef bool(*TypeDestructor_t)(void*);
typedef bool (*TypeDestructor_t)(void*);
template<typename T>
bool DestroyObject(void* obj)
@ -71,13 +71,13 @@ struct be
return byteswap(value);
}
be& operator| (T value)
be& operator|(T value)
{
set(get() | value);
return *this;
}
be& operator& (T value)
be& operator&(T value)
{
set(get() & value);
return *this;
@ -119,7 +119,7 @@ struct xpointer
return reinterpret_cast<T*>(MmGetHostAddress(ptr));
}
operator T* () const
operator T*() const
{
return get();
}
@ -144,7 +144,7 @@ typedef struct _IMAGE_CE_RUNTIME_FUNCTION
{
uint32_t BeginAddress;
union
union
{
uint32_t Data;
struct
@ -196,7 +196,7 @@ typedef struct _XDISPATCHER_HEADER
be<uint32_t> SignalState;
XLIST_ENTRY WaitListHead;
} XDISPATCHER_HEADER, * XPDISPATCHER_HEADER;
} XDISPATCHER_HEADER, *XPDISPATCHER_HEADER;
// These variables are never accessed in guest code, we can safely use them in little endian
typedef struct _XRTL_CRITICAL_SECTION
@ -207,7 +207,8 @@ typedef struct _XRTL_CRITICAL_SECTION
uint32_t OwningThread;
} XRTL_CRITICAL_SECTION;
typedef struct _XANSI_STRING {
typedef struct _XANSI_STRING
{
be<uint16_t> Length;
be<uint16_t> MaximumLength;
xpointer<char> Buffer;
@ -224,14 +225,16 @@ typedef XDISPATCHER_HEADER XKEVENT;
typedef struct _XIO_STATUS_BLOCK
{
union {
union
{
be<uint32_t> Status;
be<uint32_t> Pointer;
};
be<uint32_t> Information;
} XIO_STATUS_BLOCK;
typedef struct _XOVERLAPPED {
typedef struct _XOVERLAPPED
{
be<uint32_t> Internal;
be<uint32_t> InternalHigh;
be<uint32_t> Offset;
@ -240,7 +243,8 @@ typedef struct _XOVERLAPPED {
} XOVERLAPPED;
// this name is so dumb
typedef struct _XXOVERLAPPED {
typedef struct _XXOVERLAPPED
{
union
{
struct
@ -265,7 +269,8 @@ typedef struct _XXOVERLAPPED {
static_assert(sizeof(_XXOVERLAPPED) == 0x1C);
// https://learn.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-memorystatus
typedef struct _XMEMORYSTATUS {
typedef struct _XMEMORYSTATUS
{
be<uint32_t> dwLength;
be<uint32_t> dwMemoryLoad;
be<uint32_t> dwTotalPhys;
@ -274,7 +279,7 @@ typedef struct _XMEMORYSTATUS {
be<uint32_t> dwAvailPageFile;
be<uint32_t> dwTotalVirtual;
be<uint32_t> dwAvailVirtual;
} XMEMORYSTATUS, * XLPMEMORYSTATUS;
} XMEMORYSTATUS, *XLPMEMORYSTATUS;
typedef struct _XVIDEO_MODE
{
@ -296,7 +301,8 @@ typedef struct _XKSEMAPHORE
be<uint32_t> Limit;
} XKSEMAPHORE;
typedef struct _XUSER_SIGNIN_INFO {
typedef struct _XUSER_SIGNIN_INFO
{
be<uint64_t> xuid;
be<uint32_t> dwField08;
be<uint32_t> SigninState;
@ -315,19 +321,19 @@ typedef struct _XTIME_FIELDS
be<uint16_t> Second;
be<uint16_t> Milliseconds;
be<uint16_t> Weekday;
} XTIME_FIELDS, * PXTIME_FIELDS;
} XTIME_FIELDS, *PXTIME_FIELDS;
// Content types
#define XCONTENTTYPE_SAVEDATA 1
#define XCONTENTTYPE_DLC 2
#define XCONTENTTYPE_DLC 2
#define XCONTENTTYPE_RESERVED 3
#define XCONTENT_NEW 1
#define XCONTENT_NEW 1
#define XCONTENT_EXISTING 2
#define XCONTENT_MAX_DISPLAYNAME 128
#define XCONTENT_MAX_FILENAME 42
#define XCONTENTDEVICE_MAX_NAME 27
#define XCONTENT_MAX_FILENAME 42
#define XCONTENTDEVICE_MAX_NAME 27
typedef struct _XCONTENT_DATA
{
@ -335,15 +341,14 @@ typedef struct _XCONTENT_DATA
be<uint32_t> dwContentType;
be<uint16_t> szDisplayName[XCONTENT_MAX_DISPLAYNAME];
char szFileName[XCONTENT_MAX_FILENAME];
} XCONTENT_DATA, * PXCONTENT_DATA;
} XCONTENT_DATA, *PXCONTENT_DATA;
typedef struct _XHOSTCONTENT_DATA : _XCONTENT_DATA
{
// This is a host exclusive type so we don't care what goes on
std::string szRoot{};
std::string szRoot {};
} XHOSTCONTENT_DATA, *PXHOSTCONTENT_DATA;
#define XCONTENTDEVICETYPE_HDD 1
#define XCONTENTDEVICETYPE_MU 2
@ -358,52 +363,52 @@ typedef struct _XDEVICE_DATA
// Direct reflection of XInput structures
#define XAMINPUT_DEVTYPE_GAMEPAD 0x01
#define XAMINPUT_DEVSUBTYPE_GAMEPAD 0x01
#define XAMINPUT_DEVTYPE_GAMEPAD 0x01
#define XAMINPUT_DEVSUBTYPE_GAMEPAD 0x01
#define XAMINPUT_GAMEPAD_DPAD_UP 0x0001
#define XAMINPUT_GAMEPAD_DPAD_DOWN 0x0002
#define XAMINPUT_GAMEPAD_DPAD_LEFT 0x0004
#define XAMINPUT_GAMEPAD_DPAD_RIGHT 0x0008
#define XAMINPUT_GAMEPAD_START 0x0010
#define XAMINPUT_GAMEPAD_BACK 0x0020
#define XAMINPUT_GAMEPAD_LEFT_THUMB 0x0040
#define XAMINPUT_GAMEPAD_RIGHT_THUMB 0x0080
#define XAMINPUT_GAMEPAD_LEFT_SHOULDER 0x0100
#define XAMINPUT_GAMEPAD_RIGHT_SHOULDER 0x0200
#define XAMINPUT_GAMEPAD_A 0x1000
#define XAMINPUT_GAMEPAD_B 0x2000
#define XAMINPUT_GAMEPAD_X 0x4000
#define XAMINPUT_GAMEPAD_Y 0x8000
#define XAMINPUT_GAMEPAD_DPAD_UP 0x0001
#define XAMINPUT_GAMEPAD_DPAD_DOWN 0x0002
#define XAMINPUT_GAMEPAD_DPAD_LEFT 0x0004
#define XAMINPUT_GAMEPAD_DPAD_RIGHT 0x0008
#define XAMINPUT_GAMEPAD_START 0x0010
#define XAMINPUT_GAMEPAD_BACK 0x0020
#define XAMINPUT_GAMEPAD_LEFT_THUMB 0x0040
#define XAMINPUT_GAMEPAD_RIGHT_THUMB 0x0080
#define XAMINPUT_GAMEPAD_LEFT_SHOULDER 0x0100
#define XAMINPUT_GAMEPAD_RIGHT_SHOULDER 0x0200
#define XAMINPUT_GAMEPAD_A 0x1000
#define XAMINPUT_GAMEPAD_B 0x2000
#define XAMINPUT_GAMEPAD_X 0x4000
#define XAMINPUT_GAMEPAD_Y 0x8000
typedef struct _XAMINPUT_GAMEPAD
{
uint16_t wButtons;
uint8_t bLeftTrigger;
uint8_t bRightTrigger;
int16_t sThumbLX;
int16_t sThumbLY;
int16_t sThumbRX;
int16_t sThumbRY;
uint16_t wButtons;
uint8_t bLeftTrigger;
uint8_t bRightTrigger;
int16_t sThumbLX;
int16_t sThumbLY;
int16_t sThumbRX;
int16_t sThumbRY;
} XAMINPUT_GAMEPAD, *PXAMINPUT_GAMEPAD;
typedef struct _XAMINPUT_VIBRATION
{
uint16_t wLeftMotorSpeed;
uint16_t wRightMotorSpeed;
} XAMINPUT_VIBRATION, * PXAMINPUT_VIBRATION;
uint16_t wLeftMotorSpeed;
uint16_t wRightMotorSpeed;
} XAMINPUT_VIBRATION, *PXAMINPUT_VIBRATION;
typedef struct _XAMINPUT_CAPABILITIES
{
uint8_t Type;
uint8_t SubType;
uint16_t Flags;
XAMINPUT_GAMEPAD Gamepad;
XAMINPUT_VIBRATION Vibration;
} XAMINPUT_CAPABILITIES, * PXAMINPUT_CAPABILITIES;
uint8_t Type;
uint8_t SubType;
uint16_t Flags;
XAMINPUT_GAMEPAD Gamepad;
XAMINPUT_VIBRATION Vibration;
} XAMINPUT_CAPABILITIES, *PXAMINPUT_CAPABILITIES;
typedef struct _XAMINPUT_STATE
{
uint32_t dwPacketNumber;
XAMINPUT_GAMEPAD Gamepad;
} XAMINPUT_STATE, * PXAMINPUT_STATE;
uint32_t dwPacketNumber;
XAMINPUT_GAMEPAD Gamepad;
} XAMINPUT_STATE, *PXAMINPUT_STATE;

View File

@ -1,7 +1,7 @@
#pragma once
#include <vector>
#include "xdbf.h"
#include <vector>
struct Achievement
{
@ -27,7 +27,7 @@ struct XDBFBlock
class XDBFWrapper
{
public:
public:
const uint8_t* pBuffer;
size_t BufferSize;

View File

@ -1,6 +1,6 @@
#pragma once
#include <memory>
#include "xbox.h"
#include <memory>
inline constexpr uint8_t Xex2RetailKey[16] = { 0x20, 0xB1, 0x85, 0xA5, 0x9D, 0x28, 0xFD, 0xC3, 0x40, 0x58, 0x3F, 0xBB, 0x08, 0x96, 0xBF, 0x91 };
inline constexpr uint8_t AESBlankIV[16] = {};
@ -193,7 +193,7 @@ struct Xex2ImportHeader
be<uint32_t> numImports;
};
struct Xex2ImportLibrary
struct Xex2ImportLibrary
{
be<uint32_t> size;
char nextImportDigest[0x14];
@ -204,12 +204,12 @@ struct Xex2ImportLibrary
be<uint16_t> numberOfImports;
};
struct Xex2ImportDescriptor
struct Xex2ImportDescriptor
{
be<uint32_t> firstThunk; // VA XEX_THUNK_DATA
};
struct Xex2ThunkData
struct Xex2ThunkData
{
union
{

View File

@ -18,7 +18,8 @@
struct XexPatcher
{
enum class Result {
enum class Result
{
Success,
FileOpenFailed,
FileWriteFailed,
@ -30,6 +31,6 @@ struct XexPatcher
PatchUnsupported
};
static Result apply(const uint8_t* xexBytes, size_t xexBytesSize, const uint8_t* patchBytes, size_t patchBytesSize, std::vector<uint8_t> &outBytes, bool skipData);
static Result apply(const std::filesystem::path &baseXexPath, const std::filesystem::path &patchXexPath, const std::filesystem::path &newXexPath);
static Result apply(const uint8_t* xexBytes, size_t xexBytesSize, const uint8_t* patchBytes, size_t patchBytesSize, std::vector<uint8_t>& outBytes, bool skipData);
static Result apply(const std::filesystem::path& baseXexPath, const std::filesystem::path& patchXexPath, const std::filesystem::path& newXexPath);
};