//----------------------------------//
class C_Log
{
public:
C_Log(); // Constructor
~C_Log(); // De-constructor
void Reset( void ); // Prototype
void LoadLogLocation( char* szString ); // Prototype
void Log( char* szString, ... ); // Prototype
private:
char szLogLocation[ MAX_PATH ]; // Path of text file
}CLog;
//----------------------------------//
//----------------------------------//
C_Log::C_Log()
{
}
//----------------------------------//
C_Log::~C_Log()
{
}
//----------------------------------//
//----------------------------------//
void C_Log::Reset( void )
{
fstream pFile( szLogLocation, ios::out ); // Open the text file for output only ( eraces everything )
pFile.close(); // Closes file
}
//----------------------------------//
void C_Log::LoadLogLocation( char *szString )
{
strcpy( szLogLocation, szString ); // Moves file path into szLogLocation
char* pszTemp = strrchr( szLogLocation, '\\' ); // Gets last instance of '\' character in file path
*( pszTemp + 1 ) = 0; // Null out character after dash to append path
strcat( pszTemp, "\\Hook Log.txt" ); // Append file log name
}
//----------------------------------//
void C_Log::Log( char* szString, ... )
{
char* szBuffer = new char[ 2048 ]; // Create format holding char array
char szTime[ MAX_PATH ]; // Create time hold char array
time_t tmCurrentTime; // create time_t structure instance
va_list va_alist;
va_start( va_alist, szString );
vsprintf( szBuffer, szString, va_alist); // fill szBuffer with string and filled format
va_end ( va_alist );
time( &tmCurrentTime ); // Get local time
strcpy( szTime, ctime( &tmCurrentTime ) ); // load time string into szTime
szTime[ strlen( szTime ) - 1 ] = 0; // Remove newline character
strcpy( szBuffer, Strings._sprintf( "[ %s ] %s", szTime, szBuffer ) ); // Format the string ( for _sprintf view [Snippet] Dynamic format strings class )
fstream pFile( szLogLocation, ios::app ); // open file for appending
pFile << szBuffer << endl; // output string
pFile.close(); // close file
delete[] szBuffer; // free string memory
Strings.ClearSprintfQueue(); // clear queue
}
//----------------------------------//
BOOL WINAPI DllMain( HMODULE hModule, DWORD dwReason, LPVOID lpvReserved )
{
switch( dwReason )
{
case DLL_PROCESS_ATTACH:
char szString[ MAX_PATH ];
GetModuleFileName( hModule, szString, sizeof( szString ) ); // Gets dll full path and name
CLog.LoadLogLocation( szString ); // Sets up the text log location
CLog.Log( "// Library injected //" ); // Example on how its used
break;
case DLL_PROCESS_DETACH:
CLog.Log( "// Library released %d//\n\n\n", 0 ); // Example on how its used
break;
}
return TRUE;
}
"Jangan segan untuk bertanya, bila agan kesulitan silahkan tinggalkan komentar di bawah, maka akan saya bantu semaksimal mungkin "
Tidak ada komentar:
Posting Komentar