AgoBot 僵屍網絡研究筆記(十四)

 

十四、2008年04月8日

 

作者:青青子衿

email:[email protected]

1 LongUptime ( int   iDays )  函數

///////////////////////////////////////////////////////////////////

//

//函數功能:獲得系統正常運行的時間,如果這個值大於參數的值則顯示,

//參數:   int iDays 一個整數,比如7

//

//

///////////////////////////////////////////////////////////////////

CString   CBot :: LongUptime ( int   iDays )   // If uptime > iDays days then bot will reply with uptime stats. - PhaTTy

{  

  CString   sLongUptime ;

  if  ( iDays  == 0) 

  {

    return   false ;

  }

 

#ifdef  WIN32

  int   total = GetTickCount ()/1000;  //獲得當前系統從啓動到現在的時間,除以1000則以秒爲單位

  OSVERSIONINFO   verinfo ;

  if ( total /86400 >=  iDays //如果天數大於參數

  {

    //構造時間格式是:天、小時、分

    sLongUptime . Format ( "uptime: %dd %dh %dm" , total /86400, ( total %86400)/3600, (( total %86400)%3600)/60); 

 

  }

  else  

  {

    return   CString ( "" );  //返回空字符串

  }

#else

 

  //處理Linux平臺下的情況

  FILE  * fp = fopen ( "/proc/uptime" "r" );

  float   f1 f2 ;

 

  if (! fp

  {

    return   CString ( "Error: Can't open /proc/uptime!" );

  }

  if ( fscanf ( fp "%f %f" , & f1 , & f2 )<2) 

  {

    return   CString ( "Error: Invalid or changed /proc/uptime format!" );

  }

  fclose ( fp );

 

  int   days hours minutes ;

  days =(( abs (( int ) f1 )/60)/60)/24;

  hours =(( abs (( int ) f1 )/60)/60)%24;

  minutes =( abs (( int ) f1 )/60)%60;

  if ( days  >=  iDays )

  {

    sLongUptime . Format ( "uptime: %dd %dh %dm" days hours minutes );

  }

  else  

  {

    return   CString ( "" );

  }

#endif  // WIN32

  return   sLongUptime

}

2 Status ()   函數

///////////////////////////////////////////////////////////////////

//

//函數功能:獲得Bot運行的時間

//參數:  

//返回值:   保存有運行時間的字符串

//

/////////////////////////////////////////////////////////////////////

CString   CBot :: Status ()

{

  CString   sStatus ;

  unsigned   long   total days hours minutes

  total =( GetTickCount ()/1000)- m_lStartTime ;

  days = total /86400;

  hours =( total %86400)/3600; 

  minutes =(( total %86400)%3600)/60;

  sStatus . Format ( "%s ready. Up %dd %dh %dm." g_cMainCtrl . m_sNameVerStr . CStr (),  days hours minutes ); 

  return   sStatus

}

1、 CCryptStr   類,爲CString的子類,主要增加了對字符串加密功能的支持,但沒有支持解密功能。

class   CCryptStr  :  public   CString

{

  //該類中未出現解密函數

public :

  CCryptStr ( int   iKey );

  ~ CCryptStr ();

  char  * Str ();

  void   Release ();

protected :

  void   Decrypt ();

  int   m_iKey ;   //密鑰

  char  * m_szDecStr ;   //密文字符串buffer

  //關於明文字符串buffer部分,在其父類CString的buffer中

};

3 CCryptStr ( int   iKey )  構造函數

////////////////////////////////////////////////////

//

//函數功能:構造函數

//參數:   int iKey  密鑰

//

////////////////////////////////////////////////////

CCryptStr :: CCryptStr ( int   iKey )

  m_iKey = iKey

  m_szDecStr = NULL

}

4 :~ CCryptStr ()  析構函數

////////////////////////////////////////////////////

//

//函數功能:析構函數

//

/////////////////////////////////////////////////////

CCryptStr ::~ CCryptStr () 

  Release ();

}

5 Decrypt ()  加密函數

////////////////////////////////////////////////

//

//函數功能:加密函數,屬於簡單加密

//參數:  

//返回值:   void

//

///////////////////////////////////////////////

void   CCryptStr :: Decrypt ()

{  

  if (! m_iKey

  {

    return

  }

 

  if ( m_szDecStr

  {

    free ( m_szDecStr ); 

  }

 

  m_szDecStr =( char *) malloc ( GetLength ());

  for ( char   i =0;  i < GetLength ();  i ++) 

  {

    m_szDecStr [ i ]= m_szString [ i ]^( m_iKey +( i *( m_iKey %10)+1)); 

  }

}

6 Str ()   函數

////////////////////////////////////////////////////////////////////////

//

//函數功能:返回字符串的密文

//參數:  

//返回值:   密文字符串

//

////////////////////////////////////////////////////////////////////////////

char  * CCryptStr :: Str () 

  Decrypt (); 

  return   m_szDecStr

}

7 Release ()  函數

/////////////////////////////////////////////////////////////////

//

//函數功能:釋放保存密文的緩衝區

//參數:  

//返回值:   void

//

//////////////////////////////////////////////////////////////////

void   CCryptStr :: Release () 

  if ( m_szDecStr )

 

    free ( m_szDecStr ); 

    m_szDecStr = NULL

 

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章