Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bind all #105

Merged
merged 13 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions bin/debug/SDK/Headers/Assertions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @file Assertions.h
* @author ddkwork
* @author Sina Karvandi ([email protected])
* @brief HyperDbg's assertions
* @details This file contains asserts and static asserts
* @version 1.0
* @date 2024-06-21
*
* @copyright This project is released under the GNU Public License v3.
*
*/
#pragma once

//////////////////////////////////////////////////
// Asserts //
//////////////////////////////////////////////////

/**
* @brief check so the DEBUGGEE_UD_PAUSED_PACKET should be smaller than packet size
*
*/
static_assert(sizeof(DEBUGGEE_UD_PAUSED_PACKET) < PacketChunkSize,
"err (static_assert), size of PacketChunkSize should be bigger than DEBUGGEE_UD_PAUSED_PACKET");

/**
* @brief check so the DEBUGGER_UPDATE_SYMBOL_TABLE should be smaller than packet size
*
*/
static_assert(sizeof(DEBUGGER_UPDATE_SYMBOL_TABLE) < PacketChunkSize,
"err (static_assert), size of PacketChunkSize should be bigger than DEBUGGER_UPDATE_SYMBOL_TABLE (MODULE_SYMBOL_DETAIL)");
3 changes: 0 additions & 3 deletions bin/debug/SDK/Headers/BasicTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
// Basic Datatypes //
//////////////////////////////////////////////////

//#include <wchar.h> // 或者 #include <cwchar>


typedef unsigned long long QWORD;
typedef unsigned __int64 UINT64, *PUINT64;
typedef unsigned long DWORD;
Expand Down
6 changes: 4 additions & 2 deletions bin/debug/SDK/Headers/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
// Version Information //
//////////////////////////////////////////////////

#define VERSION_MAJOR 0
#define VERSION_MINOR 9
#define VERSION_MAJOR 1
#define VERSION_MINOR 0
#define VERSION_PATCH 0

//
Expand Down Expand Up @@ -625,6 +625,8 @@ const unsigned char BuildSignature[] = {

#define MAX_TEMP_COUNT 128

#define MAX_STACK_BUFFER_COUNT 128

// TODO: Extract number of variables from input of ScriptEngine
// and allocate variableList Dynamically.
#define MAX_VAR_COUNT 512
Expand Down
7 changes: 0 additions & 7 deletions bin/debug/SDK/Headers/DataTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,6 @@ typedef struct _DEBUGGEE_UD_PAUSED_PACKET

} DEBUGGEE_UD_PAUSED_PACKET, *PDEBUGGEE_UD_PAUSED_PACKET;

/**
* @brief check so the DEBUGGEE_UD_PAUSED_PACKET should be smaller than packet size
*
*/
static_assert(sizeof(DEBUGGEE_UD_PAUSED_PACKET) < PacketChunkSize,
"err (static_assert), size of PacketChunkSize should be bigger than DEBUGGEE_UD_PAUSED_PACKET");

//////////////////////////////////////////////////
// Message Tracing Enums //
//////////////////////////////////////////////////
Expand Down
133 changes: 92 additions & 41 deletions bin/debug/SDK/Headers/HardwareDebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@
*/
#pragma once

//////////////////////////////////////////////////
// Definitions //
//////////////////////////////////////////////////

/**
* @brief Initial debuggee to debugger offset
*
*/
#define DEFAULT_INITIAL_DEBUGGEE_TO_DEBUGGER_OFFSET 0x200

/**
* @brief Initial debugger to debuggee offset
*
*/
#define DEFAULT_INITIAL_DEBUGGER_TO_DEBUGGEE_OFFSET 0x0

//////////////////////////////////////////////////
// Enums //
//////////////////////////////////////////////////
Expand All @@ -23,9 +39,8 @@
*/
typedef enum _HWDBG_ACTION_ENUMS
{
hwdbgActionSendVersion = 1,
hwdbgActionSendPinInformation = 2,
hwdbgActionConfigureScriptBuffer = 3,
hwdbgActionSendInstanceInfo = 1,
hwdbgActionConfigureScriptBuffer = 2,

} HWDBG_ACTION_ENUMS;

