mirror of
https://github.com/eliboa/TegraRcmGUI.git
synced 2024-12-28 02:56:02 +00:00
Fixed : RC=-50 when injecting when app is launched at Win startup
Added : Auto kill existing app process(es) Added : Clean remaining keys from regestry (<v2.4)
This commit is contained in:
parent
9600f0d081
commit
56f3e05586
7 changed files with 184 additions and 84 deletions
|
@ -2,6 +2,7 @@
|
|||
#include <string>
|
||||
#include "TegraRcmGUIDlg.h"
|
||||
#include "TegraRcm.h"
|
||||
#include "afxole.h"
|
||||
|
||||
// DialogTab01 dialog
|
||||
|
||||
|
@ -19,7 +20,7 @@ public:
|
|||
#endif
|
||||
TCHAR* PAYLOAD_FILE;
|
||||
BOOL PREVENT_AUTOINJECT = TRUE;
|
||||
BOOL DELAY_AUTOINJECT = FALSE;
|
||||
BOOL DELAY_AUTOINJECT = TRUE;
|
||||
CArray <CString, CString> m_ListBox;
|
||||
int m_SelectedItem = -1;
|
||||
CFont m_BoldFont;
|
||||
|
@ -38,4 +39,5 @@ public:
|
|||
afx_msg void OnDblclkList1();
|
||||
afx_msg void OnLbnSelchangeList1();
|
||||
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
|
||||
COleDropTarget FileDropTarget;
|
||||
};
|
||||
|
|
|
@ -1,31 +1,3 @@
|
|||
/*
|
||||
DialogTab03.cpp
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright(c) 2018 eliboa
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "TegraRcmGUI.h"
|
||||
#include "DialogTab03.h"
|
||||
|
@ -55,6 +27,7 @@ void DialogTab03::DoDataExchange(CDataExchange* pDX)
|
|||
BOOL DialogTab03::OnInitDialog()
|
||||
{
|
||||
CDialog::OnInitDialog();
|
||||
CleanRegestry();
|
||||
|
||||
string value = m_TegraRcm->GetPreset("AUTO_INJECT");
|
||||
if (value == "TRUE")
|
||||
|
@ -72,25 +45,18 @@ BOOL DialogTab03::OnInitDialog()
|
|||
checkbox->SetCheck(BST_CHECKED);
|
||||
}
|
||||
|
||||
HKEY hKey;
|
||||
const std::string key = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
|
||||
const std::string subkey = "TegraRcmGUI";
|
||||
|
||||
// Open Run Registry location
|
||||
LONG lnRes = RegOpenKeyExA(HKEY_CURRENT_USER,
|
||||
key.c_str(), 0, KEY_READ, &hKey);
|
||||
|
||||
if (ERROR_SUCCESS == lnRes)
|
||||
TCHAR szPath[MAX_PATH];
|
||||
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, szPath)))
|
||||
{
|
||||
lnRes = RegQueryValueExA(hKey, subkey.c_str(), NULL, NULL, NULL, NULL);
|
||||
if (lnRes != ERROR_FILE_NOT_FOUND)
|
||||
{
|
||||
PathAppend(szPath, _T("\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\TegraRcmGUI.lnk"));
|
||||
std::ifstream infile(szPath);
|
||||
if (infile.good()) {
|
||||
infile.close();
|
||||
CMFCButton*checkbox = (CMFCButton*)GetDlgItem(RUN_WINSTART);
|
||||
checkbox->SetCheck(BST_CHECKED);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
// EXCEPTION: OCX Property Pages should return FALSE
|
||||
}
|
||||
|
@ -166,48 +132,72 @@ void DialogTab03::OnBnClickedWinstart()
|
|||
|
||||
// Get application absolute path
|
||||
TCHAR szPath[_MAX_PATH];
|
||||
VERIFY(::GetModuleFileName(AfxGetApp()->m_hInstance, szPath, _MAX_PATH));
|
||||
// Convert path to ANSI string
|
||||
int size = WideCharToMultiByte(CP_UTF8, 0, szPath, -1, NULL, 0, NULL, NULL);
|
||||
if (size > 0) {
|
||||
buffer.resize(size);
|
||||
WideCharToMultiByte(CP_UTF8, 0, szPath, -1, (LPSTR)(&buffer[0]), buffer.size(), NULL, NULL);
|
||||
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, szPath)))
|
||||
{
|
||||
// Remove shortcut
|
||||
PathAppend(szPath, _T("\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\TegraRcmGUI.lnk"));
|
||||
remove(CW2A(szPath));
|
||||
}
|
||||
std::string appPath(&buffer[0]);
|
||||
std::string keyValue;
|
||||
keyValue.append("\"");
|
||||
keyValue.append(appPath);
|
||||
keyValue.append("\" /autostart");
|
||||
|
||||
// Create new shortcut
|
||||
if (IsCheckChecked) CreateLink();
|
||||
}
|
||||
|
||||
|
||||
void DialogTab03::CreateLink()
|
||||
{
|
||||
TCHAR szAppPath[_MAX_PATH];
|
||||
VERIFY(::GetModuleFileName(AfxGetApp()->m_hInstance, szAppPath, _MAX_PATH));
|
||||
|
||||
TCHAR szPath[_MAX_PATH];
|
||||
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, szPath)))
|
||||
{
|
||||
PathAppend(szPath, _T("\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\TegraRcmGUI.lnk"));
|
||||
}
|
||||
CoInitializeEx(NULL, 0);
|
||||
HRESULT hres = 0;
|
||||
IShellLink* psl;
|
||||
if (SUCCEEDED(hres)) {
|
||||
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_ALL, IID_IShellLink, (LPVOID*)&psl);
|
||||
if (SUCCEEDED(hres)) {
|
||||
IPersistFile* ppf;
|
||||
|
||||
// Set the path to the shortcut target and add the description.
|
||||
psl->SetPath(szAppPath);
|
||||
psl->SetDescription(L"TegraRcmGUI");
|
||||
psl->SetIconLocation(szAppPath, 0);
|
||||
|
||||
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
|
||||
if (SUCCEEDED(hres)) {
|
||||
hres = ppf->Save(szPath, TRUE);
|
||||
ppf->Release();
|
||||
}
|
||||
psl->Release();
|
||||
}
|
||||
|
||||
}
|
||||
CoUninitialize();
|
||||
}
|
||||
|
||||
void DialogTab03::CleanRegestry() {
|
||||
HKEY hKey;
|
||||
const std::string key = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
|
||||
const std::string subkey = "TegraRcmGUI";
|
||||
|
||||
// Open Run Registry location
|
||||
LONG lnRes = RegOpenKeyEx(HKEY_CURRENT_USER,
|
||||
_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"),
|
||||
0L, KEY_WRITE,
|
||||
&hKey);
|
||||
LONG lnRes = RegOpenKeyExA(HKEY_CURRENT_USER,
|
||||
key.c_str(), 0, KEY_READ, &hKey);
|
||||
|
||||
if (ERROR_SUCCESS == lnRes)
|
||||
{
|
||||
if (IsCheckChecked)
|
||||
{
|
||||
// Set full application path with a keyname to registry
|
||||
lnRes = RegSetValueExA(hKey,
|
||||
key.c_str(),
|
||||
0,
|
||||
REG_SZ,
|
||||
(LPBYTE)(keyValue.c_str()),
|
||||
keyValue.size() + 1);
|
||||
}
|
||||
else
|
||||
lnRes = RegQueryValueExA(hKey, subkey.c_str(), NULL, NULL, NULL, NULL);
|
||||
if (lnRes != ERROR_FILE_NOT_FOUND)
|
||||
{
|
||||
//Remove regestry value
|
||||
lnRes = RegDeleteValueA(hKey, key.c_str());
|
||||
|
||||
// Create new shortcut
|
||||
CreateLink();
|
||||
}
|
||||
if (ERROR_SUCCESS != lnRes)
|
||||
{
|
||||
AfxMessageBox(_T("Failed to set/unset at startup"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AfxMessageBox(_T("Failed to access registry"));
|
||||
}
|
||||
}
|
|
@ -1,8 +1,27 @@
|
|||
#pragma once
|
||||
//#define _WIN32_DCOM
|
||||
//#include <comdef.h>
|
||||
//#include <taskschd.h>
|
||||
//#pragma comment(lib, "taskschd.lib")
|
||||
//#pragma comment(lib, "comsupp.lib")
|
||||
|
||||
#include <string>
|
||||
#include "TegraRcmGUIDlg.h"
|
||||
#include "TegraRcm.h"
|
||||
|
||||
#include "stdafx.h"
|
||||
#include <Windows.h>
|
||||
#include <shlobj.h>
|
||||
#include <winnls.h>
|
||||
#include <shobjidl.h>
|
||||
#include <objbase.h>
|
||||
#include <objidl.h>
|
||||
#include <shlguid.h>
|
||||
#include <atlbase.h>
|
||||
#include <atlconv.h>
|
||||
|
||||
|
||||
|
||||
// DialogTab03 dialog
|
||||
|
||||
class DialogTab03 : public CDialogEx
|
||||
|
@ -31,5 +50,7 @@ public:
|
|||
afx_msg void OnClickedMinToTray();
|
||||
afx_msg void OnBnClickedInstallDriver();
|
||||
afx_msg void OnBnClickedWinstart();
|
||||
void CreateLink();
|
||||
afx_msg void CleanRegestry();
|
||||
|
||||
};
|
||||
|
|
|
@ -453,7 +453,7 @@ void TegraRcm::AppendLog(string message)
|
|||
{
|
||||
|
||||
// DISABLED
|
||||
return;
|
||||
//return;
|
||||
|
||||
|
||||
// Get time
|
||||
|
@ -608,7 +608,6 @@ void TegraRcm::BitmapDisplay(int IMG)
|
|||
//
|
||||
void TegraRcm::LookUp()
|
||||
{
|
||||
|
||||
// Exit when PAUSE_LKP_DEVICE flag is TRUE
|
||||
if (PAUSE_LKP_DEVICE) return;
|
||||
|
||||
|
@ -646,7 +645,7 @@ void TegraRcm::LookUp()
|
|||
}
|
||||
|
||||
// On change RCM status
|
||||
if (rc != m_RC)
|
||||
if (rc != m_RC || m_RC == -99)
|
||||
{
|
||||
m_RC = rc;
|
||||
//CStatic*pCtrl0 = (CStatic*) m_Parent->GetDlgItem(RCM_PIC_4);
|
||||
|
@ -661,7 +660,12 @@ void TegraRcm::LookUp()
|
|||
m_Ctrltb1->GetDlgItem(PAYLOAD_PATH)->GetWindowTextW(file);
|
||||
|
||||
// Trigger auto inject if payload injection scheduled
|
||||
if (!FIRST_LOOKUP && DELAY_AUTOINJECT && file.GetLength() > 0)
|
||||
//if (!FIRST_LOOKUP && DELAY_AUTOINJECT && file.GetLength() > 0)
|
||||
if (FIRST_LOOKUP) {
|
||||
if(AUTOINJECT_CURR) DELAY_AUTOINJECT = TRUE;
|
||||
else DELAY_AUTOINJECT = FALSE;
|
||||
}
|
||||
if (DELAY_AUTOINJECT && file.GetLength() > 0)
|
||||
{
|
||||
|
||||
BitmapDisplay(LOADING);
|
||||
|
@ -763,18 +767,23 @@ int TegraRcm::Smasher(TCHAR args[])
|
|||
int rc = -50;
|
||||
if (NULL != ret)
|
||||
{
|
||||
AppendLog("Ret is not null");
|
||||
WaitForSingleObject(pi.hProcess, INFINITE);
|
||||
DWORD exit_code;
|
||||
if (FALSE != GetExitCodeProcess(pi.hProcess, &exit_code))
|
||||
{
|
||||
AppendLog("GetExitCodeProcess != FALSE");
|
||||
if (STILL_ACTIVE != exit_code)
|
||||
{
|
||||
rc = exit_code;
|
||||
AppendLog("Real exit code");
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = -52;
|
||||
AppendLog("RC = -52");
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -783,6 +792,9 @@ int TegraRcm::Smasher(TCHAR args[])
|
|||
CloseHandle(pi.hProcess);
|
||||
CloseHandle(pi.hThread);
|
||||
}
|
||||
else {
|
||||
AppendLog("Ret is null");
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
//
|
||||
|
@ -811,6 +823,75 @@ ULONGLONG TegraRcm::GetDllVersion(LPCTSTR lpszDllName)
|
|||
}
|
||||
return ullVersion;
|
||||
}
|
||||
|
||||
void TegraRcm::KillRunningProcess(CString process) {
|
||||
|
||||
CString compare;
|
||||
DWORD processID;
|
||||
DWORD currentProcessID = GetCurrentProcessId();
|
||||
bool procRunning = false;
|
||||
|
||||
HANDLE hProcessSnap;
|
||||
PROCESSENTRY32 pe32;
|
||||
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||
|
||||
if (hProcessSnap == INVALID_HANDLE_VALUE) {
|
||||
procRunning = false;
|
||||
}
|
||||
else {
|
||||
pe32.dwSize = sizeof(PROCESSENTRY32);
|
||||
if (Process32First(hProcessSnap, &pe32)) { // Gets first running process
|
||||
if (pe32.szExeFile == process) {
|
||||
procRunning = true;
|
||||
}
|
||||
else {
|
||||
// loop through all running processes looking for process
|
||||
while (Process32Next(hProcessSnap, &pe32)) {
|
||||
// Set to an AnsiString instead of Char[] to make compare easier
|
||||
compare = pe32.szExeFile;
|
||||
processID = pe32.th32ProcessID;
|
||||
if (compare == process && processID != currentProcessID) {
|
||||
// if found process is running, set to true and break from loop
|
||||
procRunning = true;
|
||||
HWND hProcess = find_main_window(processID);
|
||||
SendMessage(hProcess, WM_CLOSE, 0, 0);
|
||||
DWORD err = GetLastError();
|
||||
int test = 1;
|
||||
//break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// clean the snapshot object
|
||||
CloseHandle(hProcessSnap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct handle_data {
|
||||
unsigned long process_id;
|
||||
HWND window_handle;
|
||||
};
|
||||
BOOL CALLBACK enum_windows_callback(HWND handle, LPARAM lParam)
|
||||
{
|
||||
handle_data& data = *(handle_data*)lParam;
|
||||
unsigned long process_id = 0;
|
||||
GetWindowThreadProcessId(handle, &process_id);
|
||||
if (data.process_id != process_id)
|
||||
return TRUE;
|
||||
data.window_handle = handle;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
HWND TegraRcm::find_main_window(unsigned long process_id)
|
||||
{
|
||||
handle_data data;
|
||||
data.process_id = process_id;
|
||||
data.window_handle = 0;
|
||||
EnumWindows(enum_windows_callback, (LPARAM)&data);
|
||||
return data.window_handle;
|
||||
}
|
||||
|
||||
TCHAR* TegraRcm::GetAbsolutePath(TCHAR* relative_path, DWORD dwFlags)
|
||||
{
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <stdio.h>
|
||||
#include <Strsafe.h>
|
||||
#include "afxcmn.h"
|
||||
#include <tlhelp32.h>
|
||||
#pragma comment (lib, "setupapi.lib")
|
||||
|
||||
class TegraRcm
|
||||
|
@ -23,6 +24,7 @@ class TegraRcm
|
|||
public:
|
||||
TegraRcm(CDialog* pParent = NULL);
|
||||
~TegraRcm();
|
||||
|
||||
public:
|
||||
void InitCtrltbDlgs(CDialog* pCtrltb1, CDialog* pCtrltb2, CDialog* pCtrltb3);
|
||||
int GetRcmStatus();
|
||||
|
@ -42,6 +44,10 @@ public:
|
|||
int Smasher(TCHAR args[]);
|
||||
char* GetRelativeFilename(char *currentDirectory, char *absoluteFilename);
|
||||
|
||||
|
||||
void KillRunningProcess(CString process);
|
||||
HWND find_main_window(unsigned long process_id);
|
||||
|
||||
BOOL CmdShow = TRUE;
|
||||
// Notify Icon
|
||||
NOTIFYICONDATA m_NID;
|
||||
|
@ -58,7 +64,7 @@ public:
|
|||
|
||||
BOOL PAUSE_LKP_DEVICE = FALSE;
|
||||
BOOL AUTOINJECT_CURR = FALSE;
|
||||
BOOL DELAY_AUTOINJECT = FALSE;
|
||||
BOOL DELAY_AUTOINJECT = TRUE;
|
||||
BOOL WAITING_RECONNECT = FALSE;
|
||||
BOOL ASK_FOR_DRIVER = FALSE;
|
||||
BOOL MIN_TO_TRAY_CURR = FALSE;
|
||||
|
|
Binary file not shown.
|
@ -54,7 +54,7 @@ public:
|
|||
int RCM_STATUS = -10;
|
||||
BOOL WAITING_RECONNECT = FALSE;
|
||||
BOOL PREVENT_AUTOINJECT = TRUE;
|
||||
BOOL DELAY_AUTOINJECT = FALSE;
|
||||
BOOL DELAY_AUTOINJECT = TRUE;
|
||||
BOOL ASK_FOR_DRIVER = FALSE;
|
||||
BOOL PAUSE_LKP_DEVICE = FALSE;
|
||||
BOOL AUTOSTART = FALSE;
|
||||
|
|
Loading…
Reference in a new issue