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

📄 util.cpp

📁 数据加密算法
💻 CPP
字号:
#include "pch.h"
#include "util.h"

// search a given dll name which can be loaded
void xSearchModule ( LPCTSTR pFile , LPCTSTR pPath , CString& strPathName )
{
	TCHAR buf [ MAX_PATH ] ;
	TCHAR backup [ MAX_PATH ] ;

	GetCurrentDirectory ( MAX_PATH , backup ) ;
	SetCurrentDirectory ( strPathName ) ;

	if ( 0 == SearchPath ( pPath , pFile , NULL , MAX_PATH , buf , NULL ) )
	{
		if ( 0 == SearchPath ( NULL , pFile , NULL , MAX_PATH , buf , NULL ) )
		{
			strPathName = pPath ;
			strPathName += pFile ;

			return ;
		}
	}
	strPathName = buf ;

	SetCurrentDirectory ( backup ) ;
}

// translate RVA to offset in image
DWORD xFromRVA ( DWORD rva , LOADED_IMAGE& img )
{
	return ( DWORD ) ImageRvaToVa ( 
		img.FileHeader , 
		img.MappedAddress ,
		rva ,
		NULL ) ;
}

// split path name to file name and path
void xSplitPathName ( LPCTSTR pPathName , CString& strFile , CString& strPath )
{
	int i , j ;

	for ( i = strlen ( pPathName ) ; i > 0 && pPathName [ i - 1 ] != '\\' ; i-- ) ;

	if ( i <= 0 )
	{
		strFile = pPathName ;
		return ;
	}

	strFile = pPathName + i ;
	strPath.Empty ( ) ;

	for ( j = 0 ; j < i ; j++ )
	{
		strPath += pPathName [ j ] ;
	}
}

// insert a column into a list control
void xInsertColumn ( CListCtrl& ctrl , int col , UINT nID , int nWidth )
{
	CString s; 
	
	if ( nID != 0 )
	{
		s.LoadString ( nID ) ;
		ctrl.InsertColumn ( col , s , LVCFMT_LEFT , nWidth ) ;
	}
	else ctrl.InsertColumn ( col , NULL , LVCFMT_LEFT , nWidth ) ;
}

// using memory-mapping file to load an image
BOOL xMapAndLoad ( LPCTSTR pPathName , LOADED_IMAGE& img )
{
	CString fn , path ;
	LPTSTR p1 , p2 ;
	BOOL ret ;

	xSplitPathName ( pPathName , fn , path ) ;
	p1 = fn.LockBuffer ( ) ;
	p2 = path.LockBuffer ( ) ;

	ret = MapAndLoad ( p1 , p2 , &img , FALSE , TRUE ) ;

	fn.UnlockBuffer ( ) ;
	path.UnlockBuffer ( ) ;

	return ret ;
}

// check if a given file is existing
BOOL xIsFileExisting ( LPCTSTR lpPathName )
{
	HANDLE h = CreateFile ( lpPathName , GENERIC_READ , FILE_SHARE_READ | FILE_SHARE_WRITE ,
		NULL , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL ) ;

	if ( h == INVALID_HANDLE_VALUE ) return FALSE ;
	else
	{
		CloseHandle ( h ) ;
		return TRUE ;
	}
}

// translate time
void xTranslateTime ( DWORD dwTime , CString& str )
{
	DWORD t1 , t2 , t3 ;

	t3 = dwTime % 1000 ; dwTime /= 1000 ;
	t2 = dwTime % 60 ; dwTime /= 60 ;
	t1 = dwTime % 60 ; dwTime /= 60 ;

	str.Format ( "%02d:%02d:%03d" , t1 , t2 , t3 ) ;
}

⌨️ 快捷键说明

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