Expand All @@ -36,23 +51,22 @@ typedef enum _HWDBG_ACTION_ENUMS
*/
typedef enum _HWDBG_RESPONSE_ENUMS
{
hwdbgResponseInvalidPacketOrError = 1,
hwdbgResponseVersion = 2,
hwdbgResponsePinInformation = 3,
hwdbgResponseScriptBufferConfigurationResult = 4,
hwdbgResponseSuccessOrErrorMessage = 1,
hwdbgResponseInstanceInfo = 2,

} HWDBG_RESPONSE_ENUMS;

/**
* @brief Different error codes in hwdbg
* @brief Different success or error codes in hwdbg
* @warning This file should be changed along with hwdbg files
*
*/
typedef enum _HWDBG_ERROR_ENUMS
typedef enum _HWDBG_SUCCESS_OR_ERROR_ENUMS
{
hwdbgErrorInvalidPacket = 1,
hwdbgOperationWasSuccessful = 0x7FFFFFFF,
hwdbgErrorInvalidPacket = 1,

} HWDBG_ERROR_ENUMS;
} HWDBG_SUCCESS_OR_ERROR_ENUMS;

//////////////////////////////////////////////////
// Structures //
Expand All @@ -74,45 +88,82 @@ typedef struct _HWDBG_PORT_INFORMATION_ITEMS
*/
typedef struct _HWDBG_INSTANCE_INFORMATION
{
UINT32 Version; // Target version of HyperDbg (same as hwdbg)
UINT32 MaximumNumberOfStages; // Number of stages that this instance of hwdbg supports (NumberOfSupportedStages == 0 means script engine is disabled)
UINT32 scriptVariableLength; // maximum length of variables (and other script elements)
UINT32 maximumNumberOfSupportedScriptOperators; // maximum supported operators in a single func
UINT32 numberOfPins; // Number of pins
UINT32 numberOfPorts; // Number of ports
//
// ANY ADDITION TO THIS STRUCTURE SHOULD BE SYNCHRONIZED WITH SCALA AND INSTANCE INFO SENDER MODULE
//
UINT32 version; // Target version of HyperDbg (same as hwdbg)
UINT32 maximumNumberOfStages; // Number of stages that this instance of hwdbg supports (NumberOfSupportedStages == 0 means script engine is disabled)
UINT32 scriptVariableLength; // maximum length of variables (and other script elements)
UINT32 maximumNumberOfSupportedGetScriptOperators; // Maximum supported GET operators in a single func
UINT32 maximumNumberOfSupportedSetScriptOperators; // Maximum supported SET operators in a single func
UINT32 sharedMemorySize; // Size of shared memory
UINT32 debuggerAreaOffset; // The memory offset of debugger
UINT32 debuggeeAreaOffset; // The memory offset of debuggee
UINT32 numberOfPins; // Number of pins
UINT32 numberOfPorts; // Number of ports

//
// ANY ADDITION TO THIS STRUCTURE SHOULD BE SYNCHRONIZED WITH SCALA AND INSTANCE INFO SENDER MODULE
//

struct _HWDBG_SCRIPT_CAPABILITIES
{
UINT64 inc : 1;
UINT64 dec : 1;
UINT64 or : 1;
UINT64 xor : 1;
UINT64 and : 1;
UINT64 asr : 1;
UINT64 asl : 1;
UINT64 add : 1;
UINT64 sub : 1;
UINT64 mul : 1;
UINT64 div : 1;
UINT64 mod : 1;
UINT64 gt : 1;
UINT64 lt : 1;
UINT64 egt : 1;
UINT64 elt : 1;
UINT64 equal : 1;
UINT64 neq : 1;
UINT64 jmp : 1;
UINT64 jz : 1;
UINT64 jnz : 1;
UINT64 mov : 1;
UINT64 printf : 1;
//
// ANY ADDITION TO THIS MASK SHOULD BE ADDED TO HwdbgInterpreterShowScriptCapabilities
// and HwdbgInterpreterCheckScriptBufferWithScriptCapabilities as well Scala file
//
UINT64 func_or : 1;
UINT64 func_xor : 1;
UINT64 func_and : 1;
UINT64 func_asr : 1;
UINT64 func_asl : 1;
UINT64 func_add : 1;
UINT64 func_sub : 1;
UINT64 func_mul : 1;
UINT64 func_div : 1;
UINT64 func_mod : 1;
UINT64 func_gt : 1;
UINT64 func_lt : 1;
UINT64 func_egt : 1;
UINT64 func_elt : 1;
UINT64 func_equal : 1;
UINT64 func_neq : 1;
UINT64 func_jmp : 1;
UINT64 func_jz : 1;
UINT64 func_jnz : 1;
UINT64 func_mov : 1;
UINT64 func_printf : 1;

//
// ANY ADDITION TO THIS MASK SHOULD BE ADDED TO HwdbgInterpreterShowScriptCapabilities
// and HwdbgInterpreterCheckScriptBufferWithScriptCapabilities as well Scala file
//

} scriptCapabilities;

UINT32 bramAddrWidth; // BRAM address width
UINT32 bramDataWidth; // BRAM data width

//
// Here the details of port arrangements are located (HWDBG_PORT_INFORMATION_ITEMS)
// As the following type:
// HWDBG_PORT_INFORMATION_ITEMS portsConfiguration[numberOfPorts] ; Port arrangement
//

} HWDBG_SCRIPT_CAPABILITIES_INFORMATION, *PHWDBG_SCRIPT_CAPABILITIES_INFORMATION;
} HWDBG_INSTANCE_INFORMATION, *PHWDBG_INSTANCE_INFORMATION;

