📄 gbtool.cpp
字号:
// GBTool.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "GBTool.h"
#include "winioctl.h"
//#include "Tchddi.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define IOCTL_HAL_REBOOT CTL_CODE(FILE_DEVICE_HAL, 15, METHOD_BUFFERED, FILE_ANY_ACCESS)
//extern "C" __declspec(dllimport)void SetCleanRebootFlag(void);
typedef bool(__stdcall TouchPanelSetCalibration)(INT32,INT32*,INT32*,INT32*,INT32*);
typedef void(__stdcall TouchReset)(BOOL);
extern "C" __declspec(dllimport) BOOL KernelIoControl(
DWORD dwIoControlCode,
LPVOID lpInBuf,
DWORD nInBufSize,
LPVOID lpOutBuf,
DWORD nOutBufSize,
LPDWORD lpBytesReturned);
BYTE *bin;
BOOL isAU;
//BYTE bin[4096];
/////////////////////////////////////////////////////////////////////////////
// CGBToolApp
BEGIN_MESSAGE_MAP(CGBToolApp, CWinApp)
//{{AFX_MSG_MAP(CGBToolApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGBToolApp construction
CGBToolApp::CGBToolApp()
: CWinApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CGBToolApp object
CGBToolApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CGBToolApp initialization
BOOL isroot=FALSE;
BOOL CGBToolApp::InitInstance()
{
CEGUID ceguid;
TCHAR szVolumeName[MAX_PATH+1];
CREATE_INVALIDGUID(&ceguid);
CeEnumDBVolumes(&ceguid,szVolumeName,MAX_PATH);
// PCEGUID
// CeCreateDatabaseEx(
/*
CEGUID pceguid;
CeMountDBVol(&pceguid,_T("\\Storage\\ALL.CDB"),CREATE_ALWAYS);
CeFlushDBVol(&pceguid);
CeUnmountDBVol(&pceguid);
*/
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
HKEY hKey;
DWORD dwDisp=0,dwcbData=0,dwType=0;
str=::GetCommandLine();
/*
TCHAR name[2000];
dwcbData=2000;
RegCreateKeyEx(HKEY_LOCAL_MACHINE,_T("Software\\System\\StorageManager\\Profiles\\TRUEFFS_DOC"),0,NULL,0,0,NULL,&hKey,&dwDisp);
RegQueryValueEx(hKey,_T("Folder"),NULL,&dwType,(LPBYTE)name,&dwcbData);
RegCloseKey(hKey);
str.ReleaseBuffer();
str+=_T("\\GBTool.ini");
*/
// RegFlushKey(hKey);
if(ReadGBT(str))
{
return FALSE;
}
// ReadGBT(_T("Extended_ROM\\HardReset.gbt"));
if(::GetAsyncKeyState(VK_LEFT)!=0&&::GetAsyncKeyState(VK_LEFT)!=1&&::GetAsyncKeyState(VK_SELECT)!=0&&::GetAsyncKeyState(VK_SELECT)!=1)
return FALSE;
ReadGBT(_T("\\Extended_ROM\\GBtool.gbt"));
if((::GetAsyncKeyState(VK_DOWN)!=0&&::GetAsyncKeyState(VK_DOWN)!=1))
ReadGBT(_T("\\Extended_ROM\\Down.gbt"));
if((::GetAsyncKeyState(VK_UP)!=0&&::GetAsyncKeyState(VK_UP)!=1))
ReadGBT(_T("\\Extended_ROM\\Up.gbt"));
// CreateProcess(_T("TPDisable.exe"),NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
RegCreateKeyEx(HKEY_CURRENT_USER,_T("Software\\GBTool"),0,NULL,0,0,NULL,&hKey,&dwDisp);
RegCloseKey(hKey);
if(dwDisp==REG_CREATED_NEW_KEY)
{
ReadGBT(_T("Extended_ROM\\HardReset.gbt"));
ReadGBT(_T("\\Storage\\GBTool.gbt"));
if(isroot&&(::GetAsyncKeyState(VK_LEFT)==0||::GetAsyncKeyState(VK_LEFT)==1))
SoftResetPocketPC();
/*
{
dwcbData=2000;
RegCreateKeyEx(HKEY_LOCAL_MACHINE,_T("HARDWARE\\DEVICEMAP\\TOUCH"),0,NULL,0,0,NULL,&hKey,&dwDisp);
RegQueryValueEx(hKey,_T("CalibrationData"),NULL,&dwType,(LPBYTE)str.GetBuffer(512),&dwcbData);
RegCloseKey(hKey);
str.ReleaseBuffer();
if(!str.IsEmpty())
else
{
CFile lnk;
if(lnk.Open(_T("\\Windows\\启动\\welcome.lnk"),CFile::modeCreate|CFile::modeWrite))
{
char ln[512];
str=_T("15#\"welcome.exe\"");
::WideCharToMultiByte(CP_ACP, 0,str, -1,ln,sizeof ln, NULL, NULL);
lnk.Write(&ln,str.GetLength());
}
lnk.Close();
}
}
*/
}
// CreateProcess(_T("TPEnable.exe"),NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
/*
HINSTANCE hInst;
hInst = ::LoadLibrary(_T("hwTouch.dll"));
TouchReset *pFunc;
// pFunc=(TouchPanelSetCalibration *)::GetProcAddress(hInst,_T("TouchPanelSetCalibration"));
pFunc=(TouchReset*)::GetProcAddress(hInst,_T("TouchReset"));
pFunc(TRUE);
::FreeLibrary(hInst);
*/
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
void CGBToolApp::StartSet()
{
CString strl,strr,strt,mm,stre;
HKEY hKey=NULL;
DWORD dwDisp;
BOOL isreg=FALSE;
while(str.Find((TCHAR)0x0d000a)!=-1)
{
str.TrimLeft();
if(str.IsEmpty())continue;
int st=str.Find((TCHAR)0x0d000a)-1;
mm=str.Left(st);
str=str.Right(str.GetLength()-st-2);
if(mm.GetAt(0)==L';')continue;
int nl;
if(mm.IsEmpty())continue;
mm.TrimLeft();
nl=mm.Find(_T('('));
if(nl!=-1)
{
strt=mm.Left(nl);
stre=mm.Right(mm.GetLength()-nl-1);
stre=stre.Left(stre.Find(_T(')')));
}
else
strt=mm;
if(strt==_T("注册表结束"))
{
isreg =FALSE;
RegCloseKey(hKey);
}
else if(isreg==TRUE)
{
if(mm.GetAt(0)==_T('['))
{
BOOL isDel=FALSE;
HKEY k1;
mm=mm.Right(mm.GetLength()-1);
mm=mm.Left(mm.Find(_T(']')));
if(mm.GetAt(0)==_T('-'))
{
isDel=TRUE;
mm.Delete(0);
}
int L=mm.Find(_T('\\'));
if(L!=-1)
{
strt=mm.Left(L);
stre=mm.Right(mm.GetLength()-strt.GetLength()-1);
}
else
{
stre=L"";
}
if(strt==_T("HKEY_CLASSES_ROOT")||mm==_T("HKEY_CLASSES_ROOT"))
k1=HKEY_CLASSES_ROOT;
else if(strt==_T("HKEY_CURRENT_USER")||mm==_T("HKEY_CURRENT_USER"))
k1=HKEY_CURRENT_USER;
else if(strt==_T("HKEY_LOCAL_MACHINE")||mm==_T("HKEY_LOCAL_MACHINE"))
k1=HKEY_LOCAL_MACHINE;
else if(strt==_T("HKEY_USERS")||mm==_T("HKEY_USERS"))
k1=HKEY_USERS;
RegCloseKey(hKey);
if(isDel)
{
RegDeleteKey(k1,stre);
}
else if(RegCreateKeyEx(k1,stre,0,NULL,0,0,NULL,&hKey,&dwDisp)!=ERROR_SUCCESS)
{
}
if(dwDisp==REG_CREATED_NEW_KEY)
{
RegCreateKeyEx(k1,stre,0,NULL,0,0,NULL,&hKey,&dwDisp);
}
}
else if(hKey!=NULL)
{
strt=mm.Left(mm.Find(_T('=')));
stre=mm.Right(mm.GetLength()-strt.GetLength()-1);
if(strt==_T('@'))
strt.Empty();
strt.Remove(_T('"'));
while(stre.GetAt(stre.GetLength()-1)==_T('\\'))
{
stre.Delete(stre.GetLength()-1,1);
st=str.Find((TCHAR)0x0d000a)-1;
mm=str.Left(st);
mm.TrimLeft();
stre+=mm;
str=str.Right(str.GetLength()-st-2);
}
stre.TrimRight();
if(stre.GetAt(0)==_T('"'))
{
int dn=stre.Find(_T('\\'));
while(dn!=-1)
{
stre.Delete(dn);
dn=stre.Find(_T('\\'),dn+1);
}
stre.Delete(0);
stre.Delete(stre.GetLength()-1);
if(RegSetValueEx(hKey,strt,NULL,REG_SZ,(LPBYTE)stre.GetBuffer(stre.GetLength()),(stre.GetLength()+1)*sizeof(TCHAR))!=ERROR_SUCCESS)
{
}
stre.ReleaseBuffer();
}
else if(stre.GetAt(0)==_T('-'))
{
if(RegDeleteValue(hKey,strt)!=ERROR_SUCCESS)
{
}
}
else
{
strl=stre.Left(stre.Find(_T(':')));
strr=stre.Right(stre.GetLength()-stre.Find(_T(':'))-1);
strl.MakeLower();
if(strl==_T("multi_sz"))
{
int dn=strr.Find(_T('\\'));
while(dn!=-1)
{
strr.Delete(dn);
dn=strr.Find(_T('\\'),dn+1);
}
strr.Delete(0);
strr.Delete(strr.GetLength()-1);
strr.Replace(_T("\",\""),_T("]"));
int rr=strr.Replace(_T(']'),0x0000);
int rl=(strr.GetLength()+1)*sizeof(TCHAR);
RegSetValueEx(hKey,strt,NULL,REG_MULTI_SZ,(LPBYTE)strr.GetBuffer(rl),rl);
}
else if(strl==_T("dword"))
{
DWORD dwVal=HexToDword(strr);
RegSetValueEx(hKey,strt,NULL,REG_DWORD,(LPBYTE)&dwVal,sizeof(DWORD));
}
else if(strl.Find(_T("hex("))!=-1)
{
int bl;
HexToInt(strr,&bl);
TCHAR N=strl.GetAt(4);
RegSetValueEx(hKey,strt,NULL,_wtoi(&N),bin,bl);
delete bin;
}
else if(strl==_T("hex"))
{
int bl;
HexToInt(strr,&bl);
RegSetValueEx(hKey,strt,NULL,REG_BINARY,bin,bl);
delete bin;
}
}
}
}
else if(strt==_T("快捷方式"))
{
char ln[512];
int st=stre.Find(_T('='));
strl=stre.Left(st);
strr=stre.Right(stre.GetLength()-st-1);
CFile lnk;
if(lnk.Open(strr,CFile::modeCreate|CFile::modeWrite))
{
int len=strl.GetLength()+1;
mm.Format(_T("%d#"),len);
mm+=strl;
::WideCharToMultiByte(CP_ACP, 0,mm, -1,ln,sizeof ln, NULL, NULL);
lnk.Write(&ln,mm.GetLength());
}
lnk.Close();
}
else if(strt==_T("创建目录"))
{
::CreateDirectory(stre,NULL);
}
else if(strt==_T("删除文件"))
{
::DeleteFile(stre);
}
else if(strt==_T("复制文件"))
{
int st=stre.Find(_T('='));
strl=stre.Left(st);
strr=stre.Right(stre.GetLength()-st-1);
CopyFile(strl,strr,FALSE);
}
else if(strt==_T("移动文件"))
{
int st=stre.Find(_T('='));
strl=stre.Left(st);
strr=stre.Right(stre.GetLength()-st-1);
MoveFile(strl,strr);
}
else if(strt==_T("删除目录"))
{
DeleteDirectory(stre);
}
else if(strt==L"运行程序")
{
int st=stre.Find(_T('='));
strl=stre.Left(st);
strr=stre.Right(stre.GetLength()-st-1);
CreateProcess(strl,strr,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
}
else if(strt==_T("注册表开始")||strt==_T("REGEDIT4")||strt==_T("Windows Registry Editor Version 5.00"))
isreg =TRUE;
else if(strt==_T("重新启动"))
isroot=TRUE;
else if(strt==_T("导入文件"))
ReadGBT(stre);
}
}
BOOL CGBToolApp::DeleteDirectory(CString mm)
{
// return ::RemoveDirectory(mm);
HANDLE hFind; // file handle
WIN32_FIND_DATA FindFileData;
TCHAR DirPath[MAX_PATH];
TCHAR FileName[MAX_PATH];
_tcscpy(DirPath,mm);
_tcscat(DirPath,_T("\\*")); // searching all files
_tcscpy(FileName,mm);
_tcscat(FileName,_T("\\"));
hFind = FindFirstFile(DirPath,&FindFileData); // find the first file
if(hFind == INVALID_HANDLE_VALUE) return FALSE;
_tcscpy(DirPath,FileName);
bool bSearch = true;
while(bSearch)
{ // until we finds an entry
// if(IsDots(FindFileData.cFileName)) continue;
if((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_INROM))
{
}
else if((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)&&(FindFileData.dwFileAttributes&FILE_ATTRIBUTE_TEMPORARY))
{
// HTREEITEM hItem2=m_te2.InsertItem(FindFileData.cFileName,hItem);
// m_te2.SetItemImage(hItem2,2,2);
// FileEnum(hItem2);
}
else if((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
wcscat(FileName,FindFileData.cFileName);
DeleteDirectory(FileName);
RemoveDirectory(FileName); // remove the empty directory
_tcscpy(FileName,DirPath);
}
else
{
wcscat(FileName,FindFileData.cFileName);
if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
{
::SetFileAttributes(FileName,FILE_ATTRIBUTE_NORMAL);
}
DeleteFile(FileName);
_tcscpy(FileName,DirPath);
}
if(FindNextFile(hFind,&FindFileData))
{
}
else{
if(GetLastError() == ERROR_NO_MORE_FILES) // no more files there
bSearch = false;
else {
// some error occured, close the handle and return FALSE
FindClose(hFind);
return FALSE;
}
}
}
FindClose(hFind); // closing file handle
return RemoveDirectory(mm); // remove the empty directory
}
/*
BOOL CGBToolApp::IsDots(const TCHAR* str)
{
if(_tcscmp(str,_T(".")) && _tcscmp(str,_T(".."))) return FALSE;
return TRUE;
}
*/
LPBYTE CGBToolApp::HexToInt(CString mm, LPINT bl)
{
int sl=mm.GetLength();
bin=new BYTE[sl/2];
mm.MakeLower();
BOOL High=TRUE;
int n=0;
for(int i=0;i<sl;i++)
{
BYTE l= (BYTE)mm.GetAt(i);
if(l>='a'&&l<='f')
{
l=l-0x57;
}
else if(l>='0'&&l<='9')
{
l=l-0x30;
}
else continue;
if(High==TRUE)
{
bin[n]=l*0x10;
High=FALSE;
}
else
{
bin[n]+=l;
High=TRUE;
n++;
}
}
*bl=n;
return bin;
}
DWORD CGBToolApp::HexToDword(CString mm)
{
DWORD dw;
mm.MakeReverse();
mm.MakeLower();
int sl=mm.GetLength();
for(int i=0;i<sl;i++)
{
DWORD l= mm.GetAt(i);
if(l>='a'&&l<='f')
{
l=l-0x57;
}
else if(l>='0'&&l<='9')
{
l=l-0x30;
}
if(i==0)
dw=l;
else
{
if(l!=0)
{
for(int n=i;n>0;n--)
{
l*=0x10;
}
dw+=l;
}
}
}
return dw;
}
/*
BOOL CGBToolApp::HardResetPocketPC()
{
SetCleanRebootFlag();
return KernelIoControl(IOCTL_HAL_REBOOT, NULL, 0, NULL, 0, NULL);
}
*/
BOOL CGBToolApp::SoftResetPocketPC()
{
return KernelIoControl(IOCTL_HAL_REBOOT, NULL, 0, NULL, 0, NULL);
}
BOOL CGBToolApp::ReadGBT(CString name)
{
DWORD fl;
CFile gbt;
WORD filet;
if(gbt.Open(name,CFile::modeRead))
{
gbt.Read(&filet,sizeof filet);
fl=gbt.GetLength();
if(filet!=0xfeff)
{
char *ac=new char[fl];
gbt.SeekToBegin();
gbt.Read(ac,fl);
::MultiByteToWideChar(CP_ACP,0,ac,-1,str.GetBuffer(fl),fl);
str.ReleaseBuffer();
delete ac;
}
else
{
gbt.Read(str.GetBuffer(fl),fl);
}
gbt.Close();
str.ReleaseBuffer();
StartSet();
return TRUE;
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -