[Switch] SWF file encryption Basics

Source: Internet
Author: User

I was planning to write this article when I came back from work. On the one hand, it is a note record for today's learning, and on the other hand, it is a basic knowledge of SWF file encryption for some friends. The reason is that it is the foundation that I just learned. However, after watching the video for a while in the evening, I am a legend of the video, saying that Guo Degang is always playing Xie Nan. Is there a base? Don't explain ......
Before explaining the encryption and decryption methods, I would like to explain some theoretical aspects.
SWF Encryption. In fact, whether it is Flash SWF file encryption or other types of encryption, the purpose is very simple, is private, do not want to disclose the details of the specific file. Of course, this is also the trend of the big environment. Many of them come to China and understand it. SWF file encryption has two main purposes:
1. flash code encryption, such as commercial game code, is always difficult to use for theft.
2. Flash material encryption to prevent theft by some tools. Friends who use flash for animation should have a deep understanding.
File Format. What is the file format? Baidu Baike introduces this: the file format (or file type) refers to the special encoding method used by the computer to store information, is used to identify data stored internally. Simply put, all files are binary data, and files in a specific format (such as video files and video files) are classified according to a specific rule. Only suffix such as "{.swf" will be added later for identification.
In this way, the theoretical method of encryption is born for the above SWF encryption purpose.
SWF Encryption Method.
If yesEncryption CodeThen, some tools are used for code obfuscation to reduce readability. Even if the code is cracked and cannot be understood, the code is cracked in white. Some tools on the Internet are suitable, such as doswf.
If yesEncrypted materialThe file must be damaged so that the cracking tool cannot parse the data, so that the file can be protected. Destroying a file destroys binary data and the file format mentioned above. Of course, it cannot be damaged at will, because once the file is damaged, not only can someone else crack your file, but your own file cannot run normally, and the horse is put upside down. Therefore, regular damages are required.Encryption Algorithm.
Now, my files are damaged by encryption, but they cannot be used. To achieve normal use, we need another program, that isDecryption algorithm. The decryption algorithm is exactly the opposite of the encryption algorithm. It destroys a file and fixes a file to achieve normal use.

(Note: I wrote the previous paragraphs on Saturday. I accidentally smashed my feet by a stone. Although there was no blur, it was still quite painful. I would like to remind you that, I had a rock in my arms. It was time to let it go early and put it late, so I fell asleep ...... Continue to write)

So, the encryption method that I can think of now is that the sub-file must be obfuscated with the code and encrypted file at the same time, while the main file must contain the decryption code and the code at the same time, prevent Cracking.

Let's use a small example to demonstrate it. In this case, I will first use flash to make a small animation. There is a picture in it, and the generated file is named unfinished-1.swf ". Here, this small animation is a sub-file, and now I want to encrypt it.
Create a new classEncrypttool.The role of this animation isEncryption. It should be noted that, to encrypt a file, local file read/write operations will be involved. General flash player is not supported and requires an air project to run.
Extract some code to explain the encryption process.

  1. _ Urlloader = new urlloader ();
  2. _ Urlloader. dataformat = urlloaderdataformat. Binary;
Copy code

(I don't know what's going on. The Code will always be removed automatically when it is put on, so I will write it out.) _ urlloader. addeventlistener (event. Complete, loaded );
_ Urlloader. Load (New URLRequest ("Unnamed -1.swf "));


