Function processing method, device, equipment and storage medium

By loading the first core library in the application and injecting the custom connection function into the second core library using the proxy connection function, the problem of socket detection affecting stability and performance in the prior art is solved, and centralized management and detection of sockets are realized.

CN116340014BActive Publication Date: 2025-08-19DOUYIN VISION CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111598174.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-24
Publication Date
2025-08-19
Estimated Expiration
2041-12-24

AI Technical Summary

Technical Problem

The prior art requires injecting a large amount of custom code in all call places when detecting sockets, affecting the stability and performance of the application.

Method used

By loading the first core library in the preset application, using the proxy connection function to inject the custom connection function into the second core library, it is replaced by calling the custom connection function when the preset application calls the preset connection function to realize the detection of the preset socket.

Benefits of technology

Reduces the injection amount of detection socket code, ensures the stability and performance of the application, and realizes centralized management of sockets.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116340014B_ABST
    Figure CN116340014B_ABST
Patent Text Reader

Abstract

The embodiments of the present disclosure disclose a function processing method, apparatus, device and storage medium. The method includes: loading a first core library in a preset application, wherein the first core library implements centralized management of calls to a preset socket by injecting a proxy connection function into a second core library, the second core library contains a preset connection function for establishing a connection with a preset socket, and based on a preset injection method corresponding to the proxy connection function, a custom connection function is injected into the second core library, and when it is detected that the preset application calls the preset connection function through the second core library, it is replaced by calling the custom connection function to detect the preset socket. By adopting the above technical solution, the amount of code injected for detecting the socket can be reduced, thereby ensuring the stability and performance of the application.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present disclosure relate to the field of computer technology, and in particular to a function processing method, apparatus, device, and storage medium. Background Art

[0002] A socket is an application programming interface (API) for inter-process communication in a network environment, also known as a socket interface. It is the underlying interface for network capabilities on many operating system platforms. In order to monitor the network status of an application, it is often necessary to detect (Hook) the socket related to the application's network capabilities.

[0003] Currently, to fully understand network conditions, custom code needs to be injected into all socket calls to achieve detection, such as the common full-process Procedure Linkage Table Hook detection technology. Existing detection solutions inject a lot of content, affecting the overall stability and performance of the application, and are therefore not perfect. Summary of the Invention

[0004] The embodiments of the present disclosure provide a function processing method, apparatus, storage medium, and device, which can optimize existing function processing solutions.

[0005] In a first aspect, an embodiment of the present disclosure provides a function processing method, including:

[0006] Loading a first core library in a preset application, wherein the first core library centrally manages calls to a preset socket by injecting a proxy connection function in the first core library into a second core library, wherein the second core library includes a preset connection function, and the preset connection function is used to establish a connection with the preset socket;

[0007] Injecting the custom connection function into the second core library based on a preset injection method corresponding to the proxy connection function;

[0008] When it is detected that the preset application calls the preset connection function through the second core library, the preset connection function is called instead to implement custom logic to detect the preset socket.

[0009] In a second aspect, an embodiment of the present disclosure provides a function processing device, including:

[0010] a loading module, configured to load a first core library in a preset application, wherein the first core library centrally manages calls to a preset socket by injecting a proxy connection function in the first core library into a second core library, wherein the second core library includes a preset connection function, and the preset connection function is used to establish a connection with the preset socket;

[0011] An injection method calling module, configured to inject the custom connection function into the second core library based on a preset injection method corresponding to the proxy connection function;

[0012] The connection function calling module is used to replace the calling of the custom connection function to implement custom logic when detecting that the preset application calls the preset connection function through the second core library, so as to detect the preset socket.

[0013] In a third aspect, an embodiment of the present disclosure provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the function processing method provided in the embodiment of the present disclosure is implemented.

[0014] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the function processing method provided in the embodiment of the present disclosure.

[0015] The function processing scheme provided in the embodiment of the present disclosure is to load a first core library in a preset application, wherein the first core library realizes centralized management of calls to preset sockets by injecting a proxy connection function into a second core library, and the second core library contains a preset connection function for establishing a connection with a preset socket. Based on the preset injection method corresponding to the first core library, a custom connection function is injected into the second core library, and when it is detected that the preset application calls the preset connection function through the second core library, it is replaced by calling the custom connection function to detect the preset socket. By adopting the above technical scheme, it is not necessary to inject custom code into each place where a socket needs to be called to achieve the purpose of detecting the socket. The custom connection function is injected into the second core library using the preset injection method that can inject the proxy connection function into the second core library, so that the custom connection function can have the function of the proxy connection function to realize centralized management of calls to the preset socket, that is, through the injection of the custom connection function once, the effect of batch injection of detection codes corresponding to multiple preset sockets can be achieved, reducing the amount of injection of code for detecting sockets, and ensuring the stability and performance of the application. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Figure 1A flowchart of a function processing method provided in an embodiment of the present disclosure;

[0017] Figure 2 A flowchart of another function processing method provided in an embodiment of the present disclosure;

[0018] Figure 3 A schematic diagram illustrating the principle of a function processing method provided in an embodiment of the present disclosure;

[0019] Figure 4 A structural block diagram of a function processing device provided in an embodiment of the present disclosure;

[0020] Figure 5 This is a structural block diagram of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0021] The following describes embodiments of the present disclosure in more detail with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as limited to the embodiments described herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are for illustrative purposes only and are not intended to limit the scope of protection of the present disclosure.

[0022] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.

[0023] As used herein, the term "including" and its variations are open-ended, i.e., "including but not limited to." The term "based on" means "based, at least in part, on." The term "one embodiment" means "at least one embodiment," the term "another embodiment" means "at least one additional embodiment," and the term "some embodiments" means "at least some embodiments." Other terms are defined in the following description.

[0024] It should be noted that the concepts of "first" and "second" mentioned in this disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.

[0025] It should be noted that the modifications of "one" and "multiple" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, they should be understood as "one or more".

[0026] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.

[0027] In the following embodiments, each embodiment provides optional features and examples at the same time. The various features recorded in the embodiments can be combined to form multiple optional solutions. Each numbered embodiment should not be regarded as just one technical solution.

[0028] Figure 1 This is a flow chart of a function processing method provided in an embodiment of the present disclosure. This method can be applied to a preset application and executed by a function processing device, which can be implemented in software and / or hardware and generally integrated into an electronic device. The electronic device can be a mobile device such as a mobile phone, smartwatch, tablet computer, or personal digital assistant; it can also be other devices such as a desktop computer.

[0029] like Figure 1 As shown, the method includes:

[0030] Step 101: Load a first core library in a preset application, wherein the first core library implements centralized management of calls to a preset socket by injecting a proxy connection function in the first core library into a second core library, wherein the second core library includes a preset connection function, and the preset connection function is used to establish a connection with a preset socket.

[0031] For example, the preset application can be any application with network access capabilities. The preset application is installed in an operating system, the specific type of which is not limited, and can include, for example, Unix, Linux, iOS, macOS, or OS X, and Android. For ease of explanation, Android will be used as an example below.

[0032] For example, a core library, also known as a kernel library, can be understood as a library that provides basic functionality within an operating system. Applications implementing network capabilities require the use of sockets, which are implemented in the second core library. This socket implementation includes a connect function, also known as a connect method. The connect function, as a socket implementation, can be used to establish a connection with a corresponding socket. When an application initiates a network request and needs to call a socket, it can call the corresponding connect function. The name of the second core library may vary across operating systems. For example, in Android, the second core library may be the Bionic library. The first core library is a separate core library from the second core library. Because socket calls are frequently required, for ease of management, the first core library can aggregate sockets at the system level, proxying the actual socket implementation in the second core library to the first core library. The first core library can then inject its own socket implementation (referred to as a proxy connect function) into the second core library. This ensures that when the connect function in the second core library is executed, the proxy connect function is executed first, thereby enabling centralized management of socket calls. The name of the second core library may be different in different operating systems. Taking Android as an example, the second core library may be the NetdClient library, and the corresponding library file may be the libnetd_client.so file.

[0033] Exemplarily, the preset socket may include all or part of the sockets implemented in the second core library, and accordingly, the preset connection function may include all or part of the connection functions existing in the second core library, corresponding to the preset socket.

[0034] For example, the preset application can actively load the first core library after startup, or load the first core library when a loading event of the first core library is detected. Optionally, the second core library can be loaded at the same or different timing as the first core library.

[0035] Step 102: Based on the preset injection method corresponding to the proxy connection function, inject the custom connection function into the second core library.

