Skip to content

Commit 537277d

Browse files
committed
Initial Commit
0 parents  commit 537277d

File tree

16 files changed

+757
-0
lines changed

16 files changed

+757
-0
lines changed

Dumper.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.4.33110.190
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Dumper", "Dumper\Dumper.vcxproj", "{12E398CD-74B9-4C0C-8227-634472D2CB04}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{12E398CD-74B9-4C0C-8227-634472D2CB04}.Debug|x64.ActiveCfg = Debug|x64
17+
{12E398CD-74B9-4C0C-8227-634472D2CB04}.Debug|x64.Build.0 = Debug|x64
18+
{12E398CD-74B9-4C0C-8227-634472D2CB04}.Debug|x86.ActiveCfg = Debug|Win32
19+
{12E398CD-74B9-4C0C-8227-634472D2CB04}.Debug|x86.Build.0 = Debug|Win32
20+
{12E398CD-74B9-4C0C-8227-634472D2CB04}.Release|x64.ActiveCfg = Release|x64
21+
{12E398CD-74B9-4C0C-8227-634472D2CB04}.Release|x64.Build.0 = Release|x64
22+
{12E398CD-74B9-4C0C-8227-634472D2CB04}.Release|x86.ActiveCfg = Release|Win32
23+
{12E398CD-74B9-4C0C-8227-634472D2CB04}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {435462CD-C05B-4FCA-A651-0BEEE7C15E68}
30+
EndGlobalSection
31+
EndGlobal

Dumper/Dumper.vcxproj

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>16.0</VCProjectVersion>
23+
<Keyword>Win32Proj</Keyword>
24+
<ProjectGuid>{12e398cd-74b9-4c0c-8227-634472d2cb04}</ProjectGuid>
25+
<RootNamespace>Dumper</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>DynamicLibrary</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v143</PlatformToolset>
33+
<CharacterSet>MultiByte</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>DynamicLibrary</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v143</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>MultiByte</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43+
<ConfigurationType>DynamicLibrary</ConfigurationType>
44+
<UseDebugLibraries>true</UseDebugLibraries>
45+
<PlatformToolset>v143</PlatformToolset>
46+
<CharacterSet>MultiByte</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49+
<ConfigurationType>DynamicLibrary</ConfigurationType>
50+
<UseDebugLibraries>false</UseDebugLibraries>
51+
<PlatformToolset>v143</PlatformToolset>
52+
<WholeProgramOptimization>true</WholeProgramOptimization>
53+
<CharacterSet>MultiByte</CharacterSet>
54+
</PropertyGroup>
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56+
<ImportGroup Label="ExtensionSettings">
57+
</ImportGroup>
58+
<ImportGroup Label="Shared">
59+
</ImportGroup>
60+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74+
<IncludePath>C:\Program Files\Java\jdk-19\include;C:\Program Files\Java\jdk-19\include\win32;C:\Program Files\Java\jdk-19\include\win32\bridge;$(IncludePath)</IncludePath>
75+
</PropertyGroup>
76+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
77+
<IncludePath>C:\Program Files\Java\jdk-19\include;C:\Program Files\Java\jdk-19\include\win32;C:\Program Files\Java\jdk-19\include\win32\bridge;$(IncludePath)</IncludePath>
78+
</PropertyGroup>
79+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
80+
<IncludePath>C:\Program Files\Java\jdk-19\include;C:\Program Files\Java\jdk-19\include\win32;C:\Program Files\Java\jdk-19\include\win32\bridge;$(IncludePath)</IncludePath>
81+
</PropertyGroup>
82+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
83+
<IncludePath>C:\Program Files\Java\jdk-19\include;C:\Program Files\Java\jdk-19\include\win32;C:\Program Files\Java\jdk-19\include\win32\bridge;$(IncludePath)</IncludePath>
84+
</PropertyGroup>
85+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
86+
<ClCompile>
87+
<WarningLevel>Level3</WarningLevel>
88+
<SDLCheck>true</SDLCheck>
89+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
90+
<ConformanceMode>true</ConformanceMode>
91+
<LanguageStandard>stdcpp20</LanguageStandard>
92+
</ClCompile>
93+
<Link>
94+
<SubSystem>Console</SubSystem>
95+
<GenerateDebugInformation>true</GenerateDebugInformation>
96+
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
97+
<ModuleDefinitionFile>
98+
</ModuleDefinitionFile>
99+
</Link>
100+
</ItemDefinitionGroup>
101+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
102+
<ClCompile>
103+
<WarningLevel>Level3</WarningLevel>
104+
<FunctionLevelLinking>true</FunctionLevelLinking>
105+
<IntrinsicFunctions>true</IntrinsicFunctions>
106+
<SDLCheck>true</SDLCheck>
107+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
108+
<ConformanceMode>true</ConformanceMode>
109+
<LanguageStandard>stdcpp20</LanguageStandard>
110+
</ClCompile>
111+
<Link>
112+
<SubSystem>Console</SubSystem>
113+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
114+
<OptimizeReferences>true</OptimizeReferences>
115+
<GenerateDebugInformation>true</GenerateDebugInformation>
116+
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
117+
<ModuleDefinitionFile>
118+
</ModuleDefinitionFile>
119+
</Link>
120+
</ItemDefinitionGroup>
121+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
122+
<ClCompile>
123+
<WarningLevel>Level3</WarningLevel>
124+
<SDLCheck>true</SDLCheck>
125+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
126+
<ConformanceMode>true</ConformanceMode>
127+
<LanguageStandard>stdcpp20</LanguageStandard>
128+
<AdditionalIncludeDirectories>$(SolutionDir)Dumper\hook\min_hook\dll_resources\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
129+
</ClCompile>
130+
<Link>
131+
<SubSystem>Console</SubSystem>
132+
<GenerateDebugInformation>true</GenerateDebugInformation>
133+
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
134+
<ModuleDefinitionFile>
135+
</ModuleDefinitionFile>
136+
<AssemblyLinkResource>
137+
</AssemblyLinkResource>
138+
</Link>
139+
</ItemDefinitionGroup>
140+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
141+
<ClCompile>
142+
<WarningLevel>Level3</WarningLevel>
143+
<FunctionLevelLinking>true</FunctionLevelLinking>
144+
<IntrinsicFunctions>true</IntrinsicFunctions>
145+
<SDLCheck>true</SDLCheck>
146+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
147+
<ConformanceMode>true</ConformanceMode>
148+
<LanguageStandard>stdcpp20</LanguageStandard>
149+
</ClCompile>
150+
<Link>
151+
<SubSystem>Console</SubSystem>
152+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
153+
<OptimizeReferences>true</OptimizeReferences>
154+
<GenerateDebugInformation>true</GenerateDebugInformation>
155+
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
156+
<ModuleDefinitionFile>
157+
</ModuleDefinitionFile>
158+
<AssemblyLinkResource>%(AssemblyLinkResource)</AssemblyLinkResource>
159+
</Link>
160+
</ItemDefinitionGroup>
161+
<ItemGroup>
162+
<ClCompile Include="entry\entry.cpp" />
163+
<ClCompile Include="hook\hook.cpp" />
164+
<ClCompile Include="main.cpp" />
165+
</ItemGroup>
166+
<ItemGroup>
167+
<ClInclude Include="hook\hook.h" />
168+
<ClInclude Include="main.h" />
169+
</ItemGroup>
170+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
171+
<ImportGroup Label="ExtensionTargets">
172+
</ImportGroup>
173+
</Project>

Dumper/Dumper.vcxproj.filters

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Archivos de origen">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Archivos de encabezado">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Archivos de recursos">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
<Filter Include="NewFilter1">
17+
<UniqueIdentifier>{9a7b2572-426f-40db-96db-e81aef10365e}</UniqueIdentifier>
18+
</Filter>
19+
</ItemGroup>
20+
<ItemGroup>
21+
<ClInclude Include="hook\hook.h">
22+
<Filter>Archivos de encabezado</Filter>
23+
</ClInclude>
24+
<ClInclude Include="main.h">
25+
<Filter>Archivos de encabezado</Filter>
26+
</ClInclude>
27+
</ItemGroup>
28+
<ItemGroup>
29+
<ClCompile Include="entry\entry.cpp">
30+
<Filter>Archivos de origen</Filter>
31+
</ClCompile>
32+
<ClCompile Include="hook\hook.cpp">
33+
<Filter>Archivos de origen</Filter>
34+
</ClCompile>
35+
<ClCompile Include="main.cpp">
36+
<Filter>Archivos de origen</Filter>
37+
</ClCompile>
38+
</ItemGroup>
39+
</Project>

Dumper/Dumper.vcxproj.user

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ShowAllFiles>true</ShowAllFiles>
5+
</PropertyGroup>
6+
</Project>

