Method and system for obtaining command line parameters, electronic device and storage medium

By registering program startup notifications in the Linux kernel, using the kernel module to obtain command line parameters when the program starts, the problem of complex, unstable and unfriendly acquisition of command line parameters in the existing technology is solved, and the simple, stable and Friendly parameter acquisition.

CN113722002BActive Publication Date: 2024-11-22QI-ANXIN LEGENDSEC INFORMATION TECH (BEIJING) INC +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010458162.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-05-26
Publication Date
2024-11-22
Estimated Expiration
2040-05-26

AI Technical Summary

Technical Problem

The method of obtaining command line parameters in the prior art is complex and unstable, and is not program friendly, which easily interferes with program operation.

Method used

By pre-registering the kernel program to start notification, the kernel module uses the kernel module to obtain command line parameters when the program starts, avoid HOOK or redirection interference, and extract parameter information directly from the kernel structure.

Benefits of technology

The method of obtaining command line parameters is simple, stable and program-friendly, and is not affected by other programs or factors in the user state, and accurately obtains the complete command line parameters of the program.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113722002B_ABST
    Figure CN113722002B_ABST
Patent Text Reader

Abstract

The present disclosure provides a method for obtaining command line parameters, including: obtaining a notification of program startup, wherein the program startup notification is pre-registered with the kernel to obtain the program startup notification from the kernel when the program is started; after receiving the program startup notification, obtaining a structure parameter for storing program information from a pre-defined callback function; obtaining first address information about the program command line parameter from the structure parameter for storing program information; and obtaining the command line parameter of the program based on the first address information. The present disclosure also provides a device for obtaining command line parameters, an electronic device, a computer-readable storage medium, and a computer program product.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and more specifically, to a method for obtaining command line parameters, a system for obtaining command line parameters, an electronic device, a computer-readable storage medium, and a computer program product. Background Art

[0002] In operating systems, such as Linux systems, command line programs are almost everywhere. In many business scenarios, especially in security software, it is necessary to obtain the complete command line parameters of the program and then parse the command line parameters to analyze whether the behavior of the corresponding program is malicious.

[0003] In the process of implementing the concept of the present disclosure, the inventors found that there are at least the following problems in the related art:

[0004] In the prior art, the HOOK exec method can be used to obtain complete command line parameters when the program starts, but the implementation scheme is relatively complicated and requires a HOOK Exec system call. The system call parameters are very complex, and many factors must be considered when HOOKing. In another way, the Preload injection method can be used to inject the pre-compiled dynamic library into the corresponding program when the program starts, and obtain complete command line parameters when the program starts. However, this method is not program-friendly, and other programs need to be completely statically linked during injection, otherwise the solution will not work properly. In another way, the redirection method can be applied to execute other pre-compiled programs through redirection when the program starts to obtain complete command line parameters. However, this method is also not program-friendly, and after the program is redirected when it starts, it will cause other adverse effects such as slow program startup and changes in upper and lower files during operation.

[0005] Therefore, the method for obtaining command line parameters in the prior art has the problems of being complex, unstable, unfriendly to programs and easily causing interference. Summary of the invention

[0006] In view of this, the present disclosure provides a method for obtaining command line parameters, a system for obtaining command line parameters, an electronic device, a computer-readable storage medium, and a computer program product.

[0007] One aspect of the present disclosure provides a method for obtaining command line parameters, including: obtaining a notification of program startup, wherein the program startup notification is pre-registered with a kernel so as to obtain the program startup notification from the kernel when the program starts; after receiving the program startup notification, obtaining a structure parameter for storing program information from a predefined callback function; obtaining first address information about the program command line parameters from the structure parameter for storing program information; and obtaining the program command line parameters based on the first address information.

[0008] According to an embodiment of the present disclosure, the pre-registering of program startup notification with the kernel includes: calling a program startup notification interface to insert a target structure into a program startup notification linked list, wherein a target function pointer in the target structure points to the predefined callback function, and parameters of the callback function are set to structure parameters for storing program information; the obtaining of program startup notification includes: obtaining a notification of the kernel calling the callback function, and using the notification of calling the callback function as the program startup notification, wherein, after intercepting the program startup operation, the kernel calls the target function pointer of the structure and calls the callback function based on the function pointer.

[0009] According to an embodiment of the present disclosure, obtaining the first address information about the program command line parameters includes: obtaining a user-state stack top pointer pointing to the program command line parameters and information about the number of program command line parameters; based on the address information, obtaining the command line parameters of the program includes: obtaining the command line parameters of the program based on the user-state stack top pointer pointing to the program command line parameters and information about the number of program command line parameters.

