1
0
Fork 0
mirror of https://github.com/eliboa/TegraRcmGUI.git synced 2024-12-28 19:16:02 +00:00
This commit is contained in:
eliboa 2018-06-10 16:21:59 +02:00
parent cee95c9712
commit 10cfa46328
66 changed files with 2223 additions and 959 deletions

View file

@ -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)

View file

@ -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

View file

@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="TegraRcmGUI.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="TegraRcmGUIDlg.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="targetver.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="libusbk_int.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ScopeGuard.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="TegraRcmSmash.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Types.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Win32Def.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="WinHandle.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="res\BitmapPicture.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="TegraRcmGUI.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="TegraRcmGUIDlg.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="TegraRcmSmash.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="res\BitmapPicture.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="TegraRcmGUI.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<None Include="res\TegraRcmGUI.rc2">
<Filter>Resource Files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Image Include="res\TegraRcmGUI.ico">
<Filter>Resource Files</Filter>
</Image>
<Image Include="res\driver_ko.bmp">
<Filter>Resource Files</Filter>
</Image>
<Image Include="res\init_logo.bmp">
<Filter>Resource Files</Filter>
</Image>
<Image Include="res\rcm_detected.bmp">
<Filter>Resource Files</Filter>
</Image>
<Image Include="res\rcm_undetected.bmp">
<Filter>Resource Files</Filter>
</Image>
<Image Include="..\..\..\..\..\..\Visual Studio 2015\Projects\TegraRcmGUI\TegraRcmGUI\res\TegraRcmGUI.ico">
<Filter>Resource Files</Filter>
</Image>
<Image Include="res\bitmap2.bmp">
<Filter>Resource Files</Filter>
</Image>
<Image Include="res\init_log.bmp">
<Filter>Resource Files</Filter>
</Image>
<Image Include="res\error.bmp">
<Filter>Resource Files</Filter>
</Image>
<Image Include="res\loaded.bmp">
<Filter>Resource Files</Filter>
</Image>
<Image Include="res\loading.bmp">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
</Project>

View file

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

325
TegraRcmGUI/DialogTab01.cpp Normal file
View file

@ -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;
}

41
TegraRcmGUI/DialogTab01.h Normal file
View file

@ -0,0 +1,41 @@
#pragma once
#include <string>
#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 <CString, CString> 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);
};

229
TegraRcmGUI/DialogTab02.cpp Normal file
View file

@ -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;
}

36
TegraRcmGUI/DialogTab02.h Normal file
View file

@ -0,0 +1,36 @@
#pragma once
#include <string>
#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);
};

132
TegraRcmGUI/DialogTab03.cpp Normal file
View file

@ -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();
}

33
TegraRcmGUI/DialogTab03.h Normal file
View file

@ -0,0 +1,33 @@
#pragma once
#include <string>
#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();
};

72
TegraRcmGUI/MyTabCtrl.cpp Normal file
View file

@ -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);
}

25
TegraRcmGUI/MyTabCtrl.h Normal file
View file

@ -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;
};

698
TegraRcmGUI/TegraRcm.cpp Normal file
View file

@ -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("");
}

85
TegraRcmGUI/TegraRcm.h Normal file
View file

@ -0,0 +1,85 @@
#pragma once
#include <string>
#include <windows.h>
#include <time.h>
#include <iostream>
#include <sstream>
#pragma once
#include <fstream>
#include <iostream>
#include <cstdio>
#include <memory>
#include <stdexcept>
#include "resource.h"
#include "TegraRcmSmash.h"
#include <setupapi.h>
#include <stdio.h>
#include <Strsafe.h>
#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 <CString, CString> 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;
};

View file

@ -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 <string>
#include <thread>
#include <iostream>
using namespace std;

View file

