Skip to content

Commit 9a0d93b

Browse files
committed
Implement minidump plugin
1 parent fc410b3 commit 9a0d93b

File tree

6 files changed

+102
-31
lines changed

6 files changed

+102
-31
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ jobs:
1616

1717
- name: Build (x64)
1818
run: |
19-
mkdir package\plugins\x64
19+
mkdir package\x64\plugins
2020
cmake -B build64 -A x64
2121
cmake --build build64 --config Release
22-
copy build64\Release\*.dp64 package\plugins\x64\
22+
copy build64\Release\*.dp64 package\x64\plugins\
2323
2424
- name: Build (x32)
2525
run: |
26-
mkdir package\plugins\x32
26+
mkdir package\x32\plugins
2727
cmake -B build32 -A Win32
2828
cmake --build build32 --config Release
29-
copy build32\Release\*.dp32 package\plugins\x32\
29+
copy build32\Release\*.dp32 package\x32\plugins\
3030
3131
- uses: actions/upload-artifact@v2
3232
with:

CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,34 +37,34 @@ set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "/DEBUG:FULL /INCREMENTAL:NO" CACHE STRING
3737
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
3838
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" CACHE STRING "")
3939

40-
project(PluginTemplate)
40+
project(MiniDump)
4141

4242
include("cmake/CPM.cmake")
4343
include("cmake/x64dbg.cmake")
4444

45-
# Target PluginTemplate
46-
set(CMKR_TARGET PluginTemplate)
47-
set(PluginTemplate_SOURCES "")
45+
# Target MiniDump
46+
set(CMKR_TARGET MiniDump)
47+
set(MiniDump_SOURCES "")
4848

49-
list(APPEND PluginTemplate_SOURCES
49+
list(APPEND MiniDump_SOURCES
5050
"src/plugin.cpp"
5151
"src/pluginmain.cpp"
5252
"src/plugin.h"
5353
"src/pluginmain.h"
5454
)
5555

56-
list(APPEND PluginTemplate_SOURCES
56+
list(APPEND MiniDump_SOURCES
5757
cmake.toml
5858
)
5959

60-
set(CMKR_SOURCES ${PluginTemplate_SOURCES})
61-
add_library(PluginTemplate SHARED)
60+
set(CMKR_SOURCES ${MiniDump_SOURCES})
61+
add_library(MiniDump SHARED)
6262

63-
if(PluginTemplate_SOURCES)
64-
target_sources(PluginTemplate PRIVATE ${PluginTemplate_SOURCES})
63+
if(MiniDump_SOURCES)
64+
target_sources(MiniDump PRIVATE ${MiniDump_SOURCES})
6565
endif()
6666

67-
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${PluginTemplate_SOURCES})
67+
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${MiniDump_SOURCES})
6868

6969
x64dbg_plugin(${CMKR_TARGET})
7070

README.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
# PluginTemplate
1+
# MiniDumpPlugin
22

