An integrated source code-free debugging method based on Android operating system

Through ADB media and JDWP, combined with decompilation module, an integrated source-free debugging method on the Android operating system is realized, solving the problems of low efficiency of existing tools and difficulty in identifying variable types, and providing automation and source-level debugging functions, which are significantly Improve debugging efficiency.

CN114090440BActive Publication Date: 2024-11-12GUANGZHOU LIANAN TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111381511.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-21
Publication Date
2024-11-12
Estimated Expiration
2041-11-21

AI Technical Summary

Technical Problem

The existing Android program debugging tools lack automated and graphical interfaces, resulting in low debugging efficiency, especially in the absence of variable type information in the case of passive code, resulting in difficulty in debugging.

Method used

Through the ADB media, the software package is automatically installed, activated debugging mode, breakpoint setting and variable recognition are realized. Combined with JDWP and decompilation modules, it provides automated debugging process and source-level debugging functions, and supports breakpoint code execution and variable content rewriting.

Benefits of technology

It realizes an integrated source-free debugging method on the Android operating system, automatically builds a debugging environment, improves debugging efficiency, and provides important auxiliary functions, performing better than market products.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114090440B_ABST
    Figure CN114090440B_ABST
Patent Text Reader

Abstract

The invention discloses an integrated source code-free debugging method based on an Android operating system, comprising the following steps: 1) intelligent installation and updating of a program to be debugged; 2) activation of a debugging mode; turning on a debugging switch at a system level by directly modifying an environment variable ro.debuggable in the system; 3) startup and configuration of the program to be debugged; 4) variable type identification; 5) source code-level debugging based on decompilation; the method provides a complete set of automated debugging processes, using ADB as a medium, and fully automatically realizing software installation, activation of a debugging mode, startup and attachment to the program to be debugged, breakpoint setting, breakpoint variable identification, etc., in the case of only a software package but no software source code, and in the process of manual debugging, it also has functions such as supporting breakpoint code execution and rewriting variable content.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to an integrated source code-free debugging method based on an Android operating system. Background Art

[0002] Since the advent of Android in 2008, its market share has been steadily increasing, and it has directly led to the withdrawal of mobile operating systems such as Symbian and Windows Phone from the stage of history. However, such a mainstream mobile operating system has not had a relatively easy-to-use debugging tool for Android programs for many years. At present, the field of Android source code-free debugging is still in a relatively primitive and crude state. From a mobile phone and a computer to the actual start of debugging, there are various cumbersome steps in between. From ADB connection, to the opening of the debugging port, the start of the debugging mode, the installation of the program to be debugged, etc., each step consumes the debugger's energy and time. Even if the debugging is officially started, the lack of variable type information will make debugging difficult in the absence of source code debugging. The existing technical solutions not only require the debugger to do various preparations in advance, but also there is no graphical interface during the debugging process. Each debugging operation requires the debugger to directly enter the corresponding debugging command in the terminal, and the debugging output can only be displayed in the terminal, and multi-window interaction is not possible. Various factors lead to low debugging efficiency.

[0003] Therefore, it is necessary to seek a debugging method that can automatically build the debugging environment required by researchers and provide various important auxiliary functions during the debugging process. Summary of the invention

[0004] In view of this, the purpose of the present invention is to provide an automated debugging method which uses ADB as a medium and can fully automatically realize software installation, activation of debugging mode, startup and attachment to the program to be debugged, breakpoint setting, breakpoint variable identification, etc. in the case of only a software package but no software source code, and during the manual debugging process, it also has functions such as supporting breakpoint code execution and rewriting variable content.

[0005] In order to solve the above technical problems, the technical solution of the present invention is:

[0006] An integrated source code-free debugging method based on an Android operating system comprises the following steps:

[0007] 1) Intelligent installation and update of programs to be debugged;

[0008] Calculate the hash value of the program to be debugged and compare it with the hash value of the program already in the system. If and only if the two hash values ​​are not equal, that is, the content of the program to be debugged has changed, the new program to be debugged will replace the old program and be installed on the target device;

[0009] 2) Activate debug mode;

[0010] By directly modifying the system environment variable ro.debuggable, the debugging switch is turned on at the system level. This can avoid any changes to the software package, ensure the integrity of the software package, and successfully debug the program at the same time;

[0011] 3) Startup and configuration of the program to be debugged;

[0012] When the debugger is successfully attached, wait for several hundred milliseconds and assume that the debugging-related configuration has been completed during this time. Unsuspend the program and set breakpoints and other operations through JDWP in this short window according to the user's settings in the interface in advance to ensure that the timing will not be delayed.

[0013] 4) Variable type identification;

[0014] The function should be divided into blocks so that each block of code will be executed without omission once the program executes to the block, except when an exception is thrown. After the function blocks are divided, these blocks should be connected according to the transfer direction of the execution flow to build the relationship between the blocks. After the block division is completed, static single assignment should be performed. SSA generally uses subscripts to represent new variables. Whenever a variable at the Dalvik level is assigned, the subscript counter of this register will be increased by one, and the current counter value will be used as the subscript of the new SSA variable. The control flow in the form of Dalvik bytecode has different registers and variables in the function. Equivalently, there is a dynamic mapping relationship between variables and registers; in the process of constructing the SSA form of the function, SSA introduces a function called Phi, which is used to indicate the selection from these two different registers and introduce a new SSA variable. When the Phi function is fully and reasonably added to the SSA chart, the construction of SSA is completed. Given a function offset and a register, the variable type corresponding to the value of this register at this time can be found. During the debugging process, breakpoints can be set at will, and the variable type of each register can be analyzed in real time after the breakpoint is triggered, and the effective value of each register can be read in real time with the debugging protocol;

[0015] 5) Source code level debugging based on decompilation;

[0016] With the decompilation module, source code level debugging based on the decompilation results can be realized. As long as there is a mapping relationship between the Dalvik control flow and the decompiled source code, source code level debugging can be realized, and seamless switching between source code level debugging and Dalvik instruction level debugging can be achieved.

[0017] The technical effects of the present invention are mainly reflected in the following aspects: the present invention provides a complete set of automated debugging processes, using ADB as the medium, and in the case of only a software package but no software source code, can fully automatically realize software installation, activation of debugging mode, startup and attachment to the program to be debugged, breakpoint setting, breakpoint variable identification, etc., and in the manual debugging process, it also has functions such as supporting breakpoint code execution and rewriting variable content. The debugger designed according to this solution performs better than various products on the market, can automatically build the debugging environment required by researchers, and provide various important auxiliary functions during the debugging process. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 The present invention is a flow chart of an integrated source code-free debugging method based on the Android operating system. DETAILED DESCRIPTION

[0019] The following is combined with Figure 1 , the specific implementation methods of the present invention are further described in detail to make the technical solution of the present invention easier to understand and grasp.

[0020] Example

[0021] Android is one of the mainstream mobile phone operating systems today. Android Debug Bridge (ADB) is the most commonly used debugging suite in the Android operating system. It provides a variety of practical functions such as software installation and uninstallation, shell operations, port forwarding, etc. The bytecode supported by Android, called Dalvik, refers to the bytecode of the Java Virtual Machine (JVM), which changes the stack structure into a register-based instruction set. Therefore, Dalvik and JVM have many things in common. The debugging protocol Java Debug Wire Protocol (JDWP) used by the Java Virtual Machine is also adopted by Android. Even with the development of Android, the Dalvik virtual machine has been replaced by the Android Runtime (ART). Dalvik, as a set of instruction sets, still supports every Android program, and JDWP has never left the stage.

[0022] An integrated source code-free debugging method based on an Android operating system comprises the following steps:

[0023] 1) Intelligent installation and update of the program to be debugged

[0024] The content of the program to be debugged is not fixed. In some cases, the debugger may patch the program to be debugged. In this case, the patched program needs to be reinstalled on the Android device. However, the program may remain unchanged. If it needs to be reinstalled before each debugging, the installation time of minutes will greatly reduce the debugging efficiency. This solution will calculate the hash value of the program to be debugged and compare it with the hash value of the program already in the system. If and only if the two hash values ​​are not equal, that is, the content of the program to be debugged has changed, the new program to be debugged will replace the old program and be installed on the target device. This not only saves the time overhead caused by unnecessary installation, but also ensures that the debugger can debug to the latest version.

[0025] 2) Activate debug mode

[0026] Generally speaking, the release version of the software package will not mark itself as debuggable in its manifest.xml file. If an Android program is not marked as debuggable, then the program cannot be debugged. For this situation, there are generally two solutions. One is to repackage. The advantage of this method is good compatibility. For any software package, the debug mode can be activated by patching the manifest.xml. However, this method has great limitations in reality. Android requires that all software packages need to be signed, and the signature is linked to the integrity of the software package, so patching means that the entire software package needs to be re-signed. There are many software on the market that will check the signature of their own software package during operation to ensure that they have not been tampered with, and this repackaging method will trigger this detection. This solution adopts another method, by directly modifying the system environment variable ro.debuggable, to turn on the debugging switch at the system level. This treatment can avoid any changes to the software package, ensure the integrity of the software package, and successfully debug the program at the same time.

[0027] 3) Startup and configuration of the program to be debugged

[0028] On the surface, to start a program, you only need to send a command through ADB to start the target program. However, from the debugging perspective, there are many cumbersome steps from the start of the program to the debugged state. Generally speaking, debuggers want to interrupt the program as early as possible to prevent the code fragment to be debugged from running out at the moment the program starts running. In this case, it is necessary to start the program to be debugged in pause mode through ADB. The program started in this mode is in a suspended state and waits for the debugger to attach. However, just waiting for attachment is not enough. Even if it is attached, if there is no breakpoint, the program will run away directly. In addition, due to the limitations of the debugging protocol, the Android device has no means to know that the debugger has made all preparations for debugging. Therefore, on the device side, when the debugger is successfully attached, it will only wait for hundreds of milliseconds and assume that the configuration related to debugging has been completed during this time, and unsuspend the program. This solution will set breakpoints and other operations through JDWP in this short window according to the settings made by the user in the interface in advance to ensure that the timing will not be delayed.

[0029] 4) Variable type identification

[0030] The difficulty of debugging Dalvik programs lies in determining the variable type. When debugging a program based on Dalvik bytecode, if you want to obtain the content of a register through the debugging protocol, the debugger needs to provide the variable type of the variable. Programs with debugging information compiled in conventional development come with this information, so various variables can be displayed smoothly during the debugging process. However, for various reasons, the debugger may not have this debugging information. In this case, if you want to obtain a register, there are only two options left.

[0031] Solution 1 does not consider the program context and directly specifies the variable type as a primitive data type. Although this approach can obtain the value in this register, the information obtained is likely to be meaningless. For example, this register actually stores an object, but the debugger reads it through the primitive type int, then the register value obtained is a pointer to the above object. This is meaningless to researchers because what researchers want must be the object it points to, not the pointer itself.

[0032] Another solution is to first analyze and understand the program context and find out the variable type of this register at this moment, and then use the debugging protocol to obtain the contents of the register according to this variable type. This approach can correctly return the content that the researcher wants to obtain. However, the manpower cost of this approach is very high. Although the variable type of a single register at a single position in a function can be solved by human analysis, debugging is dynamic, and the location where the program is executed changes at any time, and the variable type also changes accordingly. What's more, there are multiple registers. Even if you can tolerate high-intensity human analysis, it is difficult to guarantee that human errors will not occur during the analysis process.

[0033] If the variable type is directly specified as an object, then when the register actually stores the original type, the server side of the debugging protocol will treat the value of this register as an object pointer to read the object content. Since the value of this register itself is not a legal pointer, in most cases it will cause illegal memory operations and cause the debugged program to crash directly. Even in the extremely low probability that the value of this register happens to be a valid pointer in fact, the object content read out is also wrong. Therefore, this solution does not work.

[0034] The first step of the analysis is to divide the function into blocks so that each block of code will be executed without omission once the program executes to the block, except for the case where an exception is thrown. There are three main situations in Dalvik that can change the program execution process. The first is conditional jump, such as the if-eqz instruction. If the value of the source register is zero, it jumps to the target address. The second situation is the switch instruction. The packed-switch and sparse-switch in Dalvik can determine the target address of the jump by looking up the jump table according to the value of the source register. The third situation is the capture of exceptions. If a certain exception capture is registered somewhere inside the function (that is, the try block), and this exception is thrown here, then the execution of the function will be directly transferred from the place where the exception is thrown to the corresponding exception handling code. In the above several situations, the address reached when the function execution process changes is the entrance of a code block. When this code block executes to the entrance of the next code block, it means that this is the end of this code block. After dividing the function blocks, these blocks must be connected according to the transfer direction of the execution process to build the relationship between the blocks.

[0035] After the block division is completed, the static single assignment (SSA) process must be performed. In the SSA concept, a variable will be assigned once and only once, and each variable must be assigned before use. SSA generally uses subscripts to represent new variables. Whenever a variable (i.e. register) at the Dalvik level is assigned, the subscript counter of this register will be increased by one, and the current counter value will be used as the subscript of the new SSA variable. For example, "x=10; x=20;" will become "x1=10; x2=20".

[0036] In the control flow of Dalvik bytecode, the registers are not equivalent to the variables in the function. From the perspective of compilation, developers can theoretically define an unlimited number of variables, but in fact the number of valid registers is limited. In other words, there is a dynamic mapping relationship between variables and registers. For example, when the Dalvik compiler finds that a variable in a function is no longer used after executing to a certain point, even if the life cycle of this variable has not ended in the source code, the compiler's optimization process will identify this shorter life cycle in fact, and mark the corresponding register as free at the point where the variable actually ends. The actual life cycle of this variable at this stage, that is, from the last assignment of this variable to the end of its life, can be mapped to the register that stores it. If a new variable needs to be defined thereafter, even if the old variable is still alive from the perspective of the source code, the program will still occupy this register.

[0037] In the process of constructing the SSA form of a function, there is an extremely core concept, that is, the Phi function. If there is no jump in a function, then the construction of the SSA form is very simple. Whenever a variable is reassigned, the life cycle of this variable in the SSA ends, and a new variable is generated. However, if there are jumps and branches in the function, there will be a confluence in the function. If a register is assigned values ​​in two branches respectively, and then these two branches merge and are used, then at this confluence, it cannot be determined which branch the value of this register comes from. In this case, SSA introduces a function called Phi. Its function is to indicate a choice from these two different registers and introduce a new SSA variable.

[0038] For simple control flow graphs, it is obvious where the Phi function needs to be added. However, when the control flow has a certain complexity, it becomes difficult to find the place where the Phi function needs to be inserted. To solve this problem, we need the dominance frontier (DF) in graph theory. DF is a set of nodes. Given a node, its DF indicates that if the program wants to run to the immediate dominator (IDOM) of a DF node, then the program must first pass through the given node. This feature of DF matches the Phi function mentioned above. If node N defines a variable V, then query the DF of node N. If the DF corresponding to node N is not empty, insert the Phi function for each node in DF. The calculation of DF can refer to "Efficiently computing static single assignment form and the control dependence graph" (Cytron et al., 1991).

[0039] When Phi functions are added to the SSA graph in sufficient and reasonable ways, the construction of SSA is complete. The goal at this stage is to find the place where the content of this register is defined at this moment, given a function offset and a register. Since the register is used at this position, it is possible to directly know the variable subscript of the register used here in SSA, and find the definition from SSA through this subscript.

[0040] When the definition and use of the variable can find the reference relationship through SSA, the next step is to officially start the processing of the variable type. After finding the definition through SSA, there are two situations for the content on the right side of the equal sign in the assignment statement, the type can be determined or the type cannot be determined. For the former, for example, if the variable definition comes from the Dalvik instruction const, then the type of this variable is the native integer type. If it comes from instructions such as move-result-object or new-instance, then the type of this variable is an object rather than a native variable type. As for the case where the type cannot be determined, the right side of the assignment statement is a Phi function. In this case, it is necessary to recursively process the parameters in the Phi function and query the definition of each variable appearing in the parameter again. In this case, there will be multiple definitions found in the end. For example, switch is used in the source code, and the same variable is assigned in each case block, and this variable is used after the entire switch is completed. Then in SSA, there is a Phi function in the common successor node of each case node corresponding to switch, and the variables contained in its parameters are respectively derived from the assignment statements in these case nodes. If the definitions of these variables all use the same variable type, then we can be sure that the type of the variable returned by Phi is consistent with the types of its parameters. In theory, when the types of the variables of the Phi function parameters are not consistent, the type of the variable returned by Phi cannot be determined. However, in fact, the compiler itself also needs to determine the type of a variable, otherwise the program may crash. Therefore, under normal circumstances, the types of the definitions obtained by this recursive search should be consistent.

[0041] At this point, the entire analysis and processing flow ends. Given a function offset and a register, the above process can be used to find the variable type corresponding to the value of this register at this time. During the debugging process, breakpoints can be set at will, and the variable type of each register can be analyzed in real time after the breakpoint is triggered. The effective value of each register can be read in real time with the debugging protocol, which effectively improves the debugging efficiency.

[0042] 5) Source code debugging based on decompilation

[0043] In conjunction with another supporting decompilation module, this solution can implement source-level debugging based on decompilation results. As long as there is a mapping relationship between Dalvik control flow and decompiled source code, this solution can implement source-level debugging and can seamlessly switch between source-level debugging and Dalvik instruction-level debugging.

[0044] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above and that the present invention can be implemented in other specific forms without departing from the spirit or essential features of the present invention. Therefore, the embodiments should be considered exemplary and non-restrictive in all respects, and the scope of the present invention is defined by the appended claims rather than the above description, and it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims be included in the present invention.

[0045] In addition, it should be understood that although the present specification is described according to implementation modes, not every implementation mode contains only one independent technical solution. This description of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment may also be appropriately combined to form other implementation modes that can be understood by those skilled in the art.

Claims

1. An integrated source code-free debugging method based on the Android operating system, characterized in that: The following steps are involved: 1) Intelligent installation and update of the program to be debugged; Calculate the hash value of the program to be debugged and compare it with the hash value of the program already in the system. If and only if the two hash values ​​are not equal, that is, the content of the program to be debugged has changed, the new program to be debugged will replace the old program and be installed on the target device; 2) Activate debug mode; By directly modifying the system environment variable ro.debuggable, turn on the debugging switch at the system level; 3) Startup and configuration of the program to be debugged; When the debugger is successfully attached, it waits for several hundred milliseconds and assumes that the debugging-related configuration has been completed during this time. It then unsuspends the program and sets breakpoints through JDWP in this short window according to the user's settings in the interface. 4) Variable type identification; The function should be divided into blocks so that each code block will be executed without omission once the program executes to the block, except when an exception is thrown. After the function blocks are divided, these blocks should be connected according to the transfer direction of the execution flow to build the relationship between the blocks. After the block division is completed, static single assignment should be performed. SSA uses subscripts to represent new variables. Whenever a variable at the Dalvik level is assigned, the subscript counter of this register will be increased by one, and the current counter value will be used as the subscript of the new SSA variable. The control flow in the form of Dalvik bytecode has different registers and variables in the function. Equivalently, there is a dynamic mapping relationship between variables and registers; in the process of constructing the SSA form of the function, SSA introduces a function called Phi, which is used to indicate the selection from these two different registers and introduce a new SSA variable. When the Phi function is fully and reasonably added to the SSA chart, the construction of SSA is completed. Given a function offset and a register, find out the variable type corresponding to the value of this register at this time. During the debugging process, breakpoints can be set at will, and the variable types of each register can be analyzed in real time after the breakpoint is triggered, and the effective values ​​of each register can be read in real time in conjunction with the debugging protocol; 5) Source code level debugging based on decompilation; With the decompilation module, source code level debugging based on the decompilation results can be realized. As long as there is a mapping relationship between the Dalvik control flow and the decompiled source code, source code level debugging can be realized, and seamless switching between source code level debugging and Dalvik instruction level debugging can be achieved.