The APK file uses the Unzip tool to see resources such as drawable, but some of the graphics resources in the game are not visible.
This question has been explored for a long time ...
"1" Picture resources are not placed under the drawable file, placed in the assets (but unzip the APK, the same can see the picture resources), the following is said to use the method.
Analysis: Ⅰ) When the picture resource is placed in the drawable, can have the corresponding ID to parse: Bitmapfactory.decoderesource (res, id)
If placed under assets, it needs to be parsed according to the name of the file (Android provides Assetmanager).
Ⅱ) can build a multi-level directory, easy to manage.
Ⅲ) Such parsing process, the time is more than according to the ID resolution (mobile phones more and more intelligent, this time is basically not seen).
Code:
/*** Read images from assets *@paramFilename:assets "A.png" in the root directory, "Abc/a.png" with sub-folders *@return */ Public StaticBitmap getimagefromassets (context context, String FileName) {Bitmap image=NULL; Assetmanager am=context.getresources (). Getassets (); Try{InputStream is=Am.open (fileName); Image=Bitmapfactory.decodestream (IS); Is.close (); } Catch(IOException e) {e.printstacktrace (); } returnimage; }
The "2" Picture resource is packaged under the jar and then imported into the project ( but unzip the APK, also see the picture resources )
Analysis: Use a third-party jar package, after the APK decompression is not visible, try to see. Finally, the assets file in the jar package is visible in the APK.
STEP1: Packaging jar
Engineering-Right-click->export->java/jar file-> Select the SRC and assets to be packaged (e.g.)
Step2: Interpretation of the picture in assets, with "1"
STEP3: Pack the APK and discover that the assets in the jar package is merged with the assets of the current project!
"3" Image resource is encrypted and then read under the assets file ( resource protection is possible, but looks more time consuming )
Analysis: In some way the picture is pre-encrypted, then decrypted in the Android program, converted into bitmap.
Perhaps the other application is to do so, the great God has a coup, to introduce it! (Here's an easy way to do this)
STEP1: Encryption, the use of file streaming, read resources, and then modify, and finally generate files (any format can be, you can't know is the picture)
Ⅰ) Adds a specified number of bytes per interval
Ⅱ) bytes per interval, swap bytes (code example)
Public classKMD1 { Public Static voidEncrypt (String filePath) {byte[] Tempbytes =New byte[5000]; Try{InputStream in=NewFileInputStream (FilePath); OutputStream out=NewFileOutputStream (filepath.subsequence (0, Filepath.lastindexof (".")) + "2.jpg") while(In.read (tempbytes)! =-1) {//a simple Exchange byteA = Tempbytes[0]; tempbytes[0] = tempbytes[1]; tempbytes[1] =A; Out.write (tempbytes);//Write a file } } Catch(IOException e) {e.printstacktrace (); } } Public Static voidMain (string[] args) {Kmd1.encrypt ("D:/a.jpg"); }}
STEP2: Decryption, reverse the encryption process.
/*** Read images from assets *@paramfilename*@return*/ Public StaticBitmap getimagefromassets (context context, String FileName) {Bitmap image=NULL; Assetmanager am=context.getresources (). Getassets (); Try{InputStream is=Am.open (fileName); byte[] buffer =New byte[1000000];//big Enoughis.read (buffer); for(inti=0; i<buffer.length; i+= 5000) {//Same as Encryption bytetemp =Buffer[i]; Buffer[i]= Buffer[i+1]; Buffer[i+1] =temp; } Image= Bitmapfactory.decodebytearray (buffer, 0, buffer.length); Is.close (); } Catch(IOException e) {e.printstacktrace (); } returnimage;}
"3" encrypts each pixel using SetPixel () and GetPixel () and then restores it when used
Analysis: The color value is obtained by Bitmap.getpixel (x, y), the RGB value of color is encrypted, and then SetPixel (X,y,color)
STEP1: Too lazy to write, direct sticker code:
Note: Bitmap must copy one copy, and then the second value is true in order to setpixel it, otherwise it will error, encrypt and decrypt in the code is your encryption and decryption process;
Serious problem: to bitmap setpixel then in Getpixel,color value is not set value, there is deviation, do not know why. If you can solve this problem, please leave a message.
Bitmap Temp_bitmap = image.copy (Bitmap.Config.ARGB_8888,true); intwidth =temp_bitmap.getwidth (); intHeight =temp_bitmap.getheight (); int[] pixels =New int[Width *height]; //temp_bitmap.getpixels (pixels, 0, width, 0, 0, width, height); for(inti = 0; i < height; i++) { for(intj = 0; J < width; J + +) { intcolor =Temp_bitmap.getpixel (i, j); intR =color.red (Color); intg =Color.green (Color); intb =Color.Blue (Color); intAlpha =Color.alpha (Color); //if (alpha! = 0){R= Encrptyrgb (R, i*j)); G= Encrptyrgb (g, i*j)); b= Encrptyrgb (b, 6* (i*j)); Color=Color.argb (Alpha, R, G, b); Pixels[width* i + j] =color; //Temp_bitmap.setpixel (i, J, color); }}} temp_bitmap.setpixels (pixel S,0, Width, 0, 0, width, height); for(inti = 0; i < height; i++) { for(intj = 0; J < width; J + +) { intcolor =Temp_bitmap.getpixel (i, j); intR =color.red (Color); intg =Color.green (Color); intb =Color.Blue (Color); intAlpha =Color.alpha (Color); //if (alpha! = 0){R= Decryptrgb (R, i*j)); G= Decryptrgb (g, i*j)); b= Decryptrgb (b, 6* (i*j)); Color=Color.argb (Alpha, R, G, b); Pixels[width* i + j] =color; //Temp_bitmap.setpixel (i, J, color); }}} temp_bitmap.setpixels (pixel S,0, Width, 0, 0, width, height); returnTemp_bitmap;
"?" continue to explore, forget the great God advice! Appreciate!
Android Resource Protection problem--Explore