CompressedInt Write?

74 Views Asked by At
public static function Read(param1:IDataInput) : int
      {
         var _loc2_:* = 0;
         var _loc3_:int = param1.readUnsignedByte();
         var _loc4_:* = (_loc3_ & 64) != 0;
         var _loc5_:int = 6;
         _loc2_ = _loc3_ & 63;
         while(_loc3_ & 128)
         {
            _loc3_ = param1.readUnsignedByte();
            _loc2_ = _loc2_ | (_loc3_ & 127) << _loc5_;
            _loc5_ = _loc5_ + 7;
         }
         if(_loc4_)
         {
            _loc2_ = int(-_loc2_);
         }
         return _loc2_;
      }

someone can help me with write thing? about to use in as3 server based but got only read thing

1

There are 1 best solutions below

0
VC.One On

As @Organis correctly said "there's no telling how to compose a reverted algorithm."

The only obvious things are listed below, so you'll have to do a lot of testing to get it right (that's how reverse engineering works, and it might take days or weeks). Good luck.

Assessment:

(1)

public static function Read(param1:IDataInput) : int

Look like it expects a (byte) array with two entries. I suspect you should write a Short (in hex formnat) but it'll be easier to just write two separate decimal values (since a Short is a value that spreads over two bytes).

public static function Write(val1 :int, val2 :int, targetBA :ByteArray) : void
{
    targetBA.length = 2;
    targetBA.position = 0;
    targetBA.writeByte( val1 );
    targetBA.writeByte( val2 );
    
    //# target ByteArray can now be "Read" by the other function as "param1"

}

As for the Read side...

Since the function returns a value to update some var, you should use as:

myResult = Read( targetBA ); 

Where myResult gets the function's returned _loc2_ result.

(2)

var _loc4_:* = ( (_loc3_ & 64) != 0 );

This will give either a 0 or 64. Is 0 if lower than 64, or else is 64 if equal or higher. This is likely a quick shortcut to setting a Boolean like:

var _loc4_ :Boolean;
if (_loc3_ >= 64) { _loc4_ = true}
else { _loc4_ = false; }

(3)

_loc2_ = _loc3_ & 63;

Where _loc2_ is set as an integer of either 0 or 63.

(4)

while(_loc3_ & 128)

I don't know what this is trying to achieve. (_loc3_ & 128) is either 0 or 128. This While(0) or While(128) loop will run forever and there isn't any stopping break; at the end.

(5)

_loc2_ = _loc2_ | (_loc3_ & 127) << _loc5_;

This updates _loc2_ with two values. The current loc2 value is combined with a modified loc3 value.

(6)

if(_loc4_)

Likely means if( _loc4_ == true )...