Skip to content

Commit

Permalink
Cleaned some parts of code structure
Browse files Browse the repository at this point in the history
Improved Hook to preserve registers
Fixed crash on 1.17.1 and 1.18.2
Removed bad and useless keybinds
  • Loading branch information
Lefraudeur committed Oct 20, 2023
1 parent d9c01f1 commit bbe7e9e
Show file tree
Hide file tree
Showing 55 changed files with 535 additions and 285 deletions.
15 changes: 11 additions & 4 deletions Ripterms Ghost.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)Lib;$(SolutionDir)Lib\MinHook;$(SolutionDir)Lib\JNI;$(SolutionDir)Lib\miniz;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>jawt.lib;jvm.lib;opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>jawt.lib;jvm.lib;opengl32.lib;Glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand All @@ -121,7 +121,7 @@
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>false</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)Lib;$(SolutionDir)Lib\MinHook;$(SolutionDir)Lib\JNI;$(SolutionDir)Lib\miniz;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>jawt.lib;jvm.lib;opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>jawt.lib;jvm.lib;opengl32.lib;Glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -140,7 +140,7 @@
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)Lib;$(SolutionDir)Lib\MinHook;$(SolutionDir)Lib\JNI;$(SolutionDir)Lib\miniz;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>jawt.lib;jvm.lib;opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>jawt.lib;jvm.lib;opengl32.lib;Glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -163,7 +163,7 @@
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>false</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)Lib;$(SolutionDir)Lib\MinHook;$(SolutionDir)Lib\JNI;$(SolutionDir)Lib\miniz;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>jawt.lib;jvm.lib;opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>jawt.lib;jvm.lib;opengl32.lib;Glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand All @@ -179,6 +179,8 @@
<ClCompile Include="java\lang\Object\Object.cpp" />
<ClCompile Include="java\lang\String\String.cpp" />
<ClCompile Include="java\lang\System\System.cpp" />
<ClCompile Include="java\nio\FloatBuffer\FloatBuffer.cpp" />
<ClCompile Include="java\nio\IntBuffer\IntBuffer.cpp" />
<ClCompile Include="java\util\Collection\Collection.cpp" />
<ClCompile Include="java\util\List\List.cpp" />
<ClCompile Include="java\util\Map\Map.cpp" />
Expand All @@ -191,6 +193,7 @@
<ClCompile Include="net\minecraft\client\multiplayer\PlayerControllerMP\PlayerControllerMP.cpp" />
<ClCompile Include="net\minecraft\client\multiplayer\WorldClient\WorldClient.cpp" />
<ClCompile Include="net\minecraft\client\network\NetHandlerPlayClient\NetHandlerPlayClient.cpp" />
<ClCompile Include="net\minecraft\client\renderer\ActiveRenderInfo\ActiveRenderInfo.cpp" />
<ClCompile Include="net\minecraft\client\settings\GameSettings\GameSettings.cpp" />
<ClCompile Include="net\minecraft\client\settings\KeyBinding\KeyBinding.cpp" />
<ClCompile Include="net\minecraft\entity\EntityLivingBase\EntityLivingBase.cpp" />
Expand Down Expand Up @@ -232,6 +235,8 @@
<ClInclude Include="java\lang\Object\Object.h" />
<ClInclude Include="java\lang\String\String.h" />
<ClInclude Include="java\lang\System\System.h" />
<ClInclude Include="java\nio\FloatBuffer\FloatBuffer.h" />
<ClInclude Include="java\nio\IntBuffer\IntBuffer.h" />
<ClInclude Include="java\util\Collection\Collection.h" />
<ClInclude Include="java\util\List\List.h" />
<ClInclude Include="java\util\Map\Map.h" />
Expand All @@ -243,6 +248,7 @@
<ClInclude Include="net\minecraft\client\multiplayer\PlayerControllerMP\PlayerControllerMP.h" />
<ClInclude Include="net\minecraft\client\multiplayer\WorldClient\WorldClient.h" />
<ClInclude Include="net\minecraft\client\network\NetHandlerPlayClient\NetHandlerPlayClient.h" />
<ClInclude Include="net\minecraft\client\renderer\ActiveRenderInfo\ActiveRenderInfo.h" />
<ClInclude Include="net\minecraft\client\settings\GameSettings\GameSettings.h" />
<ClInclude Include="net\minecraft\client\settings\KeyBinding\KeyBinding.h" />
<ClInclude Include="net\minecraft\entity\EntityLivingBase\EntityLivingBase.h" />
Expand All @@ -262,6 +268,7 @@
<ClInclude Include="Ripterms\Event\Event.h" />
<ClInclude Include="Ripterms\GUI\font.h" />
<ClInclude Include="Ripterms\GUI\GUI.h" />
<ClInclude Include="Ripterms\GUI\GUI_conf.h" />
<ClInclude Include="Ripterms\Hook\Hook.h" />
<ClInclude Include="Ripterms\JavaClass\JavaClass.h" />
<ClInclude Include="Ripterms\Mappings\mappings_forge_1_7_10.h" />
Expand Down
21 changes: 21 additions & 0 deletions Ripterms Ghost.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@
<ClCompile Include="Ripterms\Hook\Module.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="net\minecraft\client\renderer\ActiveRenderInfo\ActiveRenderInfo.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="java\nio\FloatBuffer\FloatBuffer.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="java\nio\IntBuffer\IntBuffer.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Ripterms\Ripterms.h">
Expand Down Expand Up @@ -332,5 +341,17 @@
<ClInclude Include="Ripterms\Hook\Hook.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="Ripterms\GUI\GUI_conf.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="net\minecraft\client\renderer\ActiveRenderInfo\ActiveRenderInfo.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="java\nio\FloatBuffer\FloatBuffer.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="java\nio\IntBuffer\IntBuffer.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions Ripterms/Cache/Cache.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Cache.h"
#include <iostream>
#include "../../net/minecraft/client/renderer/ActiveRenderInfo/ActiveRenderInfo.h"

