Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net
- {
- import flash.utils.*;
- public class Binary extends ByteArray
- {
- public var bitLength:Number;
- public var bitPosition:Number;
- public static var powList:Array;
- public static var __init:Boolean = _init();
- public function Binary()
- {
- this.bitLength = 0;
- this.bitPosition = 0;
- return;
- }// end function
- public function getDebug() : String
- {
- var _loc_1:* = new Array();
- _loc_1.push(this.bitPosition);
- _loc_1.push(this.bitLength);
- var _loc_2:uint = 0;
- while (_loc_2 < length)
- {
- _loc_1.push(this[_loc_2].toString());
- _loc_2 = _loc_2 + 1;
- }
- return _loc_1.join("=");
- }// end function
- public function setDebug(param1:String)
- {
- var _loc_2:* = param1.split("=");
- this.bitPosition = _loc_2[0];
- this.bitLength = _loc_2[1];
- var _loc_3:uint = 2;
- while (_loc_3 < _loc_2.length)
- {
- this.writeByte(Number(_loc_2[_loc_3]));
- _loc_3 = _loc_3 + 1;
- }
- return;
- }// end function
- public function bitReadString() : String
- {
- var _loc_4:uint = 0;
- var _loc_1:String = "";
- var _loc_2:* = this.bitReadUnsignedInt(16);
- var _loc_3:* = 0;
- while (_loc_3 < _loc_2)
- {
- _loc_4 = this.bitReadUnsignedInt(8);
- if (_loc_4 == 255)
- {
- _loc_4 = 8364;
- }
- _loc_1 = _loc_1 + String.fromCharCode(_loc_4);
- _loc_3 = _loc_3 + 1;
- }
- return _loc_1;
- }// end function
- public function bitReadBoolean() : Boolean
- {
- if (this.bitPosition == this.bitLength)
- {
- return false;
- }
- var _loc_1:* = Math.floor(this.bitPosition / 8);
- var _loc_2:* = this.bitPosition % 8;
- var _loc_3:String = this;
- var _loc_4:* = this.bitPosition + 1;
- _loc_3.bitPosition = _loc_4;
- return (this[_loc_1] >> 7 - _loc_2 & 1) == 1;
- }// end function
- public function bitReadUnsignedInt(param1:Number) : Number
- {
- var _loc_4:Number = NaN;
- var _loc_5:Number = NaN;
- var _loc_6:* = undefined;
- var _loc_7:* = undefined;
- var _loc_8:Number = NaN;
- if (this.bitPosition + param1 > this.bitLength)
- {
- this.bitPosition = this.bitLength;
- return 0;
- }
- var _loc_2:* = 0;
- var _loc_3:* = param1;
- while (_loc_3 > 0)
- {
- _loc_4 = Math.floor(this.bitPosition / 8);
- _loc_5 = this.bitPosition % 8;
- _loc_6 = 8 - _loc_5;
- _loc_7 = Math.min(_loc_6, _loc_3);
- _loc_8 = this[_loc_4] >> _loc_6 - _loc_7 & (powList[_loc_7] - 1);
- _loc_2 = _loc_2 + _loc_8 * powList[_loc_3 - _loc_7];
- _loc_3 = _loc_3 - _loc_7;
- this.bitPosition = this.bitPosition + _loc_7;
- }
- return _loc_2;
- }// end function
- public function bitReadSignedInt(param1:Number) : Number
- {
- var _loc_2:* = this.bitReadBoolean();
- return this.bitReadUnsignedInt((param1 - 1)) * (_loc_2 ? (1) : (-1));
- }// end function
- public function bitReadBinaryData() : Binary
- {
- var _loc_1:* = this.bitReadUnsignedInt(16);
- return this.bitReadBinary(_loc_1);
- }// end function
- public function bitReadBinary(param1:uint) : Binary
- {
- var _loc_4:uint = 0;
- var _loc_5:uint = 0;
- var _loc_2:* = new Binary();
- var _loc_3:* = this.bitPosition;
- while (this.bitPosition - _loc_3 < param1)
- {
- if (this.bitPosition == this.bitLength)
- {
- return _loc_2;
- }
- _loc_5 = Math.min(8, param1 - this.bitPosition + _loc_3);
- _loc_2.bitWriteUnsignedInt(_loc_5, this.bitReadUnsignedInt(_loc_5));
- }
- return _loc_2;
- }// end function
- public function bitWriteString(param1:String) : void
- {
- var _loc_4:uint = 0;
- var _loc_2:* = Math.min(param1.length, (powList[16] - 1));
- this.bitWriteUnsignedInt(16, _loc_2);
- var _loc_3:* = 0;
- while (_loc_3 < _loc_2)
- {
- _loc_4 = param1.charCodeAt(_loc_3);
- if (_loc_4 == 8364)
- {
- _loc_4 = 255;
- }
- this.bitWriteUnsignedInt(8, _loc_4);
- _loc_3 = _loc_3 + 1;
- }
- return;
- }// end function
- public function bitWriteSignedInt(param1:Number, param2:Number) : void
- {
- this.bitWriteBoolean(param2 >= 0);
- this.bitWriteUnsignedInt((param1 - 1), Math.abs(param2));
- return;
- }// end function
- public function bitWriteUnsignedInt(param1:Number, param2:Number) : void
- {
- var _loc_4:Number = NaN;
- var _loc_5:* = undefined;
- var _loc_6:* = undefined;
- var _loc_7:Number = NaN;
- param2 = Math.min((powList[param1] - 1), param2);
- var _loc_3:* = param1;
- while (_loc_3 > 0)
- {
- _loc_4 = this.bitLength % 8;
- if (_loc_4 == 0)
- {
- writeBoolean(false);
- }
- _loc_5 = 8 - _loc_4;
- _loc_6 = Math.min(_loc_5, _loc_3);
- _loc_7 = this.Rshift(param2, Number(_loc_3 - _loc_6));
- this[(this.length - 1)] = this[(this.length - 1)] + _loc_7 * powList[_loc_5 - _loc_6];
- param2 = param2 - _loc_7 * powList[_loc_3 - _loc_6];
- _loc_3 = _loc_3 - _loc_6;
- this.bitLength = this.bitLength + _loc_6;
- }
- return;
- }// end function
- public function bitWriteUnsignedIntOLD(param1:Number, param2:Number) : void
- {
- param2 = Math.min((powList[param1] - 1), Math.abs(param2));
- var _loc_3:* = param2.toString(2);
- while (_loc_3.length < param1)
- {
- _loc_3 = "0" + _loc_3;
- }
- var _loc_4:* = 0;
- while (_loc_4 < param1)
- {
- this.bitWriteBoolean(_loc_3.charAt(_loc_4) == "1");
- _loc_4 = _loc_4 + 1;
- }
- return;
- }// end function
- public function bitWriteBoolean(param1:Boolean) : void
- {
- var _loc_2:* = this.bitLength % 8;
- if (_loc_2 == 0)
- {
- writeBoolean(false);
- }
- if (param1)
- {
- this[(this.length - 1)] = this[(this.length - 1)] + powList[7 - _loc_2];
- }
- var _loc_3:String = this;
- var _loc_4:* = this.bitLength + 1;
- _loc_3.bitLength = _loc_4;
- return;
- }// end function
- public function bitWriteBinaryData(param1:Binary) : void
- {
- var _loc_2:* = Math.min(param1.bitLength, (powList[16] - 1));
- this.bitWriteUnsignedInt(16, _loc_2);
- this.bitWriteBinary(param1);
- return;
- }// end function
- public function bitWriteBinary(param1:Binary) : void
- {
- var _loc_3:uint = 0;
- var _loc_4:uint = 0;
- param1.bitPosition = 0;
- var _loc_2:* = param1.bitLength;
- while (_loc_2)
- {
- _loc_3 = Math.min(8, _loc_2);
- _loc_4 = param1.bitReadUnsignedInt(_loc_3);
- this.bitWriteUnsignedInt(_loc_3, _loc_4);
- _loc_2 = _loc_2 - _loc_3;
- }
- return;
- }// end function
- public function bitCopyObject(param1:Object)
- {
- this.bitPosition = param1.bitPosition;
- this.bitLength = param1.bitLength;
- param1.position = 0;
- var _loc_2:uint = 0;
- while (_loc_2 < param1.length)
- {
- writeByte(param1.readByte());
- _loc_2 = _loc_2 + 1;
- }
- return;
- }// end function
- public function Rshift(param1:Number, param2:int) : Number
- {
- return Math.floor(param1 / powList[param2]);
- }// end function
- public function Lshift(param1:Number, param2:int) : Number
- {
- return param1 * powList[param2];
- }// end function
- public static function _init() : Boolean
- {
- powList = new Array();
- var _loc_1:uint = 0;
- while (_loc_1 <= 32)
- {
- powList.push(Math.pow(2, _loc_1));
- _loc_1 = _loc_1 + 1;
- }
- return true;
- }// end function
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement