A Flash Developer Resource Site

Page 1 of 3 123 LastLast
Results 1 to 20 of 41

Thread: what the * is a byteArray anyway

  1. #1
    hippie hater Cimmerian's Avatar
    Join Date
    Oct 2006
    Location
    over there
    Posts
    599

    what the * is a byteArray anyway

    ...and what's that for?
    I read somewhere that it can be used to load a game that is into bytecode to my swf, wich makes dificult to decompile, something like that , does anyone has already done that?

  2. #2
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    ByteArray is a container for binary data. All data on your computer is made up of little 1's and 0's. Each of these are bits. 8 bits makes a byte. 10010101 is a byte's worth of data. The ByteArray, class is a class that acts like an array to hold these bytes - bytes for any binary information you have available.

    As for decompiling... it really doesn't apply so much, at least not to your SWF. It sounds like what you're hearing is that you can have saved game data as a binary rather than something like XML. As XML anyone can look at it in a text editor, make some mods and be off with a new game. As binary data, it would open as a bunch of mush unless you had some kind of application that knew how to understand that file. Given that you would be the one deciding the format of that file, that would probably mean no application could understand it - none, of course, except your Flash game.

    Lately I've been using the ByteArray class to read data from Mii characters made on the Wii. Using bluetooth, you can extract Mii data from a Wii remote and download it onto your computer as a .mii file (binary). This format is specific to the Wii but I (and a few others) have managed to reverse engineer it and interpret what bits represent what characteristics on Miis. That allowed me to build this interface http://www.miieditor.com which can load .mii files into a ByteArray and then extract that data to then generate a character preview from it. In turn, by editing the character in the interface, that data is stored back into a ByteArray and pushed to the server as a download so people can have a new edited .mii binary file. For that example, the ByteArray class is also used to do client-side JPEG encoding to produce the image export. This keeps me from having to do it on the server with something like GD lightening server load.

  3. #3
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Here is one simple example how you can use it:

    http://flashscript.biz/flashas3/Save...SaveImage.html

    and of course you can use it with the SoundMixer.computeSpectrum method to create sound analyzers.
    - The right of the People to create Flash movies shall not be infringed. -

  4. #4
    hippie hater Cimmerian's Avatar
    Join Date
    Oct 2006
    Location
    over there
    Posts
    599
    Ok...SO, to do something with a byteArray i have to know how to transform those bytes into jpgs or mii files or swfs...rigth?
    How do i learn to transform it?

  5. #5
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Use the above link.
    - The right of the People to create Flash movies shall not be infringed. -

  6. #6
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    You dont really transform bytes into a type, its already that. What you do is interpret it to get what information that you need from it with possibly adding other information back in. Thats just a matter of knowing what bits represents what information. For that, you need to know about the file format. The Mii file format, for example, can be found here:
    http://wiibrew.org/index.php?title=W...ata#Mii_format
    You can learn about the SWF format (since its an open format) here:
    http://www.adobe.com/licensing/developer/

    Each file type has its own format that you'd need to know to work with the binay data. Depending on what file you want to read/write to, you'll have to look up that format and learn how to interpret it. Of course you can always make your own and decide that for yourself. It all depends on what you want to do.

  7. #7
    hippie hater Cimmerian's Avatar
    Join Date
    Oct 2006
    Location
    over there
    Posts
    599
    I read the tutorial, what i think i get from that is that the bitmapData itself is the one who handles the 'translation' (or whatever it does) of his pixels into a byteArray, cos the methods getPixelS and setPixelS uses byteArray data in and out of it
    These mii and swf are too complicated for me, it means that load a byteArray and turn it into a movieClip is dificult as hell too?If yes, so i think the idea of load a game into a byteArray format and turn it into a game is not doable...well...rule the world is more dificult than i though...

  8. #8
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    All ByteArray is, really, is an array of numbers - each index between 0 and 255 (1 byte of data since 11111111 has a binary value of 255 and is 8 bits or one byte). You may notice this relation to colors as the R, G, B (and A or alpha which typically comes before R) channels of an image are measured with 256 values or 0-255 aka 0x00-0xFF which is what makes it favorable to use by the BitmapData object in its getPixels method. What you're really getting there is an array of A, R, G, B values in an array. Here's a quick example...
    Code:
    // create 1px by 1px square
    var s:Sprite = new Sprite();
    s.graphics.beginFill(0xDD66AA);
    s.graphics.drawRect(0,0,1,1);
    s.graphics.endFill();
    
    // draw square in bitmap data object
    var bd:BitmapData = new BitmapData(1,1,true);
    bd.draw(s);
    
    // get pixel data
    var b:ByteArray = bd.getPixels(new Rectangle(0,0,1,1));
    
    // display data 
    trace(b[0].toString(16)); // ff
    trace(b[1].toString(16)); // dd
    trace(b[2].toString(16)); // 66
    trace(b[3].toString(16)); // aa
    This, however, does not relate to any binary file type. Its just raw number data. Then again, thats what all files are, just 1's and 0's that make up numbers.

    When you're talking about movie clips, you're talking about data in RAM, something that the Flash Player has created and is using in its memory to depict display objects shown on the screen. There is no real accessible data that we as developers can access or set for them. They are all handled internally by the Player itself. That means nothing you do ByteArray-wise would be able to get you your own custom movie clip instance. Also, depending on what kind of "game" you're talking about, that could be completely different as well. It's not like you can take an NES ROM or something and just load it into the Flash player and play it. It is possible to create your own emulator that could read the data and display the pixels on the screen as needed, but that would be a *lot* of scripting and nothing so easy as load() & play().

  9. #9
    hippie hater Cimmerian's Avatar
    Join Date
    Oct 2006
    Location
    over there
    Posts
    599
    Quote Originally Posted by senocular
    That means nothing you do ByteArray-wise would be able to get you your own custom movie clip instance.

    Quote Originally Posted by senocular
    Also, depending on what kind of "game" you're talking about, that could be completely different as well.
    flash games...always flash...until the day adobe gives director the atention it deserves...

  10. #10
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    Well, actually, in that case it might be doable - that is if you want to just screw up a SWF so it can't be played except in your player. I said movie clips can't be accessible through ByteArray, but SWFs can... and SWFs can be loaded into movie clips so... so really it's not much different.

    Basically what you'd need to do is have your game, have an encoder, or a script that screws up that game's byte data, and a decoder, or a script that un-screws up the game's byte data, this obviously being part of your player.

    The concept is this: load the game swf into a movie with the encoder as a ByteArray, mess up its bytes in a specifc manner that you know how to undo, and resave those bytes into a new file. Then, load that new file into your player as a ByteArray, undo the edits you made earlier so you get that data back to its original, working SWF form, and place it in a loader which can load external SWFs or a byte array directly. I'll make an example... this will, well lets just reverse the first 40 bytes of the SWF. This will screw up the header so the Flash player won't know what to make of the SWF and be unable to play it. Then, that can be loaded into a player, be re-reversed and played as though the normal SWF. And, in this case, the encoder and decoder would actually be exactly the same since they're just reversing data.

    The example is attached. I added a method called toHexString which let me take the byte array created by the encoder and convert it to hex so I could resave it from a hex editor app (its a little more difficult to save from Flash, needing a backend server and all. This was an easier solution to that).
    Attached Files Attached Files

  11. #11
    hippie hater Cimmerian's Avatar
    Join Date
    Oct 2006
    Location
    over there
    Posts
    599
    Thanks sen, i will need some time until my slow brain can understand the example,(as usual) then i will coment it
    Another thing, is there any way to make the byteArray goes ONLY to the swf that is in my site?

  12. #12
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    Quote Originally Posted by Cimmerian
    Another thing, is there any way to make the byteArray goes ONLY to the swf that is in my site?
    Not sure what you mean by that. You can use ByteArray with anything you have access to load. The same applies to other people. If they download your SWF, they can use ByteArray with it too if they want... and if they know how. Chances are they're not going to know how to undo what you did to the encoded version of your game though. One thing they won't be able to do is download the game swf as its playing to be an decoded version since that's in RAM and never a valid file. Attempting to download the game will only give them the encoded version of that game.

  13. #13
    hippie hater Cimmerian's Avatar
    Join Date
    Oct 2006
    Location
    over there
    Posts
    599
    Quote Originally Posted by senocular
    Not sure what you mean by that.
    I mean, if someones goes to cache and gets the swf that loads the byteArray, i want to my server to not send the byteArray of the game to sites that stole and decompile games
    All i want to know is if this byteArray thing can be used to stop it
    Chances are they're not going to know how to undo what you did to the encoded version of your game though. One thing they won't be able to do is download the game swf as its playing to be an decoded version since that's in RAM and never a valid file. Attempting to download the game will only give them the encoded version of that game.
    And if they decompile the swf thats decode the game?

  14. #14
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    Quote Originally Posted by Cimmerian
    And if they decompile the swf thats decode the game?
    They can't decompile the SWF because the encoded version technically isn't a SWF anymore. Decompilers will think you are trying to give them a non-SWF file and they won't produce anything.

  15. #15
    hippie hater Cimmerian's Avatar
    Join Date
    Oct 2006
    Location
    over there
    Posts
    599
    I mean, the other swf, the one who encodes and decodes the game.swf
    As for your example, what i THINK i understand is that this Loader class is the one that turn byteArrays into swfs, isnt it?I mean, it loads byteArray and when you addChild it, voila, the game appears

  16. #16
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    That is what the loader class does. It needs valid SWF bytes to do that though, which is what the decode function does. And if they decompiled the player SWF, then yes, then they could look to see how you are decoding then download the encoded game and decode that for themselves. This step basically prevents them from directly having the game to play on their own. Getting that to work would take a lot of effort ( - rather than just downloading it, they'd have to download both, decompile the player, decipher the decoder, run that on the game and resave the game decoded). Its not a full-proof solution, but it does keep back casual stealers. And you can even disguise your game with a .jpg extension making them think its an image.

  17. #17
    hippie hater Cimmerian's Avatar
    Join Date
    Oct 2006
    Location
    over there
    Posts
    599
    Rigth...i supose, that i can also load a string full of 0s and 1s and turn it into a byteArray of a swf and run that swf too...or use it to edit another loaded byteArray
    If this works all that is left is to make a php file that will load that string into flash...
    If this works, its just a matter of find a way for nothing in the world,besides my swf, can have acess to this string from the php file and i will have a unstealable game
    Do you think it can be made?
    Last edited by Cimmerian; 02-16-2007 at 10:08 AM.

  18. #18
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    Using a string vs the binary data is pointless, since its the same information, just using letter characters instead of binary bits. In fact, in doing that, you're also rampig up the file size since each "0" or "1" as a string is a lot larger than a bit since one letter of a string requires multiple bits (since it can have many different values) vs just 1.

    But there's no 100% way to prevent this. Obfuscators probably do the best job, but I dont know if any exist for AS3. Using PHP you can also prevent caching, or push the original SWF through a PHP script (rather than referencing the SWF itself) to make it even harder

  19. #19
    hippie hater Cimmerian's Avatar
    Join Date
    Oct 2006
    Location
    over there
    Posts
    599
    Quote Originally Posted by senocular
    or push the original SWF through a PHP script (rather than referencing the SWF itself) to make it even harder
    I am not sure that i understand what you mean by that...
    I was thinking in strings cos i was thinking that was the only thing php can output, but if php can output byteArrays, thats even better!

  20. #20
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    PHP wouldnt *necessarily* be outputing byte arrays, but binary data. A ByteArray is just the structure that Flash stores binary data - raw data vs ActionScript structure from which to access that raw data.

    And pushing via php and caching are kind of the same deal (at least in what I meant). For example, instead of referencing your SWF directly by its name, say if it were called "example.swf", you'd use a PHP script like this instead:
    PHP Code:
    <?php
    header
    ('Content-type: application/x-shockwave-flash');
    header('Expires: Thu, 01 Jan 1970 00:00:00 GMT, -1');
    header('Cache-Control: no-cache, no-store, must-revalidate');
    header('Pragma: no-cache');
    @
    readfile('example.swf');
    ?>
    This channels the actual SWF through the php file where the PHP file ensures that it won't be cached. And even if it were cached, it would be in the cache as a .php extension.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center