CN111694730B - Method and device for eliminating error reference control resource - Google Patents

Method and device for eliminating error reference control resource Download PDF

Info

Publication number
CN111694730B
CN111694730B CN202010366682.3A CN202010366682A CN111694730B CN 111694730 B CN111694730 B CN 111694730B CN 202010366682 A CN202010366682 A CN 202010366682A CN 111694730 B CN111694730 B CN 111694730B
Authority
CN
China
Prior art keywords
control
searching
carrier
identification
code
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.)
Active
Application number
CN202010366682.3A
Other languages
Chinese (zh)
Other versions
CN111694730A (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 Chengshi Wanglin Information Technology Co Ltd
Original Assignee
Beijing Chengshi Wanglin 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 Chengshi Wanglin Information Technology Co Ltd filed Critical Beijing Chengshi Wanglin 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

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

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Devices For Executing Special Programs (AREA)
  • Stored Programmes (AREA)

Abstract

The embodiment of the invention provides a method and a device for eliminating error reference control resources, wherein the method comprises the following steps: acquiring an initial byte code generated by compiling a Java file; adjusting rules for searching the control according to the control identification in the initial byte code; wherein the adjusted rule comprises: when the control is not found, adjusting the control mark 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 the intrusion of the source code. When the control resources with the same name exist, the influence caused by error reference can be eliminated; the problem of erroneous references is resolved in advance before the application program generated from the executable file is run.

Description

Method and device for eliminating error reference control resource
Technical Field
The invention relates to the field of application program development, in particular to a method and a device for eliminating wrong reference control resources.
Background
Android (Android) is an operating system based on Linux free and open source codes, and is also one of the most commonly used operating systems for mobile terminals. An Application (APP) applied to Android is generally called an Android APP. In the development process of a traditional Android APP, all business data of the same Android APP are generally packaged into an Android application package (Android application package, abbreviated as 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 APP Bundle. Android apps can be packaged into multiple APKs. For example, a Base (Base) APK, and a plurality of Dynamic construction modes (Dynamic Feature) APKs. Wherein, the Base APK is an APK installed for the first time, and comprises public codes and resources; 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, the user only needs to install the Base APK, so that the application volume is greatly reduced.
Different resources typically have different resource names, both in the traditional Android App development process and in the development process under the Android APP Bundle mechanism. There may be resources with the same resource name for a variety of reasons. This makes it very easy for a reference error to occur when referencing resources having the same resource name. However, the traditional Android App development process can merge all resources, so that even if a reference error occurs when the resources with the same resource name are referenced, no problem occurs when the Android App runs.
However, under Android APP Bundle, the resources of multiple APKs are not merged. In the development process, when the resources with the same resource name are referenced, if a reference error occurs, the Android APP runtime crashes. As shown in fig. 1, the Base APK and Dynamic Feature APK each have a resource with a resource name of id_a and id_b, and a resource with a resource name of id_a in Dynamic Feature APK is required to be used in a layout file of Dynamic Feature APK. But the resource named as ID_A in the Base APK is mistakenly referenced in the referencing process due to negligence of a developer. Thus, a crash may occur at Dynamic Feature APK runtime. The only solution is currently to make modifications by specialized developers invading source code.
Disclosure of Invention
The embodiment of the invention provides a method and a device for eliminating error quotation control resources, which are used for solving the problems that in the prior art, a mode of modifying error quotation by manually invading source codes has higher requirements on operators and error quotation 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 error reference control resources, where the method includes:
acquiring an initial byte code generated by compiling a Java file;
adjusting rules for searching the control according to the control identification in the initial byte code; wherein the adjusted rule comprises: when the control is not found, adjusting the control mark 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 in the initial bytecode for finding a control according to a control identifier includes:
acquiring a carrier and a reference code for indicating a control identifier when a target method in the initial byte code is called; the target method is used for searching a control in the carrier according to the control identifier indicated by the reference code;
searching for a control in the carrier according to the control identifier indicated by the reference code;
when the control is not found, the control identification is redetermined according to the control name in the reference code; searching for a control in the carrier again according to the redetermined control identification;
and taking the control identification of the searched control as a return value of the target method.
Optionally, the step of redefining the control identifier according to the control name in the reference code includes:
searching a control identifier corresponding to the control name in the reference code in a basic android application program package resource library through a Java reflection mechanism;
and taking the control identifier corresponding to the searched control name in the reference code as a redetermined control identifier.
Optionally, after the step of searching for a control in the carrier again according to the redetermined control identification, the method further comprises:
when no control is found in the carrier, finding a control identifier corresponding to the control name in the reference code in all dynamic construction mode android application package resource libraries;
and searching the control in the carrier again according to the searched control identification.
Optionally, the step of searching for a control in the carrier includes:
according to the type of the carrier, calling findViewById methods under different types to search for a control in the carrier; wherein the types of the carrier at least comprise: popup windows, views, and windows.
Optionally, before the step of obtaining the carrier when the target method in the initial bytecode is called and the reference code for indicating the control identification, the method further includes:
and traversing the information in the initial byte code to determine the target method.
In a second aspect, an embodiment of the present invention further provides an apparatus for eliminating wrong reference to a control resource, where the apparatus includes:
the acquisition module is used for acquiring initial byte codes generated through Java file compiling;
the adjustment module is used for adjusting rules for searching the control according to the control identification in the initial byte code; wherein the adjusted rule comprises: when the control is not found, adjusting the control mark to find the control again; the controls indicated by the control identification used in each search have the same name;
and the generation module is used for generating an executable file according to the adjusted initial byte code.
Optionally, the adjusting module includes:
the acquisition unit is used for acquiring a carrier when the target method in the initial byte code is called and a reference code for indicating a control identifier; the target method is used for searching a control in the carrier according to the control identifier indicated by the reference code;
the first searching unit is used for searching the control in the carrier according to the control identifier indicated by the reference code;
the second searching unit is used for redefining the control identification according to the control name in the reference code when the control is not searched; searching for a control in the carrier again according to the redetermined control identification;
and the return unit is used for taking the control identification of the searched control as the return value of the target method.
Optionally, the second searching unit is specifically configured to search, through a Java reflection mechanism, a control identifier corresponding to a control name in the reference code in a Base APK resource library of the basic android application package; and taking the control identifier corresponding to the searched control name in the reference code as a redetermined control identifier.
Optionally, the apparatus further comprises:
the third searching unit is used for searching a control identifier corresponding to the control name in the reference code in the android application package Dynamic Feature APK resource library of all dynamic construction modes 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 is specifically configured to call a findtiewbyid method under different types according to the type of the carrier to search a control in the carrier; wherein the types of the carrier at least comprise: popup windows, views, and windows.
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.
In a third aspect, embodiments of the present invention also provide an electronic device including a memory, a processor, and a computer program stored on the memory and executable on the processor, the processor implementing the steps in the method of eliminating false reference control resources as described above when the computer program is executed.
In a fourth aspect, embodiments of the present invention also provide a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps in a method of eliminating false reference control resources as described above.
In the embodiment of the invention, the initial byte code generated by compiling Java files is acquired; and then adjusting rules in the initial byte code 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 rule includes: and when the control is not found, adjusting the control identifier to find the control again. The controls indicated by the control identifiers used in each search have the same names, namely the controls indicated by the control identifiers before and after adjustment have the same names. After the control resources with the same name are wrongly referenced, the control can be found by searching again, and the problem that the executable file generated later breaks down during execution is avoided. And generating an executable file according to the adjusted initial byte code. The adjusted initial bytecode has eliminated the impact of misreferencing control resources of the same name. Therefore, the executable file cannot crash due to wrong reference to control resources with the same name when being executed, and the problem of wrong reference is solved in advance before an 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 that are needed in the description of the embodiments of the present invention will be briefly described below, it being obvious that the drawings in the following description are only some embodiments of the present invention, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic diagram of a scenario in which a control resource is misreferenced;
FIG. 2 is a flowchart illustrating steps of a method for eliminating error reference control resources according to an embodiment of the present invention;
FIG. 3 is a flowchart illustrating steps for adjusting rules for finding a control according to a control identifier in an initial bytecode according to an embodiment of the present invention;
FIG. 4 is a process flow diagram of a method for eliminating false reference control resources provided by an embodiment of the present invention;
FIG. 5 is a block diagram of an apparatus for eliminating error reference control resources according to an embodiment of the present invention;
FIG. 6 is a block diagram of an adjustment 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 following description of the embodiments of the present invention will be made clearly and fully with reference to the accompanying drawings, in which it is evident that the embodiments described are some, but not all embodiments of the invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the 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 order of execution, and the order of execution of the processes should be determined by the functions and internal logic, and should not constitute any limitation on 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 error reference control resources, which is applied to a Dynamic Feature mode under a Android APP Bundle mechanism, and the method includes:
step 201, obtain the initial bytecode generated by compiling the Java file.
It should be noted that Java class generated by compiling a Java file may also be referred to as class file, i.e. initial bytecode. Wherein the number of class files is plural, preferably, all class files can be obtained, that is, all initial bytecodes generated by compiling Java files are obtained.
Since in the conventional method, it is difficult to modify the contents of a Java file or a class file during 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, so that the same purpose as the source code modification is achieved.
Step 202, a rule for searching the control according to the control identification in the initial byte code is adjusted.
It should be noted that the adjusted rules include: when the control is not found, adjusting the control mark to find the control again; the controls indicated by the control identifications used for each search have the same names. And if the control is found, the found identification of the control is returned, wherein the identification is the unique identification of the control, and the identifications of different controls are necessarily different. Preferably, the content of the initial byte code can be modified by a byte code modification technology, so that rules for searching the control according to the control identification in the initial byte code are adjusted.
And 203, generating an executable file according to the adjusted initial byte code.
It should be noted that the executable file is a file that can be identified, loaded and executed by the android platform virtual machine, i.e., a dex file. Specifically, the adjusted initial byte code generates a dex file through a dx command.
In the embodiment of the invention, the initial byte code generated by compiling Java files is acquired; and then adjusting rules in the initial byte code 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 rule includes: and when the control is not found, adjusting the control identifier to find the control again. The controls indicated by the control identifiers used in each search have the same names, namely the controls indicated by the control identifiers before and after adjustment have the same names. After the control resources with the same name are wrongly referenced, the control can be found by searching again, and the problem that the executable file generated later breaks down during execution is avoided. And generating an executable file according to the adjusted initial byte code. The adjusted initial bytecode has eliminated the impact of misreferencing control resources of the same name. Therefore, the executable file cannot crash due to wrong reference to control resources with the same name when being executed, and the problem of wrong reference is solved in advance before an application program generated according to the executable file runs.
As shown in fig. 3, based on the above 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 byte code is called and a reference code for indicating a control identification.
It should be noted that the target method may be determined by 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 method may be, for example, the findtiewbyid method. Execution of the reference code will obtain the control identification it indicates. For example, if the reference code is base.r.id.textview1, a control identifier corresponding to the control name textview1 will be obtained when the reference code is executed. The control names of the same control have a corresponding relation with the control identifications.
The carrier may be a certain view, a certain popup 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 popup 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.
And 302, searching the control in the carrier according to the control identification indicated by the reference code.
It should be noted that, if a 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 searching the control in the carrier, according to the type of the carrier, the findViewById method under different types can be called to search the control in the carrier; wherein, the carrier type at least comprises: popup windows, views, and windows. Of course, the type of the carrier can also be the Activity of one of the four android components, but is not limited to the Activity.
And 303, when the control is not found, re-determining the control identification according to the control name in the reference code, and finding the control in the carrier again according to the re-determined control identification.
It should be noted that, in the case that different controls have the same control name, since the control identifications of the different controls are necessarily different, when a corresponding control cannot be found in the carrier by using a certain control identification, the name of the control can be determined according to the control identification, and then the control identification of the control resource with the same name can be found by using the determined control name.
When the control identification is redetermined, the redetermined control identification and the control identification at the first searching time are required to correspond to the same control name, so that the control name is required to be determined first. The control name can be textview1 according to the control name contained in the reference code, if the reference code is base.R.id.textview 1; of course, the corresponding control name can also be directly searched in the initial byte code.
When the control identification is determined by the control name, a Java reflection mechanism can be utilized. Preferably, the step of redefining the control identifier according to the control name in the reference code includes:
searching a control identifier corresponding to the control name in the reference code in a Base APK resource library through a Java reflection mechanism; and taking the control identifier corresponding to the control name in the searched reference code as the redetermined control identifier.
If the control is not found yet, the control identification can be adjusted to continue searching. Specifically, after the step of searching the carrier for the control again according to the redetermined control identifier, the method further includes:
when the control is not found in the carrier again, finding the control identifier corresponding to the control name in the reference code in all Dynamic Feature APK resource libraries; and searching the control in the carrier again according to the searched control identification. And searching the control identification corresponding to the control name in the reference code in all Dynamic Feature APK resource libraries by utilizing a Java reflection mechanism.
And 304, taking the control identification of the searched 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 a control identifier of a control found by using the adjusted rule.
Referring to FIG. 4, a process flow diagram of a method of eliminating false references to control resources is shown in accordance with yet another embodiment of the present invention. In the Dynamic Feature mode, converting a class file generated by compiling Java files into a dex file; i.e. converting class0, class1 … into dex0, dex1 …. In the conversion process, traversing each class file, acquiring the call of the findViewById method by utilizing a byte code modification technology, and modifying the call into the findViewById realized by the plug-in. It can also be understood that the call stack intercepting each findtiewbyid method is replaced by a preset plug-in.
The findViewById realized by the plug-in is specifically: and acquiring parameters carried in the called findViewById method. Wherein the parameters include a carrier, a control identification (Identity document, abbreviated ID), and a control name. And then a distribution process is performed according to the type of the carrier. The carrier type at least comprises Activity, dialog (popup Window), window (Window), view (View). And each vector type corresponds to a respective findtiewbyid method.
Taking the carrier type as an 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 and acquiring a control identifier in the Base APK according to the control name, then continuously calling a findViewById method corresponding to the Activity, and continuously searching the corresponding control in the carrier according to the control identifier acquired by reflection. And if the corresponding control is found, returning the control identification of the found control. If the corresponding control is not found, the control identification is obtained in all Dynamic Feature APK in a reflection mode according to the control name, then the findViewById method corresponding to the Activity is continuously called, and the corresponding control is continuously found in the carrier according to the control identification obtained in the reflection mode. When the type of the carrier is Dialog, window, view, the processing procedure is similar to the processing procedure when the type of the carrier is Activity, and will not be described here again.
Having introduced the method for eliminating the error reference control resource provided by the embodiment of the invention, the device for eliminating the error reference control resource provided by the embodiment of the invention is described below with reference to the accompanying drawings.
Referring to fig. 5 and 6, the embodiment of the present invention further provides an apparatus for eliminating error reference control resources, where the apparatus includes:
an obtaining module 51, configured to obtain an initial bytecode generated by compiling a Java file;
the adjustment module 52 is configured to adjust a rule in the initial bytecode for searching for a control according to the control identifier; wherein the adjusted rule comprises: when the control is not found, adjusting the control mark to find the control again; the controls indicated by the control identification used in each search have the same name;
the generating module 53 is configured to generate an executable file according to the adjusted initial bytecode.
Optionally, the adjustment module 52 includes:
an obtaining unit 521, configured to obtain a carrier when the 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 identifier indicated by the reference code;
a first searching unit 522, configured to search for a control in the carrier according to the control identifier indicated by the reference code;
a second searching unit 523, configured to, when the control is not found, redefine the control identifier according to the control name in the reference code; searching the control again in the carrier according to the redetermined control identification;
and the return unit 524 is configured to take the control identifier of the found control as a return value of the target method.
Optionally, the second searching unit 523 is specifically configured to search, through a reflection mechanism of Java, a control identifier corresponding to a control name in the reference code in the Base APK resource library; and taking the control identifier corresponding to the control name in the searched reference code as the redetermined control identifier.
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 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 call the findtiewbyid method under different types to search for a control in the carrier according to the type of the carrier; wherein, the carrier type at least comprises: popup windows, views, and windows.
Optionally, the apparatus further comprises:
and the traversing module is used for traversing the information in the initial byte codes and determining a target method.
The device for eliminating the error reference control resource provided by the embodiment of the invention can realize each process of the method for eliminating the error reference control resource in the method embodiment of fig. 2 and 3, and is not repeated here for avoiding repetition.
In the embodiment of the invention, the acquisition module is used for acquiring the initial byte code generated by compiling the Java file. And the adjusting module is used for adjusting rules for 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 rule includes: and when the control is not found, adjusting the control identifier to find the control again. The controls indicated by the control identifiers used in each search have the same names, namely the controls indicated by the control identifiers before and after adjustment have the same names. After the control resources with the same name are wrongly referenced, the control can be found by searching again, and the problem that the executable file generated later breaks down during execution is avoided. And the generation module is used for generating the executable file according to the adjusted initial byte code. The adjusted initial bytecode has eliminated the impact of misreferencing control resources of the same name. Therefore, the executable file cannot crash due to wrong reference to control resources with the same name when being executed, and the problem of wrong reference is solved in advance before an application program generated according to the executable file runs.
In another aspect, an embodiment of the present invention further provides an electronic device, including a memory, a processor, a bus, and a computer program stored on the memory and capable of running on the processor, where the processor implements the steps in the method for eliminating the error reference control resource when executing the program.
For example, fig. 7 shows a schematic physical structure of an electronic device.
As shown in fig. 7, the electronic device may include: processor 710, communication interface (Communications Interface) 720, memory 730, and communication bus 740, wherein processor 710, communication interface 720, memory 730 communicate with each other via 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 for searching the control according to the control identification in the initial byte code; wherein the adjusted rule comprises: when the control is not found, adjusting the control mark 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.
Further, the logic instructions in the memory 730 described above may be implemented in the form of software functional units and may be stored in a computer readable storage medium when sold or used as a stand alone product. Based on this understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, comprising several instructions for causing a computer device (which may be a personal computer, a server, a network device, etc.) to perform 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, random Access Memory), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
In yet another aspect, embodiments of the present invention further provide a computer readable storage medium having stored thereon a computer program, which when executed by a processor, is implemented to perform the method for eliminating error reference control resources provided by the above embodiments, for example, including:
acquiring an initial byte code generated by compiling a Java file;
adjusting rules for searching the control according to the control identification in the initial byte code; wherein the adjusted rule comprises: when the control is not found, adjusting the control mark 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 apparatus embodiments described above are merely illustrative, wherein the elements illustrated as separate elements may or may not be physically separate, and the elements shown as elements may or may not be physical elements, may be located in one place, or may be distributed over a plurality of network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art will understand and implement the present invention without undue burden.
From the above description of the embodiments, it will be apparent to those skilled in the art that the embodiments may be implemented by means of software plus necessary general hardware platforms, or of course may be implemented by means of hardware. Based on this understanding, the foregoing technical solution may be embodied essentially or in a part contributing to the prior art in the form of a software product, which may be stored in a computer readable storage medium, such as ROM/RAM, a magnetic disk, an optical disk, etc., including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method described in the respective embodiments or some parts of the embodiments.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solution of the present invention, and are not limiting; although the 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 scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims (8)

1. A method for eliminating wrong references to control resources, which is applied to a Dynamic Feature mode under a Android APP Bundle mechanism, the method comprising:
acquiring an initial byte code generated by compiling a Java file;
adjusting rules for searching the control according to the control identification in the initial byte code; wherein the adjusted rule comprises: when the control is not found, adjusting the control mark to find the control again; the controls indicated by the control identification used in each search have the same name;
generating an executable file according to the adjusted initial byte code;
the step of adjusting the rule of searching the control according to the control identification in the initial byte code comprises the following steps:
acquiring a carrier and a reference code for indicating a control identifier when a target method in the initial byte code is called; the target method is used for searching a control in the carrier according to the control identifier indicated by the reference code;
searching for a control in the carrier according to the control identifier indicated by the reference code;
when the control is not found, the control identification is redetermined according to the control name in the reference code; searching for a control in the carrier again according to the redetermined control identification;
and taking the control identification of the searched control as a return value of the target method.
2. The method of claim 1, wherein the step of redefining a control identity from a control name in the reference code comprises:
searching a control identifier corresponding to the control name in the reference code in a Base APK resource library of a basic android application program package through a Java reflection mechanism;
and taking the control identifier corresponding to the searched control name in the reference code as a redetermined control identifier.
3. The method of claim 1, wherein after the step of searching for a control in the carrier again based on the redetermined control identification, the method further comprises:
when no control is found in the carrier again, finding a control identifier corresponding to the control name in the reference code in all dynamic construction mode android application program package Dynamic FeatureAPK resource libraries;
and searching the control in the carrier again according to the searched control identification.
4. The method of claim 1, wherein the step of finding a control in the carrier comprises:
according to the type of the carrier, calling findViewById methods under different types to search for a control in the carrier; wherein the types of the carrier at least comprise: popup windows, views, and windows.
5. The method of claim 1, wherein prior to the step of obtaining the carrier at the time the target method in the initial bytecode is invoked and the reference code for indicating the control identification, the method further comprises:
and traversing the information in the initial byte code to determine the target method.
6. An apparatus for eliminating wrong references to control resources, wherein the apparatus is applied in a Dynamic Feature mode under a Android APP Bundle mechanism, and the apparatus comprises:
the acquisition module is used for acquiring initial byte codes generated through Java file compiling;
the adjustment module is used for adjusting rules for searching the control according to the control identification in the initial byte code; wherein the adjusted rule comprises: when the control is not found, adjusting the control mark to find the control again; the controls indicated by the control identification used in each search have the same name;
the generation module is used for generating an executable file according to the adjusted initial byte code;
the adjustment module includes:
the acquisition unit is used for acquiring a carrier when the target method in the initial byte code is called and a reference code for indicating a control identifier; the target method is used for searching a control in the carrier according to the control identifier indicated by the reference code;
the first searching unit is used for searching the control in the carrier according to the control identifier indicated by the reference code;
the second searching unit is used for redefining the control identification according to the control name in the reference code when the control is not searched; searching for a control in the carrier again according to the redetermined control identification;
and the return unit is used for taking the control identification of the searched control as the return value of the target method.
7. 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 performs the steps of the method of eliminating false reference control resources as claimed in any one of claims 1 to 5.
8. A computer readable storage medium, having stored thereon a computer program which, when executed by a processor, implements the steps of the method of eliminating false reference control resources of any of claims 1 to 5.
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 CN111694730A (en) 2020-09-22
CN111694730B true 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 (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103186740A (en) * 2011-12-27 2013-07-03 北京大学 Automatic detection method for Android malicious software
CN110674025A (en) * 2018-07-03 2020-01-10 百度在线网络技术(北京)有限公司 Interactive behavior monitoring method and device and computer equipment

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7533141B2 (en) * 2003-01-24 2009-05-12 Sun Microsystems, Inc. System and method for unique naming of resources in networked environments
US7376534B2 (en) * 2004-05-21 2008-05-20 Bea Systems, Inc. Watches and notifications
CN103970514B (en) * 2013-01-28 2018-04-06 腾讯科技(深圳)有限公司 The information acquisition method and device of Android application program installation kit
CN107092494B (en) * 2016-02-18 2020-09-01 腾讯科技(深圳)有限公司 Method and device for accessing APK (android Package) resource
CN106569880B (en) * 2016-11-07 2020-12-22 Tcl科技集团股份有限公司 Method and system for dynamically sharing resources between Android applications

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103186740A (en) * 2011-12-27 2013-07-03 北京大学 Automatic detection method for Android malicious software
CN110674025A (en) * 2018-07-03 2020-01-10 百度在线网络技术(北京)有限公司 Interactive behavior monitoring method and device and computer equipment

Also Published As

Publication number Publication date
CN111694730A (en) 2020-09-22

Similar Documents

Publication Publication Date Title
US20190324772A1 (en) Method and device for processing smart contracts
EP3128421B1 (en) Method, device, and system for achieving java application installation by cloud compilation
CN107967139B (en) Hot updating method and device for game
US10635812B2 (en) Method and apparatus for identifying malicious software
CN113467980B (en) Log output method, device and system and embedded equipment
CN111679852B (en) Detection method and device for conflict dependency library
CN112612502A (en) Patch generation method, device, equipment and storage medium
CN112882732A (en) Method and device for updating function codes in Software Development Kit (SDK)
CN113220326B (en) Intelligent contract upgrading method and block chain system
US20040216138A1 (en) Method and system for processing input from a command line interface
CN111694730B (en) Method and device for eliminating error reference control resource
CN112668008A (en) Method for realizing dynamic system call hijacking based on LSM
CN111625225A (en) Program specified data output method and device
CN113641389B (en) Software upgrading method, device and equipment based on OpenCPU
CN116342283A (en) Trusted intelligent contract implementation method, device, equipment and readable storage medium
CN113220327B (en) Intelligent contract upgrading method and block chain system
CN112148318B (en) Application package release method, application method, device, medium, server and equipment
CN114706586A (en) Code compiling method, code running method, code compiling device, code running device, computer equipment and storage medium
CN114253615B (en) Method and device for setting bootstrap program, electronic equipment and storage medium
CN114371852B (en) Compiling method and device
CN111506301B (en) Method for bypassing system restriction reflection call and related equipment
CN113672238B (en) Operation method, device and equipment based on real-time operating system modularized management
CN114416219B (en) System function calling method, device, electronic equipment and readable medium
CN112256324B (en) Method and device for processing files in android application program construction process
CN111045657B (en) Program code operation method and device, and 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