Skip to content

Commit

Permalink
Merge ca52497 into caa578a
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexodia committed Mar 7, 2024
2 parents caa578a + ca52497 commit 8912405
Show file tree
Hide file tree
Showing 30 changed files with 1,154 additions and 639 deletions.
12 changes: 6 additions & 6 deletions src/bridge/bridgemain.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#ifndef _BRIDGEMAIN_H_
#define _BRIDGEMAIN_H_

#include <windows.h>
#include <Windows.h>

#ifndef __cplusplus
#include <stdbool.h>
#define DEFAULT_PARAM(name, value) name
#else
#define DEFAULT_PARAM(name, value) name = value
#endif
#endif // __cplusplus

//default structure alignments forced
#ifdef _WIN64
Expand Down Expand Up @@ -36,7 +36,7 @@ typedef signed long dsint;
#ifdef __cplusplus
extern "C"
{
#endif
#endif // __cplusplus

//Bridge defines
#define MAX_SETTING_SIZE 65536
Expand Down Expand Up @@ -147,7 +147,7 @@ BRIDGE_IMPEXP const wchar_t* BridgeUserDirectory();

#ifdef __cplusplus
}
#endif
#endif // __cplusplus

//list structure (and C++ wrapper)
#include "bridgelist.h"
Expand All @@ -157,7 +157,7 @@ BRIDGE_IMPEXP const wchar_t* BridgeUserDirectory();
#ifdef __cplusplus
extern "C"
{
#endif
#endif // __cplusplus

//Debugger defines
#define MAX_LABEL_SIZE 256
Expand Down Expand Up @@ -1477,7 +1477,7 @@ BRIDGE_IMPEXP DWORD GuiGetMainThreadId();

#ifdef __cplusplus
}
#endif
#endif // __cplusplus

// Some useful C++ wrapper classes
#ifdef __cplusplus
Expand Down
7 changes: 7 additions & 0 deletions src/dbg/_apichecker.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// HACK: pretend we are in the same environment as a plugin
//#define PLUG_IMPEXP
#ifdef BUILD_DBG
#undef BUILD_DBG
#endif // BUILD_DBG

#include "_plugins.h"
46 changes: 46 additions & 0 deletions src/dbg/_dbgfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,4 +576,50 @@ void dbgfunctionsinit()
_dbgfunctions.GetAddrFromLineEx = _getaddrfromlineex;
_dbgfunctions.ModSymbolStatus = _modsymbolstatus;
_dbgfunctions.GetCallStackByThread = _getcallstackbythread;

// New breakpoint API
_dbgfunctions.BpRefList = [](duint * count)
{
auto refs = BpRefList();
*count = refs.size();
auto result = (BP_REF*)BridgeAlloc(refs.size() * sizeof(BP_REF));
memcpy(result, refs.data(), refs.size() * sizeof(BP_REF));
return result;
};
_dbgfunctions.BpRefVa = [](BP_REF * ref, BPXTYPE type, duint va)
{
return BpRefVa(*ref, type, va);
};
_dbgfunctions.BpRefRva = [](BP_REF * ref, BPXTYPE type, const char* module, duint rva)
{
return BpRefRva(*ref, type, module, rva);
};
_dbgfunctions.BpRefDll = [](BP_REF * ref, const char* module)
{
BpRefDll(*ref, module);
};
_dbgfunctions.BpRefException = [](BP_REF * ref, unsigned int code)
{
BpRefException(*ref, code);
};
_dbgfunctions.BpRefExists = [](const BP_REF * ref)
{
return BpRefExists(*ref);
};
_dbgfunctions.BpGetFieldNumber = [](const BP_REF * ref, BP_FIELD field, duint * value)
{
return BpGetFieldNumber(*ref, field, *value);
};
_dbgfunctions.BpSetFieldNumber = [](const BP_REF * ref, BP_FIELD field, duint value)
{
return BpSetFieldNumber(*ref, field, value);
};
_dbgfunctions.BpGetFieldText = [](const BP_REF * ref, BP_FIELD field, CBSTRING callback, void* userdata)
{
return BpGetFieldText(*ref, field, callback, userdata);
};
_dbgfunctions.BpSetFieldText = [](const BP_REF * ref, BP_FIELD field, const char* value)
{
return BpSetFieldText(*ref, field, value);
};
}
101 changes: 101 additions & 0 deletions src/dbg/_dbgfunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#ifndef __cplusplus
#include <stdbool.h>
#else
#include <string>
#endif

