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

!measure command More...

#include "pch.h"

Functions

VOID CommandMeasureHelp ()
 help of the !measure command
VOID CommandMeasure (vector< CommandToken > CommandTokens, string Command)
 !measure command handler

Variables

UINT64 g_CpuidAverage
 The average calculated from the measurements of cpuid '!measure' command.
UINT64 g_CpuidStandardDeviation
 The standard deviation calculated from the measurements of cpuid '!measure' command.
UINT64 g_CpuidMedian
 The median calculated from the measurements of cpuid '!measure' command.
UINT64 g_RdtscAverage
 The average calculated from the measurements of rdtsc/p '!measure' command.
UINT64 g_RdtscStandardDeviation
 The standard deviation calculated from the measurements of rdtsc/p '!measure' command.
UINT64 g_RdtscMedian
 The median calculated from the measurements of rdtsc/p '!measure' command.
BOOLEAN g_TransparentResultsMeasured
 Shows whether the user executed and mesaured '!measure' command or not, it is because we want to use these measurements later in '!hide' command.

Detailed Description

!measure command

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

Function Documentation

◆ CommandMeasure()

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

!measure command handler

Parameters
CommandTokens
Command
Returns
VOID
57{
58 BOOLEAN DefaultMode = FALSE;
59
60 ShowMessages("This command is deprecated, you should not use it anymore!\n");
61 return;
62
63 if (CommandTokens.size() >= 3)
64 {
65 ShowMessages("incorrect use of the '%s'\n\n",
66 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
68 return;
69 }
70
71 if (CommandTokens.size() == 2 && !CompareLowerCaseStrings(CommandTokens.at(1), "default"))
72 {
73 ShowMessages("incorrect use of the '%s'\n\n",
74 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
76 return;
77 }
78 else if (CommandTokens.size() == 2 &&
79 CompareLowerCaseStrings(CommandTokens.at(1), "default"))
80 {
81 DefaultMode = TRUE;
82 }
83
84 //
85 // Check if debugger is loaded or not
86 //
87 if (g_DeviceHandle && !DefaultMode)
88 {
89 ShowMessages(
90 "Debugger is loaded and your machine is already in a hypervisor, you "
91 "should measure the times before 'load'-ing the debugger, please "
92 "'unload' the debugger and use '!measure' again or use '!measure "
93 "default' to use hardcoded measurements\n");
94 return;
95 }
96
97 if (!DefaultMode)
98 {
103 {
104 ShowMessages(
105 "we detected that there is a hypervisor, on your system, it "
106 "leads to wrong measurement results for our transparent-mode, please "
107 "make sure that you're not in a hypervisor then measure the result "
108 "again; otherwise the transparent-mode will not work but you can use "
109 "'!measure default' to use the hardcoded measurements !\n\n");
110
111 return;
112 }
113
118 {
119 ShowMessages(
120 "we detected that there is a hypervisor, on your system, it "
121 "leads to wrong measurement results for our transparent-mode, please "
122 "make sure that you're not in a hypervisor then measure the result "
123 "again; otherwise the transparent-mode will not work but you can use "
124 "'!measure default' to use the hardcoded measurements !\n\n");
125
126 return;
127 }
128 }
129 else
130 {
131 //
132 // It's a default mode
133 //
134
135 //
136 // Default values for cpuid
137 //
138 g_CpuidAverage = 0x5f;
140 g_CpuidMedian = 0x5f;
141
142 //
143 // Default values for rdtsc/p
144 //
145 g_RdtscAverage = 0x16;
147 g_RdtscMedian = 0x16;
148 }
149
150 ShowMessages("the measurements were successful\nyou can use the '!hide' command now\n");
151
152 //
153 // Indicate that the measurements was successful
154 //
156}
UCHAR BOOLEAN
Definition BasicTypes.h:35
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113
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
HANDLE g_DeviceHandle
Holds the global handle of device which is used to send the request to the kernel by IOCTL,...
Definition globals.h:481
UINT64 g_CpuidStandardDeviation
The standard deviation calculated from the measurements of cpuid '!measure' command.
Definition globals.h:542
UINT64 g_RdtscAverage
The average calculated from the measurements of rdtsc/p '!measure' command.
Definition globals.h:554
VOID CommandMeasureHelp()
help of the !measure command
Definition measure.cpp:33
UINT64 g_RdtscMedian
The median calculated from the measurements of rdtsc/p '!measure' command.
Definition globals.h:566
BOOLEAN g_TransparentResultsMeasured
Shows whether the user executed and mesaured '!measure' command or not, it is because we want to use ...
Definition globals.h:530
UINT64 g_CpuidMedian
The median calculated from the measurements of cpuid '!measure' command.
Definition globals.h:548
UINT64 g_RdtscStandardDeviation
The standard deviation calculated from the measurements of rdtsc/p '!measure' command.
Definition globals.h:560
UINT64 g_CpuidAverage
The average calculated from the measurements of cpuid '!measure' command.
Definition globals.h:536
BOOLEAN TransparentModeCheckRdtscpVmexit(UINT64 *Average, UINT64 *StandardDeviation, UINT64 *Median)
compute the average, standard deviation and median if rdtsc+rdtsc
Definition transparency.cpp:212
BOOLEAN TransparentModeCheckHypervisorPresence(UINT64 *Average, UINT64 *StandardDeviation, UINT64 *Median)
compute the average, standard deviation and median if rdtsc+cpuid+rdtsc
Definition transparency.cpp:182

◆ CommandMeasureHelp()

VOID CommandMeasureHelp ( )

help of the !measure command

Returns
VOID
34{
35 ShowMessages(
36 "This command is deprecated, you should not use it anymore!\n\n");
37 ShowMessages(
38 "!measure : measures the arguments needs for the '!hide' command.\n\n");
39
40 ShowMessages("syntax : \t!measure [default]\n");
41
42 ShowMessages("\n");
43 ShowMessages("\t\te.g : !measure\n");
44 ShowMessages("\t\te.g : !measure default\n");
45}

Variable Documentation

◆ g_CpuidAverage

UINT64 g_CpuidAverage
extern

The average calculated from the measurements of cpuid '!measure' command.

◆ g_CpuidMedian

UINT64 g_CpuidMedian
extern

The median calculated from the measurements of cpuid '!measure' command.

◆ g_CpuidStandardDeviation

UINT64 g_CpuidStandardDeviation
extern

The standard deviation calculated from the measurements of cpuid '!measure' command.

◆ g_RdtscAverage

UINT64 g_RdtscAverage
extern

The average calculated from the measurements of rdtsc/p '!measure' command.

◆ g_RdtscMedian

UINT64 g_RdtscMedian
extern

The median calculated from the measurements of rdtsc/p '!measure' command.

◆ g_RdtscStandardDeviation

UINT64 g_RdtscStandardDeviation
extern

The standard deviation calculated from the measurements of rdtsc/p '!measure' command.

◆ g_TransparentResultsMeasured

BOOLEAN g_TransparentResultsMeasured
extern

Shows whether the user executed and mesaured '!measure' command or not, it is because we want to use these measurements later in '!hide' command.