Advertisement
Guest User

Untitled

a guest
May 28th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package  {
  2.    
  3.     import flash.utils.ByteArray;
  4.     import flash.display.Bitmap;
  5.     import flash.display.BitmapData;
  6.     import flash.geom.Point;
  7.    
  8.     import com.hurlant.math.BigInteger;
  9.    
  10.     public class BitmapFunctions {
  11.        
  12.         private var Banner:habboBanner;
  13.         private var pixels:ByteArray;
  14.        
  15.         private var decodeResult:String = "";
  16.         private var xorResult:String = "";
  17.        
  18.         private var firstLength:int = 0;
  19.         private var secondLength:int = 0;
  20.        
  21.         private var firstKey:String = "";
  22.         private var secondKey:String = "";
  23.        
  24.         public function BitmapFunctions() {
  25.            
  26.             trace("Constructed bitmap decoding class");
  27.            
  28.             this.Banner = new habboBanner(0,0);
  29.             this.pixels = this.Banner.getPixels(this.Banner.rect);
  30.            
  31.             this.decodeResult = this.decodeBitmap(this.pixels, this.Banner.width, 4, new Point(4, 39), new Point(80, 30));
  32.             this.xorResult = this.xorTest(this.decodeResult, "secret");
  33.             //6d14d6c1682bf00e7c61c584e5c4f5b3 << Token
  34.             this.firstLength = this.xorResult.charCodeAt(0);
  35.             this.secondLength = this.xorResult.charCodeAt((this.firstLength + 1));
  36.            
  37.             this.firstKey = this.xorResult.substr(1, this.firstLength);
  38.             this.secondKey = this.xorResult.substr(this.firstLength + 2, this.secondLength);
  39.            
  40.             trace("First Length -> " + this.firstLength);
  41.             trace("First Key -> " + this.firstKey);
  42.             trace("");
  43.             trace("Second Length -> " + this.secondLength);
  44.             trace("Second Key -> " + this.secondKey);
  45.            
  46.             var first:BigInteger = new BigInteger();
  47.             var second:BigInteger = new BigInteger();
  48.            
  49.             first.fromRadix(this.firstKey, 10);
  50.             second.fromRadix(this.secondKey, 10);
  51.            
  52.             trace("Prime -> " + first.toString());
  53.             trace();
  54.             trace("Generator -> " + second.toString());
  55.         }
  56.        
  57.         private function xor(pixelStr:String, token:String) : String {
  58.            
  59.             var pixelCode:uint = 0;
  60.             var resultStr:String = "";
  61.             var tokenIterate:int = 0;
  62.             var pixelIterate:int = 0;
  63.            
  64.             while (pixelIterate < pixelStr.length) {
  65.                
  66.                 pixelCode = pixelStr.charCodeAt(pixelIterate);
  67.                 resultStr = resultStr + String.fromCharCode(pixelCode ^ token.charCodeAt(tokenIterate));
  68.                 tokenIterate++;
  69.                
  70.                 if (tokenIterate == token.length) {
  71.                    
  72.                     tokenIterate = 0;
  73.                 }
  74.                
  75.                 pixelIterate++;
  76.             }
  77.            
  78.             return resultStr;
  79.         }
  80.        
  81.         private function xorTest(pixelStr:String, token:String) : String {
  82.            
  83.             var pixelCode:uint = 0;
  84.             var resultStr:String = "";
  85.             var tokenIterate:int = 0;
  86.            
  87.             for (var pixelIterate:int = 0; pixelIterate < pixelStr.length; pixelIterate++) {
  88.                
  89.                 pixelCode = pixelStr.charCodeAt(pixelIterate);
  90.                 resultStr = resultStr + String.fromCharCode(pixelCode ^ token.charCodeAt(tokenIterate));
  91.                 tokenIterate++;
  92.                
  93.                 if (tokenIterate == token.length) {
  94.                    
  95.                     tokenIterate = 0;
  96.                 }
  97.                
  98.             }
  99.            
  100.             return resultStr;
  101.         }
  102.        
  103.         private function decodeBitmap(bitmap:ByteArray, bitmapWidth:int, aCount:int, pos1:Point, pos2:Point) : String {
  104.            
  105.             var pos1X:int = 0; // loc12
  106.             var pos1Y:int = 0; // loc11
  107.            
  108.             var pixelPos:uint = 0; //loc13
  109.            
  110.             var rowStart:int = 0; //loc10
  111.             var rowRemainder:uint = 0; //loc9
  112.             var tRow:uint = 0;  // loc14
  113.            
  114.             var uByte:uint = 0; // loc15
  115.             var uByteMasked:uint = 0; // loc16
  116.             var bitCount:uint = 0; // loc7
  117.             var shiftBuffer:uint = 0; // loc8
  118.            
  119.             var resultBuffer:String = "";
  120.            
  121.             if (aCount == 4) {
  122.                
  123.                 // Starting row will be 1
  124.                 rowStart = 1;
  125.             }
  126.            
  127.             pos1Y = pos1.y;
  128.            
  129.             while (pos1Y < pos1.y + pos2.y) {
  130.                
  131.                 pos1X = pos1.x;
  132.                
  133.                 while (pos1X < pos1.x + pos2.x) {
  134.                    
  135.                     pixelPos = ((pos1Y + rowRemainder) * bitmapWidth + pos1X) * aCount;
  136.                     tRow = rowStart;
  137.                    
  138.                     while (tRow < aCount) {
  139.                        
  140.                         bitmap.position = pixelPos + tRow;
  141.                        
  142.                         uByte = bitmap.readUnsignedByte();
  143.                         uByteMasked = uByte & 1;
  144.                         shiftBuffer = shiftBuffer | uByteMasked << 7 - bitCount;
  145.                        
  146.                         if (bitCount == 7) {
  147.                            
  148.                             resultBuffer = resultBuffer + String.fromCharCode(shiftBuffer);
  149.                             shiftBuffer = 0;
  150.                             bitCount = 0;
  151.                         }
  152.                         else {
  153.                            
  154.                             bitCount = bitCount + 1;
  155.                         }
  156.                        
  157.                         tRow++;
  158.                     }
  159.                    
  160.                     if (pos1X % 2 == 0) {
  161.                        
  162.                         rowRemainder = rowRemainder + 1;
  163.                     }
  164.                    
  165.                     pos1X++;
  166.                 }
  167.                
  168.                 rowRemainder = 0;
  169.                 pos1Y++;
  170.             }
  171.            
  172.             return resultBuffer;
  173.         }
  174.     }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement