2022-02-01 15:15:46 +03:30
|
|
|
/**
|
|
|
|
|
* @file switch.cpp
|
|
|
|
|
* @author Sina Karvandi (sina@hyperdbg.org)
|
|
|
|
|
* @brief .switch command
|
|
|
|
|
* @details
|
|
|
|
|
* @version 0.1
|
|
|
|
|
* @date 2022-01-31
|
|
|
|
|
*
|
|
|
|
|
* @copyright This project is released under the GNU Public License v3.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2022-05-04 16:38:21 -07:00
|
|
|
#include "pch.h"
|
2022-02-01 15:15:46 +03:30
|
|
|
|
|
|
|
|
/**
|
2023-07-13 16:05:42 +09:00
|
|
|
* @brief help of the .switch command
|
2022-02-01 15:15:46 +03:30
|
|
|
*
|
|
|
|
|
* @return VOID
|
|
|
|
|
*/
|
|
|
|
|
VOID
|
|
|
|
|
CommandSwitchHelp()
|
|
|
|
|
{
|
2022-04-10 22:24:56 +04:30
|
|
|
ShowMessages(".switch : shows the list of active debugging threads and switches "
|
2022-02-01 15:15:46 +03:30
|
|
|
"between processes and threads in VMI Mode.\n\n");
|
2022-04-17 23:05:24 +04:30
|
|
|
|
2022-02-13 03:38:24 +03:30
|
|
|
ShowMessages("syntax : \t.switch \n");
|
2022-02-09 02:16:58 +03:30
|
|
|
ShowMessages("syntax : \t.switch [pid ProcessId (hex)]\n");
|
|
|
|
|
ShowMessages("syntax : \t.switch [tid ThreadId (hex)]\n");
|
2022-04-17 23:05:24 +04:30
|
|
|
|
|
|
|
|
ShowMessages("\n");
|
2025-08-23 15:36:53 +02:00
|
|
|
ShowMessages("\t\te.g : .switch\n");
|
2022-02-01 15:15:46 +03:30
|
|
|
ShowMessages("\t\te.g : .switch list\n");
|
|
|
|
|
ShowMessages("\t\te.g : .switch pid b60 \n");
|
|
|
|
|
ShowMessages("\t\te.g : .switch tid b60 \n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief .switch command handler
|
|
|
|
|
*
|
2024-07-30 15:47:35 +09:00
|
|
|
* @param CommandTokens
|
2024-07-31 14:08:14 +09:00
|
|
|
* @param Command
|
2024-07-30 15:47:35 +09:00
|
|
|
*
|
2022-02-01 15:15:46 +03:30
|
|
|
* @return VOID
|
|
|
|
|
*/
|
|
|
|
|
VOID
|
2024-07-31 14:08:14 +09:00
|
|
|
CommandSwitch(vector<CommandToken> CommandTokens, string Command)
|
2022-02-01 15:15:46 +03:30
|
|
|
{
|
|
|
|
|
UINT32 PidOrTid = NULL;
|
|
|
|
|
|
2025-08-23 15:36:53 +02:00
|
|
|
if (CommandTokens.size() > 3)
|
2022-02-01 15:15:46 +03:30
|
|
|
{
|
2024-07-30 15:47:35 +09:00
|
|
|
ShowMessages("incorrect use of the '%s'\n\n",
|
|
|
|
|
GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
|
2022-02-01 15:15:46 +03:30
|
|
|
CommandSwitchHelp();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Perform switching or listing the threads
|
|
|
|
|
//
|
2025-08-23 15:36:53 +02:00
|
|
|
if (CommandTokens.size() == 1 || (CommandTokens.size() == 2 && CompareLowerCaseStrings(CommandTokens.at(1), "list")))
|
2022-02-01 15:15:46 +03:30
|
|
|
{
|
2022-02-13 03:38:24 +03:30
|
|
|
UdShowListActiveDebuggingProcessesAndThreads();
|
2022-02-01 15:15:46 +03:30
|
|
|
}
|
2024-07-30 15:47:35 +09:00
|
|
|
else if (CompareLowerCaseStrings(CommandTokens.at(1), "pid"))
|
2022-02-01 15:15:46 +03:30
|
|
|
{
|
2024-07-30 15:47:35 +09:00
|
|
|
if (!ConvertTokenToUInt32(CommandTokens.at(2), &PidOrTid))
|
2022-02-01 15:15:46 +03:30
|
|
|
{
|
|
|
|
|
ShowMessages("please specify a correct hex value for process id\n\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Switch by pid
|
|
|
|
|
//
|
|
|
|
|
if (UdSetActiveDebuggingThreadByPidOrTid(PidOrTid, FALSE))
|
|
|
|
|
{
|
|
|
|
|
ShowMessages("switched to process id: %x\n", PidOrTid);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-30 15:47:35 +09:00
|
|
|
else if (CompareLowerCaseStrings(CommandTokens.at(1), "tid"))
|
2022-02-01 15:15:46 +03:30
|
|
|
{
|
2024-07-30 15:47:35 +09:00
|
|
|
if (!ConvertTokenToUInt32(CommandTokens.at(2), &PidOrTid))
|
2022-02-01 15:15:46 +03:30
|
|
|
{
|
|
|
|
|
ShowMessages("please specify a correct hex value for thread id\n\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Switch by tid
|
|
|
|
|
//
|
|
|
|
|
if (UdSetActiveDebuggingThreadByPidOrTid(PidOrTid, TRUE))
|
|
|
|
|
{
|
|
|
|
|
ShowMessages("switched to thread id: %x\n", PidOrTid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ShowMessages("err, couldn't resolve error at '%s'\n",
|
2024-07-30 15:47:35 +09:00
|
|
|
GetCaseSensitiveStringFromCommandToken(CommandTokens.at(1)).c_str());
|
2022-02-01 15:15:46 +03:30
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|