void WriteMessage(const HANDLE hPipe, const Hekate::Protobuf::Proto::Client::HekateClientMessage &msg) { std::unique_ptr<char> pBytes(new char[msg.ByteSize()]); (void)msg.SerializePartialToArray(pBytes.get(), msg.ByteSize()); DWORD dwBytesWritten = 0; DWORD dwSize = msg.ByteSize(); BOOL bRet = WriteFile(hPipe, (LPCVOID)&dwSize, sizeof(DWORD), &dwBytesWritten, nullptr); if (bRet == 0) { std::cerr << "Could not send data length to server. " << "Error = 0x" << std::hex << GetLastError(); exit(-1); } bRet = WriteFile(hPipe, pBytes.get(), dwSize, &dwBytesWritten, nullptr); if (bRet == 0) { std::cerr << "Could not send message to server. " << "Error = 0x" << std::hex << GetLastError(); exit(-1); } }
void CRemote::Output(LPCTSTR pszName) { if ( _tcsstr( pszName, L".." ) || _tcschr( pszName, L'/' ) ) return; CString strValue = Settings.General.Path + L"\\Remote\\" + pszName + L".html"; CFile hFile; if ( ! hFile.Open( strValue, CFile::modeRead ) ) return; int nBytes = (int)hFile.GetLength(); CAutoVectorPtr< BYTE > pBytes( new BYTE[ nBytes ] ); hFile.Read( pBytes, nBytes ); hFile.Close(); LPCSTR pBody = (LPCSTR)(BYTE*)pBytes; if ( nBytes > 3 && pBytes[0] == 0xEF && pBytes[1] == 0xBB && pBytes[2] == 0xBF ) { // Skip BOM pBody += 3; nBytes -= 3; } CString strBody = UTF8Decode( pBody, nBytes ); CList<BOOL> pDisplayStack; for ( BOOL bDisplay = TRUE; ; ) { int nStart = strBody.Find( L"<%" ); if ( nStart < 0 ) { if ( bDisplay ) m_sResponse += strBody; break; } else if ( nStart >= 0 ) { if ( bDisplay && nStart > 0 ) m_sResponse += strBody.Left( nStart ); strBody = strBody.Mid( nStart + 2 ); } int nEnd = strBody.Find( L"%>" ); if ( nEnd < 0 ) break; CString strKey = strBody.Left( nEnd ); strBody = strBody.Mid( nEnd + 2 ); strKey.Trim(); ToLower( strKey ); if ( strKey.IsEmpty() ) { // Nothing } else if ( strKey.GetAt( 0 ) == L'=' && bDisplay ) { strKey = strKey.Mid( 1 ); strKey.Trim(); if ( m_pKeys.Lookup( strKey, strValue ) ) m_sResponse += strValue; } else if ( strKey.GetAt( 0 ) == L'?' ) { strKey = strKey.Mid( 1 ); strKey.Trim(); if ( strKey.IsEmpty() ) { if ( ! pDisplayStack.IsEmpty() ) bDisplay = pDisplayStack.RemoveTail(); } else { if ( strKey.GetAt( 0 ) == L'!' ) { strKey = strKey.Mid( 1 ); strKey.Trim(); if ( ! m_pKeys.Lookup( strKey, strValue ) ) strValue.Empty(); pDisplayStack.AddTail( bDisplay ); bDisplay = bDisplay && strValue.IsEmpty(); } else { if ( ! m_pKeys.Lookup( strKey, strValue ) ) strValue.Empty(); pDisplayStack.AddTail( bDisplay ); bDisplay = bDisplay && ! strValue.IsEmpty(); } } } } }