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

.formats command More...

#include "pch.h"

Functions

VOID CommandFormatsHelp ()
 help of the help command :)
 
VOID CommandFormatsShowResults (UINT64 U64Value)
 show results of .formats command
 
VOID CommandFormats (vector< string > SplitCommand, string Command)
 handler of .formats command
 

Detailed Description

.formats command

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

Function Documentation

◆ CommandFormats()

VOID CommandFormats ( vector< string > SplitCommand,
string Command )

handler of .formats command

Parameters
SplitCommand
Command
Returns
VOID
106{
107 UINT64 ConstantValue = 0;
108 BOOLEAN HasError = TRUE;
109
110 if (SplitCommand.size() == 1)
111 {
112 ShowMessages("incorrect use of the '.formats'\n\n");
114 return;
115 }
116
117 //
118 // Trim the command
119 //
120 Trim(Command);
121
122 //
123 // Remove .formats from it
124 //
125 Command.erase(0, SplitCommand.at(0).size());
126
127 //
128 // Trim it again
129 //
130 Trim(Command);
131
132 //
133 // Evaluate a single expression
134 //
135 ConstantValue = ScriptEngineEvalSingleExpression(Command, &HasError);
136
137 if (HasError)
138 {
139 ShowMessages("err, couldn't resolve error at '%s'\n", Command.c_str());
140 }
141 else
142 {
143 //
144 // Show formats results for a constant
145 //
146 CommandFormatsShowResults(ConstantValue);
147 }
148}
UCHAR BOOLEAN
Definition BasicTypes.h:39
#define TRUE
Definition BasicTypes.h:55
unsigned __int64 UINT64
Definition BasicTypes.h:21
void Trim(std::string &s)
trim from both ends and start of a string (in place)
Definition common.cpp:594
VOID CommandFormatsHelp()
help of the help command :)
Definition formats.cpp:20
VOID CommandFormatsShowResults(UINT64 U64Value)
show results of .formats command
Definition formats.cpp:43
VOID ShowMessages(const char *Fmt,...)
Show messages.
Definition libhyperdbg.cpp:96
UINT64 ScriptEngineEvalSingleExpression(string Expr, PBOOLEAN HasError)
Get the value from the evaluation of single expression from local debuggee and remote debuggee.
Definition script-engine.cpp:30

◆ CommandFormatsHelp()

VOID CommandFormatsHelp ( )

help of the help command :)

Returns
VOID
21{
22 ShowMessages(".formats : shows a value or register in different formats.\n\n");
23
24 ShowMessages("syntax : \t.formats [Expression (string)]\n");
25
26 ShowMessages("\n");
27 ShowMessages("\t\te.g : .formats nt!ExAllocatePoolWithTag\n");
28 ShowMessages("\t\te.g : .formats nt!Kd_DEFAULT_Mask\n");
29 ShowMessages("\t\te.g : .formats nt!Kd_DEFAULT_Mask+5\n");
30 ShowMessages("\t\te.g : .formats 55\n");
31 ShowMessages("\t\te.g : .formats @rax\n");
32 ShowMessages("\t\te.g : .formats @rbx+@rcx\n");
33 ShowMessages("\t\te.g : .formats $pid\n");
34}

◆ CommandFormatsShowResults()

VOID CommandFormatsShowResults ( UINT64 U64Value)

show results of .formats command

Parameters
U64Value
Returns
VOID
44{
45 time_t t;
46 struct tm * tmp;
47 char MY_TIME[50];
48 unsigned int Character;
49
50 time(&t);
51
52 //
53 // localtime() uses the time pointed by t ,
54 // to fill a tm structure with the values that
55 // represent the corresponding local time.
56 //
57
58 tmp = localtime(&t);
59
60 //
61 // using strftime to display time
62 //
63 strftime(MY_TIME, sizeof(MY_TIME), "%x - %I:%M%p", tmp);
64
65 ShowMessages("evaluate expression:\n");
66 ShowMessages("Hex : %s\n", SeparateTo64BitValue(U64Value).c_str());
67 ShowMessages("Decimal : %d\n", U64Value);
68 ShowMessages("Octal : %o\n", U64Value);
69
70 ShowMessages("Binary : ");
71 PrintBits(sizeof(UINT64), &U64Value);
72
73 ShowMessages("\nChar : ");
74
75 //
76 // iterate through 8, 8 bits (8*6)
77 //
78 unsigned char * TempCharacter = (unsigned char *)&U64Value;
79 for (size_t j = 0; j < sizeof(UINT64); j++)
80 {
81 Character = (unsigned int)TempCharacter[j];
82
83 if (isprint(Character))
84 {
85 ShowMessages("%c", Character);
86 }
87 else
88 {
89 ShowMessages(".");
90 }
91 }
92 ShowMessages("\nTime : %s\n", MY_TIME);
93 ShowMessages("Float : %4.2f %+.0e %E\n", U64Value, U64Value, U64Value);
94 ShowMessages("Double : %.*e\n", DECIMAL_DIG, U64Value);
95}
string SeparateTo64BitValue(UINT64 Value)
add ` between 64 bit values and convert them to string
Definition common.cpp:27
VOID PrintBits(const UINT32 Size, const void *Ptr)
print bits and bytes for d* commands
Definition common.cpp:47