Method, device and computer-readable storage medium for deobfuscating Android application source code
Through natural language processing and word frequency-inverse text frequency technology, the Android application source code is deconfused, which solves the problems of high reverse engineering complexity and poor naming readability in the existing technology, and achieves the improvement of global uniqueness and source code readability. .
Patent Information
- Application Number
- CN202110217555.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-26
- Publication Date
- 2024-11-15
- Estimated Expiration
- 2041-02-26
AI Technical Summary
Existing anti-obfuscation technologies are difficult to effectively reduce the complexity of reverse engineering of Android application source code, and the naming conversion is poor readability and lacks global uniqueness.
The natural language processing and word frequency-inverse text frequency technology are used, combined with statistical methods, and the source code of Android application is deconfused, by replacing the content of the .source field in the Smali source code, and using the string.xml file in the Android system to replace meaningless vocabulary. And use TF-IDF technology to find out high-frequency vocabulary for replacement of method names and class names to ensure the global uniqueness of naming.
It improves the efficiency and success rate of reverse engineering, improves the readability of the source code, and ensures meaningful conversion and global uniqueness of file names, class names, interface names, method names, etc.
Smart Images

Figure CN114968265B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure generally relates to the field of network technology and security, and more specifically to a method, device and computer-readable storage medium for deobfuscating Android application source code. Background Art
[0002] Source code obfuscation is the most common source code protection method in Android applications. It is widely adopted by developers as a basic, effective method with relatively little impact on the source program. However, many malicious applications also protect themselves through obfuscation. They increase the difficulty of reverse engineering for security personnel by renaming classes, interfaces, fields and methods with short and meaningless names, and increase the complexity of the program by adding useless classes, fields, methods, properties and processes. Invalid code causes some reverse tools to report errors. Therefore, for the above obfuscation methods, corresponding anti-obfuscation methods are needed to reduce the complexity of reverse engineering.
[0003] For example, there is a technical solution in the prior art, which converts instructions through javap, analyzes the instructions, converts them by type, and finally deletes useless instructions based on stack instructions. The main shortcomings are that the converted naming is less readable, there are many meaningless conversions, and deleting the useless code part at the end is less efficient.
[0004] For example, there is another technical solution in the prior art, which uses taint analysis to perform control flow tailoring, which is mainly limited to applications that only process control flow obfuscation. Summary of the invention
[0005] A brief overview of the disclosure is given below in order to provide a basic understanding of some aspects of the disclosure. However, it should be understood that this overview is not an exhaustive overview of the disclosure. It is not intended to identify the key or important parts of the disclosure, nor is it intended to limit the scope of the disclosure. Its purpose is simply to give some concepts of the disclosure in a simplified form as a prelude to a more detailed description given later.
[0006] According to one aspect of the present disclosure, a method for deobfuscating Android application source code is provided, comprising: deobfuscating the Android application source code to obtain obfuscated Smali source code and Java source code; replacing corresponding names in the obfuscated Java source code based on the content in the .source field in the obfuscated Smali source code, wherein the corresponding name includes one or more of a file name, an outermost class name, an interface name, and a constructor name; replacing meaningless words in the obfuscated Java source code based on the content in string.xml in the Android system; and using the term frequency-inverse text frequency (TF-IDF) technology to find out the unique high-frequency words in the methods and classes of the Android application and replace the corresponding method names and class names in the obfuscated Java source code with the unique high-frequency words.
[0007] According to another aspect of the present disclosure, a device for deobfuscating Android application source code is provided, comprising: a memory having instructions stored thereon; and a processor configured to execute the instructions stored on the memory to perform the method as described above.
[0008] According to another aspect of the present disclosure, a computer-readable storage medium is provided, which includes computer-executable instructions. When the computer-executable instructions are executed by one or more processors, the one or more processors execute the method according to the above aspects of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] The accompanying drawings, which constitute a part of the specification, describe embodiments of the present disclosure and, together with the specification, are used to explain the principles of the present disclosure. With reference to the accompanying drawings, the present disclosure can be more clearly understood according to the following detailed description, in which:
[0010] Figure 1 A flowchart of an example process 100 for deobfuscating Android application source code according to one embodiment of the present invention is shown;
[0011] Figure 2 A flowchart showing another example process of deobfuscating Android application source code according to one embodiment of the present invention is shown;
[0012] Figure 3 An exemplary configuration of a computing device that can implement an embodiment according to the present disclosure is shown. DETAILED DESCRIPTION
[0013] The following detailed description is made with reference to the accompanying drawings, and the following detailed description is provided to assist in a comprehensive understanding of the various exemplary embodiments of the present disclosure. The following description includes various details to assist in understanding, but these details are considered to be examples only and not to limit the present disclosure, which is defined by the appended claims and their equivalents. The words and phrases used in the following description are only used to enable a clear and consistent understanding of the present disclosure. In addition, for the sake of clarity and brevity, descriptions of well-known structures, functions, and configurations may be omitted. Those of ordinary skill in the art will recognize that various changes and modifications may be made to the examples described herein without departing from the spirit and scope of the present disclosure.
[0014] The inventors have noticed that general deobfuscation methods organize chaotic naming into a relatively regular form, but the meaning itself is still unclear. At the same time, many deobfuscation tools only make the naming unique in the current class, and do not consider global uniqueness. In order to solve the problems existing in the prior art, the inventors propose a method for deobfuscating Android application source code, which deobfuscates the source code of Android applications by introducing natural language processing and combining statistical methods, analyzes and predicts the obfuscated parts, restores the source code of Android applications, and uniquely identifies the naming, which can reduce the difficulty of reverse work and improve reverse efficiency and success rate.
[0015] Figure 1 A flowchart of an example process 100 for deobfuscating Android application source code according to an embodiment of the present invention is shown.
[0016] In block 101 , the Android application source code is deobfuscated to obtain obfuscated Smali source code and Java source code.
[0017] In block 102, corresponding names in the obfuscated Java source code are replaced based on the content in the .source field in the obfuscated Smali source code, where the corresponding names include one or more of a file name, an outermost class name, an interface name, and a constructor name.
[0018] In block 103 , meaningless words in the obfuscated Java source code are replaced based on the content in string.xml in the Android system.
[0019] In block 104, the term frequency-inverse text frequency (TF-IDF) technique is used to find out the unique high-frequency words in the methods and classes of the Android application and replace the corresponding method names and class names in the obfuscated Java source code with the unique high-frequency words.
[0020] The following combination Figure 2 Each step of process 100 is described in detail. Figure 2A flowchart of another example process of deobfuscating Android application source code according to an embodiment of the present invention is shown. It is worth noting that the following description includes a large number of unnecessary details, and those skilled in the art can choose these details as needed.
[0021] In S1, the obfuscated Smali source code of the Android application is obtained by decompiling. For example, apktool can be used to decompile the obfuscated Smali source code of the Android application.
[0022] In S2, the obfuscated Java source code of the Android application is obtained by decompiling. For example, jadx can be used to decompile the obfuscated Java source code of the Android application.
[0023] In S3, the Android application entry is found by analyzing the AndroidManifest.xml manifest file, and the control flow graph is obtained through taint analysis. The code that is not executed is deleted according to the control flow. For example, the control flow graph can be obtained by taint analysis through FlowDroid. Since there will be a series of codes that will not be actually executed, such as redundant undeleted code, commented code, temporarily written code and not used code, deleting it will reduce the subsequent workload.
[0024] The AndroidMainfest.xml manifest file is required for each Android project. It is the global description file for the entire Android application. For example, AndroidMainfest.xml can include the following content:
[0025] <! --Specify that this Activity is the entry point of the program -->
[0026] <action android:name="android.intent.action.MAIN" / >
[0027] <! --Specify to run the Activity when loading the application-->
[0028] <category android:name="android.intent.category.LAUNCHER" / >
[0029]
[0030]
[0031]
[0032] In S4, the .source field is obtained from the Smali source code extracted from S1, and the file name, outermost class name or interface name, and constructor name of the Java source code obtained in S2 are replaced by this field according to Java syntax.
[0033] In Android applications, string.xml is used to store text that is defined and appears in the application, such as text displayed on the screen. This can achieve internationalization, reduce the size of the application and reduce data redundancy.
[0034] For example, the .source field includes the main function "AuthOption.java".
[0035] a. The contents of the smali file
[0036]
[0037] b. The contents of the java file
[0038]
[0039] Replace the main function name a in the red box in b with AuthOption. This is due to the characteristics of the Java language. The name of the Java code file must be consistent with the class name, and the constructor name is the class name. In addition, other methods with the same name in the same file are overloaded methods of the constructor, so they can be replaced synchronously.
[0040] In S5, the meaningless words in the Java source code obtained in S2 are replaced according to the string.xml in the traversed resource file. By traversing the string.xml in the resource file and replacing the Java source code as much as possible with the relevant string, the accuracy of subsequent processing can be improved.
[0041] The following shows an example where string replacement can be done:
[0042]
[0043] The function of the string.xml file itself is to manage some commonly used or frequently changed strings in a unified manner, and then reference them in the application code through the name attribute. For example, the strings in the string.xml file are usually referenced in the code like this:
[0044] String str=(String)this.getResources().getText(R.string.ao1);
[0045] This will result in less information being available in this code later, but if the string.xml<string name=”ao1”> Verify your name and phone
[0046] After the replacement, there is more meaningful information in the source code for later use:
[0047] String str=(String)this.getResources().getText("Verify your name andphone");
[0048] At this point, it is easy to determine that the method to which this code belongs is most likely used to verify the username and mobile phone number.
[0049] In S6, tf-idf is used to find the unique high-frequency words in each method, and then the words in the pre-learned model that are closest to the high-frequency words are found based on the high-frequency words, and the package name and method name are combined and completed as the method name of the method; and tf-idf is used to find the unique high-frequency words in each category, and then the words in the pre-learned model that are closest to the high-frequency words are found based on the high-frequency words, and the package name is combined and completed as the class name of the class.
[0050] For example, a corpus composed of a large amount of unobfuscated code is used in advance to model the vocabulary relevance model using WordRank, and the corpus is analyzed for part of speech. Then, tf-idf is used to find the unique high-frequency words of each method in the obfuscated source code. If the high-frequency word is a verb, the noun with the highest probability in the model is selected, otherwise the verb is selected, and the gerund phrase is combined as the method name. At the same time, in order to ensure that this method is globally unique, the package name and class name need to be added in front. tf-idf is used to find the unique high-frequency words of each type in the obfuscated source code. If the high-frequency word is a verb, the noun with the highest probability in the model is selected, otherwise the verb is selected, and the gerund phrase is combined as the class name. At the same time, in order to ensure that this type of global uniqueness, the package name needs to be added in front of the class name.
[0051] tf-idf (term frequency–inverse document frequency) is a commonly used weighting technique for information retrieval and data mining, where TF is term frequency and IDF is inverse document frequency. For example, this article uses the following formula to calculate tf and idf:
[0052]
[0053] In this paper, the numerator in the TF formula represents the word n i In file d jThe denominator is the number of times it appears in file d j The numerator in the idf formula represents the total number of documents in the corpus, and the denominator is the number of documents containing the word t. i The number of files.
[0054] For example, the word frequency can be calculated by the following formula:
[0055] tfidf i,j =tf i,j ×idf i
[0056] The following shows how to use the above model to determine that the unique high-frequency words in the code are phone and DIAL.
[0057]
[0058] In addition, determine the parts of speech as noun, verb, and noun, respectively, as shown below:
[0059]
[0060] According to the unique high-frequency word phone as a noun, we take the verb with the highest probability in the model and predict that the actual method name a should be callPhone. At the same time, to ensure uniqueness, we need to add the package name and class name, so the final result is:
[0061] public void package_a.class_a.callPhone(C b){…}
[0062] This step is based on the following logic: Since the more formal naming method of class names and method names is usually to use the verb plus noun method and the camel case naming convention (for example: getAge() represents the method for getting age, setYear(int year) represents the method for setting the year), adding the package name before the method name and class name can ensure that the method is globally unique. Because the obfuscated code may appear in many different Java files with different methods obfuscated into a, it is not convenient for researchers to uniquely search and locate a specific method.
[0063] In S8, for unpredictable class names, method names, and variable names, they are renamed by adding class_, method_, and param_ prefixes, and the package names, class names, etc. are completed to complete the source code deobfuscation.
[0064] For example, before utilizing the processing in S8, the code is:
[0065]
[0066] After processing using S8, the code is:
[0067]
[0068] This step is to at least distinguish the package name, class name and method name when the class name and method name cannot be predicted. Because after obfuscation, different classes, methods and variables in different files can all become a. In this way, when searching for a, the results will be mixed with packages, classes, methods and variables with the same name, which is not convenient for researchers to classify and process.
[0069] Compared with the prior art, the present invention has one or more of the following advantages and effects:
[0070] 1. Make meaningful conversions to the file names, class names, interface names, method names, etc. of the Android application source code to ensure global uniqueness, and
[0071] 2. Improve reverse engineering efficiency and enhance source code readability.
[0072] Figure 3 An exemplary configuration of a computing device 1200 capable of implementing embodiments according to the present disclosure is shown.
[0073] The computing device 1200 is an example of a hardware device to which the above aspects of the present disclosure can be applied. The computing device 1200 can be any machine configured to perform processing and / or computing. The computing device 1200 can be, but is not limited to, a workstation, a server, a desktop computer, a laptop computer, a tablet computer, a personal data assistant (PDA), a smart phone, a vehicle-mounted computer, or a combination thereof.
[0074] like Figure 3 As shown, the computing device 1200 may include one or more components that can be connected or communicated with the bus 1202 via one or more interfaces. The bus 1202 may include, but is not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MCA) bus, an Enhanced ISA (EISA) bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus. The computing device 1200 may include, for example, one or more processors 1204, one or more input devices 1206, and one or more output devices 1208. The one or more processors 1204 may be any type of processor, and may include, but is not limited to, one or more general-purpose processors or special-purpose processors (such as special-purpose processing chips). The processor 1204 may, for example, be configured to implement the following. Figure 1The method shown. Input device 1206 can be any type of input device capable of inputting information to a computing device, and can include, but is not limited to, a mouse, a keyboard, a touch screen, a microphone, and / or a remote controller. Output device 1208 can be any type of device capable of presenting information, and can include, but is not limited to, a display, a speaker, a video / audio output terminal, a vibrator, and / or a printer.
[0075] The computing device 1200 may also include or be connected to a non-transitory storage device 1214, which may be any non-transitory storage device that can implement data storage, and may include, but is not limited to, a disk drive, an optical storage device, a solid-state memory, a floppy disk, a flexible disk, a hard disk, a tape, or any other magnetic medium, a compressed disk or any other optical medium, a cache memory, and / or any other storage chip or module, and / or any other medium from which a computer can read data, instructions, and / or code. The computing device 1200 may also include a random access memory (RAM) 1210 and a read-only memory (ROM) 1212. The ROM 1212 may store programs, utilities, or processes to be executed in a non-volatile manner. The RAM 1210 may provide volatile data storage and store instructions related to the operation of the computing device 1200. The computing device 1200 may also include a network / bus interface 1216 coupled to a data link 1218. The network / bus interface 1216 may be any type of device or system capable of enabling communication with an external device and / or a network, and may include but is not limited to a modem, a network card, an infrared communication device, a wireless communication device, and / or a chipset (such as a Bluetooth TM equipment, 802.11 equipment, WiFi equipment, WiMax equipment, cellular communication facilities, etc.).
[0076] The present disclosure may be implemented as any combination of an apparatus, a system, an integrated circuit, and a computer program on a non-transitory computer-readable medium. One or more processors may be implemented as an integrated circuit (IC), an application specific integrated circuit (ASIC), or a large scale integrated circuit (LSI), a system LSI, a super LSI, or a super LSI component that performs some or all of the functions described in the present disclosure.
[0077] The present disclosure includes the use of software, applications, computer programs, or algorithms. The software, applications, computer programs, or algorithms may be stored on a non-transitory computer-readable medium to enable a computer such as one or more processors to perform the above steps and the steps described in the accompanying drawings. For example, one or more memories store the software or algorithm in executable instructions, and one or more processors may associate a set of instructions to execute the software or algorithm to provide various functions according to the embodiments described in the present disclosure.
[0078] Software and computer programs (which may also be referred to as programs, software applications, applications, components or code) include machine instructions for a programmable processor and may be implemented in a high-level procedural language, an object-oriented programming language, a functional programming language, a logic programming language, or an assembly language or a machine language. The term "computer-readable medium" refers to any computer program product, apparatus or device for providing machine instructions or data to a programmable data processor, such as magnetic disks, optical disks, solid-state storage devices, memories and programmable logic devices (PLDs), including computer-readable media that receive machine instructions as computer-readable signals.
[0079] For example, computer readable media may include dynamic random access memory (DRAM), random access memory (RAM), read-only memory (ROM), electrically erasable read-only memory (EEPROM), compact disk read-only memory (CD-ROM) or other optical disk storage devices, magnetic disk storage devices or other magnetic storage devices, or any other medium that can be used to carry or store the desired computer readable program code in the form of instructions or data structures and can be accessed by a general or special purpose computer or a general or special purpose processor. As used herein, disk or disc includes compact disc (CD), laser disc, optical disc, digital versatile disc (DVD), floppy disk and Blu-ray disc, where disks usually reproduce data magnetically, while discs reproduce data optically by laser. Combinations of the above are also included in the scope of computer readable media.
[0080] The subject matter of the present disclosure is provided as an example of devices, systems, methods and programs for performing the features described in the present disclosure. However, in addition to the above-mentioned features, other features or variations may also be expected. It is expected that the implementation of the components and functions of the present disclosure may be completed with any emerging technology that may replace any of the above-mentioned implementation technologies.
Claims
1. A method for deobfuscating Android application source code, comprising: Deobfuscate the Android application source code to obtain the obfuscated Smali source code and Java source code; Replace the corresponding name in the obfuscated Java source code based on the content in the .source field in the obfuscated Smali source code, where the corresponding name includes one or more of the file name, the outermost class name, the interface name, and the constructor name; Replace meaningless words in the obfuscated Java source code based on the content in string.xml in the Android system; as well as Use the term frequency-inverse text frequency TF-IDF technology to find the unique high-frequency words in the methods and classes of Android applications and replace the corresponding method names and class names in the obfuscated Java source code with the unique high-frequency words, including: Use TF-IDF to find the unique high-frequency words of various methods in the obfuscated source code. If the high-frequency word is a verb, select the noun with the highest probability. Otherwise, select the verb and combine it into a gerund phrase as the method name. Add the package name and class name before the method name. Use TF-IDF to find the unique high-frequency words of each class in the obfuscated source code. If the high-frequency word is a verb, select the noun with the highest probability. Otherwise, select the verb and combine it into a gerund phrase as the class name, and add the package name before the class name; and For unpredictable class names, method names, and variable names, add class_, method_, and param_ prefixes to rename and complete the package name and class name to complete source code deobfuscation.
2. The method according to claim 1, further comprising: By analyzing the Android application's global description file AndroidManifest.xml to find the entry point of the Android application, and The control flow graph of the Android application is obtained by performing taint analysis on the Android application from the found entry, and the unexecuted code is deleted from the obfuscated Java source code according to the control flow graph.
3. The method according to claim 1, wherein a corpus consisting of a large amount of unobfuscated codes is pre-modeled using WordRank to obtain a vocabulary relevance model, and the corpus is subjected to part-of-speech analysis to obtain unique high-frequency words in methods and classes.
4. A device for deobfuscating Android application source code, comprising: a memory having instructions stored therein; as well as A processor configured to execute instructions stored on the memory to perform the method according to any one of claims 1 to 3.
5. A computer-readable storage medium, comprising computer-executable instructions, which, when executed by one or more processors, enable the one or more processors to execute the method for deobfuscating Android application source code according to any one of claims 1 to 3.
