Skip to content

Commit 0695b83

Browse files
committed
Initial release
1 parent 44270a1 commit 0695b83

7 files changed

Lines changed: 332 additions & 82 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "ChaiScript"]
2+
path = ChaiScript
3+
url = https://github.com/ChaiScript/ChaiScript.git

CMakeLists.txt

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
11
cmake_minimum_required(VERSION 2.8.11)
22

3-
project(dbgPlugin CXX C)
3+
project(chaiScriptPlugin CXX C)
44

5-
set(x64dbgfolder C:/tools/x64dbg )
5+
if(NOT X64DBGFOLDER)
6+
if($ENV{X64DBGFOLDER})
7+
set(X64DBGFOLDER $ENV{X64DBGFOLDER} )
8+
else()
9+
set(X64DBGFOLDER .. )
10+
endif()
11+
endif()
612

7-
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${x64dbgfolder}/release/x32/plugins)
8-
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${x64dbgfolder}/release/x32/plugins)
13+
if(${CMAKE_SIZEOF_VOID_P} EQUAL 4)
14+
set(ARCH "32")
15+
else()
16+
set(ARCH "64")
17+
endif()
918

10-
include_directories( ${x64dbgfolder} )
11-
LINK_DIRECTORIES( ${x64dbgfolder}/pluginsdk )
19+
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${X64DBGFOLDER}/release/x${ARCH}/plugins)
20+
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${X64DBGFOLDER}/release/x${ARCH}/plugins)
1221

22+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
23+
set(CMAKE_AUTOMOC ON)
1324

