1. Preamble
In the App-side crawling process, encountered unknown parameters, often need us to reverse crack App, for the generation of parameter logic, using Python to realize the
The logic for generating some of the app parameters may have been written in multiple JAR files, so we just need to execute the JAR in Python!
This post will talk about how Python calls methods in JARs.
2. Consolidation of JARs
Taking Android App as an example, assuming that the encryption parameter generation logic is in multiple JARs, we first need to merge all the JAR files into a single JAR file
PS: For AAR files, you can decompress them with decompression software first, and then merge the JARs.
Merging JARs is a 2-step process:
- Decompress JAR
- Merge all source code
2-1 Decompressing the JAR
After installing the JDK, use the jar -xvf command to extract individual JARs, which will generate Java-compiled class files in the same directory as the package name.
# Unpack the JARs one by one # Generate class files locally jar -xvf jar -xvf jar -xvf
2-2 Merging All Source Code
Use the jar -cvfM command to generate a new JAR with all the local class files
# Merge all sources in the current directory into one JAR # where: represents the new JAR jar -cvfM .
3. Python calls JARs
First, we install the dependency package: jpype
# Install dependent packages pip3 install JPype1
Assume that the encryption logic in the JAR is implemented in the following code:
package ; public class EncryHelper { public String encrypt(String content) { // Encryption logic } }
Calling methods in a JAR using Python is a 3-step process:
- Starting the JVM
- Instantiate the Java object and call the corresponding method.
- Shutting down the JVM
3-1 Starting the JVM
import jpype # JAR local path jar_path = (('.'), './') # Start jvm ((), "-ea", "-=%s" % (jar_path))
3-2 Instantiating JAVA Objects and Calling Methods
According to the package name of the called method, use the JClass() method in jpyte to instantiate the JAVA object, and then call the method of the JAVA object.
It should be noted that because of instance methods in JAVA, you need to instantiate the object first, and then call the method; if it's a static method, you can directly call the method
# Instantiate JAVA objects by package name EncryClass = ("") encryClass = EncryClass() # Calling encryption methods in JAVA content_encry = ("xag") print(content_encry)
4. Finally
Python calls the methods in the JAR directly, which can help us reuse the wheel and reduce the workload of the crawler!
The above is python reverse crawler correctly call JAR encryption logic of the details, more about python crawler correctly call JAR encryption logic of the information please pay attention to my other related articles!