From b777f545bb634c0da5b90a17e85a1582137e155d Mon Sep 17 00:00:00 2001 From: Greg Date: Thu, 22 Dec 2022 19:34:05 -0700 Subject: [PATCH] Tidying up and some testing. --- Playstation/OrbisLibAPI/Utilities.cpp | 7 + Playstation/OrbisLibAPI/Utilities.h | 2 + Playstation/OrbisLibAPI/Version.h | 22 +- Playstation/OrbisLibAPI/main.cpp | 2 +- Playstation/OrbisLibGeneralHelper/Common.h | 1 - Playstation/OrbisLibGeneralHelper/Detour.cpp | 105 ++++++ Playstation/OrbisLibGeneralHelper/Detour.h | 27 ++ .../LocalSocketListener.cpp | 6 +- .../LocalSocketListener.h | 2 - .../OrbisLibGeneralHelper.cpp | 28 +- .../OrbisLibGeneralHelper.vcxproj | 7 +- .../OrbisLibGeneralHelper.vcxproj.filters | 15 + Playstation/OrbisLibGeneralHelper/build.bat | 6 +- Playstation/OrbisLibGeneralHelper/hde64.cpp | 344 ++++++++++++++++++ Playstation/OrbisLibGeneralHelper/hde64.h | 124 +++++++ Playstation/OrbisLibGeneralHelper/table64.h | 74 ++++ .../Resources/BuildNumber.txt | 2 +- .../Resources/BuildString.txt | 2 +- 18 files changed, 726 insertions(+), 50 deletions(-) create mode 100644 Playstation/OrbisLibGeneralHelper/Detour.cpp create mode 100644 Playstation/OrbisLibGeneralHelper/Detour.h create mode 100644 Playstation/OrbisLibGeneralHelper/hde64.cpp create mode 100644 Playstation/OrbisLibGeneralHelper/hde64.h create mode 100644 Playstation/OrbisLibGeneralHelper/table64.h diff --git a/Playstation/OrbisLibAPI/Utilities.cpp b/Playstation/OrbisLibAPI/Utilities.cpp index a7e46a6..d826528 100644 --- a/Playstation/OrbisLibAPI/Utilities.cpp +++ b/Playstation/OrbisLibAPI/Utilities.cpp @@ -4,6 +4,7 @@ #pragma region Modules void(*_sceSysmoduleLoadModuleInternal)(uint32_t); //Import is broken for some reason +int (*_sceSysmoduleLoadModuleByNameInternal)(const char* name, int, int, int, int); bool LoadModules() { @@ -22,6 +23,12 @@ bool LoadModules() return false; } + sceKernelDlsym(ModuleHandle, "sceSysmoduleLoadModuleByNameInternal", (void**)&_sceSysmoduleLoadModuleByNameInternal); + if (_sceSysmoduleLoadModuleInternal == nullptr) { + klog("Failed to load _sceSysmoduleLoadModuleByNameInternal Import.\n"); + return false; + } + _sceSysmoduleLoadModuleInternal(SCE_SYSMODULE_INTERNAL_SYSTEM_SERVICE); _sceSysmoduleLoadModuleInternal(SCE_SYSMODULE_INTERNAL_USER_SERVICE); _sceSysmoduleLoadModuleInternal(SCE_SYSMODULE_INTERNAL_SYS_CORE); diff --git a/Playstation/OrbisLibAPI/Utilities.h b/Playstation/OrbisLibAPI/Utilities.h index e83b168..76d0041 100644 --- a/Playstation/OrbisLibAPI/Utilities.h +++ b/Playstation/OrbisLibAPI/Utilities.h @@ -2,6 +2,8 @@ // Modules. extern void(*_sceSysmoduleLoadModuleInternal)(uint32_t); //Import is broken for some reason +extern int (*_sceSysmoduleLoadModuleByNameInternal)(const char* name, int, int, int, int); + bool LoadModules(); // Misc diff --git a/Playstation/OrbisLibAPI/Version.h b/Playstation/OrbisLibAPI/Version.h index caf5cd6..8b13be9 100644 --- a/Playstation/OrbisLibAPI/Version.h +++ b/Playstation/OrbisLibAPI/Version.h @@ -1,11 +1,11 @@ -#pragma once -#define ORBISLIB_MAJOR 3 -#define ORBISLIB_MINOR 0 -#define ORBISLIB_BUILDVERSION 636 -#define stringify(a) stringify_(a) -#define stringify_(a) #a -#if defined(_DEBUG) -#define ORBISLIB_BUILDSTRING ("[OrbisLib Daemon " stringify(ORBISLIB_MAJOR) "." stringify(ORBISLIB_MINOR) "] Dev Build " stringify(ORBISLIB_BUILDVERSION) " " __DATE__ " " __TIME__) -#else -#define ORBISLIB_BUILDSTRING ("[OrbisLib Daemon " stringify(ORBISLIB_MAJOR) "." stringify(ORBISLIB_MINOR) "] Build " stringify(ORBISLIB_BUILDVERSION) " " __DATE__ " " __TIME__) -#endif +#pragma once +#define ORBISLIB_MAJOR 3 +#define ORBISLIB_MINOR 0 +#define ORBISLIB_BUILDVERSION 664 +#define stringify(a) stringify_(a) +#define stringify_(a) #a +#if defined(_DEBUG) +#define ORBISLIB_BUILDSTRING ("[OrbisLib Daemon " stringify(ORBISLIB_MAJOR) "." stringify(ORBISLIB_MINOR) "] Dev Build " stringify(ORBISLIB_BUILDVERSION) " " __DATE__ " " __TIME__) +#else +#define ORBISLIB_BUILDSTRING ("[OrbisLib Daemon " stringify(ORBISLIB_MAJOR) "." stringify(ORBISLIB_MINOR) "] Build " stringify(ORBISLIB_BUILDVERSION) " " __DATE__ " " __TIME__) +#endif diff --git a/Playstation/OrbisLibAPI/main.cpp b/Playstation/OrbisLibAPI/main.cpp index fa0b12a..d91a27d 100644 --- a/Playstation/OrbisLibAPI/main.cpp +++ b/Playstation/OrbisLibAPI/main.cpp @@ -71,7 +71,7 @@ int main() CopySflash(); // Set the Name of this process so it shows up as something other than eboot.bin. - jbc_set_proc_name("OrbisLibAPI"); + sceKernelSetProcessName("OrbisLibAPI"); klog("\n%s\n\n", ORBISLIB_BUILDSTRING); diff --git a/Playstation/OrbisLibGeneralHelper/Common.h b/Playstation/OrbisLibGeneralHelper/Common.h index 6a981c8..6c3f8b0 100644 --- a/Playstation/OrbisLibGeneralHelper/Common.h +++ b/Playstation/OrbisLibGeneralHelper/Common.h @@ -20,7 +20,6 @@ #include "../../Misc/General_IPC.h" #include "../../Misc/libjbc.h" -#include "GoldHEN.h" #include "Utilities.h" #include "LocalSocketListener.h" diff --git a/Playstation/OrbisLibGeneralHelper/Detour.cpp b/Playstation/OrbisLibGeneralHelper/Detour.cpp new file mode 100644 index 0000000..7f35186 --- /dev/null +++ b/Playstation/OrbisLibGeneralHelper/Detour.cpp @@ -0,0 +1,105 @@ +#include "Common.h" +#include "Detour.h" +#include "hde64.h" + +#define VM_PROT_NONE ((int) 0x00) +#define VM_PROT_READ ((int) 0x01) +#define VM_PROT_WRITE ((int) 0x02) +#define VM_PROT_EXECUTE ((int) 0x04) +#define VM_PROT_COPY ((int) 0x08) /* copy-on-read */ + +#define VM_PROT_ALL (VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE) +#define VM_PROT_RW (VM_PROT_READ|VM_PROT_WRITE) +#define VM_PROT_DEFAULT VM_PROT_ALL + +void Detour::WriteJump(void* Address, void* Destination) +{ + uint8_t JumpInstructions[] = { + 0xFF, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, // jmp QWORD PTR[Address] + }; + + //Write the address of our hook to the instruction. + *(uint64_t*)(JumpInstructions + 6) = (uint64_t)Destination; + + sceKernelMprotect((void*)Address, sizeof(JumpInstructions), VM_PROT_ALL); + memcpy(Address, JumpInstructions, sizeof(JumpInstructions)); +} + +void* Detour::DetourFunction(uint64_t FunctionPtr, void* HookPtr) +{ + if (FunctionPtr == NULL || HookPtr == NULL) + { + klog("[Detour] DetourFunction: FunctionPtr or HookPtr NULL (%llX -> %llX)\n", FunctionPtr, HookPtr); + return (void*)0; + } + uint32_t InstructionSize = 0; + + while (InstructionSize < 14) + { + hde64s hs; + uint32_t temp = hde64_disasm((void*)(FunctionPtr + InstructionSize), &hs); + + if (hs.flags & F_ERROR) + return (void*)0; + + InstructionSize += temp; + } + + klog("InstructionSize: %i\n", InstructionSize); + + if (InstructionSize < 14) + { + klog("[Detour] DetourFunction: Hooking Requires a minimum of 14 bytes to write jump!\n"); + return (void*)0; + } + + //Save Pointers for later + this->FunctionPtr = (void*)FunctionPtr; + this->HookPtr = HookPtr; + + //Set protection. + sceKernelMprotect((void*)FunctionPtr, InstructionSize, VM_PROT_ALL); + + //Allocate Executable memory for stub and write instructions to stub and a jump back to original execution. + this->StubSize = (InstructionSize + 14); + int res = sceKernelMmap(0, this->StubSize, VM_PROT_ALL, 0x1000 | 0x2, -1, 0, &this->StubPtr); + if (res < 0 || this->StubPtr == 0) + { + klog("[Detour] sceKernelMmap Failed: 0x%llX\n", res); + return 0; + } + + memcpy(StubPtr, (void*)FunctionPtr, InstructionSize); + WriteJump((void*)((uint64_t)StubPtr + InstructionSize), (void*)(FunctionPtr + InstructionSize)); + + //Write jump from function to hook. + WriteJump((void*)FunctionPtr, HookPtr); + + klog("[Detour] DetourFunction: Detour (%llX -> %llX) Written Successfully!\n", FunctionPtr, this->HookPtr); + + return this->StubPtr; +} + +void Detour::RestoreFunction() +{ + if (this->StubPtr) + { + sceKernelMprotect((void*)this->FunctionPtr, this->StubSize - 14, VM_PROT_ALL); + memcpy((void*)this->FunctionPtr, this->StubPtr, this->StubSize - 14); + + klog("[Detour] RestoreFunction: (%llX) has been Restored Successfully!\n", this->FunctionPtr); + } +} + +Detour::Detour() +{ + +} + +Detour::~Detour() +{ + RestoreFunction(); + + //Clean up + sceKernelMunmap(this->StubPtr, this->StubSize); +} \ No newline at end of file diff --git a/Playstation/OrbisLibGeneralHelper/Detour.h b/Playstation/OrbisLibGeneralHelper/Detour.h new file mode 100644 index 0000000..5d7b93b --- /dev/null +++ b/Playstation/OrbisLibGeneralHelper/Detour.h @@ -0,0 +1,27 @@ +#pragma once + +class Detour +{ +private: + + void* StubPtr = 0; + size_t StubSize = 0; + + void* FunctionPtr = 0; + void* HookPtr = 0; + +public: + template + result Stub(Args... args) + { + result(*Stub_internal)(Args... args) = decltype(Stub_internal)(StubPtr); + return Stub_internal(args...); + } + + void WriteJump(void* Address, void* Destination); + void* DetourFunction(uint64_t FunctionPtr, void* HookPtr); + void RestoreFunction(); + + Detour(); + ~Detour(); +}; \ No newline at end of file diff --git a/Playstation/OrbisLibGeneralHelper/LocalSocketListener.cpp b/Playstation/OrbisLibGeneralHelper/LocalSocketListener.cpp index c42acda..85875ef 100644 --- a/Playstation/OrbisLibGeneralHelper/LocalSocketListener.cpp +++ b/Playstation/OrbisLibGeneralHelper/LocalSocketListener.cpp @@ -105,8 +105,6 @@ void* LocalSocketListener::DoWork() Cleanup: klog("Listener Thread Exiting!\n"); - // Clean up. - this->ThreadCleanedUp = true; // Clean up. sceNetSocketClose(this->Socket); @@ -127,10 +125,10 @@ LocalSocketListener::LocalSocketListener(void(*ClientCallBack)(void* tdParam, Or this->ClientCallBack = ClientCallBack; this->tdParam = tdParam; this->ServerRunning = true; - this->ThreadCleanedUp = false; strcpy(this->ServerAddress, ServerAddress); scePthreadCreate(&ListenThreadHandle, NULL, &ListenThread, this, "Local Listen Thread"); + scePthreadDetach(*ListenThreadHandle); } LocalSocketListener::~LocalSocketListener() @@ -138,7 +136,7 @@ LocalSocketListener::~LocalSocketListener() klog("~Socket Listener.\n"); this->ServerRunning = false; - while (!this->ThreadCleanedUp) { sceKernelUsleep(10); } + scePthreadJoin(*ListenThreadHandle, nullptr); klog("Destruction sucessful.\n"); } \ No newline at end of file diff --git a/Playstation/OrbisLibGeneralHelper/LocalSocketListener.h b/Playstation/OrbisLibGeneralHelper/LocalSocketListener.h index ffddffd..8e9012d 100644 --- a/Playstation/OrbisLibGeneralHelper/LocalSocketListener.h +++ b/Playstation/OrbisLibGeneralHelper/LocalSocketListener.h @@ -7,8 +7,6 @@ private: OrbisNetId Socket; /// Used to signal thread to shut down bool ServerRunning; - /// Used to see when listen thread has closed. - bool ThreadCleanedUp; char ServerAddress[0x100]; void* DoWork(); diff --git a/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.cpp b/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.cpp index 4a8b9d5..4d12006 100644 --- a/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.cpp +++ b/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.cpp @@ -1,25 +1,7 @@ #include "Common.h" +#include "Detour.h" LocalSocketListener* LocalListener = nullptr; -jailbreak_backup JailBackup; - -void SendExtProcessInfo(OrbisNetId Sock) -{ - ExtProccesInfoPacket packet; - - // Get info using GoldHEN syscall. - proc_info info; - sys_sdk_proc_info(&info); - - // Populate our packet. - strncpy(packet.Path, info.path, sizeof(packet.Path)); - strncpy(packet.TitleId, info.titleid, sizeof(packet.TitleId)); - strncpy(packet.ContentId, info.contentid, sizeof(packet.ContentId)); - strncpy(packet.Version, info.version, sizeof(packet.Version)); - - // Ship it. - sceNetSend(Sock, (void*)&packet, sizeof(ExtProccesInfoPacket), 0); -} void SendLibraryList(OrbisNetId Sock) { @@ -62,21 +44,17 @@ void ListenerClientThread(void* tdParam, OrbisNetId Sock) klog("Invalid Command enum %i\n", Command); break; - case GIPC_INFO: - SendExtProcessInfo(Sock); // Obsolite with app.db - break; - case GIPC_LIB_LIST: SendLibraryList(Sock); // Really Only needed for the path. break; case GIPC_JAILBREAK: - sys_sdk_jailbreak(&JailBackup); // Could just use libjbc + //sys_sdk_jailbreak(&JailBackup); // Could just use libjbc SockSendInt(Sock, GIPC_OK); break; case GIPC_JAIL: - sys_sdk_unjailbreak(&JailBackup); // Could just use libjbc + //sys_sdk_unjailbreak(&JailBackup); // Could just use libjbc SockSendInt(Sock, GIPC_OK); break; diff --git a/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.vcxproj b/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.vcxproj index e3d159b..eabde7d 100644 --- a/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.vcxproj +++ b/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.vcxproj @@ -52,7 +52,7 @@ call build.bat $(IntDir) "$(TargetName)" "$(SolutionDir)" $(SolutionDir) - $(OO_PS4_TOOLCHAIN)\include;External\GoldHEN_Plugins_SDK\include;Misc;$(NMakeIncludeSearchPath) + $(OO_PS4_TOOLCHAIN)\include;Misc;$(NMakeIncludeSearchPath) E:\Greg\Repos\Orbis-Suite-3.0\External\GoldHEN_Plugins_SDK\include;$(IncludePath) @@ -64,13 +64,18 @@ del /s /q /f $(IntDir)\*.oelf + + + + + diff --git a/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.vcxproj.filters b/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.vcxproj.filters index 0746813..de51d8d 100644 --- a/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.vcxproj.filters +++ b/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.vcxproj.filters @@ -24,6 +24,12 @@ Source Files + + Source Files + + + Source Files + @@ -38,5 +44,14 @@ Header Files + + Header Files + + + Header Files + + + Header Files + \ No newline at end of file diff --git a/Playstation/OrbisLibGeneralHelper/build.bat b/Playstation/OrbisLibGeneralHelper/build.bat index 59e4f04..e6465e7 100644 --- a/Playstation/OrbisLibGeneralHelper/build.bat +++ b/Playstation/OrbisLibGeneralHelper/build.bat @@ -1,7 +1,7 @@ SETLOCAL EnableDelayedExpansion Rem Libraries to link in -set libraries=-lSceLibcInternal -lSceLibcInternalExt -lkernel -lSceNet -lGoldHEN_Hook -lc++ -lc +set libraries=-lSceLibcInternal -lSceLibcInternalExt -lkernel -lSceNet -lc++ -lc Rem Read the script arguments into local vars set intdir=%1 @@ -15,7 +15,7 @@ set outputStub=%intdir%%targetname%_stub.so Rem Compile object files for all the source files for %%f in (*.cpp) do ( - clang++ -cc1 -triple x86_64-scei-ps4-elf -I"%OO_PS4_TOOLCHAIN%\include" -I"%OO_PS4_TOOLCHAIN%\\include\\c++\\v1" -I"..\\..\\External\\GoldHEN_Plugins_SDK\\include" -I"..\\..\\Misc" -emit-obj -o %intdir%\%%~nf.o %%~nf.cpp + clang++ -cc1 -triple x86_64-scei-ps4-elf -I"%OO_PS4_TOOLCHAIN%\include" -I"%OO_PS4_TOOLCHAIN%\\include\\c++\\v1" -I"..\\..\\Misc" -emit-obj -o %intdir%\%%~nf.o %%~nf.cpp ) Rem Compile object files for all the assembly files @@ -28,7 +28,7 @@ set obj_files= for %%f in (%intdir%\\*.o) do set obj_files=!obj_files! .\%%f Rem Link the input ELF -ld.lld -m elf_x86_64 -pie --script "%OO_PS4_TOOLCHAIN%\link.x" --eh-frame-hdr -o "%outputElf%" "-L%OO_PS4_TOOLCHAIN%\lib" "-L..\\..\\External\\GoldHEN_Plugins_SDK" %libraries% --verbose "..\\..\\External\\GoldHEN_Plugins_SDK\\build\\crtprx.o" %obj_files% "..\\..\\External\\ps4-libjbc\\jbc.o" +ld.lld -m elf_x86_64 -pie --script "%OO_PS4_TOOLCHAIN%\link.x" --eh-frame-hdr -o "%outputElf%" "-L%OO_PS4_TOOLCHAIN%\lib" %libraries% --verbose "..\\..\\External\\GoldHEN_Plugins_SDK\\build\\crtprx.o" %obj_files% "..\\..\\External\\ps4-libjbc\\jbc.o" Rem Create stub shared libraries for %%f in (*.cpp) do ( diff --git a/Playstation/OrbisLibGeneralHelper/hde64.cpp b/Playstation/OrbisLibGeneralHelper/hde64.cpp new file mode 100644 index 0000000..836004d --- /dev/null +++ b/Playstation/OrbisLibGeneralHelper/hde64.cpp @@ -0,0 +1,344 @@ +/* +* Hacker Disassembler Engine 64 C +* Copyright (c) 2008-2009, Vyacheslav Patkov. +* All rights reserved. +* +*/ + +#include +#include + +#include "hde64.h" +#include "table64.h" + +unsigned int hde64_disasm(const void *code, hde64s *hs) +{ + uint8_t x, c, *p = (uint8_t *)code, cflags, opcode, pref = 0; + uint8_t *ht = hde64_table, m_mod, m_reg, m_rm, disp_size = 0; + uint8_t op64 = 0; + + memset(hs, 0, sizeof(hde64s)); + + for (x = 16; x; x--) + switch (c = *p++) { + case 0xf3: + hs->p_rep = c; + pref |= PRE_F3; + break; + case 0xf2: + hs->p_rep = c; + pref |= PRE_F2; + break; + case 0xf0: + hs->p_lock = c; + pref |= PRE_LOCK; + break; + case 0x26: case 0x2e: case 0x36: + case 0x3e: case 0x64: case 0x65: + hs->p_seg = c; + pref |= PRE_SEG; + break; + case 0x66: + hs->p_66 = c; + pref |= PRE_66; + break; + case 0x67: + hs->p_67 = c; + pref |= PRE_67; + break; + default: + goto pref_done; + } +pref_done: + + hs->flags = (uint32_t)pref << 23; + + if (!pref) + pref |= PRE_NONE; + + if ((c & 0xf0) == 0x40) { + hs->flags |= F_PREFIX_REX; + if ((hs->rex_w = (c & 0xf) >> 3) && (*p & 0xf8) == 0xb8) + op64++; + hs->rex_r = (c & 7) >> 2; + hs->rex_x = (c & 3) >> 1; + hs->rex_b = c & 1; + if (((c = *p++) & 0xf0) == 0x40) { + opcode = c; + goto error_opcode; + } + } + + if ((hs->opcode = c) == 0x0f) { + hs->opcode2 = c = *p++; + ht += DELTA_OPCODES; + } + else if (c >= 0xa0 && c <= 0xa3) { + op64++; + if (pref & PRE_67) + pref |= PRE_66; + else + pref &= ~PRE_66; + } + + opcode = c; + cflags = ht[ht[opcode / 4] + (opcode % 4)]; + + if (cflags == C_ERROR) { + error_opcode: + hs->flags |= F_ERROR | F_ERROR_OPCODE; + cflags = 0; + if ((opcode & -3) == 0x24) + cflags++; + } + + x = 0; + if (cflags & C_GROUP) { + uint16_t t; + t = *(uint16_t *)(ht + (cflags & 0x7f)); + cflags = (uint8_t)t; + x = (uint8_t)(t >> 8); + } + + if (hs->opcode2) { + ht = hde64_table + DELTA_PREFIXES; + if (ht[ht[opcode / 4] + (opcode % 4)] & pref) + hs->flags |= F_ERROR | F_ERROR_OPCODE; + } + + if (cflags & C_MODRM) { + hs->flags |= F_MODRM; + hs->modrm = c = *p++; + hs->modrm_mod = m_mod = c >> 6; + hs->modrm_rm = m_rm = c & 7; + hs->modrm_reg = m_reg = (c & 0x3f) >> 3; + + if (x && ((x << m_reg) & 0x80)) + hs->flags |= F_ERROR | F_ERROR_OPCODE; + + if (!hs->opcode2 && opcode >= 0xd9 && opcode <= 0xdf) { + uint8_t t = opcode - 0xd9; + if (m_mod == 3) { + ht = hde64_table + DELTA_FPU_MODRM + t * 8; + t = ht[m_reg] << m_rm; + } + else { + ht = hde64_table + DELTA_FPU_REG; + t = ht[t] << m_reg; + } + if (t & 0x80) + hs->flags |= F_ERROR | F_ERROR_OPCODE; + } + + if (pref & PRE_LOCK) { + if (m_mod == 3) { + hs->flags |= F_ERROR | F_ERROR_LOCK; + } + else { + uint8_t *table_end, op = opcode; + if (hs->opcode2) { + ht = hde64_table + DELTA_OP2_LOCK_OK; + table_end = ht + DELTA_OP_ONLY_MEM - DELTA_OP2_LOCK_OK; + } + else { + ht = hde64_table + DELTA_OP_LOCK_OK; + table_end = ht + DELTA_OP2_LOCK_OK - DELTA_OP_LOCK_OK; + op &= -2; + } + for (; ht != table_end; ht++) + if (*ht++ == op) { + if (!((*ht << m_reg) & 0x80)) + goto no_lock_error; + else + break; + } + hs->flags |= F_ERROR | F_ERROR_LOCK; + no_lock_error: + ; + } + } + + if (hs->opcode2) { + switch (opcode) { + case 0x20: case 0x22: + m_mod = 3; + if (m_reg > 4 || m_reg == 1) + goto error_operand; + else + goto no_error_operand; + case 0x21: case 0x23: + m_mod = 3; + if (m_reg == 4 || m_reg == 5) + goto error_operand; + else + goto no_error_operand; + } + } + else { + switch (opcode) { + case 0x8c: + if (m_reg > 5) + goto error_operand; + else + goto no_error_operand; + case 0x8e: + if (m_reg == 1 || m_reg > 5) + goto error_operand; + else + goto no_error_operand; + } + } + + if (m_mod == 3) { + uint8_t *table_end; + if (hs->opcode2) { + ht = hde64_table + DELTA_OP2_ONLY_MEM; + table_end = ht + sizeof(hde64_table) - DELTA_OP2_ONLY_MEM; + } + else { + ht = hde64_table + DELTA_OP_ONLY_MEM; + table_end = ht + DELTA_OP2_ONLY_MEM - DELTA_OP_ONLY_MEM; + } + for (; ht != table_end; ht += 2) + if (*ht++ == opcode) { + if (*ht++ & pref && !((*ht << m_reg) & 0x80)) + goto error_operand; + else + break; + } + goto no_error_operand; + } + else if (hs->opcode2) { + switch (opcode) { + case 0x50: case 0xd7: case 0xf7: + if (pref & (PRE_NONE | PRE_66)) + goto error_operand; + break; + case 0xd6: + if (pref & (PRE_F2 | PRE_F3)) + goto error_operand; + break; + case 0xc5: + goto error_operand; + } + goto no_error_operand; + } + else + goto no_error_operand; + + error_operand: + hs->flags |= F_ERROR | F_ERROR_OPERAND; + no_error_operand: + + c = *p++; + if (m_reg <= 1) { + if (opcode == 0xf6) + cflags |= C_IMM8; + else if (opcode == 0xf7) + cflags |= C_IMM_P66; + } + + switch (m_mod) { + case 0: + if (pref & PRE_67) { + if (m_rm == 6) + disp_size = 2; + } + else + if (m_rm == 5) + disp_size = 4; + break; + case 1: + disp_size = 1; + break; + case 2: + disp_size = 2; + if (!(pref & PRE_67)) + disp_size <<= 1; + } + + if (m_mod != 3 && m_rm == 4) { + hs->flags |= F_SIB; + p++; + hs->sib = c; + hs->sib_scale = c >> 6; + hs->sib_index = (c & 0x3f) >> 3; + if ((hs->sib_base = c & 7) == 5 && !(m_mod & 1)) + disp_size = 4; + } + + p--; + switch (disp_size) { + case 1: + hs->flags |= F_DISP8; + hs->disp.disp8 = *p; + break; + case 2: + hs->flags |= F_DISP16; + hs->disp.disp16 = *(uint16_t *)p; + break; + case 4: + hs->flags |= F_DISP32; + hs->disp.disp32 = *(uint32_t *)p; + } + p += disp_size; + } + else if (pref & PRE_LOCK) + hs->flags |= F_ERROR | F_ERROR_LOCK; + + if (cflags & C_IMM_P66) { + if (cflags & C_REL32) { + if (pref & PRE_66) { + hs->flags |= F_IMM16 | F_RELATIVE; + hs->imm.imm16 = *(uint16_t *)p; + p += 2; + goto disasm_done; + } + goto rel32_ok; + } + if (op64) { + hs->flags |= F_IMM64; + hs->imm.imm64 = *(uint64_t *)p; + p += 8; + } + else if (!(pref & PRE_66)) { + hs->flags |= F_IMM32; + hs->imm.imm32 = *(uint32_t *)p; + p += 4; + } + else + goto imm16_ok; + } + + + if (cflags & C_IMM16) { + imm16_ok: + hs->flags |= F_IMM16; + hs->imm.imm16 = *(uint16_t *)p; + p += 2; + } + if (cflags & C_IMM8) { + hs->flags |= F_IMM8; + hs->imm.imm8 = *p++; + } + + if (cflags & C_REL32) { + rel32_ok: + hs->flags |= F_IMM32 | F_RELATIVE; + hs->imm.imm32 = *(uint32_t *)p; + p += 4; + } + else if (cflags & C_REL8) { + hs->flags |= F_IMM8 | F_RELATIVE; + hs->imm.imm8 = *p++; + } + +disasm_done: + + if ((hs->len = (uint8_t)(p - (uint8_t *)code)) > 15) { + hs->flags |= F_ERROR | F_ERROR_LENGTH; + hs->len = 15; + } + + return (unsigned int)hs->len; +} \ No newline at end of file diff --git a/Playstation/OrbisLibGeneralHelper/hde64.h b/Playstation/OrbisLibGeneralHelper/hde64.h new file mode 100644 index 0000000..c653804 --- /dev/null +++ b/Playstation/OrbisLibGeneralHelper/hde64.h @@ -0,0 +1,124 @@ +/* +* Hacker Disassembler Engine 64 +* Copyright (c) 2008-2009, Vyacheslav Patkov. +* All rights reserved. +* +* hde64.h: C/C++ header file +* +*/ + +#ifndef _HDE64_H_ +#define _HDE64_H_ + +/* stdint.h - C99 standard header +* http://en.wikipedia.org/wiki/stdint.h +* +* if your compiler doesn't contain "stdint.h" header (for +* example, Microsoft Visual C++), you can download file: +* http://www.azillionmonkeys.com/qed/pstdint.h +* and change next line to: +* #include "pstdint.h" +*/ + +// Kernel Mode +#if defined(_KERNEL) || defined(MIRA_PLATFORM) +#include +#else +// User mode +#if defined(__cplusplus) +#include +#else // defined(__cplusplus) +#include +#endif // defined(__cplusplus) + +#endif // defined(_KERNEL) || defined(MIRA_PLATFORM) + +#define F_MODRM 0x00000001 +#define F_SIB 0x00000002 +#define F_IMM8 0x00000004 +#define F_IMM16 0x00000008 +#define F_IMM32 0x00000010 +#define F_IMM64 0x00000020 +#define F_DISP8 0x00000040 +#define F_DISP16 0x00000080 +#define F_DISP32 0x00000100 +#define F_RELATIVE 0x00000200 +#define F_ERROR 0x00001000 +#define F_ERROR_OPCODE 0x00002000 +#define F_ERROR_LENGTH 0x00004000 +#define F_ERROR_LOCK 0x00008000 +#define F_ERROR_OPERAND 0x00010000 +#define F_PREFIX_REPNZ 0x01000000 +#define F_PREFIX_REPX 0x02000000 +#define F_PREFIX_REP 0x03000000 +#define F_PREFIX_66 0x04000000 +#define F_PREFIX_67 0x08000000 +#define F_PREFIX_LOCK 0x10000000 +#define F_PREFIX_SEG 0x20000000 +#define F_PREFIX_REX 0x40000000 +#define F_PREFIX_ANY 0x7f000000 + +#define PREFIX_SEGMENT_CS 0x2e +#define PREFIX_SEGMENT_SS 0x36 +#define PREFIX_SEGMENT_DS 0x3e +#define PREFIX_SEGMENT_ES 0x26 +#define PREFIX_SEGMENT_FS 0x64 +#define PREFIX_SEGMENT_GS 0x65 +#define PREFIX_LOCK 0xf0 +#define PREFIX_REPNZ 0xf2 +#define PREFIX_REPX 0xf3 +#define PREFIX_OPERAND_SIZE 0x66 +#define PREFIX_ADDRESS_SIZE 0x67 + +#pragma pack(push,1) + +typedef struct { + uint8_t len; + uint8_t p_rep; + uint8_t p_lock; + uint8_t p_seg; + uint8_t p_66; + uint8_t p_67; + uint8_t rex; + uint8_t rex_w; + uint8_t rex_r; + uint8_t rex_x; + uint8_t rex_b; + uint8_t opcode; + uint8_t opcode2; + uint8_t modrm; + uint8_t modrm_mod; + uint8_t modrm_reg; + uint8_t modrm_rm; + uint8_t sib; + uint8_t sib_scale; + uint8_t sib_index; + uint8_t sib_base; + union { + uint8_t imm8; + uint16_t imm16; + uint32_t imm32; + uint64_t imm64; + } imm; + union { + uint8_t disp8; + uint16_t disp16; + uint32_t disp32; + } disp; + uint32_t flags; +} hde64s; + +#pragma pack(pop) + +#ifdef __cplusplus +extern "C" { +#endif + + /* __cdecl */ + unsigned int hde64_disasm(const void *code, hde64s *hs); + +#ifdef __cplusplus +} +#endif + +#endif /* _HDE64_H_ */ \ No newline at end of file diff --git a/Playstation/OrbisLibGeneralHelper/table64.h b/Playstation/OrbisLibGeneralHelper/table64.h new file mode 100644 index 0000000..f4b8e67 --- /dev/null +++ b/Playstation/OrbisLibGeneralHelper/table64.h @@ -0,0 +1,74 @@ +/* +* Hacker Disassembler Engine 64 C +* Copyright (c) 2008-2009, Vyacheslav Patkov. +* All rights reserved. +* +*/ + +#define C_NONE 0x00 +#define C_MODRM 0x01 +#define C_IMM8 0x02 +#define C_IMM16 0x04 +#define C_IMM_P66 0x10 +#define C_REL8 0x20 +#define C_REL32 0x40 +#define C_GROUP 0x80 +#define C_ERROR 0xff + +#define PRE_ANY 0x00 +#define PRE_NONE 0x01 +#define PRE_F2 0x02 +#define PRE_F3 0x04 +#define PRE_66 0x08 +#define PRE_67 0x10 +#define PRE_LOCK 0x20 +#define PRE_SEG 0x40 +#define PRE_ALL 0xff + +#define DELTA_OPCODES 0x4a +#define DELTA_FPU_REG 0xfd +#define DELTA_FPU_MODRM 0x104 +#define DELTA_PREFIXES 0x13c +#define DELTA_OP_LOCK_OK 0x1ae +#define DELTA_OP2_LOCK_OK 0x1c6 +#define DELTA_OP_ONLY_MEM 0x1d8 +#define DELTA_OP2_ONLY_MEM 0x1e7 + +unsigned char hde64_table[] = { + 0xa5,0xaa,0xa5,0xb8,0xa5,0xaa,0xa5,0xaa,0xa5,0xb8,0xa5,0xb8,0xa5,0xb8,0xa5, + 0xb8,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xac,0xc0,0xcc,0xc0,0xa1,0xa1, + 0xa1,0xa1,0xb1,0xa5,0xa5,0xa6,0xc0,0xc0,0xd7,0xda,0xe0,0xc0,0xe4,0xc0,0xea, + 0xea,0xe0,0xe0,0x98,0xc8,0xee,0xf1,0xa5,0xd3,0xa5,0xa5,0xa1,0xea,0x9e,0xc0, + 0xc0,0xc2,0xc0,0xe6,0x03,0x7f,0x11,0x7f,0x01,0x7f,0x01,0x3f,0x01,0x01,0xab, + 0x8b,0x90,0x64,0x5b,0x5b,0x5b,0x5b,0x5b,0x92,0x5b,0x5b,0x76,0x90,0x92,0x92, + 0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x6a,0x73,0x90, + 0x5b,0x52,0x52,0x52,0x52,0x5b,0x5b,0x5b,0x5b,0x77,0x7c,0x77,0x85,0x5b,0x5b, + 0x70,0x5b,0x7a,0xaf,0x76,0x76,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b, + 0x5b,0x5b,0x86,0x01,0x03,0x01,0x04,0x03,0xd5,0x03,0xd5,0x03,0xcc,0x01,0xbc, + 0x03,0xf0,0x03,0x03,0x04,0x00,0x50,0x50,0x50,0x50,0xff,0x20,0x20,0x20,0x20, + 0x01,0x01,0x01,0x01,0xc4,0x02,0x10,0xff,0xff,0xff,0x01,0x00,0x03,0x11,0xff, + 0x03,0xc4,0xc6,0xc8,0x02,0x10,0x00,0xff,0xcc,0x01,0x01,0x01,0x00,0x00,0x00, + 0x00,0x01,0x01,0x03,0x01,0xff,0xff,0xc0,0xc2,0x10,0x11,0x02,0x03,0x01,0x01, + 0x01,0xff,0xff,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x10, + 0x10,0x10,0x10,0x02,0x10,0x00,0x00,0xc6,0xc8,0x02,0x02,0x02,0x02,0x06,0x00, + 0x04,0x00,0x02,0xff,0x00,0xc0,0xc2,0x01,0x01,0x03,0x03,0x03,0xca,0x40,0x00, + 0x0a,0x00,0x04,0x00,0x00,0x00,0x00,0x7f,0x00,0x33,0x01,0x00,0x00,0x00,0x00, + 0x00,0x00,0xff,0xbf,0xff,0xff,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0xff,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff, + 0x00,0x00,0x00,0xbf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x00,0x00, + 0xff,0x40,0x40,0x40,0x40,0x41,0x49,0x40,0x40,0x40,0x40,0x4c,0x42,0x40,0x40, + 0x40,0x40,0x40,0x40,0x40,0x40,0x4f,0x44,0x53,0x40,0x40,0x40,0x44,0x57,0x43, + 0x5c,0x40,0x60,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, + 0x40,0x40,0x64,0x66,0x6e,0x6b,0x40,0x40,0x6a,0x46,0x40,0x40,0x44,0x46,0x40, + 0x40,0x5b,0x44,0x40,0x40,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x01,0x06, + 0x06,0x02,0x06,0x06,0x00,0x06,0x00,0x0a,0x0a,0x00,0x00,0x00,0x02,0x07,0x07, + 0x06,0x02,0x0d,0x06,0x06,0x06,0x0e,0x05,0x05,0x02,0x02,0x00,0x00,0x04,0x04, + 0x04,0x04,0x05,0x06,0x06,0x06,0x00,0x00,0x00,0x0e,0x00,0x00,0x08,0x00,0x10, + 0x00,0x18,0x00,0x20,0x00,0x28,0x00,0x30,0x00,0x80,0x01,0x82,0x01,0x86,0x00, + 0xf6,0xcf,0xfe,0x3f,0xab,0x00,0xb0,0x00,0xb1,0x00,0xb3,0x00,0xba,0xf8,0xbb, + 0x00,0xc0,0x00,0xc1,0x00,0xc7,0xbf,0x62,0xff,0x00,0x8d,0xff,0x00,0xc4,0xff, + 0x00,0xc5,0xff,0x00,0xff,0xff,0xeb,0x01,0xff,0x0e,0x12,0x08,0x00,0x13,0x09, + 0x00,0x16,0x08,0x00,0x17,0x09,0x00,0x2b,0x09,0x00,0xae,0xff,0x07,0xb2,0xff, + 0x00,0xb4,0xff,0x00,0xb5,0xff,0x00,0xc3,0x01,0x00,0xc7,0xff,0xbf,0xe7,0x08, + 0x00,0xf0,0x02,0x00 +}; \ No newline at end of file diff --git a/Windows/OrbisNeighborHood/Resources/BuildNumber.txt b/Windows/OrbisNeighborHood/Resources/BuildNumber.txt index 1447642..7e1ef81 100644 --- a/Windows/OrbisNeighborHood/Resources/BuildNumber.txt +++ b/Windows/OrbisNeighborHood/Resources/BuildNumber.txt @@ -1 +1 @@ -1976 +1990 diff --git a/Windows/OrbisNeighborHood/Resources/BuildString.txt b/Windows/OrbisNeighborHood/Resources/BuildString.txt index bc7b4c8..71c35eb 100644 --- a/Windows/OrbisNeighborHood/Resources/BuildString.txt +++ b/Windows/OrbisNeighborHood/Resources/BuildString.txt @@ -1 +1 @@ -Version 3.0.1976 Debug Build Sunday December 18 2022 10:33 PM +Version 3.0.1990 Debug Build Monday December 19 2022 8:42 PM