Advertisement
Guest User

QTS no. 8 - Text log class

a guest
Jul 9th, 2010
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.43 KB | None | 0 0
  1. /*
  2. -----------------------------------------
  3. * Game hacking QTS ( Quickie Tip Series )
  4. * no. 8 - Text log class
  5. -----------------------------------------
  6. * Author: SEGnosis  - GHAnon.net
  7. * Thanks to:
  8. * bitterbanana      - No known site
  9. * Drunken Cheetah   - No known site
  10. * fatboy88      - No known site
  11. * Geek4Ever         - No known site
  12. * learn_more        - www.uc-forum.com
  13. * Novocaine         - http://ilsken.net/blog/?page_id=64
  14. * Philly0494        - No known site
  15. * Roverturbo        - www.uc-forum.com
  16. * SilentKarma       - www.halocoders.com - offline
  17. * Strife        - www.uc-forum.com
  18. * Wieter20      - No known site
  19. */
  20.  
  21. // Requires no. 7 - Dynamic format string class
  22. //----------------------------------//
  23. class C_Log
  24. {
  25.     public:
  26.         C_Log(); // Constructor
  27.         ~C_Log(); // De-constructor
  28.         void Reset( void ); // Prototype
  29.         void LoadLogLocation( char* szString ); // Prototype
  30.         void Log( char* szString, ... ); // Prototype
  31.  
  32.     private:
  33.         char szLogLocation[ MAX_PATH ]; // Path of text file
  34. }CLog;
  35. //----------------------------------//
  36.  
  37. //----------------------------------//
  38. C_Log::C_Log()
  39. {
  40.    
  41. }
  42. //----------------------------------//
  43. C_Log::~C_Log()
  44. {
  45.    
  46. }
  47. //----------------------------------//
  48.  
  49. //----------------------------------//
  50. void C_Log::Reset( void )
  51. {
  52.     fstream pFile( szLogLocation, ios::out ); // Open the text file for output only ( eraces everything )
  53.     pFile.close(); // Closes file
  54. }
  55. //----------------------------------//
  56. void C_Log::LoadLogLocation( char *szString )
  57. {
  58.     strcpy( szLogLocation, szString ); // Moves file path into szLogLocation
  59.    
  60.     char* pszTemp = strrchr( szLogLocation, '\\' ); // Gets last instance of '\' character in file path
  61.     *( pszTemp + 1 ) = 0; // Null out character after dash to append path
  62.     strcat( pszTemp, "\\Hook Log.txt" ); // Append file log name
  63. }
  64. //----------------------------------//
  65. void C_Log::Log( char* szString,  ... )
  66. {
  67.     char*   szBuffer = new char[ 2048 ]; // Create format holding char array
  68.     char    szTime[ MAX_PATH ]; // Create time hold char array
  69.     time_t  tmCurrentTime; // create time_t structure instance
  70.  
  71.     va_list va_alist;
  72.     va_start( va_alist, szString );
  73.     vsprintf( szBuffer, szString, va_alist); // fill szBuffer with string and filled format
  74.     va_end  ( va_alist );
  75.    
  76.     time( &tmCurrentTime ); // Get local time
  77.     strcpy( szTime, ctime( &tmCurrentTime ) ); // load time string into szTime
  78.     szTime[ strlen( szTime ) - 1 ] = 0; // Remove newline character
  79.    
  80.     strcpy( szBuffer, Strings._sprintf( "[ %s ] %s", szTime, szBuffer ) ); // Format the string ( for _sprintf view [Snippet] Dynamic format strings class  )
  81.    
  82.     fstream pFile( szLogLocation, ios::app ); // open file for appending
  83.    
  84.     pFile << szBuffer << endl; // output string
  85.    
  86.     pFile.close(); // close file
  87.    
  88.     delete[] szBuffer; // free string memory
  89.     Strings.ClearSprintfQueue(); // clear queue
  90. }
  91. //----------------------------------//
  92.  
  93. BOOL WINAPI DllMain( HMODULE hModule, DWORD dwReason, LPVOID lpvReserved )
  94. {
  95.     switch( dwReason )
  96.     {
  97.         case DLL_PROCESS_ATTACH:
  98.             char szString[ MAX_PATH ];
  99.             GetModuleFileName( hModule, szString, sizeof( szString ) ); // Gets dll full path and name
  100.  
  101.             CLog.LoadLogLocation( szString ); // Sets up the text log location
  102.             CLog.Log( "// Library injected //" ); // Example on how its used
  103.         break;
  104.        
  105.         case DLL_PROCESS_DETACH:
  106.             CLog.Log( "// Library released %d//\n\n\n", 0 ); // Example on how its used
  107.         break;
  108.     }
  109.  
  110.     return TRUE;
  111. }
  112. //----------------------------------//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement