⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 allmycode.cpp

📁 让传奇3服务端支持动态域名的插件。VS2005的工程。这个是LOGINSER的插件。要和DBSER插件一起使用。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	{
		::ZeroMemory(bHostName,255);
		if(::gethostname( bHostName, 255) == SOCKET_ERROR)
			return false;
		HostEnt = gethostbyname ( bHostName );
		if( HostEnt != NULL) 
		{
			for(int Num = 0 ;;Num++ )
			{
				char* bHostIp = inet_ntoa( *( struct in_addr * )HostEnt->h_addr_list[Num] );
				::ZeroMemory(tHostIp,255);
				CharToWchar( tHostIp, bHostIp);
				HostIp->Format(_T("%s"), tHostIp );
						
				if( (HostEnt->h_addr_list[Num] + HostEnt->h_length) >= HostEnt->h_name )
					break;
			}
			return true;
		}
	}
	catch(_com_error& e)
	{
		CString ErrorMessage;
		ErrorMessage.Format( _T("操作异常!\r\n错误信息%s"), e.ErrorMessage());
		MessageBox(NULL, ErrorMessage,_T("错误"),NULL );
	}
	WSACleanup();
	return false;
}

//解析域名到IP
BOOL	HostToIP(CString	Name,CString*	HostIp)
{
	WORD wVersionRequested; 
	WSADATA	wsaData;
	CHAR	bHostName[255];
	TCHAR	tHostIp[255];
	HOSTENT*	HostEnt;


	wVersionRequested = MAKEWORD(2 , 2);
	int err = WSAStartup(wVersionRequested , &wsaData );
	if( err != 0 )
	{
		return false;
	}
	
	try
	{
		::ZeroMemory(bHostName,255);
		WcharToChar( Name.AllocSysString(), bHostName);
		HostEnt = gethostbyname ( bHostName );
		if( HostEnt != NULL) 
		{
			for(int Num = 0 ;;Num++ )
			{
				char* bHostIp = inet_ntoa( *( struct in_addr * )HostEnt->h_addr_list[Num] );
				::ZeroMemory(tHostIp,255);
				CharToWchar( tHostIp, bHostIp);
				HostIp->Format(_T("%s"), tHostIp );
						
				if( (HostEnt->h_addr_list[Num] + HostEnt->h_length) >= HostEnt->h_name )
					break;
			}
			return true;
		}
	}
	catch(_com_error& e)
	{
		CString ErrorMessage;
		ErrorMessage.Format( _T("操作异常!\r\n错误信息%s"), e.ErrorMessage());
		MessageBox(NULL, ErrorMessage,_T("错误"),NULL );
	}
	WSACleanup();
	return false;
}

