HyperDbg Debugger
Loading...
Searching...
No Matches
settings.cpp File Reference

settings command More...

#include "pch.h"

Functions

VOID CommandSettingsHelp ()
 help of the settings command
BOOLEAN CommandSettingsGetValueFromConfigFile (std::string OptionName, std::string &OptionValue)
 Gets the setting values from config file.
VOID CommandSettingsSetValueFromConfigFile (std::string OptionName, std::string OptionValue)
 Sets the setting values from config file.
VOID CommandSettingsLoadDefaultValuesFromConfigFile ()
 Loads default settings values from config file.
VOID CommandSettingsAddressConversion (vector< CommandToken > CommandTokens)
 set the address conversion enabled and disabled and query the status of this mode
VOID CommandSettingsAutoFlush (vector< CommandToken > CommandTokens)
 set the auto-flush mode to enabled and disabled and query the status of this mode
VOID CommandSettingsAutoUpause (vector< CommandToken > CommandTokens)
 set auto-unpause mode to enabled or disabled
VOID CommandSettingsSyntax (vector< CommandToken > CommandTokens)
 set the syntax of !u !u2 u u2 command
VOID CommandSettings (vector< CommandToken > CommandTokens, string Command)
 settings command handler

Variables

BOOLEAN g_AutoUnpause
 Whether auto-unpause mode is enabled or not enabled.
BOOLEAN g_AutoFlush
 Whether auto-flush mode is enabled or not enabled.
BOOLEAN g_AddressConversion
 Whether converting addresses to object names or not.
BOOLEAN g_IsConnectedToRemoteDebuggee
 Shows whether the current debugger is the host and connected to a remote debuggee (guest).
UINT32 g_DisassemblerSyntax
 Shows the syntax used in !u !u2 u u2 commands.

Detailed Description

settings command

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.1
Date
2020-08-18

Function Documentation

◆ CommandSettings()

VOID CommandSettings ( vector< CommandToken > CommandTokens,
string Command )

settings command handler

