From 1e24423ea72ae9209c54edaa120592f1ee3216a4 Mon Sep 17 00:00:00 2001 From: Sajid Date: Sat, 7 Sep 2024 18:21:08 +0600 Subject: [PATCH] Editorconfig --- .editorconfig | 10 ++++++ PowerAnalyse/main.cpp | 52 +++++++++++++++--------------- PowerRecomp/main.cpp | 4 +-- PowerUtils/disasm.cpp | 8 ++--- PowerUtils/disasm.h | 40 +++++++++++------------ PowerUtils/file.h | 26 +++++++-------- PowerUtils/xbox.h | 50 ++++++++++++++--------------- PowerUtils/xex.cpp | 74 +++++++++++++++++++++---------------------- 8 files changed, 137 insertions(+), 127 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..31f2d51 --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/PowerAnalyse/main.cpp b/PowerAnalyse/main.cpp index e262253..e63c027 100644 --- a/PowerAnalyse/main.cpp +++ b/PowerAnalyse/main.cpp @@ -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(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(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; } \ No newline at end of file diff --git a/PowerRecomp/main.cpp b/PowerRecomp/main.cpp index f44b624..905869d 100644 --- a/PowerRecomp/main.cpp +++ b/PowerRecomp/main.cpp @@ -1,4 +1,4 @@ int main() { - return 0; -} \ No newline at end of file + return 0; +} diff --git a/PowerUtils/disasm.cpp b/PowerUtils/disasm.cpp index d17f2ca..0bca6e8 100644 --- a/PowerUtils/disasm.cpp +++ b/PowerUtils/disasm.cpp @@ -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); } diff --git a/PowerUtils/disasm.h b/PowerUtils/disasm.h index fc200a2..04f5f80 100644 --- a/PowerUtils/disasm.h +++ b/PowerUtils/disasm.h @@ -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); + } } \ No newline at end of file diff --git a/PowerUtils/file.h b/PowerUtils/file.h index 13e2049..145fe4f 100644 --- a/PowerUtils/file.h +++ b/PowerUtils/file.h @@ -3,23 +3,23 @@ inline static std::vector LoadFile(const char* path) { - std::vector data{}; - auto* stream = fopen(path, "rb"); - if (stream == nullptr) - { - return data; - } + std::vector 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; } \ No newline at end of file diff --git a/PowerUtils/xbox.h b/PowerUtils/xbox.h index c057d42..8b2785a 100644 --- a/PowerUtils/xbox.h +++ b/PowerUtils/xbox.h @@ -4,35 +4,35 @@ #include #ifdef _WIN32 - #include + #include #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; diff --git a/PowerUtils/xex.cpp b/PowerUtils/xex.cpp index 4a519ce..2e87c9c 100644 --- a/PowerUtils/xex.cpp +++ b/PowerUtils/xex.cpp @@ -3,51 +3,51 @@ std::unique_ptr Xex2LoadImage(const uint8_t* data) { - auto* header = reinterpret_cast(data); - auto* security = reinterpret_cast(data + header->AddressOfSecurityInfo); + auto* header = reinterpret_cast(data); + auto* security = reinterpret_cast(data + header->AddressOfSecurityInfo); - const auto* compressionInfo = Xex2FindOptionalHeader(header, XEX_HEADER_FILE_FORMAT_INFO); + const auto* compressionInfo = Xex2FindOptionalHeader(header, XEX_HEADER_FILE_FORMAT_INFO); - std::unique_ptr result{}; - size_t imageSize = security->SizeOfImage; + std::unique_ptr 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(imageSize); - memcpy(result.get(), data + header->SizeOfHeader, imageSize); - } - else if (compressionInfo->CompressionType == XEX_COMPRESSION_BASIC) - { - auto* blocks = reinterpret_cast(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(imageSize); + memcpy(result.get(), data + header->SizeOfHeader, imageSize); + } + else if (compressionInfo->CompressionType == XEX_COMPRESSION_BASIC) + { + auto* blocks = reinterpret_cast(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(imageSize); - auto* srcData = data + header->SizeOfHeader; - auto* destData = result.get(); + result = std::make_unique(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; } \ No newline at end of file