[0036] Exemplarily, the preset injection method corresponding to the proxy connection function can be understood as an injection method capable of injecting the proxy connection function into the second core library. This method can be written according to actual needs, or the injection method provided by the operating system can be reused. Optionally, the preset injection method includes a method provided by the operating system for injecting the proxy connection function in the first core library into the second core library.

[0037] For example, taking Android as an example, the preset injection method includes the NetdClientInitConnect method. This method is open to the public by the Android operating system, and the preset application can obtain this method and then call it.

[0038] Exemplarily, the custom connection function may be injected into the second core library by calling a preset injection method.

[0039] In the embodiment of the present disclosure, a custom connection function can be pre-written during the development stage of a preset application. The function of the custom connection function is to implement custom logic. The custom logic can be understood as the logic required to implement the hook. The specific content can be written according to actual needs and is not limited here. The custom logic can exist in the custom connection function in the form of parameters, which can also be called custom parameters. The custom parameters can specifically be functions or related codes used to implement custom logic.

[0040] Optionally, the custom connection function is injected as preset parameters. When calling a preset injection method, the preset parameters can be passed in, and the preset parameters can be understood as the object to be injected. The custom connection function is used as the injection object, that is, the custom connection function is passed into the preset injection method, so that the custom connection function is injected into the second core library.

[0041] Step 103: When it is detected that the preset application program calls the preset connection function through the second core library, the preset connection function is replaced by calling the custom connection function to implement the custom logic to detect the preset socket.

[0042] For example, when the preset application initiates a network request, if it needs to call the preset socket, it needs to call the corresponding preset connection function through the second core library. Since the custom connection function has been injected into the second core library before, the original preset connection function currently called will not be executed directly. Instead, the custom connection function will be executed first, and then the custom logic will be implemented. At this time, since the preset connection function is not directly executed, it is impossible to directly establish a connection with the preset socket, thereby realizing the detection of the preset socket.

[0043] The function processing method provided in the embodiment of the present disclosure is to load a first core library in a preset application, wherein the first core library realizes centralized management of calls to preset sockets by injecting a proxy connection function into a second core library, and the second core library contains a preset connection function for establishing a connection with a preset socket, and based on the preset injection method corresponding to the first core library, a custom connection function is injected into the second core library, and when it is detected that the preset application calls the preset connection function through the second core library, it is replaced by calling the custom connection function to detect the preset socket. By adopting the above technical solution, it is not necessary to inject custom code into each place where a socket needs to be called to achieve the purpose of detecting the socket. The custom connection function is injected into the second core library using the preset injection method that can inject the proxy connection function into the second core library, so that the custom connection function can have the function of the proxy connection function to realize centralized management of calls to the preset socket, that is, through the injection of the custom connection function once, the effect of batch injection of detection codes corresponding to multiple preset sockets can be achieved, reducing the amount of injection of code for detecting sockets, and ensuring the stability and performance of the application.

[0044] In some embodiments, injecting the custom connection function into the second core library based on the preset injection method corresponding to the proxy connection function includes: using a preset dynamic library symbol function to find the address of the preset injection method corresponding to the proxy connection function; and calling the preset injection method according to the address of the preset injection method to inject the custom connection function into the second core library. The advantage of this configuration is that the address of the preset injection method provided by the operating system can be quickly and accurately found and called.

[0045] The dynamic library symbol (dlsym) function operates on a handle and symbol in a dynamic link library and returns the symbol's corresponding address. This function can be used to obtain both function addresses and variable addresses. A pre-programmed dynamic library symbol function can be understood as a dlsym function pre-written during application development to locate the address of a pre-programmed injection method, such as the dlsym function used to locate the address of the NetdClientInitConnect method.

[0046] In some embodiments, after replacing the call to the custom connection function to implement the custom logic, the method further includes: executing a system call of the preset connection function. This configuration has the advantage of preventing the preset connection function from being called again after the custom connection function is executed, thereby preventing the preset connection function from being replaced by the custom connection function again, resulting in an infinite hook call loop.

