HDC management and control method and device
By compiling the stripped code blocks in the HDC native code into a shared code library and switching calls according to the device status, the problem of low efficiency in the use of HDC tools is solved, and the flexibility of openness and closure of functions is achieved to meet the needs of different user ends.
Patent Information
- Application Number
- CN202410971881.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-19
- Publication Date
- 2024-11-05
AI Technical Summary
Existing HDC tools are unable to effectively utilize their capabilities for development, resulting in users not being able to make full use of their interactive capabilities.
By marking the code in the HDC native code that meets the requirements of instruction control as stripped code, stripping it and compiling it into a shared code library, switching different shared code library calls according to the device status, realizing the openness and closure of functions.
It meets the needs of HDC functions of different user terminals. The HDC functions are not fully open in the user state, while the functions are completely open in the development side state, improving the efficiency of function utilization.
Smart Images

Figure CN118897679A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer communication technology, and in particular to a method and device for controlling an HDC. Background Art
[0002] HDC (OpenHarmony Device Connector) is a command line tool for developers to use for debugging. This tool can be used to interact with the development machine or simulator on Windows, Linux, MacOS and other systems.
[0003] However, since HDC has powerful interactive functions, fully opening up the HDC function will allow users to modify the system through the HDC function. If the HDC function is not fully opened, the development end will not be able to fully utilize the HDC function. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide a method and device for controlling an HDC, so as to solve the problem that the HDC function cannot be effectively utilized for development.
[0005] In order to solve the above technical problems, the technical solution adopted by the present invention is:
[0006] A method for controlling HDC, comprising:
[0007] According to the instruction control requirement, mark the code in the HDC native code that meets the instruction control requirement as stripped code, and mark the code that is not marked as the stripped code as remaining code;
[0008] Stripping the stripping code in the HDC native code to obtain a stripping code block and a remaining code block;
[0009] Compiling the stripped code blocks into a first shared code library, and compiling the remaining code blocks into a second shared code library;
[0010] The method of calling the HDC native code through the native interface is changed to calling the first shared code library or the second shared code library through a library loading function;
[0011] Setting the default state to a normal mode, in which the second shared code library is called through the library loading function;
[0012] Determine whether a mode switching instruction is received, and if so, switch the normal mode to a special mode; in the special mode, call the first shared code library through the library loading function.
[0013] In order to solve the above technical problems, another technical solution adopted by the present invention is:
[0014] A control device for HDC includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program:
[0015] According to the instruction control requirement, mark the code in the HDC native code that meets the instruction control requirement as stripped code, and mark the code that is not marked as the stripped code as remaining code;
[0016] Stripping the stripping code in the HDC native code to obtain a stripping code block and a remaining code block;
[0017] Compiling the stripped code blocks into a first shared code library, and compiling the remaining code blocks into a second shared code library;
[0018] The method of calling the HDC native code through the native interface is changed to calling the first shared code library or the second shared code library through a library loading function;
[0019] Setting the default state to a normal mode, in which the second shared code library is called through the library loading function;
[0020] Determine whether a mode switching instruction is received, and if so, switch the normal mode to a special mode; in the special mode, call the first shared code library through the library loading function.
[0021] The beneficial effect of the present invention lies in that the code that meets the instruction control requirements in the HDC native code is stripped, and the stripped code blocks and the remaining code blocks are respectively compiled into the form of shared code libraries, and then different shared code libraries are called through the library loading function according to the current state of the device, so that when the device is in user use, it is in normal mode and cannot call the first shared code library, that is, the HDC function is not fully open; while when the device is in development end use, it is in special mode and can call the first shared code library and the second shared code library, that is, the HDC function is fully open, thereby meeting the use requirements of different users for the HDC function. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 This is a flow chart of the steps of a method for controlling HDC in an embodiment of the present invention;
[0023] Figure 2 It is a schematic diagram of native HDC communication in related technology;
[0024] Figure 3 A communication principle diagram of a method for controlling an HDC in an embodiment of the present invention;
[0025] Figure 4 Schematic diagram of the structure of a HDC control device in an embodiment of the present invention. DETAILED DESCRIPTION
[0026] In order to explain the technical content, achieved objectives and effects of the present invention in detail, the following is an explanation in combination with the implementation modes and the accompanying drawings.
[0027] Please refer to Figure 1 , a method for controlling HDC, comprising:
[0028] According to the instruction control requirement, mark the code in the HDC native code that meets the instruction control requirement as stripped code, and mark the code that is not marked as the stripped code as remaining code;
[0029] Stripping the stripping code in the HDC native code to obtain a stripping code block and a remaining code block;
[0030] Compiling the stripped code blocks into a first shared code library, and compiling the remaining code blocks into a second shared code library;
[0031] The method of calling the HDC native code through the native interface is changed to calling the first shared code library or the second shared code library through a library loading function;
[0032] Setting the default state to a normal mode, in which the second shared code library is called through the library loading function;
[0033] Determine whether a mode switching instruction is received, and if so, switch the normal mode to a special mode; in the special mode, call the first shared code library and the second shared code library through the library loading function.
[0034] From the above description, it can be seen that the beneficial effect of the present invention is that: by stripping the code that meets the instruction control requirements in the HDC native code, and compiling the stripped code blocks and the remaining code blocks into the form of shared code libraries, respectively, and then calling different shared code libraries through the library loading function according to the current state of the device, the device is in normal mode when it is used by the user, and the first shared code library cannot be called, that is, the HDC function is not fully open; while the device is in a special mode when it is used by the development end, and the first shared code library and the second shared code library can be called, that is, the HDC function is fully open, thereby meeting the usage requirements of different users for the HDC function.
[0035] Further, setting the default state to the normal mode includes:
[0036] Outputting the second shared code library into a system image package by compiling a script;
[0037] The second shared code library in the system image package is called in the normal mode.
[0038] As can be seen from the above description, different macros can be used to control the compilation of the second shared code library into the system image package through the compilation script, so that the second shared code library in the system image package can be directly called in the default state.
[0039] Further, the determining whether a state switching instruction is received includes:
[0040] A switching tool that authenticates and identifies access through a preset network protocol;
[0041] The mode switching instruction sent by the switching tool is received through the preset network protocol.
[0042] From the above description, it can be seen that when the working mode of the device needs to be switched, it is necessary to use a preset switching tool to implement it. The mode switching operation can only be performed after the switching tool and the device are mutually authenticated and identified through a preset network protocol, thereby improving device security.
[0043] Furthermore, before receiving the mode switching instruction sent by the switching tool through the preset network protocol, the method further includes:
[0044] The mode switching instruction is encrypted by the switching tool;
[0045] The switching of the normal mode to the special mode comprises:
[0046] The mode switching instruction is decrypted, and the decrypted mode switching instruction is verified. If the verification is passed, the normal mode is switched to the special mode.
[0047] From the above description, it can be seen that when the switching tool sends the mode switching instruction to the device, the mode switching instruction is encrypted to prevent the mode switching instruction from being intercepted and modified during the sending process; and after the device receives the mode switching instruction, it is decrypted and verified. Only when the verification instruction is legal, the mode switch is performed, thereby improving the security of the device.
[0048] Furthermore, it also includes a mode identification bit as well as a normal mode identification and a special mode identification;
[0049] The switching of the normal mode to the special mode comprises:
[0050] The special mode flag is written into the mode flag bit.
[0051] It can be seen from the above description that the switching between the normal mode and the special mode is achieved by setting the mode identification bit and writing the mode identification bit through the normal mode identification or the special mode identification.
[0052] Another embodiment of the present invention provides a control device for HDC, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program:
[0053] According to the instruction control requirement, mark the code in the HDC native code that meets the instruction control requirement as stripped code, and mark the code that is not marked as the stripped code as remaining code;
[0054] Stripping the stripping code in the HDC native code to obtain a stripping code block and a remaining code block;
[0055] Compiling the stripped code blocks into a first shared code library, and compiling the remaining code blocks into a second shared code library;
[0056] The method of calling the HDC native code through the native interface is changed to calling the first shared code library or the second shared code library through a library loading function;
[0057] Setting the default state to a normal mode, in which the second shared code library is called through the library loading function;
[0058] Determine whether a mode switching instruction is received, and if so, switch the normal mode to a special mode; in the special mode, call the first shared code library and the second shared code library through the library loading function.
[0059] From the above description, it can be seen that the beneficial effect of the present invention is that: by stripping the code that meets the instruction control requirements in the HDC native code, and compiling the stripped code blocks and the remaining code blocks into the form of shared code libraries, respectively, and then calling different shared code libraries through the library loading function according to the current state of the device, the device is in normal mode when it is used by the user, and the first shared code library cannot be called, that is, the HDC function is not fully open; while the device is in a special mode when it is used by the development end, and the first shared code library and the second shared code library can be called, that is, the HDC function is fully open, thereby meeting the usage requirements of different users for the HDC function.
[0060] Further, setting the default state to the normal mode includes:
[0061] Outputting the second shared code library into a system image package by compiling a script;
[0062] The second shared code library in the system image package is called in the normal mode.
[0063] As can be seen from the above description, different macros can be used to control the compilation of the second shared code library into the system image package through the compilation script, so that the second shared code library in the system image package can be directly called in the default state.
[0064] Further, the determining whether a state switching instruction is received includes:
[0065] A switching tool that authenticates and identifies access through a preset network protocol;
[0066] The mode switching instruction sent by the switching tool is received through the preset network protocol.
[0067] From the above description, it can be seen that when the working mode of the device needs to be switched, it is necessary to use a preset switching tool to implement it. The mode switching operation can only be performed after the switching tool and the device are mutually authenticated and identified through a preset network protocol, thereby improving device security.
[0068] Furthermore, before receiving the mode switching instruction sent by the switching tool through the preset network protocol, the method further includes:
[0069] The mode switching instruction is encrypted by the switching tool;
[0070] The switching of the normal mode to the special mode comprises:
[0071] The mode switching instruction is decrypted, and the decrypted mode switching instruction is verified. If the verification is passed, the normal mode is switched to the special mode.
[0072] From the above description, it can be seen that when the switching tool sends the mode switching instruction to the device, the mode switching instruction is encrypted to prevent the mode switching instruction from being intercepted and modified during the sending process; and after the device receives the mode switching instruction, it is decrypted and verified. Only when the verification instruction is legal, the mode switch is performed, thereby improving the security of the device.
[0073] Furthermore, it also includes a mode identification bit as well as a normal mode identification and a special mode identification;
[0074] The switching of the normal mode to the special mode comprises:
[0075] The special mode flag is written into the mode flag bit.
[0076] It can be seen from the above description that the switching between the normal mode and the special mode is achieved by setting the mode identification bit and writing the mode identification bit through the normal mode identification or the special mode identification.
[0077] The HDC control method and device provided by the present invention can be applied to Hongmeng device terminals with HDC communication mechanism to control the functions of HDC, such as disabling shell, install and other instructions. At the same time, the method is also applicable to Android systems that use ADB (Android Debug Bridge) for communication. The following is an explanation through specific implementation methods:
[0078] Embodiment 1
[0079] Please refer to Figure 1 , a method for controlling HDC, comprising:
[0080] S1. According to the instruction control requirements, the code in the HDC native code that meets the instruction control requirements is marked as stripped code, and the code that is not marked as stripped code is marked as remaining code.
[0081] Please refer to Figure 2 , the HDC component communicates by establishing a long connection through the TCP / IP protocol; its communication process is as follows: after the HDC Client is started, it will actively search for and try to connect to the HDC Server process; if the Server is not started, the Client will start a Server, and then the Client and Server will communicate through the local port. The Server searches for the simulator or device by scanning the port, and once a Daemon (hdcd) is found, a connection is established through the port; at the same time, the Server can receive HDC commands from multiple Clients, and then pass the commands to multiple connected Daemons, and run the commands in the Daemon to achieve the effect of controlling the device / simulator. Therefore, controlling the commands on the Deamon can limit the functions of HDC.
[0082] In this embodiment, the code that meets the instruction control requirements in the HDC native code is marked as stripped code, and the controlled function is stripped out of an independent so library, so that the terminal can use the controlled function by loading the stripped so library in a specific mode. The specific implementation method is as follows:
[0083] S2. Strip the stripped code in the HDC native code to obtain a stripped code block and a remaining code block. For example, assuming that the main program main calls instructions in an API interface, the complete instruction logic code is A, the code to be stripped is marked as A_1, and the remaining code is marked as B; then A_1 is stripped from A, that is, stripped code block A_1 and remaining code block B are obtained, and remaining code block B is the code block after removing A_1 from the A code.
[0084] S3, compile the stripped code block into a first shared code library, and compile the remaining code blocks into a second shared code library. For example, code block A and code block B are compiled into .so format respectively by Linux cross-compilation, that is, code block A generates hdcd_cmd.so, which is the first shared code library; code block B generates hdcd_strip.so, which is the second shared code library.
[0085] S4. Change the method of calling the HDC native code from the native interface to calling the first shared code library and / or the second shared code library through the library loading function.
[0086] Please refer to Figure 3 That is, the main program main needs to change the API call complete instruction logic code A to load the so library through opendl, so as to load different so libraries according to the current mode of the device (normal mode or special mode).
[0087] S5. Set the default state to normal mode. In normal mode, the second shared code library is called through the library loading function; that is, the second shared code library hdcd_strip.so without control instructions is used by default on the device (Device) (different from the native hdcd). The specific setting method is as follows:
[0088] Output the second shared code library to the system image package through the compilation script; call the second shared code library in the system image package in normal mode; for example: through compilation scripts such as makefile / Build.gn, different macros can be used to control the compilation and output hdcd_cmd.so or hdc_strip.so to the system image package, so that the device uses the second shared code library hdcd_strip.so without control instructions by default.
[0089] S6. Determine whether a mode switching instruction is received. If so, switch the normal mode to the special mode; in the special mode, call the first shared code library and the second shared code library through the library loading function. That is, a mode switching mechanism is introduced on the device (Device), and the user usually defaults to normal mode; when the device needs to be debugged or has special needs, the device can be switched to special mode by applying for authorization; and the second shared code library hdcd_strip.so in normal mode cannot execute controlled instructions. Among them, the device is set with a mode identification bit, a normal mode identification, and a special mode identification; if the mode identification bit is set to sysmode, 0 is the normal mode identification, and 1 is the special mode identification; the working mode of the device is determined by the variable stored in the security element Ta, such as sysmode 0 indicates normal mode, and 1 indicates special mode; and the writing of Ta requires the characteristic PC tool and the security service in the device to be implemented together, as follows:
[0090] S61. The PC tool and the device mutually authenticate and identify each other through a specific network protocol, that is, the device needs to authenticate and identify the connected switching tool through a preset network protocol, and mutually authenticate and identify the switching tool.
[0091] S62. The PC tool sends a mode switching instruction through the TCP / IP protocol, and also encrypts the mode switching instruction.
[0092] S63. The security service on the device decrypts the mode switching instruction sent by the PC and performs a legitimacy check on the decrypted mode switching instruction. If the legitimacy is passed, the mode identifier of Ta is legally written. That is, the state of sysmode is rewritten to 1, and the special mode is entered. At the same time, the second shared code library hdcd_strip.so actively identifies the valid first code library hdcd_cmd.so in the special mode and loads it. At this time, the controlled instructions can be executed, that is, the first shared code library and the second shared code library are called at the same time.
[0093] S64, the device restarts, obtains the mode state from Ta again and configures the corresponding environment attributes according to the mode. For example, after completing the debugging of the device and special needs, the device is automatically switched to the default state, that is, switched to the normal mode, by restarting the device.
[0094] Embodiment 2
[0095] Please refer to Figure 4 , a control device of HDC, comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program:
[0096] S1. According to the instruction control requirements, the code in the HDC native code that meets the instruction control requirements is marked as stripped code, and the code that is not marked as stripped code is marked as remaining code;
[0097] S2, stripping the stripping code in the HDC native code to obtain the stripping code and the remaining code;
[0098] S3, compiling the stripped code into a first shared code library, and compiling the remaining code into a second shared code library;
[0099] S4, changing the method of calling the HDC native code through the native interface to calling the first shared code library or the second shared code library through the library loading function;
[0100] S5, setting the default state to normal mode, calling the second shared code library through the library loading function in normal mode. Specifically: outputting the second shared code library to the system image package through the compilation script; calling the second shared code library in the system image package in normal mode.
[0101] S6. Determine whether a mode switching instruction is received. If so, switch the normal mode to the special mode. In the special mode, call the first shared code library and the second shared code library through the library loading function. The device is provided with a mode identification bit, a normal mode identification bit, and a special mode identification bit. The specific switching steps are as follows:
[0102] S61, authenticating and identifying the accessed switching tool through a preset network protocol;
[0103] S62, receiving a mode switching instruction sent by a switching tool through a preset network protocol; wherein the mode switching instruction is encrypted by the switching tool and then sent to the device;
[0104] S63, decrypt the mode switching instruction, and verify the decrypted mode switching instruction. If the verification is passed, the normal mode is switched to the special mode, that is, the special mode flag is written into the mode flag bit.
[0105] In summary, the present invention provides a method and device for controlling HDC, which removes the code that meets the instruction control requirements in the HDC native code, compiles the stripped code blocks and the remaining code blocks into the form of shared code libraries, and then calls different shared code libraries through the library loading function according to the current state of the device, so that when the device is in user use, it is in normal mode and cannot call the first shared code library, that is, the HDC function is not fully open; while when the device is in development end use, it is in special mode and can call the first shared code library and the second shared code library, that is, the HDC function is fully open, thereby meeting the use requirements of different users for the HDC function.
[0106] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent transformations made using the contents of the present invention's specification and drawings, or directly or indirectly applied in related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A method for controlling HDC, characterized in that: include: According to the instruction control requirement, mark the code in the HDC native code that meets the instruction control requirement as stripped code, and mark the code that is not marked as the stripped code as remaining code; Stripping the stripping code in the HDC native code to obtain a stripping code block and a remaining code block; Compiling the stripped code blocks into a first shared code library, and compiling the remaining code blocks into a second shared code library; The method of calling the HDC native code through the native interface is changed to calling the first shared code library and / or the second shared code library through a library loading function; Setting the default state to a normal mode, in which the second shared code library is called through the library loading function; Determine whether a mode switching instruction is received, and if so, switch the normal mode to a special mode; in the special mode, call the first shared code library and the second shared code library through the library loading function.
2. A method for controlling HDC according to claim 1, characterized in that: The setting of the default state to the normal mode includes: Outputting the second shared code library into a system image package by compiling a script; The second shared code library in the system image package is called in the normal mode.
3. A method for controlling HDC according to claim 1, characterized in that: The step of determining whether a state switching instruction is received includes: A switching tool that authenticates and identifies access through a preset network protocol; The mode switching instruction sent by the switching tool is received through the preset network protocol.
4. A method for controlling HDC according to claim 3, characterized in that: Before receiving the mode switching instruction sent by the switching tool through the preset network protocol, the method further includes: The mode switching instruction is encrypted by the switching tool; The switching of the normal mode to the special mode comprises: The mode switching instruction is decrypted, and the decrypted mode switching instruction is verified. If the verification is passed, the normal mode is switched to the special mode.
5. The HDC control method according to claim 1, characterized in that: It also includes a mode identification bit as well as a normal mode identification and a special mode identification; The switching of the normal mode to the special mode comprises: The special mode flag is written into the mode flag bit.
6. A control device for HDC, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the following steps are implemented: According to the instruction control requirement, mark the code in the HDC native code that meets the instruction control requirement as stripped code, and mark the code that is not marked as the stripped code as remaining code; Stripping the stripping code in the HDC native code to obtain a stripping code block and a remaining code block; Compiling the stripped code blocks into a first shared code library, and compiling the remaining code blocks into a second shared code library; The method of calling the HDC native code through the native interface is changed to calling the first shared code library and / or the second shared code library through a library loading function; Setting the default state to a normal mode, in which the second shared code library is called through the library loading function; Determine whether a mode switching instruction is received, and if so, switch the normal mode to a special mode; in the special mode, call the first shared code library and the second shared code library through the library loading function.
7. The HDC control device according to claim 1, characterized in that: The setting of the default state to the normal mode includes: Outputting the second shared code library into a system image package by compiling a script; The second shared code library in the system image package is called in the normal mode.
8. The HDC control device according to claim 1, characterized in that: The step of determining whether a state switching instruction is received includes: A switching tool that authenticates and identifies access through a preset network protocol; The mode switching instruction sent by the switching tool is received through the preset network protocol.
9. The HDC control device according to claim 8, characterized in that: Before receiving the mode switching instruction sent by the switching tool through the preset network protocol, the method further includes: The mode switching instruction is encrypted by the switching tool; The switching of the normal mode to the special mode comprises: The mode switching instruction is decrypted, and the decrypted mode switching instruction is verified. If the verification is passed, the normal mode is switched to the special mode.
10. The HDC control device according to claim 1, characterized in that: It also includes a mode identification bit as well as a normal mode identification and a special mode identification; The switching of the normal mode to the special mode comprises: The special mode flag is written into the mode flag bit.