//插入代码并加入自己的代码获得指定值存入EBX
//--------------------插入地址------------------覆盖代码长度---------------自定义函数地址/名------代码指针------代码长度-----
DWORD DetourMyCode( DWORD targetCodeAddress, DWORD targetCodeLength, DWORD ourFunctionAddress ,BYTE* lpCode , DWORD CodeLength)
{
    // 目标处代码长度小于 5 则太短不足以填充跳转代码
    if ( targetCodeLength < 5 )
        return 0x01;//代码太小

    //
    // 修改权限, 分配相关资源
    //
    DWORD oldAttr = 0, tmpAttr = 0, tmpIdx = 0;

    // 修改目标代码区权限为可执行可读写
    if ( !VirtualProtect( (void *)(DWORD_PTR)targetCodeAddress, targetCodeLength, PAGE_EXECUTE_READWRITE, &oldAttr ) )
	{
		MessageBox(NULL, _T("内存权限设置失败!"),_T("提示"),NULL);
        return 0x02;
	}

	BYTE *backupCode;
		// 在堆上分配内存用以备份原目标代码
		backupCode = new BYTE[ targetCodeLength ];
		if ( backupCode == NULL )
			return 0x03;

    // 在堆上分配内存用以存放构造的跳转代码
    BYTE *jumpCode = new BYTE[ targetCodeLength ];
    if ( jumpCode == NULL )
    {
        delete[] backupCode;
        return 0x04;
    }

    // 在堆上分配内存用以存放构造的"门"代码, 并修改其权限为可执行可读写
	DWORD GateWayCode_Len = targetCodeLength+ CodeLength + 12;
    BYTE *gatewayCode = new BYTE[ GateWayCode_Len ];
    if ( gatewayCode == NULL )
    {
        delete[] backupCode;
        delete[] jumpCode;

        return 0x05;
    }
    if ( !VirtualProtect( (void *)gatewayCode, GateWayCode_Len , PAGE_EXECUTE_READWRITE, &tmpAttr ) )
    {
        delete[] backupCode;
        delete[] jumpCode;
        delete[] gatewayCode;

        return 0x06;
    }

		//
		// 备份原目标代码
		//   
		memcpy( (void *)backupCode, (const void *)(DWORD_PTR)targetCodeAddress, targetCodeLength );
    //
    // 构造跳转代码, 覆盖到目标处代码处, 使其转到我们构造的"门"代码处
    //
    jumpCode[0] = 0xE9;//E8 CALL E9 JMP,原始E8
    *(PDWORD)( jumpCode + 1 ) = \
		(DWORD)(DWORD_PTR)(&(*gatewayCode)) - targetCodeAddress - 5;

    // 将多余字节填充为 nop
    DWORD tmp = 5;
    while ( tmp < targetCodeLength )
        jumpCode[ tmp++ ] = 0x90;

    memcpy( (void *)(DWORD_PTR)targetCodeAddress, (const void *)jumpCode, targetCodeLength );

    //
    // 构造"门"代码, 维护宿主程序现场并调用 ourFuncitonAddr
    //
	DWORD	CodePosition = 0;
		gatewayCode[CodePosition] = 0x60;
		if( lpCode )
		{
			for( CodePosition++ ;CodePosition <= CodeLength ;CodePosition++)
			{
				gatewayCode[CodePosition] = lpCode[ CodePosition-1 ];
			}
		}
		else
			CodePosition++;
		gatewayCode[CodePosition] = 0xE8;
		*(PDWORD)(gatewayCode+CodePosition+1) = ourFunctionAddress - (DWORD)(DWORD_PTR)(&(*gatewayCode)) - 1 - 1 - 4 - CodeLength;
		gatewayCode[CodePosition+5] = 0x61;
	
		memcpy( (void *)(gatewayCode+CodePosition+6), backupCode, targetCodeLength );
	    gatewayCode[ CodePosition + 6 + targetCodeLength ] = 0xE9;
		*(PDWORD)( gatewayCode + CodePosition + 6 + targetCodeLength + 1 )
			= targetCodeAddress + targetCodeLength - (DWORD)(DWORD_PTR)(&(*gatewayCode)) - 7 - targetCodeLength - 1 - 4 - CodeLength;
      
    //
    // 恢复权限, 释放相关资源
    //
    // 注意, 这里释放 backupCode, jumpCode, 不释放 gatewayCode
    // gatewayCode 在我们的目的上生命期相当于静态变量, 所以不用删除, 程
    // 序退出时操作系统会将其释放
    //
    VirtualProtect( (void *)(DWORD_PTR)targetCodeAddress, targetCodeLength, oldAttr, &tmpAttr );
   
	delete[] backupCode;
    delete[] jumpCode;

    return 0xff;
}

