Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support Functions for Fuzzing Attached Processes and Fix a False Hang issue in attached processes #61

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
4 changes: 1 addition & 3 deletions Windows/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1742,8 +1742,6 @@ DebuggerStatus Debugger::Attach(unsigned int pid, uint32_t timeout) {

if (!DebugActiveProcess(pid)) {
DWORD error_code = GetLastError();


if(error_code == 5) {
HANDLE hToken = NULL;
LUID luid;
Expand Down Expand Up @@ -1822,7 +1820,7 @@ DebuggerStatus Debugger::Continue(uint32_t timeout) {

return dbg_last_status;
}

// initializes options from command line
void Debugger::Init(int argc, char **argv) {
have_thread_context = false;
Expand Down
2 changes: 1 addition & 1 deletion Windows/debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Debugger {
Exception GetLastException() {
return last_exception;
}

protected:

enum MemoryProtection {
Expand Down
28 changes: 28 additions & 0 deletions common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ limitations under the License.
#include <chrono>

#include "common.h"
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32)
#include <tlhelp32.h>
#endif
#include <iostream>
#include <string>
#include <codecvt>
#include <locale>

uint64_t GetCurTime(void) {
auto duration = std::chrono::system_clock::now().time_since_epoch();
Expand Down Expand Up @@ -96,6 +103,27 @@ int GetIntOption(const char *name, int argc, char** argv, int default_value) {
return (int)strtol(option, NULL, 0);
}

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32)
DWORD FindProcessId(char * process_name)
{
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);

HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);

if (Process32First(snapshot, &entry) == TRUE)
{
while (Process32Next(snapshot, &entry) == TRUE)
{
if (stricmp(entry.szExeFile, process_name) == 0)
{
CloseHandle(snapshot);
return entry.th32ProcessID;
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function should return something (zero?) if the process wasn't found.

}
#endif

//quoting on Windows is weird
size_t ArgvEscapeWindows(char *in, char *out) {
Expand Down
3 changes: 3 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ uint64_t GetCurTime(void);
char *GetOption(const char *name, int argc, char** argv);
void GetOptionAll(const char *name, int argc, char** argv, std::list<char *> *results);
bool GetBinaryOption(const char *name, int argc, char** argv, bool default_value);
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32)
DWORD FindProcessId(char * process_name);
#endif
int GetIntOption(const char *name, int argc, char** argv, int default_value);

char *ArgvToCmd(int argc, char** argv);
Expand Down