📄 fn.cpp
字号:
#include "Fn.h"
#include "resource.h"
#include "Shellapi.h"
#include "shlwapi.h"
#pragma comment(lib,"shlwapi")
BOOL ExtraRes(WORD wInter,PWCHAR Type,PWCHAR FileName)
{
HRSRC res=FindResource(NULL,MAKEINTRESOURCE(wInter),Type);
if (res)
{
}
else
{
return FALSE;
}
HGLOBAL glres=LoadResource(NULL,res);
if (glres)
{
}
else
{
return FALSE;
}
LPVOID lpres=LockResource(glres);
if (lpres)
{
FreeResource(glres);
}
else
{
FreeResource(glres);
return FALSE;
}
HANDLE hfile=CreateFile(FileName,GENERIC_ALL,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
if (hfile==INVALID_HANDLE_VALUE)
{
return FALSE;
}
DWORD nobw;
if (WriteFile(hfile,lpres,SizeofResource(NULL,res),&nobw,NULL))
{
CloseHandle(hfile);
}
else
{
return FALSE;
}
return TRUE;
}
//
//功能模块函数
//
BOOL InstallDriver()
{
WCHAR TEMP[100]={0};
WCHAR PassthruDll[100]={0};
WCHAR PassthruSys[100]={0};
WCHAR PassthruInfNet[100]={0};
WCHAR PassthruInfNetM[100]={0};
WCHAR Snetcfg[100]={0};
GetTempPath(100,TEMP);
wsprintf(PassthruDll,L"%wspassthru.dll",TEMP);
wsprintf(PassthruSys,L"%wspassthru.sys",TEMP);
wsprintf(PassthruInfNet,L"%wsnetsf.inf",TEMP);
wsprintf(PassthruInfNetM,L"%wsnetsf_m.inf",TEMP);
wsprintf(Snetcfg,L"%wssnetcfg.exe",TEMP);
BOOL bRet=ExtraRes(IDR_DLL1,L"DLL",PassthruDll);
if (bRet==FALSE)
{
return FALSE;
}
bRet=ExtraRes(IDR_SYS1,L"SYS",PassthruSys);
if (bRet==FALSE)
{
return FALSE;
}
bRet=ExtraRes(IDR_NETSF,L"INF",PassthruInfNet);
if (bRet==FALSE)
{
return FALSE;
}
bRet=ExtraRes(IDR_NETSF_M,L"INF",PassthruInfNetM);
if (bRet==FALSE)
{
return FALSE;
}
bRet=ExtraRes(IDR_EXE1,L"EXE",Snetcfg);
if (bRet==FALSE)
{
return FALSE;
}
//执行安装~
WCHAR CmdLine[100]={0};
WCHAR CmdLine2[100]={0};
wsprintf(CmdLine,L"-l %ws -c s -i ms_passthru",PassthruInfNet);
wsprintf(CmdLine2,L"-l %ws -c s -i ms_passthru",PassthruInfNetM);
/* ShellExecute(NULL,L"open",Snetcfg,CmdLine,NULL,SW_HIDE);*/
SHELLEXECUTEINFO shinfo;
ZeroMemory(&shinfo,sizeof(SHELLEXECUTEINFO));
shinfo.cbSize=sizeof(SHELLEXECUTEINFO);
shinfo.fMask=SEE_MASK_FLAG_NO_UI|SEE_MASK_NOCLOSEPROCESS;
shinfo.lpVerb=L"open";
shinfo.lpFile=Snetcfg;
shinfo.lpParameters=CmdLine;
shinfo.nShow=SW_HIDE;
ShellExecuteEx(&shinfo);
WaitForSingleObject(shinfo.hProcess,INFINITE);
shinfo.lpParameters=CmdLine2;
ShellExecuteEx(&shinfo);
WaitForSingleObject(shinfo.hProcess,INFINITE);
return TRUE;
}
BOOL UnistallDriver()
{
WCHAR TEMP[100]={0};
WCHAR PassthruDll[100]={0};
WCHAR PassthruSys[100]={0};
WCHAR PassthruInfNet[100]={0};
WCHAR PassthruInfNetM[100]={0};
WCHAR Snetcfg[100]={0};
GB.hFile=NULL;
GetTempPath(100,TEMP);
wsprintf(PassthruDll,L"%wspassthru.dll",TEMP);
wsprintf(PassthruSys,L"%wspassthru.sys",TEMP);
wsprintf(PassthruInfNet,L"%wsnetsf.inf",TEMP);
wsprintf(PassthruInfNetM,L"%wsnetsf_m.inf",TEMP);
wsprintf(Snetcfg,L"%wssnetcfg.exe",TEMP);
WCHAR CmdLine[100]=L"-u ms_passthru";
/* ShellExecute(NULL,L"open",Snetcfg,CmdLine,NULL,SW_HIDE);*/
SHELLEXECUTEINFO shinfo;
ZeroMemory(&shinfo,sizeof(SHELLEXECUTEINFO));
shinfo.cbSize=sizeof(SHELLEXECUTEINFO);
shinfo.fMask=SEE_MASK_FLAG_NO_UI|SEE_MASK_NOCLOSEPROCESS;
shinfo.lpVerb=L"open";
shinfo.lpFile=Snetcfg;
shinfo.lpParameters=CmdLine;
shinfo.nShow=SW_HIDE;
ShellExecuteEx(&shinfo);
WaitForSingleObject(shinfo.hProcess,INFINITE);
DeleteFile(PassthruDll);
DeleteFile(PassthruSys);
DeleteFile(PassthruInfNet);
DeleteFile(PassthruInfNetM);
DeleteFile(Snetcfg);
return TRUE;
}
//
//return value:
//
//1--Log do not exists
//0--Clear Log Success
//2--Clear Log Failure
//
int ClearLog()
{
WCHAR *LogPath=L"c:\\ip_packet.txt";
if (!PathFileExists(LogPath))
{
return 1;
}
BOOL bRet=DeleteFile(LogPath);
if (bRet==0)
{
return 2;
}
return 0;
}
//*************************
//
//Command Module
//
BOOL StartLog()
{
DWORD dwLen=0;
if(!GB.hFile)
{
GB.hFile=CreateFile(L"\\\\.\\PassThru",GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(!GB.hFile)
{
MessageBox(NULL,L"连接驱动程序失败……",L"ERROR",MB_OK);
return FALSE;
}
}
BOOL bRet=DeviceIoControl(GB.hFile,IOCTL_START_LOG,NULL,0,NULL,0,&dwLen,NULL);
if(!bRet)
{
MessageBox(NULL,L"传送控制码(IOCTL_START_LOG)失败",L"ERROR",MB_OK);
return FALSE;
}
return TRUE;
}
BOOL StopLog()
{
DWORD dwLen=0;
if(!GB.hFile)
{
GB.hFile=CreateFile(L"\\\\.\\PassThru",GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(!GB.hFile)
{
MessageBox(NULL,L"连接驱动程序失败……",L"ERROR",MB_OK);
return FALSE;
}
}
BOOL bRet=DeviceIoControl(GB.hFile,IOCTL_STOP_LOG,NULL,0,NULL,0,&dwLen,NULL);
if(!bRet)
{
MessageBox(NULL,L"传送控制码(IOCTL_STOP_LOG)失败",L"ERROR",MB_OK);
return FALSE;
}
return TRUE;
}
//************************
BOOL ReadLog()
{
WCHAR NotePadPath[MAX_PATH];
GetWindowsDirectory(NotePadPath,MAX_PATH);
wcscat(NotePadPath,L"\\NOTEPAD.exe");
ShellExecute(NULL,L"open",NotePadPath,L"c:\\ip_packet.txt",NULL,SW_SHOW);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -