Skip to content

Commit

Permalink
refactor: add error message (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeze-zeze authored Apr 7, 2024
1 parent decba8b commit 2acc955
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions exe/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,33 @@ int wmain()
vector<DWORD> pids;
listWslHosts(&pids);

wcout << "Found " << pids.size() << " WSL host" << endl;
wcout << "Found " << pids.size() << " wslhost/wslrelay" << endl;

int patchedCount = 0;
for (const auto& pid : pids)
{
HANDLE process = attachProcess(pid);
if (!process)
{
wcout << "Attach pid " << pid << " error: " << GetLastError() << endl;
continue;
}

auto injected = getInjectedModule(process, dllPath);
if (!injected.has_value())
{
return -1;
wcout << "getInjectedModule from pid " << pid << " error" << endl;
CloseHandle(process);
continue;
}

if (injected.value() == nullptr) {
injectProcess(process, dllPath);
if (!injectProcess(process, dllPath)) {
wcout << "Inject pid " << pid << " error" << endl;
CloseHandle(process);
continue;
}
}

CloseHandle(process);
patchedCount++;
}
Expand Down

0 comments on commit 2acc955

Please sign in to comment.