[0010] According to an embodiment of the present disclosure, the method for obtaining command line parameters also includes: obtaining identification information of a process; obtaining a kernel structure of the process based on the identification information of the process; obtaining second address information about the process command line parameters from the kernel structure of the process; and obtaining the command line parameters of the process based on the second address information.

[0011] According to an embodiment of the present disclosure, obtaining the second address information about the process command line parameters includes: obtaining the starting address of the process command line parameters in the user state and the ending address of the process command line parameters in the user state; obtaining the command line parameters of the process based on the second address information includes: obtaining the command line parameters of the process based on the starting address of the process command line parameters in the user state and the ending address of the process command line parameters in the user state.

[0012] According to an embodiment of the present disclosure, obtaining the command line parameters of a process based on the starting address of the process command line parameters in user state and the ending address of the process command line parameters in user state includes: calling a kernel function for accessing a user state address space, and obtaining the command line parameters in the user state address space located between the starting address and the ending address.

[0013] Another aspect of the present disclosure provides a system for obtaining command line parameters, including a kernel module, the kernel module including: a startup notification submodule, used to obtain a notification of program startup, wherein the program startup notification is pre-registered with the kernel so as to obtain the program startup notification from the kernel when the program starts; a calling submodule, used to obtain a structure parameter for storing program information from a predefined callback function after receiving the program startup notification; a first address submodule, used to obtain first address information about the program command line parameters from the structure parameter for storing program information; and a first acquisition submodule, used to obtain the command line parameters of the program based on the first address information.

[0014] According to an embodiment of the present disclosure, the kernel module also includes: an identification information submodule, used to obtain identification information of a process; a structure information submodule, used to obtain the kernel structure of the process based on the identification information of the process; a second address submodule, used to obtain second address information about process command line parameters from the kernel structure of the process; and a second acquisition submodule, used to obtain the command line parameters of the process based on the second address information.

[0015] Another aspect of the present disclosure provides an electronic device, including: one or more processors; and a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method as described above.

[0016] Another aspect of the present disclosure provides a computer-readable storage medium storing computer-executable instructions, which are used to implement the above method when executed.

[0017] Another aspect of the present disclosure provides a computer program product, the computer program product comprising computer readable instructions, the computer readable instructions being used to implement the method described above when executed.

[0018] According to an embodiment of the present disclosure, by calling the register_binfmt interface provided in advance by the Linux kernel to register a program startup notification, the program startup notification can be obtained when the program is started later, and then the address information of the program command line parameters can be obtained, and then the complete command line parameters of the current startup program can be obtained. The interfaces and functions used in the above scheme are all exported by the Linux operating kernel and can be used by third-party kernel modules. There are no behaviors such as HOOK or redirection that interfere with the operation of the program. It is very friendly to the operating system and user-mode applications, and the scheme is simple and stable. It can accurately obtain the command line parameters of the program without being affected by any other programs and factors in the user mode. Therefore, at least partially overcome the problems of complex schemes, instability, unfriendly to programs, and easy interference in the prior art, and thus achieve the technical effect of simple schemes, stability, and program-friendly. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] The above and other objects, features and advantages of the present disclosure will become more apparent through the following description of the embodiments of the present disclosure with reference to the accompanying drawings, in which:

[0020] Figure 1 An exemplary application scenario in which the method for obtaining command line parameters according to an embodiment of the present disclosure can be applied is schematically shown;

[0021] Figure 2 A flowchart of a method for obtaining command line parameters according to an embodiment of the present disclosure is schematically shown;

[0022] Figure 3 A schematic diagram schematically shows the layout of a user-mode stack structure of program command line parameters in memory according to an embodiment of the present disclosure;

[0023] Figure 4 A flowchart of a method for obtaining command line parameters according to another embodiment of the present disclosure is schematically shown;

[0024] Figure 5 A schematic diagram of the memory layout of the process command line user mode parameters according to an embodiment of the present disclosure is schematically shown;

[0025] Figure 6 A block diagram of a system for obtaining command line parameters according to an embodiment of the present disclosure is schematically shown;

[0026] Figure 7 A block diagram schematically illustrates a core module according to another embodiment of the present disclosure; and

[0027] Figure 8 A block diagram of an electronic device suitable for implementing a method for obtaining command line parameters according to an embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION

[0028] Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the present disclosure. In the following detailed description, for ease of explanation, many specific details are set forth to provide a comprehensive understanding of the embodiments of the present disclosure. However, it is apparent that one or more embodiments may also be implemented without these specific details. In addition, in the following description, descriptions of known structures and technologies are omitted to avoid unnecessary confusion of the concepts of the present disclosure.