@ -202,12 +202,17 @@
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="DialogTab01.h" />
<ClInclude Include="DialogTab02.h" />
<ClInclude Include="DialogTab03.h" />
<ClInclude Include="libusbk_int.h" />
<ClInclude Include="MyTabCtrl.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="res\BitmapPicture.h" />
<ClInclude Include="ScopeGuard.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="TegraRcm.h" />
<ClInclude Include="TegraRcmGUI.h" />
<ClInclude Include="TegraRcmGUIDlg.h" />
<ClInclude Include="TegraRcmSmash.h" />
@ -216,6 +221,10 @@
<ClInclude Include="WinHandle.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="DialogTab01.cpp" />
<ClCompile Include="DialogTab02.cpp" />
<ClCompile Include="DialogTab03.cpp" />
<ClCompile Include="MyTabCtrl.cpp" />
<ClCompile Include="res\BitmapPicture.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
@ -223,6 +232,7 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="TegraRcm.cpp" />
<ClCompile Include="TegraRcmGUI.cpp" />
<ClCompile Include="TegraRcmGUIDlg.cpp" />
<ClCompile Include="TegraRcmSmash.cpp" />
@ -237,16 +247,25 @@
</ItemGroup>
<ItemGroup>
<Image Include="..\..\..\..\..\..\Visual Studio 2015\Projects\TegraRcmGUI\TegraRcmGUI\res\TegraRcmGUI.ico" />
<Image Include="res\add.ico" />
<Image Include="res\bitmap2.bmp" />
<Image Include="res\browse.ico" />
<Image Include="res\delete.ico" />
<Image Include="res\driver_ko.bmp" />
<Image Include="res\error.bmp" />
<Image Include="res\icon1.ico" />
<Image Include="res\init_log.bmp" />
<Image Include="res\init_logo.bmp" />
<Image Include="res\linux_icon.ico" />
<Image Include="res\loaded.bmp" />
<Image Include="res\loading.bmp" />
<Image Include="res\rcm_detected.bmp" />
<Image Include="res\rcm_undetected.bmp" />
<Image Include="res\status.ico" />
<Image Include="res\TegraRcmGUI.ico" />
<Image Include="res\tray_ico_connected.ico" />
<Image Include="res\tray_ico_not_connected.ico" />
<Image Include="res\usb_icon.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View file

@ -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 <windows.h>
#include <shellapi.h>
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<WPARAM>(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<HCURSOR>(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;
}

View file

@ -1,13 +1,14 @@
// TegraRcmGUIDlg.h : header file
//
#pragma once
#include "res/BitmapPicture.h"
#include "resource.h"
#include <string>
#include "TegraRcmSmash.h"
#include "res/BitmapPicture.h"
#include <windows.h>
#include <string>
#include <time.h>
#include <thread>
#include <iostream>
#include <sstream>
@ -17,19 +18,27 @@
#include <memory>
#include <stdexcept>
#include <array>
#include <setupapi.h>
#pragma comment (lib, "setupapi.lib")
#include <setupapi.h>
#include <stdio.h>
#include <Strsafe.h>
#include "afxcmn.h"
#include "MyTabCtrl.h"
#include "TegraRcm.h"
#include "DialogTab01.h"
#include "DialogTab02.h"
#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 @@ public:
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 @@ public:
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 @@ public:
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;
};

View file

@ -225,6 +225,98 @@ TegraRcmSmash::~TegraRcmSmash()
{
}
int TegraRcmSmash::Test()
{
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;
}
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()
{
@ -294,8 +386,7 @@ int TegraRcmSmash::RcmStatus()
// Wrong USB driver version
return -1;
}
}
}
return 0;
}

View file

@ -18,5 +18,7 @@ public:
TegraRcmSmash();
~TegraRcmSmash();
static int RcmStatus();
static int Test();
};

Binary file not shown.

Binary file not shown.

View file

@ -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

View file

@ -0,0 +1,2 @@
ums 1 mmc 1

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View file

Before

Width:  |  Height:  |  Size: 179 KiB

After

Width:  |  Height:  |  Size: 179 KiB

BIN
TegraRcmGUI/res/add.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
TegraRcmGUI/res/browse.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
TegraRcmGUI/res/delete.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View file

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 84 KiB

View file

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 84 KiB

BIN
TegraRcmGUI/res/icon1.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

View file

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View file

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 84 KiB

View file

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 84 KiB

View file

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 84 KiB

View file

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 84 KiB

BIN
TegraRcmGUI/res/status.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View file

@ -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<WPARAM>(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<HCURSOR>(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("");
*/
}

View file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB