Jump to content

Bit functions


CyRius
 Share

Recommended Posts

Hey, I have a question about Bit functions.

I have this function:

Func _BinaryToID($iNumber,$iCharUID)
     $iNumber = _BinaryToDec('0x' & $iNumber,1,8)
     $iNumber = BitXOR(BitOR(BitShift(BitAND($iNumber,0xFFFFE000),13),BitShift(BitAND($iNumber,0x1FFF),-19)),0x5F2D2463,$iCharUID) - 0x746F4AE6
     Return $iNumber
EndFunc

In C#:

uint Target = ((uint)Data[12] & 0xFF) | (((uint)Data[13] & 0xFF) << 8) | (((uint)Data[14] & 0xFF) << 16) | (((uint)Data[15] & 0xFF) << 24); //Target = 694CA544
Target = ((((Target & 0xffffe000) >> 13) | ((Target & 0x1fff) << 19)) ^ 0x5F2D2463 ^ 23143648) - 0x746F4AE6; //Target = 0

_BinaryToID('44A54C69',23143648) returns 0.

I want to know if this function can be reversed (_IDToBinary(0,23143648) would return '44A54C69')

I have this function, but it isnt correct (returns '694BBBD2' instead '44A54C69') and I dont know how could I correct it:

Func _IDToBinary($iNumber,$iCharUID)
     $iNumber = BitXOR(BitOR(BitShift(BitAND($iNumber,0xFFFFE000),-13),BitShift(BitAND($iNumber,0x1FFF),19)),0x5F2D2463,$iCharUID) + 0x746F4AE6
     $iNumber = _DecToBinary($iNumber,8)
     Return $iNumber
EndFunc

Func _BinaryToDec($iPacket,$iFrom,$iCount)
     Local $iNewPacket = ''
     $iPacket = BinaryMid($iPacket,$iFrom,$iCount)
     For $iIndex = 1 To $iCount
         $iNewPacket &= Hex(BinaryMid($iPacket,$iCount - $iIndex + 1,1))
     Next
     Return Dec($iNewPacket)
EndFunc

Func _DecToBinary($iPacket,$iCount)
     $iPacket = Hex(Binary($iPacket))
     If $iCount > StringLen($iPacket) Then
        For $iIndex = 1 To $iCount - StringLen($iPacket)
            $iPacket &= '0'
        Next
     Else 
        $iPacket = StringLeft($iPacket,$iCount)
     EndIf
     Return $iPacket
EndFunc

Can somebody help me?

Greetz, CyRius

Edited by CyRius

[font="Courier New"][size="3"]CyRius Developments[/size][/font][list][*]CO Proxy[*]CO Assembly tool[*]CO PacketSniffer[*]Larkinor proxy[*]BoIM Messenger[*]Encrypt/Decrypt[*]Hashtables[*]Slowest, but greatest skins ever xD[/list]

Link to comment
Share on other sites

I don't think you can recover data from a bit shift operation.

BitShift(65536,12) = 16
BitShift(16,-12) = 65525

BitShift() can be reversed if you shift "back" (if you shift 12 right, then you must shift 12 left).

But I think BitAND() can't be reversed.

Any ideas?

Edited by CyRius

[font="Courier New"][size="3"]CyRius Developments[/size][/font][list][*]CO Proxy[*]CO Assembly tool[*]CO PacketSniffer[*]Larkinor proxy[*]BoIM Messenger[*]Encrypt/Decrypt[*]Hashtables[*]Slowest, but greatest skins ever xD[/list]

Link to comment
Share on other sites

A right shift can't be recovered since you lose your lower order bits in the process. A left shift can be recovered provided that the initial value is low enough that the highest order value bit isn't lost in the process. A BitOR is hard to determine if all you're given is the result and one of the input.

Link to comment
Share on other sites

A right shift can't be recovered since you lose your lower order bits in the process. A left shift can be recovered provided that the initial value is low enough that the highest order value bit isn't lost in the process. A BitOR is hard to determine if all you're given is the result and one of the input.

It must be reversable somehow because this is a client server comunication. I have the server's source code and there is the _BinaryToTD() function. I wasn't able to get the client's source code and I don't know how could I "generate" that value with the _IDToBinary() function.