/**
* @brief The structure of script buffer in hwdbg
*
*/
typedef struct _HWDBG_SCRIPT_BUFFER
{
UINT32 scriptNumberOfSymbols; // Number of symbols in the script

//
// Here the script buffer is located
//
// UINT8 scriptBuffer[scriptNumberOfSymbols]; // The script buffer
//

} HWDBG_SCRIPT_BUFFER, *PHWDBG_SCRIPT_BUFFER;
7 changes: 0 additions & 7 deletions bin/debug/SDK/Headers/Symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@ typedef struct _DEBUGGER_UPDATE_SYMBOL_TABLE

} DEBUGGER_UPDATE_SYMBOL_TABLE, *PDEBUGGER_UPDATE_SYMBOL_TABLE;

/**
* @brief check so the DEBUGGER_UPDATE_SYMBOL_TABLE should be smaller than packet size
*
*/
static_assert(sizeof(DEBUGGER_UPDATE_SYMBOL_TABLE) < PacketChunkSize,
"err (static_assert), size of PacketChunkSize should be bigger than DEBUGGER_UPDATE_SYMBOL_TABLE (MODULE_SYMBOL_DETAIL)");

/*
==============================================================================================
*/
Expand Down
6 changes: 6 additions & 0 deletions bin/debug/SDK/HyperDbgSdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@
#include "SDK/Headers/Events.h"
#include "SDK/Headers/RequestStructures.h"
#include "SDK/Headers/Symbols.h"
#include "SDK/Headers/HardwareDebugger.h"

