diff --git a/README.md b/README.md deleted file mode 100644 index 841dcac..0000000 --- a/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# TegraRcmGUI -A simple C++ GUI for [TegraRcmSmash](https://github.com/rajkosto/TegraRcmSmash) by [rajkosto](https://github.com/rajkosto). - -## Important notice -This application is just a GUI for the command line program ["TegraRcmSmash"](https://github.com/rajkosto/TegraRcmSmash) (all credits goes to @rajkosto & @ktemkin). -Please, *DO NOT* report issue on TegraRcmSmash GitHub if you're using this application => Report issue [here](https://github.com/eliboa/TegraRcmGUI/issues) *FIRST*. - -## Features -- Inject payloads, such as CFW loader -- Run Linux on your switch -- Mount SD as USB mass storage (hard reboot needed after unmounting device, hold power button down for 15sec) -- Auto inject option : automatically inject payload after selection or/and when the Switch is plugged in RCM mode (does not apply at startup) -- Install APX device driver (if needed) - -![Png](http://splatoon.eu/tuto_switch/TegraRcmGUI_v1.4.png) - -## Download -[Latest release](https://github.com/eliboa/TegraRcmGUI/releases) (Windows) - -## Credits -- [Kate Temkin](https://github.com/ktemkin) / Fusée Launcher -- [Rajkosto](https://github.com/rajkosto) / TegraRcmSmash (Fusée Launcher reimplementation for Windows), momeloader, SD tool -- [fail0verflow](https://github.com/fail0verflow) / ShofEL2 (Boot stack for no-modification, universal code execution and Linux on the Nintendo Switch) diff --git a/TegraRcmGUI.sln b/TegraRcmGUI.sln deleted file mode 100644 index e8a6474..0000000 --- a/TegraRcmGUI.sln +++ /dev/null @@ -1,40 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TegraRcmGUI", "TegraRcmGUI.vcxproj", "{2C091C5B-378F-44D0-91F2-53489BA7B83C}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - Static Debug|x64 = Static Debug|x64 - Static Debug|x86 = Static Debug|x86 - Static Release|x64 = Static Release|x64 - Static Release|x86 = Static Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {2C091C5B-378F-44D0-91F2-53489BA7B83C}.Debug|x64.ActiveCfg = Debug|x64 - {2C091C5B-378F-44D0-91F2-53489BA7B83C}.Debug|x64.Build.0 = Debug|x64 - {2C091C5B-378F-44D0-91F2-53489BA7B83C}.Debug|x86.ActiveCfg = Debug|Win32 - {2C091C5B-378F-44D0-91F2-53489BA7B83C}.Debug|x86.Build.0 = Debug|Win32 - {2C091C5B-378F-44D0-91F2-53489BA7B83C}.Release|x64.ActiveCfg = Release|x64 - {2C091C5B-378F-44D0-91F2-53489BA7B83C}.Release|x64.Build.0 = Release|x64 - {2C091C5B-378F-44D0-91F2-53489BA7B83C}.Release|x86.ActiveCfg = Release|Win32 - {2C091C5B-378F-44D0-91F2-53489BA7B83C}.Release|x86.Build.0 = Release|Win32 - {2C091C5B-378F-44D0-91F2-53489BA7B83C}.Static Debug|x64.ActiveCfg = Debug|x64 - {2C091C5B-378F-44D0-91F2-53489BA7B83C}.Static Debug|x64.Build.0 = Debug|x64 - {2C091C5B-378F-44D0-91F2-53489BA7B83C}.Static Debug|x86.ActiveCfg = Debug|Win32 - {2C091C5B-378F-44D0-91F2-53489BA7B83C}.Static Debug|x86.Build.0 = Debug|Win32 - {2C091C5B-378F-44D0-91F2-53489BA7B83C}.Static Release|x64.ActiveCfg = Release|x64 - {2C091C5B-378F-44D0-91F2-53489BA7B83C}.Static Release|x64.Build.0 = Release|x64 - {2C091C5B-378F-44D0-91F2-53489BA7B83C}.Static Release|x86.ActiveCfg = Release|Win32 - {2C091C5B-378F-44D0-91F2-53489BA7B83C}.Static Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/TegraRcmGUI.vcxproj.filters b/TegraRcmGUI.vcxproj.filters deleted file mode 100644 index e9bacd8..0000000 --- a/TegraRcmGUI.vcxproj.filters +++ /dev/null @@ -1,120 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Resource Files - - - - - Resource Files - - - - - Resource Files - - - Resource Files - - - Resource Files - - - Resource Files - - - Resource Files - - - Resource Files - - - Resource Files - - - Resource Files - - - Resource Files - - - Resource Files - - - Resource Files - - - \ No newline at end of file diff --git a/TegraRcmGUI.vcxproj.user b/TegraRcmGUI.vcxproj.user deleted file mode 100644 index abe8dd8..0000000 --- a/TegraRcmGUI.vcxproj.user +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/TegraRcmGUI/DialogTab01.cpp b/TegraRcmGUI/DialogTab01.cpp new file mode 100644 index 0000000..09f7862 --- /dev/null +++ b/TegraRcmGUI/DialogTab01.cpp @@ -0,0 +1,325 @@ +/* +DialogTab01.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 "DialogTab01.h" +#include "afxdialogex.h" + +using namespace std; + + +// DialogTab01 dialog + +IMPLEMENT_DYNAMIC(DialogTab01, CDialog) + +DialogTab01::DialogTab01(TegraRcm *pTegraRcm, CWnd* Parent /*=NULL*/) + : CDialog(ID_DIALOGTAB_01, Parent) +{ + m_TegraRcm = pTegraRcm; +} + +DialogTab01::~DialogTab01() +{ +} + + +BOOL DialogTab01::OnInitDialog() +{ + CDialog::OnInitDialog(); + + string pfile = m_TegraRcm->GetPreset("PAYLOAD_FILE"); + CString file(pfile.c_str()); + this->GetDlgItem(PAYLOAD_PATH)->SetWindowTextW(file); + + CButton* pBtn = (CButton*)GetDlgItem(IDC_BROWSE); + pBtn->ModifyStyle(0, BS_ICON); + HICON hIcn = (HICON)LoadImage( + AfxGetApp()->m_hInstance, + MAKEINTRESOURCE(ID_BROWSE_ICON), + IMAGE_ICON, + 24, 24, // use actual size + LR_DEFAULTCOLOR + ); + + pBtn->SetIcon(hIcn); + + pBtn = (CButton*)GetDlgItem(ID_ADD_FAV); + pBtn->ModifyStyle(0, BS_ICON); + hIcn = (HICON)LoadImage( + AfxGetApp()->m_hInstance, + MAKEINTRESOURCE(ID_ADD_ICON), + IMAGE_ICON, + 24, 24, // use actual size + LR_DEFAULTCOLOR + ); + pBtn->SetIcon(hIcn); + + pBtn = (CButton*)GetDlgItem(ID_DEL_FAV); + pBtn->ModifyStyle(0, BS_ICON); + hIcn = (HICON)LoadImage( + AfxGetApp()->m_hInstance, + MAKEINTRESOURCE(ID_DELETE_ICON), + IMAGE_ICON, + 24, 24, // use actual size + LR_DEFAULTCOLOR + ); + pBtn->SetIcon(hIcn); + + PREVENT_AUTOINJECT = FALSE; + + for (int i = 0; i < m_TegraRcm->Favorites.GetCount(); i++) + { + CListBox*pListBox = (CListBox*)GetDlgItem(IDC_LIST1); + + int nIndex = m_TegraRcm->Favorites[i].ReverseFind(_T('\\')); + if (nIndex > 0) + { + CString csFilename, csPath, Item; + csFilename = m_TegraRcm->Favorites[i].Right(m_TegraRcm->Favorites[i].GetLength() - nIndex - 1); + csPath = m_TegraRcm->Favorites[i].Left(nIndex); + Item = csFilename + _T(" (") + csPath + _T(")"); + pListBox->AddString(_tcsdup(Item)); + } + } + + CFont* pFont = GetFont(); + LOGFONT lf; + pFont->GetLogFont(&lf); + lf.lfWeight = FW_BOLD; + m_BoldFont.CreateFontIndirect(&lf); + + GetDlgItem(IDC_INJECT)->SendMessage(WM_SETFONT, WPARAM(HFONT(m_BoldFont)), 0); + + return TRUE; // return TRUE unless you set the focus to a control + // EXCEPTION: OCX Property Pages should return FALSE +} + +BEGIN_MESSAGE_MAP(DialogTab01, CDialog) + ON_BN_CLICKED(IDC_BROWSE, &DialogTab01::OnBnClickedBrowse) + ON_EN_CHANGE(PAYLOAD_PATH, &CTegraRcmGUIDlg::OnEnChangePath) + ON_BN_CLICKED(IDC_INJECT, &DialogTab01::InjectPayload) + ON_BN_CLICKED(ID_ADD_FAV, &DialogTab01::OnBnClickedAddFav) + ON_BN_CLICKED(ID_DEL_FAV, &DialogTab01::OnBnClickedDelFav) + ON_LBN_DBLCLK(IDC_LIST1, &DialogTab01::OnDblclkList1) + ON_LBN_SELCHANGE(IDC_LIST1, &DialogTab01::OnLbnSelchangeList1) + ON_WM_CTLCOLOR() +END_MESSAGE_MAP() + +// +// Auto-inject on change path +// +void DialogTab01::OnEnChangePath() +{ + CString file; + GetDlgItem(PAYLOAD_PATH)->GetWindowTextW(file); + PAYLOAD_FILE = _tcsdup(file); + + if (!PREVENT_AUTOINJECT) + { + // Save payload path + CT2CA pszConvertedAnsiString(file); + std::string file_c(pszConvertedAnsiString); + m_TegraRcm->SetPreset("PAYLOAD_FILE", file_c); + } + + string value = m_TegraRcm->GetPreset("AUTO_INJECT"); + TegraRcmSmash device; + int RCM_STATUS = device.RcmStatus(); + // If Auto inject option enabled + if (value == "TRUE" && !PREVENT_AUTOINJECT) + { + // Delay auto inject if RCM not detected + if (RCM_STATUS != 0) + { + DELAY_AUTOINJECT = TRUE; + m_TegraRcm->SendUserMessage("Injection scheduled. Waiting for device", VALID); + } + // Inject payload if RCM detected + else { + InjectPayload(); + } + } + PREVENT_AUTOINJECT = FALSE; +} +void DialogTab01::OnBnClickedBrowse() +{ + CString szFilter; + szFilter = "Bin files (*.bin)|*.bin|All files (*.*)|*.*||"; + + CFileDialog FileOpenDialog( + TRUE, + NULL, + NULL, + OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST, + szFilter, // filter + AfxGetMainWnd()); // the parent window + + CString file; + this->GetDlgItem(PAYLOAD_PATH)->GetWindowTextW(file); + FileOpenDialog.m_ofn.lpstrInitialDir = file; + + if (FileOpenDialog.DoModal() == IDOK) + { + CFile File; + VERIFY(File.Open(FileOpenDialog.GetPathName(), CFile::modeRead)); + CString Filename; + Filename = File.GetFilePath(); + this->GetDlgItem(PAYLOAD_PATH)->SetWindowTextW(Filename); + OnEnChangePath(); + } +} +void DialogTab01::InjectPayload() +{ + CString file; + this->GetDlgItem(PAYLOAD_PATH)->GetWindowTextW(file); + PAYLOAD_FILE = _tcsdup(file); + + if (PAYLOAD_FILE == nullptr) { + m_TegraRcm->BitmapDisplay(LOAD_ERROR); + m_TegraRcm->SendUserMessage("No file selected", INVALID); + return; + } + + std::ifstream infile(file); + if (!infile.good()) + { + m_TegraRcm->SendUserMessage("File doesn't exist", INVALID); + return; + } + + m_TegraRcm->BitmapDisplay(LOADING); + GetParent()->UpdateWindow(); + + TCHAR cmd[MAX_PATH] = TEXT("\""); + lstrcat(cmd, PAYLOAD_FILE); + lstrcat(cmd, TEXT("\"")); + + m_TegraRcm->SendUserMessage("Injecting payload..."); + int rc = m_TegraRcm->Smasher(cmd); + if (rc >= 0) + { + m_TegraRcm->BitmapDisplay(LOADED); + m_TegraRcm->SendUserMessage("Payload injected !", VALID); + m_TegraRcm->WAITING_RECONNECT = TRUE; + if (!m_TegraRcm->CmdShow) m_TegraRcm->ShowTrayIconBalloon(TEXT("Payload injected"), TEXT(" "), 1000, NIIF_INFO); + } + else + { + m_TegraRcm->BitmapDisplay(LOAD_ERROR); + string s = "Error while injecting payload (RC=" + std::to_string(rc) + ")"; + if (!m_TegraRcm->CmdShow) m_TegraRcm->ShowTrayIconBalloon(TEXT("Error"), TEXT("Error while injecting payload"), 1000, NIIF_ERROR); + m_TegraRcm->SendUserMessage(s.c_str(), INVALID); + + } +} + + +void DialogTab01::OnBnClickedAddFav() +{ + + CString csPath; + GetDlgItem(PAYLOAD_PATH)->GetWindowTextW(csPath); + std::ifstream infile(csPath); + if (!infile.good()) + { + m_TegraRcm->SendUserMessage("File doesn't exist", INVALID); + return; + } + + CListBox*pListBox = (CListBox*) GetDlgItem(IDC_LIST1); + CString csPathf(csPath), csFilename, Item; + int nIndex = csPathf.ReverseFind(_T('\\')); + if (nIndex > 0) csFilename = csPathf.Right(csPathf.GetLength() - nIndex - 1); + else return; + csPath = csPathf.Left(nIndex); + Item = csFilename + _T(" (") + csPath + _T(")"); + pListBox->AddString(_tcsdup(Item)); + m_ListBox.Add(csPathf); + m_TegraRcm->Favorites.Add(csPathf); + m_TegraRcm->SaveFavorites(); +} + + +void DialogTab01::OnBnClickedDelFav() +{ + + CListBox*pListBox = (CListBox*)GetDlgItem(IDC_LIST1); + int i = pListBox->GetCurSel(); + if (i >= 0) + { + pListBox->DeleteString(i); + m_TegraRcm->Favorites.RemoveAt(i); + m_TegraRcm->SaveFavorites(); + } +} + + +void DialogTab01::OnDblclkList1() +{ + if (m_SelectedItem >= 0) + { + CString fav = m_TegraRcm->Favorites.GetAt(m_SelectedItem); + GetDlgItem(PAYLOAD_PATH)->SetWindowTextW(fav); + GetDlgItem(PAYLOAD_PATH)->GetFocus(); + if (m_TegraRcm->GetPreset("AUTO_INJECT") != "TRUE" && m_TegraRcm->GetRcmStatus() == 0) + { + InjectPayload(); + } + else + { + OnEnChangePath(); + } + } +} + + +void DialogTab01::OnLbnSelchangeList1() +{ + CListBox*pListBox = (CListBox*)GetDlgItem(IDC_LIST1); + int i = pListBox->GetCurSel(); + if (i >= 0) + { + m_SelectedItem = i; + } +} + +HBRUSH DialogTab01::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) +{ + HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); + + switch (pWnd->GetDlgCtrlID()) + { + case ID_SELECT_PAYLOAD: + case ID_FAVORITES_TITLE: + pDC->SelectObject(&m_BoldFont); + break; + } + return hbr; +} diff --git a/TegraRcmGUI/DialogTab01.h b/TegraRcmGUI/DialogTab01.h new file mode 100644 index 0000000..404709f --- /dev/null +++ b/TegraRcmGUI/DialogTab01.h @@ -0,0 +1,41 @@ +#pragma once +#include +#include "TegraRcmGUIDlg.h" +#include "TegraRcm.h" + +// DialogTab01 dialog + +class DialogTab01 : + public CDialog +{ + DECLARE_DYNAMIC(DialogTab01) +public: + DialogTab01(TegraRcm *pTegraRcm, CWnd* Parent = NULL); // standard constructor + virtual ~DialogTab01(); + +// Dialog Data +#ifdef AFX_DESIGN_TIME + enum { IDD = ID_DIALOGTAB_01 }; +#endif + TCHAR* PAYLOAD_FILE; + BOOL PREVENT_AUTOINJECT = TRUE; + BOOL DELAY_AUTOINJECT = FALSE; + CArray m_ListBox; + int m_SelectedItem = -1; + CFont m_BoldFont; + virtual BOOL OnInitDialog(); + DECLARE_MESSAGE_MAP() + + afx_msg void OnEnChangePath(); + +private: + TegraRcm *m_TegraRcm; +public: + afx_msg void InjectPayload(); + afx_msg void OnBnClickedBrowse(); + afx_msg void OnBnClickedAddFav(); + afx_msg void OnBnClickedDelFav(); + afx_msg void OnDblclkList1(); + afx_msg void OnLbnSelchangeList1(); + afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor); +}; diff --git a/TegraRcmGUI/DialogTab02.cpp b/TegraRcmGUI/DialogTab02.cpp new file mode 100644 index 0000000..ca54d9b --- /dev/null +++ b/TegraRcmGUI/DialogTab02.cpp @@ -0,0 +1,229 @@ +/* +DialogTab02.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 "afxdialogex.h" +#include "DialogTab02.h" + + +using namespace std; + +// DialogTab02 dialog + +IMPLEMENT_DYNAMIC(DialogTab02, CDialogEx) + +DialogTab02::DialogTab02(TegraRcm *pTegraRcm, CWnd* Parent /*=NULL*/) + : CDialogEx(ID_DIALOGTAB_02, Parent) +{ + m_TegraRcm = pTegraRcm; +} + +DialogTab02::~DialogTab02() +{ +} + +void DialogTab02::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); +} + + +BEGIN_MESSAGE_MAP(DialogTab02, CDialogEx) + ON_BN_CLICKED(IDC_MOUNT_SD, &DialogTab02::OnBnClickedMountSd) + ON_BN_CLICKED(IDC_SHOFEL2, &DialogTab02::OnBnClickedShofel2) +// ON_WM_CTLCOLOR() +ON_WM_CTLCOLOR() +END_MESSAGE_MAP() + + +// DialogTab02 message handlers + +BOOL DialogTab02::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + CButton* pBtn = (CButton*)GetDlgItem(IDC_MOUNT_SD); + pBtn->ModifyStyle(0, BS_ICON); + HICON hIcn = (HICON)LoadImage( + AfxGetApp()->m_hInstance, + MAKEINTRESOURCE(ID_UMSTOOL_ICON), + IMAGE_ICON, + 32, 32, // use actual size + LR_DEFAULTCOLOR + ); + pBtn->SetIcon(hIcn); + + pBtn = (CButton*)GetDlgItem(IDC_SHOFEL2); + pBtn->ModifyStyle(0, BS_ICON); + hIcn = (HICON)LoadImage( + AfxGetApp()->m_hInstance, + MAKEINTRESOURCE(ID_LINUX_ICON), + IMAGE_ICON, + 32, 32, // use actual size + LR_DEFAULTCOLOR + ); + pBtn->SetIcon(hIcn); + + + CFont* pFont = GetFont(); + LOGFONT lf; + pFont->GetLogFont(&lf); + lf.lfWeight = FW_BOLD; + m_BoldFont.CreateFontIndirect(&lf); + + return TRUE; // return TRUE unless you set the focus to a control + // EXCEPTION: OCX Property Pages should return FALSE +} + +void DialogTab02::OnBnClickedMountSd() +{ + m_TegraRcm->BitmapDisplay(LOADING); + GetParent()->UpdateWindow(); + string s; + TCHAR args[] = TEXT("memloader\\memloader_usb.bin -r --dataini=memloader\\ums_sd.ini"); + int rc = m_TegraRcm->Smasher(args); + if (rc < 0) + { + m_TegraRcm->BitmapDisplay(LOAD_ERROR); + s = "Error while injecting payload (RC=" + std::to_string(rc) + ")"; + if (!m_TegraRcm->CmdShow) m_TegraRcm->ShowTrayIconBalloon(TEXT("Error"), TEXT("Error while injecting payload"), 1000, NIIF_ERROR); + } + else + { + m_TegraRcm->BitmapDisplay(LOADED); + s = "UMS Tool injected"; + if (!m_TegraRcm->CmdShow) m_TegraRcm->ShowTrayIconBalloon(TEXT("UMS Tool injected"), TEXT(" "), 1000, NIIF_INFO); + } + CA2T wt(s.c_str()); + GetParent()->SetDlgItemText(INFO_LABEL, wt); +} + + +void DialogTab02::OnBnClickedShofel2() +{ + TCHAR *exe_dir = m_TegraRcm->GetAbsolutePath(TEXT(""), CSIDL_APPDATA); + + string s; + TCHAR *COREBOOT_FILE = m_TegraRcm->GetAbsolutePath(TEXT("shofel2\\coreboot\\coreboot.rom"), CSIDL_APPDATA); + TCHAR *PAYLOAD = m_TegraRcm->GetAbsolutePath(TEXT("shofel2\\coreboot\\cbfs.bin"), CSIDL_APPDATA); + CString COREBOOT_FILE2 = COREBOOT_FILE; + CString COREBOOT = _T("CBFS+") + COREBOOT_FILE2; + + std::ifstream infile(COREBOOT_FILE); + BOOL coreboot_exists = infile.good(); + std::ifstream infile2(PAYLOAD); + BOOL payload_exists = infile2.good(); + + if (!coreboot_exists || !payload_exists) { + GetParent()->SetDlgItemText(INFO_LABEL, TEXT("Linux coreboot not found in \\shofel2 dir")); + CString message = _T("Kernel not found in shofel2 directory. Do you want to automatically download arch linux kernel from SoulCipher repo ?"); + const int result = MessageBox(message, _T("Kernel not found"), MB_YESNOCANCEL | MB_ICONQUESTION); + if (result == IDYES) + { + PROCESS_INFORMATION pif; + STARTUPINFO si; + ZeroMemory(&si, sizeof(si)); + si.cb = sizeof(si); + TCHAR *download_script = m_TegraRcm->GetAbsolutePath(TEXT("shofel2\\download.bat"), CSIDL_APPDATA); + BOOL bRet = CreateProcess(download_script, NULL, NULL, NULL, FALSE, 0, NULL, exe_dir, &si, &pif); + } + return; // TO-DO : Remove return for coreboot injection after download + } + m_TegraRcm->BitmapDisplay(LOADING); + GetParent()->UpdateWindow(); + GetParent()->SetDlgItemText(INFO_LABEL, TEXT("Loading coreboot. Please wait.")); + + //int rc = device.SmashMain(5, args); + TCHAR cmd[MAX_PATH] = TEXT("--relocator= \""); + lstrcat(cmd, _tcsdup(PAYLOAD)); + lstrcat(cmd, TEXT("\" \"CBFS:")); + lstrcat(cmd, _tcsdup(COREBOOT_FILE)); + lstrcat(cmd, TEXT("\"")); + int rc = m_TegraRcm->Smasher(cmd); + + if (rc >= 0 || rc < -7) + { + GetParent()->SetDlgItemText(INFO_LABEL, TEXT("Coreboot injected. Waiting 5s for device...")); + Sleep(5000); + + PROCESS_INFORMATION pif; + STARTUPINFO si; + ZeroMemory(&si, sizeof(si)); + si.cb = sizeof(si); + TCHAR *imx_script = m_TegraRcm->GetAbsolutePath(TEXT("shofel2\\imx_usb.bat"), CSIDL_APPDATA); + GetParent()->SetDlgItemText(INFO_LABEL, TEXT("Loading coreboot... Please wait.")); + BOOL ret = CreateProcess(imx_script, NULL, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, exe_dir, &si, &pif); + int rc = -50; + if (NULL != ret) + { + WaitForSingleObject(pif.hProcess, INFINITE); + DWORD exit_code; + if (FALSE != GetExitCodeProcess(pif.hProcess, &exit_code)) + { + if (STILL_ACTIVE != exit_code) rc = exit_code; + } + else rc = -51; + CloseHandle(pif.hProcess); + CloseHandle(pif.hThread); + } + + if (rc == 0) + { + m_TegraRcm->BitmapDisplay(LOADED); + s = "\nCoreboot loaded !"; + if (!m_TegraRcm->CmdShow) m_TegraRcm->ShowTrayIconBalloon(TEXT("Coreboot loaded "), TEXT(" "), 1000, NIIF_INFO); + } + else + { + m_TegraRcm->BitmapDisplay(LOAD_ERROR); + s = "Error while loading imx_usb.exe"; + if (!m_TegraRcm->CmdShow) m_TegraRcm->ShowTrayIconBalloon(TEXT("Error"), TEXT("Error while loading imx_usb.exe"), 1000, NIIF_ERROR); + } + } + else + { + s = "Error while injecting payload. (RC=" + std::to_string(rc) + ")"; + if (!m_TegraRcm->CmdShow) m_TegraRcm->ShowTrayIconBalloon(TEXT("Error"), TEXT("Error while injecting payload"), 1000, NIIF_ERROR); + } + CA2T wt2(s.c_str()); + GetParent()->SetDlgItemText(INFO_LABEL, wt2); +} + +HBRUSH DialogTab02::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) +{ + HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor); + + switch (pWnd->GetDlgCtrlID()) + { + case ID_UMSTOOL_TITLE: + case ID_LINUX_TITLE: + pDC->SelectObject(&m_BoldFont); + break; + } + return hbr; +} diff --git a/TegraRcmGUI/DialogTab02.h b/TegraRcmGUI/DialogTab02.h new file mode 100644 index 0000000..637001c --- /dev/null +++ b/TegraRcmGUI/DialogTab02.h @@ -0,0 +1,36 @@ +#pragma once +#include +#include "TegraRcmGUIDlg.h" +#include "TegraRcm.h" + + +// DialogTab02 dialog + +class DialogTab02 : + public CDialogEx +{ + DECLARE_DYNAMIC(DialogTab02) +public: + DialogTab02(TegraRcm *pTegraRcm, CWnd* pParent = NULL); // standard constructor + virtual ~DialogTab02(); + +// Dialog Data +#ifdef AFX_DESIGN_TIME + enum { IDD = ID_DIALOGTAB_02 }; +#endif + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + CFont m_BoldFont; + DECLARE_MESSAGE_MAP() +public: + afx_msg void OnBnClickedMountSd(); + afx_msg void OnBnClickedShofel2(); +private: + TegraRcm *m_TegraRcm; +public: + virtual BOOL OnInitDialog(); +// HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor); + + afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor); +}; diff --git a/TegraRcmGUI/DialogTab03.cpp b/TegraRcmGUI/DialogTab03.cpp new file mode 100644 index 0000000..504f624 --- /dev/null +++ b/TegraRcmGUI/DialogTab03.cpp @@ -0,0 +1,132 @@ +/* +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" +#include "afxdialogex.h" + + +// DialogTab03 dialog + +IMPLEMENT_DYNAMIC(DialogTab03, CDialogEx) + +DialogTab03::DialogTab03(TegraRcm *pTegraRcm, CWnd* Parent /*=NULL*/) + : CDialogEx(ID_DIALOGTAB_03, Parent) +{ + m_TegraRcm = pTegraRcm; +} + +DialogTab03::~DialogTab03() +{ +} + +void DialogTab03::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); +} + + +BOOL DialogTab03::OnInitDialog() +{ + CDialog::OnInitDialog(); + + string value = m_TegraRcm->GetPreset("AUTO_INJECT"); + if (value == "TRUE") + { + m_TegraRcm->AUTOINJECT_CURR = TRUE; + CMFCButton*checkbox = (CMFCButton*)GetDlgItem(AUTO_INJECT); + checkbox->SetCheck(BST_CHECKED); + } + + value = m_TegraRcm->GetPreset("MIN_TO_TRAY"); + if (value == "TRUE") + { + m_TegraRcm->MIN_TO_TRAY_CURR = TRUE; + CMFCButton*checkbox = (CMFCButton*)GetDlgItem(MIN_TO_TRAY); + checkbox->SetCheck(BST_CHECKED); + } + + return TRUE; // return TRUE unless you set the focus to a control + // EXCEPTION: OCX Property Pages should return FALSE +} + +BEGIN_MESSAGE_MAP(DialogTab03, CDialogEx) + ON_BN_CLICKED(AUTO_INJECT, &DialogTab03::OnClickedAutoInject) + ON_BN_CLICKED(MIN_TO_TRAY, &DialogTab03::OnClickedMinToTray) + ON_BN_CLICKED(ID_INSTALL_DRIVER, &DialogTab03::OnBnClickedInstallDriver) +END_MESSAGE_MAP() + + +// DialogTab03 message handlers + + +void DialogTab03::OnClickedAutoInject() +{ + // Get Auto inject checkbox value (checked, unchecked) + CButton *m_ctlCheck = (CButton*)GetDlgItem(AUTO_INJECT); + BOOL IsCheckChecked = (m_ctlCheck->GetCheck() == 1) ? true : false; + + if (m_TegraRcm->AUTOINJECT_CURR != IsCheckChecked) + { + // Auto inject option enabled + if (IsCheckChecked) + { + m_TegraRcm->SetPreset("AUTO_INJECT", "TRUE"); + m_TegraRcm->DELAY_AUTOINJECT = TRUE; + } + // Auto inject option disabled + else + { + m_TegraRcm->SetPreset("AUTO_INJECT", "FALSE"); + m_TegraRcm->DELAY_AUTOINJECT = FALSE; + } + // Save current checkbox value + m_TegraRcm->AUTOINJECT_CURR = IsCheckChecked; + } +} + + +void DialogTab03::OnClickedMinToTray() +{ + // Get Minimize to tray checkbox value (checked, unchecked) + CButton *m_ctlCheck = (CButton*)GetDlgItem(MIN_TO_TRAY); + BOOL IsCheckChecked = (m_ctlCheck->GetCheck() == 1) ? true : false; + if (m_TegraRcm->MIN_TO_TRAY_CURR != IsCheckChecked) + { + if (IsCheckChecked) m_TegraRcm->SetPreset("MIN_TO_TRAY", "TRUE"); + else m_TegraRcm->SetPreset("MIN_TO_TRAY", "FALSE"); + m_TegraRcm->MIN_TO_TRAY_CURR = IsCheckChecked; + } +} + + +void DialogTab03::OnBnClickedInstallDriver() +{ + m_TegraRcm->InstallDriver(); +} diff --git a/TegraRcmGUI/DialogTab03.h b/TegraRcmGUI/DialogTab03.h new file mode 100644 index 0000000..067efec --- /dev/null +++ b/TegraRcmGUI/DialogTab03.h @@ -0,0 +1,33 @@ +#pragma once +#include +#include "TegraRcmGUIDlg.h" +#include "TegraRcm.h" + +// DialogTab03 dialog + +class DialogTab03 : public CDialogEx +{ + DECLARE_DYNAMIC(DialogTab03) + +public: + DialogTab03(TegraRcm *pTegraRcm, CWnd* Parent = NULL); // standard constructor + virtual ~DialogTab03(); + +// Dialog Data +#ifdef AFX_DESIGN_TIME + enum { IDD = ID_DIALOGTAB_03 }; +#endif + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + + virtual BOOL OnInitDialog(); + DECLARE_MESSAGE_MAP() + +private: + TegraRcm *m_TegraRcm; +public: + afx_msg void OnClickedAutoInject(); + afx_msg void OnClickedMinToTray(); + afx_msg void OnBnClickedInstallDriver(); +}; diff --git a/TegraRcmGUI/MyTabCtrl.cpp b/TegraRcmGUI/MyTabCtrl.cpp new file mode 100644 index 0000000..79fe265 --- /dev/null +++ b/TegraRcmGUI/MyTabCtrl.cpp @@ -0,0 +1,72 @@ +#include "stdafx.h" +#include "MyTabCtrl.h" +#include "DialogTab01.h" +#include "DialogTab02.h" +#include "DialogTab03.h" +#include "resource.h" +using namespace std; + + +MyTabCtrl::MyTabCtrl() +{ + + m_DialogID[0] = ID_DIALOGTAB_01; + m_DialogID[1] = ID_DIALOGTAB_02; + m_DialogID[2] = ID_DIALOGTAB_03; + + m_nPageCount = 3; +} + + +MyTabCtrl::~MyTabCtrl() +{ +} + +BEGIN_MESSAGE_MAP(MyTabCtrl, CTabCtrl) + ON_NOTIFY_REFLECT(TCN_SELCHANGE, &MyTabCtrl::OnTcnSelchange) +END_MESSAGE_MAP() + +//This function creates the Dialog boxes once +void MyTabCtrl::InitDialogs(TegraRcm *parent) +{ + m_TegraRcm = parent; + m_Dialog[0] = new DialogTab01(m_TegraRcm); + m_Dialog[1] = new DialogTab02(m_TegraRcm); + m_Dialog[2] = new DialogTab03(m_TegraRcm); + m_Dialog[0]->Create(m_DialogID[0], GetParent()); + m_Dialog[1]->Create(m_DialogID[1], GetParent()); + m_Dialog[2]->Create(m_DialogID[2], GetParent()); +} + +void MyTabCtrl::OnTcnSelchange(NMHDR *pNMHDR, LRESULT *pResult) +{ + // TODO: Add your control notification handler code here + ActivateTabDialogs(); + *pResult = 0; +} + +void MyTabCtrl::ActivateTabDialogs() +{ + //ASSERT(MyParentDlg); + //.OnPaint(); + + int nSel = GetCurSel(); + if (m_Dialog[nSel]->m_hWnd) + m_Dialog[nSel]->ShowWindow(SW_HIDE); + + CRect l_rectClient; + CRect l_rectWnd; + + GetClientRect(l_rectClient); + AdjustRect(FALSE, l_rectClient); + GetWindowRect(l_rectWnd); + GetParent()->ScreenToClient(l_rectWnd); + l_rectClient.OffsetRect(l_rectWnd.left, l_rectWnd.top); + for (int nCount = 0; nCount < m_nPageCount; nCount++) { + m_Dialog[nCount]->SetWindowPos(&wndTop, l_rectClient.left, l_rectClient.top, l_rectClient.Width(), l_rectClient.Height(), SWP_HIDEWINDOW); + } + m_Dialog[nSel]->SetWindowPos(&wndTop, l_rectClient.left, l_rectClient.top, l_rectClient.Width(), l_rectClient.Height(), SWP_SHOWWINDOW); + + m_Dialog[nSel]->ShowWindow(SW_SHOW); + +} \ No newline at end of file diff --git a/TegraRcmGUI/MyTabCtrl.h b/TegraRcmGUI/MyTabCtrl.h new file mode 100644 index 0000000..bc1ddac --- /dev/null +++ b/TegraRcmGUI/MyTabCtrl.h @@ -0,0 +1,25 @@ +#pragma once +#include "afxcmn.h" +#include "TegraRcm.h" + +class MyTabCtrl : + public CTabCtrl +{ +public: + MyTabCtrl(); + ~MyTabCtrl(); + + //Array to hold the list of dialog boxes/tab pages for CTabCtrl + int m_DialogID[3]; + //CDialog Array Variable to hold the dialogs + CDialog *m_Dialog[3]; + int m_nPageCount; + //Function to Create the dialog boxes during startup + void InitDialogs(TegraRcm *parent); + + //Function to activate the tab dialog boxes + void ActivateTabDialogs(); + DECLARE_MESSAGE_MAP() + afx_msg void OnTcnSelchange(NMHDR *pNMHDR, LRESULT *pResult); + TegraRcm *m_TegraRcm; +}; diff --git a/ScopeGuard.h b/TegraRcmGUI/ScopeGuard.h similarity index 100% rename from ScopeGuard.h rename to TegraRcmGUI/ScopeGuard.h diff --git a/TegraRcmGUI/TegraRcm.cpp b/TegraRcmGUI/TegraRcm.cpp new file mode 100644 index 0000000..20f7900 --- /dev/null +++ b/TegraRcmGUI/TegraRcm.cpp @@ -0,0 +1,698 @@ +/* +TegraRcm.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 "TegraRcm.h" + +using namespace std; + +TegraRcm::TegraRcm(CDialog* pParent /*=NULL*/) +{ + m_Parent = pParent; + m_hWnd = AfxGetMainWnd()->GetSafeHwnd(); + GetFavorites(); + SendUserMessage("Waiting for device in RCM mode"); +} + +TegraRcm::~TegraRcm() +{ +} + +void TegraRcm::InitCtrltbDlgs(CDialog* pCtrltb1, CDialog* pCtrltb2, CDialog* pCtrltb3) +{ + m_Ctrltb1 = pCtrltb1; + m_Ctrltb2 = pCtrltb2; + m_Ctrltb3 = pCtrltb3; +} + +int TegraRcm::GetRcmStatus() +{ + return m_Device.RcmStatus(); +} + + +// +// Tray icon +// +BOOL TegraRcm::CreateTrayIcon() +{ + memset(&m_NID, 0, sizeof(m_NID)); + ULONGLONG ullVersion = GetDllVersion(_T("Shell32.dll")); + if (ullVersion >= MAKEDLLVERULL(5, 0, 0, 0)) + m_NID.cbSize = sizeof(NOTIFYICONDATA); + else m_NID.cbSize = NOTIFYICONDATA_V2_SIZE; + + // set tray icon ID + m_NID.uID = ID_SYSTEMTRAY; + + // set handle to the window that receives tray icon notifications + m_NID.hWnd = m_hWnd; + + // set message that will be sent from tray icon to the window + m_NID.uCallbackMessage = WM_SYSICON; + + // fields that are being set when adding tray icon + m_NID.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; + + // set image + if (m_RC >= 0) m_NID.hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(ID_TRAYICON_RCM)); + else m_NID.hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(ID_TRAYICON_NO_RCM)); + + if (!m_NID.hIcon) + return FALSE; + + if (!Shell_NotifyIcon(NIM_ADD, &m_NID)) + return FALSE; + + return Shell_NotifyIcon(NIM_SETVERSION, &m_NID); +} +BOOL TegraRcm::DestroyTrayIcon() +{ + return Shell_NotifyIcon(NIM_DELETE, &m_NID); +} +BOOL TegraRcm::SetTrayIconTipText(LPCTSTR pszText) +{ + if (StringCchCopy(m_NID.szTip, sizeof(m_NID.szTip), pszText) != S_OK) + return FALSE; + + m_NID.uFlags |= NIF_TIP; + return Shell_NotifyIcon(NIM_MODIFY, &m_NID); +} +BOOL TegraRcm::ShowTrayIconBalloon(LPCTSTR pszTitle, LPCTSTR pszText, UINT unTimeout, DWORD dwInfoFlags) +{ + m_NID.uFlags |= NIF_INFO; + m_NID.uTimeout = unTimeout; + m_NID.dwInfoFlags = dwInfoFlags; + + if (StringCchCopy(m_NID.szInfoTitle, sizeof(m_NID.szInfoTitle), pszTitle) != S_OK) + return FALSE; + + if (StringCchCopy(m_NID.szInfo, sizeof(m_NID.szInfo), pszText) != S_OK) + return FALSE; + + return Shell_NotifyIcon(NIM_MODIFY, &m_NID); +} +BOOL TegraRcm::SetTrayIcon(HICON hIcon) +{ + m_NID.hIcon = hIcon; + m_NID.uFlags |= NIF_ICON; + + return Shell_NotifyIcon(NIM_MODIFY, &m_NID); +} +BOOL TegraRcm::SetTrayIcon(WORD wIconID) +{ + HICON hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(wIconID)); + + if (!hIcon) + return FALSE; + + return SetTrayIcon(hIcon); +} +void TegraRcm::ShowContextMenu(HWND hWnd) +{ + POINT pt; + GetCursorPos(&pt); + HMENU hMenu = CreatePopupMenu(); + if (hMenu) + { + if (m_RC == 0) + { + CString csPathf, csFilename, payload; + m_Ctrltb1->GetDlgItem(PAYLOAD_PATH)->GetWindowTextW(csPathf); + int nIndex = csPathf.ReverseFind(_T('\\')); + if (nIndex > 0) + { + csFilename = csPathf.Right(csPathf.GetLength() - nIndex - 1); + payload = _T("Inject ") + csFilename; + InsertMenu(hMenu, -1, MF_BYPOSITION, SWM_INJECT, payload); + } + InsertMenu(hMenu, -1, MF_BYPOSITION, SWM_MOUNT, _T("Mount SD")); + InsertMenu(hMenu, -1, MF_BYPOSITION, SWM_LINUX, _T("Linux")); + InsertMenu(hMenu, -1, MF_BYPOSITION, SWM_BROWSE, _T("Browse...")); + } + if (IsWindowVisible(hWnd)) + InsertMenu(hMenu, -1, MF_BYPOSITION, SWM_HIDE, _T("Hide")); + else + InsertMenu(hMenu, -1, MF_BYPOSITION, SWM_SHOW, _T("Show")); + InsertMenu(hMenu, -1, MF_BYPOSITION, SWM_EXIT, _T("Exit")); + + // note: must set window to the foreground or the + // menu won't disappear when it should + SetForegroundWindow(hWnd); + + TrackPopupMenu(hMenu, TPM_BOTTOMALIGN, + pt.x, pt.y, 0, hWnd, NULL); + DestroyMenu(hMenu); + } +} +LRESULT TegraRcm::OnTrayIconEvent(UINT wParam, LPARAM lParam) +{ + if ((UINT)wParam != ID_SYSTEMTRAY) + { + int t = 1; + } + if ((UINT)wParam != ID_SYSTEMTRAY) + return ERROR_SUCCESS; + + switch ((UINT)lParam) + { + case WM_LBUTTONDOWN: + { + if (CmdShow) + { + AfxGetMainWnd()->ShowWindow(SW_HIDE); + CmdShow = FALSE; + } + else + { + AfxGetMainWnd()->ShowWindow(SW_RESTORE); + AfxGetMainWnd()->SetForegroundWindow(); + AfxGetMainWnd()->SetFocus(); + AfxGetMainWnd()->SetActiveWindow(); + CmdShow = TRUE; + } + break; + } + case WM_LBUTTONUP: + { + //ShowTrayIconBalloon(TEXT("Baloon message title"), TEXT("Left click!"), 1000, NIIF_INFO); + break; + } + case WM_RBUTTONUP: + { + ShowContextMenu(m_Parent->GetSafeHwnd()); + // e.g. show context menu or disable tip and display baloon: + //SetTrayIconTipText((LPCTSTR)TEXT("Salut")); + //ShowTrayIconBalloon(TEXT("Baloon message title"), TEXT("Right click!"), 1000, NIIF_INFO); + break; + } + + } + + return ERROR_SUCCESS; +} + + +// +// Presets functions +// +string TegraRcm::GetPreset(string param) +{ + TCHAR *rfile = GetAbsolutePath(TEXT("presets.conf"), CSIDL_APPDATA); + CT2A rfile_c(rfile, CP_UTF8); + TRACE(_T("UTF8: %S\n"), rfile_c.m_psz); + + ifstream readFile(rfile_c); + string readout; + string search = param + "="; + std::string value = ""; + if (readFile.is_open()) + { + while (getline(readFile, readout)) { + if (readout.find(search) != std::string::npos) { + std::string delimiter = "="; + value = readout.substr(readout.find(delimiter) + 1, readout.length() + 1); + } + } + } + readFile.close(); + return value; +} +void TegraRcm::SetPreset(string param, string value) +{ + TCHAR *rfile = GetAbsolutePath(TEXT("presets.conf"), CSIDL_APPDATA); + TCHAR *wfile = GetAbsolutePath(TEXT("presets.conf.tmp"), CSIDL_APPDATA); + CT2A rfile_c(rfile, CP_UTF8); + TRACE(_T("UTF8: %S\n"), rfile_c.m_psz); + CT2A wfile_c(wfile, CP_UTF8); + TRACE(_T("UTF8: %S\n"), wfile_c.m_psz); + + // Replace or create preset in file + ofstream outFile(wfile_c); + ifstream readFile(rfile_c); + string readout; + string search = param + "="; + string replace = search + value + "\n"; + BOOL found = FALSE; + while (getline(readFile, readout)) { + if (readout.find(search) != std::string::npos) { + outFile << replace; + found = TRUE; + } + else if(sizeof(readout)>0) { + outFile << readout + "\n"; + } + } + if (!found) { + outFile << replace; + } + outFile.close(); + readFile.close(); + remove(rfile_c); + rename(wfile_c, rfile_c); +} +void TegraRcm::GetFavorites() +{ + Favorites.RemoveAll(); + TCHAR *rfile = GetAbsolutePath(TEXT("favorites.conf"), CSIDL_APPDATA); + CT2A rfile_c(rfile, CP_UTF8); + TRACE(_T("UTF8: %S\n"), rfile_c.m_psz); + string readout; + ifstream readFile(rfile_c); + if (readFile.is_open()) { + while (getline(readFile, readout)) { + CString fav(readout.c_str(), readout.length()); + Favorites.Add(fav); + } + } +} +void TegraRcm::AddFavorite(CString value) +{ + CString CoutLine(value + _T('\n')); + CT2CA pszConvertedAnsiString(CoutLine); + std::string outLine = pszConvertedAnsiString; + fstream outFile; + outFile.open(GetAbsolutePath(TEXT("favorites.conf"), CSIDL_APPDATA), fstream::in | fstream::out | fstream::app); + outFile << outLine; + outFile.close(); +} +void TegraRcm::SaveFavorites() +{ + TCHAR *rfile = GetAbsolutePath(TEXT("favorites.conf"), CSIDL_APPDATA); + CT2A rfile_c(rfile, CP_UTF8); + TRACE(_T("UTF8: %S\n"), rfile_c.m_psz); + remove(rfile_c); + for (int i = 0; i < Favorites.GetCount(); i++) + { + AddFavorite(Favorites[i]); + } +} +// +// User message & log +// +void TegraRcm::AppendLog(string message) +{ + // Get time + char str[32]; + struct tm time_info; + time_t a = time(nullptr); + if (localtime_s(&time_info, &a) == 0) { + //strftime(str, sizeof(str), "%d-%m-%Y %I:%M:%S", &time_info); + strftime(str, sizeof(str), "%I:%M:%S", &time_info); + } + std::string current_time(str); + + // Format line + string outline; + outline = current_time + " : "; + outline += message; + outline += "\n"; + + // Append line in log file + fstream outFile; + outFile.open(GetAbsolutePath(TEXT("output_log.txt"), CSIDL_APPDATA), fstream::in | fstream::out | fstream::app); + outFile << outline; + outFile.close(); +} +void TegraRcm::SendUserMessage(string message, int type) +{ + CA2T wmessage(message.c_str()); + switch (type) { + case INVALID: + LabelColor = RGB(255, 0, 0); + break; + case VALID: + LabelColor = RGB(0, 150, 0); + break; + default: + LabelColor = RGB(0, 0, 0); + break; + } + AfxGetMainWnd()->SetDlgItemText(INFO_LABEL, wmessage); + AppendLog(message); +} + + +// +// Driver detection & installation +// +void TegraRcm::InstallDriver() +{ + if (ASK_FOR_DRIVER) return; + CString message = _T("APX device driver is missing. Do you want to install it now ?"); + const int result = MessageBox(m_hWnd, message, _T("APX driver not found !"), MB_YESNOCANCEL | MB_ICONQUESTION); + if (result == IDYES) + { + SHELLEXECUTEINFO shExInfo = { 0 }; + shExInfo.cbSize = sizeof(shExInfo); + shExInfo.fMask = SEE_MASK_NOCLOSEPROCESS; + shExInfo.hwnd = 0; + shExInfo.lpVerb = _T("runas"); + CString csPath; + TCHAR szPath[_MAX_PATH]; + VERIFY(::GetModuleFileName(AfxGetApp()->m_hInstance, szPath, _MAX_PATH)); + CString csPathf(szPath); + int nIndex = csPathf.ReverseFind(_T('\\')); + if (nIndex > 0) csPath = csPathf.Left(nIndex); + else csPath.Empty(); + CString exe_file = csPath + _T("\\apx_driver\\InstallDriver.exe"); + shExInfo.lpFile = exe_file; + shExInfo.lpDirectory = 0; + shExInfo.nShow = SW_SHOW; + shExInfo.hInstApp = 0; + + if (ShellExecuteEx(&shExInfo)) + { + CloseHandle(shExInfo.hProcess); + } + } + ASK_FOR_DRIVER = TRUE; +} +typedef int(__cdecl *MYPROC)(LPWSTR); +BOOL TegraRcm::LookForAPXDevice() +{ + unsigned index; + HDEVINFO hDevInfo; + SP_DEVINFO_DATA DeviceInfoData; + TCHAR HardwareID[1024]; + // List all connected USB devices + hDevInfo = SetupDiGetClassDevs(NULL, TEXT("USB"), NULL, DIGCF_PRESENT | DIGCF_ALLCLASSES); + for (index = 0; ; index++) { + DeviceInfoData.cbSize = sizeof(DeviceInfoData); + if (!SetupDiEnumDeviceInfo(hDevInfo, index, &DeviceInfoData)) { + return FALSE; // no match + } + SetupDiGetDeviceRegistryProperty(hDevInfo, &DeviceInfoData, SPDRP_HARDWAREID, NULL, (BYTE*)HardwareID, sizeof(HardwareID), NULL); + if (_tcsstr(HardwareID, _T("VID_0955&PID_7321"))) { + return TRUE; // match + } + } + return FALSE; +} + +void TegraRcm::BitmapDisplay(int IMG) +{ + // Init & bitmap pointers + CStatic*pRcm_not_detected = (CStatic*)AfxGetMainWnd()->GetDlgItem(RCM_PIC_1); + CStatic*pDriverKO = (CStatic*)AfxGetMainWnd()->GetDlgItem(RCM_PIC_2); + CStatic*pRcm_detected = (CStatic*)AfxGetMainWnd()->GetDlgItem(RCM_PIC_3); + CStatic*pInitLogo = (CStatic*)AfxGetMainWnd()->GetDlgItem(RCM_PIC_4); + CStatic*pLoading = (CStatic*)AfxGetMainWnd()->GetDlgItem(RCM_PIC_5); + CStatic*pLoaded = (CStatic*)AfxGetMainWnd()->GetDlgItem(RCM_PIC_6); + CStatic*pError = (CStatic*)AfxGetMainWnd()->GetDlgItem(RCM_PIC_7); + + pRcm_not_detected->ShowWindow(SW_HIDE); + pDriverKO->ShowWindow(SW_HIDE); + pRcm_detected->ShowWindow(SW_HIDE); + pInitLogo->ShowWindow(SW_HIDE); + pLoading->ShowWindow(SW_HIDE); + pLoaded->ShowWindow(SW_HIDE); + pError->ShowWindow(SW_HIDE); + + switch (IMG) + { + case INIT_LOGO: + pInitLogo->ShowWindow(SW_SHOW); + break; + case RCM_NOT_DETECTED: + pRcm_not_detected->ShowWindow(SW_SHOW); + break; + case DRIVER_KO: + pDriverKO->ShowWindow(SW_SHOW); + break; + case RCM_DETECTED: + pRcm_detected->ShowWindow(SW_SHOW); + break; + case LOADING: + pLoading->ShowWindow(SW_SHOW); + AfxGetMainWnd()->UpdateWindow(); + break; + case LOADED: + pLoaded->ShowWindow(SW_SHOW); + break; + case LOAD_ERROR: + pError->ShowWindow(SW_SHOW); + break; + default: + break; + } +} + +// +// Lookup +// +void TegraRcm::LookUp() +{ + + // Exit when PAUSE_LKP_DEVICE flag is TRUE + if (PAUSE_LKP_DEVICE) return; + + // Get RCM device Status + // This feature has been developped by Rajkosto (copied from TegraRcmSmash) + TegraRcmSmash device; + int rc = device.RcmStatus(); + + // RCM Status = "RCM detected" + if (rc >= 0) + { + m_Ctrltb1->GetDlgItem(IDC_INJECT)->EnableWindow(TRUE); + m_Ctrltb2->GetDlgItem(IDC_SHOFEL2)->EnableWindow(TRUE); + m_Ctrltb2->GetDlgItem(IDC_MOUNT_SD)->EnableWindow(TRUE); + m_Ctrltb3->GetDlgItem(ID_INSTALL_DRIVER)->EnableWindow(FALSE); + + } + // RCM Status = "USB Driver KO" + else if (rc > -5) + { + m_Ctrltb1->GetDlgItem(IDC_INJECT)->EnableWindow(FALSE); + m_Ctrltb2->GetDlgItem(IDC_SHOFEL2)->EnableWindow(FALSE); + m_Ctrltb2->GetDlgItem(IDC_MOUNT_SD)->EnableWindow(FALSE); + m_Ctrltb3->GetDlgItem(ID_INSTALL_DRIVER)->EnableWindow(TRUE); + } + // RCM Status = "RCM not detected" + else + { + m_Ctrltb1->GetDlgItem(IDC_INJECT)->EnableWindow(FALSE); + m_Ctrltb2->GetDlgItem(IDC_SHOFEL2)->EnableWindow(FALSE); + m_Ctrltb2->GetDlgItem(IDC_MOUNT_SD)->EnableWindow(FALSE); + m_Ctrltb3->GetDlgItem(ID_INSTALL_DRIVER)->EnableWindow(TRUE); + // Delay Auto inject if needed + if (AUTOINJECT_CURR) DELAY_AUTOINJECT = TRUE; + } + + // On change RCM status + if (rc != m_RC) + { + m_RC = rc; + CStatic*pCtrl0 = (CStatic*) m_Parent->GetDlgItem(RCM_PIC_4); + pCtrl0->ShowWindow(SW_HIDE); + + // Status changed to "RCM Detected" + if (rc == 0) + { + BitmapDisplay(RCM_DETECTED); + + CString file; + m_Ctrltb1->GetDlgItem(PAYLOAD_PATH)->GetWindowTextW(file); + + // Trigger auto inject if payload injection scheduled + if (!FIRST_LOOKUP && DELAY_AUTOINJECT && file.GetLength() > 0) + { + + BitmapDisplay(LOADING); + PAYLOAD_FILE = _tcsdup(file); + TCHAR cmd[MAX_PATH] = TEXT("\""); + lstrcat(cmd, PAYLOAD_FILE); + lstrcat(cmd, TEXT("\"")); + + int rc = Smasher(cmd); + if (rc >= 0) + { + BitmapDisplay(LOADED); + SendUserMessage("Payload injected !", VALID); + if (!CmdShow) ShowTrayIconBalloon(TEXT("Payload injected"), TEXT(" "), 1000, NIIF_INFO); + WAITING_RECONNECT = TRUE; + } + else + { + BitmapDisplay(LOAD_ERROR); + string s = "Error while injecting payload (RC=" + std::to_string(rc) + ")"; + CString error = TEXT("Error while injecting payload"); + if (!CmdShow) ShowTrayIconBalloon(TEXT("Error"), error, 1000, NIIF_ERROR); + SendUserMessage(s.c_str(), INVALID); + } + DELAY_AUTOINJECT = FALSE; + } + else + { + SendUserMessage("Waiting for user action"); + } + } + // Status changed to "RCM not detected" or "USB driver KO" + else + { + // Ask for driver install + if (rc > -5) + { + BitmapDisplay(DRIVER_KO); + InstallDriver(); + } + else + { + if (LookForAPXDevice()) + { + BitmapDisplay(DRIVER_KO); + InstallDriver(); + } + else + { + BitmapDisplay(RCM_NOT_DETECTED); + if (FIRST_LOOKUP) SendUserMessage("Waiting for device in RCM mode");; + } + } + } + // Status changed to "RCM not detected" -> Disable WAITING_RECONNECT flag + if (rc <= -5) WAITING_RECONNECT = FALSE; + + DestroyTrayIcon(); + CreateTrayIcon(); + } + m_RC = rc; + FIRST_LOOKUP = FALSE; +} + +// +// Smasher => TegraRcmSmash.exe calls +// +int TegraRcm::Smasher(TCHAR args[]) +{ + if (WAITING_RECONNECT) + { + CString message = _T("Payload already injected. Are you sure you want to overwrite the stack again ?"); + const int result = MessageBox(m_hWnd, message, _T("WARNING !"), MB_YESNOCANCEL | MB_ICONQUESTION); + if (result != IDYES) + { + DELAY_AUTOINJECT = FALSE; + m_RC = -99; + return -99; + } + WAITING_RECONNECT = FALSE; + } + + SECURITY_ATTRIBUTES sa; + sa.nLength = sizeof(sa); + sa.lpSecurityDescriptor = NULL; + sa.bInheritHandle = TRUE; + PROCESS_INFORMATION pi; + STARTUPINFO si; + BOOL ret = FALSE; + DWORD flags = CREATE_NO_WINDOW; + ZeroMemory(&pi, sizeof(PROCESS_INFORMATION)); + ZeroMemory(&si, sizeof(STARTUPINFO)); + si.cb = sizeof(STARTUPINFO); + si.dwFlags |= STARTF_USESTDHANDLES; + si.hStdInput = NULL; + TCHAR cmd[MAX_PATH] = TEXT(".\\TegraRcmSmash.exe "); + lstrcat(cmd, args); + ret = CreateProcess(NULL, cmd, NULL, NULL, TRUE, flags, NULL, NULL, &si, &pi); + int rc = -50; + if (NULL != ret) + { + WaitForSingleObject(pi.hProcess, INFINITE); + DWORD exit_code; + if (FALSE != GetExitCodeProcess(pi.hProcess, &exit_code)) + { + if (STILL_ACTIVE != exit_code) + { + rc = exit_code; + } + } + else + { + rc = -51; + } + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + } + return rc; +} +// +// System functions +// +ULONGLONG TegraRcm::GetDllVersion(LPCTSTR lpszDllName) +{ + ULONGLONG ullVersion = 0; + HINSTANCE hinstDll; + hinstDll = LoadLibrary(lpszDllName); + if (hinstDll) + { + DLLGETVERSIONPROC pDllGetVersion; + pDllGetVersion = (DLLGETVERSIONPROC)GetProcAddress(hinstDll, "DllGetVersion"); + if (pDllGetVersion) + { + DLLVERSIONINFO dvi; + HRESULT hr; + ZeroMemory(&dvi, sizeof(dvi)); + dvi.cbSize = sizeof(dvi); + hr = (*pDllGetVersion)(&dvi); + if (SUCCEEDED(hr)) + ullVersion = MAKEDLLVERULL(dvi.dwMajorVersion, dvi.dwMinorVersion, 0, 0); + } + FreeLibrary(hinstDll); + } + return ullVersion; +} +TCHAR* TegraRcm::GetAbsolutePath(TCHAR* relative_path, DWORD dwFlags) +{ + /* + // Get current directory + CString csPath; + TCHAR szPath[_MAX_PATH]; + VERIFY(::GetModuleFileName(AfxGetApp()->m_hInstance, szPath, _MAX_PATH)); + CString csPathf(szPath); + int nIndex = csPathf.ReverseFind(_T('\\')); + if (nIndex > 0) csPath = csPathf.Left(nIndex); + else csPath.Empty(); + CString csPath2; + csPath2 = csPath; + csPath2 += TEXT("\\"); + csPath2 += relative_path; + return _tcsdup(csPath2); + + */ + // USE THIS INSTEAD TO BUILD FOR MSI PACKAGER + + TCHAR szPath[MAX_PATH]; + + if (SUCCEEDED(SHGetFolderPath(NULL, dwFlags, NULL, SHGFP_TYPE_CURRENT, szPath))) + { + if (dwFlags == CSIDL_APPDATA) PathAppend(szPath, _T("\\TegraRcmGUI")); + PathAppend(szPath, relative_path); + return _tcsdup(szPath); + } + return _T(""); +} diff --git a/TegraRcmGUI/TegraRcm.h b/TegraRcmGUI/TegraRcm.h new file mode 100644 index 0000000..9a2a70f --- /dev/null +++ b/TegraRcmGUI/TegraRcm.h @@ -0,0 +1,85 @@ +#pragma once +#include +#include +#include +#include +#include +#pragma once +#include +#include +#include +#include +#include +#include "resource.h" +#include "TegraRcmSmash.h" +#include +#include +#include +#include "afxcmn.h" +#pragma comment (lib, "setupapi.lib") + +class TegraRcm +{ +public: + TegraRcm(CDialog* pParent = NULL); + ~TegraRcm(); +public: + void InitCtrltbDlgs(CDialog* pCtrltb1, CDialog* pCtrltb2, CDialog* pCtrltb3); + int GetRcmStatus(); + ULONGLONG GetDllVersion(LPCTSTR lpszDllName); + TCHAR* GetAbsolutePath(TCHAR* relative_path, DWORD dwFlags); + string GetPreset(string param); + void InstallDriver(); + BOOL LookForAPXDevice(); + void AppendLog(string message); + void SendUserMessage(string message, int type = NEUTRAL); + void SetPreset(string param, string value); + void GetFavorites(); + void AddFavorite(CString value); + void SaveFavorites(); + void BitmapDisplay(int IMG); + void LookUp(); + int Smasher(TCHAR args[]); + + BOOL CmdShow = TRUE; + // Notify Icon + NOTIFYICONDATA m_NID; + CPoint m_ptMouseHoverEvent; + + BOOL CreateTrayIcon(); + BOOL SetTrayIconTipText(LPCTSTR pszText); + BOOL ShowTrayIconBalloon(LPCTSTR pszTitle, LPCTSTR pszText, UINT unTimeout, DWORD dwInfoFlags); + BOOL SetTrayIcon(HICON hIcon); + BOOL SetTrayIcon(WORD wIconID); + void ShowContextMenu(HWND hWnd); + BOOL DestroyTrayIcon(); + LRESULT OnTrayIconEvent(UINT wParam, LPARAM lParam); + + BOOL PAUSE_LKP_DEVICE = FALSE; + BOOL AUTOINJECT_CURR = FALSE; + BOOL DELAY_AUTOINJECT = FALSE; + BOOL WAITING_RECONNECT = FALSE; + BOOL ASK_FOR_DRIVER = FALSE; + BOOL MIN_TO_TRAY_CURR = FALSE; + + CString csPath; + COLORREF LabelColor = RGB(0, 0, 0); + COLORREF WhiteRGB = RGB(255, 255, 255); + COLORREF BlackRGB = RGB(0, 0, 0); + COLORREF RedRGB = RGB(255, 0, 0); + COLORREF GreenRGB = RGB(0, 100, 0); + + TCHAR* PAYLOAD_FILE; + CArray Favorites; + CDialog* m_Parent; + CDialog* m_Ctrltb1; + CDialog* m_Ctrltb2; + CDialog* m_Ctrltb3; +private: + HWND m_hWnd; + TegraRcmSmash m_Device; + int m_RC = -99;; + BOOL FIRST_LOOKUP = TRUE; + +}; + diff --git a/TegraRcmGUI.cpp b/TegraRcmGUI/TegraRcmGUI.cpp similarity index 68% rename from TegraRcmGUI.cpp rename to TegraRcmGUI/TegraRcmGUI.cpp index 8c0e014..ba7c014 100644 --- a/TegraRcmGUI.cpp +++ b/TegraRcmGUI/TegraRcmGUI.cpp @@ -1,15 +1,38 @@ +/* +TegraRcmGUI.cpp -// TegraRcmGUI.cpp : Defines the class behaviors for the application. -// +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 "MyTabCtrl.h" #include "TegraRcmGUIDlg.h" #include "TegraRcmSmash.h" #include #include #include - using namespace std; diff --git a/TegraRcmGUI.h b/TegraRcmGUI/TegraRcmGUI.h similarity index 100% rename from TegraRcmGUI.h rename to TegraRcmGUI/TegraRcmGUI.h diff --git a/TegraRcmGUI.rc b/TegraRcmGUI/TegraRcmGUI.rc similarity index 57% rename from TegraRcmGUI.rc rename to TegraRcmGUI/TegraRcmGUI.rc index 6597c59..a4be1d3 100644 Binary files a/TegraRcmGUI.rc and b/TegraRcmGUI/TegraRcmGUI.rc differ diff --git a/TegraRcmGUI.vcxproj b/TegraRcmGUI/TegraRcmGUI.vcxproj similarity index 94% rename from TegraRcmGUI.vcxproj rename to TegraRcmGUI/TegraRcmGUI.vcxproj index 8a43572..76ec7e9 100644 --- a/TegraRcmGUI.vcxproj +++ b/TegraRcmGUI/TegraRcmGUI.vcxproj @@ -202,12 +202,17 @@ + + + + + @@ -216,6 +221,10 @@ + + + + Create @@ -223,6 +232,7 @@ Create Create + @@ -237,16 +247,25 @@ + + + + + + + + + diff --git a/TegraRcmGUI/TegraRcmGUIDlg.cpp b/TegraRcmGUI/TegraRcmGUIDlg.cpp new file mode 100644 index 0000000..2bcf314 --- /dev/null +++ b/TegraRcmGUI/TegraRcmGUIDlg.cpp @@ -0,0 +1,340 @@ +/* +TegraRcmGUIDlg.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 "afxdialogex.h" +#include "TegraRcmGUI.h" +#include "TegraRcmGUIDlg.h" +#include +#include + +using namespace std; + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +#define ARRAY_SIZE 1024 + +CString csPath; +CString csPath2; +ULONGLONG GetDllVersion(LPCTSTR lpszDllName); + +// +// dialog +// +CTegraRcmGUIDlg::CTegraRcmGUIDlg(CWnd* pParent /*=NULL*/) + : CDialog(IDD_TEGRARCMGUI_DIALOG, pParent) + , STATUS(0) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); +} +void CTegraRcmGUIDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + DDX_Control(pDX, RCM_PIC_1, RCM_BITMAP1); + DDX_Control(pDX, RCM_PIC_2, RCM_BITMAP2); + DDX_Control(pDX, RCM_PIC_3, RCM_BITMAP3); + DDX_Control(pDX, RCM_PIC_4, RCM_BITMAP0); + DDX_Control(pDX, RCM_PIC_5, RCM_BITMAP4); + DDX_Control(pDX, RCM_PIC_6, RCM_BITMAP5); + DDX_Control(pDX, RCM_PIC_7, RCM_BITMAP6); + DDX_Control(pDX, IDC_TAB_CONTROL, m_tbCtrl); +} +BEGIN_MESSAGE_MAP(CTegraRcmGUIDlg, CDialog) + ON_WM_CTLCOLOR() + ON_WM_TIMER() + ON_WM_SIZE() + ON_WM_SYSCOMMAND() + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_WM_SHOWWINDOW() + ON_WM_CLOSE() + ON_MESSAGE(WM_SYSICON, OnTrayIconEvent) + ON_COMMAND(SWM_EXIT, OnClose) + ON_COMMAND(SWM_SHOW, ShowWindowCommand) + ON_COMMAND(SWM_HIDE, HideWindowCommand) + ON_COMMAND(SWM_INJECT, InjectCommand) + ON_COMMAND(SWM_BROWSE, BrowseCommand) + ON_COMMAND(SWM_LINUX, LinuxCommand) + ON_COMMAND(SWM_MOUNT, MountCommand) +END_MESSAGE_MAP() + +// +// message handlers +// +BOOL CTegraRcmGUIDlg::OnInitDialog() +{ + CDialog::OnInitDialog(); + + // Accessibility + EnableActiveAccessibility(); + + // Get current directory + TCHAR szPath[_MAX_PATH]; + VERIFY(::GetModuleFileName(AfxGetApp()->m_hInstance, szPath, _MAX_PATH)); + CString csPathf(szPath); + int nIndex = csPathf.ReverseFind(_T('\\')); + if (nIndex > 0) csPath = csPathf.Left(nIndex); + else csPath.Empty(); + + // Initialize bitmap + RCM_BITMAP0.SetBitmap(INIT_LOGO); + RCM_BITMAP1.SetBitmap(RCM_NOT_DETECTED); + RCM_BITMAP2.SetBitmap(DRIVER_KO); + RCM_BITMAP3.SetBitmap(RCM_DETECTED); + RCM_BITMAP4.SetBitmap(LOADING); + RCM_BITMAP5.SetBitmap(LOADED); + RCM_BITMAP6.SetBitmap(LOAD_ERROR); + + // Menu + ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); + ASSERT(IDM_ABOUTBOX < 0xF000); + CMenu* pSysMenu = GetSystemMenu(FALSE); + if (pSysMenu != NULL) + { + BOOL bNameValid; + CString strAboutMenu; + bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX); + ASSERT(bNameValid); + if (!strAboutMenu.IsEmpty()) + { + pSysMenu->AppendMenu(MF_SEPARATOR); + pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); + } + } + + // Set icons + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + m_TegraRcm = new TegraRcm(this); + m_tbCtrl.InitDialogs(m_TegraRcm); + + TCITEM tcItem1; + tcItem1.mask = TCIF_TEXT; + tcItem1.pszText = _T("Payload"); + m_tbCtrl.InsertItem(0, &tcItem1); + + TCITEM tcItem2; + tcItem2.mask = TCIF_TEXT; + tcItem2.pszText = _T("Tools"); + m_tbCtrl.InsertItem(1, &tcItem2); + + TCITEM tcItem3; + tcItem3.mask = TCIF_TEXT; + tcItem3.pszText = _T("Settings"); + + m_tbCtrl.InsertItem(2, &tcItem3); + m_tbCtrl.ActivateTabDialogs(); + + m_TegraRcm->InitCtrltbDlgs(m_tbCtrl.m_Dialog[0], m_tbCtrl.m_Dialog[1], m_tbCtrl.m_Dialog[2]); + + m_TegraRcm->BitmapDisplay(INIT_LOGO); + + // Tray icon + m_TegraRcm->CreateTrayIcon(); + m_TegraRcm->SetTrayIconTipText(TEXT("TegraRcmGUI")); + + // Start timer to check RCM status every second + CTegraRcmGUIDlg::StartTimer(); + + + + return TRUE; +} +void CTegraRcmGUIDlg::OnSysCommand(UINT nID, LPARAM lParam) +{ + CDialog::OnSysCommand(nID, lParam); +} +void CTegraRcmGUIDlg::OnShowWindow(BOOL bShow, UINT nStatus) +{ + //CmdShow = bShow; + //CDialog::OnShowWindow(bShow, nStatus); +} +HBRUSH CTegraRcmGUIDlg::OnCtlColor(CDC* pDC, CWnd *pWnd, UINT nCtlColor) +{ + switch (nCtlColor) + { + case CTLCOLOR_STATIC: + if (GetDlgItem(IDC_RAJKOSTO)->GetSafeHwnd() == pWnd->GetSafeHwnd() || GetDlgItem(SEPARATOR)->GetSafeHwnd() == pWnd->GetSafeHwnd()) + { + pDC->SetTextColor(RGB(192, 192, 192)); + pDC->SetBkMode(TRANSPARENT); + return (HBRUSH)GetStockObject(NULL_BRUSH); + } + if (GetDlgItem(INFO_LABEL)->GetSafeHwnd() == pWnd->GetSafeHwnd()) + { + pDC->SetBkMode(TRANSPARENT); + pDC->SetTextColor(m_TegraRcm->LabelColor); + return (HBRUSH) CreateSolidBrush( WhiteRGB ); + } + if (GetDlgItem(IDC_STATUS_BG)->GetSafeHwnd() == pWnd->GetSafeHwnd()) + { + return (HBRUSH)CreateSolidBrush(WhiteRGB); + } + default: + return CDialog::OnCtlColor(pDC, pWnd, nCtlColor); + } +} +void CTegraRcmGUIDlg::OnPaint() +{ + + if (IsIconic()) + { + CPaintDC dc(this); // device context for painting + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); + + // Center icon in client rectangle + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // Draw the icon + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialog::OnPaint(); + } +} +HCURSOR CTegraRcmGUIDlg::OnQueryDragIcon() +{ + return static_cast(m_hIcon); +} +void CTegraRcmGUIDlg::OnSize(UINT nType, int cx, int cy) +{ + if (nType == SIZE_MINIMIZED) + { + if (m_TegraRcm->MIN_TO_TRAY_CURR) + { + ShowWindow(SW_HIDE); + } + if (m_TegraRcm != NULL) + { + m_TegraRcm->CmdShow = FALSE; + } + } + else + { + if (m_TegraRcm != NULL) m_TegraRcm->CmdShow = TRUE; + //ShowWindow(SW_RESTORE); + } +} +void CTegraRcmGUIDlg::OnClose() +{ + m_TegraRcm->DestroyTrayIcon(); + PostQuitMessage(0); +} + +LRESULT CTegraRcmGUIDlg::OnTrayIconEvent(UINT wParam, LPARAM lParam) +{ + return m_TegraRcm->OnTrayIconEvent(wParam, lParam); +} +void CTegraRcmGUIDlg::ShowWindowCommand() +{ + ShowWindow(SW_RESTORE); + SetForegroundWindow(); + SetFocus(); + SetActiveWindow(); + if (m_TegraRcm != NULL) + { + m_TegraRcm->CmdShow = TRUE; + } +} +void CTegraRcmGUIDlg::HideWindowCommand() +{ + ShowWindow(SW_HIDE); + if (m_TegraRcm != NULL) + { + m_TegraRcm->CmdShow = FALSE; + } +} +void CTegraRcmGUIDlg::InjectCommand() +{ + if (m_TegraRcm != NULL) + { + DialogTab01 *pt = (DialogTab01*) m_TegraRcm->m_Ctrltb1; + pt->InjectPayload(); + } +} +void CTegraRcmGUIDlg::BrowseCommand() +{ + if (m_TegraRcm != NULL) + { + DialogTab01 *pt = (DialogTab01*)m_TegraRcm->m_Ctrltb1; + pt->OnBnClickedBrowse(); + } +} +void CTegraRcmGUIDlg::LinuxCommand() +{ + if (m_TegraRcm != NULL) + { + DialogTab02 *pt = (DialogTab02*)m_TegraRcm->m_Ctrltb2; + pt->OnBnClickedShofel2(); + } +} +void CTegraRcmGUIDlg::MountCommand() +{ + if (m_TegraRcm != NULL) + { + DialogTab02 *pt = (DialogTab02*)m_TegraRcm->m_Ctrltb2; + pt->OnBnClickedMountSd(); + } +} + + +void CTegraRcmGUIDlg::StartTimer() +{ + // Set timer for Minutes. + //SetTimer(ID_TIMER_MINUTE, 60 * 1000, 0); + // Set timer for Seconds. + SetTimer(ID_TIMER_SECONDS, 1000, 0); +} +void CTegraRcmGUIDlg::StopTimer() +{ + // Stop both timers. + KillTimer(ID_TIMER_MINUTE); + KillTimer(ID_TIMER_SECONDS); +} +void CTegraRcmGUIDlg::OnTimer(UINT nIDEvent) +{ + // Each second + if (nIDEvent == ID_TIMER_SECONDS) + { + m_TegraRcm->LookUp(); + } +} + +void CTegraRcmGUIDlg::OnEnChangePath() +{ + int test = 1; +} diff --git a/TegraRcmGUIDlg.h b/TegraRcmGUI/TegraRcmGUIDlg.h similarity index 54% rename from TegraRcmGUIDlg.h rename to TegraRcmGUI/TegraRcmGUIDlg.h index b322cd7..da96cdc 100644 --- a/TegraRcmGUIDlg.h +++ b/TegraRcmGUI/TegraRcmGUIDlg.h @@ -1,13 +1,14 @@ - // TegraRcmGUIDlg.h : header file // #pragma once #include "res/BitmapPicture.h" +#include "resource.h" #include #include "TegraRcmSmash.h" #include "res/BitmapPicture.h" #include #include +#include #include #include #include @@ -17,19 +18,27 @@ #include #include #include +#include +#include +#include +#include "afxcmn.h" +#include "MyTabCtrl.h" +#include "TegraRcm.h" +#include "DialogTab01.h" +#include "DialogTab02.h" -#include -#pragma comment (lib, "setupapi.lib") -#include +#pragma comment (lib, "setupapi.lib") // CTegraRcmGUIDlg dialog -class CTegraRcmGUIDlg : public CDialog +class CTegraRcmGUIDlg : + public CDialog { // Construction public: CTegraRcmGUIDlg(CWnd* pParent = NULL); // standard constructor + CBitmapPicture RCM_BITMAP0; CBitmapPicture RCM_BITMAP1; CBitmapPicture RCM_BITMAP2; @@ -37,7 +46,27 @@ class CTegraRcmGUIDlg : public CDialog CBitmapPicture RCM_BITMAP4; CBitmapPicture RCM_BITMAP5; CBitmapPicture RCM_BITMAP6; + HICON StatusIcon; CMFCEditBrowseCtrl m_EditBrowse; + + BOOL AUTOINJECT_CURR = FALSE; + TCHAR* PAYLOAD_FILE; + int RCM_STATUS = -10; + BOOL WAITING_RECONNECT = FALSE; + BOOL PREVENT_AUTOINJECT = TRUE; + BOOL DELAY_AUTOINJECT = FALSE; + BOOL ASK_FOR_DRIVER = FALSE; + BOOL PAUSE_LKP_DEVICE = FALSE; + BOOL CmdShow; + COLORREF LabelColor = RGB(0, 0, 0); + COLORREF WhiteRGB = RGB(255, 255, 255); + COLORREF BlackRGB = RGB(0, 0, 0); + COLORREF RedRGB = RGB(255, 0, 0); + COLORREF GreenRGB = RGB(0, 100, 0); + + const UINT ID_TIMER_MINUTE = 0x1001; + const UINT ID_TIMER_SECONDS = 0x1000; + // Dialog Data #ifdef AFX_DESIGN_TIME enum { IDD = IDD_TEGRARCMGUI_DIALOG }; @@ -46,18 +75,23 @@ class CTegraRcmGUIDlg : public CDialog protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - // Implementation -protected: + HICON m_hIcon; + // Generated message map functions virtual BOOL OnInitDialog(); afx_msg void OnSysCommand(UINT nID, LPARAM lParam); afx_msg void OnIdle(); - afx_msg void OnShowWindow(); + afx_msg void OnShowWindow(BOOL bShow, UINT nStatus); afx_msg void OnPaint(); + afx_msg void OnClose(); + afx_msg void OnSize(UINT nType, int cx, int cy); afx_msg HCURSOR OnQueryDragIcon(); + afx_msg void OnDestroy(); + afx_msg LRESULT OnTrayIconEvent(UINT wParam, LPARAM lParam); DECLARE_MESSAGE_MAP() + public: void StartTimer(); void StopTimer(); @@ -65,14 +99,15 @@ class CTegraRcmGUIDlg : public CDialog int STATUS; afx_msg void BitmapDisplay(int IMG); afx_msg void OnEnChangePath(); - afx_msg void InjectPayload(); - afx_msg void OnBnClickedShofel2(); - afx_msg string GetPreset(string param); - afx_msg void SetPreset(string param, string value); - afx_msg void InstallDriver(); - afx_msg BOOL LookForAPXDevice(); - afx_msg void OnBnClickedMountSd(); - afx_msg int Smasher(TCHAR args[]); - afx_msg TCHAR* GetAbsolutePath(TCHAR *relative_path, DWORD dwFlags); afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd *pWnd, UINT nCtlColor); + void ShowWindowCommand(); + void HideWindowCommand(); + void InjectCommand(); + void BrowseCommand(); + void LinuxCommand(); + void MountCommand(); + CTegraRcmGUIDlg *m_pMainWnd = this; +private: + MyTabCtrl m_tbCtrl; + TegraRcm *m_TegraRcm; }; diff --git a/TegraRcmSmash.cpp b/TegraRcmGUI/TegraRcmSmash.cpp similarity index 78% rename from TegraRcmSmash.cpp rename to TegraRcmGUI/TegraRcmSmash.cpp index 74d2373..7c275b8 100644 --- a/TegraRcmSmash.cpp +++ b/TegraRcmGUI/TegraRcmSmash.cpp @@ -225,8 +225,7 @@ TegraRcmSmash::~TegraRcmSmash() { } - -int TegraRcmSmash::RcmStatus() +int TegraRcmSmash::Test() { KLST_DEVINFO_HANDLE deviceInfo = nullptr; @@ -294,8 +293,100 @@ int TegraRcmSmash::RcmStatus() // Wrong USB driver version return -1; } + + ByteVector readBuffer(32768, 0); + for (int i = 0; i <= 100; i++) + { + int bytesRead = 0; + if ((bytesRead = rcmDev.read(&readBuffer[0], readBuffer.size())) > 0) + { + static const char READY_INDICATOR[] = "READY.\n"; + if (bytesRead == array_countof(READY_INDICATOR) - 1 && memcmp(&readBuffer[0], READY_INDICATOR, array_countof(READY_INDICATOR) - 1) == 0) + { + int bytesSent = rcmDev.write((const u8*)"RECV", strlen("RECV")); + if (bytesSent == strlen("RECV")) + { + return 0; + } + } + } + } + + } + + return 0; +} + + +int TegraRcmSmash::RcmStatus() +{ + KLST_DEVINFO_HANDLE deviceInfo = nullptr; + + KLST_HANDLE deviceList = nullptr; + if (!LstK_Init(&deviceList, KLST_FLAG_NONE)) + { + const auto errorCode = GetLastError(); + // Win32 error trying to list USB devices + return -6; + } + auto lstKgrd = MakeScopeGuard([&deviceList]() + { + if (deviceList != nullptr) + { + LstK_Free(deviceList); + deviceList = nullptr; + } + }); + + // Get the number of devices contained in the device list. + UINT deviceCount = 0; + LstK_Count(deviceList, &deviceCount); + + if (deviceCount == 0 || LstK_FindByVidPid(deviceList, deviceVid, devicePid, &deviceInfo) == FALSE) + { + // No device found in RCM Mode + return -5; } + if (deviceInfo != nullptr) + { + if (deviceInfo->DriverID != KUSB_DRVID_LIBUSBK) + { + /* + Wrong driver => need to install libusbK driver + */ + return -4; + } + + KUSB_DRIVER_API Usb; + LibK_LoadDriverAPI(&Usb, deviceInfo->DriverID); + + // Initialize the device + KUSB_HANDLE handle = nullptr; + if (!Usb.Init(&handle, deviceInfo)) + { + const auto errorCode = GetLastError(); + // Failed to handle device + return -3; + } + + RCMDeviceHacker rcmDev(Usb, handle); handle = nullptr; + + libusbk::version_t usbkVersion; + memset(&usbkVersion, 0, sizeof(usbkVersion)); + const auto versRetVal = rcmDev.getDriverVersion(usbkVersion); + if (versRetVal <= 0) + { + // Failed to get USB driver version + return -2; + } + else if (usbkVersion.major != 3 || usbkVersion.minor != 0 || usbkVersion.micro != 7) + { + + // Wrong USB driver version + return -1; + } + } return 0; } \ No newline at end of file diff --git a/TegraRcmSmash.h b/TegraRcmGUI/TegraRcmSmash.h similarity index 94% rename from TegraRcmSmash.h rename to TegraRcmGUI/TegraRcmSmash.h index c5b3de6..3902adf 100644 --- a/TegraRcmSmash.h +++ b/TegraRcmGUI/TegraRcmSmash.h @@ -18,5 +18,7 @@ class TegraRcmSmash TegraRcmSmash(); ~TegraRcmSmash(); static int RcmStatus(); + static int Test(); + }; diff --git a/Types.h b/TegraRcmGUI/Types.h similarity index 100% rename from Types.h rename to TegraRcmGUI/Types.h diff --git a/Win32Def.h b/TegraRcmGUI/Win32Def.h similarity index 100% rename from Win32Def.h rename to TegraRcmGUI/Win32Def.h diff --git a/WinHandle.h b/TegraRcmGUI/WinHandle.h similarity index 100% rename from WinHandle.h rename to TegraRcmGUI/WinHandle.h diff --git a/libusbk_int.h b/TegraRcmGUI/libusbk_int.h similarity index 100% rename from libusbk_int.h rename to TegraRcmGUI/libusbk_int.h diff --git a/TegraRcmGUI/memloader/memloader_usb.bin b/TegraRcmGUI/memloader/memloader_usb.bin new file mode 100644 index 0000000..54d08e3 Binary files /dev/null and b/TegraRcmGUI/memloader/memloader_usb.bin differ diff --git a/TegraRcmGUI/memloader/u-boot.elf b/TegraRcmGUI/memloader/u-boot.elf new file mode 100644 index 0000000..29e2422 Binary files /dev/null and b/TegraRcmGUI/memloader/u-boot.elf differ diff --git a/TegraRcmGUI/memloader/ums_sd.ini b/TegraRcmGUI/memloader/ums_sd.ini new file mode 100644 index 0000000..24d76bd --- /dev/null +++ b/TegraRcmGUI/memloader/ums_sd.ini @@ -0,0 +1,12 @@ +[load:PH_0] +if=u-boot.elf +skip=0x00010000 +count=0x0007c1bf +dst=0x80110000 + +[load:script] +if=ums_sd.scr.img +dst=0x80100000 + +[boot:ENTRY] +pc=0x80110000 diff --git a/TegraRcmGUI/memloader/ums_sd.scr b/TegraRcmGUI/memloader/ums_sd.scr new file mode 100644 index 0000000..f7e8929 --- /dev/null +++ b/TegraRcmGUI/memloader/ums_sd.scr @@ -0,0 +1,2 @@ +ums 1 mmc 1 + diff --git a/TegraRcmGUI/memloader/ums_sd.scr.img b/TegraRcmGUI/memloader/ums_sd.scr.img new file mode 100644 index 0000000..c6edbd9 Binary files /dev/null and b/TegraRcmGUI/memloader/ums_sd.scr.img differ diff --git a/res/BitmapPicture.cpp b/TegraRcmGUI/res/BitmapPicture.cpp similarity index 100% rename from res/BitmapPicture.cpp rename to TegraRcmGUI/res/BitmapPicture.cpp diff --git a/res/BitmapPicture.h b/TegraRcmGUI/res/BitmapPicture.h similarity index 100% rename from res/BitmapPicture.h rename to TegraRcmGUI/res/BitmapPicture.h diff --git a/TegraRcmGUI/res/TegraRcmGUI.ico b/TegraRcmGUI/res/TegraRcmGUI.ico new file mode 100644 index 0000000..ccec0f8 Binary files /dev/null and b/TegraRcmGUI/res/TegraRcmGUI.ico differ diff --git a/res/TegraRcmGUI.rc2 b/TegraRcmGUI/res/TegraRcmGUI.rc2 similarity index 100% rename from res/TegraRcmGUI.rc2 rename to TegraRcmGUI/res/TegraRcmGUI.rc2 diff --git a/res/TegraRcmGUI.ico b/TegraRcmGUI/res/TegraRcmGUI_bck.ico similarity index 100% rename from res/TegraRcmGUI.ico rename to TegraRcmGUI/res/TegraRcmGUI_bck.ico diff --git a/res/Thumbs.db b/TegraRcmGUI/res/Thumbs.db similarity index 100% rename from res/Thumbs.db rename to TegraRcmGUI/res/Thumbs.db diff --git a/TegraRcmGUI/res/add.ico b/TegraRcmGUI/res/add.ico new file mode 100644 index 0000000..d8306c7 Binary files /dev/null and b/TegraRcmGUI/res/add.ico differ diff --git a/TegraRcmGUI/res/browse.ico b/TegraRcmGUI/res/browse.ico new file mode 100644 index 0000000..64955e1 Binary files /dev/null and b/TegraRcmGUI/res/browse.ico differ diff --git a/TegraRcmGUI/res/delete.ico b/TegraRcmGUI/res/delete.ico new file mode 100644 index 0000000..0bf70d4 Binary files /dev/null and b/TegraRcmGUI/res/delete.ico differ diff --git a/res/driver_ko.bmp b/TegraRcmGUI/res/driver_ko.bmp similarity index 100% rename from res/driver_ko.bmp rename to TegraRcmGUI/res/driver_ko.bmp diff --git a/res/error.bmp b/TegraRcmGUI/res/error.bmp similarity index 100% rename from res/error.bmp rename to TegraRcmGUI/res/error.bmp diff --git a/TegraRcmGUI/res/icon1.ico b/TegraRcmGUI/res/icon1.ico new file mode 100644 index 0000000..5d06b9f Binary files /dev/null and b/TegraRcmGUI/res/icon1.ico differ diff --git a/res/init_logo.bmp b/TegraRcmGUI/res/init_logo.bmp similarity index 100% rename from res/init_logo.bmp rename to TegraRcmGUI/res/init_logo.bmp diff --git a/TegraRcmGUI/res/linux_icon.ico b/TegraRcmGUI/res/linux_icon.ico new file mode 100644 index 0000000..01f776d Binary files /dev/null and b/TegraRcmGUI/res/linux_icon.ico differ diff --git a/res/loaded.bmp b/TegraRcmGUI/res/loaded.bmp similarity index 100% rename from res/loaded.bmp rename to TegraRcmGUI/res/loaded.bmp diff --git a/res/loading.bmp b/TegraRcmGUI/res/loading.bmp similarity index 100% rename from res/loading.bmp rename to TegraRcmGUI/res/loading.bmp diff --git a/res/rcm_detected.bmp b/TegraRcmGUI/res/rcm_detected.bmp similarity index 100% rename from res/rcm_detected.bmp rename to TegraRcmGUI/res/rcm_detected.bmp diff --git a/res/rcm_undetected.bmp b/TegraRcmGUI/res/rcm_undetected.bmp similarity index 100% rename from res/rcm_undetected.bmp rename to TegraRcmGUI/res/rcm_undetected.bmp diff --git a/TegraRcmGUI/res/status.ico b/TegraRcmGUI/res/status.ico new file mode 100644 index 0000000..2f96b79 Binary files /dev/null and b/TegraRcmGUI/res/status.ico differ diff --git a/TegraRcmGUI/res/tray_ico_connected.ico b/TegraRcmGUI/res/tray_ico_connected.ico new file mode 100644 index 0000000..f2dd069 Binary files /dev/null and b/TegraRcmGUI/res/tray_ico_connected.ico differ diff --git a/TegraRcmGUI/res/tray_ico_not_connected.ico b/TegraRcmGUI/res/tray_ico_not_connected.ico new file mode 100644 index 0000000..4c9abfd Binary files /dev/null and b/TegraRcmGUI/res/tray_ico_not_connected.ico differ diff --git a/TegraRcmGUI/res/usb_icon.ico b/TegraRcmGUI/res/usb_icon.ico new file mode 100644 index 0000000..6051cf0 Binary files /dev/null and b/TegraRcmGUI/res/usb_icon.ico differ diff --git a/resource.h b/TegraRcmGUI/resource.h similarity index 51% rename from resource.h rename to TegraRcmGUI/resource.h index 86044d2..236558f 100644 Binary files a/resource.h and b/TegraRcmGUI/resource.h differ diff --git a/shofel2/download.bat b/TegraRcmGUI/shofel2/download.bat similarity index 100% rename from shofel2/download.bat rename to TegraRcmGUI/shofel2/download.bat diff --git a/stdafx.cpp b/TegraRcmGUI/stdafx.cpp similarity index 100% rename from stdafx.cpp rename to TegraRcmGUI/stdafx.cpp diff --git a/stdafx.h b/TegraRcmGUI/stdafx.h similarity index 100% rename from stdafx.h rename to TegraRcmGUI/stdafx.h diff --git a/targetver.h b/TegraRcmGUI/targetver.h similarity index 100% rename from targetver.h rename to TegraRcmGUI/targetver.h diff --git a/TegraRcmGUIDlg.cpp b/TegraRcmGUIDlg.cpp deleted file mode 100644 index 21f3210..0000000 --- a/TegraRcmGUIDlg.cpp +++ /dev/null @@ -1,749 +0,0 @@ - -// TegraRcmGUIDlg.cpp : implementation file -// - -#include "stdafx.h" -#include "afxdialogex.h" -#include "TegraRcmGUI.h" -#include "TegraRcmGUIDlg.h" - - -using namespace std; -#ifdef _DEBUG -#define new DEBUG_NEW -#endif - -#define ARRAY_SIZE 1024 - -TCHAR* PAYLOAD_FILE; -int RCM_STATUS = -10; -BOOL WAITING_RECONNECT = FALSE; -BOOL AUTOINJECT_CURR = FALSE; -BOOL PREVENT_AUTOINJECT = TRUE; -BOOL DELAY_AUTOINJECT = FALSE; -BOOL ASK_FOR_DRIVER = FALSE; -BOOL PAUSE_LKP_DEVICE = FALSE; - -CString csPath; -CString csPath2; - - -// CTegraRcmGUIDlg dialog - -CTegraRcmGUIDlg::CTegraRcmGUIDlg(CWnd* pParent /*=NULL*/) - : CDialog(IDD_TEGRARCMGUI_DIALOG, pParent) - , STATUS(0) -{ - m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); -} - -void CTegraRcmGUIDlg::DoDataExchange(CDataExchange* pDX) -{ - CDialog::DoDataExchange(pDX); - DDX_Control(pDX, RCM_PIC_1, RCM_BITMAP1); - DDX_Control(pDX, RCM_PIC_2, RCM_BITMAP2); - DDX_Control(pDX, RCM_PIC_3, RCM_BITMAP3); - DDX_Control(pDX, RCM_PIC_4, RCM_BITMAP0); - DDX_Control(pDX, RCM_PIC_5, RCM_BITMAP4); - DDX_Control(pDX, RCM_PIC_6, RCM_BITMAP5); - DDX_Control(pDX, RCM_PIC_7, RCM_BITMAP6); - DDX_Control(pDX, PAYLOAD_PATH, m_EditBrowse); -} - -BEGIN_MESSAGE_MAP(CTegraRcmGUIDlg, CDialog) - ON_WM_CTLCOLOR() - ON_WM_TIMER() - ON_WM_SYSCOMMAND() - ON_WM_PAINT() - ON_WM_QUERYDRAGICON() - ON_EN_CHANGE(PAYLOAD_PATH, &CTegraRcmGUIDlg::OnEnChangePath) - ON_BN_CLICKED(IDC_INJECT, &CTegraRcmGUIDlg::InjectPayload) - ON_BN_CLICKED(IDC_SHOFEL2, &CTegraRcmGUIDlg::OnBnClickedShofel2) - ON_BN_CLICKED(IDC_MOUNT_SD, &CTegraRcmGUIDlg::OnBnClickedMountSd) -END_MESSAGE_MAP() - - - -HBRUSH CTegraRcmGUIDlg::OnCtlColor(CDC* pDC, CWnd *pWnd, UINT nCtlColor) -{ - switch (nCtlColor) - { - case CTLCOLOR_STATIC: - if (GetDlgItem(IDC_RAJKOSTO)->GetSafeHwnd() == pWnd->GetSafeHwnd() || GetDlgItem(SEPARATOR)->GetSafeHwnd() == pWnd->GetSafeHwnd()) - { - pDC->SetTextColor(RGB(192, 192, 192)); - pDC->SetBkMode(TRANSPARENT); - return (HBRUSH)GetStockObject(NULL_BRUSH); - } - default: - return CDialog::OnCtlColor(pDC, pWnd, nCtlColor); - } -} -// CTegraRcmGUIDlg message handlers - -BOOL CTegraRcmGUIDlg::OnInitDialog() -{ - CDialog::OnInitDialog(); - - // Accessibility - EnableActiveAccessibility(); - - // Get current directory - TCHAR szPath[_MAX_PATH]; - VERIFY(::GetModuleFileName(AfxGetApp()->m_hInstance, szPath, _MAX_PATH)); - CString csPathf(szPath); - int nIndex = csPathf.ReverseFind(_T('\\')); - if (nIndex > 0) csPath = csPathf.Left(nIndex); - else csPath.Empty(); - - // Initialize bitmap - RCM_BITMAP0.SetBitmap(INIT_LOGO); - RCM_BITMAP1.SetBitmap(RCM_NOT_DETECTED); - RCM_BITMAP2.SetBitmap(DRIVER_KO); - RCM_BITMAP3.SetBitmap(RCM_DETECTED); - RCM_BITMAP4.SetBitmap(LOADING); - RCM_BITMAP5.SetBitmap(LOADED); - RCM_BITMAP6.SetBitmap(LOAD_ERROR); - - BitmapDisplay(INIT_LOGO); - - // Check for APX driver at startup - //BOOL isDriverInstalled = LookForAPXDevice(); - //if (!isDriverInstalled) InstallDriver(); - - // Read & apply presets - string value = GetPreset("AUTO_INJECT"); - if (value == "TRUE") - { - AUTOINJECT_CURR = TRUE; - CMFCButton*checkbox = (CMFCButton*)GetDlgItem(AUTO_INJECT); - checkbox->SetCheck(BST_CHECKED); - - } - - string pfile = GetPreset("PAYLOAD_FILE"); - CString file(pfile.c_str()); - this->GetDlgItem(PAYLOAD_PATH)->SetWindowTextW(file); - //PREVENT_AUTOINJECT = TRUE; - - // Menu - ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); - ASSERT(IDM_ABOUTBOX < 0xF000); - CMenu* pSysMenu = GetSystemMenu(FALSE); - if (pSysMenu != NULL) - { - BOOL bNameValid; - CString strAboutMenu; - bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX); - ASSERT(bNameValid); - if (!strAboutMenu.IsEmpty()) - { - pSysMenu->AppendMenu(MF_SEPARATOR); - pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); - } - } - - // Set icons - SetIcon(m_hIcon, TRUE); // Set big icon - SetIcon(m_hIcon, FALSE); // Set small icon - - // Start timer to check RCM status every second - CTegraRcmGUIDlg::StartTimer(); - - return TRUE; -} - -void CTegraRcmGUIDlg::OnSysCommand(UINT nID, LPARAM lParam) -{ - CDialog::OnSysCommand(nID, lParam); -} - - -void CTegraRcmGUIDlg::OnPaint() -{ - - if (IsIconic()) - { - CPaintDC dc(this); // device context for painting - - SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); - - // Center icon in client rectangle - int cxIcon = GetSystemMetrics(SM_CXICON); - int cyIcon = GetSystemMetrics(SM_CYICON); - CRect rect; - GetClientRect(&rect); - int x = (rect.Width() - cxIcon + 1) / 2; - int y = (rect.Height() - cyIcon + 1) / 2; - - // Draw the icon - dc.DrawIcon(x, y, m_hIcon); - } - else - { - CDialog::OnPaint(); - } -} -// The system calls this function to obtain the cursor to display while the user drags -// the minimized window. -HCURSOR CTegraRcmGUIDlg::OnQueryDragIcon() -{ - return static_cast(m_hIcon); -} -const UINT ID_TIMER_MINUTE = 0x1001; -const UINT ID_TIMER_SECONDS = 0x1000; -// Start the timers. -void CTegraRcmGUIDlg::StartTimer() -{ - // Set timer for Minutes. - //SetTimer(ID_TIMER_MINUTE, 60 * 1000, 0); - // Set timer for Seconds. - SetTimer(ID_TIMER_SECONDS, 1000, 0); -} - -// Stop the timers. -void CTegraRcmGUIDlg::StopTimer() -{ - // Stop both timers. - KillTimer(ID_TIMER_MINUTE); - KillTimer(ID_TIMER_SECONDS); -} - -void CTegraRcmGUIDlg::BitmapDisplay(int IMG) -{ - // Init & bitmap pointers - CStatic*pRcm_not_detected = (CStatic*)GetDlgItem(RCM_PIC_1); - CStatic*pDriverKO = (CStatic*)GetDlgItem(RCM_PIC_2); - CStatic*pRcm_detected = (CStatic*)GetDlgItem(RCM_PIC_3); - CStatic*pInitLogo = (CStatic*)GetDlgItem(RCM_PIC_4); - CStatic*pLoading = (CStatic*)GetDlgItem(RCM_PIC_5); - CStatic*pLoaded = (CStatic*)GetDlgItem(RCM_PIC_6); - CStatic*pError = (CStatic*)GetDlgItem(RCM_PIC_7); - - pRcm_not_detected->ShowWindow(SW_HIDE); - pDriverKO->ShowWindow(SW_HIDE); - pRcm_detected->ShowWindow(SW_HIDE); - pInitLogo->ShowWindow(SW_HIDE); - pLoading->ShowWindow(SW_HIDE); - pLoaded->ShowWindow(SW_HIDE); - pError->ShowWindow(SW_HIDE); - - switch (IMG) - { - case INIT_LOGO: - pInitLogo->ShowWindow(SW_SHOW); - break; - case RCM_NOT_DETECTED: - pRcm_not_detected->ShowWindow(SW_SHOW); - break; - case DRIVER_KO: - pDriverKO->ShowWindow(SW_SHOW); - break; - case RCM_DETECTED: - pRcm_detected->ShowWindow(SW_SHOW); - break; - case LOADING: - pLoading->ShowWindow(SW_SHOW); - UpdateWindow(); - break; - case LOADED: - pLoaded->ShowWindow(SW_SHOW); - break; - case LOAD_ERROR: - pError->ShowWindow(SW_SHOW); - break; - default: - break; - } -} - -// -// Timer Handler. -void CTegraRcmGUIDlg::OnTimer(UINT nIDEvent) -{ - // Each second - if (nIDEvent == ID_TIMER_SECONDS) - { - // Exit when PAUSE_LKP_DEVICE flag is TRUE - if (PAUSE_LKP_DEVICE) return; - - // Get Auto inject checkbox value (checked, unchecked) - CButton *m_ctlCheck = (CButton*)GetDlgItem(AUTO_INJECT); - BOOL IsCheckChecked = (m_ctlCheck->GetCheck() == 1) ? true : false; - - if (AUTOINJECT_CURR != IsCheckChecked) - { - // Auto inject option enabled - if (IsCheckChecked) - { - SetPreset("AUTO_INJECT", "TRUE"); - DELAY_AUTOINJECT = TRUE; - } - // Auto inject option disabled - else - { - SetPreset("AUTO_INJECT", "FALSE"); - DELAY_AUTOINJECT = FALSE; - } - // Save current checkbox value - AUTOINJECT_CURR = IsCheckChecked; - } - - // Get RCM device Status - // This feature has been developped by Rajkosto (copied from TegraRcmSmash) - TegraRcmSmash device; - int rc = device.RcmStatus(); - - std::string s = ""; - - // RCM Status = "RCM detected" - if (rc >= 0) - { - this->GetDlgItem(IDC_INJECT)->EnableWindow(TRUE); - this->GetDlgItem(IDC_SHOFEL2)->EnableWindow(TRUE); - this->GetDlgItem(IDC_MOUNT_SD)->EnableWindow(TRUE); - - } - // RCM Status = "USB Driver KO" - else if (rc > -5) - { - this->GetDlgItem(IDC_INJECT)->EnableWindow(FALSE); - this->GetDlgItem(IDC_SHOFEL2)->EnableWindow(FALSE); - this->GetDlgItem(IDC_MOUNT_SD)->EnableWindow(FALSE); - s = "lbusbK driver is needed !"; - } - // RCM Status = "RCM not detected" - else - { - this->GetDlgItem(IDC_INJECT)->EnableWindow(FALSE); - this->GetDlgItem(IDC_SHOFEL2)->EnableWindow(FALSE); - this->GetDlgItem(IDC_MOUNT_SD)->EnableWindow(FALSE); - s = "Waiting for Switch in RCM mode."; - - // Delay Auto inject if needed - if (AUTOINJECT_CURR) DELAY_AUTOINJECT = TRUE; - } - - // On change RCM status - if (rc != RCM_STATUS) - { - RCM_STATUS = rc; - CStatic*pCtrl0 = (CStatic*)GetDlgItem(RCM_PIC_4); - pCtrl0->ShowWindow(SW_HIDE); - - // Status changed to "RCM Detected" - if (rc == 0) - { - BitmapDisplay(RCM_DETECTED); - - CString file; - this->GetDlgItem(PAYLOAD_PATH)->GetWindowTextW(file); - - // Trigger auto inject if payload injection scheduled - if (DELAY_AUTOINJECT && file.GetLength() > 0) - { - InjectPayload(); - DELAY_AUTOINJECT = FALSE; - } - else - { - SetDlgItemText(INFO_LABEL, TEXT("\nSelect a payload :")); - } - } - // Status changed to "RCM not detected" or "USB driver KO" - else - { - // Ask for driver install - if (rc > -5) - { - BitmapDisplay(DRIVER_KO); - InstallDriver(); - } - else - { - if (LookForAPXDevice()) - { - BitmapDisplay(DRIVER_KO); - InstallDriver(); - } - else - { - BitmapDisplay(RCM_NOT_DETECTED); - } - } - } - // Status changed to "RCM not detected" -> Disable WAITING_RECONNECT flag - if (rc <= -5) WAITING_RECONNECT = FALSE; - } - RCM_STATUS = rc; - } -} - -// -// On change payload path -void CTegraRcmGUIDlg::OnEnChangePath() -{ - CString file; - this->GetDlgItem(PAYLOAD_PATH)->GetWindowTextW(file); - PAYLOAD_FILE = _tcsdup(file); - - if (!PREVENT_AUTOINJECT) - { - // Save payload path - CT2CA pszConvertedAnsiString(file); - std::string file_c(pszConvertedAnsiString); - SetPreset("PAYLOAD_FILE", file_c); - } - - std::string s = "\nSelect a payload :"; - - CButton *m_ctlCheck = (CButton*)GetDlgItem(AUTO_INJECT); - BOOL IsCheckChecked = (m_ctlCheck->GetCheck() == 1) ? true : false; - // If Auto inject option enabled - if (IsCheckChecked && !PREVENT_AUTOINJECT) - { - // Delay auto inject if RCM not detected - if (RCM_STATUS != 0) - { - DELAY_AUTOINJECT = TRUE; - s = "Payload injection scheduled.\nWaiting for RCM mode."; - } - // Inject payload if RCM detected - else InjectPayload(); - } - PREVENT_AUTOINJECT = FALSE; - CA2T wt(s.c_str()); - SetDlgItemText(INFO_LABEL, wt); -} - - -// -// User payload injection -void CTegraRcmGUIDlg::InjectPayload() -{ - string s; - if (PAYLOAD_FILE == nullptr) { - BitmapDisplay(LOAD_ERROR); - SetDlgItemText(INFO_LABEL, TEXT("\nNo file selected !")); - return; - } - BitmapDisplay(LOADING); - - TCHAR cmd[MAX_PATH] = TEXT("\""); - lstrcat(cmd, PAYLOAD_FILE); - lstrcat(cmd, TEXT("\"")); - - int rc = Smasher(cmd); - if (rc >= 0) - { - BitmapDisplay(LOADED); - s = "\nPayload injected !"; - WAITING_RECONNECT = TRUE; - } - else - { - BitmapDisplay(LOAD_ERROR); - s = "Error while injecting payload (RC=" + std::to_string(rc) + ")"; - } - CA2T wt(s.c_str()); - CTegraRcmGUIDlg::SetDlgItemText(INFO_LABEL, wt); -} - -void CTegraRcmGUIDlg::OnBnClickedShofel2() -{ - TCHAR *exe_dir = GetAbsolutePath(TEXT(""), CSIDL_APPDATA); - - string s; - TCHAR *COREBOOT_FILE = GetAbsolutePath(TEXT("shofel2\\coreboot\\coreboot.rom"), CSIDL_APPDATA); - TCHAR *PAYLOAD = GetAbsolutePath(TEXT("shofel2\\coreboot\\cbfs.bin"), CSIDL_APPDATA); - CString COREBOOT_FILE2 = COREBOOT_FILE; - CString COREBOOT = _T("CBFS+") + COREBOOT_FILE2; - - std::ifstream infile(COREBOOT_FILE); - BOOL coreboot_exists = infile.good(); - std::ifstream infile2(PAYLOAD); - BOOL payload_exists = infile2.good(); - - if (!coreboot_exists || !payload_exists) { - SetDlgItemText(INFO_LABEL, TEXT("Linux coreboot not found in \\shofel2 dir")); - CString message = _T("Kernel not found in shofel2 directory. Do you want to automatically download arch linux kernel from SoulCipher repo ?"); - const int result = MessageBox(message, _T("Kernel not found"), MB_YESNOCANCEL | MB_ICONQUESTION); - if (result == IDYES) - { - PROCESS_INFORMATION pif; - STARTUPINFO si; - ZeroMemory(&si, sizeof(si)); - si.cb = sizeof(si); - TCHAR *download_script = GetAbsolutePath(TEXT("shofel2\\download.bat"), CSIDL_APPDATA); - BOOL bRet = CreateProcess(download_script, NULL, NULL, NULL, FALSE, 0, NULL, exe_dir, &si, &pif); - } - return; // TO-DO : Remove return for coreboot injection after download - } - BitmapDisplay(LOADING); - SetDlgItemText(INFO_LABEL, TEXT("Loading coreboot. Please wait.")); - - //int rc = device.SmashMain(5, args); - TCHAR cmd[MAX_PATH] = TEXT("--relocator= \""); - lstrcat(cmd, _tcsdup(PAYLOAD)); - lstrcat(cmd, TEXT("\" \"CBFS:")); - lstrcat(cmd, _tcsdup(COREBOOT_FILE)); - lstrcat(cmd, TEXT("\"")); - int rc = Smasher(cmd); - - if (rc >= 0 || rc < -7) - { - SetDlgItemText(INFO_LABEL, TEXT("Coreboot injected. Waiting 5s for device...")); - Sleep(5000); - - PROCESS_INFORMATION pif; - STARTUPINFO si; - ZeroMemory(&si, sizeof(si)); - si.cb = sizeof(si); - TCHAR *imx_script = GetAbsolutePath(TEXT("shofel2\\imx_usb.bat"), CSIDL_APPDATA); - SetDlgItemText(INFO_LABEL, TEXT("Loading coreboot... Please wait.")); - BOOL ret = CreateProcess(imx_script, NULL, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, exe_dir, &si, &pif); - int rc = -50; - if (NULL != ret) - { - WaitForSingleObject(pif.hProcess, INFINITE); - DWORD exit_code; - if (FALSE != GetExitCodeProcess(pif.hProcess, &exit_code)) - { - if (STILL_ACTIVE != exit_code) rc = exit_code; - } - else rc = -51; - CloseHandle(pif.hProcess); - CloseHandle(pif.hThread); - } - - if (rc == 0) - { - BitmapDisplay(LOADED); - s = "\nCoreboot loaded !"; - } - else - { - BitmapDisplay(LOAD_ERROR); - s = "Error while loading imx_usb.exe"; - } - } - else - { - s = "Error while injecting payload. (RC=" + std::to_string(rc) + ")"; - } - CA2T wt2(s.c_str()); - SetDlgItemText(INFO_LABEL, wt2); - -} - - -string CTegraRcmGUIDlg::GetPreset(string param) -{ - TCHAR *rfile = GetAbsolutePath(TEXT("presets.conf"), CSIDL_APPDATA); - CT2A rfile_c(rfile, CP_UTF8); - TRACE(_T("UTF8: %S\n"), rfile_c.m_psz); - - ifstream readFile(rfile_c); - string readout; - string search = param + "="; - std::string value = ""; - if (readFile.is_open()) - { - while (getline(readFile, readout)) { - if (readout.find(search) != std::string::npos) { - std::string delimiter = "="; - value = readout.substr(readout.find(delimiter) + 1, readout.length() + 1); - } - } - } - readFile.close(); - return value; -} - -void CTegraRcmGUIDlg::SetPreset(string param, string value) -{ - TCHAR *rfile = GetAbsolutePath(TEXT("presets.conf"), CSIDL_APPDATA); - TCHAR *wfile = GetAbsolutePath(TEXT("presets.conf.tmp"), CSIDL_APPDATA); - CT2A rfile_c(rfile, CP_UTF8); - TRACE(_T("UTF8: %S\n"), rfile_c.m_psz); - CT2A wfile_c(wfile, CP_UTF8); - TRACE(_T("UTF8: %S\n"), wfile_c.m_psz); - - // Replace or create preset in file - ofstream outFile(wfile_c); - ifstream readFile(rfile_c); - string readout; - string search = param + "="; - string replace = "\n" + search + value + "\n"; - BOOL found = FALSE; - while (getline(readFile, readout)) { - if (readout.find(search) != std::string::npos) { - outFile << replace; - found = TRUE; - } - else { - outFile << readout; - } - } - if (!found) { - outFile << replace; - } - outFile.close(); - readFile.close(); - remove(rfile_c); - rename(wfile_c, rfile_c); -} - - -void CTegraRcmGUIDlg::InstallDriver() -{ - if (ASK_FOR_DRIVER) return; - CString message = _T("APX device driver is missing. Do you want to install it now ?"); - const int result = MessageBox(message, _T("APX driver not found !"), MB_YESNOCANCEL | MB_ICONQUESTION); - if (result == IDYES) - { - SHELLEXECUTEINFO shExInfo = { 0 }; - shExInfo.cbSize = sizeof(shExInfo); - shExInfo.fMask = SEE_MASK_NOCLOSEPROCESS; - shExInfo.hwnd = 0; - shExInfo.lpVerb = _T("runas"); - CString exe_file = csPath + _T("\\apx_driver\\InstallDriver.exe"); - shExInfo.lpFile = exe_file; - shExInfo.lpDirectory = 0; - shExInfo.nShow = SW_SHOW; - shExInfo.hInstApp = 0; - - if (ShellExecuteEx(&shExInfo)) - { - CloseHandle(shExInfo.hProcess); - } - } - ASK_FOR_DRIVER = TRUE; -} -typedef int(__cdecl *MYPROC)(LPWSTR); - - -BOOL CTegraRcmGUIDlg::LookForAPXDevice() -{ - unsigned index; - HDEVINFO hDevInfo; - SP_DEVINFO_DATA DeviceInfoData; - TCHAR HardwareID[1024]; - // List all connected USB devices - hDevInfo = SetupDiGetClassDevs(NULL, TEXT("USB"), NULL, DIGCF_PRESENT | DIGCF_ALLCLASSES); - for (index = 0; ; index++) { - DeviceInfoData.cbSize = sizeof(DeviceInfoData); - if (!SetupDiEnumDeviceInfo(hDevInfo, index, &DeviceInfoData)) { - return FALSE; // no match - } - SetupDiGetDeviceRegistryProperty(hDevInfo, &DeviceInfoData, SPDRP_HARDWAREID, NULL, (BYTE*)HardwareID, sizeof(HardwareID), NULL); - if (_tcsstr(HardwareID, _T("VID_0955&PID_7321"))) { - return TRUE; // match - } - } - return FALSE; -} - - -void CTegraRcmGUIDlg::OnBnClickedMountSd() -{ - BitmapDisplay(LOADING); - string s; - TCHAR args[] = TEXT("memloader\\memloader_usb.bin -r --dataini=memloader\\ums_sd.ini"); - int rc = Smasher(args); - if (rc < 0) - { - - BitmapDisplay(LOAD_ERROR); - s = "Error while loading payload (RC=" + std::to_string(rc) + ")"; - } - else - { - BitmapDisplay(LOADING); - s = "SD tool (by rajkosto) injected"; - } - CA2T wt(s.c_str()); - CTegraRcmGUIDlg::SetDlgItemText(INFO_LABEL, wt); -} - -int CTegraRcmGUIDlg::Smasher(TCHAR args[]) -{ - if (WAITING_RECONNECT) - { - CString message = _T("Payload already injected. Are you sure you want to overwrite the stack again ?"); - const int result = MessageBox(message, _T("WARNING !"), MB_YESNOCANCEL | MB_ICONQUESTION); - if (result != IDYES) - { - DELAY_AUTOINJECT = FALSE; - RCM_STATUS = -99; - return -99; - } - WAITING_RECONNECT = FALSE; - } - - SECURITY_ATTRIBUTES sa; - sa.nLength = sizeof(sa); - sa.lpSecurityDescriptor = NULL; - sa.bInheritHandle = TRUE; - PROCESS_INFORMATION pi; - STARTUPINFO si; - BOOL ret = FALSE; - DWORD flags = CREATE_NO_WINDOW; - ZeroMemory(&pi, sizeof(PROCESS_INFORMATION)); - ZeroMemory(&si, sizeof(STARTUPINFO)); - si.cb = sizeof(STARTUPINFO); - si.dwFlags |= STARTF_USESTDHANDLES; - si.hStdInput = NULL; - TCHAR cmd[MAX_PATH] = TEXT(".\\TegraRcmSmash.exe "); - lstrcat(cmd, args); - ret = CreateProcess(NULL, cmd, NULL, NULL, TRUE, flags, NULL, NULL, &si, &pi); - int rc = -50; - if (NULL != ret) - { - WaitForSingleObject(pi.hProcess, INFINITE); - DWORD exit_code; - if (FALSE != GetExitCodeProcess(pi.hProcess, &exit_code)) - { - if (STILL_ACTIVE != exit_code) - { - rc = exit_code; - } - } - else - { - rc = -51; - } - CloseHandle(pi.hProcess); - CloseHandle(pi.hThread); - } - return rc; -} - -TCHAR* CTegraRcmGUIDlg::GetAbsolutePath(TCHAR* relative_path, DWORD dwFlags) -{ - - // Get current directory - TCHAR szPath[_MAX_PATH]; - VERIFY(::GetModuleFileName(AfxGetApp()->m_hInstance, szPath, _MAX_PATH)); - CString csPathf(szPath); - int nIndex = csPathf.ReverseFind(_T('\\')); - if (nIndex > 0) csPath = csPathf.Left(nIndex); - else csPath.Empty(); - - csPath2 = csPath; - csPath2 += TEXT("\\"); - csPath2 += relative_path; - return _tcsdup(csPath2); - /* - TCHAR szPath[MAX_PATH]; - - if (SUCCEEDED(SHGetFolderPath(NULL, dwFlags, NULL, SHGFP_TYPE_CURRENT, szPath))) - { - if (dwFlags == CSIDL_APPDATA) PathAppend(szPath, _T("\\TegraRcmGUI")); - PathAppend(szPath, relative_path); - return _tcsdup(szPath); - } - return _T(""); - */ -} - diff --git a/presets.conf b/presets.conf deleted file mode 100644 index e69de29..0000000 diff --git a/res/bitmap2.bmp b/res/bitmap2.bmp deleted file mode 100644 index 6e8e840..0000000 Binary files a/res/bitmap2.bmp and /dev/null differ diff --git a/res/driver_ko2.bmp b/res/driver_ko2.bmp deleted file mode 100644 index 7b2e5f4..0000000 Binary files a/res/driver_ko2.bmp and /dev/null differ diff --git a/res/init_logo_2.bmp b/res/init_logo_2.bmp deleted file mode 100644 index cd196ec..0000000 Binary files a/res/init_logo_2.bmp and /dev/null differ diff --git a/res/rcm_detected2.bmp b/res/rcm_detected2.bmp deleted file mode 100644 index 1f01c7a..0000000 Binary files a/res/rcm_detected2.bmp and /dev/null differ diff --git a/res/rcm_undetected2.bmp b/res/rcm_undetected2.bmp deleted file mode 100644 index b8774e5..0000000 Binary files a/res/rcm_undetected2.bmp and /dev/null differ