I/o system
Decorative pattern
In file IO, a layer of read and write is calledDecorative pattern.
Decoration mode is like wearing clothes, layer by layer. There is an underlying abstraction (people), and then there can be a separate implementation (wear pajamas, not others), or there can be an abstract superclass + infinite decorative implementation (wear underwear, long sleeves, sweaters, cotton-padded jackets)
Context is decoration mode
Current part
The correspondence between a byte stream and a character stream
One character =2 bytes. One byte for English, two bytes for Chinese and punctuation, symbols, etc. If it is all written in English, then byte stream is ok, but if there is Chinese in it, then byte stream will read out all gibberish. There’s no point. So the essential difference between byte stream and character stream is the rule of reading and writing
Diagram of the correspondence between byte stream and character stream
Byte stream
Table of correspondence
Read the way you write it. I want the order to be the same, otherwise I’m going to have all the 01’s at the bottom, and the first eight 01’s are int’s but I’m going to read it as Boolean.
OutPut code
InPut code
BufferedInputStream– Use the cache to read data. You can also use FileInputStream without caching, but FileInputStream is a character-by-character read. Will frequent disk I/O, very slow, consume performance!! But BufferedInputStream is read piece by piece, fast
Characters of the flow
Table of correspondence
outWriter
new FileWriter(PATH) == new OutputStreamWriter( new FileOutputStream( new File(PATH)), "GBK")
FileWriter automatically converts files to File–>FileOutputStream –>OutputStreamWriter
Use the default encoding format, but if you need to customize the encoding format, you need to write the full encoding format
inReader
File
Java file classes represent file names and directory pathnames in an abstract way. This class is used to create files and directories, search for files, and delete files. The File object represents the files and directories that actually exist on the disk
RandomAccessFile
RandomAccessFile differs from The File class in that RandomAccessFile defines the length of the File, the position of the pointer (written starting after the 100th character) seek() defines the position of the pointer
Since you can customize the position from which the pointer reads and writes, it can be continued from breakpoint!! (1 thread reads from 0-100, 2 thread reads from 100-200) (File can only be read from the beginning)
NIO – FileChannel
Channel. Using FileChannel when reading large files can significantly improve read and write speed. (dozens of times)
FileInputStream == a pot of oil. BufferedInputStream == Truckloads of oil. FileChannel == Oil pipeline transport.
Real-dex File encryption (APK hardening)
Apk reinforcement
decompiling
Dex file is an executable file of the Android system, which contains all operation instructions and runtime data of the application program.
Decompress apk. 2. Convert the. Dex file into a. Jar file (with tools available) 3. Use the JD-GUI tool to look at the.jar file
Detailed operations blog.csdn.net/qq_34801506…
Strengthening plan
There are three common reinforcement schemes: 1. Anti-simulator, encounter simulator does not execute core code. 2. Code virtualization, code virtualization in the desktop platform application protection has been very common, the main idea is to build a virtual execution engine, and then convert the native executable code into custom instructions for virtual execution. 3. Encryption. Currently, the main reinforcement scheme of APP is to encrypt the code
Ideas of reinforcement
1. Decompress the APK package and extract the. Dex file
2. Convert the. Dex file to byte[] and encrypt the binary
3. Extract the. Jar from the newly created. Aar and convert it to the. Dex file to create a. Dex shell
4. Package encrypted. Dex, empty. Dex, and other apK files into a new APK
5. Sign the new APK
Dex Indicates the file structure
APK packaging process interview questions
1. Resource files are parsed by AAPT into R.java +.aidl files and parsed by AIDL into Java files + original Java files
2.. Java is parsed by the compiler into.class files
3.. Class +lib is parsed into a. Dex file
4.. Dex files + others (RES, etc.) are packaged as unsigned APK
5. Apk signature
Apk reinforcement source code
1. Decompress the APK package and extract the. Dex file
The first step main.java
Unzip the code, zip.java
Convert the.dex file to byte[], and then encrypt the binary
Specific code
2. Process aar file and obtain shell DEX
Specific code
3. Pack your signature
Signing by CMD