From b1a4854c1b1b745d7819004d60d2cd8106dc5cdf Mon Sep 17 00:00:00 2001 From: Liliana Newton Date: Sun, 26 Oct 2025 00:14:49 +0100 Subject: [PATCH] non-working linux successful build + instructions --- README.md | 12 +++++------- llvm360/Emulator/src/Shared.h | 1 - llvm360/Emulator/src/emulator.cpp | 16 ++++++++++------ llvm360/Naive+/CMakeLists.txt | 4 ++-- .../Naive+/src/Decoder/InstructionRegistry.cpp | 2 +- llvm360/Naive+/src/Decoder/InstructionRegistry.h | 9 +++++++-- llvm360/Naive+/src/LLVM360.cpp | 2 +- llvm360/Naive+/src/Loader/ImageLoader.cpp | 12 ++++++++++-- llvm360/Naive+/src/Loader/PEImage.h | 13 ++++++++++++- llvm360/Naive+/src/Logger.h | 10 +++++----- llvm360/Naive+/src/Naive+/Naive+.h | 6 ++++-- llvm360/Naive+/src/Shared.h | 6 +++++- 12 files changed, 62 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index a013b57..80c4b80 100644 --- a/README.md +++ b/README.md @@ -8,17 +8,15 @@ This is just a little personal experiment i'm doing with llvm, the code is not g Join the project [Discord][dis] server! ### Name -"LLVM360" LLVM + xbox360, but it's just a temporany, i don't really like it so will probably change +"LLVM360" LLVM + xbox360, but it's just temporary, i don't really like it so will probably change ## Building - Clang compiler is required -- Git Clone this repository -- idk that's it -- If everything is good and i or you didn't messed up something, it should compile fine +- Git Clone this repository by doing `git clone https://github.com/AleBello7276/LLVM360 --recursive --shallow-submodules`, so it doesnt take 500 years to download llvm (but it will still take a long time because it's 1.4gb which is stupid) +- Do `cmake .` +- If everything is good and i or you didn't mess something up, it should compile fine ## Contributing -if want to contribute, make a fork and a PR :} also join the discord server! - - +if want to contribute, make a fork and a PR :} also join the discord server! [dis]: https://discord.gg/JufwFS9mmf diff --git a/llvm360/Emulator/src/Shared.h b/llvm360/Emulator/src/Shared.h index 27fc6e4..731c077 100644 --- a/llvm360/Emulator/src/Shared.h +++ b/llvm360/Emulator/src/Shared.h @@ -7,6 +7,5 @@ #include #include -#include #include diff --git a/llvm360/Emulator/src/emulator.cpp b/llvm360/Emulator/src/emulator.cpp index 9e926f1..b15ef57 100644 --- a/llvm360/Emulator/src/emulator.cpp +++ b/llvm360/Emulator/src/emulator.cpp @@ -1,14 +1,18 @@ #include "Shared.h" #include "Naive+.h" +#include +#include - - - -int main() +int main(int argc, char *argv[]) { - - PBinaryHandle* handle = TranslateBinary(L"./kernel17559.exe", false, true); + std::wstring path; + if (argc < 2) { + path = L"./kernel17559.exe"; + } else { + path = std::wstring_convert>().from_bytes(argv[1]); + } + PBinaryHandle* handle = TranslateBinary(path, false, true); printf("YEY"); return 0; } diff --git a/llvm360/Naive+/CMakeLists.txt b/llvm360/Naive+/CMakeLists.txt index a8a801c..119958e 100644 --- a/llvm360/Naive+/CMakeLists.txt +++ b/llvm360/Naive+/CMakeLists.txt @@ -5,7 +5,7 @@ project(Naive+) set(Loader src/Loader/PEImage.h - src/Loader/XexImage.h + src/Loader/XEXImage.h src/Loader/ImageLoader.cpp src/Loader/ImageLoader.h src/Loader/table/ImportTable.h @@ -43,4 +43,4 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) add_library(Naive+ SHARED ${CMAKE_CURRENT_SOURCE_DIR}/${SRC}) target_link_libraries(Naive+ PRIVATE ext_llvm) target_compile_definitions(Naive+ PRIVATE NAIVE_EXPORT) -target_include_directories(Naive+ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/Naive+) \ No newline at end of file +target_include_directories(Naive+ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/Naive+) diff --git a/llvm360/Naive+/src/Decoder/InstructionRegistry.cpp b/llvm360/Naive+/src/Decoder/InstructionRegistry.cpp index fede326..da1e75f 100644 --- a/llvm360/Naive+/src/Decoder/InstructionRegistry.cpp +++ b/llvm360/Naive+/src/Decoder/InstructionRegistry.cpp @@ -20,7 +20,7 @@ void InstructionRegistry::InitialiseOpCodeKey(uint32_t mainOP, uint32_t extMASK) void InstructionRegistry::AddDescriptorToKey(uint32_t mainOP, std::string mnemonic, FormType type, uint32_t extOP) { auto it = m_mainOPs.find(mainOP); - if (it == m_mainOPs.end()) { printf("AddDescriptorToKey, Something is wrong :/, did you registerInstructions for this main Opcode? "); _CrtDbgBreak(); } + if (it == m_mainOPs.end()) { printf("AddDescriptorToKey, Something is wrong :/, did you registerInstructions for this main Opcode? "); BREAKPOINT(); } OpcodeKey& key = it->second; uint32_t shift = __builtin_ctz(key.m_extMASK); InstructionDescriptor desc = { mnemonic, type }; diff --git a/llvm360/Naive+/src/Decoder/InstructionRegistry.h b/llvm360/Naive+/src/Decoder/InstructionRegistry.h index e119292..86ac79c 100644 --- a/llvm360/Naive+/src/Decoder/InstructionRegistry.h +++ b/llvm360/Naive+/src/Decoder/InstructionRegistry.h @@ -3,6 +3,11 @@ #include #include +#ifdef _WIN32 +#define BREAKPOINT _CrtDbgBreak +#else +#define BREAKPOINT __builtin_trap +#endif enum FormType { @@ -173,12 +178,12 @@ struct InstructionRegistry // get OpcodeKey by main Opcode auto it = m_mainOPs.find(operands.DEF.OPCD); - if (it == m_mainOPs.end()) { printf("Instruction::DecodeInstr %s : %d", "MAIN OPCODE HAS NO KEY", operands.DEF.OPCD); _CrtDbgBreak(); } + if (it == m_mainOPs.end()) { printf("Instruction::DecodeInstr %s : %d", "MAIN OPCODE HAS NO KEY", operands.DEF.OPCD); BREAKPOINT(); } OpcodeKey& key = it->second; uint32_t extOpcode = (data & key.m_extMASK); auto itDesc = key.m_descriptors.find(extOpcode); - if (itDesc == key.m_descriptors.end()) { printf("Instruction::DecodeInstr %s %d", "OpCodeKey HAS NO DESCRIPTOR FOR THIS EXTOP", extOpcode >> (__builtin_ctz(key.m_extMASK))); _CrtDbgBreak(); } + if (itDesc == key.m_descriptors.end()) { printf("Instruction::DecodeInstr %s %d", "OpCodeKey HAS NO DESCRIPTOR FOR THIS EXTOP", extOpcode >> (__builtin_ctz(key.m_extMASK))); BREAKPOINT(); } InstructionDescriptor& desc = itDesc->second; instr.address = address; diff --git a/llvm360/Naive+/src/LLVM360.cpp b/llvm360/Naive+/src/LLVM360.cpp index ca98ee0..7f4a03d 100644 --- a/llvm360/Naive+/src/LLVM360.cpp +++ b/llvm360/Naive+/src/LLVM360.cpp @@ -149,7 +149,7 @@ void PBinaryHandle::LoadBinary() while (address <= end) { // get and byteswap - uint32_t data = __bswapd( (uint32_t) * (uint32_t*)(secDataPtr + (address - start)) ); + uint32_t data = __bswap_32( (uint32_t) * (uint32_t*)(secDataPtr + (address - start)) ); Instruction instruction = registry.DecodeInstr(data, address); //if (instructionSize == 0) //{ diff --git a/llvm360/Naive+/src/Loader/ImageLoader.cpp b/llvm360/Naive+/src/Loader/ImageLoader.cpp index 945f4a4..90756de 100644 --- a/llvm360/Naive+/src/Loader/ImageLoader.cpp +++ b/llvm360/Naive+/src/Loader/ImageLoader.cpp @@ -4,6 +4,10 @@ #include #include #include +#ifndef _WIN32 +#include +#include +#endif namespace XLoader { @@ -47,7 +51,11 @@ namespace XLoader // ImageLoader implementation std::unique_ptr ImageLoader::load(const std::wstring& path) { // Open file + #ifdef _WIN32 std::ifstream file(path, std::ios::binary | std::ios::ate); + #else + std::ifstream file(std::wstring_convert>().to_bytes(path), std::ios::binary | std::ios::ate); + #endif if (!file.is_open()) { printf("Failed to open file\n"); return nullptr; @@ -306,7 +314,7 @@ namespace XLoader auto& importDir = m_optHeader.dataDirectories[1]; if (importDir.VirtualAddress != 0 && importDir.Size != 0) { // Would parse import descriptors here - printf("Import directory found at RVA 0x%08X\n", importDir.VirtualAddress); + printf("Import directory found at RVA 0x%08lX\n", importDir.VirtualAddress); } } @@ -848,4 +856,4 @@ import->funcImportAddr = recordAddr; return true; } -} \ No newline at end of file +} diff --git a/llvm360/Naive+/src/Loader/PEImage.h b/llvm360/Naive+/src/Loader/PEImage.h index 7ceb36a..7eb7715 100644 --- a/llvm360/Naive+/src/Loader/PEImage.h +++ b/llvm360/Naive+/src/Loader/PEImage.h @@ -1,6 +1,17 @@ #pragma once #include "ImageLoader.h" +#ifdef _WIN32 #include +#else +typedef unsigned long DWORD; +typedef struct _IMAGE_DATA_DIRECTORY { + DWORD VirtualAddress; + DWORD Size; +} IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY; +#define IMAGE_SCN_MEM_EXECUTE 0x20000000 +#define IMAGE_SCN_MEM_READ 0x40000000 +#define IMAGE_SCN_MEM_WRITE 0x80000000 +#endif @@ -126,4 +137,4 @@ namespace XLoader std::vector> m_imports; }; -} \ No newline at end of file +} diff --git a/llvm360/Naive+/src/Logger.h b/llvm360/Naive+/src/Logger.h index 4e99b93..b2811cd 100644 --- a/llvm360/Naive+/src/Logger.h +++ b/llvm360/Naive+/src/Logger.h @@ -33,10 +33,10 @@ void LOG_PRINT(LogLevel level, const char* name, const char* fmt, ...) printf("\033[0m\n"); } -#define LOG_INFO(name, fmt, ...) LOG_PRINT(LogLevel::LEVEL_INFO, name, fmt, __VA_ARGS__) -#define LOG_WARNING(name, fmt, ...) LOG_PRINT(LogLevel::LEVEL_WARNING, name, fmt, __VA_ARGS__) -#define LOG_ERROR(name, fmt, ...) LOG_PRINT(LogLevel::LEVEL_ERROR, name, fmt, __VA_ARGS__) -#define LOG_DEBUG(name, fmt, ...) LOG_PRINT(LogLevel::LEVEL_DEBUG, name, fmt, __VA_ARGS__) -#define LOG_FATAL(name, fmt, ...) LOG_PRINT(LogLevel::LEVEL_FATAL, name, fmt, __VA_ARGS__) +#define LOG_INFO(name, fmt, args...) LOG_PRINT(LogLevel::LEVEL_INFO, name, fmt, ## args) +#define LOG_WARNING(name, fmt, args...) LOG_PRINT(LogLevel::LEVEL_WARNING, name, fmt, ## args) +#define LOG_ERROR(name, fmt, args...) LOG_PRINT(LogLevel::LEVEL_ERROR, name, fmt, ## args) +#define LOG_DEBUG(name, fmt, args...) LOG_PRINT(LogLevel::LEVEL_DEBUG, name, fmt, ## args) +#define LOG_FATAL(name, fmt, args...) LOG_PRINT(LogLevel::LEVEL_FATAL, name, fmt, ## args) diff --git a/llvm360/Naive+/src/Naive+/Naive+.h b/llvm360/Naive+/src/Naive+/Naive+.h index 31dd391..8e25194 100644 --- a/llvm360/Naive+/src/Naive+/Naive+.h +++ b/llvm360/Naive+/src/Naive+/Naive+.h @@ -4,11 +4,13 @@ #include -#ifdef NAIVE_EXPORT +//#ifndef NAIVE_EXPORT +#ifdef _WIN32 #define NAIVE_EXPORT __declspec(dllexport) #else -#define NAIVE_EXPORT __declspec(dllimport) +#define NAIVE_EXPORT __attribute__((visibility("default"))) #endif +//#endif struct Instruction; diff --git a/llvm360/Naive+/src/Shared.h b/llvm360/Naive+/src/Shared.h index 0145093..2f3a48e 100644 --- a/llvm360/Naive+/src/Shared.h +++ b/llvm360/Naive+/src/Shared.h @@ -10,10 +10,14 @@ #include #include #include +#ifdef _WIN32 #include +#include +#else +#include +#endif #include #include -#include #include "Decoder/InstructionRegistry.h"