[0047] For example, a system call (also known as a system call or syscall) is a means for user space to access the kernel and is a legitimate entry point into the kernel. When a preset connection function is normally called, the corresponding system call will continue to be executed to call the relevant functions of the system bottom layer (kernel layer, also known as the kernel layer), ultimately implementing the function of the preset connection function. In the embodiment of the present disclosure, after calling a custom connection function to implement custom logic, the system call of the preset connection function is directly executed instead of returning to call the preset connection function, thereby preventing an infinite dead loop and ensuring the normal operation of the preset application.

[0048] In some embodiments, when the type parameter in the preset connection function is a network socket, the custom logic includes replacing the destination address in the preset connection function with the target address corresponding to the local server proxy. The advantage of this setting is that the custom logic can forward network requests to the local server proxy, facilitating the acquisition of data transmitted between the preset application and the real server, thereby achieving network data acquisition. A network socket can be understood as a common socket used for communication between processes running on different computer devices. A local server proxy can be understood as a proxy server implemented within the preset application, and a real server can be understood as a remote server required by the preset application to establish a network connection. During the development phase of the preset application, relevant code for implementing the local server proxy can be pre-written, including the target address corresponding to the local server proxy. Optionally, the target address can include the Internet Protocol (IP) address corresponding to the local network card of the electronic device, such as 127.0.0.1. After the preset application is started, the local server proxy can be started within the preset application and bound to the target address. Network data can then be acquired through the local server proxy, achieving network data acquisition within the application.

[0049] In some embodiments, when the type parameter in the preset connection function is a local socket, the custom logic includes replacing the destination file path in the preset connection function with the target file path corresponding to the local domain name server proxy. This configuration has the advantage of allowing network requests to be directed to the local domain name server proxy through the custom logic, facilitating network traffic control during the domain name resolution phase. A local socket, also known as a Unix domain socket, is used for communication between processes running on the same computer device. The local domain name server proxy can specifically be a domain name server proxy based on a local socket service, which can be understood as a localsocket server for domain name resolution. During the development phase of a preset application, code implementing the domain name server proxy can be pre-written, including the target file path corresponding to the domain name server proxy. After the preset application is launched, the domain name server proxy can be started and associated with the target file path. When the local socket is called, the destination file path in the corresponding connection function is replaced with the target file path, thereby enabling the preset application (which can also be understood as the client loaded in the preset application process during the domain name resolution phase, such as NetdClient in the Android operating system) to avoid directly connecting to a real domain name server (such as NetdServer in the Android operating system).

[0050] Optionally, replacing the destination address in the preset connection function with the destination address corresponding to the local server proxy can be recorded as the first custom logic, and the corresponding custom connection function can be recorded as the first custom connection function; replacing the destination file path in the preset connection function with the destination file path corresponding to the local domain name server proxy can be recorded as the second custom logic, and the corresponding custom connection function can be recorded as the second custom connection function. The first custom connection function and the second custom connection function can be injected into the second core library in advance. When it is detected that the preset application calls the preset connection function through the second core library, the type parameter in the preset connection function is first obtained. If the type parameter is a network socket, it is replaced by calling the first custom connection function to implement the first custom logic; if the type parameter is a local socket, it is replaced by calling the second custom connection function to implement the second custom logic.

[0051] It should be noted that there may be other custom logics. The above-mentioned first custom logic and second custom logic are only for illustrative purposes. In actual applications, they can be written according to actual needs, and are not specifically limited in the embodiments of the present disclosure.

[0052] Figure 2 This is a flow chart of a function processing method provided in an embodiment of the present disclosure. The embodiment of the present disclosure is optimized based on the various optional solutions in the above embodiments. Figure 3A schematic diagram of a function processing method provided in an embodiment of the present disclosure, which can be combined with Figure 2 and Figure 3 Understand the embodiments of the present disclosure.

[0053] Specifically, taking the Android operating system as an example, the method includes the following steps:

[0054] Step 201: After the preset application is started, the first core library is loaded in the preset application, wherein the first core library implements centralized management of calls to the preset socket by injecting the proxy connection function in the first core library into the second core library, and the second core library contains the preset connection function, which is used to establish a connection with the preset socket.

[0055] Exemplarily, after the application is started, it is preset to actively load the NetdClient library, that is, load the libnetd_client.so file.

[0056] Step 202: Use the preset dynamic library symbol function to search for the address of the preset injection method corresponding to the proxy connection function.

[0057] For example, a preset dlsym function may be pre-written during the development phase of a preset application program, and the preset application program uses the preset dlsym function to find the address of the NetdClientInitConnect method.

[0058] Step 203: Call the preset injection method according to the address of the preset injection method to inject the custom connection function into the second core library.

[0059] The custom connection function is injected in the form of preset parameters, and the custom connection function is used to implement custom logic.

[0060] like Figure 3 As shown, the default application injects the custom connection function into the second core library by calling the default injection method in the first core library. Taking Android as an example, the default application can call the NetdClientInitConnect method in the NetdClient library and pass in the custom connection function to inject the custom connection function into the Bionic library.

[0061] Step 204: When it is detected that the preset application program calls the preset connection function through the second core library, the preset connection function is replaced by calling the custom connection function to implement the custom logic to detect the preset socket.

[0062] like Figure 3As shown, when the preset application calls the preset socket, the preset connection function is called through the second core library. At this time, it is replaced by calling the custom connection function and executing the corresponding system call.

[0063] For example, when a preset application initiates a network request, it can be detected that the preset application calls a preset connection function in the Bionic library. At this time, it is replaced by calling a custom connection function to implement the logic required for the hook.

[0064] Step 205: Execute the system call of the preset connection function.

[0065] For example, after the logic required by the hook is executed, a system call is used to perform the underlying operation of the preset connection function to prevent an infinite loop call.

[0066] The function processing method provided by the embodiment of the present disclosure is that after the application is started, it finds the address of the NetdClientInitConnect method in the NetdClient library and injects the custom connection function used to implement the custom logic into the Bionic library by calling the NetdClientInitConnect method. This allows subsequent applications to replace the original connection function in the Bionic library with calls to the custom connection function to implement the custom logic and detect the socket call. By adopting this solution, there is no need to inject detection code into every location in the Bionic library that needs to call the preset connection function, which can reduce the amount of detection code injected and ensure the stability and performance of the application.

[0067] Figure 4 This is a structural block diagram of a function processing device provided by an embodiment of the present disclosure. The device can be configured in a preset application, can be implemented by software and / or hardware, can generally be integrated into an electronic device, and can perform function processing by executing a function processing method. Figure 4 As shown, the device includes:

[0068] A loading module 401 is configured to load a first core library into a preset application, wherein the first core library centrally manages calls to a preset socket by injecting a proxy connection function in the first core library into a second core library, wherein the second core library includes a preset connection function for establishing a connection with the preset socket;

[0069] An injection method calling module 402 is configured to inject the custom connection function into the second core library based on a preset injection method corresponding to the proxy connection function;

[0070] The connection function calling module 403 is configured to, when detecting that the preset application calls the preset connection function through the second core library, replace it with calling the custom connection function to implement custom logic so as to detect the preset socket.

[0071] The function processing device provided in the embodiment of the present disclosure does not need to inject custom code into each place where a socket needs to be called to achieve the purpose of detecting the socket. The custom connection function is injected into the second core library using a preset injection method that can inject the proxy connection function into the second core library, so that the custom connection function can have the function of the proxy connection function to realize centralized management of the calls to the preset socket, that is, through the one-time injection of the custom connection function, the effect of batch injection of detection codes corresponding to multiple preset sockets can be achieved, thereby reducing the amount of code injected for detecting the socket and ensuring the stability and performance of the application.

[0072] Optionally, the custom connection function is injected in the form of preset parameters.

[0073] Optionally, the preset injection method includes a method provided by an operating system for injecting the proxy connection function into the second core library.

[0074] Optionally, the injection method calling module includes:

[0075] An address search unit, configured to use a preset dynamic library symbol function to search for an address of a preset injection method corresponding to the proxy connection function;

[0076] The injection method calling unit is used to call the preset injection method according to the address of the preset injection method to inject the custom connection function into the second core library.

[0077] Optionally, the device further includes:

[0078] The system call execution module is used to execute the system call of the preset connection function after replacing it with calling the custom connection function to implement the custom logic.

[0079] Optionally, the operating system includes an Android operating system, the first core library includes a NetdClient library, the second core library includes a Bionic library, and the preset injection method includes a NetdClientInitConnect method.

[0080] Optionally, when the type parameter in the preset connection function is a network socket, the custom logic includes replacing the destination address in the preset connection function with a target address corresponding to the local server agent.

