From f037212ac8c3a7f77af7f7a3006fe1c48884d94f Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 9 Aug 2016 21:47:28 +0200 Subject: [PATCH] Fixed some bugs --- src/danog/MadelineProto/Session.php | 13 ++++---- src/danog/MadelineProto/TL/Exception.php | 40 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 src/danog/MadelineProto/TL/Exception.php diff --git a/src/danog/MadelineProto/Session.php b/src/danog/MadelineProto/Session.php index b65dff03..4793c461 100755 --- a/src/danog/MadelineProto/Session.php +++ b/src/danog/MadelineProto/Session.php @@ -132,14 +132,15 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB } $packet_length = $this->struct->unpack('sock->read($packet_length - 4); - if ($packet_length == 4) { - throw new Exception('Server response error: '.$this->struct->unpack('newcrc32($packet_length_data.substr($packet, 0, -4)) == $this->struct->unpack('struct->unpack('struct->unpack('struct->unpack('<8sI', substr($packet, 12, 12)); $data = substr($packet, 24, (24 + $message_length) - 24); @@ -224,8 +225,8 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB $this->log->log(sprintf('Factorization %s = %s * %s', $pq, $p, $q)); // Serialize object for req_DH_params - $p_bytes = $this->struct->pack('>Q', (string) $p); - $q_bytes = $this->struct->pack('>Q', (string) $q); + $p_bytes = $this->struct->pack('>I', (string) $p); + $q_bytes = $this->struct->pack('>I', (string) $q); $new_nonce = \phpseclib\Crypt\Random::string(32); $data = $this->tl->serialize_obj('p_q_inner_data', ['pq' => $pq_bytes, 'p' => $p_bytes, 'q' => $q_bytes, 'nonce' => $nonce, 'server_nonce' => $server_nonce, 'new_nonce' => $new_nonce]); $sha_digest = sha1($data, true); diff --git a/src/danog/MadelineProto/TL/Exception.php b/src/danog/MadelineProto/TL/Exception.php new file mode 100644 index 00000000..1709993e --- /dev/null +++ b/src/danog/MadelineProto/TL/Exception.php @@ -0,0 +1,40 @@ +. +*/ + +namespace danog\MadelineProto\TL; + +class Exception extends \Exception +{ + public function __construct($message, $code = 0, Exception $previous = null) + { + // some code + if (isset($GLOBALS['doingphptests']) && $GLOBALS['doingphptests']) { + var_dump($message); + } + // make sure everything is assigned properly + parent::__construct($message, $code, $previous); + } + + /** + * ExceptionErrorHandler. + * + * Error handler + */ + public function ExceptionErrorHandler($errno = 0, $errstr = null, $errfile = null, $errline = null) + { + // If error is suppressed with @, don't throw an exception + if (error_reporting() === 0) { + return true; // return true to continue through the others error handlers + } + throw new self($errstr.' on line '.$errline.' of file '.$errfile, $errno); + } +}