[0029] The terms used herein are only for describing specific embodiments and are not intended to limit the present disclosure. The terms "comprise", "include", etc. used herein indicate the existence of the features, steps, operations and / or components, but do not exclude the existence or addition of one or more other features, steps, operations or components.

[0030] All terms (including technical and scientific terms) used herein have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification, and should not be interpreted in an idealized or overly rigid manner.

[0031] In the case of using expressions such as "at least one of A, B, and C, etc.", it should generally be interpreted in accordance with the meaning of the expression generally understood by those skilled in the art (for example, "a system having at least one of A, B, and C" should include but is not limited to a system having A alone, B alone, C alone, A and B, A and C, B and C, and / or A, B, C, etc.). In the case of using expressions such as "at least one of A, B, or C, etc.", it should generally be interpreted in accordance with the meaning of the expression generally understood by those skilled in the art (for example, "a system having at least one of A, B, or C" should include but is not limited to a system having A alone, B alone, C alone, A and B, A and C, B and C, and / or A, B, C, etc.).

[0032] The embodiment of the present disclosure provides a method for obtaining command line parameters, the method comprising: obtaining a notification of program startup, wherein the program startup notification is pre-registered with the kernel, so as to obtain the program startup notification from the kernel when the program is started. After receiving the notification of program startup, a structure parameter for storing program information is obtained from a pre-defined callback function; first address information about the program command line parameters is obtained from the structure parameter for storing program information; and based on the first address information, the command line parameters of the program are obtained.

[0033] Figure 1 The following schematically illustrates an exemplary application scenario in which the method for obtaining command line parameters according to an embodiment of the present disclosure can be applied. It should be noted that: Figure 1 What is shown are merely examples of application scenarios to which the embodiments of the present disclosure can be applied, in order to help those skilled in the art understand the technical content of the present disclosure, but it does not mean that the embodiments of the present disclosure cannot be used in other devices, systems, environments or scenarios.

[0034] like Figure 1 As shown, a corresponding kernel module can be added to a Linux system that needs to obtain complete command line parameters, and the method of the embodiment of the present disclosure can be executed by the kernel module. The kernel module can execute the method of the embodiment of the present disclosure to obtain the command line parameters of multiple applications (application 1, application 2, ..., application N).

[0035] The command line parameters of the program / process obtained by the kernel module can be provided to applications such as security programs (security software) for use, so that the security programs and other applications can analyze each application / process according to the command line parameters of the program / process. For example, the security program can analyze whether the behavior of each application / process is safe and reliable according to the command line parameters of the program / process. Specifically, a user-mode security program is started, and the security program is used to receive the command line parameter information of the program / process obtained by the kernel module for analysis and processing. For example, the command line parameters of the program and the command line parameters of the process that starts the program need to be analyzed and processed, such as obtaining the files to be accessed and the network addresses to be accessed in the command line parameters, so as to determine whether its behavior is safe.

[0036] In actual business scenarios, once the kernel module finds that a program is started, it can obtain the command line parameters of the program and the command line parameters of the process that starts the program, and send the relevant information to applications such as security programs. The kernel module can use the Netlink mechanism to send the corresponding information to the application.

[0037] Figure 2 The flowchart of the method for obtaining command line parameters according to an embodiment of the present disclosure is schematically shown.

[0038] like Figure 2 As shown, the method may include operations S210 - S240 .

[0039] In operation S210 , a notification of program startup is acquired, wherein the program startup notification is pre-registered with the kernel so as to acquire the program startup notification from the kernel when the program is started.

[0040] According to an embodiment of the present disclosure, a kernel program startup notification interface named register_binfmt can be called to register a program startup notification with the kernel, wherein the program startup notification interface is an external interface provided in advance by the kernel. By registering the program startup notification with the kernel, a notification representing the program startup can be obtained after the kernel intercepts the program startup operation.

[0041] Take the first program as an example, wherein the first program may be any application program installed in the system. After registering the program startup notification interface with the kernel, when the first program is started, the startup notification of the first program can be obtained immediately.

[0042] According to an embodiment of the present disclosure, pre-registering a program startup notification with the kernel may include: calling a program startup notification interface to insert a target structure into a program startup notification linked list, wherein a target function pointer in the target structure points to a predefined callback function, and parameters of the callback function are set to structure parameters for storing program information.

[0043] For example, the target structure may refer to the struct linux_binfmt structure, which is a data structure provided by the Linux system. With the struct linux_binfmt structure as a parameter, the kernel program startup notification interface named register_binfmt is called to register the program startup notification with the kernel. The register_binfmt interface will insert the incoming structlinux_binfmt structure type parameter into the program startup notification linked list predefined by the kernel. When the program is started, the kernel will traverse the program startup notification linked list. Among them, the struct linux_binfmt structure has a member named load_binary, which is a function pointer.

[0044] According to an embodiment of the present disclosure, a callback function can be predefined, and the load_binary function pointer load_binary points to the predefined callback function, and the parameters of the callback function can be pre-set to struct linux_binprm structure parameters, wherein the struct linux_binprm structure parameters are structure parameters used to store program information in the Linux system. The predefined callback function can be named, for example, the load_action_check callback function.

[0045] According to an embodiment of the present disclosure, obtaining a notification of program startup may include: obtaining a notification of the kernel calling a callback function, and using the notification of calling the callback function as the notification of program startup, wherein after intercepting the program startup operation, the kernel calls a target function pointer of a structure and calls the callback function based on the function pointer.

[0046] For example, when the program starts, the kernel will traverse the program startup notification list. Since the struct linux_binfmt structure has been inserted into the program startup notification list, the kernel will call the load_binary function pointer in the struct linux_binfmt structure saved in the list. Since the function pointer points to the predefined callback function, the kernel will call the predefined callback function according to the function pointer. The kernel will only call the predefined callback function when the program starts. Therefore, the notification of calling the callback function can be used as the notification of program startup. When the callback function is called, it can be considered that the program has started.

[0047] In operation S220, after receiving the notification of program startup, a structure parameter for storing program information is obtained from a predefined callback function.

[0048] After intercepting the first program startup operation, that is, after obtaining the program startup notification, a callback function named load_action_check can be triggered to call, and then the parameters of the callback function can be obtained. The parameters of the callback function are the structure parameters of struct linux_binprm, and the struct linux_binprm structure parameters can store some relevant information of the first program to be executed, such as relevant information about the command line parameters of the first program. The detailed structure of the structlinux_binprm can refer to the source code of the Linux kernel.

[0049] In operation S230, first address information about program command line parameters is obtained from a structure parameter used to store program information.

[0050] As described above, the struct linux_binprm structure parameter bprm can be obtained according to the callback function, and the structure parameter stores some relevant information of the first program to be executed, such as address information about the command line parameters of the first program, including a pointer to the command line parameters of the first program in the user mode stack.

[0051] In operation S240, command line parameters of the program are acquired based on the first address information.

[0052] For example, command line parameters of the first program may be extracted from a corresponding position according to the first address information.

[0053] According to an embodiment of the present disclosure, by calling the register_binfmt interface provided in advance by the Linux kernel to register a program startup notification, the program startup notification can be obtained when the program is started later, and then the address information of the program command line parameters can be obtained, and then the complete command line parameters of the current startup program can be obtained. The interfaces and functions used in the above scheme are all exported by the Linux operating kernel and can be used by third-party kernel modules. There are no behaviors such as HOOK or redirection that interfere with the operation of the program. It is very friendly to the operating system and user-mode applications, and the scheme is simple and stable. It can accurately obtain the command line parameters of the program without being affected by any other programs and factors in the user mode. Therefore, at least partially overcome the problems of complex schemes, instability, unfriendly to programs, and easy interference in the prior art, and thus achieve the technical effect of simple schemes, stability, and program-friendly.

[0054] According to an embodiment of the present disclosure, obtaining first address information about program command line parameters in operation S230 may include: obtaining a user state stack top pointer pointing to the program command line parameters and information about the number of program command line parameters.

[0055] For example, the struct linux_binprm structure parameter bprm has two very important members:

[0056] (1) bprm->p points to the top pointer of the user stack of the program command line parameters;

[0057] (2)bprm->argc: the number of command line parameters of the program.

[0058] The first address information of the program command line parameter may refer to the user state stack top pointer pointing to the program command line parameter and the number of the program command line parameters.

[0059] According to an embodiment of the present disclosure, obtaining the command line parameters of the program based on the address information in operation S240 may include: obtaining the command line parameters of the program based on a user state stack top pointer pointing to the program command line parameters and information about the number of the program command line parameters.

[0060] Figure 3 The schematic diagram shows the layout of the user-mode stack structure of the program command line parameters in the memory according to an embodiment of the present disclosure.

[0061] like Figure 3As shown in the figure, the program command line parameters are stored in order, bprm->p corresponds to the starting address of the first parameter of the program command line parameters in the user state stack, and the number of program command line parameters is identified by the bprm->argc member. Therefore, the program command line parameters can be extracted one by one from the user state stack according to bprm->p and bprm->argc.

