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< string > SplitCommand)
 set the address conversion enabled and disabled and query the status of this mode
 
VOID CommandSettingsAutoFlush (vector< string > SplitCommand)
 set the auto-flush mode to enabled and disabled and query the status of this mode
 
VOID CommandSettingsAutoUpause (vector< string > SplitCommand)
 set auto-unpause mode to enabled or disabled
 
VOID CommandSettingsSyntax (vector< string > SplitCommand)
 set the syntax of !u !u2 u u2 command
 
VOID CommandSettings (vector< string > SplitCommand, 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< string > SplitCommand,
string Command )

settings command handler

Parameters
SplitCommand
Command
Returns
VOID
545{
546 if (SplitCommand.size() <= 1)
547 {
548 ShowMessages("incorrect use of the 'settings'\n\n");
550 return;
551 }
552
553 //
554 // Interpret the field name
555 //
556 if (!SplitCommand.at(1).compare("autounpause"))
557 {
558 //
559 // Handle it locally
560 //
561 CommandSettingsAutoUpause(SplitCommand);
562 }
563 else if (!SplitCommand.at(1).compare("syntax"))
564 {
565 //
566 // If it's a remote debugger then we send it to the remote debugger
567 //
569 {
570 RemoteConnectionSendCommand(Command.c_str(), (UINT32)Command.length() + 1);
571 }
572 else
573 {
574 //
575 // If it's a connection over serial or a local debugging then
576 // we handle it locally
577 //
578 CommandSettingsSyntax(SplitCommand);
579 }
580 }
581 else if (!SplitCommand.at(1).compare("autoflush"))
582 {
583 //
584 // If it's a remote debugger then we send it to the remote debugger
585 //
587 {
588 RemoteConnectionSendCommand(Command.c_str(), (UINT32)Command.length() + 1);
589 }
590 else
591 {
592 //
593 // If it's a connection over serial or a local debugging then
594 // we handle it locally
595 //
596 CommandSettingsAutoFlush(SplitCommand);
597 }
598 }
599 else if (!SplitCommand.at(1).compare("addressconversion"))
600 {
601 //
602 // If it's a remote debugger then we send it to the remote debugger
603 //
605 {
606 RemoteConnectionSendCommand(Command.c_str(), (UINT32)Command.length() + 1);
607 }
608 else
609 {
610 //
611 // If it's a connection over serial or a local debugging then
612 // we handle it locally
613 //
615 }
616 }
617 else
618 {
619 //
620 // optionm not found
621 //
622 ShowMessages("incorrect use of the 'settings', please use 'help settings' "
623 "for more details\n");
624 return;
625 }
626}
unsigned int UINT32
Definition BasicTypes.h:48
VOID ShowMessages(const char *Fmt,...)
Show messages.
Definition libhyperdbg.cpp: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
BOOLEAN g_IsConnectedToRemoteDebuggee
Shows whether the current debugger is the host and connected to a remote debuggee (guest)
Definition globals.h:74
VOID CommandSettingsAddressConversion(vector< string > SplitCommand)
set the address conversion enabled and disabled and query the status of this mode
Definition settings.cpp:274
VOID CommandSettingsHelp()
help of the settings command
Definition settings.cpp:29
VOID CommandSettingsSyntax(vector< string > SplitCommand)
set the syntax of !u !u2 u u2 command
Definition settings.cpp:464
VOID CommandSettingsAutoFlush(vector< string > SplitCommand)
set the auto-flush mode to enabled and disabled and query the status of this mode
Definition settings.cpp:338
VOID CommandSettingsAutoUpause(vector< string > SplitCommand)
set auto-unpause mode to enabled or disabled
Definition settings.cpp:401

◆ CommandSettingsAddressConversion()

VOID CommandSettingsAddressConversion ( vector< string > SplitCommand)

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

