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< string > SplitCommand, string Command)
 .attach command handler
 

Variables

BOOLEAN g_IsSerialConnectedToRemoteDebuggee
 Shows if the debugger was connected to remote debuggee over (A remote guest)
 
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< string > SplitCommand,
string Command )

.attach command handler

Parameters
SplitCommand
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 (SplitCommand.size() >= 4)
71 {
72 ShowMessages("incorrect use of the '.attach'\n\n");
74 return;
75 }
76
77 //
78 // .attach and .detach commands are only supported in VMI Mode
79 //
81 {
82 ShowMessages("err, '.attach', and '.detach' commands are only usable "
83 "in VMI Mode, you can use the '.process', or the '.thread' "
84 "in Debugger Mode\n");
85 return;
86 }
87
88 for (auto item : SplitCommand)
89 {
90 //
91 // Find out whether the user enters pid or not
92 //
93 if (NextIsPid)
94 {
95 NextIsPid = FALSE;
96
97 if (!ConvertStringToUInt32(item, &TargetPid))
98 {
99 ShowMessages("please specify a correct hex value for process id\n\n");
101 return;
102 }
103 }
104 else if (!item.compare("pid"))
105 {
106 //
107 // next item is a pid for the process
108 //
109 NextIsPid = TRUE;
110 }
111 }
112
113 //
114 // Check if the process id is empty or not
115 //
116 if (TargetPid == 0)
117 {
118 ShowMessages("please specify a hex value for process id\n\n");
120 return;
121 }
122
123 //
124 // Perform attach to target process
125 //
126 UdAttachToProcess(TargetPid, NULL, NULL, FALSE);
127}
UCHAR BOOLEAN
Definition BasicTypes.h:39
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
unsigned int UINT32
Definition BasicTypes.h:48
BOOLEAN g_IsSerialConnectedToRemoteDebugger
Shows if the debugger was connected to remote debugger (A remote host)
Definition globals.h:238
VOID CommandAttachHelp()
help of the .attach command
Definition attach.cpp:26
BOOLEAN g_IsSerialConnectedToRemoteDebuggee
Shows if the debugger was connected to remote debuggee over (A remote guest)
Definition globals.h:231
BOOLEAN ConvertStringToUInt32(string TextToConvert, PUINT32 Result)
check and convert string to a 32 bit unsigned it and also check for special notations like 0x etc.
Definition common.cpp:347
VOID ShowMessages(const char *Fmt,...)
Show messages.
Definition libhyperdbg.cpp:96
BOOLEAN UdAttachToProcess(UINT32 TargetPid, const WCHAR *TargetFileAddress, const WCHAR *CommandLine, BOOLEAN RunCallbackAtTheFirstInstruction)
Attach to target process.
Definition ud.cpp:349

◆ CommandAttachHelp()

VOID CommandAttachHelp ( )

help of the .attach command

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

Variable Documentation

◆ g_IsSerialConnectedToRemoteDebuggee

BOOLEAN g_IsSerialConnectedToRemoteDebuggee
extern

Shows if the debugger was connected to remote debuggee over (A remote guest)

◆ g_IsSerialConnectedToRemoteDebugger

BOOLEAN g_IsSerialConnectedToRemoteDebugger
extern

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