From 79a6464c587d29f1ae852365d6f1284c67ff7e7a Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Wed, 28 Jun 2023 20:15:19 +0300 Subject: [PATCH] sample hle function loading (libc) --- CMakeLists.txt | 2 +- src/Core/PS4/HLE/LibC.cpp | 25 +++++++++++++++++++++++++ src/Core/PS4/HLE/LibC.h | 10 ++++++++++ src/Core/PS4/HLE/Libs.cpp | 3 ++- src/Core/PS4/Linker.cpp | 1 + src/Core/PS4/Linker.h | 3 +++ src/main.cpp | 4 +++- 7 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 src/Core/PS4/HLE/LibC.cpp create mode 100644 src/Core/PS4/HLE/LibC.h diff --git a/CMakeLists.txt b/CMakeLists.txt index f673c228..c656aadc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,7 @@ add_executable(shadps4 src/Core/Memory.h src/Core/PS4/Linker.cpp src/Core/PS4/Linker.h - "src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Util/StringUtil.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h") + "src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Util/StringUtil.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h") find_package(OpenGL REQUIRED) diff --git a/src/Core/PS4/HLE/LibC.cpp b/src/Core/PS4/HLE/LibC.cpp new file mode 100644 index 00000000..73fc4d2f --- /dev/null +++ b/src/Core/PS4/HLE/LibC.cpp @@ -0,0 +1,25 @@ +#include "LibC.h" +#include "../Loader/Elf.h" + +namespace HLE::Libs::LibC { + + static void init_env() //every game/demo should probably + { + __debugbreak();//if we reach here it will be a great progress :D + } + + void LibC_RegisterFunc(SymbolsResolver* sym) + { + //TODO this will be convert to macro probably once we decide how will it work and what's the best + SymbolRes sr {}; + sr.name = "bzQExy189ZI"; + sr.library = "libc"; + sr.library_version = 1; + sr.module = "libc"; + sr.module_version_major = 1; + sr.module_version_minor = 1; + sr.type = STT_FUN; + auto func = reinterpret_cast(init_env); + sym->AddSymbol(sr, func); + } +}; \ No newline at end of file diff --git a/src/Core/PS4/HLE/LibC.h b/src/Core/PS4/HLE/LibC.h new file mode 100644 index 00000000..0f4f1726 --- /dev/null +++ b/src/Core/PS4/HLE/LibC.h @@ -0,0 +1,10 @@ +#pragma once +#include "../Loader/SymbolsResolver.h" + +namespace HLE::Libs::LibC { + + void LibC_RegisterFunc(SymbolsResolver* sym); + //functions + static void init_env(); + +}; \ No newline at end of file diff --git a/src/Core/PS4/HLE/Libs.cpp b/src/Core/PS4/HLE/Libs.cpp index 2d5318f8..c4dd7f67 100644 --- a/src/Core/PS4/HLE/Libs.cpp +++ b/src/Core/PS4/HLE/Libs.cpp @@ -1,9 +1,10 @@ #include "Libs.h" +#include "LibC.h" namespace HLE::Libs { void Init_HLE_Libs(SymbolsResolver *sym) { - + LibC::LibC_RegisterFunc(sym); } } \ No newline at end of file diff --git a/src/Core/PS4/Linker.cpp b/src/Core/PS4/Linker.cpp index 3cf8e904..0572d179 100644 --- a/src/Core/PS4/Linker.cpp +++ b/src/Core/PS4/Linker.cpp @@ -13,6 +13,7 @@ static u64 g_load_addr = SYSTEM_RESERVED + CODE_BASE_OFFSET; Linker::Linker() { + m_HLEsymbols = new SymbolsResolver; } Linker::~Linker() diff --git a/src/Core/PS4/Linker.h b/src/Core/PS4/Linker.h index f86f5205..bc7ce63b 100644 --- a/src/Core/PS4/Linker.h +++ b/src/Core/PS4/Linker.h @@ -109,9 +109,12 @@ public: void LoadModuleToMemory(Module* m); void LoadDynamicInfo(Module* m); void LoadSymbols(Module* m); + SymbolsResolver* getHLESymbols() { return m_HLEsymbols; } private: const ModuleInfo* FindModule(const Module& m, const std::string& id); const LibraryInfo* FindLibrary(const Module& program, const std::string& id); + std::vector m_modules; + SymbolsResolver* m_HLEsymbols = nullptr; }; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 023d13e3..7a14d705 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,6 +28,7 @@ #include #include #include +#include "Core/PS4/HLE/Libs.h" // Main code int main(int argc, char* argv[]) @@ -35,8 +36,9 @@ int main(int argc, char* argv[]) logging::init(true);//init logging - const char* const path = argv[1]; //argument 1 is the path of self file to boot + const char* const path = argv[1]; //argument 1 is the path of self file to boot auto* linker = Singleton::Instance(); + HLE::Libs::Init_HLE_Libs(linker->getHLESymbols()); auto *module =linker->LoadModule(path);//load main executable #if 0