[0062] According to the embodiments of the present disclosure, the program command line parameters in the user state stack are obtained by using the user state stack top pointer pointing to the program command line parameters and the number of program command line parameters, and the "memory address space" storing the corresponding command line parameters is directly accessed to obtain the corresponding command line parameters from the "memory address space" without any file reading and searching operations. The real-time performance is good and it can ensure that the complete program command line parameters are obtained.

[0063] The above describes how to obtain the command line parameters of a program. In addition, in some application scenarios, for example, when security software performs security detection, it is also necessary to obtain the complete command line parameters of the process so that the security software can analyze whether the behavior of the corresponding process is malicious.

[0064] In the related art, all schemes are to obtain command line parameters when the program is started, and it is impossible to obtain the complete command line parameters of the running process. The method of the embodiment of the present disclosure can solve this problem, and the complete command line parameters of the running process can be obtained through the following operations.

[0065] Figure 4 A flowchart of a method for obtaining command line parameters according to another embodiment of the present disclosure is schematically shown.

[0066] like Figure 4 As shown, according to an embodiment of the present disclosure, in addition to obtaining the command line parameters of the program through the above-mentioned S210 to S240, the method for obtaining command line parameters can also obtain the command line parameters of the running process through operations S410 to S440.

[0067] In operation S410, identification information of a process is obtained.

[0068] Taking the first process as an example, the identification information of the first process may refer to the process ID PID of the first process, where the process ID PID is an integer value used to uniquely identify a process in the kernel.

[0069] In operation S420, a kernel structure of the process is acquired based on identification information of the process.

[0070] For example, the kernel provides interface functions such as find_pid_ns that can obtain process information. This type of interface can obtain the kernel structure of the corresponding process through the process PID: struct task_struct structure, which is used by the kernel to store process information, such as address information about the command line parameters of the first program.

[0071] The definition of the struct task_struct structure and its related members may refer to the source code of the Linux kernel. In operation S430, second address information about the process command line parameters is obtained from the kernel structure of the process.

[0072] As described above, the kernel structure struct task_struct of the process is obtained. The kernel structure is used by the kernel to store relevant information of the process, wherein address information of command line parameters of the first process is stored.

[0073] In operation S440, command line parameters of the process are obtained based on the second address information.

[0074] For example, the command line parameters of the first process may be extracted from the corresponding position according to the second address information.

[0075] According to the embodiments of the present disclosure, by using find_pid_ns and other interface functions that can obtain process information and combining with the process number, the kernel structure of the corresponding process can be obtained, and the address information of the process command line parameters can be obtained according to the kernel structure of the process, and then the complete command line parameters of the corresponding process can be obtained. Based on the above method, the command line parameters of the running process can be obtained, and the interfaces and functions used in the above scheme are all exported by the Linux operating kernel and can be used by third-party kernel modules. The scheme is simple and stable, and can accurately obtain the command line parameters of the process.

[0076] According to an embodiment of the present disclosure, obtaining the second address information about the process command line parameter in operation S430 may include: obtaining a starting address of the process command line parameter in the user state and an ending address of the process command line parameter in the user state.

[0077] For example, the struct mm_struct member of the struct task_struct structure contains the user-mode addresses describing the command line parameters of the current process: arg_start, arg_end. Among them, arg_start is the starting address of the process command line parameters in the user mode, and arg_end is the ending address of the process command line parameters in the user mode.

[0078] The second address information of the process command line parameter may refer to the starting address of the process command line parameter in the user state and the ending address of the process command line parameter in the user state.

[0079] According to an embodiment of the present disclosure, obtaining the command line parameters of the process based on the second address information in operation S440 may include: obtaining the command line parameters of the process based on the starting address of the process command line parameters in the user state and the ending address of the process command line parameters in the user state.

[0080] According to an embodiment of the present disclosure, based on the starting address of the process command line parameters in the user state and the ending address of the process command line parameters in the user state, obtaining the command line parameters of the process includes: calling a kernel function for accessing the user state address space, and obtaining the command line parameters located between the starting address and the ending address in the user state address space.

[0081] Figure 5 The following schematically shows a memory layout diagram of process command line user mode parameters according to an embodiment of the present disclosure.

[0082] like Figure 5 As shown, the process command line parameters are saved in a continuous memory in the user state, and the process command line parameters are stored in order. The starting address (arg_start) of the process command line parameters in the user state corresponds to the address of the first parameter of the command line parameters of the corresponding process in the memory, and the ending address (arg_end) of the process command line parameters in the user state corresponds to the address of the last parameter of the command line parameters of the corresponding process in the memory. The process command line parameters between the starting address (arg_start) and the ending address (arg_end) can be "copied" from the user state to the kernel space through the copy_from_user function, and the command line parameters of the corresponding process can be obtained.