/*
在IP地址的主要三种类型里,各保留了三个区域作为私有地址,其地址范围如下: 

A类地址:10.0.0.0~10.255.255.255 

B类地址:172.16.0.0~172.31.255.255 

C类地址:192.168.0.0~192.168.255.255 
*/
inline BOOL  IsPrivateIP( CString InComeIP)
{
	LPINICONTROL	lpConfigIni = new INICONTROL;
	TCHAR	PmsIP[16];
	InComeIP.Trim();
	if( lpConfigIni->GetIntFromIni( CfgIni_ServerKey_Main, CfgIni_ServerKey_UseProtMap, CfgIni_DEF_UseFlag) )
	{
		CString		ProtMapIP;
		lpConfigIni->GetStrFromIni( CfgIni_ServerKey_Main, CfgIni_ServerKey_ProtMapSerIP, PmsIP);
		ProtMapIP = PmsIP;
		if( ProtMapIP.IsEmpty())
			ProtMapIP = CfgIni_DEF_PMSIP;
		ProtMapIP.Trim();
		if( ProtMapIP.Compare( InComeIP ) == NULL )
		{
			delete [] lpConfigIni;
			return false;
		}
		delete [] lpConfigIni;
	}


	int		PrivateIP_First[] = { 10,172,192 };
	int		PrivateIP_Second[] = { 16,31,168};
	char	strInComeIP[16] = {0}, strInComeIP_First[4]={0},strInComeIP_Second[4]={0};
	if( InComeIP.Compare( _T("127.0.0.1") ) == NULL )//相同
		return true;
	if( WcharToChar( InComeIP.AllocSysString() , strInComeIP))
	{
		size_t First_Len = strstr(  strInComeIP, ".") - strInComeIP;
		::ZeroMemory( strInComeIP_First, 4);
		strncpy_s( strInComeIP_First, -1, strInComeIP,First_Len);
		size_t Second_Len = strstr( strstr(  strInComeIP, ".")+1, ".") - (strstr(  strInComeIP, ".")+1);
		::ZeroMemory( strInComeIP_Second, 4);
		strncpy_s( strInComeIP_Second, -1, strstr(  strInComeIP, ".")+1 ,Second_Len);
		int FirstNum = atoi( strInComeIP_First );
		int SecindNum = atoi( strInComeIP_Second );
		for(int i=0;i < 3 ; i++)
		{
			if( PrivateIP_First[i] == FirstNum)
			{
				if( i == 0 )
					return true;
				else if( i == 1 )
				{
					if( PrivateIP_Second[ i-1 ] <= SecindNum && PrivateIP_Second[ i ] >= SecindNum)
						return true;
				}
				else
				{
					if( PrivateIP_Second[ i ] == SecindNum )
						return true;
				}
			}
		}
	}
	return false;
}

//-----------------------------------------------------------------------------
extern HHOOK	MainWndHook;
static HWND	BackMainWnd_hWnd = NULL, Wnd_hWnd = NULL;
NOTIFYICONDATA	SF_Pnotify;//系统栏
LRESULT CALLBACK MyWindProc( int nCode, WPARAM wParam, LPARAM lParam )
{
	PCWPSTRUCT	lpMsg_Stc = PCWPSTRUCT(lParam);
	UINT	HK_Message = lpMsg_Stc->message;
	WPARAM	HK_wParam = lpMsg_Stc->wParam;
	LPARAM	HK_lParam = lpMsg_Stc->lParam;
	HWND	HK_hWnd = lpMsg_Stc->hwnd ;

	CString	cMainDlgText = _T("Login Server"),cWndText;
	if(nCode == HC_ACTION )//
	{
		if( Wnd_hWnd == NULL || HK_hWnd == Wnd_hWnd)
		{
			switch( HK_Message ) 
			{
				case WM_CREATE:
					return 0;
			
			//	case SF_SYS_ICON:
			//		break;

				case WM_SETTEXT:
					cWndText = (LPCTSTR)HK_lParam;
					if( cWndText.Find( cMainDlgText ) != -1 )
					{
						Wnd_hWnd = HK_hWnd;
						//::RegisterHotKey( Wnd_hWnd, , , );
						//-----------------------在系统栏显示图标-------------------------------
						SF_Pnotify.hWnd = Wnd_hWnd;
						SF_Pnotify.hIcon = LoadIcon( NULL, (LPCTSTR)IDI_LOGINSER);
						SF_Pnotify.cbSize = sizeof(NOTIFYICONDATA);
						SF_Pnotify.uCallbackMessage = SF_SYS_ICON;
						SF_Pnotify.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
						SF_Pnotify.uID = IDI_LOGINSER;
						_tcscpy_s( SF_Pnotify.szTip,-1,cWndText.AllocSysString());
						::Shell_NotifyIcon(NIM_ADD , &SF_Pnotify);
					}
					break;

				case WM_COMMAND:
					break;
			
				case WM_DESTROY:
					break;
			}
		}
	}
	return CallNextHookEx(MainWndHook, nCode, wParam, lParam );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -