APP interface similarity calculation method based on structure and component
By combining the weighted average calculation of interface structure and component matching, it solves the problem of insufficient accuracy of interface similarity calculation under traditional methods, achieves more efficient malware detection, and avoids leakage of user information and property losses.
Patent Information
- Application Number
- CN202410800534.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-20
- Publication Date
- 2024-10-15
AI Technical Summary
The traditional APP interface similarity calculation method is only based on structural information and is difficult to accurately detect malware. Especially after the interface complexity increases and personalized themes become popular, the accuracy rate decreases and it is difficult to meet the detection needs.
The APP interface similarity calculation method based on structure and components is used to calculate the interface similarity through the weighted average of interface structure similarity and component matching, including interface preprocessing, tree edit distance calculation, and component text information extraction and matching calculation. , using techniques such as tree edit distance and WMD word embedding model.
It achieves more accurate interface similarity calculation, helps detectors identify malware, avoids leakage of user information and property losses, and improves detection results.
Smart Images

Figure CN118779847A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of software engineering, and in particular to a method for calculating the similarity of APP interfaces based on structures and components. Background Art
[0002] As the scale of the computer software industry gradually expands and the complexity of programs continues to increase, a large number of malware that imitates genuine software has appeared on the market. Malware makers often imitate popular software with a large user base and design interfaces that are highly similar to genuine software to deceive users and induce them to enter various sensitive privacy information to carry out fraudulent activities. Because these malware are deliberately designed to be difficult to distinguish from genuine software, traditional detection methods based on signatures or behavioral analysis are not ideal.
[0003] APP interface similarity calculation can effectively detect malware. If the interface layout, icons, text, etc. of a software are highly similar to those of a well-known genuine software, it is very likely that it is imitating the software to carry out malicious activities. Systematic comparative analysis of these interfaces can better identify such malware. Traditional interface similarity calculation methods are mostly based on the structural information of the APP interface, and judgment is made by comparing the relative position and type of components. With the increase in the types and number of APPs, more and more APPs adopt personalized interface themes, and the interface complexity is also increased accordingly. The accuracy of traditional interface similarity calculation methods has gradually decreased, and it is difficult to meet the interface similarity matching problem in the test sample generation process.
[0004] This patent not only considers the similarity relationship between interface structures, but also considers the matching degree between components in the interface during the calculation process, breaking the limitation of traditional research process that only relies on structure to derive interface similarity. It can make the calculation results more accurate and assist detection personnel to better find malicious imitation software. Summary of the invention
[0005] In order to solve the problems existing in the background technology, the present invention proposes a method for calculating the similarity of APP interfaces based on structure and components, and the method includes:
[0006] A method for calculating APP interface similarity based on structure and components, characterized in that the method performs interface structure similarity calculation and component matching similarity calculation on two App interfaces to obtain the structural similarity and component matching between the interfaces, and obtains the interface similarity by weighted average of the structural similarity and component matching.
[0007] Furthermore, the method comprises the following steps:
[0008] S1, calculation of interface structure similarity; by preprocessing the interface, the layout tree is abstracted into a tree with different labeled nodes, and the tree edit distance between the two layout trees is calculated to obtain the structural similarity between the interfaces;
[0009] S2, component matching calculation; first, filter out the effective information of the component, and extract and preprocess the text information therein; then calculate the text similarity between all components in the two interfaces, and calculate their best match to find the most matching component in the interface; finally, weight the text similarity between all the most matching components as the component matching between the interfaces;
[0010] S3, weighted average structural similarity and component matching to obtain interface similarity.
[0011] Furthermore, the interface preprocessing in step S1 specifically includes:
[0012] S11, classify and mark the components according to class type: "FrameLayout" and "LinearLayout" container type components are marked as A, "ImageView" type components are marked as B, and "TextView" type components are marked as C;
[0013] S12, replacing the components in the layout tree with nodes with corresponding marks.
[0014] Furthermore, the tree edit distance in step S1 is a method for measuring tree structure similarity, which is defined as the minimum number of operations required to transform one tree into another tree through operations between nodes, and the node operations include insertion, deletion and conversion. After calculating the tree edit distance between the interface layout trees after the two interfaces are abstracted, step S1 divides the tree edit distance by the sum of the number of components in the two interfaces to obtain the result as the structural similarity between the interfaces.
[0015] Furthermore, the valid information in step S2 is appropriate attributes in the component, and the appropriate attributes include four attributes of resource-id, hint, content-desc, and text in the component.
[0016] Furthermore, the extraction of text information from component attributes in step S2 specifically includes the following steps:
[0017] S201, for the resource-id attribute, use a regular expression to extract the content after " / ", and for other text attributes, retain all information of the text attributes;
[0018] S202, concatenating the text information of all attributes into strings to obtain text information representing the component;
[0019] Furthermore, the step S2 of preprocessing the text information specifically includes:
[0020] S211, removing irrelevant symbols: removing irrelevant symbols such as punctuation marks and separators in the text information by using regular expressions;
[0021] S212, word segmentation: first, the words in the text information need to be segmented according to spaces. For the resource-id attribute, a combined word is used to describe the component information. Specifically, the word is usually composed of multiple words in the manner of upper camel case naming, lower camel case naming, and separator combination; for the word, it is necessary to manually segment it;
[0022] S213, remove stop words: use the stopwords library in the nltk library to match and remove stop words;
[0023] S214, removing invalid phrases: maintaining an invalid phrase list for removing invalid phrases.
[0024] Furthermore, the step S2 of calculating the component matching degree specifically includes the following steps:
[0025] S221, if the component is located at a leaf node in the layout tree, mark the component as a leaf component; if the component is located at a non-leaf node in the layout tree, mark the component as a non-leaf component;
[0026] S222, extracting text information from each component and preprocessing it;
[0027] S223, for each component in an interface A, calculating the type similarity classSim between the interface A and all components in another interface B, wherein if the class attributes of the two components are the same, classSim is 1, and if the class attributes of the two components are different, classSim is 0;
[0028] S224, for each component in interface A, calculating the semantic similarity semanticSim between interface A and all components in interface B, where semanticSim is calculated by using the Google-Play corpus through the WMD word embedding model;
[0029] S225, for each component in interface A, calculate the component matching degree nodeSim between interface A and all components in interface B. The formula of component matching degree nodeSim is:
[0030]
[0031] S226, after the calculations in steps S223-S225, the component matching degree between all components between the two interfaces can be obtained, and the best bipartite graph matching is calculated for the components in the two interfaces by using the Hungarian algorithm;
[0032] S227, for the best bipartite graph matching, add the weights of all matching edges and divide the sum by the smaller value of the number of components in the two interfaces to obtain the component matching degree between the two interfaces.
[0033] The present invention adopts the above technical solution to obtain the following beneficial effects:
[0034] The present invention realizes a technology for accurately calculating the similarity between different application interfaces from two aspects: structural similarity and component matching. This technology can help detection personnel better find malicious plagiarism software and avoid users' personal information leakage or property loss. Compared with the existing interface similarity calculation technology, the present invention not only considers the similarity relationship between interface structures, but also considers the matching degree between components in the interface during the calculation process, which can make the similarity calculation result more accurate. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 The figure is an overall framework diagram of the method for calculating the similarity of APP interfaces based on structures and components according to an embodiment of the present invention.
[0036] Figure 2 The diagram is a schematic diagram of an abstracted interface layout tree according to an embodiment of the present invention. DETAILED DESCRIPTION
[0037] The present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0038] The present invention provides a method for calculating the similarity of APP interfaces based on structure and components, such as Figure 1 As shown, Figure 1 The overall framework diagram of the APP interface similarity calculation method based on structure and components in the embodiment of the present invention is as follows. The method of the present invention performs interface structure similarity calculation and component matching similarity calculation on two App interfaces, obtains the structural similarity and component matching between the interfaces respectively, and then obtains the interface similarity by weighted average structural similarity and component matching. The specific steps of this method include:
[0039] S1, calculation of interface structure similarity; through preprocessing of the interface, the layout tree is abstracted into a tree with different labeled nodes, and the tree edit distance between the two layout trees is calculated to obtain the structural similarity between the interfaces.
[0040] S11, interface preprocessing:
[0041] The interface of a mobile application is defined through a layout file (XML file). Its mechanism requires developers to use a tree data structure to define the hierarchy of the interface layout, which is called a layout tree. In the layout tree, each component is mapped to an XML element. The component contains multiple attributes, among which the class attribute indicates the type of the component. Even for different applications, the classes used by their components are the same. For example, ImageView represents an image type component, TextView represents a text type component, and EditText represents an input type component.
[0042] In the interface preprocessing stage, the method abstracts the layout tree into a tree with different marked nodes. The interface preprocessing specifically includes the following steps:
[0043] S101 classifies and marks components according to class type: container-type components ending with "Layout" are marked as A, "ImageView"-type components are marked as B, and "TextView"-type components are marked as C.
[0044] S102 replaces the components in the layout tree with nodes with corresponding marks.
[0045] The structure of the abstracted layout tree is as follows Figure 2 shown.
[0046] S12, interface structure similarity calculation:
[0047] The tree edit distance in step S1 is a method for measuring the similarity of tree structures, which is defined as the minimum number of operations required to transform one tree into another tree through operations between nodes, wherein the node operations include three types:
[0048] Insert: insert a node into a tree;
[0049] Delete: delete a node from a tree;
[0050] Transformation: Transform a node in a tree into another node.
[0051] This embodiment first calculates the tree edit distance between the interface layout trees after the two interfaces are abstracted, and then divides the tree edit distance by the sum of the number of components in the two interfaces to obtain the structural similarity between the interfaces.
[0052] S2, component matching calculation; in the component matching calculation process, this embodiment first needs to select appropriate attribute information in the component and extract the text information therein for preprocessing; then calculate the matching between all components in the two interfaces, and calculate the best bipartite matching for the components in the two interfaces; the weight of the edge in the bipartite matching is used as the component matching between the interfaces.
[0053] S21, component attribute selection:
[0054] A component usually contains a lot of attribute information, including the attributes of text information and their functions are as follows:
[0055] resource-id: component identifier, used to locate the component;
[0056] hint: A text description of a component, used for editable components to help users fill in the correct content;
[0057] content-desc: The invisible text description of the component, often used to describe the component function to visually impaired users;
[0058] activity-name: The Java type of the current screen, which can be used to infer the function of the screen;
[0059] text: The text content displayed by the component.
[0060] Among them, all components in an interface have the same activity-name, so this attribute has the side effect of distinguishing different components in the same interface. Although the hint attribute and content-desc attribute are empty in many components, they contain important information that can describe the function of the component, so they cannot be ignored; finally, this embodiment decides to select the resource-id, hint, content-desc, and text attributes in the component to preprocess the text information.
[0061] S22, component text information preprocessing:
[0062] For the attributes in the component, it is necessary to select the appropriate part to extract and preprocess it.
[0063] The format of resource-id is different from other text attributes. It consists of package name + ":id" + " / " + identifier representing id. Since the package name does not contain the component information itself but is an identifier of the application attribute, for the resource-id attribute, you need to use a regular expression to extract the content after " / ", while other text attributes retain all their information. Then, the text information of all attributes is concatenated to get the text information representing the component.
[0064] After that, the text information needs to be preprocessed. The preprocessing includes four parts: removing irrelevant symbols, word segmentation, removing stop words, and removing invalid phrases:
[0065] Removing irrelevant symbols: This embodiment removes punctuation marks, separators, and special characters in text information through regular expressions.
[0066] Word segmentation: First, the words in the text information need to be segmented according to spaces. For the resource-id attribute, compound words are usually used to describe component information. Specifically, the words are usually composed of multiple words in upper camel case naming, lower camel case naming, and separator combination. Therefore, for these words, the method needs to manually segment them.
[0067] Remove stop words: In English words, some phrases do not contain actual meaning compared with other words. At the same time, these words appear more often in the sentence, which will affect the results of subsequent processing; for example, "the", "a", "an", "that", "over", "under", etc., these words are called stop words; for text information, this embodiment uses the stopwords library in the nltk library to match and remove stop words.
[0068] Removing invalid phrases: In component properties, some abbreviation phrases usually appear, such as btn, which is used to indicate that the element is a Button type component, iv, which is an ImageView type component, and et, which is an EditText type component. These phrases are not included in the text library, so errors may occur when calculating the semantic similarity of the text. This embodiment maintains an invalid phrase list for removing these invalid phrases.
[0069] S23, component matching calculation:
[0070] The Word Mover's distance (WMD) word embedding model is a method for measuring text similarity proposed in 2015. It does not rely on labeled data and only requires the result of word vector as input without any hyperparameters. The AppsDescriptions (Google-Play) corpus is a large-scale text dataset created by Google, containing English descriptions of 900,805 Android applications in the Google Play Store.
[0071] For two interfaces A and B, the method calculates the component matching degree using the following method.
[0072] S231, if the component is located at a leaf node in the layout tree, mark the component as a leaf component; if the component is located at a non-leaf node in the layout tree, mark the component as a non-leaf component;
[0073] S232, extracting text information and preprocessing for each component using the method in S22;
[0074] S233, for each component in interface A, calculating the type similarity classSim of all components in interface A and interface B, wherein if the class attributes of the two components are the same, classSim is 1; if the class attributes of the two components are different, classSim is 0;
[0075] S234, for each component in interface A, calculating the semantic similarity semanticSim between interface A and all components in interface B, where semanticSim is calculated by using the Google-Play corpus through the WMD word embedding model;
[0076] S235, for each component in interface A, calculate the component matching degree nodeSim between interface A and all components in interface B. The component matching degree nodeSim formula is:
[0077]
[0078] S236, after the above calculation, the component matching degree between all components between the two interfaces can be obtained. The best bipartite graph matching is calculated for the components in the two interfaces by using the Hungarian algorithm;
[0079] S237, for the best bipartite graph matching, the weights of all matching edges are added together and divided by the smaller value of the number of components in the two interfaces, which is the component matching degree between the two interfaces.
[0080] S3, after obtaining the structural similarity and component matching in steps S1 and S2, the similarity between the interfaces can be obtained by weighted average calculation.
[0081] The above is only a preferred embodiment of the present invention, but the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention. Any simple modification, equivalent changes and modifications made to the above embodiments by any technician familiar with the profession according to the technical essence of the present invention without departing from the principle and spirit of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for calculating APP interface similarity based on structure and components, characterized in that: This method calculates the interface structure similarity and component matching similarity of two App interfaces to obtain the structural similarity and component matching between the interfaces, and obtains the interface similarity by weighted average of the structural similarity and component matching.
2. The method for calculating APP interface similarity based on structure and components according to claim 1 is characterized in that: The method comprises the following steps: S1, calculation of interface structure similarity; by preprocessing the interface, the layout tree is abstracted into a tree with different labeled nodes, and the tree edit distance between the two layout trees is calculated to obtain the structural similarity between the interfaces; S2, component matching calculation; first, filter out the effective information of the component, and extract and preprocess the text information therein; then calculate the text similarity between all components in the two interfaces, and calculate their best match to find the most matching component in the interface; finally, weight the text similarity between all the most matching components as the component matching between the interfaces; S3, weighted average structural similarity and component matching to obtain interface similarity.
3. The method for calculating APP interface similarity based on structure and components according to claim 1 or 2, characterized in that: The interface preprocessing step S1 specifically includes: S11, classify and mark the components according to class type: "FrameLayout" and "LinearLayout" container type components are marked as A, "ImageView" type components are marked as B, and "TextView" type components are marked as C; S12, replacing the components in the layout tree with nodes with corresponding marks.
4. The method for calculating APP interface similarity based on structure and components according to claim 1 or 2, characterized in that: The tree edit distance in step S1 is a method for measuring tree structure similarity, which is defined as the minimum number of operations required to transform one tree into another tree through operations between nodes, and the node operations include insertion, deletion and conversion. After calculating the tree edit distance between the interface layout trees after the two interfaces are abstracted, step S1 divides the tree edit distance by the sum of the number of components in the two interfaces to obtain the result as the structural similarity between the interfaces.
5. The method for calculating APP interface similarity based on structure and components according to claim 2 is characterized in that: The valid information in step S2 is the appropriate attributes in the component, and the appropriate attributes include the four attributes of resource-id, hint, content-desc, and text in the component.
6. The method for calculating APP interface similarity based on structure and components according to claim 2 is characterized in that: The extraction of text information from component attributes in step S2 specifically includes the following steps: S201, for the resource-id attribute, use a regular expression to extract the content after " / ", and for other text attributes, retain all information of the text attributes; S202, concatenating the text information of all attributes into strings to obtain text information representing the component.
7. The method for calculating APP interface similarity based on structure and components according to claim 2, characterized in that: The step S2 of preprocessing the text information specifically includes: S211, removing irrelevant symbols: removing irrelevant symbols such as punctuation marks and separators in the text information by using regular expressions; S212, word segmentation: first, the words in the text information need to be segmented according to spaces. For the resource-id attribute, a combined word is used to describe the component information. Specifically, the word is usually composed of multiple words in the manner of upper camel case naming, lower camel case naming, and separator combination; for the word, it is necessary to manually segment it; S213, remove stop words: use the stopwords library in the nltk library to match and remove stop words; S214, removing invalid phrases: maintaining an invalid phrase list for removing invalid phrases.
8. The method for calculating APP interface similarity based on structure and components according to claim 1 or 2, characterized in that: The step S2 of calculating the component matching degree specifically includes the following steps: S221, if the component is located at a leaf node in the layout tree, mark the component as a leaf component; if the component is located at a non-leaf node in the layout tree, mark the component as a non-leaf component; S222, extracting text information from each component and preprocessing it; S223, for each component in an interface A, calculating the type similarity classSim between the interface A and all components in another interface B, wherein if the class attributes of the two components are the same, classSim is 1, and if the class attributes of the two components are different, classSim is 0; S224, for each component in interface A, calculating the semantic similarity semanticSim between interface A and all components in interface B, where semanticSim is calculated by using the Google-Play corpus through the WMD word embedding model; S225, for each component in interface A, calculate the component matching degree nodeSim between interface A and all components in interface B. The formula of component matching degree nodeSim is: S226, after the calculations in steps S223-S225, the component matching degree between all components between the two interfaces can be obtained, and the best bipartite graph matching is calculated for the components in the two interfaces by using the Hungarian algorithm; S227, for the best bipartite graph matching, add the weights of all matching edges and divide the sum by the smaller value of the number of components in the two interfaces to obtain the component matching degree between the two interfaces.