[0081] Optionally, when the type parameter in the preset connection function is a local socket, the custom logic includes replacing the destination file path in the preset connection function with a target file path corresponding to the local domain name server agent.

[0082] Reference below Figure 5 , which shows a schematic structural diagram of an electronic device 500 suitable for implementing the embodiments of the present disclosure. The electronic devices in the embodiments of the present disclosure may include, but are not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 5 The electronic device shown is only an example and should not limit the functions and scope of use of the embodiments of the present disclosure.

[0083] like Figure 5 As shown, the electronic device 500 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage device 508 into a random access memory (RAM) 503. Various programs and data required for the operation of the electronic device 500 are also stored in the RAM 503. The processing device 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0084] Typically, the following devices may be connected to the I / O interface 505: an input device 506 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 507 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 508 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 509. The communication device 509 may allow the electronic device 500 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 5 The electronic device 500 is shown with various devices, but it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed instead.

[0085] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart 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 non-transitory computer-readable medium, and the computer program includes 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 device 509, or installed from the storage device 508, or installed from the ROM 502. When the computer program is executed by the processing device 501, the above-mentioned functions defined in the method of the embodiment of the present disclosure are performed.

[0086] It should be noted that the computer-readable medium mentioned above in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or component, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, 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), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, device, or component. In the present disclosure, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium may be transmitted using any suitable medium, including but not limited to wires, optical cables, RF (radio frequency), etc., or any suitable combination thereof.

[0087] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.

[0088] The above-mentioned computer-readable medium carries one or more programs. When the above-mentioned one or more programs are executed by the electronic device, the electronic device: loads a first core library in a preset application, wherein the first core library implements centralized management of calls to the preset socket by injecting the proxy connection function in the first core library into the second core library, and the second core library contains a preset connection function, and the preset connection function is used to establish a connection with the preset socket; based on the preset injection method corresponding to the proxy connection function, a custom connection function is injected into the second core library; when it is detected that the preset application calls the preset connection function through the second core library, it is replaced by calling the custom connection function to implement custom logic to detect the preset socket.

[0089] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages, or a combination thereof, including, but not limited to, object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on the remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).

[0090] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation 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 flowchart or block diagram can represent a module, program segment, or a part of code, and the module, program segment, or a part of 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 than that 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 and / or flowchart, and the combination of the boxes in the block diagram and / or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0091] The modules involved in the embodiments described in the present disclosure may be implemented by software or by hardware. The name of the module does not, in some cases, constitute a limitation on the module itself. For example, a loading module may also be described as "a module that loads a first core library in a preset application, wherein the first core library implements centralized management of calls to a preset socket by injecting a proxy connection function in the first core library into a second core library, and the second core library contains a preset connection function, which is used to establish a connection with the preset socket."

[0092] The functions described above herein may be performed, at least in part, by one or more hardware logic components. For example, and without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chip (SOCs), complex programmable logic devices (CPLDs), and the like.

[0093] In the context of the present disclosure, a machine-readable medium can be a tangible medium that can contain or store a program for use by or in conjunction with an instruction execution system, device or equipment. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium can include an electrical connection based on one or more lines, 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), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0094] According to one or more embodiments of the present disclosure, a function processing method is provided, including:

[0095] Loading a first core library in a preset application, wherein the first core library centrally manages calls to a preset socket by injecting a proxy connection function in the first core library into a second core library, wherein the second core library includes a preset connection function, and the preset connection function is used to establish a connection with the preset socket;

[0096] Injecting the custom connection function into the second core library based on a preset injection method corresponding to the proxy connection function;

[0097] When it is detected that the preset application calls the preset connection function through the second core library, the preset connection function is called instead to implement custom logic to detect the preset socket.

[0098] Furthermore, the custom connection function is injected in the form of preset parameters.

[0099] Furthermore, the preset injection method includes a method provided by the operating system for injecting the proxy connection function into the second core library.

[0100] Furthermore, the step of injecting the custom connection function into the second core library based on the preset injection method corresponding to the proxy connection function includes:

[0101] Using a preset dynamic library symbol function to search for the address of a preset injection method corresponding to the proxy connection function;

[0102] The preset injection method is called according to the address of the preset injection method to inject the custom connection function into the second core library.

[0103] Furthermore, after replacing the calling of the custom connection function to implement the custom logic, the method further includes:

[0104] Execute the system call of the preset connection function.

