Skip to content

Commit 92c55ef

Browse files
committed
Bug fix
1 parent 86b5365 commit 92c55ef

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

HiJack/HiJack.cpp

+15-8
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ bool DebugProcess(DWORD unTimeout, bool* pbContinue, bool* pbStopped) {
684684
}
685685

686686
int _tmain(int argc, PTCHAR argv[], PTCHAR envp[]) {
687-
_tprintf_s(_T("HiJack [Version 1.0.0]\n\n"));
687+
_tprintf_s(_T("HiJack [Version 1.0.3]\n\n"));
688688

689689
if (argc < 2) {
690690
_tprintf_s(_T("Usage variations:\n"));
@@ -715,12 +715,12 @@ int _tmain(int argc, PTCHAR argv[], PTCHAR envp[]) {
715715
return EXIT_FAILURE;
716716
}
717717

718-
auto ProcessPath = GetProcessPath(GetCurrentProcess());
719-
if (ProcessPath.empty()) {
718+
PTCHAR szSelfProcessPath = NtCurrentTeb()->ProcessEnvironmentBlock->ProcessParameters->ImagePathName.Buffer;
719+
if (!szSelfProcessPath) {
720720
return EXIT_FAILURE;
721721
}
722722

723-
if (RegSetValueEx(hKey, _T("Debugger"), 0, REG_SZ, reinterpret_cast<const BYTE*>(ProcessPath.c_str()), (static_cast<DWORD>(ProcessPath.length()) + 1) * sizeof(TCHAR)) != ERROR_SUCCESS) {
723+
if (RegSetValueEx(hKey, _T("Debugger"), 0, REG_SZ, reinterpret_cast<const BYTE*>(szSelfProcessPath), (static_cast<DWORD>(_tcslen(szSelfProcessPath)) + 1) * sizeof(TCHAR)) != ERROR_SUCCESS) {
724724
_tprintf_s(_T("ERROR: RegSetValueEx (Error = 0x%08X)\n"), GetLastError());
725725
RegCloseKey(hKey);
726726
return EXIT_FAILURE;
@@ -747,23 +747,30 @@ int _tmain(int argc, PTCHAR argv[], PTCHAR envp[]) {
747747
}
748748

749749
HKEY hKey = nullptr;
750-
if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, szKey, NULL, nullptr, NULL, KEY_READ | KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS) {
750+
if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, szKey, NULL, nullptr, NULL, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS) {
751751
_tprintf_s(_T("ERROR: RegCreateKeyEx (Error = 0x%08X)\n"), GetLastError());
752752
return EXIT_FAILURE;
753753
}
754754

755755
RegDeleteValue(hKey, _T("Debugger"));
756+
RegCloseKey(hKey);
757+
758+
hKey = nullptr;
759+
if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, szKey, NULL, nullptr, NULL, KEY_READ, NULL, &hKey, NULL) != ERROR_SUCCESS) {
760+
_tprintf_s(_T("ERROR: RegCreateKeyEx (Error = 0x%08X)\n"), GetLastError());
761+
return EXIT_FAILURE;
762+
}
756763

757-
DWORD unKeysCount = 0;
758-
if (RegQueryInfoKey(hKey, nullptr, nullptr, nullptr, &unKeysCount, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr) != ERROR_SUCCESS) {
764+
DWORD unValuesCount = 0;
765+
if (RegQueryInfoKey(hKey, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, &unValuesCount, nullptr, nullptr, nullptr, nullptr) != ERROR_SUCCESS) {
759766
_tprintf_s(_T("ERROR: RegQueryInfoKey (Error = 0x%08X)\n"), GetLastError());
760767
RegCloseKey(hKey);
761768
return EXIT_SUCCESS;
762769
}
763770

764771
RegCloseKey(hKey);
765772

766-
if (!unKeysCount) {
773+
if (!unValuesCount) {
767774
if (RegDeleteKey(HKEY_LOCAL_MACHINE, szKey) != ERROR_SUCCESS) {
768775
_tprintf_s(_T("WARNING: RegDeleteKey (Error = 0x%08X)\n"), GetLastError());
769776
}

0 commit comments

Comments
 (0)