[0083] Among them, arg_start and arg_end identify the user-state address of the process, which cannot be directly accessed by the kernel. Therefore, it is necessary to use kernel functions such as copy_from_user to access the user-state address space to copy the data in the user-state memory to the kernel space before accessing it. copy_from_user is a function specially provided by the kernel for this type of operation, and its definition is as follows:

[0084] unsigned long copy_from_user(void*to, const void_user*from, unsignedlong n)

[0085] According to an embodiment of the present disclosure, the "memory address space" storing the corresponding process command line parameters is directly accessed through the starting address of the process command line parameters in the user state and the ending address of the process command line parameters in the user state, and the corresponding process command line parameters are obtained from the "memory address space" without any file reading and searching operations, with good real-time performance and the ability to ensure that the complete process command line parameters are obtained.

[0086] Through the above solution, the complete command line parameters of programs and processes can be obtained directly in the kernel in an efficient, real-time and accurate manner.

[0087] Another aspect of an embodiment of the present disclosure provides a system for obtaining command line parameters.

[0088] Figure 6 A block diagram of a system for obtaining command line parameters according to an embodiment of the present disclosure is schematically shown.

[0089] like Figure 6 As shown, the system includes a kernel module 600 , and the kernel module 600 includes a startup notification submodule 610 , a calling submodule 620 , a first address submodule 630 and a first acquisition submodule 640 .

[0090] The startup notification submodule 610 is used to obtain a notification of program startup, wherein the program startup notification is pre-registered with the kernel so as to obtain the program startup notification from the kernel when the program is started.

[0091] The calling submodule 620 is used to obtain a structure parameter for storing program information from a predefined callback function after receiving a notification of program startup.

[0092] The first address submodule 630 is used to obtain first address information about program command line parameters from a structure parameter used to store program information.

[0093] The first acquisition submodule 640 is used to acquire command line parameters of the program based on the first address information.

[0094] According to an embodiment of the present disclosure, pre-registering a program startup notification with the kernel includes: calling a program startup notification interface to insert a target structure into a program startup notification linked list, wherein a target function pointer in the target structure points to a predefined callback function, and parameters of the callback function are set to structure parameters for storing program information.

[0095] Obtaining a notification of program startup includes: obtaining a notification of the kernel calling a callback function, and using the notification of calling the callback function as a notification of program startup, wherein after intercepting the program startup operation, the kernel calls a target function pointer of the structure and calls the callback function based on the function pointer.

[0096] According to an embodiment of the present disclosure, obtaining first address information about a program command line parameter includes: obtaining a user-state stack top pointer pointing to the program command line parameter and information about the number of program command line parameters. Based on the address information, obtaining the command line parameters of the program includes: obtaining the command line parameters of the program based on the user-state stack top pointer pointing to the program command line parameter and information about the number of program command line parameters.

[0097] Figure 7 A block diagram of a kernel module according to another embodiment of the present disclosure is schematically shown.

[0098] like Figure 7 As shown, according to an embodiment of the present disclosure, the core module 600 may further include an identification information submodule 710 , a structure information submodule 720 , a second address submodule 730 , and a second acquisition submodule 740 .

[0099] The identification information submodule 710 is used to obtain identification information of a process.

[0100] The structure information submodule 720 is used to obtain the kernel structure of the process based on the identification information of the process.

[0101] The second address submodule 730 is used to obtain second address information about process command line parameters from the kernel structure of the process.

[0102] The second acquisition submodule 740 is used to acquire command line parameters of the process based on the second address information.

[0103] According to an embodiment of the present disclosure, obtaining the second address information about the process command line parameters includes: obtaining the starting address of the process command line parameters in the user state and the ending address of the process command line parameters in the user state. Based on the second address information, obtaining the command line parameters of the process includes: obtaining the command line parameters of the process based on the starting address of the process command line parameters in the user state and the ending address of the process command line parameters in the user state.

[0104] According to an embodiment of the present disclosure, based on the starting address of the process command line parameters in the user state and the ending address of the process command line parameters in the user state, obtaining the command line parameters of the process includes: calling a kernel function for accessing the user state address space, and obtaining the command line parameters located between the starting address and the ending address in the user state address space.