typedef struct
Expand Down Expand Up @@ -136,6 +138,60 @@ typedef enum
MODSYMLOADED
} MODULESYMBOLSTATUS;

typedef enum
{
bpf_type, // number (read-only, BPXTYPE)
bpf_offset, // number (read-only)
bpf_address, // number (read-only)
bpf_enabled, // number (bool)
bpf_singleshoot, // number (bool)
bpf_active, // number (read-only)
bpf_silent, // number (bool)
bpf_typeex, // number (read-only, BPHWTYPE/BPMEMTYPE/BPDLLTYPE/BPEXTYPE)
bpf_hwsize, // number (read-only, BPHWSIZE)
bpf_hwslot, // number (read-only)
bpf_oldbytes, // number (read-only, uint16_t)
bpf_fastresume, // number (bool)
bpf_hitcount, // number
bpf_module, // text (read-only)
bpf_name, // text
bpf_breakcondition, // text
bpf_logtext, // text
bpf_logcondition, // text
bpf_commandtext, // text
bpf_commandcondition, // text
bpf_logfile, // text
} BP_FIELD;

// An instance of this structure represents a reference to a breakpoint.
// Use DbgFunctions()->BpRefXxx() list/create references.
// Use DbgFunctions()->BpXxx() to manipulate breakpoints with the references.
typedef struct
{
BPXTYPE type;
duint module;
duint offset;

// C++ helper functions
#ifdef __cplusplus
bool GetField(BP_FIELD field, duint & value);
bool GetField(BP_FIELD field, bool & value);
bool SetField(BP_FIELD field, duint value);
bool GetField(BP_FIELD field, std::string & value);
bool SetField(BP_FIELD field, const std::string & value);

template<class T, typename = typename std::enable_if< std::is_enum<T>::value, T >::type>
void GetField(BP_FIELD field, T & value)
{
duint n = 0;
getField(field, n);
value = (T)n;
}
#endif // __cplusplus
} BP_REF;

typedef void(*CBSTRING)(const char* str, void* userdata);

typedef bool (*ASSEMBLEATEX)(duint addr, const char* instruction, char* error, bool fillnop);
typedef bool (*SECTIONFROMADDR)(duint addr, char* section);
typedef bool (*MODNAMEFROMADDR)(duint addr, char* modname, bool extension);
Expand Down Expand Up @@ -287,8 +343,53 @@ typedef struct DBGFUNCTIONS_
GETADDRFROMLINEEX GetAddrFromLineEx;
MODSYMBOLSTATUS ModSymbolStatus;
GETCALLSTACKBYTHREAD GetCallStackByThread;
// New Breakpoint API
BP_REF* (*BpRefList)(duint* count);
bool (*BpRefVa)(BP_REF* ref, BPXTYPE type, duint va);
bool (*BpRefRva)(BP_REF* ref, BPXTYPE type, const char* module, duint rva);
void (*BpRefDll)(BP_REF* ref, const char* module);
void (*BpRefException)(BP_REF* ref, unsigned int code);
bool (*BpRefExists)(const BP_REF* ref);
bool (*BpGetFieldNumber)(const BP_REF* ref, BP_FIELD field, duint* value);
bool (*BpSetFieldNumber)(const BP_REF* ref, BP_FIELD field, duint value);
bool (*BpGetFieldText)(const BP_REF* ref, BP_FIELD field, CBSTRING callback, void* userdata);
bool (*BpSetFieldText)(const BP_REF* ref, BP_FIELD field, const char* value);
} DBGFUNCTIONS;

#ifdef __cplusplus
inline bool BP_REF::GetField(BP_FIELD field, duint & value)
{
return DbgFunctions()->BpGetFieldNumber(this, field, &value);
}

inline bool BP_REF::GetField(BP_FIELD field, bool & value)
{
duint n = 0;
if(!DbgFunctions()->BpGetFieldNumber(this, field, &n))
return false;
value = !!n;
return true;
}

inline bool BP_REF::SetField(BP_FIELD field, duint value)
{
return DbgFunctions()->BpSetFieldNumber(this, field, value);
}

inline bool BP_REF::GetField(BP_FIELD field, std::string & value)
{
return DbgFunctions()->BpGetFieldText(this, field, [](const char* str, void* userdata)
{
*(std::string*)userdata = str;
}, &value);
}

