1. Introduction
In the crawler process of App end, when we encounter unknown parameters, we often need to reverse crack the App and use Python to realize the generation logic of parameters
The generation logic for some of the App arguments may have been written into multiple JAR files, in which case we just need to execute the JAR in Python
This article will talk about how Python calls methods in jars
2. Combine the JAR
Taking the Android App as an example, assuming that the encryption parameter generation logic is in multiple JARS, we first need to merge all JAR files into a single JAR file
PS: For AAR files, you can decompress them using decompression software and then merge the JARS
Merging jars is divided into two steps:
-
Extract the JAR
-
Merge all source code
2-1 extract the JAR
After installing the JDK, unzip individual jars using the jar-xvf command to generate JAVA compiled class files in the same directory as the package name
Jar-jar-xvf b. jar-jar-xvf c. JARCopy the code
2-2 Merge all source code
Use the jar-cvfm command to generate a new JAR from all the local class files
JAR = JAR JAR -cvfm output.jar = JAR JAR -cvfm output.jarCopy the code
3. Python invokes the JAR
First, we install the dependency package: JPype
Pip3 install JPype1Copy the code
Assume that the encryption logic implementation code in the JAR is as follows:
package com.xingag.common; Public class EncryHelper {public String encrypt(String Content) {// Encrypt logic}}Copy the code
Calling a JAR method using Python has three steps:
-
Start the JVM
-
Instantiate the JAVA object and call the corresponding method
-
Close the JVM
3-1 to start the JVM
Import jpype # JAR Jar_path = os.path.join(os.path.abspath('.')) StartJVM (jpype.getDefaultjvmpath (), "-EA "," -djava.class.path =%s" % (jar_path))Copy the code
3-2 Instantiate the JAVA object and call the method
Based on the package name of the called method, instantiate the Java-like object using the JClass() method in JPyTE, and finally call the JAVA object’s method
Note that since JAVA is an instance method, you need to instantiate the object first and then call the method; If the method is static, you can call the method directly
# by package name, Instantiates a JAVA object EncryClass = jpype. JClass (" com.xingag.com mon. EncryHelper ") EncryClass = EncryClass # () call in JAVA encryption method content_encry = encryClass.encrypt("xag") print(content_encry)Copy the code
3-3 close the JVM
You can choose to actively shut down the JVM, or wait until the Python program is running to shut it down automatically, freeing resources
Import jpype # to disable jjpype.shutdownJVM ()Copy the code
4. The last
Python calls JAR methods directly, which can help us reuse wheels and reduce crawler workload!
I have sent the complete source code to the background, follow the public number “AirPython”, the background reply “pjar” can be obtained
If you think the article is good, please like, share, leave a message, because this will be my continuous output of more high-quality articles the strongest power!