From 063a68981221e32edfd792da42f622a1d3409b30 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 13 Jul 2023 12:56:36 +0300 Subject: [PATCH] patching more dummy functions --- CMakeLists.txt | 2 +- src/Core/PS4/HLE/LibC.cpp | 15 +++---------- src/Core/PS4/HLE/LibC.h | 2 +- src/Core/PS4/HLE/LibKernel.cpp | 30 +++++++++++++++++++++++++ src/Core/PS4/HLE/LibKernel.h | 13 +++++++++++ src/Core/PS4/HLE/LibSceGnmDriver.cpp | 0 src/Core/PS4/HLE/LibSceGnmDriver.h | 0 src/Core/PS4/HLE/LibSceVideoOut.cpp | 0 src/Core/PS4/HLE/LibSceVideoOut.h | 0 src/Core/PS4/HLE/Libs.cpp | 4 +++- src/Core/PS4/HLE/Libs.h | 15 +++++++++++++ src/Core/PS4/Linker.cpp | 2 +- src/Core/PS4/Loader/SymbolsResolver.cpp | 2 ++ 13 files changed, 69 insertions(+), 16 deletions(-) create mode 100644 src/Core/PS4/HLE/LibKernel.cpp create mode 100644 src/Core/PS4/HLE/LibKernel.h create mode 100644 src/Core/PS4/HLE/LibSceGnmDriver.cpp create mode 100644 src/Core/PS4/HLE/LibSceGnmDriver.h create mode 100644 src/Core/PS4/HLE/LibSceVideoOut.cpp create mode 100644 src/Core/PS4/HLE/LibSceVideoOut.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ee1da38..33ae2b02 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/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.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" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceVideoOut.cpp" "src/Core/PS4/HLE/LibSceVideoOut.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h") find_package(OpenGL REQUIRED) diff --git a/src/Core/PS4/HLE/LibC.cpp b/src/Core/PS4/HLE/LibC.cpp index 1ae10613..2154fd86 100644 --- a/src/Core/PS4/HLE/LibC.cpp +++ b/src/Core/PS4/HLE/LibC.cpp @@ -1,4 +1,5 @@ #include "LibC.h" +#include "Libs.h" #include "../Loader/Elf.h" namespace HLE::Libs::LibC { @@ -11,18 +12,8 @@ namespace HLE::Libs::LibC { //__debugbreak();//if we reach here it will be a great progress :D } - void LibC_RegisterFunc(SymbolsResolver* sym) + void LibC_Register(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); + LIB_FUNCTION("bzQExy189ZI", "libc", 1, "libc", 1, 1, init_env); } }; \ No newline at end of file diff --git a/src/Core/PS4/HLE/LibC.h b/src/Core/PS4/HLE/LibC.h index 0f4f1726..2f0cc2b7 100644 --- a/src/Core/PS4/HLE/LibC.h +++ b/src/Core/PS4/HLE/LibC.h @@ -3,7 +3,7 @@ namespace HLE::Libs::LibC { - void LibC_RegisterFunc(SymbolsResolver* sym); + void LibC_Register(SymbolsResolver* sym); //functions static void init_env(); diff --git a/src/Core/PS4/HLE/LibKernel.cpp b/src/Core/PS4/HLE/LibKernel.cpp new file mode 100644 index 00000000..7ec0ec2d --- /dev/null +++ b/src/Core/PS4/HLE/LibKernel.cpp @@ -0,0 +1,30 @@ +#include "../Loader/Elf.h" +#include "LibKernel.h" +#include "Libs.h" + +namespace HLE::Libs::LibKernel { + + int sceKernelAllocateDirectMemory(off_t searchStart, off_t searchEnd, size_t len, size_t alignment, int memoryType, off_t* physAddrOut) { return 0;//OK + } + size_t sceKernelGetDirectMemorySize() { return 0; + } + int32_t sceKernelMapDirectMemory(void** addr, size_t len, int prot, int flags, off_t directMemoryStart, size_t alignment) { return 0; + } + int32_t sceKernelReleaseDirectMemory(off_t start, size_t len) { return 0; + } + + int sceKernelCreateEqueue(/* SceKernelEqueue* eq*/int eq,const char* name) + { return 0; + } + + void LibKernel_Register(SymbolsResolver* sym) { + //memory + LIB_FUNCTION("rTXw65xmLIA", "libkernel", 1, "libkernel", 1, 1, sceKernelAllocateDirectMemory); + LIB_FUNCTION("pO96TwzOm5E", "libkernel", 1, "libkernel", 1, 1, sceKernelGetDirectMemorySize); + LIB_FUNCTION("L-Q3LEjIbgA", "libkernel", 1, "libkernel", 1, 1, sceKernelMapDirectMemory); + LIB_FUNCTION("MBuItvba6z8", "libkernel", 1, "libkernel", 1, 1, sceKernelReleaseDirectMemory); + //equeue + LIB_FUNCTION("D0OdFMjp46I", "libkernel", 1, "libkernel", 1, 1, sceKernelCreateEqueue); + } + +}; \ No newline at end of file diff --git a/src/Core/PS4/HLE/LibKernel.h b/src/Core/PS4/HLE/LibKernel.h new file mode 100644 index 00000000..7361c21a --- /dev/null +++ b/src/Core/PS4/HLE/LibKernel.h @@ -0,0 +1,13 @@ +#include "../Loader/SymbolsResolver.h" + +namespace HLE::Libs::LibKernel { + +void LibKernel_Register(SymbolsResolver* sym); +// functions +int sceKernelAllocateDirectMemory(off_t searchStart, off_t searchEnd, size_t len, size_t alignment, int memoryType, off_t* physAddrOut); +size_t sceKernelGetDirectMemorySize(); +int sceKernelCreateEqueue(/* SceKernelEqueue* eq*/ int eq, const char* name); +int32_t sceKernelMapDirectMemory(void** addr, size_t len, int prot, int flags, off_t directMemoryStart, size_t alignment); +int32_t sceKernelReleaseDirectMemory(off_t start, size_t len); + +}; // namespace HLE::Libs::LibKernel \ No newline at end of file diff --git a/src/Core/PS4/HLE/LibSceGnmDriver.cpp b/src/Core/PS4/HLE/LibSceGnmDriver.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/Core/PS4/HLE/LibSceGnmDriver.h b/src/Core/PS4/HLE/LibSceGnmDriver.h new file mode 100644 index 00000000..e69de29b diff --git a/src/Core/PS4/HLE/LibSceVideoOut.cpp b/src/Core/PS4/HLE/LibSceVideoOut.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/Core/PS4/HLE/LibSceVideoOut.h b/src/Core/PS4/HLE/LibSceVideoOut.h new file mode 100644 index 00000000..e69de29b diff --git a/src/Core/PS4/HLE/Libs.cpp b/src/Core/PS4/HLE/Libs.cpp index c4dd7f67..66f319f6 100644 --- a/src/Core/PS4/HLE/Libs.cpp +++ b/src/Core/PS4/HLE/Libs.cpp @@ -1,10 +1,12 @@ #include "Libs.h" #include "LibC.h" +#include "LibKernel.h" namespace HLE::Libs { void Init_HLE_Libs(SymbolsResolver *sym) { - LibC::LibC_RegisterFunc(sym); + LibC::LibC_Register(sym); + LibKernel::LibKernel_Register(sym); } } \ No newline at end of file diff --git a/src/Core/PS4/HLE/Libs.h b/src/Core/PS4/HLE/Libs.h index 9e1944c6..a7177ca3 100644 --- a/src/Core/PS4/HLE/Libs.h +++ b/src/Core/PS4/HLE/Libs.h @@ -1,6 +1,21 @@ #pragma once #include "../Loader/SymbolsResolver.h" + +#define LIB_FUNCTION(nid, lib, libversion, mod, moduleVersionMajor, moduleVersionMinor, function) \ + {\ + SymbolRes sr{}; \ + sr.name = nid; \ + sr.library = lib; \ + sr.library_version = libversion;\ + sr.module = mod;\ + sr.module_version_major = moduleVersionMajor;\ + sr.module_version_minor = moduleVersionMinor;\ + sr.type = STT_FUN;\ + auto func = reinterpret_cast(function);\ + sym->AddSymbol(sr, func);\ + } + namespace HLE::Libs { void Init_HLE_Libs(SymbolsResolver* sym); } \ No newline at end of file diff --git a/src/Core/PS4/Linker.cpp b/src/Core/PS4/Linker.cpp index aed80637..e7461690 100644 --- a/src/Core/PS4/Linker.cpp +++ b/src/Core/PS4/Linker.cpp @@ -569,7 +569,7 @@ static void relocate(u32 idx, elf_relocation* rel, Module* m, bool isJmpRel) { } else { - LOG_INFO_IF(debug_loader, "function not patched!\n"); + LOG_INFO_IF(debug_loader, "function not patched! {}\n",rel_name); } } diff --git a/src/Core/PS4/Loader/SymbolsResolver.cpp b/src/Core/PS4/Loader/SymbolsResolver.cpp index de28a99a..babce4f5 100644 --- a/src/Core/PS4/Loader/SymbolsResolver.cpp +++ b/src/Core/PS4/Loader/SymbolsResolver.cpp @@ -1,5 +1,6 @@ #include "../../../types.h" #include "SymbolsResolver.h" +#include "../../../Util/Log.h" void SymbolsResolver::AddSymbol(const SymbolRes& s, u64 virtual_addr) @@ -26,5 +27,6 @@ const SymbolRecord* SymbolsResolver::FindSymbol(const SymbolRes& s) const { } index++; } + LOG_INFO_IF(true, "unresolved! {}\n", name); return nullptr; } \ No newline at end of file