1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
| 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
}
} |
Partager