@[toc]
The background,
As shown in the figure below, HERE I need to modify the three-party SDK source code.
- First, its SDK is an AAR package, which is decompressed to get the dependency package classes.jar.
- Decompiling classes. The jar to get the source code, will com. HDGQ. Locationlib. Constant. The ENVIRONMENT value defaults to “release”.
- Repackage the tests.
By three-party SDK changes, I mean changes to the Java part. Since Java is a language that runs on a virtual machine and its compiled bytecode class files are relatively easy to crack, this mechanism opens up the possibility of cracking all Java programs.
2. Run unzip to decompress the file
The so-called WGT, JAR, AAR, APK and IPA are all compressed formats in nature and follow the zip compression specification. Here we use the MacOs(Unix-based) zip command, of course, can also directly use Windows that advertised daily compression software.
unzip -o -d /home/sunny myfile.zip
Copy the code
Decompress the myfile.zip file to /home/sunny/
-o: Overwrites files without prompting. -d:-d /home/sunny decompresses the file to the /home/sunny directory.
Here we get the unzipped folder as followsGo ahead and unzip classes.jar to get the folder belowHere we open the target file Constants.class and we get the following
Edit the class file
The class file here is a machine bytecode file compiled by Java. If you open it directly, it will not be recognized. Here we need to use the compilation tool, drag the file to Idea, AndroidStudio and other tools. You can see the source code figure
Note the package name here
package com.hdgq.locationlib.constant
Copy the code
Since we can’t modify the bytecode file directly, we can generate it indirectly. Create a new project using androidStudio. The package names for adding dependent Modules are the same as above. See the figure belowClick Recompile to get the modified class file in build
Zip command to repackage the SDK
Here we replace the modified class file with the file in the classess.jar decompress folder, and use the zip command to regenerate the classess.jar package. Then overwrite the classess.jar into the locationSDK-1.0.0. aar decompress folder and regenerate the locationSDK-1.0.0. aar package
Zip -r myfile.zip./*Copy the code
All files and folders in the current directory are compressed into myfile.zip inline code block file. Inline code block -r indicates that all files in the subdirectory are recursively compressed.
Iv. Test and verification
At this point, we put the generated SDK back into the original project directory and use androidStudio to view it, as shown in the figureTest its SDK function to no problem.