sample hle function loading (libc)

This commit is contained in:
georgemoralis 2023-06-28 20:15:19 +03:00
parent e0cee2d7fd
commit 79a6464c58
7 changed files with 45 additions and 3 deletions

View file

@ -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)

25
src/Core/PS4/HLE/LibC.cpp Normal file
View file

@ -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<u64>(init_env);
sym->AddSymbol(sr, func);
}
};

10
src/Core/PS4/HLE/LibC.h Normal file
View file

@ -0,0 +1,10 @@
#pragma once
#include "../Loader/SymbolsResolver.h"
namespace HLE::Libs::LibC {
void LibC_RegisterFunc(SymbolsResolver* sym);
//functions
static void init_env();
};

View file

@ -1,9 +1,10 @@
#include "Libs.h"
#include "LibC.h"
namespace HLE::Libs {
void Init_HLE_Libs(SymbolsResolver *sym)
{
LibC::LibC_RegisterFunc(sym);
}
}

View file

@ -13,6 +13,7 @@ static u64 g_load_addr = SYSTEM_RESERVED + CODE_BASE_OFFSET;
Linker::Linker()
{
m_HLEsymbols = new SymbolsResolver;
}
Linker::~Linker()

View file

@ -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<Module*> m_modules;
SymbolsResolver* m_HLEsymbols = nullptr;
};

View file

@ -28,6 +28,7 @@
#include <stdio.h>
#include <inttypes.h>
#include <Zydis/Zydis.h>
#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<Linker>::Instance();
HLE::Libs::Init_HLE_Libs(linker->getHLESymbols());
auto *module =linker->LoadModule(path);//load main executable
#if 0