void CMMServer::ProcessStatisticsRequest(CMMData* data, CMMSocket* sender){ uint16 nWidth = data->ReadShort(); CArray<UpDown>* rawData = theApp.webserver->GetPointsForWeb(); int nRawDataSize = rawData->GetSize(); int nCompressEvery = (nRawDataSize > nWidth) ? nRawDataSize / nWidth : 1; int nPos = (nRawDataSize > nWidth) ? (nRawDataSize % nWidth) : 0; int nAddUp, nAddDown, nAddCon, i; ASSERT (nPos + nCompressEvery * nWidth == nRawDataSize || (nPos == 0 && nRawDataSize < nWidth)); CMMPacket* packet = new CMMPacket(MMP_STATISTICSANS); packet->WriteShort((uint16)((nRawDataSize-nPos)*thePrefs.GetTrafficOMeterInterval())); packet->WriteShort((uint16)(min(nWidth, nRawDataSize))); while (nPos < nRawDataSize){ nAddUp = nAddDown = nAddCon = 0; for (i = 0; i != nCompressEvery; i++){ if (nPos >= nRawDataSize){ ASSERT ( false ); break; } else{ nAddUp += (int) (rawData->ElementAt(nPos).upload * 1024); nAddDown += (int) (rawData->ElementAt(nPos).download * 1024); nAddCon += rawData->ElementAt(nPos).connections; } nPos++; } packet->WriteInt((uint32)ROUND(nAddUp/i)); packet->WriteInt((uint32)ROUND(nAddDown/i)); packet->WriteShort((uint16)ROUND(nAddCon/i)); } ASSERT ( nPos == nRawDataSize ); sender->SendPacket(packet); }
bool MusicUtils::IsStrInStrAarry(CString e,CString str) { CArray<CString,CString&> arrays; SpliteCString(str,arrays,_T(",")); for (int i=0;i<arrays.GetSize();i++) { if (arrays.ElementAt(i)==e) return true; } return false; }
u32 CHookFunction_i::GetExportFunctionInfo(CArray<EXPORT_FUN_INFO, EXPORT_FUN_INFO&>& InfoArray, const char* pszDllFile) { if(!pszDllFile) { return 0; } PLOADED_IMAGE pImage = ::ImageLoad((char*)pszDllFile, NULL); if(!pImage) { return 0; } DWORD dwBase = (DWORD)pImage->MappedAddress; PIMAGE_SECTION_HEADER pSections = (PIMAGE_SECTION_HEADER)((DWORD)pImage->FileHeader + sizeof(IMAGE_NT_HEADERS)); PIMAGE_EXPORT_DIRECTORY pExportDir = (PIMAGE_EXPORT_DIRECTORY)(RVA2RawAdr(pSections, pImage->FileHeader->OptionalHeader.DataDirectory[0].VirtualAddress) + dwBase); InfoArray.RemoveAll(); EXPORT_FUN_INFO info; DWORD* pFunOffsetAdr = (DWORD*)(RVA2RawAdr(pSections, pExportDir->AddressOfFunctions) + dwBase); for(DWORD i = 0; i < pExportDir->NumberOfFunctions; i++) { info.dwOffset = 0; info.strFunName = ""; info.dwOrdinal = 0; info.dwOffset = *(pFunOffsetAdr + i); info.dwOrdinal = i + 1; InfoArray.Add(info); } DWORD* pFunNamesAdr = (DWORD*)(RVA2RawAdr(pSections, pExportDir->AddressOfNames) + dwBase); WORD* pFunNamesOrdinalAdr = (WORD*)(RVA2RawAdr(pSections, pExportDir->AddressOfNameOrdinals) + dwBase); char* pName = NULL; for(i = 0; i < pExportDir->NumberOfNames; i++) { pName = (char*)(RVA2RawAdr(pSections, *(pFunNamesAdr+i)) + dwBase); int idx = *(pFunNamesOrdinalAdr+i); if(idx < InfoArray.GetSize()) { EXPORT_FUN_INFO& tmpInfo = InfoArray.ElementAt(idx); tmpInfo.strFunName = pName; } } ImageUnload(pImage); return InfoArray.GetSize(); }
// CString strDllFile(_T("E:\\DevTools\\VC6\\VC6.0.Full.G\\VC98\\Bin\\C1.DLL")); u32 CHookFunction_i::ViewExportFunctionInfo(LPCTSTR pszDllFile, LPCTSTR pszOutFile, bool bAutoOpenFile) // _T("*****@*****.**") { u32 ret = ERR_OK_I; CArray<EXPORT_FUN_INFO, EXPORT_FUN_INFO&> InfoArray; #ifdef HAVE_UNICODE_I CHAR file[MAX_PATH] = {0, }; CStringUtl::wcs2mbsz(file, wcslen(pszDllFile), pszDllFile); if(GetExportFunctionInfo(InfoArray, file) > 0) #else if(GetExportFunctionInfo(InfoArray, pszDllFile) > 0) #endif { CFile fileTmp; if(fileTmp.Open(pszOutFile, CFile::modeCreate | CFile::modeReadWrite)) { CString strTmp; strTmp.Format("%s Export Information:", pszDllFile); fileTmp.Write(strTmp, strTmp.GetLength()); for (int i=0;i < InfoArray.GetSize();i++) { EXPORT_FUN_INFO& r = InfoArray.ElementAt(i); // return the reference. if(r.dwOffset == 0) continue; strTmp.Format("\r\n%3d 0x%p %s", r.dwOrdinal, r.dwOffset, r.strFunName); fileTmp.Write(strTmp, strTmp.GetLength()); } fileTmp.Close(); if(bAutoOpenFile) { ShellExecute(NULL, "open", "notepad.exe", pszOutFile, NULL, SW_NORMAL); } } } return ret; }
bool CTobCompiler::CompilePass2(F_ErrorHandler ErrorHandler) { bool haserr = false; int i, j, m, n = m_exp.GetSize(); int pos, val, temp, factor; int len = m_bin.GetSize(); CString err; m_line = 0; for(i = 0; i < n; ++i) { val = 0; factor = 1; const SExpInfo* ti = m_exp.ElementAt(i); m = ti->m_item.GetSize(); pos = ti->m_pos; for(j = 0; j < m; ++j) { CString& str = ti->m_item[j]; if(str == "+") factor = 1; else if(str == "-") factor = -1; else if(str == "@") { val += (pos + m_bit_i/8) * factor; factor = 1; } else { char c = str[0]; if(c == '$') { str.Delete(0); c = str[0]; } if(c >= '0' && c <= '9') val += atoi(str) * factor; else { if(m_label.Lookup(str, temp)) val += temp * factor; else { m_err.Format("not found token '%s' at line %d", (LPCTSTR)str, ti->m_line); haserr = true; if(!ErrorHandler(GetErrorString(err))) return false; } } factor = 1; } } if(pos + m_bit_i/8 > len) { m_err.Format("internal compiler error %d > %d", pos + m_bit_i/8, len); haserr = true; ErrorHandler(GetErrorString(err)); return false; } if(m_bit_i < 32 && val >= (1<<m_bit_i)) { m_err.Format("overflow address (%p) when setting '.bit %u'", val, m_bit_i); haserr = true; if(!ErrorHandler(GetErrorString(err))) return false; } m_bin[pos ] = val & 255; if(m_bit_i >= 16) m_bin[pos + 1] = (val >> 8) & 255; if(m_bit_i >= 24) m_bin[pos + 2] = (val >> 16) & 255; if(m_bit_i >= 32) m_bin[pos + 3] = val >> 24; } return !haserr; }
// speed optimized and made unicode-compatible inline bool CFilenameLayer::FilesEqual( CFileInfo & FileInfo1, CFileInfo & FileInfo2) const { switch ( m_FilenameMatchMode ) { case IDC_MATCH_FILENAMES: if ( m_CaseSensitive ) return _tcscmp( FileInfo1.GetName() , FileInfo2.GetName() ) == 0; else return _tcsicmp( FileInfo1.GetName() , FileInfo2.GetName() ) == 0; break; case IDC_MATCH_EXTENSIONS: { LPCTSTR pExtension1, pExtension2; pExtension1 = FileInfo1.GetExtension(); pExtension2 = FileInfo2.GetExtension(); if ( pExtension1 == NULL || pExtension2 == NULL ) { return ( pExtension1 == pExtension2 ); } else { if ( m_CaseSensitive ) return _tcscmp( pExtension1 , pExtension2 ) == 0; else return _tcsicmp( pExtension1 , pExtension2 ) == 0; } } break; case IDC_MATCH_NOT_FILENAME: if ( m_CaseSensitive ) return _tcscmp( FileInfo1.GetName() , FileInfo2.GetName() ) != 0; else return _tcsicmp( FileInfo1.GetName() , FileInfo2.GetName() ) != 0; break; case IDC_MATCH_NOT_EXTENSIONS: { LPCTSTR pExtension1, pExtension2; pExtension1 = FileInfo1.GetExtension(); pExtension2 = FileInfo2.GetExtension(); if ( pExtension1 == NULL || pExtension2 == NULL ) { return ( pExtension1 == pExtension2 ); } else { if ( m_CaseSensitive ) return _tcscmp( pExtension1 , pExtension2 ) != 0; else return _tcsicmp( pExtension1 , pExtension2 ) != 0; } } break; case IDC_MATCH_WORDS: { CArray <CString, CString&> Words1; CArray <CString, CString&> Words2; CArray <CString, CString> IgnoreWords; CString strMask; CString TempStr = FileInfo1.GetBaseName(); int nPos = 0; int nNextPos = 0; int x, y; nPos = 0; nNextPos = 0; // add file masks while (nPos < TempStr.GetLength()) { nNextPos = TempStr.Find( _T(" ") ,nPos); if (nNextPos == -1) nNextPos = TempStr.GetLength(); strMask = TempStr.Mid(nPos, nNextPos-nPos); strMask.TrimLeft(); strMask.TrimRight(); if ( !m_CaseSensitive ) strMask.MakeUpper(); if (strMask != "") Words1.Add(strMask); nPos = nNextPos + 1; } // TempStr = FileInfo2.GetBaseName(); nPos = 0; nNextPos = 0; // add file masks while (nPos < TempStr.GetLength()) { nNextPos = TempStr.Find( _T(" ") ,nPos); if (nNextPos == -1) nNextPos = TempStr.GetLength(); strMask = TempStr.Mid(nPos, nNextPos-nPos); strMask.TrimLeft(); strMask.TrimRight(); if ( !m_CaseSensitive ) strMask.MakeUpper(); if (strMask != "") Words2.Add(strMask); nPos = nNextPos + 1; } // // remove duplicate words for (x = Words1.GetSize()-1; x > 0 ; x--) { for (y = x-1; y >= 0; y--) { if ( Words1.ElementAt(x) == Words1.ElementAt(y) ) { Words1.RemoveAt(x); break; } } } // // remove duplicate words for (x = Words2.GetSize()-1; x > 0 ; x--) { for (y = x-1; y >= 0; y--) { if ( Words2.ElementAt(x) == Words2.ElementAt(y) ) { Words2.RemoveAt(x); break; } } } // IgnoreWords.Add("-"); IgnoreWords.Add("A"); IgnoreWords.Add("THE"); IgnoreWords.Add("I"); IgnoreWords.Add("AT"); IgnoreWords.Add("OF"); IgnoreWords.Add("ON"); bool deleted; // remove ignored words for (x = Words1.GetSize()-1; x>=0; x--) { deleted = false; y = 0; //for (y = 0; y < IgnoreWords.GetSize(); y++) while ( !deleted && y < IgnoreWords.GetSize() ) { if ( Words1.ElementAt(x) == IgnoreWords.ElementAt(y) ) { Words1.RemoveAt(x); deleted = true; } y++; } } // remove ignored words for (x = Words2.GetSize()-1; x>=0; x--) { deleted = false; y = 0; //for (y = 0; y < IgnoreWords.GetSize(); y++) while ( !deleted && y < IgnoreWords.GetSize() ) { if ( Words2.ElementAt(x) == IgnoreWords.ElementAt(y) ) { Words2.RemoveAt(x); deleted = true; } y++; } } UINT CommonCount = 0; // calculate the number of common words for (x = 0; x < Words1.GetSize(); x++) { for (y = 0; y < Words2.GetSize(); y++) { if ( Words1.ElementAt(x) == Words2.ElementAt(y) ) CommonCount++; } } return ( CommonCount >= m_WordCount ); } break; default: AfxMessageBox( _T("FMM_ERROR") ); return true; break; } /* // not optimized CString File1, File2; File1 = FileInfo1.Filename.Right( FileInfo1.Filename.GetLength() - FileInfo1.Filename.ReverseFind('\\') - 1 ); File2 = FileInfo2.Filename.Right( FileInfo2.Filename.GetLength() - FileInfo2.Filename.ReverseFind('\\') - 1 ); if ( !m_FilenameLayerForm.m_CaseSensitive ) { File1.MakeUpper(); File2.MakeUpper(); } switch ( m_FilenameMatchMode ) { case IDC_MATCH_FILENAMES: return File1 == File2; break; case IDC_MATCH_EXTENSIONS: return File1.Right( File1.GetLength() - File1.ReverseFind('.') - 1 ) == File2.Right( File2.GetLength() - File2.ReverseFind('.') - 1); break; case IDC_MATCH_NOTHING: return true; break; case IDC_MATCH_NOT_FILENAME: return File1 != File2; break; case IDC_MATCH_NOT_EXTENSIONS: return File1.Right( File1.GetLength() - File1.ReverseFind('.') - 1 ) != File2.Right( File2.GetLength() - File2.ReverseFind('.') - 1); break; default: AfxMessageBox("FMM_ERROR"); return true; break; } */ }