14-
add_library(dbgPlugin SHARED
15-
main.cc
25+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
26+
27+
find_package(Qt5Widgets)
28+
find_package(Qt5Core)
29+
30+
include_directories( . ${X64DBGFOLDER} ChaiScript/include)
31+
LINK_DIRECTORIES( ${X64DBGFOLDER}/pluginsdk )
32+
33+
add_library(chaiScriptPlugin SHARED
34+
pluginmain.cc
35+
dbgops.h
36+
chaiInterops.h
1637
)
1738

18-
target_link_libraries(dbgPlugin x32dbg x32bridge )
19-
set_target_properties(dbgPlugin PROPERTIES SUFFIX ".dp32")
39+
target_link_libraries(chaiScriptPlugin x${ARCH}dbg x${ARCH}bridge Qt5::Core Qt5::Widgets )
40+
set_target_properties(chaiScriptPlugin PROPERTIES SUFFIX ".dp${ARCH}")

ChaiScript

Submodule ChaiScript added at 176d608

chaiinterops.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#pragma once
2+
#include <ChaiScript/chaiscript_defines.hpp>
3+
#include <ChaiScript/language/chaiscript_engine.hpp>
4+
5+
template <typename T> struct TypeWrapper {
6+
typedef T f_arg;
7+
typedef T chai_arg;
8+
static inline f_arg convert(chai_arg a) { return a; }
9+
};
10+
11+
template <> struct TypeWrapper<void> {
12+
typedef void f_arg;
13+
typedef void chai_arg;
14+
static inline f_arg convert(chai_arg ) { }
15+
};
16+
17+
template <> struct TypeWrapper <const char*> {
18+
typedef const char* f_arg;
19+
typedef const std::string& chai_arg;
20+
static inline f_arg convert(chai_arg a) { return a.c_str(); }
21+
};
22+
23+
template <> struct TypeWrapper <const unsigned char*> {
24+
typedef const unsigned char* f_arg;
25+
typedef const std::vector<unsigned char>& chai_arg;
26+
static inline f_arg convert(chai_arg a) { return &a[0]; }
27+
};
28+
29+
template <> struct TypeWrapper <unsigned char*> { };
30+
template <> struct TypeWrapper <char*> { };
31+
32+
template < typename... args >
33+
static inline std::function< void (typename TypeWrapper<args>::chai_arg...) >
34+
FunctionWrapper( void (*fn)(args...), int __pref ) {
35+
return [=] (typename TypeWrapper<args>::chai_arg... in) {
36+
fn( (TypeWrapper<args>::convert(in))... );
37+
};
38+
};
39+
40+
template < typename rtn, typename... args >
41+
static inline std::function< typename TypeWrapper<rtn>::chai_arg (typename TypeWrapper<args>::chai_arg...) >
42+
FunctionWrapper( rtn (*fn)(args...), int __pref) {
43+
return [=] (typename TypeWrapper<args>::chai_arg... in) {
44+
return TypeWrapper<rtn>::convert( fn( (TypeWrapper<args>::convert(in))... ) );
45+
};
46+
};
47+
48+
extern chaiscript::ChaiScript chai;

dbgops.h

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#ifndef DBG_FUNCTION
2+
#define DBG_FUNCTION(x)
3+
#endif
4+
5+
DBG_FUNCTION(DbgMemWrite)
6+
DBG_FUNCTION(DbgMemGetPageSize)
7+
DBG_FUNCTION(DbgCmdExec)
8+
DBG_FUNCTION(DbgCmdExecDirect)
9+
DBG_FUNCTION(DbgIsValidExpression)
10+
DBG_FUNCTION(DbgIsDebugging)
11+
DBG_FUNCTION(DbgIsJumpGoingToExecute)
12+
DBG_FUNCTION(DbgSetLabelAt)
13+
DBG_FUNCTION(DbgClearLabelRange)
14+
DBG_FUNCTION(DbgSetCommentAt)
15+
DBG_FUNCTION(DbgClearCommentRange)
16+
DBG_FUNCTION(DbgGetBookmarkAt)
17+
DBG_FUNCTION(DbgSetBookmarkAt)
18+
DBG_FUNCTION(DbgClearBookmarkRange)
19+
DBG_FUNCTION(DbgGetBpxTypeAt)
20+
DBG_FUNCTION(DbgValFromString)
21+
DBG_FUNCTION(DbgGetRegDump)
22+
DBG_FUNCTION(DbgValToString)
23+
DBG_FUNCTION(DbgMemIsValidReadPtr)
24+
DBG_FUNCTION(DbgGetFunctionTypeAt)
25+
DBG_FUNCTION(DbgGetLoopTypeAt)
26+
DBG_FUNCTION(DbgGetBranchDestination)
27+
DBG_FUNCTION(DbgScriptLoad)
28+
DBG_FUNCTION(DbgScriptUnload)
29+
DBG_FUNCTION(DbgScriptRun)
30+
DBG_FUNCTION(DbgScriptStep)
31+
DBG_FUNCTION(DbgScriptBpToggle)
32+
DBG_FUNCTION(DbgScriptBpGet)
33+
DBG_FUNCTION(DbgScriptCmdExec)
34+
DBG_FUNCTION(DbgScriptAbort)
35+
DBG_FUNCTION(DbgScriptGetLineType)
36+
DBG_FUNCTION(DbgScriptSetIp)
37+
DBG_FUNCTION(DbgSymbolEnum)
38+
DBG_FUNCTION(DbgAssembleAt)
39+
DBG_FUNCTION(DbgModBaseFromName)
40+
DBG_FUNCTION(DbgSettingsUpdated)
41+
DBG_FUNCTION(DbgMenuEntryClicked)
42+
DBG_FUNCTION(DbgFunctionOverlaps)
43+
DBG_FUNCTION(DbgFunctionAdd)
44+
DBG_FUNCTION(DbgFunctionDel)
45+
DBG_FUNCTION(DbgArgumentOverlaps)
46+
DBG_FUNCTION(DbgArgumentAdd)
47+
DBG_FUNCTION(DbgArgumentDel)
48+
DBG_FUNCTION(DbgLoopOverlaps)
49+
DBG_FUNCTION(DbgLoopAdd)
50+
DBG_FUNCTION(DbgLoopDel)
51+
DBG_FUNCTION(DbgXrefAdd)
52+
DBG_FUNCTION(DbgXrefDelAll)
53+
DBG_FUNCTION(DbgGetXrefCountAt)
54+
DBG_FUNCTION(DbgGetXrefTypeAt)
55+
DBG_FUNCTION(DbgIsRunLocked)
56+
DBG_FUNCTION(DbgIsBpDisabled)
57+
DBG_FUNCTION(DbgSetAutoCommentAt)
58+
DBG_FUNCTION(DbgClearAutoCommentRange)
59+
DBG_FUNCTION(DbgSetAutoLabelAt)
60+
DBG_FUNCTION(DbgClearAutoLabelRange)
61+
DBG_FUNCTION(DbgSetAutoBookmarkAt)
62+
DBG_FUNCTION(DbgClearAutoBookmarkRange)
63+
DBG_FUNCTION(DbgSetAutoFunctionAt)
64+
DBG_FUNCTION(DbgClearAutoFunctionRange)
65+
DBG_FUNCTION(DbgFunctions)
66+
DBG_FUNCTION(DbgWinEvent)
67+
DBG_FUNCTION(DbgWinEventGlobal)
68+
DBG_FUNCTION(DbgIsRunning)
69+
DBG_FUNCTION(DbgGetTimeWastedCounter)
70+
DBG_FUNCTION(DbgGetArgTypeAt)
71+
DBG_FUNCTION(DbgReleaseEncodeTypeBuffer)
72+
DBG_FUNCTION(DbgGetEncodeTypeAt)
73+
DBG_FUNCTION(DbgGetEncodeSizeAt)
74+
DBG_FUNCTION(DbgSetEncodeType)
75+
DBG_FUNCTION(DbgDelEncodeTypeRange)
76+
DBG_FUNCTION(DbgDelEncodeTypeSegment)
77+
78+
#undef DBG_FUNCTION

main.cc

Lines changed: 8 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,14 @@
11
#include <windows.h>
22
#include "pluginsdk/_plugins.h"
33

4-
#ifndef DLL_EXPORT
5-
#define DLL_EXPORT __declspec(dllexport)
6-
#endif //DLL_EXPORT
4+
extern "C" void plugsetup(PLUG_SETUPSTRUCT* setupStruct);
5+
bool chaiRun(int argc, char* argv[]);
76

8-
#define plugin_name "testplugin"
9-
#define plugin_version 1
7+
int main(int argc, char** argv) {
8+
PLUG_SETUPSTRUCT setupStruct;
9+
plugsetup(&setupStruct);
10+
char* args[2] = {"", "C:\\tools\\x64dbg\\release\\x32\\scripts\\example.chai"};
11+
chaiRun(2, args);
1012

11-
int pluginHandle;
12-
HWND hwndDlg;
13-
int hMenu;
14-
int hMenuDisasm;
15-
int hMenuDump;
16-
int hMenuStack;
17-
18-
bool exec(int argc, char* argv[]) {
19-
for(unsigned i = 1;i < argc;i++) {
20-
DbgCmdExec(argv[i]);
21-
}
22-
return true;
23-
}
24-
25-
bool printMemoryRegion(int argc, char* argv[]) {
26-
size_t length = 16;
27-
if(argc == 1)
28-
return true;
29-
if(argc > 2) {
30-
length = atoi(argv[2]);
31-
}
32-
33-
auto memPtr = DbgValFromString(argv[1]);
34-
35-
_plugin_logprintf("0x%x (%d):", memPtr, length);
36-
for(unsigned i = 0;i < length;i++) {
37-
uint8_t buf = 0;
38-
DbgMemRead(memPtr + i, &buf, 1);
39-
_plugin_logprintf("%02x ", buf);
40-
}
41-
_plugin_logprintf("\n");
42-
return true;
43-
}
44-
45-
extern "C" DLL_EXPORT bool pluginit(PLUG_INITSTRUCT* initStruct)
46-
{
47-
initStruct->pluginVersion = plugin_version;
48-
initStruct->sdkVersion = PLUG_SDKVERSION;
49-
strcpy(initStruct->pluginName, plugin_name);
50-
pluginHandle = initStruct->pluginHandle;
51-
52-
_plugin_logprintf("[TEST] pluginHandle: %d\n", pluginHandle);
53-
if(!_plugin_registercommand(pluginHandle, "printMemoryRegion", printMemoryRegion, false))
54-
_plugin_logputs("[TEST] error registering the \"printMemoryRegion\" command!");
55-
if(!_plugin_registercommand(pluginHandle, "exec", exec, false))
56-
_plugin_logputs("[TEST] error registering the \"exec\" command!");
57-
58-
return true;
59-
}
60-
61-
extern "C" DLL_EXPORT bool plugstop()
62-
{
63-
return true;
64-
}
65-
66-
extern "C" DLL_EXPORT void plugsetup(PLUG_SETUPSTRUCT* setupStruct)
67-
{
68-
hwndDlg = setupStruct->hwndDlg;
69-
hMenu = setupStruct->hMenu;
70-
hMenuDisasm = setupStruct->hMenuDisasm;
71-
hMenuDump = setupStruct->hMenuDump;
72-
hMenuStack = setupStruct->hMenuStack;
73-
}
74-
75-
extern "C" DLL_EXPORT BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
76-
{
77-
return TRUE;
13+
return 0;
7814
}

0 commit comments

Comments
 (0)