A Differential-Based Cross-Version Anti-Obfuscation Detection Method for Android Applications
By aligning methods such as preprocessing and analysis, dynamic programming, and obfuscation awareness at the method level, the problem of repetitive analysis and obfuscation processing in cross-version differencing is solved, achieving efficient incremental detection and fine-grained differencing, and improving detection accuracy and efficiency.
Patent Information
- Application Number
- CN202611421874.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-14
- Publication Date
- 2026-11-17
AI Technical Summary
Existing technologies cannot identify and isolate unchanged code, resulting in a large amount of duplicate analysis and noise during cross-version differential analysis, and cannot effectively handle the low detection efficiency caused by obfuscator renaming.
By preprocessing and analysis, class-level alignment based on dynamic programming and method-level alignment based on confusion awareness, combined with character mapping normalization, logical focus pruning and instruction abstraction, a precise incremental difference is achieved using dynamic programming algorithm and context-triggered segmented hashing technology. Semantic refinement and correction are then performed using LLM to generate high-fidelity fine-grained difference results.
It achieves accurate extraction of incremental difference results in a confused environment, improves the recall rate of class-level matching, reduces computational complexity, improves detection efficiency, and provides high-fidelity incremental change evidence.
Smart Images

Figure CN123116231A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a technology in the field of information security, specifically a method for cross-version anti-obfuscation detection of Android applications based on differential methods. Background Technology
[0002] In the context of rapid iteration and high-frequency updates in modern applications, most of the underlying code between two consecutive versions of an application typically remains unchanged. Performing full code inspection on every new version would result in excessively high computational costs, slow response times, and difficulty in accurately capturing incremental security threats that emerge during version evolution. Existing differential methods cannot identify and isolate unchanged code, generating a large amount of redundant analysis and noise during cross-version comparisons. Furthermore, they ignore the deterministic processing order during obfuscator (such as R8) renaming, making it difficult to accurately isolate incremental changes from tens of thousands of obfuscated classes, resulting in low detection efficiency. Summary of the Invention
[0003] This invention addresses the shortcomings of existing technologies that cannot identify and isolate unchanged code, leading to a large amount of redundant analysis during cross-version differential analysis. It proposes a differential-based method for anti-obfuscation detection of Android applications across versions. Through preprocessing and analysis, class-level alignment based on dynamic programming, and method-level alignment based on obfuscation awareness, it accurately extracts and outputs high-fidelity, fine-grained incremental differential result files containing class-level and method-level states from two Android application installation package files (APKs).
[0004] This invention is achieved through the following technical solution:
[0005] This invention relates to a differential-based method for cross-version anti-obfuscation detection of Android applications, comprising:
[0006] Step 1: Android binary file preprocessing and analysis, specifically including:
[0007] 1.1 Perform multi-level feature extraction across three dimensions: Using reverse engineering tools, unpack, disassemble, and extract code information from the two input Android application installation package files APK1 and APK2, respectively. Specifically, this includes:
[0008] 1) Unpacking: APK1 and APK2 are read and decompressed respectively to obtain AndroidManifest.xml, DEX files, and application resource files. The DEX file is the executable code file of the Android application. Further, application metadata such as package name and component information in AndroidManifest.xml is read, and the code file to be analyzed is determined based on the DEX file contained in the APK.
[0009] 2) Disassembly: Disassemble the DEX files in APK1 and APK2 respectively, convert the Dalvik bytecode in the DEX files into analyzable Smali instruction form, and obtain the classes, methods and their corresponding bytecode instruction sequences in the application.
[0010] 3) Code Information Extraction: Class-level and method-level information is extracted from the disassembled code of APK1 and APK2 respectively. Class-level information includes class name, access flags, parent class, implemented interfaces, fields, and contained methods; method-level information includes method name, method descriptor, access flags, and the corresponding Smali instruction sequence. Further, based on the extracted class-method hierarchical relationships, method information is associated with its parent class, forming a code information set organized by class, which serves as input for subsequent code feature construction and cross-version code matching.
[0011] The three dimensions include: metadata recovery (including method signatures and field descriptors), static cross-references (control flow and call relationships), and Smali (the assembly representation of Android bytecode) instruction sequences.
[0012] The reverse engineering tools mentioned are implemented using, but are not limited to, software such as AndroGuard.
[0013] 1.2 Character Mapping Normalization: Remapping logic is performed on non-standard Unicode characters generated during the R8 code obfuscation process when building APKs. These characters are mapped to areas that can be processed normally. By eliminating ambiguity at the encoding level, decoding crashes or string hash inconsistencies that may occur when decompilation engines process deeply obfuscated APKs are effectively prevented, ensuring the robustness of the analysis process.
[0014] The non-standard Unicode characters mentioned above refer to surrogate pairs of characters that cannot be directly decoded and are located in the range of 0xD800–0xDFFF.
[0015] The area that can be processed normally is the characters in the range of 0xE000–0xE7FF, that is, <mapped character> = 0xE000 + (<original character> - 0xD800).
[0016] 1.3 Logic Focus Pruning: First, filter out the auxiliary classes and methods automatically generated by the compiler during APK construction. Then, clean up empty entities that do not contain any valid logical instructions and resource index classes that are unrelated to business logic, thereby accurately focusing limited computing resources on the core business logic of the application.
[0017] 1.4 Instruction Abstraction Processing: All Smali instruction streams retained in step 1.3 are abstracted to eliminate surface-level and volatile features unrelated to functional logic, thus constructing an obfuscated and invariant instruction pattern. Specifically, this includes:
[0018] 1.4.1 Replace all the specific register indices in the instructions obtained in step 1.3 with generic placeholders that do not distinguish between numbers, i.e., vX represents local registers and pY represents parameter registers; thereby eliminating the influence of register allocation scheme on instruction mode.
[0019] 1.4.2 The immediate values contained in the instructions obtained in step 1.3 are desensitized, that is, the immediate values contained in the instructions are uniformly replaced with a standard marker to ignore the differences in specific values.
[0020] The instruction abstraction process retains the core logical skeleton composed of opcode sequences and control flow by abstracting, while ignoring the differences in register allocation or changes in local constants that may occur under different compilation environments due to compiler optimization and obfuscator rule settings. This significantly enhances the resistance to minor instruction scheduling and rearrangement behaviors performed by obfuscators such as R8 that do not change the semantics, thus providing a stable and reliable input foundation for subsequent feature extraction and similarity comparison based on fuzzy hashing.
[0021] Step 2: Employ a class-level alignment algorithm based on dynamic programming to accurately map the confused class entities in the results of Step 1. This specifically includes:
[0022] 2.1 Class order reconstruction based on deterministic sorting of obfuscator: After extracting the complete class entity lists of APK1 and APK2 from the preprocessing results of step one, sort them lexicographically by obfuscation name and convert them into two class sequences with stable relative positional relationships.
[0023] 2.2 Anchor-Assisted Search Space Partitioning: Anchor classes are extracted from the two class sequences obtained in step 2.1 as boundaries. The full class sequence obtained in step 2.1 is then divided into multiple small local intervals, specifically including:
[0024] 2.2.1 Calculate the fuzzy hash value (such as context-triggered segmented hash CTPH) of the obfuscation invariant feature string of each obfuscation class. If a certain hash value appears only once in all obfuscation classes of APK1 and only once in all obfuscation classes of APK2, and the values are the same in both versions, then the corresponding two classes are identified as anchor classes.
[0025] The obfuscated invariant characteristic strings include: 1) Field information: access flags and descriptors for each field; 2) Interface implementation relationship: type names for each interface; 3) Parent class inheritance relationship: type names for parent classes; 4) Method information: descriptors for each method (signature sequence of parameters and return types after type abstraction); 5) Constant string sequence: string constants loaded by const-string instructions within the method. Type abstraction refers to uniformly replacing all user-defined types not belonging to the Android SDK with the placeholder "X".
[0026] 2.2.2 Using the anchor class as the boundary, the sorted class sequences of APK1 and APK2 are divided into non-overlapping local intervals between adjacent anchor classes. Subsequently, class-level matching is only performed within the corresponding local intervals.
[0027] 2.3 Structural alignment based on Longest Common Subsequence (LCS): Precise structural alignment based on LCS is performed within each local interval, specifically including:
[0028] 2.3.1 Generate a comprehensive obfuscation-invariant feature string for each class within the local interval;
[0029] 2.3.2 After generating a fuzzy hash value for the obfuscated invariant feature string using Context Triggered Piece Hash (CTPH) technology, the Levinstein distance between the CTPH hash values of two classes is calculated to quantify their structural differences. For any pair of classes within the corresponding local intervals of the two versions, the similarity score matrix is obtained through pairwise calculations. Specifically: Where: h1 and h2 are the CTPH fuzzy hash values of the two classes in APK1 and APK2, respectively; lev(h1,h2) is the Levenstein distance between them; |h| represents the length of the hash value; This indicates that the larger value is taken; Sim(h1,h2) is the normalized structural similarity score between the two classes, with a value between 0 and 1.
[0030] The aforementioned context-triggered piecewise hashing employs, but is not limited to, the techniques described in "Identifying almost identical files using context-triggered piecewise hashing" (Digit. Investig. 3 (September, 2006), 91–97).
[0031] 2.3.3 The longest common subsequence (LCS) of the similarity score matrix is solved using a dynamic programming algorithm, which maximizes the sum of the cumulative similarities of all matching pairs along the matching path that traverses the matrix. Specifically, a matching function is defined. Match returns 1 if a match is found, and 0 otherwise. Here, Match(h1,h2) is the matching function. The normalization threshold is used. This matching function is used to populate the dynamic programming table and backtrack to extract the optimal LCS path. Class pairs on the path are classified as matched classes. Classes that are identified as matches but not entered into the path are marked as "candidate matches" and handled by subsequent semantic refinement. Other classes not identified as matches are classified according to their version: if they exist in APK2 but not in APK1, they are classified as added classes; otherwise, they are classified as deleted classes.
[0032] The normalized threshold The preferred value is 0.6.
[0033] 2.4 LLM-based Semantic Refinement and Correction: For the candidate matching groups obtained after structural alignment in step 2.3, LLM-based semantic reasoning is performed, specifically including:
[0034] 2.4.1 Extract and format a rich set of contextual information for each pair of candidate classes from APK1 and APK2, including the decompiled Java pseudocode of the class, the key API call sequence of the main methods in the class, and the field definitions, inheritance relationships and internal class structure of the class.
[0035] 2.4.2 This information is structured into a specific prompt word and submitted to the LLM for judgment: The prompt word requires the LLM to get rid of its dependence on the surface characters and structure of the code, and to judge from the perspective of functional intent and logical behavior whether the two given candidate classes represent the evolution of the same functional entity in different versions (such as undergoing renaming, method splitting / merging, algorithm refactoring but the function remains unchanged);
[0036] The prompts include: 1) Task instructions: requiring the LLM to determine whether two candidate classes correspond to the same functional entity across versions based solely on functional logic equivalence; 2) Context information: decompiled Java pseudocode of the two candidate classes, key API call sequences of main methods, field definitions, inheritance relationships, and inner class structures; 3) Output constraints: requiring the LLM to output a "Matched / Not Matched" judgment and provide a brief explanation.
[0037] The aforementioned judgment refers to the following: when the LLM determines that the two are logically equivalent in function, the tool will determine that the two classes are "Matched Classes" and record this association in the final difference mapping table.
[0038] Step 3: For the method entities within the matched classes in the class analysis result file obtained in Step 2, perform fine-grained alignment and change detection sequentially. Adopt differentiated processing strategies based on whether the methods are obfuscated. Finally, merge and output a differential report including both class and method levels, specifically including:
[0039] 3.1 The newly added classes, deleted classes, and matched classes obtained in step two form a class level, and multiple independent classes are cascaded together to form a method level.
[0040] Each paragraph in the method hierarchy corresponds to a set of internal method comparison results of matched classes, including: completely identical: methods in APK1 and APK2 that have not undergone logical changes; similar: methods that are determined to be the same method, but whose internal underlying code logic has been modified; newly added: method entities that exist in APK2 but not in APK1; deleted: method entities that exist in APK1 but not in APK2.
[0041] 3.2 Direct Identifier Mapping for Unobfuscated Methods: For method entities within each paragraph of the method hierarchy obtained in step 3.1 that retain their original names without obfuscation, a one-to-one precise mapping is first performed based on the complete descriptor of the method name, parameter type, and return value. Methods for which no mapping can be found are classified as newly added or deleted in the global report according to their version. After completing the mapping, the instruction sequence hash values of the two versions of the method are compared. If the hash values are completely identical, they are determined to be completely identical; if they are inconsistent, they are determined to be similar.
[0042] 3.3 Fingerprint synthesis and fuzzy matching using obfuscation methods, specifically including:
[0043] 3.3.1 Extracting and Normalizing Method Descriptors That is, after extracting the original descriptor such as the return type and parameter list of the method, all user-defined types in the original descriptor are uniformly replaced with a general placeholder "X", and non-functional modifiers such as access flags are removed, so as to obtain a normalized descriptor string that only contains normalized type information (such as primitive types I, Z, etc. and placeholders) and is immune to class name obfuscation.
[0044] 3.3.2 The instruction sequence obtained in step one is preprocessed to generate an instruction sequence string. Specifically, this includes instruction abstraction, noise instruction filtering (removing debug information, line number labels, and no-operations), and control flow simplification (eliminating redundant jumps while maintaining the topology), resulting in an instruction sequence string that represents the core logic of the method and is insensitive to register allocation and minor scheduling.
[0045] 3.3.3 Normalize the descriptor string With instruction sequence string Two strings are concatenated sequentially to generate a representative feature string. Then, use CTPH as Generate fuzzy fingerprints and calculate the normalized similarity score Sim( ) between the two fingerprints to be compared. 1, 2), and then compare the similarity score with the empirically optimized threshold. The comparison is performed, and those with a similarity score of 1 are considered to be completely identical. Those with a score less than 1 but not lower than the threshold are considered to be similar. Those with a score lower than the threshold are classified as newly added or deleted in the global report according to their version.
[0046] The representative feature string .
[0047] 3.4 Incremental State Establishment and Conflict Handling: Verify whether conflicting candidate matching pairs have the same or adjacent sequence indices in their respective classes. By combining this sequence consistency with the aforementioned semantic similarity score, the most likely unique correct match can be effectively analyzed, thereby resolving ambiguous conflicts and ensuring that each method is assigned at most one most reasonable corresponding state. Specifically: when there may be multiple fuzzy matching results for similar method pairs, first use sequence consistency as a hard constraint, retaining only candidate matching pairs with the same or adjacent declaration sequence indices; if conflicts still exist after filtering, select the highest score from the remaining candidates based on the normalized similarity score in 3.3 as the unique match, ensuring that each method is assigned at most one corresponding state. The sequence index refers to the declaration sequence number of the method within its class entity (which declared method).
[0048] 3.5 Generate Final Report: Summarize the aforementioned class-level matching results with the method-level comparison results of each matching class pair, and output a differential report file with the suffix xx.match. This report includes: class-level matching results, i.e., a list of class entities in three states: newly added class, deleted class, and matched class, and the correspondence between each pair of matched classes in the two versions; and method-level matching results, i.e., the method comparison results within each pair of matched classes, including four states: completely identical, similar, newly added, and deleted. This differential report serves as input for downstream security detection tools or manual analysts to conduct incremental risk screening.
[0049] This invention relates to an Android application cross-version anti-obfuscation detection system that implements the above-mentioned method, comprising a preprocessing unit, a class-level alignment unit, a method-level alignment unit, and a report generation unit, wherein: the preprocessing unit is used to perform unpacking and decompiling, character mapping normalization, logic focus pruning, and instruction abstraction processing on the installation package files of the two Android applications to be compared, to obtain corresponding preprocessed information files; the class-level alignment unit is used to deterministically sort the obfuscation class sets of the two versions according to the obfuscation name based on the preprocessed information files, divide them into local intervals with anchor class as the boundary, and perform LCS within the intervals. The system performs structural alignment and semantic refinement and correction of candidate matching groups based on LLM to obtain a class analysis result file containing the states of newly added classes, deleted classes, and matching classes. A method-level alignment unit is used to perform direct identifier mapping on non-obfuscated methods, fingerprint synthesis and fuzzy matching on obfuscated methods, and conflict handling in conjunction with order consistency, based on the matching class pairs in the class analysis result file, to obtain the comparison results of method entities in completely identical, similar, newly added, and deleted states within each matching class. A report generation unit is used to merge and output a differential report file with the suffix .match, based on the class-level matching results and the method-level matching results.
[0050] Technical effect
[0051] Compared with existing technologies, this invention solves the decoding crashes and string hash inconsistencies caused by non-standard Unicode characters during the decompilation of deeply obfuscated APKs through five steps: character normalization mapping and logical focus pruning preprocessing, serialization alignment based on deterministic sorting using obfuscation tools, anchor point identification and search space partitioning strategies, integration of an LLM semantic reasoning correction module, and hierarchical alignment based on CTPH fuzzy hashing and normalized fingerprint formulas. It transforms complex graph matching or full search into ordered sequence matching, fundamentally eliminating the "alignment offset" phenomenon caused by obfuscation, greatly improving the recall rate of class-level matching, reducing the computational complexity from global O(N²) to local O(M²), and solving the problem that traditional static comparison tools cannot align between highly evolved versions. Ultimately, it achieves accurate differentiation between "complete matches" and "minor updates," providing security inspectors with high-fidelity incremental change evidence. Attached Figure Description
[0052] Figure 1 This is a flowchart of the present invention;
[0053] Figure 2 A schematic diagram of the deterministic sorting mechanism of the R8 obfuscator;
[0054] Figure 3 A schematic diagram of the search space partitioning for anchor point classes;
[0055] In the diagram: each square represents a class entity, and the black squares represent the corresponding anchor point class entities in the two versions;
[0056] Figure 4 This is a diagram of the decompiled Java code of the v1() method in the newly added malicious activity HomeOpenUrlActivity in the embodiment.
[0057] Figure 5 This is a diagram illustrating the decompiled Java code of the newly added method com.xvideostudio.videoeditor.tool.h0::b() in the example. Detailed Implementation
[0058] like Figure 1 As shown in the figure, this embodiment involves a method for cross-version anti-obfuscation detection of Android applications based on differential mapping. The screen recording application V Recorder, which has been downloaded more than 100 million times worldwide, is used as the analysis object. The comparison version is the initial version v5.0.1 and the iterative version v6.3.4.
[0059] The developers of V Recorder used deep R8 obfuscation, resulting in numerous business class names and method names becoming meaningless short characters. When upgrading from version v5.0.1 to v6.3.4, the application introduced a privacy leak risk: the new version added a suspicious activity, HomeOpenUrlActivity, which contains an obfuscated v1() method that calls setJavaScriptEnabled(true) to enable JavaScript execution. Subsequently, the obfuscated method com.xvideostudio.videoeditor.tool.h0::b() calls the source API's getDeviceId(), and quietly leaks the device ID to the WebView page via JavaScript. The pseudocode obtained through manual analysis using reverse engineering tools is as follows... Figure 4 and Figure 5 As shown.
[0060] This embodiment specifically includes:
[0061] Step 1: Android binary file preprocessing and analysis, specifically including:
[0062] 1.1 Taking the APK files of V Recorder v5.0.1 and v6.3.4 as input, the program sequentially unpacks and decompiles the files and extracts the metadata (method signature, field descriptor), static cross-references, and Smali instruction sequences of each class.
[0063] 1.2 Map non-standard Unicode characters to a properly processed region; filter compiler-generated helper classes and methods (such as constructors). <init>()V, composition method s1(Lcom / xvideostudio / videoeditor / activity / HomeOpenUrlActivity;Ljava / lang / String;)V), empty entity and resource index class;
[0064] 1.3 Abstraction is performed on reserved instructions, replacing registers with general placeholders, immediate values with standard flags (e.g., const / 4v0,0x1 is abstracted to const / 4vX,#IMM), and user-defined types with placeholders "X" (e.g., the parameter of method L1(Lcom / xvideostudio / videoeditor / gsonentity / HomePosterAnd Material;)V is abstracted to X).
[0065] In this embodiment, after preprocessing, the parent class of the class HomeOpenUrlActivity is BaseActivity, and the interface is SwipeRefreshLayout$j. The constructor and composition method are filtered out, while the method L1(Lcom / ... / HomePosterAndMaterial;)V is retained. The parameter type is abstracted to X, and the return type is V.
[0066] Step 2: Class-level alignment based on dynamic programming algorithm, specifically including:
[0067] 2.1 Taking the preprocessed information of two versions as input, first sort the two versions of the obfuscation class set by the lexicographical order of the obfuscation name to obtain two class sequences, such as... Figure 2 As shown;
[0068] 2.2 Identify the class whose feature hash is unique in its respective version and has the same value in both versions as the anchor class, and use it as the boundary to divide the sequence into local intervals, such as... Figure 3 As shown;
[0069] 2.3 Generate confusion-invariant feature strings for each class within each interval, construct a similarity matrix by performing CTPH fuzzy hashing and calculating Levinstein distance, and obtain the matching path by solving LCS using dynamic programming;
[0070] 2.4 Sentence refinement is performed on candidate matching groups outside of LCS by calling LLM.
[0071] In this embodiment, the class-level alignment results are as follows: Added classes include PngjUnsupportedException, bolts.a, HomeOpenUrlActivity, etc.; Deleted classes include abab$a$a, abac, etc.; Matching class pairs include abaa→dbaa, abaa$a→dbaa$a, fliw0.s0→com.xvideostudio.videoeditor.tool.h0, etc.
[0072] Step 3: Method-level alignment based on confusion awareness, specifically including:
[0073] 3.1 Fine-grained alignment and change detection are performed on the method entities in each matching class pair obtained by class-level alignment. For unobfuscated methods, the instruction sequence hash is compared after a one-to-one mapping between the name and the complete descriptor to determine whether they are completely identical or similar. For obfuscated methods, the normalized method descriptor and the instruction sequence are concatenated to generate a representative feature string. After generating a fuzzy fingerprint using CTPH, the normalized similarity is compared to determine whether they are completely identical, similar, newly added, or deleted.
[0074] In this embodiment, taking the matching class pair fliw0.s0→com.xvideostudio.videoeditor.tool.h0 as an example: the method pair ()V close -> ()V close and the method pair ()Ln / y; b -> ()Ln / v; c have a normalized similarity of 1, and are judged to be completely identical; the method pair ()Ljava / lang / String; toString -> ()Ljava / lang / String; toString has undergone logical modification but its normalized similarity is greater than the threshold, and is judged to be similar; the methods (Ln / c; J)Va and (Lorg / json / JSONArray; Landroid / webkit / WebView;)V b did not have a corresponding method entity with a normalized similarity value greater than the threshold in the old version, and are judged to be newly added; there are no deleted methods.
[0075] Step 4: Security testing based on differential reports, specifically including:
[0076] 4.1 Incremental risk screening based directly on differential reports: The Added class list in the differential report records a class HomeOpenUrlActivity, which contains an obfuscated method v1(). Another matching class com.xvideostudio.videoeditor.tool.h0 contains a newly added method b().
[0077] 4.2 When parsing the feature string of v1(), the WebView configuration API call setJavaScriptEnabled(true) was matched, and this method was marked as "enabling JavaScript execution" behavior according to the rule library. When parsing the feature string of b(), it was identified that it contained a reference to the TelephonyManager type and a call to the getDeviceId() method. According to the rule library, this was marked as "reading device unique identifier" behavior and classified as high-risk privacy data acquisition.
[0078] 4.3 Output the two alarms separately, along with their respective class names, method names, and characteristic contexts. Security analysts can locate the newly added code in HomeOpenUrlActivity.v1() and h0.b() based on the report. Combining their calling relationship (e.g., a data leakage chain can be formed through the WebView bridging mechanism), further dynamic verification or manual review can be performed.
[0079] In this process, the detection tool does not need to recompile the entire code; it only needs to process the incremental parts explicitly indicated in the differential report. Furthermore, thanks to the method's ability to accurately identify new and modified methods even in obfuscated environments, the system can reliably extract semantic features and trigger rule matching even though v1() and b() are both obfuscated names. This fully demonstrates that the differential report generated by this method provides a precise and efficient incremental data foundation for downstream automated security detection, significantly reducing security response time and manual workload.
[0080] Through practical application scenario experiments, under a hardware and software environment of 64-bit Ubuntu 20.04LTS operating system, Python 3.12 runtime environment, and Androguard 4.12 parsing library, 64 open-source Android applications were used as test objects (covering 228 versions and 164 pairs of adjacent version combinations, of which 20 applications, 97 versions, and 77 pair of version combinations came from the F-Droid open-source store and were all obfuscated with R8 to verify anti-obfuscation capabilities). Statistics were compiled by adding / deleting / matching entities, containing 11927 / ... The dataset contains 10452 / 159611 classes and 50919 / 35359 / 612526 methods; the remaining 44 applications, 131 versions, and 87 version combinations are from the publicly available APKDiffer benchmark dataset, used to verify generalization ability (corresponding to 6655 / 8995 / 48596 classes and 39296 / 54878 / 234898 methods for added / deleted / matched entities, respectively). The method, based on difference, is used to run the Android application cross-version anti-obfuscation detection method of this invention. In the experiment, the class-level matching similarity threshold... Set to 0.6, method-level matching similarity threshold Tuning was performed based on experimental experience. Classes and methods were divided into three categories: addition, deletion, and matching. Precision (P), recall (R), and F1 score were used as evaluation indicators. The results are shown in Tables 1 and 2. The efficiency comparison with existing technologies is shown in Table 3.
[0081] Table 1 provides a quantitative comparison of the difference performance between the current state-of-the-art techniques (based on all method entities in the dataset).
[0082] Table 2 Comparison of Class-Level and Method-Level Differential Performance and Ablation Experiment Results (Precision P / Recall R / F1 Score)
[0083] Table 3 Comparison of operating efficiency with existing technologies (seconds)
[0084] Where Q1, median, and Q3 represent the average time spent in the 25th, 50th, and 75th scale tiers, respectively, based on the number of method entities involved in a single analysis, with the number of methods in parentheses representing that tier; the average column represents the average time spent for all test cases.
[0085] Compared with existing technologies, the advantages of this method include:
[0086] 1. Class-level alignment (anchor point partitioning and LCS structure alignment): This method utilizes the order-preserving property of R8 deterministic renaming for anchor point partitioning and adopts global LCS alignment based on dynamic programming. Compared with the local greedy matching of the existing technology MatchScope, the class-level matching F1 score is improved from 89.4% to 96.7%, an improvement of 7.3 percentage points; the F1 score for newly added class recognition is improved from 71.2% to 79.7%, an improvement of 8.5 percentage points; and the F1 score for deleted class recognition is improved from 70.0% to 78.3%, an improvement of 8.3 percentage points.
[0087] 2. Method-level alignment (normalized fingerprint and LLM semantic correction): The F1 score for newly added methods was improved from 35.6% in MatchScope to 67.3%, an increase of 31.7 percentage points; the F1 score for deleted methods was improved from 39.4% to 70.8%, an increase of 31.4 percentage points.
[0088] 3. Performance: The average time for a complete analysis without LLM is 52.2 seconds, which is lower than MatchScope's 66.2 seconds and much lower than ApkDiffer's 1,248.2 seconds. Only with very large binary inputs does the time taken exceed that of MatchScope's local heuristic due to the computational complexity of global LCS matching, which is an acceptable trade-off.
[0089] The above-described specific implementations can be partially adjusted by those skilled in the art in different ways without departing from the principles and purpose of the present invention. The scope of protection of the present invention is defined by the claims and is not limited to the above-described specific implementations. All implementation schemes within the scope of the claims are bound by the present invention.< / init>
Claims
1. A method for cross-version anti-obfuscation detection of Android applications based on differential mapping, characterized in that, include: Step 1: Android binary file preprocessing and analysis; Step 2: Use a class-level alignment algorithm based on dynamic programming to accurately map the confused class entities in the processing results of Step 1; Step 3: For the method entities within the matched classes in the class analysis result file obtained in Step 2, perform fine-grained alignment and change detection in sequence. Adopt differentiated processing strategies based on whether the methods are obfuscated. Finally, merge and output a differential report including class level and method level.
2. The method for cross-version anti-obfuscation detection of Android applications based on differential recognition according to claim 1, characterized in that, Step one, as described above, specifically includes: 1.1 Perform multi-level feature extraction across three dimensions: Use reverse engineering tools to unpack, disassemble, and extract code information from the two input Android application installation package files APK1 and APK2 respectively; The three dimensions mentioned include: metadata recovery, static cross-referencing, and the assembly representation of Android bytecode instruction sequences; 1.2 Character Mapping Normalization: Remapping logic is performed on non-standard Unicode characters generated during the R8 code obfuscation process when building APKs, mapping such characters to areas that can be processed normally. By eliminating ambiguity at the encoding level, this effectively prevents decoding crashes or inconsistent string hashes that may occur when decompilation engines process deeply obfuscated APKs, ensuring the robustness of the analysis process. 1.3 Logic Focus Pruning: First, filter out the helper classes and methods automatically generated by the compiler during APK construction, and then clean up empty entities that do not contain any valid logical instructions and resource index classes that are unrelated to business logic, so as to accurately focus limited computing resources on the core business logic of the application; 1.4 Instruction Abstraction Processing: Perform abstraction processing on all Smali instruction streams retained in step 1.3 to eliminate surface and volatile features in the code that are unrelated to functional logic in order to construct an obfuscated and invariant instruction pattern.
3. The method for cross-version anti-obfuscation detection of Android applications based on differential recognition according to claim 2, characterized in that, Step 1.1 specifically includes: 1) Unpacking: Read and decompress APK1 and APK2 respectively to obtain AndroidManifest.xml, DEX file and application resource file. DEX file is the executable code file of Android application. Further read application metadata such as package name and component information in AndroidManifest.xml, and determine the code file to be analyzed based on the DEX file contained in APK. 2) Disassembly: Disassemble the DEX files in APK1 and APK2 respectively, convert the Dalvik bytecode in the DEX files into analyzable Smali instruction form, and obtain the classes, methods and their corresponding bytecode instruction sequences in the application; 3) Code Information Extraction: Class-level and method-level information are extracted from the disassembled code of APK1 and APK2 respectively. Class-level information includes class name, access flags, parent class, implemented interfaces, fields, and methods. Method-level information includes method name, method descriptor, access flags, and the corresponding Smali instruction sequence. Further, based on the subordinate relationship between the extracted classes and methods, the method information is associated with its class, forming a code information set organized by class, which serves as the input for subsequent code feature construction and cross-version code matching.
4. The method for cross-version anti-obfuscation detection of Android applications based on differential recognition according to claim 2, characterized in that, Step 1.4 specifically includes: 1.4.1 Replace all the specific register indices in the instructions obtained in step 1.3 with generic placeholders that do not distinguish between numbers, i.e., vX represents a local register and pY represents a parameter register; thereby eliminating the influence of the register allocation scheme on the instruction mode. 1.4.2 The immediate values contained in the instructions obtained in step 1.3 are de-sensitized, that is, the immediate values contained in the instructions are uniformly replaced with a standard marker to ignore the differences in specific values. The instruction abstraction process retains the core logical skeleton composed of opcode sequences and control flow by abstracting, while ignoring the differences in register allocation or changes in local constants that may occur under different compilation environments due to compiler optimization and obfuscator rule settings. This significantly enhances the resistance to minor instruction scheduling and rearrangement behaviors performed by obfuscators such as R8 that do not change the semantics, thus providing a stable and reliable input foundation for subsequent feature extraction and similarity comparison based on fuzzy hashing.
5. The method for cross-version anti-obfuscation detection of Android applications based on differential recognition according to claim 1, characterized in that, Step two, specifically include: 2.1 Class order reconstruction based on deterministic sorting of obfuscator: After extracting the complete class entity lists of APK1 and APK2 from the preprocessing results of step one, sort them lexicographically by obfuscation name and convert them into two class sequences with stable relative positional relationships. 2.2 Anchor-assisted search space partitioning: Extract anchor classes from the two class sequences obtained in step 2.1 as boundaries, and cut the full class sequence obtained in step 2.1 into multiple small local intervals; 2.3 Structural alignment based on longest common subsequence: Perform precise structural alignment based on LCS within each local interval; 2.4 Semantic Refinement and Correction Based on LLM: For the candidate matching groups obtained after structural alignment in step 2.3, semantic reasoning based on LLM is performed.
6. The method for cross-version anti-obfuscation detection of Android applications based on differential recognition according to claim 5, characterized in that step 2.2 specifically includes: 2.2.1 Calculate the fuzzy hash value of the obfuscated invariant feature string for each obfuscation class. If a certain hash value appears only once in all obfuscation classes of APK1 and only once in all obfuscation classes of APK2, and the values are the same in both versions, then the corresponding two classes are identified as anchor classes. 2.2.2 Using the anchor class as the boundary, the sorted class sequences of APK1 and APK2 are divided into non-overlapping local intervals between adjacent anchor classes. Subsequently, class-level matching is only performed within the corresponding local intervals. The obfuscated invariant characteristic strings include: 1) Field information: access flags and descriptors of each field; 2) Interface implementation relationship: type name of each interface; 3) Parent class inheritance relationship: type name of the parent class; 4) Method information: descriptors of each method; 5) Constant string sequence: string constants loaded by const-string instructions within the method, where type abstraction refers to uniformly replacing all user-defined types that do not belong to the Android SDK with placeholders "X".
7. The method for cross-version anti-obfuscation detection of Android applications based on differential mapping as described in claim 5, characterized in that, Step 2.3 specifically includes: 2.3.1 Generate a comprehensive obfuscation-invariant feature string for each class within the local interval; 2.3.2 After generating a fuzzy hash value for the obfuscated invariant feature string using context-triggered segmented hashing, the Levinstein distance between the CTPH hash values of the two classes is calculated to quantify their structural differences. For any class pair within the corresponding local interval of the two versions, the similarity score matrix is obtained through pairwise calculations. Specifically: Where: h1 and h2 are the CTPH fuzzy hash values of the two classes in APK1 and APK2, respectively; lev(h1,h2) is the Levenstein distance between them; |h| represents the length of the hash value; This indicates that the larger value is taken; Sim(h1,h2) is the normalized structural similarity score between the two classes, with a value between 0 and 1; 2.3.3 The longest common subsequence is found in the similarity score matrix using a dynamic programming algorithm, which is to find the matching path that runs through the matrix and maximize the cumulative similarity of all matching pairs on the path. Specifically, a matching function is defined. Match returns 1 if a match is found, and 0 otherwise. Here, Match(h1,h2) is the matching function. To normalize the threshold, the dynamic programming table is filled with this matching function and the optimal LCS path is extracted by backtracking. Class pairs on the path are determined to be matched classes. Classes that are determined to be matched but do not enter the path are marked as "candidate matches" and handed over to subsequent semantic refinement processing. The remaining classes that are not determined to be matched are classified according to their version, i.e., if they exist in APK2 but not in APK1, they are classified as newly added classes, or vice versa.
8. The method for cross-version anti-obfuscation detection of Android applications based on differential recognition according to claim 5, characterized in that, Step 2.4 specifically includes: 2.4.1 Extract and format a rich set of contextual information for each pair of candidate classes from APK1 and APK2, including the decompiled Java pseudocode of the class, the key API call sequence of the main methods in the class, and the field definitions, inheritance relationships and internal class structure of the class; 2.4.2 This information is structured into a specific prompt word and submitted to the LLM for judgment: The prompt word requires the LLM to get rid of its dependence on the surface characters and structure of the code, and to judge whether the two given candidate classes represent the evolution of the same functional entity in different versions from the perspective of functional intent and logical behavior; The prompts include: 1) Task instructions: requiring the LLM to determine whether two candidate classes correspond to the same functional entity across versions based solely on functional logical equivalence; 2) Context information: decompiled Java pseudocode of the two candidate classes, key API call sequences of main methods, field definitions, inheritance relationships, and inner class structures; 3) Output constraints: requiring the LLM to output the matching judgment and provide a brief basis. The aforementioned judgment refers to the following: when the LLM determines that the two are logically equivalent in function, the tool will determine that the two classes are matching classes and record this association in the final difference mapping table.
9. The method for cross-version anti-obfuscation detection of Android applications based on differential recognition according to claim 1, characterized in that, Step three specifically includes: 3.1 The newly added classes, deleted classes, and matched classes obtained in step two form a class level, and multiple independent classes are cascaded together to form a method level for the analyzed paragraphs; Each paragraph in the method hierarchy corresponds to a set of internal method comparison results of matched classes, including: completely identical: methods in APK1 and APK2 that have not undergone logical changes; similar: methods that are determined to be the same method, but whose internal underlying code logic has been modified; newly added: method entities that exist in APK2 but not in APK1; deleted: method entities that exist in APK1 but not in APK2. 3.2 Direct Identifier Mapping for Unobfuscated Methods: For method entities in each paragraph of the method hierarchy obtained in step 3.1 that have retained their original names without obfuscation, a one-to-one precise mapping is first performed based on the complete descriptors of the method name, parameter types, and return values. Methods for which no mapping can be found are classified as newly added or deleted in the global report according to their version. After the mapping is completed, the instruction sequence hash values of the two versions of the method are compared. If the hash values are completely identical, they are determined to be completely identical; if they are inconsistent, they are determined to be similar. 3.3 Fingerprint synthesis and fuzzy matching using obfuscation methods, specifically including: 3.3.1 Extracting and Normalizing Method Descriptors That is, after extracting the original descriptor such as the return type and parameter list of the method, all user-defined types in the original descriptor are uniformly replaced with a general placeholder "X", and non-functional modifiers such as access flags are removed, so as to obtain a normalized descriptor string that only contains normalized type information and is immune to class name obfuscation; 3.3.2 The instruction sequence obtained in step one is preprocessed to generate an instruction sequence string. Specifically, this includes instruction abstraction, noise instruction filtering, and control flow simplification, resulting in an instruction sequence string that represents the core logic of the method and is insensitive to register allocation and minor scheduling. 3.3.3 Normalize the descriptor string With instruction sequence string Two strings are concatenated sequentially to generate a representative feature string. Then, use CTPH as Generate fuzzy fingerprints and calculate the normalized similarity score Sim( ) between the two fingerprints to be compared. 1, 2), and then compare the similarity score with the empirically optimized threshold. The comparison is performed. A similarity score of 1 is considered to be completely identical. A score less than 1 but not lower than the threshold is considered to be similar. A score lower than the threshold is classified as newly added or deleted in the global report according to its version. The representative feature string ; 3.4 Incremental State Establishment and Conflict Handling: Verify whether conflicting candidate matching pairs have the same or adjacent ordinal indices in their respective classes. By combining this ordinal consistency with the aforementioned semantic similarity score, the most likely unique correct match can be effectively analyzed, thus resolving ambiguity conflicts and ensuring that each method is assigned at most one most reasonable corresponding state. Specifically: when there may be multiple fuzzy matching results for similar method pairs, ordinal consistency is used as a hard constraint, retaining only those with the same or adjacent ordinal indices. Candidate matching pairs; if conflicts still exist after filtering, the best candidate is selected from the remaining candidates based on the normalized similarity score of 3.3, and the one with the highest score is selected as the unique match, ensuring that each method is assigned at most one corresponding state. The sequence index refers to the declaration sequence number of the method in its class entity. 3.5 Generate Final Report: Summarize the aforementioned class-level matching results with the method-level comparison results of each matching class pair, and output a differential report file with the suffix xx.match. The report includes: class-level matching results, i.e., a list of class entities in three states: newly added class, deleted class, and matched class, and the correspondence between each pair of matched classes in the two versions; and method-level matching results, i.e., the method comparison results within each pair of matched classes, including four states: completely identical, similar, newly added, and deleted. The differential report serves as input for downstream security detection tools or manual analysts to conduct incremental risk screening.
10. An Android application cross-version anti-obfuscation detection system implementing the method of any one of claims 1-9, characterized in that, include: The system includes a preprocessing unit, a class-level alignment unit, a method-level alignment unit, and a report generation unit. The preprocessing unit is used to perform unpacking and decompiling, character mapping normalization, logic focus pruning, and instruction abstraction processing on the installation package files of the two Android applications to be compared, in order to obtain the corresponding preprocessed information file. The class-level alignment unit is used to deterministically sort the two versions of the obfuscated class sets according to the obfuscation name based on the preprocessed information file, divide them into local intervals with the anchor class as the boundary, perform structural alignment based on LCS within the intervals, and perform semantic refinement and correction on the candidate matching groups based on LLM, to obtain a class analysis result file containing the status of newly added classes, deleted classes, and matching classes; the method-level alignment unit is used to perform direct identifier mapping on non-obfuscated methods, fingerprint synthesis and fuzzy matching on obfuscated methods based on the matching class pairs in the class analysis result file, and perform conflict handling in combination with order consistency, to obtain the method entity comparison results of completely identical, similar, newly added, and deleted statuses within each matching class; the report generation unit is used to merge and output a differential report file with the suffix .match based on the class-level matching results and the method-level matching results.
