In the reverse analysis of Android APK, it is often necessary to analyze its. so file. This. So file is a dynamic link library of Linux, but it is compiled under ARM-CPU. So it's important to learn the arm instructions under Android. At present, the ARM-CPU in the market basically support a kind of instruction set mode called Thumb. This thumb instruction set can be seen as a subset of the arm instruction set, except that the arm instruction set is a 32bit,thumb instruction set of 16bit. The reason to use this thumb instruction set is to increase the code density. Specific information we can Google.
Here's how to easily modify the. so file.
First, we need to be familiar with the opcode of arm/thumb directives. Take Movs R1, #0 as an example. At first glance, this is an arm 32bit assembly instruction, but the 16 binary representation of this instruction is only 16bit! because the compiler has automatically optimized this instruction to 16-bit thumb-instruction MOV R1, #0, whose 16-binary representation is 00 21. So how did this 00 21 come from? This requires us to understand the opcode of the thumb command:
As shown, the 0~7 bit is the immediate value, the 8~10 bit is the source/destination register, and the 11~12 is the first 3 bits of sub_opcode,13~15 for opcode. It is worth noting that the 5-bit opcode is divided into two parts-the first 3 bits 001 are fixed, and the last 2 bits are used to identify different operations in 4: MOV, CMP, add, Sub. So the opcode binary representation of the MOV instruction is 00100; here Rd is R1, so the 8~10 bit is 001, so 0~7 is 0000 0000. So Movs R1, #0的2进制表示为: 0010 0001 0000 0000 = 0x 21 00.
But why is 00 21 displayed? This is because ARM-CPU uses small-end alignment, and as for what is small-end alignment, you can also Google yourself.
Analysis here, it's over. If we want the original. So file Movs R1, #0 modified to Movs R1, #1, then we just need to change the original 0x 00 21 to 0x01 21.
attached thumb opcode address: https://ece.uwaterloo.ca/~ece222/ARM/ARM7-TDMI-manual-pt3.pdf
ARM opcode:http://simplemachines.it/doc/arm_inst.pdf