[0105] According to the embodiments of the present invention, any one or more of the modules, submodules, units, and subunits, or at least part of the functions of any one of them can be implemented in one module. According to the embodiments of the present invention, any one or more of the modules, submodules, units, and subunits can be split into multiple modules for implementation. According to the embodiments of the present invention, any one or more of the modules, submodules, units, and subunits can be at least partially implemented as hardware circuits, such as field programmable gate arrays (FPGAs), programmable logic arrays (PLAs), systems on chips, systems on substrates, systems on packages, application specific integrated circuits (ASICs), or can be implemented by hardware or firmware in any other reasonable way of integrating or packaging the circuit, or implemented in any one of the three implementation methods of software, hardware, and firmware, or in any appropriate combination of any of them. Alternatively, according to the embodiments of the present invention, one or more of the modules, submodules, units, and subunits can be at least partially implemented as computer program modules, and when the computer program modules are run, the corresponding functions can be performed.

[0106] For example, any multiple of the kernel module 600, the startup notification submodule 610, the call submodule 620, the first address submodule 630, the first acquisition submodule 640, the identification information submodule 710, the structure information submodule 720, the second address submodule 730, and the second acquisition submodule 740 can be combined in one module / unit / subunit for implementation, or any one of the modules / units / subunits can be split into multiple modules / units / subunits. Alternatively, at least part of the functions of one or more of these modules / units / subunits can be combined with at least part of the functions of other modules / units / subunits and implemented in one module / unit / subunit. According to an embodiment of the present disclosure, at least one of the kernel module 600, the startup notification submodule 610, the calling submodule 620, the first address submodule 630, the first acquisition submodule 640, the identification information submodule 710, the structure information submodule 720, the second address submodule 730 and the second acquisition submodule 740 can be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on a chip, a system on a substrate, a system on a package, an application-specific integrated circuit (ASIC), or can be implemented by hardware or firmware such as any other reasonable way of integrating or packaging the circuit, or can be implemented in any one of the three implementation methods of software, hardware and firmware or in an appropriate combination of any of them. Alternatively, at least one of the kernel module 600, the boot notification submodule 610, the calling submodule 620, the first address submodule 630, the first acquisition submodule 640, the identification information submodule 710, the structure information submodule 720, the second address submodule 730 and the second acquisition submodule 740 can be at least partially implemented as a computer program module, which can execute corresponding functions when the computer program module is executed.

[0107] It should be noted that the system part for obtaining command line parameters in the embodiments of the present disclosure corresponds to the method part for obtaining command line parameters in the embodiments of the present disclosure. The description of the system part for obtaining command line parameters specifically refers to the method part for obtaining command line parameters, which will not be repeated here.

[0108] Figure 8 A block diagram of an electronic device suitable for implementing the method described above according to an embodiment of the present disclosure is schematically shown. Figure 8 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0109] like Figure 8As shown, the electronic device 800 according to an embodiment of the present disclosure includes a processor 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage part 808 into a random access memory (RAM) 803. The processor 801 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor and / or a related chipset and / or a special-purpose microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor 801 may also include an onboard memory for caching purposes. The processor 801 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of the present disclosure.

[0110] In RAM 803, various programs and data required for the operation of electronic device 800 are stored. Processor 801, ROM 802 and RAM 803 are connected to each other via bus 804. Processor 801 performs various operations of the method flow according to the embodiment of the present disclosure by executing the program in ROM 802 and / or RAM 803. It should be noted that the program can also be stored in one or more memories other than ROM 802 and RAM 803. Processor 801 can also perform various operations of the method flow according to the embodiment of the present disclosure by executing the program stored in the one or more memories.

[0111] According to an embodiment of the present disclosure, the electronic device 800 may further include an input / output (I / O) interface 805, which is also connected to the bus 804. The electronic device 800 may further include one or more of the following components connected to the I / O interface 805: an input portion 806 including a keyboard, a mouse, etc.; an output portion 807 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage portion 808 including a hard disk, etc.; and a communication portion 809 including a network interface card such as a LAN card, a modem, etc. The communication portion 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to the I / O interface 805 as needed. A removable medium 811, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 810 as needed, so that a computer program read therefrom is installed into the storage portion 808 as needed.

[0112] According to an embodiment of the present disclosure, the method flow according to an embodiment of the present disclosure can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable storage medium, and the computer program contains a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 809, and / or installed from the removable medium 811. When the computer program is executed by the processor 801, the above-mentioned functions defined in the system of the embodiment of the present disclosure are executed. According to an embodiment of the present disclosure, the system, equipment, device, module, unit, etc. described above can be implemented by a computer program module.

[0113] The present disclosure also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or may exist independently without being assembled into the device / apparatus / system. The above computer-readable storage medium carries one or more programs, and when the above one or more programs are executed, the method according to the embodiment of the present disclosure is implemented.

[0114] According to an embodiment of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium. For example, it may include, but is not limited to: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, apparatus, or device.