Somehow it must be reversable (I hope).

[font="Courier New"][size="3"]CyRius Developments[/size][/font][list][*]CO Proxy[*]CO Assembly tool[*]CO PacketSniffer[*]Larkinor proxy[*]BoIM Messenger[*]Encrypt/Decrypt[*]Hashtables[*]Slowest, but greatest skins ever xD[/list]

Link to comment
Share on other sites

00011011 >> 2 = 00000110

How do you expect to guess what the last two bits were given 00000110?

In right shift, you lose the lower order bits and the sign bit gets padded up front. You can't reverse it.

Okay, i see now. Thank you.

But do you have any idea how can the client generate '44A54C69' from the number 0? I don't see any other way to calculate it.

[font="Courier New"][size="3"]CyRius Developments[/size][/font][list][*]CO Proxy[*]CO Assembly tool[*]CO PacketSniffer[*]Larkinor proxy[*]BoIM Messenger[*]Encrypt/Decrypt[*]Hashtables[*]Slowest, but greatest skins ever xD[/list]

Link to comment
Share on other sites

Operators Compared in Different Languages

http://msdn.microsoft.com/en-us/library/2hxce09y%28VS.71%29.aspx

uint Target = ((uint)Data[12] & 0xFF) | (((uint)Data[13] & 0xFF) << 8) | (((uint)Data[14] & 0xFF) << 16) | (((uint)Data[15] & 0xFF) << 24); //Target = 694CA544

Target = ((((Target & 0xffffe000) >> 13) | ((Target & 0x1fff) << 19)) ^ 0x5F2D2463 ^ 23143648) - 0x746F4AE6; //Target = 0

$Target = BitAND($Data[12] , 0xFF) + BitShift(BitAND($Data[13] , 0xFF) , 8) + _
BitShift(BitAND($Data[14] , 0xFF) , 16) + BitShift(BitAND($Data[15] , 0xFF) , 24)

$Target = BitXOR(BitRotate(BitAND($Target , 0xffffe000) , 13) + BitShift(BitAND($Target , 0x1fff) , 19) _
,0x5F2D2463 ,23143648) - 0x746F4AE6

صرح السماء كان هنا

 

Link to comment
Share on other sites

@wolf9228

Your function doesn't work for me.

_BinaryToTarget('44A54C69',23143648) returns -371411555 (should return 0).

Edited by CyRius

[font="Courier New"][size="3"]CyRius Developments[/size][/font][list][*]CO Proxy[*]CO Assembly tool[*]CO PacketSniffer[*]Larkinor proxy[*]BoIM Messenger[*]Encrypt/Decrypt[*]Hashtables[*]Slowest, but greatest skins ever xD[/list]

Link to comment
Share on other sites

@wolf9228

Your function doesn't work for me.

_BinaryToTarget('44A54C69',23143648) returns -371411555 (should return 0).

Type the values of Data Array

I will attempt

uint Target = ((uint)Data[12] & 0xFF) | (((uint)Data[13] & 0xFF) << 8) | (((uint)Data[14] & 0xFF) << 16) | (((uint)Data[15] & 0xFF) << 24); //Target = 694CA544

Target = ((((Target & 0xffffe000) >> 13) | ((Target & 0x1fff) << 19)) ^ 0x5F2D2463 ^ 23143648) - 0x746F4AE6; //Target = 0

These operations For C++ Programming language

I think the problem in the type of the variable (uint)

صرح السماء كان هنا

 

Link to comment
Share on other sites

@wolf9228

Data is an array which contains the bytes of binary variable (example: 0x2000FE0300000000E024610144A54C69EE98276115000000EDD4252F00000000).

So the 12.,13.,14.,15. bytes are 0x44,0xA5,0x4C,0x69.

Greetz, CyRius

[font="Courier New"][size="3"]CyRius Developments[/size][/font][list][*]CO Proxy[*]CO Assembly tool[*]CO PacketSniffer[*]Larkinor proxy[*]BoIM Messenger[*]Encrypt/Decrypt[*]Hashtables[*]Slowest, but greatest skins ever xD[/list]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...