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

.restart command More...

#include "pch.h"

Functions

VOID CommandRestartHelp ()
 help of the .restart command
VOID CommandRestart (vector< CommandToken > CommandTokens, string Command)
 .restart command handler

Variables

UINT32 g_ProcessIdOfLatestStartingProcess
 The process id of the latest starting process.
std::wstring g_StartCommandPath
 the start path used in .start command
std::wstring g_StartCommandPathAndArguments
 the start arguments used in .start command
ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
 State of active debugging thread.

Detailed Description

.restart command

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

Function Documentation

◆ CommandRestart()

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

.restart command handler

Parameters
CommandTokens
Command
Returns
VOID
48{
49 if (CommandTokens.size() != 1)
50 {
51 ShowMessages("incorrect use of the '%s'\n\n",
52 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
54 return;
55 }
56
57 //
58 // Check if the .start command is previously called or not
59 //
60 if (g_StartCommandPath.empty())
61 {
62 ShowMessages("nothing to restart, did you use the '.start' command before?\n");
63 return;
64 }
65
66 //
67 // Check to kill the current active process (if exists)
68 //
70 {
71 //
72 // kill the process, we will restart the process even if we didn't
73 // successfully killed the active process
74 //
76 }
78 {
80
81 //
82 // No longer the last process exists
83 //
85 }
86
87 //
88 // Perform run of the target file
89 //
91 {
92 //
93 // TEMPORARY LINUX SHIM (same as in pe.cpp/dump.cpp): the path is a
94 // std::wstring of native wchar_t (4 bytes on Linux), but UdAttachToProcess
95 // takes a 2-byte HyperDbg WCHAR * (UINT16). The cast is a bogus 2-byte
96 // reinterpretation on Linux, acceptable only because the user-debugger
97 // path is still stubbed there. On Windows WCHAR == wchar_t, so it is a
98 // plain correct pointer. TODO(Linux): convert wchar_t -> 2-byte WCHAR
99 // properly once the Linux user-debugger path is real.
100 //
102 (WCHAR *)g_StartCommandPath.c_str(),
103 NULL,
104 FALSE);
105 }
106 else
107 {
108 //
109 // TEMPORARY LINUX SHIM (same as in pe.cpp/dump.cpp): the path/arguments
110 // are std::wstring of native wchar_t (4 bytes on Linux), but
111 // UdAttachToProcess takes 2-byte HyperDbg WCHAR * (UINT16). The casts are
112 // a bogus 2-byte reinterpretation on Linux, acceptable only because the
113 // user-debugger path is still stubbed there. On Windows WCHAR == wchar_t,
114 // so they are plain correct pointers. TODO(Linux): convert wchar_t ->
115 // 2-byte WCHAR properly once the Linux user-debugger path is real.
116 //
118 (WCHAR *)g_StartCommandPath.c_str(),
119 (WCHAR *)g_StartCommandPathAndArguments.c_str(),
120 FALSE);
121 }
122}
ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
State of active debugging thread.
Definition globals.h:372
#define FALSE
Definition BasicTypes.h:113
std::string GetCaseSensitiveStringFromCommandToken(CommandToken TargetToken)
Get case sensitive string from command token.
Definition common.cpp:467
UINT32 g_ProcessIdOfLatestStartingProcess
The process id of the latest starting process.
Definition globals.h:378
NULL()
Definition test-case-generator.py:530
std::wstring g_StartCommandPathAndArguments
the start arguments used in .start command
Definition globals.h:663
VOID CommandRestartHelp()
help of the .restart command
Definition restart.cpp:29
std::wstring g_StartCommandPath
the start path used in .start command
Definition globals.h:657
BOOLEAN UdKillProcess(UINT32 TargetPid)
Kill the target process from kernel.
Definition ud.cpp:688
BOOLEAN UdAttachToProcess(UINT32 TargetPid, const WCHAR *TargetFileAddress, const WCHAR *CommandLine, BOOLEAN RunCallbackAtTheFirstInstruction)
Attach to target process.
Definition ud.cpp:372

◆ CommandRestartHelp()

VOID CommandRestartHelp ( )

help of the .restart command

Returns
VOID
30{
31 ShowMessages(".restart : restarts the previously started process "
32 "(using '.start' command).\n\n");
33
34 ShowMessages(
35 "syntax : \t.restart \n");
36}

Variable Documentation

◆ g_ActiveProcessDebuggingState

ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
extern

State of active debugging thread.

372{0};

◆ g_ProcessIdOfLatestStartingProcess

UINT32 g_ProcessIdOfLatestStartingProcess
extern

The process id of the latest starting process.

◆ g_StartCommandPath

std::wstring g_StartCommandPath
extern

the start path used in .start command

◆ g_StartCommandPathAndArguments

std::wstring g_StartCommandPathAndArguments
extern

the start arguments used in .start command