Method for obtaining obfuscated resources, intelligent terminal and computer-readable storage medium

By rewriting the getidentifier method in Android development, obtaining the identification information of confusing resources and indexing to confuse resources, solving the problem of incomplete resources caused by too much resource, optimized the resource acquisition process and reduced resource management costs.

CN114880632BActive Publication Date: 2025-01-24HANGZHOU TUYA INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210405339.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-18
Publication Date
2025-01-24
Estimated Expiration
2042-04-18

AI Technical Summary

Technical Problem

When the existing technology obtains resources through whitelists in Android development, too many resources lead to weakening of confusion, and the whitelist needs to be maintained manually for a long time, which is prone to errors and unknown problems.

Method used

By setting a custom subclass context and resource management class in the context class of the resource installation package, override the getIdentifier method to obtain the identification information of the obfuscated resource, and use the identification information to index the obfuscated resource.

Benefits of technology

In the case of ensuring that all resources are confused, obtain the corresponding resources after confusion through the rewrite GetIdentifier method, optimize the process of obtaining confusion resources, reduce resource management costs, and avoid the defects of the maintenance of the whitelist.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114880632B_ABST
    Figure CN114880632B_ABST
Patent Text Reader

Abstract

The present application discloses a method for obtaining obfuscated resources, an intelligent terminal, and a computer-readable storage medium, wherein the method for obtaining obfuscated resources is applied to a resource installation package, a custom subclass context is set in the context class of the resource installation package, and a custom subclass resource management file of a resource management class is set in the subclass context, and the method includes: before starting the getIdentifier method based on the context class, passing the subclass context into the first class object and the second class object of the context class to rewrite the getIdentifier method; based on the rewritten getIdentifier method, obtaining the identification information of the obfuscated resource; based on the identification information, obtaining the obfuscated resource. In the above manner, by setting the subclass resource management file in the subclass context to rewrite the getIdentifier method, when all resources are obfuscated, the corresponding resources after obfuscation can be obtained through the rewritten getIdentifier method, thereby optimizing the process of obtaining obfuscated resources and reducing resource management costs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of client development, and in particular to a method for obtaining obfuscated resources, an intelligent terminal, and a computer-readable storage medium. Background Art

[0002] In Android development, for security reasons and to reduce the size of the installation package, most Android applications will obfuscate resource names. However, in application development, it is inevitable that resources need to be obtained by their original names (for example, the resource names are not known but are sent over the network). The current common practice is to add these resources that need to be obtained by their original names to a whitelist. The resources in the whitelist will not be obfuscated and will retain their original names.

[0003] The current method of obtaining resources through whitelists has the problem that some resources will not be obfuscated. If there are too many resources in the whitelist, the significance of protecting resources through resource obfuscation will be weakened. In addition, the whitelist requires long-term manual maintenance, which is prone to errors and omissions, and may cause some unknown problems. Summary of the invention

[0004] To solve the above problems, the present application provides a method for obtaining obfuscated resources, an intelligent terminal and a computer-readable storage medium, which can optimize the process of obtaining obfuscated resources and reduce resource management costs.

[0005] A technical solution adopted in the present application is: providing a method for obtaining obfuscated resources, the method being applied to a resource installation package, wherein a custom subclass context is set in the context class of the resource installation package, and a custom subclass resource management file of a resource management class is set in the subclass context; the method comprises: before starting a getIdentifier method based on the context class, passing the subclass context into a first class object and a second class object of the context class to rewrite the getIdentifier method; based on the rewritten getIdentifier method, obtaining identification information of the obfuscated resource; and obtaining the obfuscated resource based on the identification information.

[0006] Among them, based on the overridden getIdentifier method, the identification information of the obfuscated resource is obtained, including: calling the getResource method in the subclass context to return the subclass resource management file; overloading the getIdentifier method in the subclass resource management file; and obtaining the identification information based on the overloaded getIdentifier method.

[0007] Among them, the identification information is the ID name of the obfuscated resource; based on the overwritten getIdentifier method, the identification information of the obfuscated resource is obtained, including: passing the original variable name, resource type and application package name of the obfuscated resource into the getIdentifier method to overload the getIdentifier method; based on the overloaded getIdentifier method, using the original variable name, resource type and application package name, reflectively calling the R.java class file to perform resource ID indexing; based on the result of the resource ID indexing, obtaining the ID name.

[0008] Among them, the original variable name, resource type and application package name are used to reflectively call the R.java class file to perform resource ID indexing, including: using the original variable name, resource type and application package name to reflectively call the mapping relationship table in the R.java file; based on the mapping relationship table, the resource ID corresponding to the original variable name is indexed.

[0009] Among them, the first type of object is the Application object, and the second type of object is the Activity object; before starting the getIdentifier method based on the context class, the subclass context is passed into the first type of object and the second type of object of the context class to rewrite the getIdentifier method, including: before starting the getIdentifier method based on the context class, creating an Application object and an Activity object; when initializing based on the Application object and the Activity object, calling the attachBaseContext method to pass the subclass context into the Application object and the Activity object to rewrite the getIdentifier method.

[0010] The method of obtaining the obfuscated resource based on the identification information includes: based on the identification information, indexing the path of the obfuscated resource in the resource management class to obtain the obfuscated resource.

[0011] Indexing the path of the obfuscated resource in the resource management class includes: indexing the path of the obfuscated resource in at least one of a string class file, a layout class file, or an image class file of the resource management class.

[0012] Among them, before this method, it also includes: obtaining a resource installation package; compiling the original resources in the resource installation package to generate a mapping relationship table between the identification information and the original variable names of the obfuscated resources; storing the mapping relationship table in the R.java class file; and obfuscating the original resources to form obfuscated resources.

[0013] Another technical solution adopted in the present application is: to provide an intelligent terminal, which includes a processor and a memory connected to the processor; wherein program data is stored in the memory, and the processor calls the program data stored in the memory to execute the method for obtaining obfuscated resources as described above.

[0014] Another technical solution adopted by the present application is: providing a computer-readable storage medium, in which program data is stored. When the program data is executed by a processor, it is used to implement the method for obtaining obfuscated resources as described above.

[0015] The method for obtaining obfuscated resources provided in the present application is applied to a resource installation package, wherein a custom subclass context is set in the context class of the resource installation package, and a custom subclass resource management file of a resource management class is set in the subclass context, and the method includes: before starting the getIdentifier method based on the context class, passing the subclass context into the first class object and the second class object of the context class to rewrite the getIdentifier method; based on the rewritten getIdentifier method, obtaining the identification information of the obfuscated resource; based on the identification information, obtaining the obfuscated resource. In the above manner, by setting a custom subclass resource management file in the custom subclass context to rewrite the getIdentifier method, it is possible to obtain the corresponding resources after obfuscation through the rewritten getIdentifier method while ensuring that all resources are obfuscated, thereby optimizing the process of obtaining obfuscated resources and reducing resource management costs. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. Among them:

[0017] Figure 1 It is a schematic diagram of an embodiment of file configuration in this application;

[0018] Figure 2 It is a flowchart of the first embodiment of the method for obtaining obfuscated resources provided by the present application;

[0019] Figure 3 It is a flowchart of an embodiment of step 11 in this application;

[0020] Figure 4 It is a flowchart of an embodiment of establishing a mapping relationship between the identification information of an obfuscated resource and the original variable name in the present application;

[0021] Figure 5 It is a flowchart of an embodiment of step 12 in this application;

[0022] Figure 6 This is a schematic diagram of a process for obtaining identification information in an embodiment of the present application;

[0023] Figure 7 This is a flowchart of an embodiment of resource ID indexing in this application;

[0024] Figure 8 It is a flowchart of a second embodiment of the method for obtaining obfuscated resources provided by the present application;

[0025] Fig. 9 A schematic diagram of the structure of a smart terminal provided for this application;

[0026] Fig.10 A schematic diagram of the structure of an embodiment of a computer-readable storage medium provided in this application. DETAILED DESCRIPTION

[0027] The scheme of the embodiment of the present disclosure is described in detail below with reference to the accompanying drawings.

[0028] In the following description, for the purpose of explanation rather than limitation, specific details such as specific system structures, processes, and technologies are set forth to facilitate a thorough understanding of the present application.

[0029] In conjunction with the drawings in the embodiments of the present disclosure, the technical solutions in the embodiments of the present disclosure are clearly and completely described. It is understandable that the specific embodiments described herein are only used to explain the present disclosure, rather than to limit the present disclosure. It should also be noted that, for ease of description, only parts related to the present disclosure, rather than all structures, are shown in the drawings. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present disclosure.

[0030] Reference to "embodiments" in this disclosure means that a particular feature, process, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the disclosure. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0031] The steps in the embodiments of the present disclosure do not necessarily have to be processed in the order of the described steps. The steps can be selectively rearranged, or the steps in the embodiments can be deleted, or the steps in the embodiments can be added as needed. The step descriptions in the embodiments of the present disclosure are only optional sequence combinations and do not represent all step sequence combinations in the embodiments of the present disclosure. The order of the steps in the embodiments cannot be regarded as a limitation of the present disclosure.

[0032] The term "and / or" in the embodiments of the present disclosure is only a description of the association relationship of the associated objects, and includes any and all possible combinations of one or more of the associated enumerated items, which indicates that there may be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in the present disclosure generally indicates that the objects associated before and after are in an "or" relationship. In addition, "many" in the present disclosure means two or more than two. In addition, the term "at least one" in the present disclosure means any combination of at least two of any one or more of a plurality of, for example, including at least one of A, B, and C, which can mean including any one or more elements selected from the set consisting of A, B, and C. It should also be noted that when used in the present disclosure, "include / comprise" specifies the existence of the stated features, integers, steps, operations, elements, and / or components, but does not exclude the existence or addition of one or more other features, integers, steps, operations, elements, and / or components and / or their groups.

[0033] The terms "first", "second", etc. in the embodiments of the present disclosure are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units that are inherent to these processes, methods, products, or devices.

[0034] In addition, although the terms "first", "second", etc. are used many times in the embodiments of the present disclosure to describe various operations (or various elements or various applications or various instructions or various thresholds), etc., these operations (or elements or applications or instructions or thresholds) should not be limited by these terms. These terms are only used to distinguish one operation (or element or application or instruction or threshold) from another operation (or element or application or instruction or threshold). For example, a first type of object can be called a second type of object, and a second type of object can also be called a first type of object. It is just that the scopes included by the two are different, without departing from the scope of the present disclosure. The first type of object and the second type of object can both be sets of various objects, but the two are not sets of the same objects, and there is at least one object included in the various object sets.

[0035] The intelligent terminal of the embodiment of the present disclosure can be implemented in various forms. Among them, the intelligent terminal can be a mobile terminal including such as a collection and identification device (such as a camera and a video recorder), a mobile phone, a smart phone, a laptop computer, a personal digital assistant (PDA, Personal Digital Assistant), a tablet computer (PAD), etc., and the intelligent terminal can also be a fixed terminal of a digital broadcast transmitter, a digital TV, a desktop computer, a server, etc. Below, it is assumed that the intelligent terminal is a fixed terminal. However, it will be understood by those skilled in the art that, in addition to being particularly used for fixed type elements, the construction according to the embodiment of the present disclosure can also be applied to mobile type terminals.

[0036] In one embodiment, for the sake of security and reducing the size of the installation package, software design engineers currently obfuscate resources and the original variable names of resources. However, there are some resources that need to obtain the storage path of the resources through the original variable names of the resources during the subsequent program operation. In this case, these resources will not be obfuscated. Generally, these resources are added to a whitelist. The resources in the whitelist will not be obfuscated and the original variable names are kept. When the storage path of the resource needs to be obtained during the subsequent program operation, the smart terminal uses the original variable name of the resource and calls the getIdentifier method of the Resources class to reflect the whitelist, thereby obtaining the storage path of the resource.

[0037] However, the above-mentioned method of adding resources to the whitelist has some inevitable defects. For example, if there are many resources in the whitelist, it means that a large part of the resources are not obfuscated, and the effect of enhancing security performance and reducing the size of the installation package will be weakened. For another example, if the project needs to obtain resources by name, and the source of the resource is uncertain (such as the name is not known, but issued through the network), then the resource cannot be added to the whitelist, and the obfuscation can only be abandoned, thereby increasing the amount of the whitelist. In addition, the whitelist needs to be maintained manually, which is prone to errors and omissions, causing some unknown problems.

[0038] Therefore, the intended purpose of this application is to provide a method for obtaining obfuscated resources. This method can ensure that all resources are obfuscated, and the corresponding resources after obfuscation can still be obtained through the original variable name of the resource, without setting up a whitelist, thereby maximizing the role of resource obfuscation and reducing human maintenance costs.

[0039] The method for obtaining obfuscated resources in the disclosed embodiment is applied to a resource installation package, which is a software development kit (SDK) for smart terminals, and can provide common functional components for applications in smart terminals. Applications can integrate various functional modules by referencing the SDK and calling the SDK interface. The resource installation package has a variety of computer programs that can run in user mode to complete one or more specific tasks. The computer programs can be modified by users. Optionally, the smart terminal can be based on Liunx (GNU / Linux) system, Mac (Macintosh) system or Microsoft system for program operation, and the smart terminal can also be based on platform, platform, Platform or Platforms, etc. are used for program applications.

[0040] In one embodiment, if Figure 1 As shown, Figure 1 This is a schematic diagram of an embodiment of file configuration in the present application, in which a custom subclass context (customContext) is set in the context class (Context class) of the resource installation package, and a custom subclass resource management file (CustomResources) of a resource management class (Resources class) is set in the subclass context. Among them, the Context class represents an application scenario, which describes information about an application environment, that is, a context, which represents a process of interaction with the operating system.

[0041] CustomResources is an extension class based on the Kubernetes API. You can control the running status of resources in the cluster by dynamically registering the CustomResources class. After installing the CustomResources class, you can create and access objects of the CustomResources class through kubectl configuration, just like built-in resources (such as pod resources). Optionally, there are usually two ways to customize the CustomResources class: through CRD (CustomResourceDefinitions) and using the aggregate API.

[0042] In one embodiment, during the application development process, if you want to use an object of the Resources class, you need to obtain it through an object of the Context class, and you cannot directly obtain the Resources object through the Resources class. Therefore, if you set the custom CustomResources class to the Context class, that is, save the Resources object in the Context object, and save a Resources object in a Context object, you need to set the custom Resources object to the custom customContext class in the constructor of the Resources class, and then you can set the custom Resources object in the Context object through the custom Context object. Therefore, when the Context class is started to obtain resources later, the Context class obtains the custom Resources object.

[0043] See also Figure 2 , Figure 2 1 is a flow chart of the first embodiment of the method for obtaining obfuscated resources provided by the present application. The method is applied to the smart terminal in the above embodiment to be executed by the smart terminal. Specifically, the method may include the following steps:

[0044] Step 11: Before initiating the getIdentifier method based on the context class, pass the subclass context into the first and second class objects of the context class to override the getIdentifier method.

[0045] Specifically, before the smart terminal starts the getIdentifier method based on the context class to obtain the storage path of the obfuscated resource, the smart terminal needs to pass the subclass context into the first and second class objects of the context class to rewrite the getIdentifier method.

[0046] In one embodiment, the first type of object of the context class is the Application object of the Context class, and the second type of object is the Activity object. The Application object and the Activity object are a subclass context of the ContextWrapper class (wrapper class) in the Context class.

[0047] Among them, the Activity object class contains theme-related interfaces, which are specified by the android:theme attribute, that is, the Activity object requires an android theme.

[0048] See also Figure 3 , Figure 3 1 is a flow chart of an embodiment of step 11 in the present application. Specifically, step 11 may include the following steps:

[0049] Step 111: Before launching the getIdentifier method based on the context class, create the Application object and the Activity object.

[0050] In one embodiment, in response to an application of the intelligent terminal being started for the first time, an Application object is first created. Moreover, the timing of creating the Application object is in creating a handleBindApplication() method, the function of which is located in the ActivityThread.java class.

[0051] In one embodiment, when the smart terminal detects that a new Activity object needs to be created, the smart terminal requests to start an Activity object through the startActivity() method or the startActivityForResult() method. The handleLaunchActivity() method can be called back through these two methods, and then the performLaunchActivity() method is called and the onCreate() method and onStart() method are called back through this method, thereby creating an Activity instance. Among them, the functions of the performLaunchActivity() method, the onCreate() method, and the onStart() method are all located in the ActivityThread.java class.

[0052] Step 112: When initializing based on the Application object and the Activity object, call the attachBaseContext method to pass the subclass context into the Application object and the Activity object to override the getIdentifier method.

[0053] Specifically, the method to rewrite the getIdentifier method is to call the attachBaseContext method to pass the custom subclass context to the Application object when the Application object starts the initialization program, and call the attachBaseContext method to pass the custom subclass context to the Activity object when the Activity object starts the initialization program to rewrite the getIdentifier method. Then, all places in the application where the getIdentifier method is called will eventually call the getIdentifier method rewritten in the custom CustomResources.

[0054] In one embodiment, before rewriting the getIdentifier method, it is necessary to first establish a mapping relationship between the identification information of the obfuscated resource and the original variable name, so as to map the original variable name of the obfuscated resource to the identification information of the obfuscated resource through the rewritten getIdentifier method, and then index the actual storage path of the obfuscated resource through the identification information of the obfuscated resource. The identification information of the obfuscated resource can be the resource ID of the obfuscated resource. The identification information and the actual storage path of the obfuscated resource will not be changed as the resource is obfuscated.

[0055] See also Figure 4 , Figure 4 This is a flowchart of an embodiment of establishing a mapping relationship between the identification information of the obfuscated resource and the original variable name in this application. Specifically, it may include the following steps:

[0056] Step a1: Get the resource installation package.

[0057] Specifically, the smart terminal may be connected to a third-party organization (eg, a computer, a cloud server, or a data processing platform, etc.) so that the resource installation package can be transmitted to the smart terminal through the third-party organization and the resource installation package can be collected.

[0058] Step a2: compile the original resources in the resource installation package to generate a mapping relationship table between the identification information of the obfuscated resources and the original variable names.

[0059] Specifically, while the intelligent terminal compiles the original resources in the resource installation package, it generates a one-to-one mapping relationship table between the identification information and the original variable name. Among them, the mapping relationship table can also be graded. For example, the identification information and the original variable name are the last level, and the upper level is the application package name to which the resource belongs. The upper level of the application package name can be the resource type of the resource. Therefore, when using the mapping relationship table for mapping indexing, first use the resource type of the resource to index to the resource type level in the mapping relationship table, and then use the application package name for mapping indexing to map to the application package name level of the resource. In this application package name, the identification information of the resource is indexed by the original variable name of the resource.

[0060] Optionally, the mapping relationship table between the identification information of the obfuscated resource and the original variable name can be a MAP file. The MAP file is a mapping file for all programs, data and IO space used by DSP (digital signal processing) generated after the CCS software is compiled. The MAP file is roughly divided into four parts: file header, memory configuration, segment mapping, and global symbol. The memory configuration is associated with the MEMORY instruction in the CMD file. The program and data interval definitions defined in the CMD file can all be found in this part. When it is different from the CMD file, an actually used interval is added to the MAP file, that is, the actual length of the space used in the program. The segment mapping part is associated with the SECTION instruction in the CMD file. The starting address and actual length of all segments actually mapped in this part of the program are detailed. It can be specific to the segment specified by the PROGMA (preprocessing instruction) in the program and the OBJ (project) file generated by each separate file. The global symbol can be every function used by the program, and the global variables defined in the program can find the corresponding starting address here. There are two ways to list in the MAP file, one is to arrange by corresponding address, and the other is to arrange by global symbol letters.

[0061] Step a3: Store the mapping relationship table in the R.java class file.

[0062] Among them, the R.java class file is automatically generated by the smart terminal during compilation, and is used to define the index of all types of resources in the Android program. In addition, the content in the R.java class file is read-only and developers do not modify it. Storing the mapping relationship table in the R.java class file can facilitate users to restore and trace back the obfuscation rules and obfuscation resources.

[0063] Step a4: Obfuscate the original resource to form an obfuscated resource.

[0064] Specifically, the original variable name and resource ID assigned to the resource file during compilation are the original resources of the resource file. After obtaining the original resources of the resource file, the original resources need to be obfuscated using a preset obfuscation rule.

[0065] In one embodiment, the obfuscation process specifically refers to performing obfuscation process on the resource file and replacing the original variable name of the original resource with a simple letter combination.

[0066] In one embodiment, the obfuscation rule is a method for generating a new resource variable name. In this embodiment, the new resource variable name can be generated by randomly generating a letter combination of a specified length, randomly generating a letter combination of an indefinite length, or generating a letter combination of increasing length by permutation and combination. However, the resource variable name obtained by the obfuscation process is not limited to this. Depending on the application scenario, the new resource variable name formed by the obfuscation rule can be (not limited to) a number combination, a mixed combination of numbers and letters, or a common graphic combination. In this embodiment, the letters are not limited to the commonly used English letters. Depending on the application scenario, the letters can be any writing system with alphabetic characters in the world's writing system.

[0067] The new resource variable name generated according to the preset obfuscation rules will replace the original variable name to complete the obfuscation. The new resource variable name is the obfuscated identity file of the resource file.

[0068] Step 12: Based on the rewritten getIdentifier method, obtain the identification information of the obfuscated resource.

[0069] See also Figure 5 , Figure 5 1 is a flow chart of an embodiment of step 12 in the present application. Specifically, step 12 may include the following steps:

[0070] Step 121: Call the getResource method in the subclass context to return the subclass resource management file.

[0071] Specifically, the intelligent terminal calls the getResource method in the subclass context to return a URL (i.e., a uniform resource locator) with a given resource name. Therefore, before calling the getResource method, the resource name of the subclass resource management file needs to be given so that the uniform resource locator of the subclass resource management file can be returned through this method.

[0072] The getResource method is a non-static method that can only be accessed through the class object. If you try to access the method using the class name, you will receive an error message. The getResource method is available in the java.lang package.

[0073] Step 122: Override the getIdentifier method in the subclass resource management file.

[0074] Specifically, the user inputs a getIdentifier method instruction to start the system into the smart terminal, so as to finally overload the getIdentifier method in the returned subclass resource management file (ie, the customized CustomResources).

[0075] Step 123: Based on the overloaded getIdentifier method, obtain identification information.

[0076] See also Figure 6 , Figure 6 1 is a flow chart of an embodiment of obtaining identification information in the present application. Specifically, step 123 may include the following steps:

[0077] Step b1: Pass the original variable name, resource type and application package name of the obfuscated resource into the getIdentifier method to overload the getIdentifier method.

[0078] Specifically, in the system's getIdentifier method, the user passes the original variable name, resource type, and application package name of the obfuscated resource into the getIdentifier method, and the system's getIdentifier method starts to index the identification information corresponding to the original variable name of the obfuscated resource. Finally, the system's getIdentifier method is applied to the subclass resource management file, and based on the original variable name, resource type, and application package name of the obfuscated resource, it overloads the getIdentifier method in CustomResources.

[0079] Step b2: Based on the overloaded getIdentifier method, the original variable name, resource type and application package name are used to reflectively call the R.java class file to perform resource ID indexing.

[0080] See also Figure 7 , Figure 7 1 is a flow chart of an embodiment of resource ID indexing in the present application. Specifically, step b2 may include the following steps:

[0081] Step c1: Use the original variable name, resource type and application package name to reflectively call the mapping relationship table in the R.java file.

[0082] Specifically, in the getIdentifier method in CustomResources, the smart terminal calls the mapping relationship table in the R.java file, and uses the application package name to reflect the application package name to which the obfuscated resource belongs, and uses the resource type to reflect the resource type to which the obfuscated resource belongs in the corresponding application package name.

[0083] Step c2: Based on the mapping relationship table, index the resource ID corresponding to the original variable name.

[0084] Specifically, the intelligent terminal indexes the corresponding resource ID based on the original variable name of the obfuscated resource in the mapping relationship table.

[0085] Step b3: Based on the result of the resource ID index, obtain the ID name.

[0086] Specifically, the result of the resource ID index obtained by the getIdentifier method includes returning the resource ID (ie, the resource ID index is successful), and returning a value of "0" (ie, the resource ID index fails).

[0087] Step 13: Based on the identification information, obtain the obfuscated resource.

[0088] Specifically, after the smart terminal compiles the resource installation package, the resource ID and the actual path of the resource will not change during the application running. Therefore, the smart terminal indexes the path of the obfuscated resource in the resource management class (Resource class) based on the identification information (i.e. resource ID) obtained by the getIdentifier method to obtain the actual storage path of the obfuscated resource, and obtains the obfuscated resource according to the actual storage path.

[0089] In one embodiment, the intelligent terminal indexes the actual path of the obfuscated resource in at least one of a string class file (Publicstatic class String class), a layout class file (Public static class layout class), or an image class file (Public static class drawable class) of a resource management class (Resource class).

[0090] See also Figure 8 , Figure 8 1 is a flow chart of a second embodiment of the method for obtaining obfuscated resources provided by the present application. The method is applied to the smart terminal in the above embodiment to be executed by the smart terminal. Specifically, the method may include the following steps:

[0091] Step S1: APP calls context.getResource().getdentifier(Stering name).

[0092] Specifically, the smart terminal control application (i.e., APP) first calls the getResource() method in the context class to return the Resource object; then the user enters the original name of the obfuscated resource into the smart terminal to start the program that calls the getdentifier(Stering name) method in the Resource object.

[0093] Step S2: In response to calling the getdentifier(Stering name) method, the context class creates and initializes the Application class and the Activity class. When initializing the Application class and the Activity class, the smart terminal passes the customized Context context class into the two classes to start calling the attachBaseSontext(Context context) method of the Application class and the Activity class.

[0094] Step S3: In response to calling the attachBaseSontext(Context context) method, the customized CustomContext object in the customized Context context class of the smart terminal returns the customized CustomResources object encapsulated in its object to the system; then, the user enters the original name of the obfuscated resource into the smart terminal to start calling the Getdentifier(String name) method in the CustomResources object.

[0095] Step S4: In response to calling the Getdentifier(Stringname) method in the CustomResources object, the smart terminal reflects and calls at least one of the Public static classString file, Public static class drawable, and Public static class layout in the R.java file in the Resource class to reflect the resource ID corresponding to the original name of the obfuscated resource in the at least one folder. And subsequently, the user indexes the actual storage path of the corresponding obfuscated resource in the Resource class according to the resource ID.

[0096] Different from the prior art, the method for obtaining obfuscated resources provided in this embodiment is applied to a resource installation package, wherein a custom subclass context is set in the context class of the resource installation package, and a custom subclass resource management file of a resource management class is set in the subclass context, and the method includes: before starting the getIdentifier method based on the context class, passing the subclass context into the first class object and the second class object of the context class to rewrite the getIdentifier method; based on the rewritten getIdentifier method, obtaining the identification information of the obfuscated resource; based on the identification information, obtaining the obfuscated resource. In the above manner, the smart terminal uses the custom subclass resource management file set in the custom subclass context to rewrite the getIdentifier method, and can obtain the corresponding resources after obfuscation through the rewritten getIdentifier method while ensuring that all resources are obfuscated, thereby optimizing the process of obtaining obfuscated resources and reducing resource management costs.

[0097] See also Fig. 9 , Fig. 9 A structural diagram of a smart terminal provided in the present application, the smart terminal 100 includes a processor 101 and a memory 102 connected to the processor 101, wherein program data is stored in the memory 102, and the processor 101 calls the program data stored in the memory 102 to execute the above-mentioned method for obtaining obfuscated resources.

[0098] Optionally, in one embodiment, the processor 101 is applied to a resource installation package, wherein a custom subclass context is set in the context class of the resource installation package, and a custom subclass resource management file of a resource management class is set in the subclass context; the processor 101 is used to execute program data to implement the following method: before starting the getIdentifier method based on the context class, the subclass context is passed into the first class object and the second class object of the context class to rewrite the getIdentifier method; based on the rewritten getIdentifier method, the identification information of the obfuscated resource is obtained; based on the identification information, the obfuscated resource is obtained.

[0099] In the above scheme, the smart terminal 100 uses a custom subclass resource management file set in a custom subclass context to rewrite the getIdentifier method. While ensuring that all resources are obfuscated, the corresponding resources after obfuscation can be obtained through the rewritten getIdentifier method, thereby optimizing the process of obtaining obfuscated resources and reducing resource management costs.

[0100] Among them, the processor 101 can also be called a CPU (Central Processing Unit). The processor 101 may be an electronic chip with signal processing capabilities. The processor 101 can also be a general-purpose processor, a digital signal processor (Digital Signal Processor, DSP), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field-programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. In addition, the processor 101 can be implemented by an integrated circuit chip.

[0101] The memory 102 can be a memory stick, a TF card, etc., which can store all the information in the smart terminal 100, including the input raw data, computer programs, intermediate operation results and final operation results are all stored in the memory 102. It stores and retrieves information according to the location specified by the processor 101. With the memory 102, the smart terminal 100 has a memory function and can ensure normal operation. The memory 102 of the smart terminal 100 can be divided into main memory (internal memory) and auxiliary memory (external memory) according to its purpose, and there is also a classification method of dividing it into external memory and internal memory. External memory is usually a magnetic medium or an optical disk, etc., which can store information for a long time. Memory refers to the storage component on the motherboard, which is used to store the data and programs currently being executed, but it is only used to temporarily store programs and data. If the power is turned off or the power is cut off, the data will be lost.

[0102] By way of example and not limitation, Fig. 9 As shown, the memory 102 may load application programs, program data, and an operating system that may be executed, which may include various applications (such as a Web browser, a middle-tier application, a relational database management system (RDBMS), etc.). As an example, the operating system may include various versions of Microsoft Apple and / or Linux operating system, various commercial or similar Operating systems (including but not limited to various GNU / Linux operating systems, Google OS, etc.) and / or mobile operating systems such as Phone, OS, OS, OS operating system, and other operating systems.

[0103] In the several embodiments provided in the present application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the implementation of the intelligent terminal 100 described above is only illustrative, for example, the getIdentifier method is overloaded according to the original variable name, resource type and application package name of the obfuscated resource, the R.java class file is reflectively called to index the resource ID, etc., which is only a collection method, and there may be other division methods in actual implementation, for example, the string class file, layout class file or image class file of the resource management class can be combined or can be collected into another system, or some features can be ignored or not executed.

[0104] In addition, each functional unit (such as context class and resource management class, etc.) in each embodiment of the present application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional unit.

[0105] See also Fig.10 , Fig.10 This is a schematic diagram of the structure of an embodiment of a computer-readable storage medium provided in the present application. The computer-readable storage medium 110 stores program instructions 111 that can implement all the above methods.

[0106] If the integrated units of the functional units in the various embodiments of the present application are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium 110. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer-readable storage medium 110 includes several instructions in a program instruction 111 to enable a computer device (which can be a personal computer, a system server, or a network device, etc.), an electronic device (such as MP3, MP4, etc., or a mobile terminal such as a mobile phone, a tablet computer, a wearable device, or a desktop computer, etc.) or a processor to execute all or part of the steps of the methods of various implementation methods of the present application.

[0107] Optionally, in one embodiment, program instructions 111 are applied to a resource installation package, wherein a custom subclass context is set in the context class of the resource installation package, and a custom subclass resource management file of a resource management class is set in the subclass context; when the program instructions 111 are executed by the processor, they are used to implement the following method: before starting the getIdentifier method based on the context class, passing the subclass context into the first class object and the second class object of the context class to rewrite the getIdentifier method; based on the rewritten getIdentifier method, obtaining the identification information of the obfuscated resource; based on the identification information, obtaining the obfuscated resource.

[0108] In the above scheme, the computer-readable storage medium 110 uses a custom subclass resource management file set in a custom subclass context to rewrite the getIdentifier method. While ensuring that all resources are obfuscated, the corresponding resources after obfuscation can be obtained through the rewritten getIdentifier method, thereby optimizing the process of obtaining obfuscated resources and reducing resource management costs.

[0109] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-readable storage media 110 (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0110] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by a computer-readable storage medium 110. These computer-readable storage media 110 can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the program instructions 111 executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0111] These computer-readable storage media 110 may also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to operate in a specific manner, so that the program instructions 111 stored in the computer-readable storage medium 110 produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0112] These computer-readable storage media 110 can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing program instructions 111 executed on the computer or other programmable device for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0113] In one embodiment, these programmable data processing devices include a processor and a memory. The processor may also be referred to as a CPU (Central Processing Unit). The processor may be an electronic chip having signal processing capabilities. The processor may also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0114] The memory can be a memory stick, TF card, etc. It stores and retrieves information according to the location specified by the processor. According to the purpose, the memory can be divided into primary memory (internal memory) and auxiliary memory (external memory). There is also a classification method of dividing it into external memory and internal memory. External memory is usually a magnetic medium or optical disk, etc., which can store information for a long time. Memory refers to the storage component on the motherboard, which is used to store the data and programs currently being executed, but it is only used to temporarily store programs and data. If the power is turned off or the power is cut off, the data will be lost.

[0115] The above description is only an implementation method of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made according to the description and drawings of the present application, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. A method for obtaining obfuscated resources, the method being applied to a resource installation package, characterized in that: A custom subclass context is set in the context class of the resource installation package, and a custom subclass resource management file of a resource management class is set in the subclass context. The method includes: Before starting the getIdentifier method based on the context class, passing the subclass context into a first class object and a second class object of the context class to rewrite the getIdentifier method; the first class object is an Application object, and the second class object is an Activity object; Based on the rewritten getIdentifier method, obtain the identification information of the obfuscated resource; the identification information is the ID name of the obfuscated resource; Based on the identification information, obtaining an obfuscated resource; Wherein, the obtaining of the identification information of the obfuscated resource based on the rewritten getIdentifier method includes: Pass the original variable name, resource type and application package name of the obfuscated resource into the getIdentifier method to overload the getIdentifier method; Based on the overloaded getIdentifier method, the original variable name, resource type and application package name are used to reflectively call the R.java class file to perform resource ID indexing; Based on the result of the resource ID index, the ID name is obtained.

2. The method according to claim 1, characterized in that: The method based on the rewritten getIdentifier method obtains the identification information of the obfuscated resource, including: Call the getResource method in the subclass context to return the subclass resource management file; Override the getIdentifier method in the subclass resource management file; Based on the overloaded getIdentifier method, the identification information is obtained.

3. The method according to claim 1, characterized in that The method of using the original variable name, resource type and application package name to reflectively call the R.java class file to perform resource ID indexing includes: Using the original variable name, resource type and application package name, reflectively call the mapping relationship table in the R.java file; Based on the mapping relationship table, the resource ID corresponding to the original variable name is indexed.

4. The method according to claim 1, characterized in that Before starting the getIdentifier method based on the context class, passing the subclass context into the first class object and the second class object of the context class to rewrite the getIdentifier method, includes: Before starting the getIdentifier method based on the context class, creating the Application object and the Activity object; When initializing based on the Application object and the Activity object, the attachBaseContext method is called to pass the subclass context into the Application object and the Activity object to rewrite the getIdentifier method.

5. The method according to claim 1, characterized in that The acquiring the obfuscated resource based on the identification information includes: Based on the identification information, the path of the obfuscated resource is indexed in the resource management class to obtain the obfuscated resource.

6. The method according to claim 5, characterized in that The path of indexing the obfuscated resource in the resource management class includes: The path of the obfuscated resource is indexed in at least one of a string class file, a layout class file, or an image class file of the resource management class.

7. The method according to claim 1, characterized in that Prior to the method, it also includes: Obtain the resource installation package; Compiling the original resources in the resource installation package to generate a mapping relationship table between the identification information and the original variable names of the obfuscated resources; The mapping relationship table is stored in the R.java class file; The original resource is obfuscated to form the obfuscated resource.

8. An intelligent terminal, characterized in that: The intelligent terminal includes a processor and a memory connected to the processor, wherein the memory stores program data, and the processor calls the program data stored in the memory to execute the method for obtaining obfuscated resources as described in any one of claims 1-7.

9. A computer-readable storage medium having program instructions stored therein, characterized in that: The program instructions are executed to implement the method for obtaining obfuscated resources as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Java code-based obfuscation method and apparatus

    CN109614771A

  • APK resource file confusion method and device

    CN111143789A