Dumper/entry/entry.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "../main.h"
2+
3+
bool __stdcall DllMain(HINSTANCE dll, DWORD reason, LPVOID reserved)
4+
{
5+
if (reason == DLL_PROCESS_ATTACH)
6+
{
7+
AllocConsole();
8+
9+
freopen("CONOUT$", "w", stdout);
10+
11+
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)main::thread, dll, 0, 0);
12+
13+
}
14+
15+
else if (reason == DLL_PROCESS_DETACH)
16+
{
17+
FreeConsole();
18+
fclose(stdout);
19+
}
20+
return true;
21+
}

Dumper/hook/hook.cpp

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#include "hook.h"
2+
3+
void __stdcall __callback_class_file_load_hook(jvmtiEnv* jvmti_env,
4+
JNIEnv* jni_env,
5+
jclass class_being_redefined,
6+
jobject loader,
7+
const char* name,
8+
jobject protection_domain,
9+
jint class_data_len,
10+
const unsigned char* class_data,
11+
jint* new_class_data_len,
12+
unsigned char** new_class_data) {
13+
14+
15+
if (class_data_len <= 0 || name == NULL || class_data == NULL)
16+
return;
17+
18+
std::string path_name = "C:/Class-Dumper/Dump/" + std::string(name) + ".class";
19+
20+
std::filesystem::path path = std::filesystem::path(path_name);
21+
22+
if (!std::filesystem::exists(path.parent_path()) && !std::filesystem::create_directories(path.parent_path()))
23+
return;
24+
25+
std::ofstream outfile(path_name, std::ios_base::binary | std::ios_base::out);
26+
27+
if (!outfile.is_open())
28+
return;
29+
30+
std::cout << "Class loaded: " << name << std::endl;
31+
32+
outfile.write(reinterpret_cast<const char*>(class_data), class_data_len);
33+
34+
outfile.close();
35+
}
36+
37+
bool hook::c_hook::set_callbacks() {
38+
39+
jvmtiEventCallbacks callbacks;
40+
memset(&callbacks, 0, sizeof(callbacks));
41+
42+
callbacks.ClassFileLoadHook = &__callback_class_file_load_hook;
43+
44+
jvmtiError set_callback_error = jvmti_env->SetEventCallbacks(&callbacks, (jint) sizeof(callbacks));
45+
46+
if (set_callback_error)
47+
{
48+
logger("SetEventCallback Failed");
49+
return false;
50+
}
51+
52+
jvmtiError set_event_error = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL);
53+
54+
if (set_event_error)
55+
{
56+
logger("SetEventNotificationMode Failed");
57+
return false;
58+
}
59+
60+
return true;
61+
}
62+
63+
bool hook::c_hook::attach()
64+
{
65+
66+
HMODULE jvm = GetModuleHandleA("jvm.dll");
67+
68+
using t_createdvms = jint(__stdcall*)(JavaVM**, jsize, jsize*);
69+
70+
FARPROC processAddress = GetProcAddress(reinterpret_cast<HMODULE>(jvm), "JNI_GetCreatedJavaVMs");
71+
t_createdvms created_java_vms = reinterpret_cast<t_createdvms>(processAddress);
72+
73+
auto error = created_java_vms(&vm, 1, nullptr);
74+
75+
if (error != JNI_OK) {
76+
logger("JNI_GetCreatedJavaVMs Failed");
77+
return false;
78+
}
79+
80+
81+
error = vm->AttachCurrentThread(reinterpret_cast<void**>(&env), nullptr);
82+
83+
if (error != JNI_OK) {
84+
logger("AttachCurrentThread Failed");
85+
return false;
86+
}
87+
88+
vm->GetEnv(reinterpret_cast<void**>(&jvmti_env), JVMTI_VERSION_1_1);
89+
90+
if (!jvmti_env) {
91+
logger("GetEnv Failed");
92+
return false;
93+
}
94+
95+
return true;
96+
}
97+
98+
void hook::c_hook::dettach() {
99+
100+
jvmti_env->SetEventCallbacks(NULL, NULL);
101+
jvmti_env->SetEventNotificationMode(JVMTI_DISABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL);
102+
103+
vm->DetachCurrentThread();
104+
105+
env = nullptr;
106+
jvmti_env = nullptr;
107+
vm = nullptr;
108+
}

0 commit comments

Comments
 (0)