3-
Template CMake project for x64dbg plugins. This uses [cmkr](https://build-cpp.github.io/cmkr/), `cmake.toml` contains the project configuration.
3+
Simple [x64dbg](https://x64dbg.com) plugin to save the current state in a full minidump. Created for [dumpulator](https://github.com/mrexodia/dumpulator).
44

5-
## Using the template
6-
7-
You can click the green *Use this template* button. See the article [*Creating a repository from a template*
8-
](https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template) by GitHub for more details.
9-
10-
Alternatively you can download a ZIP of this repository and set up the template locally.
5+
**Download the latest binaries [here](https://github.com/mrexodia/MiniDumpPlugin/releases).**
116

127
## Building
138

@@ -18,7 +13,7 @@ cmake -B build64 -A x64
1813
cmake --build build64 --config Release
1914
```
2015

21-
You will get `build64\PluginTemplate.sln` that you can open in Visual Studio.
16+
You will get `build64\MiniDump.sln` that you can open in Visual Studio.
2217

2318
To build a 32-bit plugin:
2419

@@ -29,5 +24,3 @@ cmake --build build32 --config Release
2924

3025
Alternatively you can open this folder in Visual Studio/CLion/Qt Creator.
3126

32-
![building animation](https://github.com/x64dbg/PluginTemplate/blob/3951eb4b320b7a26164616ab5141414e8cd5b0a1/building.gif?raw=true)
33-

cmake.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "/DEBUG:FULL /INCREMENTAL:NO" CACHE STRING
1414
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
1515
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" CACHE STRING "")
1616
"""
17-
name = "PluginTemplate"
17+
name = "MiniDump"
1818
include-after = [
1919
"cmake/CPM.cmake",
2020
"cmake/x64dbg.cmake",
2121
]
2222

23-
[target.PluginTemplate]
23+
[target.MiniDump]
2424
type = "shared"
2525
sources = [
2626
"src/*.cpp",

cmake/x64dbg.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CPMAddPackage(
22
NAME x64dbg
3-
URL https://downloads.sourceforge.net/project/x64dbg/snapshots/snapshot_2021-11-20_10-12.zip
4-
URL_HASH SHA1=C75AC6BA7E7E5AB60632EED5648254E4BEF11465
3+
URL https://downloads.sourceforge.net/project/x64dbg/snapshots/snapshot_2021-05-08_14-17.zip
4+
URL_HASH SHA1=a46f3bf3f84fee3b1f7da8949e79d425d7294979
55
DOWNLOAD_ONLY ON
66
)
77

src/plugin.cpp

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,87 @@
11
#include "plugin.h"
2+
#include <DbgHelp.h>
3+
4+
#pragma comment(lib, "dbghelp.lib")
5+
6+
static bool g_hasException = false;
7+
static EXCEPTION_DEBUG_INFO g_exception;
8+
9+
PLUG_EXPORT void CBEXCEPTION(CBTYPE, PLUG_CB_EXCEPTION* exception)
10+
{
11+
if (exception->Exception)
12+
{
13+
g_hasException = true;
14+
memcpy(&g_exception, exception->Exception, sizeof(g_exception));
15+
}
16+
}
17+
18+
PLUG_EXPORT void CBSTOPDEBUG(CBTYPE, PLUG_CB_STOPDEBUG*)
19+
{
20+
g_hasException = false;
21+
}
22+
23+
static bool cbMiniDump(int argc, char* argv[])
24+
{
25+
if (DbgIsRunning())
26+
{
27+
dputs("Cannot dump while running...");
28+
return false;
29+
}
30+
31+
if (argc < 2)
32+
{
33+
dputs("Usage: MiniDump my.dmp");
34+
return false;
35+
}
36+
37+
HANDLE hFile = CreateFileA(argv[1], GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
38+
if (hFile == INVALID_HANDLE_VALUE)
39+
{
40+
dprintf("Failed to create '%s'\n", argv[1]);
41+
return false;
42+
}
43+
44+
CONTEXT context;
45+
context.ContextFlags = CONTEXT_ALL;
46+
GetThreadContext(DbgGetThreadHandle(), &context);
47+
48+
EXCEPTION_POINTERS exceptionPointers = {};
49+
exceptionPointers.ContextRecord = &context;
50+
exceptionPointers.ExceptionRecord = &g_exception.ExceptionRecord;
51+
if (exceptionPointers.ExceptionRecord->ExceptionCode == 0)
52+
{
53+
auto& exceptionRecord = *exceptionPointers.ExceptionRecord;
54+
exceptionRecord.ExceptionCode = 0xFFFFFFFF;
55+
#ifdef _WIN64
56+
exceptionRecord.ExceptionAddress = PVOID(context.Rip);
57+
#else
58+
exceptionRecord.ExceptionAddress = PVOID(context.Eip);
59+
#endif // _WIN64
60+
}
61+
62+
MINIDUMP_EXCEPTION_INFORMATION exceptionInfo = {};
63+
exceptionInfo.ThreadId = DbgGetThreadId();
64+
exceptionInfo.ExceptionPointers = &exceptionPointers;
65+
exceptionInfo.ClientPointers = FALSE;
66+
auto dumpType = MINIDUMP_TYPE(MiniDumpWithFullMemory | MiniDumpWithFullMemoryInfo | MiniDumpIgnoreInaccessibleMemory);
67+
if (MiniDumpWriteDump(DbgGetProcessHandle(), DbgGetProcessId(), hFile, dumpType, &exceptionInfo, nullptr, nullptr))
68+
{
69+
dputs("Dump saved!");
70+
}
71+
else
72+
{
73+
dprintf("MiniDumpWriteDump failed :( LastError = %d\n", GetLastError());
74+
}
75+
76+
CloseHandle(hFile);
77+
return true;
78+
}
279

380
//Initialize your plugin data here.
481
bool pluginInit(PLUG_INITSTRUCT* initStruct)
582
{
6-
return true; //Return false to cancel loading the plugin.
83+
_plugin_registercommand(pluginHandle, "MiniDump", cbMiniDump, true);
84+
return true; //Return false to cancel loading the plugin.
785
}
886

987
//Deinitialize your plugin data here.

0 commit comments

Comments
 (0)