47{
54 UINT32 ActionBreakToDebuggerLength = 0;
55 UINT32 ActionCustomCodeLength = 0;
56 UINT32 ActionScriptLength = 0;
57 UINT32 NumberOfStagesForScript = 0;
58 UINT32 NumberOfOperandsForScript = 0;
59 size_t NewCompressedBufferSize = 0;
60 size_t NumberOfNeededFlipFlopsInTargetDevice = 0;
61 size_t NumberOfBytesPerChunk = 0;
62 vector<string> SplitCommandCaseSensitive {
Split(Command,
' ')};
65
66 if (SplitCommand.size() >= 2 && !SplitCommand.at(1).compare("test"))
67 {
68 TCHAR TestFilePath[MAX_PATH] = {0};
69 const SIZE_T BufferSize = 256;
71 UINT32 MemoryBuffer[BufferSize];
72
75 {
76
77
78
79 for (SIZE_T I = 0; I < BufferSize; ++I)
80 {
83 }
84 }
85
86
87
88
90 {
91 ShowMessages(
"instance info interpreted successfully\n");
92
104
105
106
107
109
112
115
117 {
118 ShowMessages(
"Port number %d ($hw_port%d): 0x%x\n", PortNum, PortNum, item);
119 PortNum++;
120 }
121 }
122 else
123 {
124 ShowMessages(
"err, unable to interpret instance info packet of the debuggee");
125 return;
126 }
127
128
129
130
131
133 &SplitCommand,
134 &SplitCommandCaseSensitive,
136 &Event,
137 &EventLength,
138 &ActionBreakToDebugger,
139 &ActionBreakToDebuggerLength,
140 &ActionCustomCode,
141 &ActionCustomCodeLength,
142 &ActionScript,
143 &ActionScriptLength,
144 &EventParsingErrorCause))
145 {
146 return;
147 }
148
149
150
151
152 ShowMessages(
"\nHyperDbg (general) script buffer (size=%d, flip-flops (just script)=%d):\n\n",
155 );
156
158
160 {
162 }
163
165
166
167
168
170 ScriptBuffer,
172 &NumberOfStagesForScript,
173 &NumberOfOperandsForScript))
174 {
175 ShowMessages(
"\n[+] target script is supported by this instance of hwdbg!\n");
176
177
178
179
181 {
182
183
184
186 {
187
188
189
190
191
192
193
197 NumberOfStagesForScript,
198 &NewScriptBuffer,
199 &NewCompressedBufferSize) ==
TRUE &&
200
201
202
203
204
206 NewCompressedBufferSize,
209 &NewCompressedBufferSize,
210 &NumberOfBytesPerChunk) ==
TRUE)
211 {
212 ShowMessages(
"\n---------------------------------------------------------\n");
213
215
216
217
218
219
220
226 (NumberOfStagesForScript) +
228
229 ShowMessages(
"hwdbg script buffer (buffer size=%d, stages=%d, operands needed: %d - operands used: %d (%.2f%%), total used flip-flops=%d, number of bytes per chunk: %d):\n\n",
230 NewCompressedBufferSize,
231 NumberOfStagesForScript,
232 NumberOfOperandsImplemented,
233 NumberOfOperandsForScript,
234 ((float)NumberOfOperandsForScript / (float)NumberOfOperandsImplemented) * 100,
235 NumberOfNeededFlipFlopsInTargetDevice,
236 NumberOfBytesPerChunk);
237
238 for (size_t i = 0; i < NewCompressedBufferSize; i++)
239 {
241 }
242
243 ShowMessages(
"\n\nwriting script configuration packet into the file\n");
244
245
246
247
250 TestFilePath,
251 NumberOfStagesForScript + NumberOfOperandsImplemented - 1,
252 NewScriptBuffer,
253 (
UINT32)NewCompressedBufferSize))
254 {
255 ShowMessages(
"\n[*] script buffer successfully written into file: %s\n", TestFilePath);
256 }
257 else
258 {
260 }
261
262
263
264
268 TestFilePath,
271 NULL,
273 {
274 ShowMessages(
"[*] instance info successfully written into file: %s\n", TestFilePath);
275 }
276 }
277 }
278 else
279 {
280
281
282
283 ShowMessages(
"err, the script variable length should be at least 8 bits (1 byte)\n");
284 }
285 }
286 }
287 else
288 {
289 ShowMessages(
"\n[-] target script is NOT supported by this instance of hwdbg!\n");
290 }
291
292
293
294
295 if (NewScriptBuffer != NULL)
296 {
297 free(NewScriptBuffer);
298 }
300 }
301 else
302 {
303 ShowMessages(
"incorrect use of the '%s'\n\n", SplitCommand.at(0).c_str());
305 return;
306 }
307}
#define NULL_ZERO
Definition BasicTypes.h:51
unsigned char BYTE
Definition BasicTypes.h:24
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
unsigned __int64 UINT64
Definition BasicTypes.h:21
unsigned char UINT8
Definition BasicTypes.h:46
unsigned int UINT32
Definition BasicTypes.h:48
char CHAR
Definition BasicTypes.h:31
@ DEBUGGER_REMOTE_PACKET_TYPE_DEBUGGER_TO_DEBUGGEE_HARDWARE_LEVEL
Definition Connection.h:169
@ hwdbgActionSendInstanceInfo
Definition HardwareDebugger.h:42
struct HWDBG_SHORT_SYMBOL HWDBG_SHORT_SYMBOL
const vector< string > Split(const string &s, const char &c)
general split command
Definition common.cpp:117
UINT32 Log2Ceil(UINT32 n)
Function to compute log2Ceil.
Definition common.cpp:1216
VOID FreeEventsAndActionsMemory(PDEBUGGER_GENERAL_EVENT_DETAIL Event, PDEBUGGER_GENERAL_ACTION ActionBreakToDebugger, PDEBUGGER_GENERAL_ACTION ActionCustomCode, PDEBUGGER_GENERAL_ACTION ActionScript)
Deallocate buffers relating to events and actions.
Definition debugger.cpp:2292
BOOLEAN InterpretGeneralEventAndActionsFields(vector< string > *SplitCommand, vector< string > *SplitCommandCaseSensitive, VMM_EVENT_TYPE_ENUM EventType, PDEBUGGER_GENERAL_EVENT_DETAIL *EventDetailsToFill, PUINT32 EventBufferLength, PDEBUGGER_GENERAL_ACTION *ActionDetailsToFillBreakToDebugger, PUINT32 ActionBufferLengthBreakToDebugger, PDEBUGGER_GENERAL_ACTION *ActionDetailsToFillCustomCode, PUINT32 ActionBufferLengthCustomCode, PDEBUGGER_GENERAL_ACTION *ActionDetailsToFillScript, PUINT32 ActionBufferLengthScript, PDEBUGGER_EVENT_PARSING_ERROR_CAUSE ReasonForErrorInParsing)
Interpret general event fields.
Definition debugger.cpp:2342
VOID CommandHwClkHelp()
help of the !hw_clk command
Definition hw_clk.cpp:28
std::vector< UINT32 > g_HwdbgPortConfiguration
Ports configuration of hwdbg.
Definition globals.h:693
HWDBG_INSTANCE_INFORMATION g_HwdbgInstanceInfo
Instance information of the current hwdbg debuggee.
Definition globals.h:681
BOOLEAN g_HwdbgInstanceInfoIsValid
Shows whether the instance info is valid (received) or not.
Definition globals.h:687
BOOLEAN HwdbgInterpreterFillMemoryFromFile(const TCHAR *FileName, UINT32 *MemoryBuffer, size_t BufferSize)
Function to read the file and fill the memory buffer.
Definition hwdbg-interpreter.cpp:577
BOOLEAN HwdbgInterpreterConvertSymbolToHwdbgShortSymbolBuffer(HWDBG_INSTANCE_INFORMATION *InstanceInfo, SYMBOL *SymbolBuffer, size_t SymbolBufferLength, UINT32 NumberOfStages, HWDBG_SHORT_SYMBOL **NewShortSymbolBuffer, size_t *NewBufferSize)
Function to compress the buffer.
Definition hwdbg-interpreter.cpp:806
BOOLEAN HwdbgInterpreterSendScriptPacket(HWDBG_INSTANCE_INFORMATION *InstanceInfo, const TCHAR *FileName, UINT32 NumberOfSymbols, HWDBG_SHORT_SYMBOL *Buffer, UINT32 BufferLength)
Sends a HyperDbg script packet to the hwdbg.
Definition hwdbg-interpreter.cpp:1131
VOID HwdbgInterpreterShowScriptCapabilities(HWDBG_INSTANCE_INFORMATION *InstanceInfo)
Shows the script capablities of the target debuggee.
Definition hwdbg-interpreter.cpp:179
BOOLEAN HwdbgInterpreterCheckScriptBufferWithScriptCapabilities(HWDBG_INSTANCE_INFORMATION *InstanceInfo, PVOID ScriptBuffer, UINT32 CountOfScriptSymbolChunks, UINT32 *NumberOfStages, UINT32 *NumberOfOperands)
Check the script capablities with the target script buffer.
Definition hwdbg-interpreter.cpp:238
BOOLEAN HwdbgInterpreterCompressBuffer(UINT64 *Buffer, size_t BufferLength, UINT32 ScriptVariableLength, UINT32 BramDataWidth, size_t *NewBufferSize, size_t *NumberOfBytesPerChunk)
Function to compress the buffer.
Definition hwdbg-interpreter.cpp:724
BOOLEAN HwdbgInterpretPacket(PVOID BufferReceived, UINT32 LengthReceived)
Interpret packets of hwdbg.
Definition hwdbg-interpreter.cpp:30
BOOLEAN HwdbgInterpreterSendPacketAndBufferToHwdbg(HWDBG_INSTANCE_INFORMATION *InstanceInfo, const TCHAR *FileName, DEBUGGER_REMOTE_PACKET_TYPE PacketType, HWDBG_ACTION_ENUMS RequestedAction, CHAR *Buffer, UINT32 BufferLength)
Sends a HyperDbg packet + a buffer to the hwdbg.
Definition hwdbg-interpreter.cpp:994
#define HWDBG_TEST_WRITE_SCRIPT_BUFFER_PATH
Path to write the sample of the script buffer.
Definition hwdbg-interpreter.h:28
#define HWDBG_TEST_READ_INSTANCE_INFO_PATH
Path to read the sample of the instance info.
Definition hwdbg-interpreter.h:22
#define HWDBG_TEST_WRITE_INSTANCE_INFO_PATH
Path to write the sample of the instance info requests.
Definition hwdbg-interpreter.h:34
BOOLEAN SetupPathForFileName(const CHAR *FileName, _Inout_updates_bytes_all_(BufferLength) PCHAR FileLocation, ULONG BufferLength, BOOLEAN CheckFileExists)
Setup file name.
Definition install.cpp:440
VOID ShowMessages(const char *Fmt,...)
Show messages.
Definition libhyperdbg.cpp:96
NULL()
Definition test-case-generator.py:530
Each event can have multiple actions.
Definition Events.h:406
UINT32 ScriptBufferSize
Definition Events.h:413
Each command is like the following struct, it also used for tracing works in user mode and sending it...
Definition Events.h:350
UINT32 version
Definition HardwareDebugger.h:95
UINT32 sharedMemorySize
Definition HardwareDebugger.h:102
UINT32 maximumNumberOfSupportedGetScriptOperators
Definition HardwareDebugger.h:100
UINT32 debuggeeAreaOffset
Definition HardwareDebugger.h:104
UINT32 numberOfSupportedLocalAndGlobalVariables
Definition HardwareDebugger.h:98
UINT32 debuggerAreaOffset
Definition HardwareDebugger.h:103
struct _HWDBG_INSTANCE_INFORMATION::_HWDBG_SCRIPT_CAPABILITIES scriptCapabilities
UINT32 maximumNumberOfStages
Definition HardwareDebugger.h:96
UINT32 numberOfSupportedTemporaryVariables
Definition HardwareDebugger.h:99
UINT32 numberOfPorts
Definition HardwareDebugger.h:106
UINT32 bramAddrWidth
Definition HardwareDebugger.h:152
UINT32 maximumNumberOfSupportedSetScriptOperators
Definition HardwareDebugger.h:101
UINT32 bramDataWidth
Definition HardwareDebugger.h:153
UINT32 numberOfPins
Definition HardwareDebugger.h:105
UINT32 scriptVariableLength
Definition HardwareDebugger.h:97
Definition ScriptEngineCommonDefinitions.h:15
Definition ScriptEngineCommonDefinitions.h:6