Parameters
SplitCommand
Returns
VOID
275{
276 if (SplitCommand.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 (SplitCommand.size() == 3)
291 {
292 //
293 // The user tries to set a value as the autoflush
294 //
295 if (!SplitCommand.at(2).compare("on"))
296 {
299
300 ShowMessages("set address conversion to enabled\n");
301 }
302 else if (!SplitCommand.at(2).compare("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 'settings', please use 'help settings' "
315 "for more details\n");
316 return;
317 }
318 }
319 else
320 {
321 //
322 // Sth is incorrect
323 //
324 ShowMessages("incorrect use of the 'settings', please use 'help settings' "
325 "for more details\n");
326 return;
327 }
328}
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
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:584

◆ CommandSettingsAutoFlush()

VOID CommandSettingsAutoFlush ( vector< string > SplitCommand)

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

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

◆ CommandSettingsAutoUpause()

VOID CommandSettingsAutoUpause ( vector< string > SplitCommand)

set auto-unpause mode to enabled or disabled

Parameters
SplitCommand
Returns
VOID
402{
403 if (SplitCommand.size() == 2)
404 {
405 //
406 // It's a query
407 //
408 if (g_AutoUnpause)
409 {
410 ShowMessages("auto-unpause is enabled\n");
411 }
412 else
413 {
414 ShowMessages("auto-unpause is disabled\n");
415 }
416 }
417 else if (SplitCommand.size() == 3)
418 {
419 //
420 // The user tries to set a value as the autounpause
421 //
422 if (!SplitCommand.at(2).compare("on"))
423 {
425 CommandSettingsSetValueFromConfigFile("AutoUnpause", "on");
426
427 ShowMessages("set auto-unpause to enabled\n");
428 }
429 else if (!SplitCommand.at(2).compare("off"))
430 {
432 CommandSettingsSetValueFromConfigFile("AutoUnpause", "off");
433
434 ShowMessages("set auto-unpause to disabled\n");
435 }
436 else
437 {
438 //
439 // Sth is incorrect
440 //
441 ShowMessages("incorrect use of the 'settings', please use 'help settings' "
442 "for more details\n");
443 return;
444 }
445 }
446 else
447 {
448 //
449 // Sth is incorrect
450 //
451 ShowMessages("incorrect use of the 'settings', please use 'help settings' "
452 "for more details\n");
453 return;
454 }
455}
BOOLEAN g_AutoUnpause
Whether auto-unpause mode is enabled or not enabled.
Definition globals.h:577

◆ 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}
wchar_t WCHAR
Definition BasicTypes.h:32
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:671
BOOLEAN IsFileExistW(const wchar_t *FileName)
check if a file exist or not (wide-char)
Definition common.cpp:632
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{
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:598

◆ 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< string > SplitCommand)

set the syntax of !u !u2 u u2 command

Parameters
SplitCommand
Returns
VOID
465{
466 if (SplitCommand.size() == 2)
467 {
468 //
469 // It's a query
470 //
471 if (g_DisassemblerSyntax == 1)
472 {
473 ShowMessages("disassembler syntax is : intel\n");
474 }
475 else if (g_DisassemblerSyntax == 2)
476 {
477 ShowMessages("disassembler syntax is : at&t\n");
478 }
479 else if (g_DisassemblerSyntax == 3)
480 {
481 ShowMessages("disassembler syntax is : masm\n");
482 }
483 else
484 {
485 ShowMessages("unknown syntax\n");
486 }
487 }
488 else if (SplitCommand.size() == 3)
489 {
490 //
491 // The user tries to set a value as the syntax
492 //
493 if (!SplitCommand.at(2).compare("intel"))
494 {
496 CommandSettingsSetValueFromConfigFile("AsmSyntax", "intel");
497
498 ShowMessages("set syntax to intel\n");
499 }
500 else if (!SplitCommand.at(2).compare("att") ||
501 !SplitCommand.at(2).compare("at&t"))
502 {
504 CommandSettingsSetValueFromConfigFile("AsmSyntax", "att");
505
506 ShowMessages("set syntax to at&t\n");
507 }
508 else if (!SplitCommand.at(2).compare("masm"))
509 {
511 CommandSettingsSetValueFromConfigFile("AsmSyntax", "masm");
512
513 ShowMessages("set syntax to masm\n");
514 }
515 else
516 {
517 //
518 // Sth is incorrect
519 //
520 ShowMessages("incorrect use of the 'settings', please use 'help settings' "
521 "for more details\n");
522 return;
523 }
524 }
525 else
526 {
527 //
528 // Sth is incorrect
529 //
530 ShowMessages("incorrect use of the 'settings', please use 'help settings' "
531 "for more details\n");
532 return;
533 }
534}

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)