[0115] For example, according to an embodiment of the present disclosure, the computer-readable storage medium may include the ROM 802 and / or the RAM 803 described above and / or one or more memories other than the ROM 802 and the RAM 803 .

[0116] The flow charts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0117] It will be appreciated by those skilled in the art that the features described in the various embodiments and / or claims of the present disclosure may be combined and / or combined in a variety of ways, even if such combinations and / or combinations are not explicitly described in the present disclosure. In particular, the features described in the various embodiments and / or claims of the present disclosure may be combined and / or combined in a variety of ways without departing from the spirit and teachings of the present disclosure. All of these combinations and / or combinations fall within the scope of the present disclosure.

[0118] The embodiments of the present disclosure are described above. However, these embodiments are only for illustrative purposes and are not intended to limit the scope of the present disclosure. Although the embodiments are described above separately, this does not mean that the measures in the various embodiments cannot be used in combination to advantage. The scope of the present disclosure is defined by the attached claims and their equivalents. Without departing from the scope of the present disclosure, those skilled in the art may make a variety of substitutions and modifications, which should all fall within the scope of the present disclosure.

Claims

1. A method for obtaining command line parameters, comprising: Obtaining a program startup notification, wherein the program startup notification is pre-registered with the kernel so as to obtain the program startup notification from the kernel when the program is started; After receiving the notification of program startup, obtaining a structure parameter for storing program information from a predefined callback function; Acquire first address information about a program command line parameter from the structure parameter used to store program information; and Based on the first address information, obtaining command line parameters of the program; Wherein, the pre-registering of program startup notification with the kernel includes: Calling a program startup notification interface to insert a target structure into a program startup notification linked list, wherein a target function pointer in the target structure points to the predefined callback function, and a parameter of the callback function is set to a structure parameter for storing program information; The notification of obtaining the program start includes: Obtain a notification that the kernel calls the callback function, and use the notification of calling the callback function as a notification of program startup, wherein after intercepting the program startup operation, the kernel calls a target function pointer of a structure and calls the callback function based on the function pointer.

2. The method according to claim 1, wherein: The obtaining of the first address information about the program command line parameter includes: obtaining a user state stack top pointer pointing to the program command line parameter and the number information of the program command line parameter; Based on the first address information, obtaining the command line parameters of the program includes: obtaining the command line parameters of the program based on the user state stack top pointer pointing to the program command line parameters and the number information of the program command line parameters.

3. The method according to claim 1, further comprising: Get the process identification information; Based on the identification information of the process, obtaining the kernel structure of the process; Acquire second address information about process command line parameters from the kernel structure of the process; and Based on the second address information, command line parameters of the process are obtained.

4. The method according to claim 3, wherein: The obtaining of the second address information about the process command line parameter includes: obtaining the starting address of the process command line parameter in the user state and the ending address of the process command line parameter in the user state; The acquiring the command line parameters of the process based on the second address information includes: acquiring the command line parameters of the process based on the starting address of the process command line parameters in the user state and the ending address of the process command line parameters in the user state.

5. The method according to claim 4, wherein: The acquiring the command line parameters of the process based on the starting address of the command line parameters of the process in the user state and the ending address of the command line parameters of the process in the user state comprises: A kernel function for accessing a user state address space is called to obtain command line parameters between the start address and the end address in the user state address space.

6. A system for obtaining command line parameters, comprising a kernel module, wherein the kernel module comprises: A startup notification submodule is used to obtain a notification of program startup, wherein the program startup notification is pre-registered with the kernel so as to obtain the program startup notification from the kernel when the program is started; A calling submodule, used for obtaining a structure parameter for storing program information from a predefined callback function after receiving a notification of program startup; A first address submodule, used to obtain first address information about a program command line parameter from the structure parameter used to store program information; and A first acquisition submodule, used for acquiring command line parameters of a program based on the first address information; Wherein, the pre-registering program startup notification with the kernel includes: Calling a program startup notification interface to insert a target structure into a program startup notification linked list, wherein a target function pointer in the target structure points to the predefined callback function, and a parameter of the callback function is set to a structure parameter for storing program information; The startup notification submodule includes: The acquisition unit is used to obtain the notification of the kernel calling the callback function, and use the notification of calling the callback function as the notification of the program startup, wherein after intercepting the program startup operation, the kernel calls the target function pointer of the structure and calls the callback function based on the function pointer.

7. An electronic device comprising: one or more processors; a memory for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 5.

8. A computer-readable storage medium having executable instructions stored thereon, which, when executed by a processor, enables the processor to implement the method according to any one of claims 1 to 5.

9. A computer program product comprising computer readable instructions, wherein: The computer readable instructions are used to perform the method according to any one of claims 1 to 5 when executed.