inline bool BP_REF::SetField(BP_FIELD field, const std::string & value)
{
return DbgFunctions()->BpSetFieldText(this, field, value.c_str());
}
#endif // __cplusplus

#ifdef BUILD_DBG

const DBGFUNCTIONS* dbgfunctionsget();
Expand Down
10 changes: 5 additions & 5 deletions src/dbg/_exports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ static bool getAutoComment(duint addr, String & comment)
if(!temp_string.empty())
temp_string += ", ";
};
if(*bp.breakCondition)
if(!bp.breakCondition.empty())
{
next();
temp_string += GuiTranslateText(QT_TRANSLATE_NOOP("DBG", "breakif"));
Expand All @@ -472,10 +472,10 @@ static bool getAutoComment(duint addr, String & comment)
}
else //fast resume skips all other steps
{
if(*bp.logText)
if(!bp.logText.empty())
{
next();
if(*bp.logCondition)
if(!bp.logCondition.empty())
{
temp_string += GuiTranslateText(QT_TRANSLATE_NOOP("DBG", "logif"));
temp_string += "(";
Expand All @@ -491,10 +491,10 @@ static bool getAutoComment(duint addr, String & comment)
temp_string += ")";
}

if(*bp.commandText)
if(!bp.commandText.empty())
{
next();
if(*bp.commandCondition)
if(!bp.commandCondition.empty())
{
temp_string += GuiTranslateText(QT_TRANSLATE_NOOP("DBG", "cmdif"));
temp_string += "(";
Expand Down
1 change: 0 additions & 1 deletion src/dbg/_global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
\brief Implements the global class.
*/

#include <windows.h>
#include "_global.h"
#include <objbase.h>
#include <shlobj.h>
Expand Down
4 changes: 3 additions & 1 deletion src/dbg/_plugin_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@

#else

#include <Windows.h>

#ifdef __GNUC__
#include "dbghelp/dbghelp.h"
#else
#pragma warning(push)
#pragma warning(disable:4091)
#include <dbghelp.h>
#include <DbgHelp.h>
#pragma warning(pop)
#endif // __GNUC__

Expand Down
2 changes: 1 addition & 1 deletion src/dbg/_plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ bool _plugin_registerexprfunction(int pluginHandle, const char* name, int argc,
return pluginexprfuncregister(pluginHandle, name, argc, cbFunction, userdata);
}

bool _plugin_registerexprfunctionex(int pluginHandle, const char* name, const ValueType & returnType, const ValueType* argTypes, size_t argCount, CBPLUGINEXPRFUNCTIONEX cbFunction, void* userdata)
bool _plugin_registerexprfunctionex(int pluginHandle, const char* name, ValueType returnType, const ValueType* argTypes, size_t argCount, CBPLUGINEXPRFUNCTIONEX cbFunction, void* userdata)
{
return pluginexprfuncregisterex(pluginHandle, name, returnType, argTypes, argCount, cbFunction, userdata);
}
Expand Down
2 changes: 1 addition & 1 deletion src/dbg/_plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ PLUG_IMPEXP bool _plugin_menuentryremove(int pluginHandle, int hEntry);
PLUG_IMPEXP void _plugin_startscript(CBPLUGINSCRIPT cbScript);
PLUG_IMPEXP bool _plugin_waituntilpaused();
PLUG_IMPEXP bool _plugin_registerexprfunction(int pluginHandle, const char* name, int argc, CBPLUGINEXPRFUNCTION cbFunction, void* userdata);
PLUG_IMPEXP bool _plugin_registerexprfunctionex(int pluginHandle, const char* name, const ValueType & returnType, const ValueType* argTypes, size_t argCount, CBPLUGINEXPRFUNCTIONEX cbFunction, void* userdata);
PLUG_IMPEXP bool _plugin_registerexprfunctionex(int pluginHandle, const char* name, ValueType returnType, const ValueType* argTypes, size_t argCount, CBPLUGINEXPRFUNCTIONEX cbFunction, void* userdata);
PLUG_IMPEXP bool _plugin_unregisterexprfunction(int pluginHandle, const char* name);
PLUG_IMPEXP bool _plugin_unload(const char* pluginName);
PLUG_IMPEXP bool _plugin_load(const char* pluginName);
Expand Down

0 comments on commit 8912405

Please sign in to comment.