The above code indicates loading and reading the animation in binary data mode. After the animation is loaded, the following method is triggered.

  1. Private function loaded (E: Event): void
  2. {
  3. _ Urlloader. removeeventlistener (event. Complete, loaded );
  4. VaR data: bytearray = _ urlloader. Data as bytearray; // use a binary array to keep the read data.
  5. Var key: String = "this is a test"; // set the password key to this string.
  6. VaR keybytes: bytearray = new bytearray ();
  7. Keybytes. writeobject (key); // converts the string to a binary array
  8. // The following is the encryption algorithm.
  9. VaR P: Int = data. Length/2; // obtain the location index in the center of the original data
  10. VaR B1: bytearray = new bytearray ();
  11. For (var I: Int = 0; I <keybytes. length; I ++ ){
  12. B1.writebyte (data [I + P] ^ keybytes [I])
  13. }
  14. // The above cycle mainly refers to the calculation of the password data and the original data, that is, the data of the same number of bytes as the password data is obtained from the intermediate position of the original data, they perform an exclusive or operation and store the operation results in a binary array.
  15. // I don't know what an exclusive or operation is. Baidu, I just checked it ......
  16. Data. Position = P; // adjust the original data position to the intermediate position.
  17. Data. writebytes (B1); // replace all the data after calculation in the middle
  18. // The encryption process is in the middle, which is a little troublesome. It is also simpler, such as tuning the first byte.
  19. // The data above is encrypted. Now you need to save the encrypted data as a file. For convenience, it is still saved as a SWF file.
  20. Var file: file = new file ("C:/Documents and Settings/user/desktop/encryption/Decryption/decrypttool/src/mc.swf ");
  21. VaR FS: filestream = new filestream ();
  22. FS. Open (file, filemode. Write );
  23. FS. writebytes (data );
  24. FS. Close ();
Copy code


After all, you have saved an encrypted file and copied mc.swf in the folder. Although it looks like a normal SWF animation file, if you open it directly, you will find that there is nothing left blank. At this time, try again to use the flash client Genie and other cracking software to crack this animation, and the prompt "file damaged" will pop up. Yes, the file is damaged, encrypted, and cannot be cracked.

The file is encrypted, but it cannot run normally. At this time, you need to find the place to use it.Decryption. Create a classDecrypttool., This does not require the air project. It is normal. Now, if this animation is required, decryption starts.
Similarly, you must first load the encrypted file as binary data.

  1. _ Urlloader = new urlloader ();
  2. _ Urlloader. dataformat = urlloaderdataformat. Binary;
  3. _ Urlloader. addeventlistener (event. Complete, bytesloaded );
  4. _ Urlloader. Load (New URLRequest ("mc.swf "));
Copy code

After loading, trigger the following method.

  1. Private function bytesloaded (E: Event): void
  2. {
  3. _ Urlloader. removeeventlistener (event. Complete, bytesloaded );
  4. VaR data: bytearray = _ urlloader. Data as bytearray; // Similarly, save the read data, which is encrypted

  5. // The following decryption operation is the same as the encryption operation because of the exclusive or operation. The reverse operation is no different from the previous one.
  6. Var key: String = "this is a test ";
  7. VaR keybytes: bytearray = new bytearray ();
  8. Keybytes. writeobject (key );
  9. VaR P: Int = data. Length/2;
  10. VaR B1: bytearray = new bytearray ();
  11. For (var I: Int = 0; I <keybytes. length; I ++ ){
  12. B1.writebyte (data [I + P] ^ keybytes)
  13. }
  14. Data. Position = P;
  15. Data. writebytes (B1 );
  16. // The data obtained above is the decrypted data. This is the complete data, which is exactly the same as the previously read "untitled -1.swf" data, because this step is used to restore the data. At this time, if you save this data as a SWF file, you will find that this file can be used normally, and the bitmap is displayed normally, which is no different from the previous source file.
  17. // After the complete data is obtained, use loader to read the binary data. Note the following bold lines of code. This is very important. Otherwise, an error is reported, indicating that SWF is not supported.
Copy code

(I don't know what's going on. The Code will always be automatically removed from the back. I will write it out directly)

  1. _ Loader = new loader ();
  2. _ Loader. contentloaderinfo. addeventlistener (event. Complete, loaded );
  3. VaR LC: loadercontext = new loadercontext ();
  4. LC. allowcodeimport = true;
  5. _ Loader. loadbytes (data, LC );
Copy code

(The code turned into a Q expression just now. It's too speechless. Let's take a look)
After reading the data above, proceed to the following method.

  1. Private function loaded (E: Event): void
  2. {
  3. _ Loader. contentloaderinfo. removeeventlistener (event. Complete, loaded );
  4. VaR MC: movieclip = _ loader. content as movieclip;
  5. Addchild (MC );
  6. }
Copy code


The above program gets a video clip from the binary array through loader. At this time, the animation in the program can be played normally, indicating that the decryption is successful.

This is the basic idea of encryption and decryption. Of course, do not forget to confuse the decryption code. Otherwise, it will be useless. If you don't understand the code, you only need a hacker to crack the sub-file.
Code obfuscation. We haven't conducted any experiments yet. If you don't do any demonstration, download the tool.

Encryption is not omnipotent, and it will certainly be able to be implemented. However, with this foundation, it is still possible to defend against cainiao and individual cracking tools. The path to encryption is endless.

By the way, the Sina Blog does not have the function of inserting code. As a result, it takes a lot of time to manually print the code.
Code formatting is really uncomfortable. This is also a problem.

 

Reproduced from: http://bbs.9ria.com/forum.php? MoD = viewthread & tid = 172529 & page = 1 & extra = # pid1654416

[Switch] SWF file encryption Basics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.