Luigi Auriemma

aluigi.org (ARCHIVE-ONLY FORUM!)
It is currently 19 Jul 2012 16:17

All times are UTC [ DST ]





Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 22 posts ] 
Author Message
 Post subject: Gsmsalg 0.3.2 PHP port by jan0 giving strange ip's/ports...
PostPosted: 21 Apr 2008 12:39 

Joined: 21 Apr 2008 12:34
Posts: 13
Hey!

I have tried out the Gsmsalg PHP port by jan0, but the IP list of for example battlefield2 is not correct. No IP or port is correct... I have also tried other games, the IP's and ports always have some value, just not the right one (Compared with net.gamespy.com/masterserver).
I just copied the files to my webspace and opened index2.php.

Does anyone know what's wrong?
Thanks!
Greets


Top
 Profile  
 
 
 Post subject:
PostPosted: 23 Apr 2008 09:21 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
tested just now locally using index2.php and it works perfectly, the results are corrects and are the same of gslist


Top
 Profile  
 
 Post subject:
PostPosted: 23 Apr 2008 14:56 

Joined: 21 Apr 2008 12:34
Posts: 13
Hello!

Thanks for testing! I have just done so too locally and it really worked well.
So it must be my webspace provider. Do you have any clue if there must be some special PHP settings activated? I am only getting strange, incorrect ip and port numbers on my webspace.

Thanks!
Greets


Top
 Profile  
 
 Post subject:
PostPosted: 23 Apr 2008 15:47 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
except for the usage of the sockets I have not seen additional things


Top
 Profile  
 
 Post subject:
PostPosted: 23 Apr 2008 16:05 

Joined: 21 Apr 2008 12:34
Posts: 13
Damn...

I can't explain these strange values myself. Tested now on a few webspace providers, always the same :(

If someone got a hint, so please...

Here you can see, all ports are different, but they should be 15425:
http://rhonkar.kilu.de/test/index2.php
(Game: Vietcong)

Any chance to contact @jan0 ?

Thanks!
Greets


Top
 Profile  
 
 Post subject:
PostPosted: 24 Apr 2008 13:30 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
"Notice: Uninitialized string offset: 6 in /data/apache/users/kilu.de/rhonkar/www/test/uberconteneur.php on line 48"... maybe this the cause of the problems?

about contacting jan0, if I'm not in error he or someone else placed the link to his work on the kquery forum and unfortunately kquery is dead from months and that forum has been deleted so there are no other references about jan0.
I have tried to search in all the programs/stuff on that page but still no references about how to contact him


Top
 Profile  
 
 Post subject:
PostPosted: 24 Apr 2008 16:46 

Joined: 21 Apr 2008 12:34
Posts: 13
Too bad... thanks for the efforts!

Hmm I cannot get the notice fixed, but it works on my local server so why not on any other? I have tried out several PHP settings, failed...

Greets


Top
 Profile  
 
 Post subject:
PostPosted: 28 Apr 2008 14:01 

Joined: 21 Apr 2008 12:34
Posts: 13
Hey!

I think I have found the answer. The Bitoperation-Functions are only designed for 32bit CPU's... But webhosters are mostly running 64bit like mine:


Code:
Webhoster:
PHP_VERSION=5.1.6
PHP_OS=Linux
PHP_INT_MAX=9223372036854775807
PHP_INT_SIZE=8
+1 -> -9223372036854775808
- -> -9223372036854775807
-1 -> -9223372036854775808
L -> dcba
N -> abcd
V -> dcba


Local:
PHP_VERSION=5.2.5
PHP_OS=WINNT
PHP_INT_MAX=2147483647
PHP_INT_SIZE=4
+1 -> -2147483648
- -> -2147483647
-1 -> -2147483648
L -> dcba
N -> abcd
V -> dcba



