CN111694730A - Method and device for eliminating mistaken reference of control resources - Google Patents

Method and device for eliminating mistaken reference of control resources Download PDF

Info

Publication number
CN111694730A
CN111694730A CN202010366682.3A CN202010366682A CN111694730A CN 111694730 A CN111694730 A CN 111694730A CN 202010366682 A CN202010366682 A CN 202010366682A CN 111694730 A CN111694730 A CN 111694730A
Authority
CN
China
Prior art keywords
control
identification
carrier
searching
control identification
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202010366682.3A
Other languages
Chinese (zh)
Other versions
CN111694730B (en
Inventor
况众文
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Urban Network Neighbor Information Technology Co Ltd
Original Assignee
Beijing Urban Network Neighbor Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Urban Network Neighbor Information Technology Co Ltd filed Critical Beijing Urban Network Neighbor Information Technology Co Ltd
Priority to CN202010366682.3A priority Critical patent/CN111694730B/en
Publication of CN111694730A publication Critical patent/CN111694730A/en
Application granted granted Critical
Publication of CN111694730B publication Critical patent/CN111694730B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/3628Software debugging of optimised code
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/366Software debugging using diagnostics
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The embodiment of the invention provides a method and a device for eliminating mistakenly-referenced control resources, wherein the method comprises the following steps: acquiring an initial byte code generated by compiling a Java file; adjusting rules of searching controls according to the control identifications in the initial bytecode; wherein the adjusted rules include: when the control is not found, adjusting the control identification to find the control again; the controls indicated by the control identification used in each search have the same name; and generating an executable file according to the adjusted initial byte code. The invention can achieve the same purpose as modifying the source code by adjusting the byte code, thereby avoiding invading the source code. When the homonymous control resources exist, the influence caused by wrong reference can be eliminated; the problem of false references is solved in advance before the application generated from the executable file runs.

Description

Method and device for eliminating mistaken reference of control resources
Technical Field
The invention relates to the field of application program development, in particular to a method and a device for eliminating mistakenly-referenced control resources.
Background
Android (Android) is a Linux-based operating system with free and open source codes, and is one of the most common operating systems for mobile terminals. An Application (APP) applied to Android is generally called an Android APP. In a development process of a conventional Android APP, all service data of the same Android APP are generally packaged into an Android Application Package (APK). The user only needs to download and install the APK.
At present, a new Android App development, compiling and publishing mechanism is popular, namely Android apppbundle. The Android App may be packaged as a plurality of APKs. Such as a Base (Base) APK, a plurality of Dynamic configuration modes (Dynamic Feature) APK. Wherein, the Base APK is an APK which is installed for the first time and comprises public codes and resources; the Dynamic Feature APK is a Base APK-based module that is loaded without first installation. When a user downloads and installs an application program for the first time, only the Base APK needs to be installed, and therefore the application volume is greatly reduced.
In both the traditional Android App development process and the development process under the Android App Bundle mechanism, different resources generally have different resource names. But for a variety of reasons there may be resources with the same resource name. Thus, when the resources with the same resource name are referenced, the reference error is easy to occur. However, all resources are merged in the traditional Android App development process, so that even if a reference error occurs when the resources with the same resource name are referred, no problem occurs when the Android App runs.
However, under the Android APP Bundle mechanism, the resources of multiple APKs are not merged. Therefore, in the development process, when resources with the same resource names are referenced, if a reference error occurs, the Android APP runtime crashes. As shown in FIG. 1, both the Base APK and the Dynamic Feature APK have resources with resource names ID _ A and ID _ B, and a certain layout file of the Dynamic Feature APK needs to use the resource with resource name ID _ A in the Dynamic Feature APK. But the resource with the resource name ID _ A in the Base APK is wrongly referred to due to carelessness of a developer in the reference process. Thus, a crash occurs while the Dynamic Feature APK is running. The only solution at present is to make modifications by the intrusion of professional developers into the source code.
Disclosure of Invention
The embodiment of the invention provides a method and a device for eliminating wrong reference control resources, which are used for solving the problems that in the prior art, the method of modifying the wrong reference by manually intruding a source code has higher requirements on operators and the wrong reference cannot be solved in advance before an application program runs.
In a first aspect, an embodiment of the present invention provides a method for eliminating an erroneously referenced control resource, where the method includes:
acquiring an initial byte code generated by compiling a Java file;
adjusting rules of searching controls according to the control identifications in the initial bytecode; wherein the adjusted rules include: when the control is not found, adjusting the control identification to find the control again; the controls indicated by the control identification used in each search have the same name;
and generating an executable file according to the adjusted initial byte code.
Optionally, the step of adjusting a rule for searching for a control according to a control identifier in the initial bytecode includes:
acquiring a carrier when a target method in the initial bytecode is called and a reference code for indicating a control identification; the target method is used for searching a control in the carrier according to the control identification indicated by the reference code;
searching a control in the carrier according to the control identification indicated by the reference code;
when the control is not found, re-determining the control identification according to the control name in the reference code; searching the control in the carrier again according to the redetermined control identification;
and taking the found control identification of the control as a return value of the target method.
Optionally, the step of re-determining the control identifier according to the control name in the reference code includes:
searching a control identification corresponding to the control name in the reference code in a basic android application package resource library through a Java reflection mechanism;
and taking the control identification corresponding to the control name in the found reference code as the redetermined control identification.
Optionally, after the step of searching for the control in the carrier again according to the re-determined control identifier, the method further includes:
when the control is not found in the carrier again, finding the control identification corresponding to the control name in the reference code in all dynamically constructed mode android application package resource libraries;
and searching the control in the carrier again according to the searched control identification.
Optionally, the step of finding a control in the carrier includes:
calling findViewById methods under different types to search controls in the carrier according to the type of the carrier; wherein the types of the carrier at least include: pop-up, view, and window.
Optionally, before the step of obtaining a carrier when a target method in the initial bytecode is called and reference code for indicating a control identifier, the method further includes:
and traversing information in the initial byte codes to determine the target method.
In a second aspect, an embodiment of the present invention further provides an apparatus for eliminating an erroneously referenced control resource, where the apparatus includes:
the acquisition module is used for acquiring an initial byte code generated by compiling a Java file;
the adjusting module is used for adjusting the rule of searching the control according to the control identification in the initial byte code; wherein the adjusted rules include: when the control is not found, adjusting the control identification to find the control again; the controls indicated by the control identification used in each search have the same name;
and the generating module is used for generating an executable file according to the adjusted initial byte code.
Optionally, the adjusting module includes:
the obtaining unit is used for obtaining a carrier when a target method in the initial bytecode is called and a reference code used for indicating a control identification; the target method is used for searching a control in the carrier according to the control identification indicated by the reference code;
the first searching unit is used for searching the control in the carrier according to the control identification indicated by the reference code;
the second searching unit is used for re-determining the control identification according to the control name in the reference code when the control is not searched; searching the control in the carrier again according to the redetermined control identification;
and the return unit is used for taking the found control identification of the control as a return value of the target method.
Optionally, the second searching unit is specifically configured to search, in a Base APK repository of a basic android application package, a control identifier corresponding to a control name in the reference code through a Java reflection mechanism; and taking the control identification corresponding to the control name in the found reference code as the redetermined control identification.
Optionally, the apparatus further comprises:
a third searching unit, configured to search, when no control is found in the carrier again, a control identifier corresponding to the control name in the reference code in all dynamically constructed mode android application package Dynamic Feature APK resource libraries; and searching the control in the carrier again according to the searched control identification.
Optionally, the first search unit is specifically configured to invoke findViewById methods of different types to search for a control in the carrier according to the type of the carrier; wherein the types of the carrier at least include: pop-up, view, and window.
Optionally, the apparatus further comprises:
and the traversing module is used for traversing the information in the initial bytecode and determining the target method.
In a third aspect, an embodiment of the present invention further provides an electronic device, where the electronic device includes a memory, a processor, and a computer program stored on the memory and executable on the processor, and the processor, when executing the computer program, implements the steps in the method for eliminating an erroneous reference control resource as described above.
In a fourth aspect, the embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the steps in the method for eliminating the erroneous reference control resource as described above.
In the embodiment of the invention, the initial byte code generated by compiling the Java file is obtained; and then adjusting rules in the initial byte codes for searching the control according to the control identification. By adjusting the initial bytecode, intrusion into the source code can be avoided. And the adjusted rules include: and when the control is not found, adjusting the control identification to find the control again. The controls indicated by the control identifications used for each search have the same name, that is, the controls indicated by the control identifications before and after adjustment have the same name. After the control resource with the same name is referenced by mistake, the control can be found by searching again, and the crash of the executable file generated subsequently in the execution process is avoided. And generating an executable file according to the adjusted initial byte code. The adjusted initial byte codes eliminate the influence caused by mistakenly referencing the control resources with the same name. Therefore, the executable file can not be crashed due to the fact that the same-name control resources are wrongly referenced during execution, and the problem of wrong reference is solved in advance before the application program generated according to the executable file runs.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the description of the embodiments of the present invention will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art that other drawings can be obtained according to these drawings without inventive labor.
FIG. 1 is a schematic diagram of a scenario in which a control resource is referenced in error;
FIG. 2 is a flowchart illustrating steps of a method for eliminating a control resource referenced by an error according to an embodiment of the present invention;
fig. 3 is a flowchart of a step of adjusting a rule for searching for a control according to a control identifier in an initial bytecode according to an embodiment of the present invention;
FIG. 4 is a flowchart illustrating a method for eliminating a control resource referenced by an error according to an embodiment of the present invention;
FIG. 5 is a block diagram of an apparatus for eliminating an erroneously referenced control resource according to an embodiment of the present invention;
fig. 6 is a block diagram of an adjusting module according to an embodiment of the present invention;
fig. 7 is a block diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be appreciated that reference throughout this specification to "one embodiment" or "an embodiment" means that a particular feature, structure or characteristic described in connection with the embodiment is included in at least one embodiment of the present invention. Thus, the appearances of the phrases "in one embodiment" or "in an embodiment" in various places throughout this specification are not necessarily all referring to the same embodiment. Furthermore, the particular features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.
In various embodiments of the present invention, it should be understood that the sequence numbers of the following processes do not mean the execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present invention.
Referring to fig. 2, an embodiment of the present invention provides a method for eliminating an erroneously referenced control resource, which is applied to a Dynamic Feature mode under an Android APP Bundle mechanism, and the method includes:
step 201, obtaining an initial bytecode generated by compiling a Java file.
It should be noted that the Java class generated by the Java file compilation may also be referred to as a class file, i.e., the initial bytecode. The number of class files is multiple, and preferably, all class files, that is, all initial bytecodes generated by compiling the Java file, may be obtained.
Because of the conventional method, it is difficult to modify the contents of a Java file or class file during the compilation of the Java file. Therefore, under the condition of not invading the source code, the content of the generated class file can be modified through the byte code modification technology, thereby achieving the same purpose as modifying the source code.
Step 202, adjusting rules in the initial bytecode for searching the control according to the control identification.
It should be noted that the adjusted rules include: when the control is not found, adjusting the control identification to find the control again; the control indicated by the control identification used for each search has the same name. And if the control is found, returning the identifier of the found control, wherein the identifier is the only identifier of the control, and the identifiers of different controls are different. Preferably, the content of the initial bytecode can be modified by a bytecode modification technology, so as to adjust a rule for searching the control according to the control identifier in the initial bytecode.
And step 203, generating an executable file according to the adjusted initial bytecode.
It should be noted that the executable file is a file that can be recognized, loaded and executed by the android platform virtual machine, i.e., a dex file. Specifically, the adjusted initial bytecode generates a dex file by a dx command.
In the embodiment of the invention, an initial byte code generated by compiling a Java file is obtained; and then adjusting rules in the initial byte codes for searching the control according to the control identification. By adjusting the initial bytecode, intrusion into the source code can be avoided. And the adjusted rules include: and when the control is not found, adjusting the control identification to find the control again. The controls indicated by the control identifications used for each search have the same name, that is, the controls indicated by the control identifications before and after adjustment have the same name. After the control resource with the same name is referenced by mistake, the control can be found by searching again, and the crash of the executable file generated subsequently in the execution process is avoided. And generating an executable file according to the adjusted initial byte code. The adjusted initial byte codes eliminate the influence caused by mistakenly referencing the control resources with the same name. Therefore, the executable file can not be crashed due to the fact that the same-name control resources are wrongly referenced during execution, and the problem of wrong reference is solved in advance before the application program generated according to the executable file runs.
As shown in fig. 3, on the basis of the foregoing embodiment of the present invention, in the embodiment of the present invention, the step of adjusting the rule for searching for the control according to the control identifier in the initial bytecode includes:
step 301, acquiring a carrier when a target method in the initial bytecode is called and a reference code for indicating a control identifier.
It should be noted that the target method may be determined first by traversing, i.e., traversing the information in the initial bytecode. The target method is used for searching the control in the carrier according to the control identification indicated by the reference code. The target process may be, for example, the findViewById process. Executing the reference code will obtain the control identification it indicates. For example, the reference code is base.r.id.textview w1, the control id corresponding to the control name textview1 is obtained when the reference code is executed. And the control name and the control identification of the same control have a corresponding relation.
The carrier may be a certain view, a certain pop-up window or a certain window. The target method is to search a control with a control identifier indicated by a reference code in a certain view, a certain pop-up window or a certain window, and return the searched control.
When the carrier and the reference code when the target method is called are obtained, the call stack of the target method can be intercepted, and then the parameters of the target method, namely the carrier and the reference code, are obtained.
Step 302, finding the control in the carrier according to the control identification indicated by the reference code.
It should be noted that, if the control is found, the control identifier of the found control is used as the return value of the target method. There will be multiple controls in the carrier, each control having a different control identification; and searching a control in the carrier, namely searching a control in a plurality of controls in the carrier, wherein the control identification of the control is the same as the control identification indicated by the reference code.
Preferably, when the control is searched in the carrier, the findViewById methods under different types can be called to search the control in the carrier according to the type of the carrier; wherein the types of the carrier at least include: pop-up, view, and window. Of course, the type of the carrier can also be Activity of one of the four android components, but is not limited to this.
Step 303, when the control is not found, re-determining the control identifier according to the control name in the reference code, and searching the control in the carrier again according to the re-determined control identifier.
It should be noted that, under the condition that different controls have the same control name, because the control identifiers of different controls are different, when a corresponding control cannot be found in the carrier by using a certain control identifier, the name of the control can be determined according to the control identifier, and then the control identifier of the control resource with the same name is found by using the determined control name.
When the control identifier is determined again, the determined control identifier and the control identifier found for the first time are both required to correspond to the same control name, so that the control name is required to be determined first. The control name may be textview1 according to the control name contained in the reference code, such as when the reference code is base.r.id.textview w 1; of course, the corresponding control name can also be directly searched in the initial bytecode.
When the control identification is determined by the control name, a reflection mechanism of Java can be utilized. Preferably, the step of re-determining the control identifier according to the control name in the reference code includes:
searching a control identification corresponding to the control name in the reference code in a Base APK resource library through a Java reflection mechanism; and taking the control identification corresponding to the control name in the searched reference code as the redetermined control identification.
If the control is not found yet, the control identification can be adjusted to continue searching. Specifically, after the step of searching for the control again in the carrier according to the re-determined control identifier, the method further includes:
when the control is not found in the carrier again, searching a control identification corresponding to the control name in the reference code in all the Dynamic Feature APK resource libraries; and searching the control in the carrier again according to the searched control identification. And searching a control identification corresponding to the control name in the reference code in all Dynamic Feature APK resource libraries by using a Java reflection mechanism.
And step 304, taking the found control identification of the control as a return value of the target method.
It should be noted that the return value parameter of the original target method may be replaced by the control identifier of the control found by using the adjusted rule.
Referring to fig. 4, a flowchart of a method for eliminating an erroneously referenced control resource according to yet another embodiment of the present invention is shown. Converting class files generated by compiling Java files into dex files in a Dynamic Feature mode; i.e., class0, class1 … to dex0, dex1 …. In the conversion process, each class file is traversed, the calling of the findViewById method is obtained by using a byte code modification technology, and the findViewById is modified into the findViewById realized by the plug-in. It can also be understood that the call stack that intercepts each findViewById method is replaced with a pre-configured plug-in.
The findViewById realized by the plug-in is specifically as follows: and acquiring parameters carried in the called findViewById method. The parameters include a carrier, an Identity Document (ID) and a control name. And then performs distribution processing according to the type of the carrier. The types of the carrier at least include Activity, Dialog, Window, View. And each vector type corresponds to a respective findViewById method.
Taking the carrier type as Activity as an example, calling a findViewById method corresponding to the Activity, and searching a control corresponding to the control identifier in the carrier. And if the corresponding control is found, returning the control identification of the found control. If the corresponding control is not found, reflecting in the Base APK according to the control name to obtain the control identification, then continuing to call the findViewById method corresponding to Activity, and continuing to find the corresponding control in the carrier according to the control identification obtained by reflection. And if the corresponding control is found, returning the control identification of the found control. And if the corresponding control is not found, reflecting and acquiring control identification in all Dynamic Feature APKs according to the control name, then continuing to call a findViewById method corresponding to Activity, and continuing to find the corresponding control in the carrier according to the control identification acquired through reflection. When the type of the carrier is Dialog, Window, View, the processing procedure is similar to that when the type of the carrier is Activity, and is not described herein again.
The method for eliminating the erroneously referenced control resource according to the embodiment of the present invention is described above, and the apparatus for eliminating the erroneously referenced control resource according to the embodiment of the present invention will be described below with reference to the accompanying drawings.
Referring to fig. 5 and fig. 6, an embodiment of the present invention further provides an apparatus for eliminating an erroneously referenced control resource, where the apparatus includes:
an obtaining module 51, configured to obtain an initial bytecode generated by compiling a Java file;
the adjusting module 52 is configured to adjust a rule in the initial bytecode, where the rule is used to search for a control according to the control identifier; wherein the adjusted rules include: when the control is not found, adjusting the control identification to find the control again; the controls indicated by the control identification used in each search have the same name;
and a generating module 53, configured to generate an executable file according to the adjusted initial bytecode.
Optionally, the adjusting module 52 includes:
an obtaining unit 521, configured to obtain a carrier when a target method in the initial bytecode is called and a reference code for indicating a control identifier; the target method is used for searching the control in the carrier according to the control identification indicated by the reference code;
the first searching unit 522 is configured to search a control in the carrier according to the control identifier indicated by the reference code;
a second searching unit 523, configured to re-determine the control identifier according to the control name in the reference code when the control is not found; searching the control in the carrier again according to the re-determined control identification;
and a returning unit 524, configured to take the found control identifier of the control as a return value of the target method.
Optionally, the second searching unit 523 is specifically configured to search, in the Base APK repository, a control identifier corresponding to a control name in the reference code through a reflection mechanism of Java; and taking the control identification corresponding to the control name in the searched reference code as the redetermined control identification.
Optionally, the apparatus further comprises:
the third searching unit is used for searching the control identification corresponding to the control name in the reference code in all the Dynamic Feature APK resource libraries when the control is not searched in the carrier again; and searching the control in the carrier again according to the searched control identification.
Optionally, the first searching unit 522 is specifically configured to invoke findViewById methods under different types to search for a control in the carrier according to the type of the carrier; wherein the types of the carrier at least include: pop-up, view, and window.
Optionally, the apparatus further comprises:
and the traversing module is used for traversing the information in the initial byte codes and determining the target method.
The device for eliminating the mistaken reference control resource provided by the embodiment of the invention can realize each process realized by the method for eliminating the mistaken reference control resource in the method embodiments of fig. 2 and fig. 3, and in order to avoid repetition, the repeated description is omitted here.
In an embodiment of the present invention, the obtaining module is configured to obtain an initial bytecode generated by compiling a Java file. And the adjusting module is used for adjusting the rule of searching the control according to the control identification in the initial byte code. By adjusting the initial bytecode, intrusion into the source code can be avoided. And the adjusted rules include: and when the control is not found, adjusting the control identification to find the control again. The controls indicated by the control identifications used for each search have the same name, that is, the controls indicated by the control identifications before and after adjustment have the same name. After the control resource with the same name is referenced by mistake, the control can be found by searching again, and the crash of the executable file generated subsequently in the execution process is avoided. And the generating module is used for generating the executable file according to the adjusted initial byte code. The adjusted initial byte codes eliminate the influence caused by mistakenly referencing the control resources with the same name. Therefore, the executable file can not be crashed due to the fact that the same-name control resources are wrongly referenced during execution, and the problem of wrong reference is solved in advance before the application program generated according to the executable file runs.
In another aspect, an embodiment of the present invention further provides an electronic device, which includes a memory, a processor, a bus, and a computer program stored on the memory and executable on the processor, where the processor executes the computer program to implement the steps in the method for eliminating an erroneously referenced control resource.
For example, fig. 7 shows a schematic physical structure diagram of an electronic device.
As shown in fig. 7, the electronic device may include: a processor (processor)710, a communication Interface (Communications Interface)720, a memory (memory)730, and a communication bus 740, wherein the processor 710, the communication Interface 720, and the memory 730 communicate with each other via the communication bus 740. Processor 710 may call logic instructions in memory 730 to perform the following method:
acquiring an initial byte code generated by compiling a Java file;
adjusting rules of searching controls according to the control identifications in the initial bytecode; wherein the adjusted rules include: when the control is not found, adjusting the control identification to find the control again; the controls indicated by the control identification used in each search have the same name;
and generating an executable file according to the adjusted initial byte code.
In addition, the logic instructions in the memory 730 can be implemented in the form of software functional units and stored in a computer readable storage medium when the software functional units are sold or used as independent products. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
In still another aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program is implemented by a processor to perform the method for eliminating an erroneous reference control resource provided in the foregoing embodiments, for example, the method includes:
acquiring an initial byte code generated by compiling a Java file;
adjusting rules of searching controls according to the control identifications in the initial bytecode; wherein the adjusted rules include: when the control is not found, adjusting the control identification to find the control again; the controls indicated by the control identification used in each search have the same name;
and generating an executable file according to the adjusted initial byte code.
The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. With this understanding in mind, the above-described technical solutions may be embodied in the form of a software product, which can be stored in a computer-readable storage medium such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in the embodiments or some parts of the embodiments.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (10)

1. A method for eliminating false references to control resources, the method comprising:
acquiring an initial byte code generated by compiling a Java file;
adjusting rules of searching controls according to the control identifications in the initial bytecode; wherein the adjusted rules include: when the control is not found, adjusting the control identification to find the control again; the controls indicated by the control identification used in each search have the same name;
and generating an executable file according to the adjusted initial byte code.
2. The method of claim 1, wherein adjusting the rule in the initial bytecode for finding a control according to a control identification comprises:
acquiring a carrier when a target method in the initial bytecode is called and a reference code for indicating a control identification; the target method is used for searching a control in the carrier according to the control identification indicated by the reference code;
searching a control in the carrier according to the control identification indicated by the reference code;
when the control is not found, re-determining the control identification according to the control name in the reference code; searching the control in the carrier again according to the redetermined control identification;
and taking the found control identification of the control as a return value of the target method.
3. The method of claim 2, wherein the step of re-determining the control identification from the control name in the reference code comprises:
searching a control identification corresponding to the control name in the reference code in a Base APK (android Package) resource library of a basic android application program through a Java reflection mechanism;
and taking the control identification corresponding to the control name in the found reference code as the redetermined control identification.
4. The method according to claim 2, wherein after the step of finding a control in the carrier again according to the re-determined control identification, the method further comprises:
when the control is not found in the carrier again, finding the control identification corresponding to the control name in the reference code in all dynamic construction mode android application package dynamic feature APK resource libraries;
and searching the control in the carrier again according to the searched control identification.
5. The method of claim 2, wherein the step of finding a control in the carrier comprises:
calling findViewById methods under different types to search controls in the carrier according to the type of the carrier; wherein the types of the carrier at least include: pop-up, view, and window.
6. The method of claim 2, wherein prior to the step of obtaining the carrier when the target method in the initial bytecode is called and the reference code indicating the control identity, the method further comprises:
and traversing information in the initial byte codes to determine the target method.
7. An apparatus for eliminating erroneously referenced control resources, the apparatus comprising:
the acquisition module is used for acquiring an initial byte code generated by compiling a Java file;
the adjusting module is used for adjusting the rule of searching the control according to the control identification in the initial byte code; wherein the adjusted rules include: when the control is not found, adjusting the control identification to find the control again; the controls indicated by the control identification used in each search have the same name;
and the generating module is used for generating an executable file according to the adjusted initial byte code.
8. The apparatus of claim 7, wherein the adjustment module comprises:
the obtaining unit is used for obtaining a carrier when a target method in the initial bytecode is called and a reference code used for indicating a control identification; the target method is used for searching a control in the carrier according to the control identification indicated by the reference code;
the first searching unit is used for searching the control in the carrier according to the control identification indicated by the reference code;
the second searching unit is used for re-determining the control identification according to the control name in the reference code when the control is not searched; searching the control in the carrier again according to the redetermined control identification;
and the return unit is used for taking the found control identification of the control as a return value of the target method.
9. An electronic device comprising a processor, a memory and a computer program stored on the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the method of eliminating an erroneous reference control resource as claimed in any of claims 1 to 6.
10. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the method of eliminating a false reference control resource according to any one of claims 1 to 6.
CN202010366682.3A 2020-04-30 2020-04-30 Method and device for eliminating error reference control resource Active CN111694730B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010366682.3A CN111694730B (en) 2020-04-30 2020-04-30 Method and device for eliminating error reference control resource

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010366682.3A CN111694730B (en) 2020-04-30 2020-04-30 Method and device for eliminating error reference control resource

Publications (2)

Publication Number Publication Date
CN111694730A true CN111694730A (en) 2020-09-22
CN111694730B CN111694730B (en) 2023-07-25

Family

ID=72476903

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010366682.3A Active CN111694730B (en) 2020-04-30 2020-04-30 Method and device for eliminating error reference control resource

Country Status (1)

Country Link
CN (1) CN111694730B (en)

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040148326A1 (en) * 2003-01-24 2004-07-29 Nadgir Neelakanth M. System and method for unique naming of resources in networked environments
US20050261875A1 (en) * 2004-05-21 2005-11-24 Sandeep Shrivastava Watches and notifications
CN103186740A (en) * 2011-12-27 2013-07-03 北京大学 Automatic detection method for Android malicious software
CN103970514A (en) * 2013-01-28 2014-08-06 腾讯科技(深圳)有限公司 Information acquisition method and device for Android application program installation package
CN106569880A (en) * 2016-11-07 2017-04-19 Tcl集团股份有限公司 Method and system for dynamically sharing resources between Android applications
CN107092494A (en) * 2016-02-18 2017-08-25 腾讯科技(深圳)有限公司 The method and apparatus for accessing APK resources
CN110674025A (en) * 2018-07-03 2020-01-10 百度在线网络技术(北京)有限公司 Interactive behavior monitoring method and device and computer equipment

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040148326A1 (en) * 2003-01-24 2004-07-29 Nadgir Neelakanth M. System and method for unique naming of resources in networked environments
US20050261875A1 (en) * 2004-05-21 2005-11-24 Sandeep Shrivastava Watches and notifications
CN103186740A (en) * 2011-12-27 2013-07-03 北京大学 Automatic detection method for Android malicious software
CN103970514A (en) * 2013-01-28 2014-08-06 腾讯科技(深圳)有限公司 Information acquisition method and device for Android application program installation package
CN107092494A (en) * 2016-02-18 2017-08-25 腾讯科技(深圳)有限公司 The method and apparatus for accessing APK resources
CN106569880A (en) * 2016-11-07 2017-04-19 Tcl集团股份有限公司 Method and system for dynamically sharing resources between Android applications
CN110674025A (en) * 2018-07-03 2020-01-10 百度在线网络技术(北京)有限公司 Interactive behavior monitoring method and device and computer equipment

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
GUANGDONG BAI等: "All Your Sessions Are Belong to US: Investigating Authenticator Leakage through Backup Channels on Android", pages 60 - 69 *
余勇等: "基于Smali Code的移动应用行为模型的自动构建方法", pages 207 - 220 *

Also Published As

Publication number Publication date
CN111694730B (en) 2023-07-25

Similar Documents

Publication Publication Date Title
US20190324772A1 (en) Method and device for processing smart contracts
US6944846B2 (en) Algorithm for localization of a JAVA application using reflection API and a custom class loader
CN108121594B (en) Process management method and device
EP3499364B1 (en) Method and device for loading kernel module
CN107967139B (en) Hot updating method and device for game
US10635812B2 (en) Method and apparatus for identifying malicious software
EP3147783B1 (en) Automatic determination of compiler configuration
CN112612502A (en) Patch generation method, device, equipment and storage medium
CN110333872B (en) Application processing method, device, equipment and medium
CN114003235A (en) Kernel module compiling method and device, computer equipment and storage medium
CN109408256B (en) Application calling method and device
CN112199151B (en) Application program running method and device
US20040216138A1 (en) Method and system for processing input from a command line interface
CN111679852A (en) Detection method and device for conflict dependency library
CN111694730B (en) Method and device for eliminating error reference control resource
CN113127329A (en) Script debugging method and device and computer storage medium
CN113641389B (en) Software upgrading method, device and equipment based on OpenCPU
WO2022078057A1 (en) Method and apparatus for publishing application package, method and apparatus for applying application package, and medium, server and device
CN114706586A (en) Code compiling method, code running method, code compiling device, code running device, computer equipment and storage medium
EP1136910A2 (en) A method of compiling code in an object oriented programming language
CN113760249A (en) Program file processing method, device and equipment
CN111399842A (en) Code compiling method and device
US20190056963A1 (en) System and method of emulating execution of files
CN111782282B (en) Start program loading method and device, electronic equipment and storage medium
CN114371852B (en) Compiling method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant