Тема: icq бот
Показать сообщение отдельно

  #37  
Старый 18.02.2006, 02:58
KEZ
Banned
Регистрация: 18.05.2005
Сообщений: 1,981
Провел на форуме:
1941233

Репутация: 2726


По умолчанию

По порядку.
Это c99phpicq.php

Код:
<?php
##########################################################
#######!              c99phpicq.php              !########
##########################################################
class ICQ
{
 var $socket,$server,$port,$connected,
	 $uin,$pass,$logged,
	 $dbgstream,$errorstream,$lasterror;
 var $TLV = array();
 var $TLV_dstb = array();
 var $FLAP = array();
 var $mess = array();
 var $memory = array();
 var $events = array();
 var $settings = array();
 function ICQ($uin,$pass,$server="login.icq.com",$port=5190)
 {
  $this->events = array(
   "onunwanteddisconnect" => "\$this->connect();",
   "onmessagerecv" => null
  );
  $this->settings = array(
   "client" => array(
    "name" => "1",
    "country" => "ru",
    "language" => "ru",
    "build" => 1,
    "id" => 234,
    "major" => 0,
    "minor" => 2,
    "lesser" => 1
   )
  );
#  $this->dbgstream = fopen("dbgstream.out","wb");
  //$this->dbgstream = fsockopen(127.0.0.1,5191);
#  $this->errorstream = fopen("errorstream.out","wb");
  //$this->errorstream = fsockopen(127.0.0.1,5192);
  $this->server = $server;
  $this->port = $port;
  $this->uin = $uin;
  $this->pass = $pass;  
 }
 function connect($server="",$port="")
 {
  if (!empty($server)) {$this->server = $server;}
  if (!empty($port)) {$this->port = $port;}
  $this->socket = @fsockopen($this->server,$this->port,$errno,$errstr,3);
  if (!$this->socket) {$this->_error("connect","connection to ".$this->server.":".$this->port." has failed: ".$errno." - ".$errstr,__FILE__,__LINE__); return false;}
  else {$this->connected = true; return true;}
 }
 function _connect_migration($server,$port)
 {
  $this->socket = @fsockopen($server,$port,$errno,$errstr,3);
  if (!$this->socket) {$this->_error("connect_migration","migration to ".$server.":".$port." has failed: ".$errno." - ".$errstr,__FILE__,__LINE__); return false;}
  else {$this->connected = true; return true;}
 }
 function connect_pass()
 {
  if ($this->connected)
  {
   if ($this->socket) {return true;}
   else
   {
    eval($this->events["onunwanteddisconnect"]);
    return is_resource($this->socket);
   }
  }
  else {return false;}
 }
 function login_pass() {$this->connect_pass(); return $this->socket and $this->logged;}
 function login($uin="",$pass="")
 {
  if ($uin) {$this->uin = $uin;}
  if ($pass !== "") {$this->pass = $pass;}
  $this->TLV[1] = $this->uin;
  $this->TLV[2] = xorpass($this->pass);
  $this->TLV[3] = substr($this->settings["client"]["name"],0,20);
  $this->TLV[14] = $this->settings["client"]["country"];
  $this->TLV[15] = $this->settings["client"]["language"];
  $this->TLV[20] = 85;
  $this->TLV_dstb[20] = 4;
  $this->TLV[22] = $this->settings["client"]["id"];
  $this->TLV_dstb[22] = 2;
  $this->TLV[23] = $this->settings["client"]["major"];
  $this->TLV_dstb[23] = 2;
  $this->TLV[24] = $this->settings["client"]["minor"];
  $this->TLV_dstb[24] = 2;
  $this->TLV[25] = $this->settings["client"]["lesser"];
  $this->TLV_dstb[25] = 2;
  $this->TLV[26] = $this->settings["client"]["build"];
  $this->TLV_dstb[26] = 2;
  $this->connect_pass();
  if (!$this->socket) {return false;}
  else
  {
   $this->FLAP["outsid"] = rand(0x0001,0x8000);
   $this->FLAP_recv();
   $this->FLAP_send("CMD_LOGIN");
   $cook = $this->FLAP_recv();
   if ($this->FLAP["type"] == 4) {$this->TLV_recv($cook);}
   if (isset($this->TLV[5]) && isset($this->TLV[6]))
   {
    $address = explode(":", $this->TLV[5]);
    $this->_connect_migration($address[0],$address[1]);
    if (!$this->socket) {return false;}
    else
    {
     $this->FLAP_recv();
     $this->FLAP_send("CMD_COOKIE");
     $this->FLAP_recv();
     $this->FLAP_send("CMD_READY");
     //$this->TLV = array();
     $this->logged = true;
     return true;
    }
   }
   else {$this->_error("login","authorization failed: too fast",__FILE__,__LINE__); return false;}
  }
 }
 function message_send($uin,$message)
 {
  $this->login_pass();
  if ($this->logged and $this->is_uin($uin))
  {
   $this->FLAP["touin"] = $uin;
   $this->FLAP["outdata"] = $message;
   $this->FLAP_send("CMD_MESSAGE");
   //sleep(10);
   return true;
  }
  else {return false;}
 }
 function listen()
 {
  unset($this->mess);
  $arr = $this->FLAP_recv();
  if ($arr !== 0)
  {
   if ($this->FLAP["type"] == 2) {$this->SNAC_recv($arr);} 
   if (isset($this->mess["channel"]))
   {
    if ($this->mess["channel"] == 1) {$this->mess["text"] = $this->_message_recv1($this->TLV[2]);}
    if ($this->mess["channel"] == 2) {$this->mess["text"] = $this->_message_recv2($this->TLV[5]);}
    eval($this->events["onmessagerecv"]);
    return true;
   }
   else {return false;} 
   return true;
   //unset($this->TLV); 
  }
  else {return false;}
 }
 function FLAP_recv()
 {
  $Fh = @fread($this->socket,6);
  if (strlen($Fh) == 6)
  { 
   $this->_dbg("FLAP_recv","inhead:".$Fh);
   if (ord($Fh{0}) !== 0x2A) {$this->_error("FLAP_recv","ICQ protocol sync error",__FILE__,__LINE__); return false;}
   $this->FLAP["type"] = ord($Fh[1]);
   $Fsid = ord($Fh{3})+(ord($Fh[2])<<8);
   //$Fsid = (int)(ord($Fh{2}).ord($Fh{3}));
   if (!isset($this->FLAP["insid"])) {$this->FLAP["insid"] = $Fsid;}
   if ($Fsid != $this->FLAP["insid"])
   {
     $this->_error("FLAP_recv","ICQ protocol sync error my sid ".$Fsid." != ".$this->FLAP["insid"],__FILE__,__LINE__);
     return false;
   }
   else
   {
    $this->FLAP["insid"]++;
    if ($this->FLAP["insid"] == 0x8000) {$this->FLAP["insid"] = 0x0000;}
   }
   $Fds = ord($Fh{5})+(ord($Fh{4})<<8);
   //$Fds = (int)(ord($Fh{4}).ord($Fh{5}));
   $data = fread($this->socket,$Fds);
   if ($this->FLAP["type"] == 4) {fclose($this->socket); unset($this->FLAP["insid"]);}
   $this->_dbg("FLAP_recv","|-|".$data);
   return $data;
  }
  else {return false;}
 }
 function FLAP_send($type,$SNAC=false)
 {
  if (!$SNAC) {$SNAC = $this->SNAC_send($type);}
  if (!$SNAC) {return false;}
  else
  {
   list($channel,$SNAC) = $SNAC;
   $FLAP = i2b(1,0x2A).i2b(1,$channel).i2b(2,$this->FLAP["outsid"]).i2b(2,strlen($SNAC));
   $data = $FLAP.$SNAC;
   $this->_dbg("FLAP_send","send type ".$type.", channel ".$channel.": |||".$FLAP."|-|".$SNAC."|||");
   fwrite($this->socket,$data);
   $this->FLAP["outsid"]++;
  }
 }
 function TLV_send($arr)
 {
  if (!is_array($arr)) {$arr = func_get_args();}
  $out = "";
  foreach($arr as $i)
  {
   $out .= i2b(2,$i);
   if (isset($this->TLV_dstb[$i])) {$size = $this->TLV_dstb[$i];}
   else {$size = strlen($this->TLV[$i]);}
   $out .= i2b(2,$size);
   if (is_int($this->TLV[$i])) {$out .= i2b($size,$this->TLV[$i]);}
   else {$out .= $this->TLV[$i];}
  }
  return $out;
 }
 function TLV_recv($str="")
 {
  $out = array();
  while ($str != "")
  {
   $i = ord($str[1])+(ord($str[0])<<8);
   $out[] = $i;
   $size = ord($str[3])+(ord($str[2])<<8);
   $sizes[] = $size;
   $this->TLV[$i] = substr($str,4,$size);
   $str = substr($str,4+$size);
  }
  return $out;
 }
 function SNAC_send($type)
 {
  $channel = 2;
  if ($type == "CMD_LOGIN") {$data = i2b(4,1).$this->TLV_send(1,2,3,22,23,24,25,26,20,15,14); $channel = 1;}
  elseif ($type == "CMD_COOKIE") {$data = i2b(4,1).$this->TLV_send(6); $this->TLV[6] = ""; $channel = 1;}
  elseif ($type == "CMD_READY")
  {
   $data = "\x00\x01\x00\x02\x00\x00\x00\x00\x00\x02\x00\x01\x00\x03\x01\x10".
	   "\x02\x8A\x00\x02\x00\x01\x01\x01\x02\x8A\x00\x03\x00\x01\x01\x10". 
           "\x02\x8A\x00\x15\x00\x01\x01\x10\x02\x8A\x00\x04\x00\x01\x01\x10". 
           "\x02\x8A\x00\x06\x00\x01\x01\x10\x02\x8A\x00\x09\x00\x01\x01\x10". 
           "\x02\x8A\x00\x0A\x00\x01\x01\x10\x02\x8A";
  }
  elseif ($type == "CMD_MESSAGE")
  {
   $this->TLV[2] =
    i2b(4,0x05010001).i2b(3,0x010101).
    i2b(2,strlen($this->FLAP["outdata"])+4).i2b(4,0).
    $this->FLAP["outdata"];
   $data =
    i2b(2,4).i2b(2,6).			i2b(2,0).i2b(4,6).
    i2b(8,time()).i2b(2,1).  	i2b(1,strlen($this->FLAP["touin"])).
    $this->FLAP["touin"].		$this->TLV_send(2,6);
  }
  else {$this->_error("SNAC_send() error: unknown/unsupported SNAC-type (".$type.")."); return false;}
  return array($channel,$data);
  $this->_dbg("SNAC_send","type ".$type.", channel ".$channel.": ".$data);
 }
 function SNAC_recv($str)
 {
  $result = null;
  $family = ord($str[1])+(ord($str[0])<<8);
  $subfamily = ord($str[3])+(ord($str[2])<<8);
  if ($family == 4)
  {
   if ($subfamily == 7)
   {
    $this->mess["mid"] = substr($str,10,8);
    $this->mess["channel"] = ord(substr($str,19,1));
    $uin_size = ord(substr($str,20,1));
    $this->mess["uin"] = substr($str,21,$uin_size);
    $str = substr($str,25+$uin_size);
    $this->TLV_recv($str);
    $result = true;
   }
  }
  if ($result === null) {$this->_error("SNAC_recv","unknown/unsupported SNAC ".$family."-".$subfamily.".",__FILE__,__LINE__); return false;}
  elseif ($result === false) {$this->_error("SNAC_recv","processing ".$family."-".$subfamily." failed: ".$err.".",__FILE__,__LINE__); return false;}
  else {return true;}
 }
 function _message_recv1($str)
 {
  $s1 = ord($str{3})+(ord($str{2})<<8);
  $s = substr($str,6+$s1,2);
  $s2 = ord($s[1])+(ord($s[0])<<8);
  $text = substr($str,12+$s1,$s2+4);
  return $text;
 }
 function _message_recv2($str)
 {
  $s1 = substr($str,2,2);
  $s2 = substr($str,6+$s1,2);
  return substr($str,8+$s1,$s2);
 }
 function _dbg($procedure,$info,$file="unknown",$line="unknown")
 {
#  $string = $procedure."() info: ".$info." in file ".$file." at line ".$line.".";
#  if (is_resource($this->dbgstream)) {fwrite($this->dbgstream,$string."\n"); return true;}
#  else {return false;}
  return true;
 }
 function _error($procedure,$error,$file="unknown",$line="unknown")
 {
#  $string = $procedure."() error: ".$error." in file ".$file." at line ".$line.".";
#  $this->lasterror = $string;
#  if (is_resource($this->errorstream)) {fwrite($this->errorstream,$string."\n"); return true;}
#  else {return false;}
  return true;
 }
 function lasterror() {return $this->lasterror;}
 function is_uin($uin) {$uin = $this->defake($uin); return is_numeric($uin) and strlen($uin) >= 1 and strlen($uin) <= 9;}
 function defake($uin) {while ($uin - 4294967296 > 0) {$uin -= 4294967296;} return $uin;}
 function disconnect() {$this->connected = $this->logged = false; return fclose($this->socket);}
 function http_checklogin($uin,$password)
 {
  $http = @fsockopen("www.icqmail.com",80,$errno,$errstr,1);
  if ($http)
  {
   $post ="user=admin&AltID=".$uin."&pwd=".urlencode($password)."&repwd=".urlencode($password)."&firstname=&lastname=&tosagree=&action=register&xo=RU";
   fwrite($http,"POST http://www.icqmail.com/s/icq/reg_icq.asp HTTP/1.1\n". 
			"Host: www.icqmail.com\n".
			"Connection: close\n".
			"TE: deflate, gzip, chunked, identity, trailers\n".
			"Content-Type: application/x-www-form-urlencoded\n".
			"Content-Length: ".strlen($post)."\n".
			"\n".$post."\n");
  while (!feof($http) and $line = fgets($http)) {if (strpos($line,"someone has already chosen")) {return 1; break;} elseif (strpos($line,"Password do not match")) {return 0; break;}}
  return false;
 }
 else {$this->_error("http_checklogin","connection to www.icqmail.com:80 has failed",__FILE__,__LINE__);}
}
}
function int2bits($bits,$val=0) {$ret = ""; for ($i=0; $i<$bits; $i++) {$ret = chr(($val >> ($i*8) & 0xFF)).$ret;} return $ret;}
function i2b($bits,$val=0) {return int2bits($bits,$val);}
function bits2int($hex=0)
{
 $dec = 0;
 $bitval = 1; 
 for($pos = 1; $pos <= strlen($hex); $pos++) {$dec += hexdec(substr($hex, -$pos, 1)) * $bitval; $bitval *= 16;} 
 return $dec;
}
function b2i($hex=0) {return bits2int($hex);}
function xorpass($pass)
{
 $roast = array(0xF3,0x26,0x81,0xC4,0x39,0x86,0xDB,0x92 /*,0x71,0xA3,0xB9,0xE6,0x53,0x7A,0x95,0x7c*/);
 $xored = "";
 for ($i=0; $i<strlen($pass); $i++) {$xored .= chr($roast[$i] ^ ord($pass{$i}));}
 return $xored;
}
###############################################################
#################!   END OF c99phpicq.php    !#################
###############################################################
?>
А это example.php
Код:
<?php
$BotUin = "232323";
$BotPass = "6(sic)6";

include( "c99phpicq.php" );

$icq = new ICQ( $BotUin, $BotPass );
@$icq->connect() || die( "Couldnot connect - @\$icq->connect() failed\n" );
@$icq->login() || die( "Couldnot login - @\$icq->login() failed\n" );

$icq->message_send( "898989", "Fuck me" ); 

?>
попробуй. если все ок, напишу тебе как сделать из этого бота