BOOL CSecurity::Import(LPCTSTR pszFile) { CString strText; CBuffer pBuffer; CFile pFile; if ( ! pFile.Open( pszFile, CFile::modeRead ) ) return FALSE; pBuffer.EnsureBuffer( (DWORD)pFile.GetLength() ); pBuffer.m_nLength = (DWORD)pFile.GetLength(); pFile.Read( pBuffer.m_pBuffer, pBuffer.m_nLength ); pFile.Close(); CXMLElement* pXML = CXMLElement::FromBytes( pBuffer.m_pBuffer, pBuffer.m_nLength, TRUE ); BOOL bResult = FALSE; if ( pXML != NULL ) { bResult = FromXML( pXML ); delete pXML; } else { CString strLine; while ( pBuffer.ReadLine( strLine ) ) { strLine.Trim(); if ( strLine.IsEmpty() ) continue; if ( strLine.GetAt( 0 ) == ';' ) continue; CSecureRule* pRule = new CSecureRule(); if ( pRule->FromGnucleusString( strLine ) ) { CQuickLock oLock( m_pSection ); m_pRules.AddTail( pRule ); bResult = TRUE; } else { delete pRule; } } } // Check all lists for newly denied hosts PostMainWndMessage( WM_SANITY_CHECK ); return bResult; }
int CProfileProfilePage::LoadDefaultInterests() { int nCount = 0; const CString strFile = Settings.General.Path + _T("\\Data\\Interests.dat"); // Settings.General.DataPath ? CFile pFile; if ( ! pFile.Open( strFile, CFile::modeRead ) ) return nCount; try { CString strLine; CString strLang = _T(" ") + Settings.General.Language; CBuffer pBuffer; pBuffer.EnsureBuffer( (DWORD)pFile.GetLength() ); pBuffer.m_nLength = (DWORD)pFile.GetLength(); pFile.Read( pBuffer.m_pBuffer, pBuffer.m_nLength ); pFile.Close(); // Format: Delineated List, enabled by prespecified #languages: #start en ... #end en // (Allows multiple/nested/overlapped languages, all applicable results displayed alphabetically) BOOL bActive = FALSE; while ( pBuffer.ReadLine( strLine ) ) { if ( strLine.GetLength() < 2 ) continue; // Blank line if ( strLine.GetAt( 0 ) == '#' ) // Language start/end line { if ( strLine.Find( strLang, 4 ) < 1 && strLine.Find( _T(" all"), 4 ) < 1 ) { if ( strLine.Left( 10 ) == _T("#languages") ) strLang = _T(" en"); } else if ( strLine.Left( 6 ) == _T("#start") || strLine.Left( 6 ) == _T("#begin") ) bActive = TRUE; else if ( strLine.Left( 4 ) == _T("#end") ) bActive = FALSE; //break; continue; } if ( ! bActive ) continue; // Disinterested language if ( strLine.Find( _T("\t") ) > 0 ) // Trim at whitespace (remove any comments) strLine.Left( strLine.Find( _T("\t") ) ); nCount++; m_wndInterestAll.AddString( strLine ); } } catch ( CException* pException ) { if ( pFile.m_hFile != CFile::hFileNull ) pFile.Close(); // File is still open so close it pException->Delete(); } return nCount; }
void CMessageFilter::Load() { CFile pFile; CString strFilteredPhrases, strED2KSpamPhrases; const CString strFile = Settings.General.Path + _T("\\Data\\MessageFilter.dat"); // Delete current filter (if present) if ( m_pszFilteredPhrases ) delete [] m_pszFilteredPhrases; m_pszFilteredPhrases = NULL; // Load the message filter from disk if ( pFile.Open( strFile, CFile::modeRead ) ) { try { CBuffer pBuffer; DWORD nLen = (DWORD)pFile.GetLength(); if ( ! pBuffer.EnsureBuffer( nLen ) ) AfxThrowUserException(); pBuffer.m_nLength = nLen; pFile.Read( pBuffer.m_pBuffer, pBuffer.m_nLength ); pFile.Close(); pBuffer.ReadLine( strED2KSpamPhrases ); pBuffer.ReadLine( strFilteredPhrases ); } catch ( CException* pException ) { if ( pFile.m_hFile != CFile::hFileNull ) pFile.Close(); // If file is still open close it pException->Delete(); } } // Insert some defaults if there was a read error if ( strED2KSpamPhrases.IsEmpty() ) strED2KSpamPhrases = _T("Your client is connecting too fast|Join the L33cher Team|PeerFactor|Your client is making too many connections|ZamBoR 2|AUTOMATED MESSAGE:|eMule FX the BEST eMule ever|DI-Emule"); if ( strFilteredPhrases.IsEmpty() ) strFilteredPhrases = _T(""); // Load the ED2K spam into the filter if ( strED2KSpamPhrases.GetLength() > 3 ) { LPCTSTR pszPtr = strED2KSpamPhrases; int nWordLen = 3; CList< CString > pWords; int nStart = 0, nPos = 0; for ( ; *pszPtr ; nPos++, pszPtr++ ) { if ( *pszPtr == '|' ) { if ( nStart < nPos ) { pWords.AddTail( strED2KSpamPhrases.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } nStart = nPos + 1; } } if ( nStart < nPos ) { pWords.AddTail( strED2KSpamPhrases.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } m_pszED2KSpam = new TCHAR[ nWordLen ]; LPTSTR pszFilter = m_pszED2KSpam; for ( POSITION pos = pWords.GetHeadPosition() ; pos ; ) { CString strWord( pWords.GetNext( pos ) ); ToLower( strWord ); CopyMemory( pszFilter, (LPCTSTR)strWord, sizeof( TCHAR ) * ( strWord.GetLength() + 1 ) ); pszFilter += strWord.GetLength() + 1; } *pszFilter++ = 0; *pszFilter++ = 0; } // Load the blocked strings into the filter if ( strFilteredPhrases.GetLength() > 3 ) { LPCTSTR pszPtr = strFilteredPhrases; int nWordLen = 3; CList< CString > pWords; int nStart = 0, nPos = 0; for ( ; *pszPtr ; nPos++, pszPtr++ ) { if ( *pszPtr == '|' ) { if ( nStart < nPos ) { pWords.AddTail( strFilteredPhrases.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } nStart = nPos + 1; } } if ( nStart < nPos ) { pWords.AddTail( strFilteredPhrases.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } m_pszFilteredPhrases = new TCHAR[ nWordLen ]; LPTSTR pszFilter = m_pszFilteredPhrases; for ( POSITION pos = pWords.GetHeadPosition() ; pos ; ) { CString strWord( pWords.GetNext( pos ) ); ToLower( strWord ); CopyMemory( pszFilter, (LPCTSTR)strWord, sizeof( TCHAR ) * ( strWord.GetLength() + 1 ) ); pszFilter += strWord.GetLength() + 1; } *pszFilter++ = 0; *pszFilter++ = 0; } }
void CListLoader::OnRun() { while ( IsThreadEnabled() && m_pQueue.GetCount() ) { CSecureRule* pRule = m_pQueue.GetHead(); if ( ! pRule || ! pRule->m_pContent || pRule->m_nType != CSecureRule::srExternal ) { m_pQueue.RemoveHead(); continue; } CString strPath = pRule->GetContentWords(); if ( strPath.GetLength() < 6 ) { m_pQueue.RemoveHead(); continue; } CString strCommentBase = pRule->m_sComment; if ( strCommentBase.IsEmpty() ) strCommentBase = _T("• %u"); else if ( strCommentBase.ReverseFind( _T('•') ) >= 0 ) strCommentBase = strCommentBase.Left( strCommentBase.ReverseFind( _T('•') ) + 1 ) + _T(" %u"); else strCommentBase += _T(" • %u"); if ( strPath[1] != _T(':') ) strPath = Settings.General.DataPath + strPath; CFile pFile; if ( ! pFile.Open( (LPCTSTR)strPath.GetBuffer(), CFile::modeRead ) ) { m_pQueue.RemoveHead(); continue; } const BYTE nIndex = Security.SetRuleIndex( pRule ); try { CBuffer pBuffer; const DWORD nLength = pFile.GetLength(); pBuffer.EnsureBuffer( nLength ); pBuffer.m_nLength = nLength; pFile.Read( pBuffer.m_pBuffer, nLength ); pFile.Close(); // Format: Delineated Lists CString strLine, strURN; DWORD nCount = 0; int nPos; //TIMER_START while ( pBuffer.ReadLine( strLine ) && IsThreadEnabled() && pRule ) { strLine.TrimRight(); if ( strLine.GetLength() < 7 ) continue; // Blank/Invalid line if ( strLine[ 0 ] == '#' ) { if ( strLine[ strLine.GetLength() - 1 ] == _T(':') && strLine.Find( _T("urn:") ) > 0 ) strURN = strLine.Mid( strLine.Find( _T("urn:") ) ); // Default "# urn:type:" continue; // Comment line } if ( strLine[ 0 ] < '0' || strLine[ 0 ] > 'z' ) // Whitespace/Chars continue; // Invalid line if ( ++nCount % 10 == 0 ) { if ( pRule->m_sComment.IsEmpty() ) strCommentBase = _T("• %u"); else if ( pRule->m_sComment.ReverseFind( _T('•') ) < 0 ) strCommentBase = pRule->m_sComment + _T(" • %u"); pRule->m_sComment.Format( strCommentBase, nCount ); Sleep( 1 ); // Limit CPU } // Hashes: if ( ( ! strURN.IsEmpty() && strLine.Find( _T('.'), 5 ) < 0 ) || StartsWith( strLine, _PT("urn:") ) ) { nPos = strLine.FindOneOf( _T(" \t") ); if ( nPos > 0 ) strLine.Truncate( nPos ); // Trim at whitespace (remove any trailing comments) if ( ! strURN.IsEmpty() && ! StartsWith( strLine, _PT("urn:") ) ) strLine = strURN + strLine; // Default "urn:type:" prepended if ( strLine.GetLength() > 35 ) Security.SetHashMap( strLine, nIndex ); else nCount--; continue; } // IPs: nPos = strLine.ReverseFind( _T(':') ); if ( nPos > 0 ) strLine = strLine.Mid( nPos + 1 ); // Remove leading comment for some formats nPos = strLine.FindOneOf( _T(" \t") ); if ( nPos > 0 ) strLine.Truncate( nPos ); // Trim at whitespace (remove any trailing comments) if ( strLine.GetLength() < 7 || strLine.Find( _T('.') ) < 1 ) { nCount--; continue; } nPos = strLine.Find( _T('-') ); // Possible Range if ( nPos < 0 ) // Single IP { Security.SetAddressMap( IPStringToDWORD( strLine, TRUE ), nIndex ); continue; } CString strFirst = strLine.Left( nPos ); CString strLast = strLine.Mid( nPos + 1 ); if ( strFirst == strLast ) { Security.SetAddressMap( IPStringToDWORD( strLine, TRUE ), nIndex ); continue; } // inet_addr( CT2CA( (LPCTSTR)strLast ) DWORD nFirst = IPStringToDWORD( strFirst, FALSE ); DWORD nLast = IPStringToDWORD( strLast, FALSE ); if ( nFirst < 10 || nFirst >= 0xE0000000 ) // 0 or "0.0." or "224-255" continue; // Redundant/Invalid //if ( Network.IsReserved( (IN_ADDR*)nFirst ) ) // Crash //if ( StartsWith( strFirst, _PT("0.0") ) || // StartsWith( strFirst, _PT("6.0") ) || // StartsWith( strFirst, _PT("7.0") ) || // StartsWith( strFirst, _PT("11.0") ) || // StartsWith( strFirst, _PT("55.0") ) || // StartsWith( strFirst, _PT("127.0") ) ) // continue; // Redundant for ( DWORD nRange = Settings.Security.ListRangeLimit ; nFirst <= nLast && nRange ; nFirst++, nRange-- ) { Security.SetAddressMap( htonl( nFirst ), nIndex ); // Reverse host-byte order } } if ( pRule ) pRule->m_sComment.Format( strCommentBase, nCount ); // Final update PostMainWndMessage( WM_SANITY_CHECK ); //TIMER_STOP } catch ( CException* pException ) { if ( pFile.m_hFile != CFile::hFileNull ) pFile.Close(); // File is still open so close it pException->Delete(); } m_pQueue.RemoveHead(); // Done } Exit(); Wakeup(); Sleep( 5000 ); // Recheck if ( ! m_pQueue.GetCount() ) // && IsThreadEnabled() { CQuickLock oLock( Security.m_pSection ); Security.m_Cache.clear(); PostMainWndMessage( WM_SANITY_CHECK ); } }
void CAdultFilter::Load() { CFile pFile; CString strBlockedWords, strDubiousWords, strChildWords; const CString strFile = Settings.General.Path + _T("\\Data\\AdultFilter.dat"); // Settings.General.DataPath ? // Delete current adult filters (if present) if ( m_pszBlockedWords ) delete [] m_pszBlockedWords; m_pszBlockedWords = NULL; if ( m_pszDubiousWords ) delete [] m_pszDubiousWords; m_pszDubiousWords = NULL; if ( m_pszChildWords ) delete [] m_pszChildWords; m_pszChildWords = NULL; // Load the adult filter from disk if ( pFile.Open( strFile, CFile::modeRead ) ) { try { CBuffer pBuffer; const DWORD nLen = (DWORD)pFile.GetLength(); if ( ! pBuffer.EnsureBuffer( nLen ) ) AfxThrowUserException(); pBuffer.m_nLength = nLen; pFile.Read( pBuffer.m_pBuffer, pBuffer.m_nLength ); pFile.Close(); pBuffer.ReadLine( strBlockedWords ); // Line 1: words that are blocked if ( ! strBlockedWords.IsEmpty() && strBlockedWords.GetAt( 0 ) == '#' ) strBlockedWords.Empty(); pBuffer.ReadLine( strDubiousWords ); // Line 2: words that may be okay if ( ! strDubiousWords.IsEmpty() && strDubiousWords.GetAt( 0 ) == '#' ) strDubiousWords.Empty(); pBuffer.ReadLine( strChildWords ); // Line 3: words for child pornography if ( ! strChildWords.IsEmpty() && strChildWords.GetAt( 0 ) == '#' ) strChildWords.Empty(); } catch ( CException* pException ) { if ( pFile.m_hFile != CFile::hFileNull ) pFile.Close(); // File is still open so close it pException->Delete(); } } // Insert some defaults if the load failed if ( strBlockedWords.IsEmpty() ) strBlockedWords = L"xxx p**n f**k c**k c**t v****a pussy nude naked boobs breast hentai " L"lesbian w***e shit rape preteen hardcore lolita playboy penthouse " L"topless r-rated x-rated d***o pr0n erotic sexy o****m nipple fetish " L"upskirt beastiality bestiality pedofil necrofil t**s lolicon shemale fisting"; if ( strDubiousWords.IsEmpty() ) strDubiousWords = L"ass sex anal gay teen thong babe bikini viagra dick cum s***s"; if ( strChildWords.IsEmpty() ) strChildWords = L"child preteen"; // Load the blocked words into the Adult Filter if ( strBlockedWords.GetLength() > 3 ) { LPCTSTR pszPtr = strBlockedWords; int nWordLen = 3; CList< CString > pWords; int nStart = 0, nPos = 0; for ( ; *pszPtr ; nPos++, pszPtr++ ) { if ( *pszPtr == ' ' ) { if ( nStart < nPos ) { pWords.AddTail( strBlockedWords.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } nStart = nPos + 1; } } if ( nStart < nPos ) { pWords.AddTail( strBlockedWords.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } m_pszBlockedWords = new TCHAR[ nWordLen ]; LPTSTR pszFilter = m_pszBlockedWords; for ( POSITION pos = pWords.GetHeadPosition() ; pos ; ) { CString strWord( pWords.GetNext( pos ) ); ToLower( strWord ); CopyMemory( pszFilter, (LPCTSTR)strWord, sizeof( TCHAR ) * ( strWord.GetLength() + 1 ) ); pszFilter += strWord.GetLength() + 1; } *pszFilter++ = 0; *pszFilter++ = 0; } // Load the possibly blocked words into the Adult Filter if ( strDubiousWords.GetLength() > 3 ) { LPCTSTR pszPtr = strDubiousWords; int nWordLen = 3; CList< CString > pWords; int nStart = 0, nPos = 0; for ( ; *pszPtr ; nPos++, pszPtr++ ) { if ( *pszPtr == ' ' ) { if ( nStart < nPos ) { pWords.AddTail( strDubiousWords.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } nStart = nPos + 1; } } if ( nStart < nPos ) { pWords.AddTail( strDubiousWords.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } m_pszDubiousWords = new TCHAR[ nWordLen ]; LPTSTR pszFilter = m_pszDubiousWords; for ( POSITION pos = pWords.GetHeadPosition() ; pos ; ) { CString strWord( pWords.GetNext( pos ) ); ToLower( strWord ); CopyMemory( pszFilter, (LPCTSTR)strWord, sizeof( TCHAR ) * ( strWord.GetLength() + 1 ) ); pszFilter += strWord.GetLength() + 1; } *pszFilter++ = 0; *pszFilter++ = 0; } // Load child pornography words into the Adult Filter if ( strChildWords.GetLength() > 3 ) { LPCTSTR pszPtr = strChildWords; int nWordLen = 3; CList< CString > pWords; int nStart = 0, nPos = 0; for ( ; *pszPtr ; nPos++, pszPtr++ ) { if ( *pszPtr == ' ' ) { if ( nStart < nPos ) { pWords.AddTail( strChildWords.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } nStart = nPos + 1; } } if ( nStart < nPos ) { pWords.AddTail( strChildWords.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } m_pszChildWords = new TCHAR[ nWordLen ]; LPTSTR pszFilter = m_pszChildWords; for ( POSITION pos = pWords.GetHeadPosition() ; pos ; ) { CString strWord( pWords.GetNext( pos ) ); ToLower( strWord ); CopyMemory( pszFilter, (LPCTSTR)strWord, sizeof( TCHAR ) * ( strWord.GetLength() + 1 ) ); pszFilter += strWord.GetLength() + 1; } *pszFilter++ = 0; *pszFilter++ = 0; } }