mirror of
https://github.com/hedge-dev/XenonRecomp.git
synced 2025-04-19 10:51:18 +00:00
Editorconfig
This commit is contained in:
parent
0f9a53f75a
commit
1e24423ea7
10
.editorconfig
Normal file
10
.editorconfig
Normal file
@ -0,0 +1,10 @@
|
||||
# editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
insert_final_newline = true
|
||||
end_of_line = lf
|
@ -5,37 +5,37 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
// TODO: ELFs, symbols, sections, a lot
|
||||
const auto file = LoadFile("default.xex");
|
||||
const auto image = Xex2LoadImage(file.data());
|
||||
// TODO: ELFs, symbols, sections, a lot
|
||||
const auto file = LoadFile("default.xex");
|
||||
const auto image = Xex2LoadImage(file.data());
|
||||
|
||||
auto* headers = (IMAGE_NT_HEADERS32*)(image.get() + ((IMAGE_DOS_HEADER*)image.get())->e_lfanew);
|
||||
auto numSections = headers->FileHeader.NumberOfSections;
|
||||
auto* sections = (IMAGE_SECTION_HEADER*)(headers + 1);
|
||||
auto base = headers->OptionalHeader.ImageBase;
|
||||
auto* headers = (IMAGE_NT_HEADERS32*)(image.get() + ((IMAGE_DOS_HEADER*)image.get())->e_lfanew);
|
||||
auto numSections = headers->FileHeader.NumberOfSections;
|
||||
auto* sections = (IMAGE_SECTION_HEADER*)(headers + 1);
|
||||
auto base = headers->OptionalHeader.ImageBase;
|
||||
|
||||
for (size_t i = 0; i < numSections; i++)
|
||||
{
|
||||
const auto& section = sections[i];
|
||||
std::printf("Section %.8s\n", reinterpret_cast<const char*>(section.Name));
|
||||
std::printf("\t%X-%X\n", base + section.VirtualAddress, base + section.VirtualAddress + section.Misc.VirtualSize);
|
||||
for (size_t i = 0; i < numSections; i++)
|
||||
{
|
||||
const auto& section = sections[i];
|
||||
std::printf("Section %.8s\n", reinterpret_cast<const char*>(section.Name));
|
||||
std::printf("\t%X-%X\n", base + section.VirtualAddress, base + section.VirtualAddress + section.Misc.VirtualSize);
|
||||
|
||||
auto* data = image.get() + section.VirtualAddress; // XEX is weird
|
||||
ppc::SetDetail(true);
|
||||
auto* data = image.get() + section.VirtualAddress; // XEX is weird
|
||||
ppc::SetDetail(true);
|
||||
|
||||
if (section.Characteristics & IMAGE_SCN_CNT_CODE)
|
||||
{
|
||||
cs_insn* instructions;
|
||||
size_t n = ppc::Disassemble(data, section.SizeOfRawData, base + section.VirtualAddress, 0, &instructions);
|
||||
if (section.Characteristics & IMAGE_SCN_CNT_CODE)
|
||||
{
|
||||
cs_insn* instructions;
|
||||
size_t n = ppc::Disassemble(data, section.SizeOfRawData, base + section.VirtualAddress, 0, &instructions);
|
||||
|
||||
for(size_t i = 0; i < n; i++)
|
||||
{
|
||||
printf("\t%s\n", instructions[i].mnemonic);
|
||||
}
|
||||
for(size_t i = 0; i < n; i++)
|
||||
{
|
||||
printf("\t%s\n", instructions[i].mnemonic);
|
||||
}
|
||||
|
||||
cs_free(instructions, n);
|
||||
}
|
||||
}
|
||||
cs_free(instructions, n);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
@ -4,20 +4,20 @@ DisassemblerEngine ppc::gPPCBigEndianDisassembler{ CS_ARCH_PPC, CS_MODE_BIG_ENDI
|
||||
|
||||
DisassemblerEngine::DisassemblerEngine(cs_arch arch, cs_mode mode)
|
||||
{
|
||||
cs_open(arch, mode, &handle);
|
||||
cs_open(arch, mode, &handle);
|
||||
}
|
||||
|
||||
size_t DisassemblerEngine::Disassemble(const uint8_t* code, size_t size, uint64_t base, size_t count, cs_insn** instructions) const
|
||||
{
|
||||
return cs_disasm(handle, code, size, base, count, instructions);
|
||||
return cs_disasm(handle, code, size, base, count, instructions);
|
||||
}
|
||||
|
||||
void DisassemblerEngine::SetOption(cs_opt_type option, size_t value)
|
||||
{
|
||||
cs_option(handle, option, value);
|
||||
cs_option(handle, option, value);
|
||||
}
|
||||
|
||||
DisassemblerEngine::~DisassemblerEngine()
|
||||
{
|
||||
cs_close(&handle);
|
||||
cs_close(&handle);
|
||||
}
|
||||
|
@ -3,32 +3,32 @@
|
||||
|
||||
struct DisassemblerEngine
|
||||
{
|
||||
csh handle{};
|
||||
csh handle{};
|
||||
|
||||
DisassemblerEngine(const DisassemblerEngine&) = default;
|
||||
DisassemblerEngine& operator=(const DisassemblerEngine&) = delete;
|
||||
DisassemblerEngine(const DisassemblerEngine&) = default;
|
||||
DisassemblerEngine& operator=(const DisassemblerEngine&) = delete;
|
||||
|
||||
DisassemblerEngine(cs_arch arch, cs_mode mode);
|
||||
~DisassemblerEngine();
|
||||
size_t Disassemble(const uint8_t* code, size_t size, uint64_t base, size_t count, cs_insn** instructions) const;
|
||||
void SetOption(cs_opt_type option, size_t value);
|
||||
DisassemblerEngine(cs_arch arch, cs_mode mode);
|
||||
~DisassemblerEngine();
|
||||
size_t Disassemble(const uint8_t* code, size_t size, uint64_t base, size_t count, cs_insn** instructions) const;
|
||||
void SetOption(cs_opt_type option, size_t value);
|
||||
|
||||
void SetDetail(bool value)
|
||||
{
|
||||
SetOption(CS_OPT_DETAIL, value);
|
||||
}
|
||||
void SetDetail(bool value)
|
||||
{
|
||||
SetOption(CS_OPT_DETAIL, value);
|
||||
}
|
||||
};
|
||||
|
||||
namespace ppc
|
||||
{
|
||||
extern DisassemblerEngine gPPCBigEndianDisassembler;
|
||||
static size_t Disassemble(const uint8_t* code, size_t size, uint64_t base, size_t count, cs_insn** instructions)
|
||||
{
|
||||
return gPPCBigEndianDisassembler.Disassemble(code, size, base, count, instructions);
|
||||
}
|
||||
extern DisassemblerEngine gPPCBigEndianDisassembler;
|
||||
static size_t Disassemble(const uint8_t* code, size_t size, uint64_t base, size_t count, cs_insn** instructions)
|
||||
{
|
||||
return gPPCBigEndianDisassembler.Disassemble(code, size, base, count, instructions);
|
||||
}
|
||||
|
||||
static void SetDetail(bool value)
|
||||
{
|
||||
gPPCBigEndianDisassembler.SetDetail(value);
|
||||
}
|
||||
static void SetDetail(bool value)
|
||||
{
|
||||
gPPCBigEndianDisassembler.SetDetail(value);
|
||||
}
|
||||
}
|
@ -3,23 +3,23 @@
|
||||
|
||||
inline static std::vector<uint8_t> LoadFile(const char* path)
|
||||
{
|
||||
std::vector<uint8_t> data{};
|
||||
auto* stream = fopen(path, "rb");
|
||||
if (stream == nullptr)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
std::vector<uint8_t> data{};
|
||||
auto* stream = fopen(path, "rb");
|
||||
if (stream == nullptr)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
fseek(stream, 0, SEEK_END);
|
||||
fseek(stream, 0, SEEK_END);
|
||||
|
||||
const auto size = ftell(stream);
|
||||
const auto size = ftell(stream);
|
||||
|
||||
fseek(stream, 0, SEEK_SET);
|
||||
fseek(stream, 0, SEEK_SET);
|
||||
|
||||
data.resize(size);
|
||||
data.resize(size);
|
||||
|
||||
fread(data.data(), 1, data.size(), stream);
|
||||
fclose(stream);
|
||||
fread(data.data(), 1, data.size(), stream);
|
||||
fclose(stream);
|
||||
|
||||
return data;
|
||||
return data;
|
||||
}
|
@ -4,35 +4,35 @@
|
||||
#include <bit>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <windows.h>
|
||||
#else
|
||||
#define near
|
||||
#define far
|
||||
#define near
|
||||
#define far
|
||||
|
||||
typedef char CHAR;
|
||||
typedef wchar_t WCHAR;
|
||||
typedef unsigned long DWORD;
|
||||
typedef int BOOL;
|
||||
typedef unsigned char BYTE;
|
||||
typedef unsigned short WORD;
|
||||
typedef float FLOAT;
|
||||
typedef FLOAT* PFLOAT;
|
||||
typedef BOOL near* PBOOL;
|
||||
typedef BOOL far* LPBOOL;
|
||||
typedef BYTE near* PBYTE;
|
||||
typedef BYTE far* LPBYTE;
|
||||
typedef int near* PINT;
|
||||
typedef int far* LPINT;
|
||||
typedef WORD near* PWORD;
|
||||
typedef WORD far* LPWORD;
|
||||
typedef long far* LPLONG;
|
||||
typedef DWORD near* PDWORD;
|
||||
typedef DWORD far* LPDWORD;
|
||||
typedef void far* LPVOID;
|
||||
typedef const void far* LPCVOID;
|
||||
typedef char CHAR;
|
||||
typedef wchar_t WCHAR;
|
||||
typedef unsigned long DWORD;
|
||||
typedef int BOOL;
|
||||
typedef unsigned char BYTE;
|
||||
typedef unsigned short WORD;
|
||||
typedef float FLOAT;
|
||||
typedef FLOAT* PFLOAT;
|
||||
typedef BOOL near* PBOOL;
|
||||
typedef BOOL far* LPBOOL;
|
||||
typedef BYTE near* PBYTE;
|
||||
typedef BYTE far* LPBYTE;
|
||||
typedef int near* PINT;
|
||||
typedef int far* LPINT;
|
||||
typedef WORD near* PWORD;
|
||||
typedef WORD far* LPWORD;
|
||||
typedef long far* LPLONG;
|
||||
typedef DWORD near* PDWORD;
|
||||
typedef DWORD far* LPDWORD;
|
||||
typedef void far* LPVOID;
|
||||
typedef const void far* LPCVOID;
|
||||
typedef unsigned long ULONG;
|
||||
typedef ULONG* PULONG;
|
||||
typedef signed long LONG;
|
||||
typedef signed long LONG;
|
||||
typedef LONG* PLONG;
|
||||
typedef unsigned long long ULONGLONG;
|
||||
typedef ULONGLONG* PULONGLONG;
|
||||
|
@ -3,51 +3,51 @@
|
||||
|
||||
std::unique_ptr<uint8_t[]> Xex2LoadImage(const uint8_t* data)
|
||||
{
|
||||
auto* header = reinterpret_cast<const XEX_HEADER*>(data);
|
||||
auto* security = reinterpret_cast<const XEX2_SECURITY_INFO*>(data + header->AddressOfSecurityInfo);
|
||||
auto* header = reinterpret_cast<const XEX_HEADER*>(data);
|
||||
auto* security = reinterpret_cast<const XEX2_SECURITY_INFO*>(data + header->AddressOfSecurityInfo);
|
||||
|
||||
const auto* compressionInfo = Xex2FindOptionalHeader<XEX_FILE_FORMAT_INFO>(header, XEX_HEADER_FILE_FORMAT_INFO);
|
||||
const auto* compressionInfo = Xex2FindOptionalHeader<XEX_FILE_FORMAT_INFO>(header, XEX_HEADER_FILE_FORMAT_INFO);
|
||||
|
||||
std::unique_ptr<uint8_t[]> result{};
|
||||
size_t imageSize = security->SizeOfImage;
|
||||
std::unique_ptr<uint8_t[]> result{};
|
||||
size_t imageSize = security->SizeOfImage;
|
||||
|
||||
if (compressionInfo != nullptr)
|
||||
{
|
||||
assert(compressionInfo->CompressionType >= XEX_COMPRESSION_BASIC);
|
||||
assert(compressionInfo->EncryptionType == XEX_ENCRYPTION_NONE);
|
||||
if (compressionInfo != nullptr)
|
||||
{
|
||||
assert(compressionInfo->CompressionType >= XEX_COMPRESSION_BASIC);
|
||||
assert(compressionInfo->EncryptionType == XEX_ENCRYPTION_NONE);
|
||||
|
||||
if (compressionInfo->CompressionType == XEX_COMPRESSION_NONE)
|
||||
{
|
||||
result = std::make_unique<uint8_t[]>(imageSize);
|
||||
memcpy(result.get(), data + header->SizeOfHeader, imageSize);
|
||||
}
|
||||
else if (compressionInfo->CompressionType == XEX_COMPRESSION_BASIC)
|
||||
{
|
||||
auto* blocks = reinterpret_cast<const XEX_BASIC_FILE_COMPRESSION_INFO*>(compressionInfo + 1);
|
||||
const size_t numBlocks = (compressionInfo->SizeOfHeader / sizeof(XEX_BASIC_FILE_COMPRESSION_INFO)) - 1;
|
||||
if (compressionInfo->CompressionType == XEX_COMPRESSION_NONE)
|
||||
{
|
||||
result = std::make_unique<uint8_t[]>(imageSize);
|
||||
memcpy(result.get(), data + header->SizeOfHeader, imageSize);
|
||||
}
|
||||
else if (compressionInfo->CompressionType == XEX_COMPRESSION_BASIC)
|
||||
{
|
||||
auto* blocks = reinterpret_cast<const XEX_BASIC_FILE_COMPRESSION_INFO*>(compressionInfo + 1);
|
||||
const size_t numBlocks = (compressionInfo->SizeOfHeader / sizeof(XEX_BASIC_FILE_COMPRESSION_INFO)) - 1;
|
||||
|
||||
imageSize = 0;
|
||||
for (size_t i = 0; i < numBlocks; i++)
|
||||
{
|
||||
imageSize += blocks[i].SizeOfData + blocks[i].SizeOfPadding;
|
||||
}
|
||||
imageSize = 0;
|
||||
for (size_t i = 0; i < numBlocks; i++)
|
||||
{
|
||||
imageSize += blocks[i].SizeOfData + blocks[i].SizeOfPadding;
|
||||
}
|
||||
|
||||
result = std::make_unique<uint8_t[]>(imageSize);
|
||||
auto* srcData = data + header->SizeOfHeader;
|
||||
auto* destData = result.get();
|
||||
result = std::make_unique<uint8_t[]>(imageSize);
|
||||
auto* srcData = data + header->SizeOfHeader;
|
||||
auto* destData = result.get();
|
||||
|
||||
for (size_t i = 0; i < numBlocks; i++)
|
||||
{
|
||||
memcpy(destData, srcData, blocks[i].SizeOfData);
|
||||
for (size_t i = 0; i < numBlocks; i++)
|
||||
{
|
||||
memcpy(destData, srcData, blocks[i].SizeOfData);
|
||||
|
||||
srcData += blocks[i].SizeOfData;
|
||||
destData += blocks[i].SizeOfData;
|
||||
srcData += blocks[i].SizeOfData;
|
||||
destData += blocks[i].SizeOfData;
|
||||
|
||||
memset(destData, 0, blocks[i].SizeOfPadding);
|
||||
destData += blocks[i].SizeOfPadding;
|
||||
}
|
||||
}
|
||||
}
|
||||
memset(destData, 0, blocks[i].SizeOfPadding);
|
||||
destData += blocks[i].SizeOfPadding;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user