Is it much work to change these functions so that they are compatible with 32- AND 64bit? I have no knowledge about this stuff :(
Maybe someone can help me?

Here you can find the much more clear arranged script:
http://rhonkar.kilu.de/gsquery.rar

The problematic functions (I think):

function lshiftright($var,$amt)
function _BF_SHR32($x,$bits)
function _BF_SHL32($x,$bits)
...

Thanks!
Greets


Last edited by Atako on 28 Apr 2008 15:26, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: 28 Apr 2008 14:27 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
nice intuition, who has a 64 bit processor to verify this at 100% and possibly modify the php code?
Anyway try to substituite the "return $total;" at line 54 of encshared.php with "return $total & 0xffffffff;".
I bet there are other things to change but this can be a beginning.


Top
 Profile  
 
 Post subject: Re: Gsmsalg 0.3.2 PHP port by jan0 giving strange ip's/ports...
PostPosted: 07 Jun 2009 11:28 

Joined: 21 Apr 2008 12:34
Posts: 13
Still noone?

//EDIT:
I progressed a little.
I got a tip that every left-shift must be changed because otherwhise the bits >32 would make a new value, so everything over 32 must be deleted and I have tried that. Have also changed some "4" values into PHP_INT_SIZE (as much as possible so that there are still a few 154... ports).
Now, a few ports are suspicious correct (beginning with 154...), but still, as already said, ~95% of all ports must begin with 154...

Old code:
http://rhonkar.kilu.de/gsquery.zip
Output: http://rhonkar.kilu.de/1/

New code:
http://rhonkar.kilu.de/gsquery64try.zip
Output: http://rhonkar.kilu.de/2/


Thanks anyways!


Top
 Profile  
 
 Post subject: Re: Gsmsalg 0.3.2 PHP port by jan0 giving strange ip's/ports...
PostPosted: 07 Jun 2009 21:36 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
as you know I can't help much.
but I have a (stupid) doubt about a thing.
do you know if the values used in the shift operations are declared as signed or unsigned?
because shifting and signed numbers can't be used (x86 architecture) otherwise there are risks of wrong results.
so if you can declare unsigned numbers (like in my code), do it.


Top
 Profile  
 
 Post subject: Re: Gsmsalg 0.3.2 PHP port by jan0 giving strange ip's/ports...
PostPosted: 08 Jun 2009 06:24 

Joined: 21 Apr 2008 12:34
Posts: 13
php.net wrote:
PHP does not support unsigned integers


Top
 Profile  
 
 Post subject: Re: Gsmsalg 0.3.2 PHP port by jan0 giving strange ip's/ports...
PostPosted: 08 Jun 2009 07:25 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
and what about the following?
Quote:
PHP_INT_SIZE=8

have you verified if locally works and remotely not?
because the size of int is for sure a big reason


Top
 Profile  
 
 Post subject: Re: Gsmsalg 0.3.2 PHP port by jan0 giving strange ip's/ports...
PostPosted: 08 Jun 2009 08:40 

Joined: 21 Apr 2008 12:34
Posts: 13
What do you mean?
I have tried to change some of the constant "4" values to PHP_INT_SIZE, without success.

//EDIT: Oh, yes, it works on 32bit systems but not on 64bit.


Top
 Profile  
 
 Post subject: Re: Gsmsalg 0.3.2 PHP port by jan0 giving strange ip's/ports...
PostPosted: 08 Jun 2009 08:53 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
what about the following?
http://it2.php.net/manual/en/language.t ... .php#73766

if that one doesn't work or can't be implemented (I'm not a PHP guy so my knowledge about it is limited) you can choose the &0xffffffff work-around after some math operations


Top
 Profile  
 
 Post subject: Re: Gsmsalg 0.3.2 PHP port by jan0 giving strange ip's/ports...
PostPosted: 08 Jun 2009 09:26 

Joined: 21 Apr 2008 12:34
Posts: 13
I don't know what a "+ 0" to an integer should do... in that example there is a string literal... I also noticed no change whilst experimenting.
I don't know what you mean with a "&0xffffffff workaround".

//EDIT:
Oh, but isn't it the same doing this...

Code:
// 32 bit
//$dst .= gsvalfunc((($x & 3) << 4) | ($y >> 4));
      
// 64 bit
$temp1 = ($x & 3) << 4;
$temp1 &= ~(0xFFFFFFFF << 32); // Change here
$dst .= gsvalfunc($temp1 | ($y >> 4));

...and this...

Code:
// 32 bit
//$dst .= gsvalfunc((($x & 3) << 4) | ($y >> 4));
      
// 64 bit
$temp1 = ($x & 3) << 4;
$temp1 &= 0xFFFFFFFF; // Change here
$dst .= gsvalfunc($temp1 | ($y >> 4));

.. for example?


Top
 Profile  
 
 Post subject: Re: Gsmsalg 0.3.2 PHP port by jan0 giving strange ip's/ports...
PostPosted: 08 Jun 2009 10:49 

Joined: 21 Apr 2008 12:34
Posts: 13
I progressed again. Tested the Decode() function with constant data on both 32bit and 64bit systems.
Result: The while-loop in DecodeHelper1() is the problem! Before it, the data is the same on 32bit and 64bit, but not after it...


Top
 Profile  
 
 Post subject: Re: Gsmsalg 0.3.2 PHP port by jan0 giving strange ip's/ports...
PostPosted: 08 Jun 2009 12:20 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
"&= ~(0xFFFFFFFF << 32)" and "&= 0xFFFFFFFF" are the same but why someone should be so crazy to use the first one? :)

DecodeHelper1 is the core of the algorithm which calls DecodeHelper2 two times.
in my opinion, just as lame test, you should put a "var &= 0xffffffff" after each operation like:
Code:
         $t2 = ~$t2;
         $t2 &= 0xffffffff;
         $t4 = ($t4 << 1) + 1;
         $t4 &= 0xffffffff;
         $t3 = ($t2 << 24) | lshiftright($t2 , 8);
         $t3 &= 0xffffffff;
only a test, nothing else (but plus or less is what you have already done so don't know)


Top
 Profile  
 
 Post subject: Re: Gsmsalg 0.3.2 PHP port by jan0 giving strange ip's/ports...
PostPosted: 08 Jun 2009 13:48 

Joined: 21 Apr 2008 12:34
Posts: 13
Ok thanks! After doing that (but only in DecodeHelper3()), $dest ($tbuff in helper1) is equal on 32bit and 64bit before a call to DecodeHelper1().

So I can say now:
DecodeHelper1() is the last function call for the result. There is a while-loop. Before that loop, every data is the same on 32bit and 64bit ($tbuff, $datap and $len). After the while-loop, $datap differs from 32bit on 64bit even if I'm commenting out the DecodeHelper2() call in that loop...


Top
 Profile  
 
 Post subject: Re: Gsmsalg 0.3.2 PHP port by jan0 giving strange ip's/ports...
PostPosted: 08 Jun 2009 14:08 

Joined: 21 Apr 2008 12:34
Posts: 13
IT WORKS IT WORKS IT WORKS =)
Thanks such a lot! Did the same ( &= 0xFFFFFFFF) in DecodeHelper2().

YAHOO!


Top
 Profile  
 
 Post subject: Re: Gsmsalg 0.3.2 PHP port by jan0 giving strange ip's/ports...
PostPosted: 08 Jun 2009 20:20 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
well done.
anyway this lack of portability in PHP is really a very bad thing, I hope exist other non-invasive solutions for using 32bit variables instead of the continuous &0xffffffff.

feel free to share the final result, maybe someone else could be interested.


Top
 Profile  
 
 Post subject: Re: Gsmsalg 0.3.2 PHP port by jan0 giving strange ip's/ports...
PostPosted: 08 Jun 2009 21:40 

Joined: 21 Apr 2008 12:34
Posts: 13
http://rhonkar.kilu.de/gsquery64.zip

*THUMBS UP*


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 22 posts ] 

All times are UTC [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: