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< CommandToken > CommandTokens, 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< CommandToken > CommandTokens,
string Command )

handler of .formats command

Parameters
CommandTokens
Command
Returns
VOID
107{
108 UINT64 ConstantValue = 0;
109 BOOLEAN HasError = TRUE;
110
111 if (CommandTokens.size() == 1)
112 {
113 ShowMessages("incorrect use of the '%s'\n\n",
114 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
116 return;
117 }
118
119 //
120 // Trim the command
121 //
122 Trim(Command);
123
124 //
125 // Remove .formats from it
126 //
127 Command.erase(0, GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).size());
128
129 //
130 // Trim it again
131 //
132 Trim(Command);
133
134 //
135 // Evaluate a single expression
136 //
137 ConstantValue = ScriptEngineEvalSingleExpression(Command, &HasError);
138
139 if (HasError)
140 {
141 ShowMessages("err, couldn't resolve error at '%s'\n", Command.c_str());
142 }
143 else
144 {
145 //
146 // Show formats results for a constant
147 //
148 CommandFormatsShowResults(ConstantValue);
149 }
150}
UCHAR BOOLEAN
Definition BasicTypes.h:35
#define TRUE
Definition BasicTypes.h:114
std::string GetCaseSensitiveStringFromCommandToken(CommandToken TargetToken)
Get case sensitive string from command token.
Definition common.cpp:467
VOID Trim(std::string &s)
trim from both ends and start of a string (in place)
Definition common.cpp:715
VOID CommandFormatsHelp()
help of the help command :)
Definition formats.cpp:20
VOID CommandFormatsShowResults(UINT64 U64Value)
show results of .formats command
Definition formats.cpp:43
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:31

◆ 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 UINT32 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 UCHAR * TempCharacter = (UCHAR *)&U64Value;
79 for (SIZE_T j = 0; j < sizeof(UINT64); j++)
80 {
81 Character = (UINT32)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}
unsigned char UCHAR
Definition BasicTypes.h:34
unsigned int UINT32
Definition BasicTypes.h:54
char CHAR
Definition BasicTypes.h:33
string SeparateTo64BitValue(UINT64 Value)
VOID PrintBits(const UINT32 size, const VOID *ptr)