将二进制数据嵌入到Flash应用程序中 [英] Embedding binary data into Flash applications

查看:983
本文介绍了将二进制数据嵌入到Flash应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在反编译混淆的Adobe Flash应用程序时,我注意到它们中的很多包含了一个加密的二进制组件:



我的问题是,如何在应用程序中包含二进制组件(如上所述),以及如何使用ActionScript加载它以便进一步处理它?注意:我的IDE是Flash Builder,我正在使用Adobe AIR应用程序。

解决方案




我注意到,许多关于@ Denis-Kokorin的回答它们包含一个加密的二进制组件:

请注意,DefineBinaryData是SWF格式的标准片段不是一个反编译技巧。为了让它存在,你只需通过你的AS3代码 [embed] 一个文件。这就变成了Tag中定义的二进制数据。

lockquote
我的问题是,如何包含一个二进制组件(如
)以及如何使用ActionScript
加载它以便进一步处理它?<​​/ p>

加载取决于你在什么文件格式嵌入。对图像使用位图(jpg,png等)& movieClip 用于SWF,使用 Sound 来解码MP3数据为可播放(PCM)声音。 Netstream的 AppendBytes 将解码视频字节。如果你想要任何加密的东西,那么在嵌入之前就这么做。您必须决定使用哪种加密方法或自行创建,当然,您的AS3应用程序在尝试处理之前必须具有解密代码。



在下面的代码中,我展示了一个加载不同格式内容的例子。从那里你可以像往常一样处理它(例如: bitmapdata 编辑像素或 sound.extract 等等)。我还展示了如何获取字节到 ByteArray incase如果它是你想要编辑的字节值。阅读手册以处理 ByteArray 一> 即可。此 指南 也可以帮助您。

 
{

import flash.display.MovieClip;
import flash.utils。*;
import flash.display。*;
导入flash.events。*;
import flash.media。*;

public class embed_test extends MovieClip
{

[Embed(source =image.jpg)] private var emb_Image:Class;
[Embed(source =track.mp3)] private var emb_MP3:Class;
[Embed(source =vctest.swf)] private var emb_SWF:Class;

//用于访问字节(二进制数据)
[嵌入(source =image.jpg,mimeType =application / octet-stream)] private var emb_Bytes:Class ;

public function embed_test()
{
var my_Pic:Bitmap = new emb_Image();
addChild(my_Pic); //#在舞台上显示图像

var my_Snd:Sound = new emb_MP3();
my_Snd.play(); //#播放声音

var my_Swf:MovieClip = new emb_SWF();
addChild(my_Swf); //在舞台上显示SWF

var my_BA:ByteArray = new emb_Bytes as ByteArray;
trace(bytes length:+ my_BA.length); //#检查字节总数是否正确
trace(bytes(HEX):+ bytes_toHex(my_BA)); //#以十六进制格式检查字节


$ b私有函数bytes_toHex(输入:ByteArray):字符串
{
var strOut:String = ; var strRead:String =;
var input_Size:uint = input.length;
input.position = 0; (var i:int = 0; i< input_Size; i ++)



strRead = input.readUnsignedByte()。toString(16); $(strRead.length< 2){strRead =0+ strRead; } //#填充
strOut + = strRead;
}

return strOut.toUpperCase();
}

}

}


While decompiling obfuscated Adobe flash applications, I noticed that many of them contain an encrypted binary component:

My question is, how do you include a binary component (as described above) in your application and how do you load it using ActionScript in order to further process it?

Note: My IDE is Flash Builder and I am working with a Adobe AIR application.

解决方案

Just to expand on @Denis-Kokorin's answer and clear your concerns...

I noticed that many of them contain an encrypted binary component:

Just be aware that "DefineBinaryData" is a standard segment (called Tags) of the SWF format, not a decompiler trick. To have it exist, you simply [embed] a file via your AS3 code. That becomes the binary data as defined within the Tag.

My question is, how do you include a binary component (as described above) in your application and how do you load it using ActionScript in order to further process it?

Loading depends on what file format you embed. Use Bitmap for images (jpg, png etc) & movieClip for SWF, use Sound for decoding MP3 data to playable (PCM) sound. Netstream's AppendBytes will decode video bytes. If you want anything "encrypted" then do so before you embed it. You'll have to decide which encryption method to use or invent your own, of course your AS3 app must have the "decryption" code before you try to process it.

In the code below I've shown an example of loading content of different formats. From there you can process it as usual (eg: bitmapdata for editing pixels or sound.extract for editing audio samples, etc). I've also shown how to get bytes into a ByteArray incase if it's the byte values you want to edit. Read the manual for handling ByteArray. This guide might also help you.

package  
{

import flash.display.MovieClip;
import flash.utils.*;
import flash.display.*;
import flash.events.*;
import flash.media.*;

public class embed_test extends MovieClip 
{

[Embed(source="image.jpg")] private var emb_Image : Class;
[Embed(source="track.mp3")] private var emb_MP3 : Class;
[Embed(source="vctest.swf")] private var emb_SWF : Class;

//# for access to bytes (binary data)
[Embed(source="image.jpg", mimeType="application/octet-stream")] private var emb_Bytes : Class;

    public function embed_test() 
    {
        var my_Pic : Bitmap = new emb_Image();
        addChild(my_Pic); //# display image on stage

        var my_Snd : Sound = new emb_MP3();
        my_Snd.play(); //# play sound

        var my_Swf : MovieClip = new emb_SWF();
        addChild(my_Swf); //# display SWF on stage

        var my_BA : ByteArray = new emb_Bytes as ByteArray;
        trace("bytes length : " + my_BA.length); //# check bytes total is correct
        trace("bytes (HEX) : " + bytes_toHex(my_BA) ); //# check bytes in hex format

    }

    private function bytes_toHex (input : ByteArray) : String
    {
        var strOut : String = ""; var strRead:String = "";
        var input_Size : uint = input.length; 
        input.position = 0;

        for (var i:int = 0; i < input_Size; i++)
        {
            strRead = input.readUnsignedByte().toString(16); 

            if(strRead.length < 2) { strRead = "0" + strRead; } //# do padding
            strOut += strRead ;     
        }

        return strOut.toUpperCase();
    }

}

}

这篇关于将二进制数据嵌入到Flash应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