Parameters
CommandTokens
Command
Returns
VOID
554{
555 if (CommandTokens.size() <= 1)
556 {
557 ShowMessages("incorrect use of the '%s'\n\n",
558 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
560 return;
561 }
562
563 //
564 // Interpret the field name
565 //
566 if (CompareLowerCaseStrings(CommandTokens.at(1), "autounpause"))
567 {
568 //
569 // Handle it locally
570 //
571 CommandSettingsAutoUpause(CommandTokens);
572 }
573 else if (CompareLowerCaseStrings(CommandTokens.at(1), "syntax"))
574 {
575 //
576 // If it's a remote debugger then we send it to the remote debugger
577 //
579 {
580 RemoteConnectionSendCommand(Command.c_str(), (UINT32)Command.length() + 1);
581 }
582 else
583 {
584 //
585 // If it's a connection over serial or a local debugging then
586 // we handle it locally
587 //
588 CommandSettingsSyntax(CommandTokens);
589 }
590 }
591 else if (CompareLowerCaseStrings(CommandTokens.at(1), "autoflush"))
592 {
593 //
594 // If it's a remote debugger then we send it to the remote debugger
595 //
597 {
598 RemoteConnectionSendCommand(Command.c_str(), (UINT32)Command.length() + 1);
599 }
600 else
601 {
602 //
603 // If it's a connection over serial or a local debugging then
604 // we handle it locally
605 //
606 CommandSettingsAutoFlush(CommandTokens);
607 }
608 }
609 else if (CompareLowerCaseStrings(CommandTokens.at(1), "addressconversion"))
610 {
611 //
612 // If it's a remote debugger then we send it to the remote debugger
613 //
615 {
616 RemoteConnectionSendCommand(Command.c_str(), (UINT32)Command.length() + 1);
617 }
618 else
619 {
620 //
621 // If it's a connection over serial or a local debugging then
622 // we handle it locally
623 //
625 }
626 }
627 else
628 {
629 //
630 // option not found
631 //
632 ShowMessages("incorrect use of the '%s', please use 'help %s' for more information\n",
633 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str(),
634 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
635 return;
636 }
637}
unsigned int UINT32
Definition BasicTypes.h:54
std::string GetCaseSensitiveStringFromCommandToken(CommandToken TargetToken)
Get case sensitive string from command token.
Definition common.cpp:467
BOOLEAN CompareLowerCaseStrings(CommandToken TargetToken, const CHAR *StringToCompare)
Compare lower case strings.
Definition common.cpp:503
BOOLEAN g_IsConnectedToRemoteDebuggee
Shows whether the current debugger is the host and connected to a remote debuggee (guest).
Definition globals.h:96
INT RemoteConnectionSendCommand(const CHAR *sendbuf, INT len)
send the command as a client (debugger, host) to the server (debuggee, guest)
Definition remote-connection.cpp:445
VOID CommandSettingsSyntax(vector< CommandToken > CommandTokens)
set the syntax of !u !u2 u u2 command
Definition settings.cpp:471
VOID CommandSettingsAddressConversion(vector< CommandToken > CommandTokens)
set the address conversion enabled and disabled and query the status of this mode
Definition settings.cpp:274
VOID CommandSettingsAutoUpause(vector< CommandToken > CommandTokens)
set auto-unpause mode to enabled or disabled
Definition settings.cpp:406
VOID CommandSettingsHelp()
help of the settings command
Definition settings.cpp:29
VOID CommandSettingsAutoFlush(vector< CommandToken > CommandTokens)
set the auto-flush mode to enabled and disabled and query the status of this mode
Definition settings.cpp:341

◆ CommandSettingsAddressConversion()

VOID CommandSettingsAddressConversion ( vector< CommandToken > CommandTokens)

set the address conversion enabled and disabled and query the status of this mode

Parameters
CommandTokens
Returns
VOID
275{
276 if (CommandTokens.size() == 2)
277 {
278 //
279 // It's a query
280 //
282 {
283 ShowMessages("address conversion is enabled\n");
284 }
285 else
286 {
287 ShowMessages("address conversion is disabled\n");
288 }
289 }
290 else if (CommandTokens.size() == 3)
291 {
292 //
293 // The user tries to set a value as the autoflush
294 //
295 if (CompareLowerCaseStrings(CommandTokens.at(2), "on"))
296 {
299
300 ShowMessages("set address conversion to enabled\n");
301 }
302 else if (CompareLowerCaseStrings(CommandTokens.at(2), "off"))
303 {
305 CommandSettingsSetValueFromConfigFile("AddrConv", "off");
306
307 ShowMessages("set address conversion to disabled\n");
308 }
309 else
310 {
311 //
312 // Sth is incorrect
313 //
314 ShowMessages("incorrect use of the '%s', please use 'help %s' for more information\n",
315 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str(),
316 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
317
318 return;
319 }
320 }
321 else
322 {
323 //
324 // Sth is incorrect
325 //
326 ShowMessages("incorrect use of the '%s', please use 'help %s' for more information\n",
327 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str(),
328 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
329 return;
330 }
331}
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113
VOID CommandSettingsSetValueFromConfigFile(std::string OptionName, std::string OptionValue)
Sets the setting values from config file.
Definition settings.cpp:115
BOOLEAN g_AddressConversion
Whether converting addresses to object names or not.
Definition globals.h:594

◆ CommandSettingsAutoFlush()

VOID CommandSettingsAutoFlush ( vector< CommandToken > CommandTokens)

set the auto-flush mode to enabled and disabled and query the status of this mode

Parameters
CommandTokens
Returns
VOID
342{
343 if (CommandTokens.size() == 2)
344 {
345 //
346 // It's a query
347 //
348 if (g_AutoFlush)
349 {
350 ShowMessages("auto-flush is enabled\n");
351 }
352 else
353 {
354 ShowMessages("auto-flush is disabled\n");
355 }
356 }
357 else if (CommandTokens.size() == 3)
358 {
359 //
360 // The user tries to set a value as the autoflush
361 //
362 if (CompareLowerCaseStrings(CommandTokens.at(2), "on"))
363 {
365 CommandSettingsSetValueFromConfigFile("AutoFlush", "on");
366
367 ShowMessages("set auto-flush to enabled\n");
368 }
369 else if (CompareLowerCaseStrings(CommandTokens.at(2), "off"))
370 {
372 CommandSettingsSetValueFromConfigFile("AutoFlush", "off");
373
374 ShowMessages("set auto-flush to disabled\n");
375 }
376 else
377 {
378 //
379 // Sth is incorrect
380 //
381 ShowMessages("incorrect use of the '%s', please use 'help %s' for more information\n",
382 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str(),
383 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
384 return;
385 }
386 }
387 else
388 {
389 //
390 // Sth is incorrect
391 //
392 ShowMessages("incorrect use of the '%s', please use 'help %s' for more information\n",
393 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str(),
394 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
395 return;
396 }
397}
BOOLEAN g_AutoFlush
Whether auto-flush mode is enabled or not enabled.
Definition globals.h:601

◆ CommandSettingsAutoUpause()

VOID CommandSettingsAutoUpause ( vector< CommandToken > CommandTokens)

set auto-unpause mode to enabled or disabled

Parameters
CommandTokens
Returns
VOID
407{
408 if (CommandTokens.size() == 2)
409 {
410 //
411 // It's a query
412 //
413 if (g_AutoUnpause)
414 {
415 ShowMessages("auto-unpause is enabled\n");
416 }
417 else
418 {
419 ShowMessages("auto-unpause is disabled\n");
420 }
421 }
422 else if (CommandTokens.size() == 3)
423 {
424 //
425 // The user tries to set a value as the autounpause
426 //
427 if (CompareLowerCaseStrings(CommandTokens.at(2), "on"))
428 {
430 CommandSettingsSetValueFromConfigFile("AutoUnpause", "on");
431
432 ShowMessages("set auto-unpause to enabled\n");
433 }
434 else if (CompareLowerCaseStrings(CommandTokens.at(2), "off"))
435 {
437 CommandSettingsSetValueFromConfigFile("AutoUnpause", "off");
438
439 ShowMessages("set auto-unpause to disabled\n");
440 }
441 else
442 {
443 //
444 // Sth is incorrect
445 //
446 ShowMessages("incorrect use of the '%s', please use 'help %s' for more information\n",
447 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str(),
448 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
449 return;
450 }
451 }
452 else
453 {
454 //
455 // Sth is incorrect
456 //
457 ShowMessages("incorrect use of the '%s', please use 'help %s' for more information\n",
458 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str(),
459 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
460 return;
461 }
462}
BOOLEAN g_AutoUnpause
Whether auto-unpause mode is enabled or not enabled.
Definition globals.h:587

◆ CommandSettingsGetValueFromConfigFile()

BOOLEAN CommandSettingsGetValueFromConfigFile ( std::string OptionName,
std::string & OptionValue )

Gets the setting values from config file.

Parameters
OptionName
OptionValue
Returns
BOOLEAN Shows if the settings is available or not
61{
63 WCHAR ConfigPath[MAX_PATH] = {0};
64 std::string OptionValueFromFile;
65
66 //
67 // Get config file path
68 //
69 GetConfigFilePath(ConfigPath);
70
71 if (!IsFileExistW(ConfigPath))
72 {
73 return FALSE;
74 }
75
76 //
77 // Open the file
78 //
79 ifstream Is(ConfigPath);
80
81 //
82 // Read config file
83 //
84 Ini.parse(Is);
85
86 //
87 // Show config file
88 //
89 // Ini.generate(std::cout);
90
91 inipp::get_value(Ini.sections["DEFAULT"], OptionName, OptionValueFromFile);
92
93 Is.close();
94
95 if (!OptionValueFromFile.empty())
96 {
97 OptionValue = OptionValueFromFile;
98 return TRUE;
99 }
100 else
101 {
102 return FALSE;
103 }
104}
Definition inipp.h:172
Sections sections
Definition inipp.h:178
void parse(std::basic_istream< CharT > &is)
Definition inipp.h:202
VOID GetConfigFilePath(PWCHAR ConfigPath)
Get config path.
Definition common.cpp:792
BOOLEAN IsFileExistW(const WCHAR *FileName)
check if a file exist or not (wide-char)
Definition common.cpp:753
bool get_value(const std::map< std::basic_string< CharT >, std::basic_string< CharT > > &sec, const std::basic_string< CharT > &key, T &dst)
Definition inipp.h:116

◆ CommandSettingsHelp()

VOID CommandSettingsHelp ( )

help of the settings command

Returns
VOID
30{
31 ShowMessages(
32 "settings : queries, sets, or changes a value for a special settings option.\n\n");
33
34 ShowMessages("syntax : \tsettings [OptionName (string)]\n");
35 ShowMessages("syntax : \tsettings [OptionName (string)] [Value (hex)]\n");
36 ShowMessages("syntax : \tsettings [OptionName (string)] [Value (string)]\n");
37 ShowMessages("syntax : \tsettings [OptionName (string)] [on|off]\n");
38
39 ShowMessages("\n");
40 ShowMessages("\t\te.g : settings autounpause\n");
41 ShowMessages("\t\te.g : settings autounpause on\n");
42 ShowMessages("\t\te.g : settings autounpause off\n");
43 ShowMessages("\t\te.g : settings addressconversion on\n");
44 ShowMessages("\t\te.g : settings addressconversion off\n");
45 ShowMessages("\t\te.g : settings autoflush on\n");
46 ShowMessages("\t\te.g : settings autoflush off\n");
47 ShowMessages("\t\te.g : settings syntax intel\n");
48 ShowMessages("\t\te.g : settings syntax att\n");
49 ShowMessages("\t\te.g : settings syntax masm\n");
50}

◆ CommandSettingsLoadDefaultValuesFromConfigFile()

VOID CommandSettingsLoadDefaultValuesFromConfigFile ( )

Loads default settings values from config file.

Returns
VOID
162{
163 string OptionValue;
164
165 //
166 // *** Set default configurations ***
167 //
168
169 //
170 // Set the assembly syntax
171 //
172 if (CommandSettingsGetValueFromConfigFile("AsmSyntax", OptionValue))
173 {
174 //
175 // The user tries to set a value as the syntax
176 //
177 if (!OptionValue.compare("intel"))
178 {
180 }
181 else if (!OptionValue.compare("att") ||
182 !OptionValue.compare("at&t"))
183 {
185 }
186 else if (!OptionValue.compare("masm"))
187 {
189 }
190 else
191 {
192 //
193 // Sth is incorrect
194 //
195 ShowMessages("err, incorrect assembly syntax settings\n");
196 }
197 }
198
199 //
200 // Set the auto unpause
201 //
202 if (CommandSettingsGetValueFromConfigFile("AutoUnpause", OptionValue))
203 {
204 if (!OptionValue.compare("on"))
205 {
207 }
208 else if (!OptionValue.compare("off"))
209 {
211 }
212 else
213 {
214 //
215 // Sth is incorrect
216 //
217 ShowMessages("err, incorrect auto unpause settings\n");
218 }
219 }
220
221 //
222 // Set the auto flush
223 //
224 if (CommandSettingsGetValueFromConfigFile("AutoFlush", OptionValue))
225 {
226 if (!OptionValue.compare("on"))
227 {
229 }
230 else if (!OptionValue.compare("off"))
231 {
233 }
234 else
235 {
236 //
237 // Sth is incorrect
238 //
239 ShowMessages("err, incorrect auto flush settings\n");
240 }
241 }
242
243 //
244 // Set the address conversion
245 //
246 if (CommandSettingsGetValueFromConfigFile("AddrConv", OptionValue))
247 {
248 if (!OptionValue.compare("on"))
249 {
251 }
252 else if (!OptionValue.compare("off"))
253 {
255 }
256 else
257 {
258 //
259 // Sth is incorrect
260 //
261 ShowMessages("err, incorrect address conversion settings\n");
262 }
263 }
264}
BOOLEAN CommandSettingsGetValueFromConfigFile(std::string OptionName, std::string &OptionValue)
Gets the setting values from config file.
Definition settings.cpp:60
UINT32 g_DisassemblerSyntax
Shows the syntax used in !u !u2 u u2 commands.
Definition globals.h:608

◆ CommandSettingsSetValueFromConfigFile()

VOID CommandSettingsSetValueFromConfigFile ( std::string OptionName,
std::string OptionValue )

Sets the setting values from config file.

Parameters
OptionName
OptionValue
Returns
VOID
116{
118 WCHAR ConfigPath[MAX_PATH] = {0};
119
120 //
121 // Get config file path
122 //
123 GetConfigFilePath(ConfigPath);
124
125 ifstream Is(ConfigPath);
126
127 //
128 // Read config file
129 //
130 Ini.parse(Is);
131
132 Is.close();
133
134 //
135 // Save the config
136 //
137 Ini.sections["DEFAULT"][OptionName] = OptionValue.c_str();
138 Ini.interpolate();
139
140 //
141 // Test, show the config
142 //
143 // Ini.generate(std::cout);
144
145 //
146 // Save the config
147 //
148 ofstream Os(ConfigPath);
149
150 Ini.generate(Os);
151
152 Os.close();
153}
void generate(std::basic_ostream< CharT > &os) const
Definition inipp.h:189
void interpolate()
Definition inipp.h:246

◆ CommandSettingsSyntax()

VOID CommandSettingsSyntax ( vector< CommandToken > CommandTokens)

set the syntax of !u !u2 u u2 command

Parameters
CommandTokens
Returns
VOID
472{
473 if (CommandTokens.size() == 2)
474 {
475 //
476 // It's a query
477 //
478 if (g_DisassemblerSyntax == 1)
479 {
480 ShowMessages("disassembler syntax is : intel\n");
481 }
482 else if (g_DisassemblerSyntax == 2)
483 {
484 ShowMessages("disassembler syntax is : at&t\n");
485 }
486 else if (g_DisassemblerSyntax == 3)
487 {
488 ShowMessages("disassembler syntax is : masm\n");
489 }
490 else
491 {
492 ShowMessages("unknown syntax\n");
493 }
494 }
495 else if (CommandTokens.size() == 3)
496 {
497 //
498 // The user tries to set a value as the syntax
499 //
500 if (CompareLowerCaseStrings(CommandTokens.at(2), "intel"))
501 {
503 CommandSettingsSetValueFromConfigFile("AsmSyntax", "intel");
504
505 ShowMessages("set syntax to intel\n");
506 }
507 else if (CompareLowerCaseStrings(CommandTokens.at(2), "att") ||
508 CompareLowerCaseStrings(CommandTokens.at(2), "at&t"))
509 {
511 CommandSettingsSetValueFromConfigFile("AsmSyntax", "att");
512
513 ShowMessages("set syntax to at&t\n");
514 }
515 else if (CompareLowerCaseStrings(CommandTokens.at(2), "masm"))
516 {
518 CommandSettingsSetValueFromConfigFile("AsmSyntax", "masm");
519
520 ShowMessages("set syntax to masm\n");
521 }
522 else
523 {
524 //
525 // Sth is incorrect
526 //
527 ShowMessages("incorrect use of the '%s', please use 'help %s' for more information\n",
528 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str(),
529 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
530 return;
531 }
532 }
533 else
534 {
535 //
536 // Sth is incorrect
537 //
538 ShowMessages("incorrect use of the '%s', please use 'help %s' for more information\n",
539 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str(),
540 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
541 return;
542 }
543}

Variable Documentation

◆ g_AddressConversion

BOOLEAN g_AddressConversion
extern

Whether converting addresses to object names or not.

it is enabled by default

◆ g_AutoFlush

BOOLEAN g_AutoFlush
extern

Whether auto-flush mode is enabled or not enabled.

it is disabled by default

◆ g_AutoUnpause

BOOLEAN g_AutoUnpause
extern

Whether auto-unpause mode is enabled or not enabled.

it is enabled by default

◆ g_DisassemblerSyntax

UINT32 g_DisassemblerSyntax
extern

Shows the syntax used in !u !u2 u u2 commands.

INTEL = 1, ATT = 2, MASM = 3

◆ g_IsConnectedToRemoteDebuggee

BOOLEAN g_IsConnectedToRemoteDebuggee
extern

Shows whether the current debugger is the host and connected to a remote debuggee (guest).