[0105] Furthermore, the operating system includes an Android operating system, the first core library includes a NetdClient library, the second core library includes a Bionic library, and the preset injection method includes a NetdClientInitConnect method.

[0106] Furthermore, when the type parameter in the preset connection function is a network socket, the custom logic includes replacing the destination address in the preset connection function with a target address corresponding to the local server agent.

[0107] Furthermore, when the type parameter in the preset connection function is a local socket, the custom logic includes replacing the destination file path in the preset connection function with a target file path corresponding to the local domain name server proxy.

[0108] According to one or more embodiments of the present disclosure, there is provided a function processing device, comprising:

[0109] a loading module, configured to load a first core library into the preset application, wherein the first core library centrally manages calls to a preset socket by injecting a proxy connection function in the first core library into a second core library, wherein the second core library includes a preset connection function, and the preset connection function is used to establish a connection with the preset socket;

[0110] An injection method calling module, configured to inject the custom connection function into the second core library based on a preset injection method corresponding to the proxy connection function;

[0111] The connection function calling module is used to replace the calling of the custom connection function to implement custom logic when detecting that the preset application calls the preset connection function through the second core library, so as to detect the preset socket.

[0112] The above description is merely a preferred embodiment of the present disclosure and an illustration of the technical principles employed. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by the specific combination of the above-mentioned technical features, but also includes other technical solutions formed by any combination of the above-mentioned technical features or their equivalents without departing from the above-mentioned disclosed concepts. For example, a technical solution formed by replacing the above-mentioned features with (but not limited to) technical features with similar functions disclosed in this disclosure.

[0113] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details have been included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.

[0114] Although the subject matter has been described in language specific to structural features and / or methodological logical acts, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are merely example forms of implementing the claims.

Claims

1. A function processing method, characterized in that: include: Loading a first core library in a preset application, wherein the first core library centrally manages calls to a preset socket by injecting a proxy connection function in the first core library into a second core library, wherein the second core library includes a preset connection function, and the preset connection function is used to establish a connection with the preset socket; Injecting the custom connection function into the second core library based on a preset injection method corresponding to the proxy connection function; When it is detected that the preset application calls the preset connection function through the second core library, the preset connection function is called instead to implement custom logic to detect the preset socket.

2. The method according to claim 1, characterized in that The custom connection function is injected in the form of preset parameters.

3. The method according to claim 1, characterized in that The preset injection method includes a method provided by the operating system for injecting the proxy connection function into the second core library.

4. The method according to claim 3, characterized in that The step of injecting the custom connection function into the second core library based on the preset injection method corresponding to the proxy connection function includes: Using a preset dynamic library symbol function to search for the address of a preset injection method corresponding to the proxy connection function; The preset injection method is called according to the address of the preset injection method to inject the custom connection function into the second core library.

5. The method according to claim 1, wherein After replacing it with calling the custom connection function to implement the custom logic, it also includes: Execute the system call of the preset connection function.

6. The method according to claim 3, characterized in that The operating system includes an Android operating system, the first core library includes a NetdClient library, the second core library includes a Bionic library, and the preset injection method includes a NetdClientInitConnect method.

7. The method according to any one of claims 1 to 6, characterized in that: When the type parameter in the preset connection function is a network socket, the custom logic includes replacing the destination address in the preset connection function with a target address corresponding to the local server agent.

8. The method according to any one of claims 1 to 6, characterized in that: When the type parameter in the preset connection function is a local socket, the custom logic includes replacing the destination file path in the preset connection function with a target file path corresponding to the local domain name server agent.

9. A function processing device, characterized in that: include: a loading module, configured to load a first core library in a preset application, wherein the first core library centrally manages calls to a preset socket by injecting a proxy connection function in the first core library into a second core library, wherein the second core library includes a preset connection function, and the preset connection function is used to establish a connection with the preset socket; An injection method calling module, configured to inject the custom connection function into the second core library based on a preset injection method corresponding to the proxy connection function; The connection function calling module is used to replace the calling of the custom connection function to implement custom logic when detecting that the preset application calls the preset connection function through the second core library, so as to detect the preset socket.

10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the method according to any one of claims 1 to 8 is implemented.

11. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.

Citation Information

Patent Citations

  • Traffic monitoring method and device, storage medium and electronic equipment

    CN113556260A