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

.attach command More...

#include "pch.h"

Functions

VOID CommandAttachHelp ()
 help of the .attach command
VOID CommandAttach (vector< CommandToken > CommandTokens, string Command)
 .attach command handler

Variables

BOOLEAN g_IsSerialConnectedToRemoteDebugger
 Shows if the debugger was connected to remote debugger (A remote host).

Detailed Description

.attach command

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

Function Documentation

◆ CommandAttach()

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

.attach command handler

Parameters
CommandTokens
Command
Returns
VOID
45{
46 UINT32 TargetPid = 0;
47 BOOLEAN NextIsPid = FALSE;
48
49 //
50 // Disable user-mode debugger in this version
51 //
52#if ActivateUserModeDebugger == FALSE
53
55 {
56 ShowMessages("the user-mode debugger in VMI Mode is still in the beta version and not stable. "
57 "we decided to exclude it from this release and release it in future versions. "
58 "if you want to test the user-mode debugger in VMI Mode, you should build "
59 "HyperDbg with special instructions. But attaching/switching to other processes\n"
60 "are fully supported in the Debugger Mode.\n"
61 "(it's not recommended to use it in VMI Mode yet!)\n");
62 return;
63 }
64
65#endif // !ActivateUserModeDebugger
66
67 //
68 // It's a attach to a target PID
69 //
70 if (CommandTokens.size() >= 4)
71 {
72 ShowMessages("incorrect use of the '%s'\n\n",
73 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
75 return;
76 }
77
78 for (auto Section = CommandTokens.begin() + 1; Section != CommandTokens.end(); Section++)
79 {
80 //
81 // Find out whether the user enters pid or not
82 //
83 if (NextIsPid)
84 {
85 NextIsPid = FALSE;
86
87 if (!ConvertTokenToUInt32(*Section, &TargetPid))
88 {
89 ShowMessages("please specify a correct hex value for process id\n\n");
91 return;
92 }
93 }
94 else if (CompareLowerCaseStrings(*Section, "pid"))
95 {
96 //
97 // next item is a pid for the process
98 //
99 NextIsPid = TRUE;
100 }
101 else
102 {
103 ShowMessages("unknown parameter at '%s'\n\n",
106 return;
107 }
108 }
109
110 //
111 // Check if the process id is empty or not
112 //
113 if (TargetPid == 0)
114 {
115 ShowMessages("please specify a hex value for process id\n\n");
117 return;
118 }
119
120 //
121 // Perform attach to target process
122 //
123 ShowMessages("Attaching to process 0x%llx (%lld)...\n\n", TargetPid, TargetPid);
124 UdAttachToProcess(TargetPid, NULL, NULL, FALSE);
125}
VOID CommandAttachHelp()
help of the .attach command
Definition attach.cpp:25
UCHAR BOOLEAN
Definition BasicTypes.h:35
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113
unsigned int UINT32
Definition BasicTypes.h:54
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
BOOLEAN ConvertTokenToUInt32(CommandToken TargetToken, PUINT32 Result)
check and convert command token to a 32 bit unsigned integer
Definition common.cpp:546
BOOLEAN g_IsSerialConnectedToRemoteDebugger
Shows if the debugger was connected to remote debugger (A remote host).
Definition rev.cpp:18
BOOLEAN UdAttachToProcess(UINT32 TargetPid, const WCHAR *TargetFileAddress, const WCHAR *CommandLine, BOOLEAN RunCallbackAtTheFirstInstruction)
Attach to target process.
Definition ud.cpp:372

◆ CommandAttachHelp()

VOID CommandAttachHelp ( )

help of the .attach command

Returns
VOID
26{
27 ShowMessages(".attach : attaches to debug a thread in VMI Mode.\n\n");
28
29 ShowMessages("syntax : \t.attach [pid ProcessId (hex)]\n");
30
31 ShowMessages("\n");
32 ShowMessages("\t\te.g : .attach pid b60 \n");
33}

Variable Documentation

◆ g_IsSerialConnectedToRemoteDebugger

BOOLEAN g_IsSerialConnectedToRemoteDebugger
extern

Shows if the debugger was connected to remote debugger (A remote host).