//
// Asserts
//
#include "SDK/Headers/Assertions.h"
50 changes: 31 additions & 19 deletions bin/debug/SDK/Imports/HyperDbgScriptImports.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,55 @@
extern "C" {
#endif

__declspec(dllimport) PSYMBOL_BUFFER ScriptEngineParse(char * str);
__declspec(dllimport) PSYMBOL_BUFFER GetStackBuffer();
__declspec(dllimport) void PrintSymbolBuffer(const PSYMBOL_BUFFER SymbolBuffer);
__declspec(dllimport) void PrintSymbol(PSYMBOL Symbol);
__declspec(dllimport) void RemoveSymbolBuffer(PSYMBOL_BUFFER SymbolBuffer);
//
// Script engine
//
__declspec(dllimport) PSYMBOL_BUFFER
ScriptEngineParse(char * str);
__declspec(dllimport) void
PrintSymbolBuffer(const PSYMBOL_BUFFER SymbolBuffer);
__declspec(dllimport) void
PrintSymbol(PSYMBOL Symbol);
__declspec(dllimport) void
RemoveSymbolBuffer(PSYMBOL_BUFFER SymbolBuffer);
__declspec(dllimport) BOOLEAN
FuncGetNumberOfOperands(UINT64 FuncType, UINT32 * NumberOfGetOperands, UINT32 * NumberOfSetOperands);
__declspec(dllimport) BOOLEAN
ScriptEngineSetHwdbgInstanceInfo(HWDBG_INSTANCE_INFORMATION * InstancInfo);

;

//
// pdb parser
//
__declspec(dllimport) VOID
ScriptEngineSetTextMessageCallback(PVOID Handler);
ScriptEngineSetTextMessageCallback(PVOID Handler);
__declspec(dllimport) VOID
ScriptEngineSymbolAbortLoading();
ScriptEngineSymbolAbortLoading();
__declspec(dllimport) UINT64
ScriptEngineConvertNameToAddress(const char * FunctionOrVariableName, PBOOLEAN WasFound);
ScriptEngineConvertNameToAddress(const char * FunctionOrVariableName, PBOOLEAN WasFound);
__declspec(dllimport) UINT32
ScriptEngineLoadFileSymbol(UINT64 BaseAddress, const char * PdbFileName, const char * CustomModuleName);
ScriptEngineLoadFileSymbol(UINT64 BaseAddress, const char * PdbFileName, const char * CustomModuleName);
__declspec(dllimport) UINT32
ScriptEngineUnloadAllSymbols();
ScriptEngineUnloadAllSymbols();
__declspec(dllimport) UINT32
ScriptEngineUnloadModuleSymbol(char * ModuleName);
ScriptEngineUnloadModuleSymbol(char * ModuleName);
__declspec(dllimport) UINT32
ScriptEngineSearchSymbolForMask(const char * SearchMask);
ScriptEngineSearchSymbolForMask(const char * SearchMask);
__declspec(dllimport) BOOLEAN
ScriptEngineGetFieldOffset(CHAR * TypeName, CHAR * FieldName, UINT32 * FieldOffset);
ScriptEngineGetFieldOffset(CHAR * TypeName, CHAR * FieldName, UINT32 * FieldOffset);
__declspec(dllimport) BOOLEAN
ScriptEngineGetDataTypeSize(CHAR * TypeName, UINT64 * TypeSize);
ScriptEngineGetDataTypeSize(CHAR * TypeName, UINT64 * TypeSize);
__declspec(dllimport) BOOLEAN
ScriptEngineCreateSymbolTableForDisassembler(void * CallbackFunction);
ScriptEngineCreateSymbolTableForDisassembler(void * CallbackFunction);
__declspec(dllimport) BOOLEAN
ScriptEngineConvertFileToPdbPath(const char * LocalFilePath, char * ResultPath);
ScriptEngineConvertFileToPdbPath(const char * LocalFilePath, char * ResultPath);
__declspec(dllimport) BOOLEAN
ScriptEngineConvertFileToPdbFileAndGuidAndAgeDetails(const char * LocalFilePath, char * PdbFilePath, char * GuidAndAgeDetails, BOOLEAN Is32BitModule);
ScriptEngineConvertFileToPdbFileAndGuidAndAgeDetails(const char * LocalFilePath, char * PdbFilePath, char * GuidAndAgeDetails, BOOLEAN Is32BitModule);
__declspec(dllimport) BOOLEAN
ScriptEngineSymbolInitLoad(PVOID BufferToStoreDetails, UINT32 StoredLength, BOOLEAN DownloadIfAvailable, const char * SymbolPath, BOOLEAN IsSilentLoad);
ScriptEngineSymbolInitLoad(PVOID BufferToStoreDetails, UINT32 StoredLength, BOOLEAN DownloadIfAvailable, const char * SymbolPath, BOOLEAN IsSilentLoad);
__declspec(dllimport) BOOLEAN
ScriptEngineShowDataBasedOnSymbolTypes(const char * TypeName, UINT64 Address, BOOLEAN IsStruct, PVOID BufferAddress, const char * AdditionalParameters);
ScriptEngineShowDataBasedOnSymbolTypes(const char * TypeName, UINT64 Address, BOOLEAN IsStruct, PVOID BufferAddress, const char * AdditionalParameters);

#ifdef __cplusplus
}
Expand Down
Binary file removed bin/debug/SDK/Libraries/HPRDBGCTRL.dll
Binary file not shown.
Binary file removed bin/debug/SDK/Libraries/hprdbghv.dll
Binary file not shown.
Binary file removed bin/debug/SDK/Libraries/hprdbgrev.dll
Binary file not shown.
Binary file removed bin/debug/SDK/Libraries/hyperlog.dll
Binary file not shown.
Binary file removed bin/debug/SDK/Libraries/kdserial.dll
Binary file not shown.
Binary file removed bin/debug/SDK/Libraries/pdbex.dll
Binary file not shown.
Binary file removed bin/debug/SDK/Libraries/script-engine.dll
Binary file not shown.
Binary file removed bin/debug/SDK/Libraries/symbol-parser.dll
Binary file not shown.
Loading
Loading