Ripterms::Cache::Cache()
{
Expand All @@ -25,6 +26,9 @@ bool Ripterms::Cache::fillCache()
gameSettings = theMinecraft.getGameSettings();
timer = theMinecraft.getTimer();
playerController = theMinecraft.getPlayerController();
//MODELVIEW = ActiveRenderInfo::getMODELVIEW();
//PROJECTION = ActiveRenderInfo::getPROJECTION();
//VIEWPORT = ActiveRenderInfo::getVIEWPORT();
}
return true;
}
6 changes: 5 additions & 1 deletion Ripterms/Cache/Cache.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once
#include "../../java/lang/Object/Object.h"
#include "../../net/minecraft/client/Minecraft/Minecraft.h"
#include "../../java/util/Map/Map.h"
#include "../../net/minecraft/util/Timer/Timer.h"
#include "../../java/nio/FloatBuffer/FloatBuffer.h"
#include "../../java/nio/IntBuffer/IntBuffer.h"

namespace Ripterms
{
Expand All @@ -18,6 +19,9 @@ namespace Ripterms
List playerEntities{};
GameSettings gameSettings{};
Timer timer{};
FloatBuffer MODELVIEW{}; // not done
FloatBuffer PROJECTION{}; // not done
IntBuffer VIEWPORT{}; // not done

Map EMPTY_MAP{};
bool fillCache();
Expand Down
4 changes: 0 additions & 4 deletions Ripterms/Event/Event.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#pragma once
#include <JNI/jni.h>
#include <JNI/jvmti.h>
#include "../../java/lang/Object/Object.h"
#include "../../java/lang/String/String.h"
#include "../../java/util/Map/Map.h"

namespace Ripterms
{
Expand Down
25 changes: 22 additions & 3 deletions Ripterms/GUI/GUI.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "GUI.h"
#include <Windows.h>
#include <iostream>
#define IMGUI_DEFINE_MATH_OPERATORS
#include <ImGui/imgui.h>
#include <ImGui/imgui_impl_opengl3.h>
#include <ImGui/imgui_impl_win32.h>
#include <gl/GL.h>
#include <Windows.h>
#include "../Modules/Modules.h"
#include "font.h"
#include "../Hook/Hook.h"
#include "GUI_conf.h"

namespace
{
Expand Down Expand Up @@ -131,6 +131,25 @@ static BOOL WINAPI detour_wglSwapBuffers(HDC unnamedParam1)
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();


ImGui::SetNextWindowPos(ImVec2(0, 0));
ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize);
ImGui::Begin("Overlay", nullptr,
ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoScrollbar |
ImGuiWindowFlags_NoInputs |
ImGuiWindowFlags_NoBackground);
for (const std::pair<std::string, std::vector<Ripterms::Modules::IModule*>>& category : Ripterms::Modules::categories)
{
for (Ripterms::Modules::IModule* m : category.second)
{
m->render();
}
}
ImGui::End();

if (Ripterms::GUI::draw)
{
update_style();
Expand Down
41 changes: 0 additions & 41 deletions Ripterms/GUI/GUI.h
Original file line number Diff line number Diff line change
@@ -1,52 +1,11 @@
#pragma once

#include "imgui.h"

namespace Ripterms
{
namespace GUI
{
inline bool draw = false;
bool init();
void clean();

inline ImVec2 category_button_size = ImVec2(100, 30);

/* other style*/

inline bool ripterms_title = true;
/* both are false by default but eh why not */
inline bool show_color_theming = false;
inline bool show_rounding_theming = false;

/* color picker colors */
inline ImVec4 color_active_tab = ImVec4(.6f, .0f, .0f, 1.f);
//inline ImVec4 color_inactive_tab = ImVec4(.5f, .5f, .5f, 1.f);
inline ImColor color_child_bg = ImColor(23, 23, 23, 190);
inline ImColor color_bool_enabled = ImColor(10, 150, 10, 255);
inline ImColor color_bool_disabled = ImColor(173, 55, 65, 255);
inline ImColor color_slider_grab = ImColor(10, 150, 10, 255);
inline ImColor color_slider_line = ImColor(173, 55, 65, 255);
inline ImColor color_frame_bg = ImColor(35, 35, 35, 255);
inline ImColor color_frame_bg_active = ImColor(35, 35, 35, 255);
inline ImColor color_frame_bg_hovered = ImColor(35, 35, 35, 255);
inline ImColor color_window_bg = ImColor(11, 14, 15, 255);
inline ImColor color_button = ImColor(31, 30, 31, 255);
inline ImColor color_button_active = ImColor(239, 73, 88, 255);
inline ImColor color_button_hovered = ImColor(173, 55, 65, 255);
inline ImColor color_text = ImColor(200, 200, 200, 255);
inline ImColor color_header = ImColor(78, 78, 78, 255);
inline ImColor color_header_active = ImColor(78, 78, 78, 255);
inline ImColor color_header_hovered = ImColor(78, 78, 78, 255);

/* rounding */

inline float rounding_frame = 10.f;
inline float rounding_window = 5.f;
inline float rounding_child = 5.f;
inline float rounding_grab = 5.f;
inline float rounding_popup = 5.f;
inline float rounding_scrollbar = 5.f;
inline float rounding_tab = 5.f;
}
}
44 changes: 44 additions & 0 deletions Ripterms/GUI/GUI_conf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once
#include <ImGui/imgui.h>

namespace Ripterms::GUI
{
static ImVec2 category_button_size = ImVec2(100, 30);

/* other style*/

static bool ripterms_title = true;
/* both are false by default but eh why not */
static bool show_color_theming = false;
static bool show_rounding_theming = false;

/* color picker colors */
static ImVec4 color_active_tab = ImVec4(.6f, .0f, .0f, 1.f);
//inline ImVec4 color_inactive_tab = ImVec4(.5f, .5f, .5f, 1.f);
static ImColor color_child_bg = ImColor(23, 23, 23, 190);
static ImColor color_bool_enabled = ImColor(10, 150, 10, 255);
static ImColor color_bool_disabled = ImColor(173, 55, 65, 255);
static ImColor color_slider_grab = ImColor(10, 150, 10, 255);
static ImColor color_slider_line = ImColor(173, 55, 65, 255);
static ImColor color_frame_bg = ImColor(35, 35, 35, 255);
static ImColor color_frame_bg_active = ImColor(35, 35, 35, 255);
static ImColor color_frame_bg_hovered = ImColor(35, 35, 35, 255);
static ImColor color_window_bg = ImColor(11, 14, 15, 255);
static ImColor color_button = ImColor(31, 30, 31, 255);
static ImColor color_button_active = ImColor(239, 73, 88, 255);
static ImColor color_button_hovered = ImColor(173, 55, 65, 255);
static ImColor color_text = ImColor(200, 200, 200, 255);
static ImColor color_header = ImColor(78, 78, 78, 255);
static ImColor color_header_active = ImColor(78, 78, 78, 255);
static ImColor color_header_hovered = ImColor(78, 78, 78, 255);

/* rounding */

static float rounding_frame = 10.f;
static float rounding_window = 5.f;
static float rounding_child = 5.f;
static float rounding_grab = 5.f;
static float rounding_popup = 5.f;
static float rounding_scrollbar = 5.f;
static float rounding_tab = 5.f;
}
24 changes: 14 additions & 10 deletions Ripterms/Hook/Hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,25 @@ void Ripterms::Hook::hook_RELATIVE_5B_JMP(void* a_detour_function_addr, void** a
our_tmp_instructions[10] = '\xff'; // jmp
our_tmp_instructions[11] = '\xe0'; // rax

allocated_instructions = (uint8_t*)VirtualAlloc(nullptr, bytes_to_replace + 12, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);

allocated_instructions = (uint8_t*)VirtualAlloc(nullptr, bytes_to_replace + 22, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if (!allocated_instructions)
throw std::exception("Failed to allocate memory for the hook");
*a_original_function_addr = allocated_instructions; // where to go once detour returns

// we copy the original instructions to our allocated instructions, because they are going to be overwritten by the relative jmp instruction
memcpy(allocated_instructions, target_function_addr, bytes_to_replace);
// jump back to normal execution flow
allocated_instructions[bytes_to_replace] = '\x48'; // mov
allocated_instructions[bytes_to_replace + 1] = '\xB8'; // rax,
*((uint64_t*)(allocated_instructions + bytes_to_replace + 2)) = (uint64_t)target_function_addr + bytes_to_replace;
allocated_instructions[bytes_to_replace + 10] = '\xff'; // jmp
allocated_instructions[bytes_to_replace + 11] = '\xe0'; // rax
// jump back to normal execution flow, by preserving registers and stack
// mov[rsp - 16], rax
// mov rax, 0x7e80e42e7d8e1b34
// push rax
// mov rax, [rsp - 8]
// ret
uint8_t shell_code1[] = { 0x48, 0x89, 0x44, 0x24, 0xf0, 0x48, 0xb8 };
memcpy(allocated_instructions + bytes_to_replace, shell_code1, 7);
*((uint64_t*)(allocated_instructions + bytes_to_replace + 7)) = (uint64_t)target_function_addr + bytes_to_replace;
uint8_t shell_code2[] = { 0x50, 0x48, 0x8B, 0x44, 0x24, 0xF8, 0xC3 };
memcpy(allocated_instructions + bytes_to_replace + 15, shell_code2, 7);


// relative jump from target_function_addr to our_tmp_instructions
Expand All @@ -126,14 +132,12 @@ void Ripterms::Hook::hook_RELATIVE_5B_JMP(void* a_detour_function_addr, void** a

VirtualProtect(target_function_addr, bytes_to_replace, original_protection, &original_protection);
VirtualProtect(our_tmp_instructions, 12, PAGE_EXECUTE_READ, &original_protection);
VirtualProtect(allocated_instructions, bytes_to_replace + 12, PAGE_EXECUTE_READ, &original_protection);
VirtualProtect(allocated_instructions, bytes_to_replace + 22, PAGE_EXECUTE_READ, &original_protection);
}

void Ripterms::Hook::remove_RELATIVE_5B_JMP()
{
DWORD original_protection = 0;
VirtualProtect(our_tmp_instructions, 12, PAGE_EXECUTE_READWRITE, &original_protection);
VirtualProtect(allocated_instructions, bytes_to_replace + 12, PAGE_EXECUTE_READWRITE, &original_protection);
VirtualProtect(target_function_addr, bytes_to_replace, PAGE_EXECUTE_READWRITE, &original_protection);

memcpy(target_function_addr, allocated_instructions, bytes_to_replace);
Expand Down
2 changes: 1 addition & 1 deletion Ripterms/JavaClass/JavaClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace Ripterms

static std::unordered_map<JNIEnv*, std::unordered_map<std::string, JClass>> jclassCache;
static std::unordered_map<std::string, JavaClassData> data;
inline static const nlohmann::json* mappings = nullptr;
inline static nlohmann::json mappings{};

std::string class_path{};
};
Expand Down
Loading

0 comments on commit bbe7e9e

Please sign in to comment.