WO2023116503A1 - 函数处理方法、装置、设备及存储介质 - Google Patents
函数处理方法、装置、设备及存储介质 Download PDFInfo
- Publication number
- WO2023116503A1 WO2023116503A1 PCT/CN2022/138605 CN2022138605W WO2023116503A1 WO 2023116503 A1 WO2023116503 A1 WO 2023116503A1 CN 2022138605 W CN2022138605 W CN 2022138605W WO 2023116503 A1 WO2023116503 A1 WO 2023116503A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- preset
- connection function
- core library
- function
- socket
- Prior art date
Links
- 238000003672 processing method Methods 0.000 title claims abstract description 19
- 238000000034 method Methods 0.000 claims abstract description 100
- 238000002347 injection Methods 0.000 claims abstract description 65
- 239000007924 injection Substances 0.000 claims abstract description 65
- 230000006870 function Effects 0.000 claims description 262
- 238000012545 processing Methods 0.000 claims description 16
- 239000003795 chemical substances by application Substances 0.000 claims description 14
- 238000004590 computer program Methods 0.000 claims description 14
- 239000011664 nicotinic acid Substances 0.000 claims description 9
- 239000000243 solution Substances 0.000 abstract description 12
- 238000010586 diagram Methods 0.000 description 10
- 238000001514 detection method Methods 0.000 description 9
- 238000004891 communication Methods 0.000 description 7
- 230000003287 optical effect Effects 0.000 description 6
- 238000011161 development Methods 0.000 description 5
- 230000008569 process Effects 0.000 description 5
- 230000008901 benefit Effects 0.000 description 4
- 230000000694 effects Effects 0.000 description 3
- 230000009471 action Effects 0.000 description 2
- 238000005516 engineering process Methods 0.000 description 2
- 239000013307 optical fiber Substances 0.000 description 2
- 230000000644 propagated effect Effects 0.000 description 2
- 239000004065 semiconductor Substances 0.000 description 2
- 239000008186 active pharmaceutical agent Substances 0.000 description 1
- 238000003491 array Methods 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000005457 optimization Methods 0.000 description 1
- 230000001960 triggered effect Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/547—Remote procedure calls [RPC]; Web services
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/541—Interprogram communication via adapters, e.g. between incompatible applications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/16—Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
- H04L69/161—Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields
- H04L69/162—Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields involving adaptations of sockets based mechanisms
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Definitions
- Embodiments of the present disclosure relate to the field of computer technology, and in particular, to a function processing method, device, device, and storage medium.
- Socket is an application programming interface (Application Programming Interface, API) for inter-process communication in a network environment, also known as a socket interface, which is the underlying interface of network capabilities on many operating system platforms. For network conditions, it is often necessary to detect (Hook) the socket related to the network capability of the application program.
- API Application Programming Interface
- Embodiments of the present disclosure provide a function processing method, device, storage medium, and equipment, which can optimize existing function processing schemes.
- an embodiment of the present disclosure provides a function processing method, including:
- the first core library implements the calling of the preset socket by injecting the proxy connection function in the first core library into the second core library Centralized management, the second core library includes a preset connection function, and the preset connection function is used to establish a connection with the preset socket;
- 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, so as to detect the preset socket .
- an embodiment of the present disclosure provides a function processing device, including:
- the loading module is used to load the first core library in the preset application program, wherein the first core library implements the preset package by injecting the proxy connection function in the first core library into the second core library
- the call of the socket is managed centrally, and 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 a custom connection function into the second core library based on a preset injection method corresponding to the proxy connection function;
- a link function calling module configured to call the custom link function to implement custom logic when detecting that the preset application program calls the preset link function through the second core library, so as to implement custom logic for all The default socket mentioned above is detected.
- an embodiment of the present disclosure provides an electronic device, including a memory, a processor, and a computer program stored on the memory and operable on the processor.
- the processor executes the computer program, the computer program according to the present disclosure is implemented The function processing method provided by the embodiment.
- the embodiments of the present disclosure provide a computer-readable storage medium on which a computer program is stored, and when the program is executed by a processor, the function processing method provided in the embodiments of the present disclosure is implemented.
- the first core library is loaded in the preset application program, wherein the first core library implements the call to the preset socket by injecting the proxy connection function into the second core library
- the second core library contains a preset connection function for establishing a connection with a preset socket, and injects a custom connection function into the second core library based on the default injection method corresponding to the first 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 a custom connection function to detect the preset socket.
- FIG. 1 is a schematic flowchart of a function processing method provided by an embodiment of the present disclosure
- FIG. 2 is a schematic flowchart of another function processing method provided by an embodiment of the present disclosure
- FIG. 3 is a schematic diagram of the principle of a function processing method provided by an embodiment of the present disclosure
- FIG. 4 is a structural block diagram of a function processing device provided by an embodiment of the present disclosure.
- Fig. 5 is a structural block diagram of an electronic device provided by an embodiment of the present disclosure.
- the term “comprise” and its variations are open-ended, ie “including but not limited to”.
- the term “based on” is “based at least in part on”.
- the term “one embodiment” means “at least one embodiment”; the term “another embodiment” means “at least one further embodiment”; the term “some embodiments” means “at least some embodiments.” Relevant definitions of other terms will be given in the description below.
- 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 only as a technical solution.
- Fig. 1 is a schematic flowchart of a function processing method provided by an embodiment of the present disclosure, the method can be applied to a preset application program, and can be executed by a function processing device, wherein the device can be implemented by software and/or hardware, and generally can be integrated in in electronic equipment.
- the electronic device can be a mobile device such as a mobile phone, a smart watch, a tablet computer, and a personal digital assistant; it can also be other devices such as a desktop computer.
- the method includes:
- Step 101 load the first core library in the preset application program, wherein the first core library realizes the centralized calling of the preset socket by injecting the proxy connection function in the first core library into the second core library management, the second core library contains a preset connection function, and the preset connection function is used to establish a connection with a preset socket.
- the preset application program may be any application program with a network access function.
- the preset application program is loaded in the operating system, and the specific type of the operating system is not limited, for example, it may include Yonex (Unix), Linus (Linux), Apple (iOS, macOS or OS X) and Android ( Android), etc., for the sake of illustration, Android will be used as an example below.
- the core library may also be called a kernel library, which may be understood as a library used to provide basic functions in the operating system.
- a kernel library which may be understood as a library used to provide basic functions in the operating system.
- the application realizes the network capability, it needs to use the socket, and the implementation of the socket is in the second core library, and the implementation of the socket includes a connection (connect) function, which is also called a connect method.
- the connection function as a socket implementation can be used to establish a connection with the corresponding socket.
- the application program initiates a connection action of a network request and needs to call the socket, the connection function corresponding to the socket can be called.
- the name of the second core library may be different. Taking Android as an example, the second core library may be the Bionic library.
- the first core library is different from the second core library.
- the first core library can aggregate sockets at the system level, and the sockets in the second core library can be aggregated.
- the actual implementation of the agent is delegated to the first core library, and the first core library can inject its own socket implementation (which can be called a proxy connection function) into the second core library, so that when the connection function in the second core library is executed , execute the proxy connection function first, and then realize the centralized management of socket calls.
- the name of the second core library may be different. 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.
- the preset socket may include all or part of the socket implemented in the second core library, and correspondingly, the preset connection function may include all or part of the connection function existing in the second core library, and the preset Set the corresponding socket.
- the preset application program may actively load the first core library after being started, or may load the first core library when it is detected that a loading event of the first core library is triggered.
- the loading timing of the second core library may be the same as or different from that of the first core library.
- Step 102 based on the preset injection method corresponding to the proxy connection function, inject the custom connection function into the second core library.
- 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.
- the method can be written according to actual requirements, and the injection method provided by the operating system can also be reused.
- 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.
- the preset injection method includes the NetdClientInitConnect method. This method is open to the public by the Android operating system, and the preset application program can obtain the method and then call the method.
- the custom connection function may be injected into the second core library by calling a preset injection method.
- a custom connection function can be pre-written in the development stage of the preset application program.
- the function of the custom connection function is to realize the custom logic.
- the custom logic can be understood as the logic required to realize the hook.
- the specific content can be Write according to actual needs, there is no limitation here, custom logic can exist in the custom connection function in the form of parameters, and can also be called custom parameters, custom parameters can be functions used to implement custom logic or related code.
- the custom connection function is injected in the form of preset parameters.
- Preset parameters can be passed in when calling the preset injection method, and the preset parameters can be understood as objects that need 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 as to inject the custom connection function into the second core library.
- Step 103 When it is detected that the preset application calls the preset connection function through the second core library, it is replaced by calling a custom connection function to implement custom logic to detect the preset socket.
- the preset application program 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, because the custom connection function has been injected into the second The core library, therefore, does not directly execute the original preset connection function that is currently called, but executes the custom connection function first, and then implements the custom logic. At this time, because the default connection function is not directly executed, it cannot be directly established The connection with the preset socket, so as to realize the detection of the preset socket.
- the first core library is loaded in the preset application program, wherein the first core library realizes calling the preset socket by injecting the proxy connection function into the second core library
- the second core library contains a preset connection function for establishing a connection with a preset socket, and injects a custom connection function into the second core library based on the default injection method corresponding to the first 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 a custom connection function to detect the preset socket.
- the custom connection function is injected into the second core library, so that the custom connection function can have the function of proxy connection function to realize the centralized management of the call of the preset socket, that is, one injection of the custom connection function can Realize the effect of injecting detection codes corresponding to multiple preset sockets in batches, reduce the injection amount of codes used to detect sockets, and ensure the stability and performance of the application.
- injecting the custom connection function into the second core library based on the preset injection method corresponding to the proxy connection function includes: searching for the proxy connection function by using a preset dynamic library symbol function The address of the corresponding preset injection method; calling the preset injection method according to the address of the preset injection method, so as to inject the custom connection function into the second core library.
- the function of the dynamic library symbol (dynamic library symbol, dlsym) function is to operate the handle and symbol according to the dynamic link library, and return the address corresponding to the symbol, not only can obtain the function address, but also can obtain the variable address.
- the preset dynamic library symbol function can be understood as a dlsym function pre-written in the preset application development stage for finding the address of the preset injection method, for example, a dlsym function for finding the address of the NetdClientInitConnect method.
- the custom logic by calling the custom connection function after implementing the custom logic by calling the custom connection function, it further includes: executing a system call of the preset connection function.
- a system call (also called a system call or a syscall) is a means for user space to access the kernel (kernel), and is a legal entry of the kernel.
- the preset connection function normally, it will continue to execute the corresponding system call to call the relevant functions of the bottom layer of the system (kernel layer, also known as the kernel layer), and finally realize the function of the preset connection function.
- the system call of the preset connection function is directly executed instead of returning to call the preset connection function, so as to prevent the occurrence of an infinite loop and ensure that the default application normal operation of the program.
- the custom logic 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 destination address corresponding to the local server agent .
- the network socket can be understood as an ordinary socket, which is used for communication between processes running on different computer devices.
- the local server proxy proxy
- the real server can be understood as a remote server that needs to establish a network connection for the preset application program.
- the target address may include an Internet Protocol (Internet Protocol, IP) address corresponding to a local network card of the electronic device, such as 127.0.0.1.
- IP Internet Protocol
- the custom logic 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 one corresponding to the local domain name server agent target file path.
- local socket local socket
- the local domain name server proxy can specifically be a domain name server proxy based on local socket services, which can be understood as a local socket server for domain name resolution.
- relevant codes for realizing the proxy of the domain name server may be pre-written, including the target file path corresponding to the proxy of the domain name server.
- the domain name server proxy can be started, and the domain name server proxy can be associated with the target file path.
- the preset application program here can also be understood as the client in the domain name resolution stage loaded in the preset application program process, such as NetdClient in the Android operating system, avoids directly connecting to the real domain name server (such as the NetdClient in the Android operating system) NetdServer).
- 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 is recorded as the first custom connection function; the preset connection
- the replacement of the target file path in the function with the target file path corresponding to the local domain name server proxy can be recorded as the second custom logic, and the corresponding custom connection function is recorded as the second custom connection function.
- the first custom link function and the second custom link function may be injected into the second core library in advance.
- the preset application program calls the preset connection function through the second core library, first obtain the type parameter in the preset connection function, if the type parameter is a network socket, replace it with calling the first custom connection function to achieve The first custom logic; if the type parameter is a local socket, it is replaced by calling the second custom connection function to realize the second custom logic.
- first custom logic and second custom logic are only used as schematic illustrations, and can be written according to actual needs in actual applications, and are not specifically limited in the embodiments of the present disclosure. .
- FIG. 2 is a schematic flow chart of a function processing method provided by an embodiment of the present disclosure.
- the embodiment of the present disclosure performs optimization based on various alternative solutions in the foregoing embodiments.
- FIG. 3 is a schematic schematic diagram of a function processing method provided by an embodiment of the present disclosure, and the embodiment of the present disclosure can be understood in conjunction with FIG. 2 and FIG. 3 .
- the method includes the following steps:
- Step 201 after the preset application program is started, load the first core library in the preset application program, wherein the first core library implements the preset function by injecting the proxy connection function in the first core library into the second core library
- the call of the socket is managed centrally, 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.
- the NetdClient library is actively loaded, that is, the libnetd_client.so file is loaded.
- Step 202 using the default dynamic library symbol function to find the address of the default injection method corresponding to the proxy connection function.
- the preset dlsym function may be pre-written during the development stage of the preset application program, and the preset application program uses the preset dlsym function to find the address of the NetdClientInitConnect method.
- Step 203 Call the default injection method according to the address of the default injection method, so as to inject the custom connection function into the second core library.
- the custom connection function is injected in the form of preset parameters, and the custom connection function is used to implement custom logic.
- the default application program injects the custom connection function into the second core library by calling the preset injection method in the first core library.
- the default application can call the NetdClientInitConnect method in the NetdClient library, pass in a custom connection function, and inject the custom connection function into the Bionic library.
- Step 204 when it is detected that the preset application calls the preset connection function through the second core library, it is replaced by calling a custom connection function to implement custom logic, so as to detect the preset socket.
- the preset application program calls the preset socket, it calls the preset connection function through the second core library. At this time, it is replaced by calling a custom connection function and executing a corresponding system call.
- the preset application program when the preset application program initiates a network request, it may be detected that the preset application program calls the preset connection function in the Bionic library. At this time, it is replaced by calling a custom connection function to implement the logic required by the hook.
- Step 205 execute the system call of the preset connection function.
- a system call is used to perform the underlying operation of the preset connection function, so as to prevent an infinite loop call.
- the address of the NetdClientInitConnect method in the NetdClient library is found, and the custom connection function for implementing custom logic is injected into the Bionic library by calling the NetdClientInitConnect method , so that when the subsequent application calls the original connection function in the Bionic library, it is replaced by calling the custom connection function, so as to realize the custom logic and detect the socket call.
- Fig. 4 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 program, can be implemented by software and/or hardware, and can generally be integrated in an electronic device, and can be implemented by executing a function processing method for function processing.
- the device includes:
- the loading module 401 is configured to load the first core library in the preset application program, wherein the first core library realizes the preset The call of the socket is managed centrally, 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;
- An injection method calling module 402 configured to inject a custom connection function into the second core library based on a preset injection method corresponding to the proxy connection function;
- a connection function calling module 403 configured to call 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 The default socket to detect.
- the function processing device does not need to inject custom code for each place that needs to call the socket to achieve the purpose of detecting the socket.
- the default injection method injects the custom connection function into the second core library, so that the custom connection function can have the function of proxy connection function to realize the centralized management of the call of the preset socket, that is, through the custom connection
- One-time injection of the function can realize the effect of injecting detection codes corresponding to multiple preset sockets in batches, reduce the injection amount of codes used to detect sockets, and ensure the stability and performance of the application.
- the custom connection function is injected in the form of preset parameters.
- the preset injection method includes a method provided by an operating system for injecting the proxy connection function into the second core library.
- the injection method calling module includes:
- An address search unit configured to use a preset dynamic library symbol function to find the address of the preset injection method corresponding to the agent connection function;
- An injection method calling unit configured to call the preset injection method according to the address of the preset injection method, so as to inject the custom connection function into the second core library.
- the device also includes:
- a system call execution module configured to execute the system call of the preset connection function after replacing it with calling the self-defined connection function to realize the self-defined logic.
- the operating system includes an Android operating system
- the first core library includes a NetdClient library
- the second core library includes a Bionic library
- the preset injection method includes a NetdClientInitConnect method.
- the custom logic when the type parameter in the preset connection function is a network socket, includes replacing the destination address in the preset connection function with the destination address corresponding to the local server proxy.
- the custom logic when the type parameter in the preset connection function is a local socket, includes replacing the target file path in the preset connection function with the target file corresponding to the local domain name server agent path.
- FIG. 5 it shows a schematic structural diagram of an electronic device 500 suitable for implementing an embodiment of the present disclosure.
- the electronic equipment in the embodiment of the present disclosure may include but not limited to such as mobile phone, notebook computer, digital broadcast receiver, PDA (personal digital assistant), PAD (tablet computer), PMP (portable multimedia player), vehicle terminal (such as mobile terminals such as car navigation terminals) and fixed terminals such as digital TVs, desktop computers and the like.
- the electronic device shown in FIG. 5 is only an example, and should not limit the functions and scope of use of the embodiments of the present disclosure.
- an electronic device 500 may include a processing device (such as a central processing unit, a graphics processing unit, etc.) 501, which may be randomly accessed according to a program stored in a read-only memory (ROM) 502 or loaded from a storage device 508.
- ROM read-only memory
- RAM random access memory
- various appropriate actions and processes are executed by programs in the memory (RAM) 503 .
- RAM random access memory
- various programs and data necessary for the operation of the electronic device 500 are also stored.
- the processing device 501, ROM 502, and RAM 503 are connected to each other through a bus 504.
- An input/output (I/O) interface 505 is also connected to the bus 504 .
- the following devices can be connected to the I/O interface 505: input devices 506 including, for example, a touch screen, touchpad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; including, for example, a liquid crystal display (LCD), speaker, vibration an output device 507 such as a computer; a storage device 508 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 509.
- the communication means 509 may allow the electronic device 500 to perform wireless or wired communication with other devices to exchange data. While FIG. 5 shows electronic device 500 having various means, it should be understood that implementing or having all of the means shown is not a requirement. More or fewer means may alternatively be implemented or provided.
- embodiments of the present disclosure include a computer program product, which includes a computer program carried on a non-transitory computer readable medium, where the computer program includes program code for executing the method shown in the flowchart.
- the computer program may be downloaded and installed from a network via communication means 509, or from storage means 508, or from ROM 502.
- the processing device 501 When the computer program is executed by the processing device 501, the above-mentioned functions defined in the methods of the embodiments of the present disclosure are executed.
- 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 device, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to, electrical connections with one or more wires, portable computer diskettes, hard disks, random access memory (RAM), read-only memory (ROM), erasable Programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination of the above.
- 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, apparatus, or device.
- a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave carrying computer-readable program code therein. Such propagated data signals may take many forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing.
- a computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which can transmit, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device .
- Program code embodied on a computer readable medium may be transmitted by any appropriate medium, including but not limited to wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
- the above-mentioned computer-readable medium may be included in the above-mentioned electronic device, or may exist independently without being incorporated into the electronic device.
- the above-mentioned computer-readable medium carries one or more programs, and when the above-mentioned one or more programs are executed by the electronic device, the electronic device: loads the first core library in the preset application program, wherein the first The core library implements centralized management of calls to preset sockets by injecting the proxy connection function in the first core library into the second core library.
- the second core library contains a preset connection function, and the 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, the custom connection function is injected into the second core library; the preset connection function is detected It is assumed that when the application calls the preset connection function through the second core library, it is replaced by calling the custom connection function to implement custom logic, so as to detect the preset socket.
- Computer program code for carrying out operations of the present disclosure may be written in one or more programming languages, or combinations thereof, including but not limited to object-oriented programming languages—such as Java, Smalltalk, C++, and Includes conventional procedural programming languages - such as the "C" language or similar programming languages.
- the program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server.
- the remote computer can be connected to the user computer through any kind of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (such as through an Internet service provider). Internet connection).
- LAN local area network
- WAN wide area network
- Internet service provider such as AT&T, MCI, Sprint, EarthLink, MSN, GTE, etc.
- each block in a flowchart or block diagram may represent a module, program segment, or portion of code that contains one or more logical functions for implementing specified executable instructions.
- the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or they may sometimes be executed in the reverse order, depending upon the functionality involved.
- each block of the block diagrams and/or flowchart illustrations, and combinations of blocks in the block diagrams and/or flowchart illustrations can be implemented by a dedicated hardware-based system that performs the specified functions or operations , or may be implemented by a combination of dedicated hardware and computer instructions.
- the modules involved in the embodiments described in the present disclosure may be implemented by software or by hardware. Wherein, the name of the module does not constitute a limitation on the module itself under certain circumstances.
- the loading module can also be described as "a module that loads the first core library in the preset application program, wherein the first The core library implements centralized management of calls to preset sockets by injecting the proxy connection function in the first core library into the second core library.
- the second core library contains a preset connection function, and the The default connection function is used to establish a connection with the default socket".
- FPGAs Field Programmable Gate Arrays
- ASICs Application Specific Integrated Circuits
- ASSPs Application Specific Standard Products
- SOCs System on Chips
- CPLD Complex Programmable Logical device
- a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device.
- a machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium.
- a machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing.
- machine-readable storage media would include one or more wire-based electrical connections, portable computer discs, hard drives, random access memory (RAM), read only memory (ROM), erasable programmable read only memory (EPROM or flash memory), optical fiber, compact disk read only memory (CD-ROM), optical storage, magnetic storage, or any suitable combination of the foregoing.
- RAM random access memory
- ROM read only memory
- EPROM or flash memory erasable programmable read only memory
- CD-ROM compact disk read only memory
- magnetic storage or any suitable combination of the foregoing.
- a function processing method including:
- the first core library implements the calling of the preset socket by injecting the proxy connection function in the first core library into the second core library Centralized management, the second core library includes a preset connection function, and the preset connection function is used to establish a connection with the preset socket;
- 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, so as to detect the preset socket .
- custom connection function is injected in the form of preset parameters.
- the preset injection method includes a method provided by an operating system for injecting the proxy connection function into the second core library.
- injecting the custom connection function into the second core library based on the preset injection method corresponding to the proxy connection function includes:
- the operating system includes an Android operating system
- the first core library includes a NetdClient library
- the second core library includes a Bionic library
- the preset injection method includes a NetdClientInitConnect method.
- the custom logic includes replacing the destination address in the preset connection function with the destination address corresponding to the local server proxy.
- the custom logic includes replacing the target file path in the preset connection function with the target file path corresponding to the local domain name server agent .
- a function processing device including:
- a loading module configured to load a first core library in the preset application program, wherein the first core library implements the preset Set the call of the socket for centralized management, 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 a custom connection function into the second core library based on a preset injection method corresponding to the proxy connection function;
- a link function calling module configured to call the custom link function to implement custom logic when detecting that the preset application program calls the preset link function through the second core library, so as to implement custom logic for all The default socket mentioned above is detected.
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computer Security & Cryptography (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Stored Programmes (AREA)
Abstract
本公开实施例公开了函数处理方法、装置、设备及存储介质。该方法包括:在预设应用程序中加载第一核心库,其中,第一核心库通过将代理连接函数注入至第二核心库来实现对预设套接字的调用进行集中管理,第二核心库中包含用于建立与预设套接字的连接的预设连接函数,基于代理连接函数对应的预设注入方法,将自定义连接函数注入至第二核心库,检测到预设应用程序通过第二核心库调用预设连接函数时,替换为调用自定义连接函数,以对预设套接字进行检测。通过采用上述技术方案,可减少用于检测套接字的代码的注入量,保证应用程序的稳定性和性能。
Description
相关申请的交叉引用
本申请要求申请号为202111598174.9,题为“函数处理方法、装置、设备及存储介质”、申请日为2021年12月24日的中国发明专利申请的优先权,通过引用的方式将该申请整本并入本文。
本公开实施例涉及计算机技术领域,尤其涉及函数处理方法、装置、设备及存储介质。
套接字(socket)是网络环境中进程间通信的应用程序编程接口(Application Programming Interface,API),又称套接字接口,是很多操作系统平台上网络能力的底层接口,为了监控应用程序的网络状况,经常需要对与应用程序的网络能力相关的socket进行检测(Hook)。
目前,为了全面地了解网络状况,需要在所有调用socket的地方注入自定义的代码以达到检测的目的,例如常见的全程过程链接表检测(Procedure Linkage Table Hook)技术。现有检测方案注入的内容较多,影响应用程序整体的稳定性和性能,因此并不完善。
发明内容
本公开实施例提供了函数处理方法、装置、存储介质及设备,可以优化现有的函数处理方案。
第一方面,本公开实施例提供了一种函数处理方法,包括:
在预设应用程序中加载第一核心库,其中,所述第一核心库通过将所述第一核心库中的代理连接函数注入至第二核心库来实现对预设套接字的调用进行集中管理,所述第二核心库中包含预设连接函数,所述预设连接函数用于建立与所述预设套接字的连接;
基于所述代理连接函数对应的预设注入方法,将自定义连接函数注入至所述第二核心库;
检测到所述预设应用程序通过所述第二核心库调用所述预设连接函数时,替换为调用所述自定义连接函数来实现自定义逻辑,以对所述预设套接字进行检测。
第二方面,本公开实施例提供了一种函数处理装置,包括:
加载模块,用于在预设应用程序中加载第一核心库,其中,所述第一核心库通过将所述第一核心库中的代理连接函数注入至第二核心库来实现对预设套接字的调用进行集中管理,所述第二核心库中包含预设连接函数,所述预设连接函数用于建立与所述预设套接字的连接;
注入方法调用模块,用于基于所述代理连接函数对应的预设注入方法,将自定义连接函数注入至所述第二核心库;
连接函数调用模块,用于在检测到所述预设应用程序通过所述第二核心库调用所述预设连接函数时,替换为调用所述自定义连接函数来实现自定义逻辑,以对所述预设套接字进行检测。
第三方面,本公开实施例提供了一种电子设备,包括存储器、处理器及存 储在存储器上并可在处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现如本公开实施例提供的函数处理方法。
第四方面,本公开实施例提供了一种计算机可读存储介质,其上存储有计算机程序,该程序被处理器执行时实现如本公开实施例提供的函数处理方法。
本公开实施例中提供的函数处理方案,在预设应用程序中加载第一核心库,其中,第一核心库通过将代理连接函数注入至第二核心库来实现对预设套接字的调用进行集中管理,第二核心库中包含用于建立与预设套接字的连接的预设连接函数,基于第一核心库对应的预设注入方法,将自定义连接函数注入至第二核心库,检测到预设应用程序通过第二核心库调用预设连接函数时,替换为调用自定义连接函数,以对预设套接字进行检测。通过采用上述技术方案,不需要针对每个需要调用套接字的地方注入自定义的代码以达到检测套接字的目的,利用能够将代理连接函数注入至第二核心库的预设注入方法将自定义连接函数注入到第二核心库中,而使得自定义连接函数能够具备代理连接函数的功能实现对预设套接字的调用进行集中管理,也即通过自定义连接函数的一次注入可以实现批量地注入多个预设套接字对应的检测代码的效果,减少用于检测套接字的代码的注入量,保证应用程序的稳定性和性能。
图1为本公开实施例提供的一种函数处理方法的流程示意图;
图2为本公开实施例提供的又一种函数处理方法的流程示意图;
图3为本公开实施例提供的一种函数处理方法的原理示意图;
图4为本公开实施例提供的一种函数处理装置的结构框图;
图5为本公开实施例提供的一种电子设备的结构框图。
下面将参照附图更详细地描述本公开的实施例。虽然附图中显示了本公开的某些实施例,然而应当理解的是,本公开可以通过各种形式来实现,而且不应该被解释为限于这里阐述的实施例,相反提供这些实施例是为了更加透彻和完整地理解本公开。应当理解的是,本公开的附图及实施例仅用于示例性作用,并非用于限制本公开的保护范围。
应当理解,本公开的方法实施方式中记载的各个步骤可以按照不同的顺序执行,和/或并行执行。此外,方法实施方式可以包括附加的步骤和/或省略执行示出的步骤。本公开的范围在此方面不受限制。
本文使用的术语“包括”及其变形是开放性包括,即“包括但不限于”。术语“基于”是“至少部分地基于”。术语“一个实施例”表示“至少一个实施例”;术语“另一实施例”表示“至少一个另外的实施例”;术语“一些实施例”表示“至少一些实施例”。其他术语的相关定义将在下文描述中给出。
需要注意,本公开中提及的“第一”、“第二”等概念仅用于对不同的装置、模块或单元进行区分,并非用于限定这些装置、模块或单元所执行的功能的顺序或者相互依存关系。
需要注意,本公开中提及的“一个”、“多个”的修饰是示意性而非限制性的,本领域技术人员应当理解,除非在上下文另有明确指出,否则应该理解为“一个或多个”。
本公开实施方式中的多个装置之间所交互的消息或者信息的名称仅用于说明性的目的,而并不是用于对这些消息或信息的范围进行限制。
下述各实施例中,每个实施例中同时提供了可选特征和示例,实施例中记 载的各个特征可进行组合,形成多个可选方案,不应将每个编号的实施例仅视为一个技术方案。
图1为本公开实施例提供的一种函数处理方法的流程示意图,该方法可应用于预设应用程序,可以由函数处理装置执行,其中该装置可由软件和/或硬件实现,一般可集成在电子设备中。所述电子设备可以为手机、智能手表、平板电脑以及个人数字助理等移动设备;也可为台式计算机等其他设备。
如图1所示,该方法包括:
步骤101、在预设应用程序中加载第一核心库,其中,第一核心库通过将第一核心库中的代理连接函数注入至第二核心库来实现对预设套接字的调用进行集中管理,第二核心库中包含预设连接函数,预设连接函数用于建立与预设套接字的连接。
示例性的,预设应用程序可以是任意的具备网络访问功能的应用程序。预设应用程序装载于操作系统中,该操作系统的具体类型不做限定,例如可以包括尤内克斯(Unix)、林纳斯(Linux)、苹果(iOS、macOS或OS X)以及安卓(Android)等,为了便于说明,下文将以安卓为例。
示例性的,核心库也可称为内核库,可以理解为操作系统中用于提供基础功能的库。应用程序实现网络能力时需要使用socket,socket的实现处于第二核心库中,socket的实现包括连接(connect)函数,又称connect方法。连接函数作为socket的实现可用于建立与对应socket的连接,在应用程序发起网络请求的连接动作,需要调用socket时,可以调用socket对应的连接函数。不同的操作系统中,第二核心库的名称可能不同,以安卓为例,第二核心库可以是Bionic库。第一核心库是与第二核心库不同的核心库,由于需要调用socket的地方较多,为了便于管理,可以由第一核心库在系统层面对socket进行聚集,将第二 核心库中对socket的真正实现代理到第一核心库中,第一核心库可以将自己的socket的实现(可称为代理连接函数)注入到第二核心库中,使得第二核心库中的连接函数被执行时,先执行代理连接函数,进而实现对socket的调用进行集中管理。不同的操作系统中,第二核心库的名称可能不同,以安卓为例,第二核心库可以是NetdClient库,对应的库文件可以是libnetd_client.so文件。
示例性的,预设套接字可以包括在第二核心库中实现的全部或部分套接字,相应的,预设连接函数可以包括第二核心库中存在的全部或部分连接函数,与预设套接字相对应。
示例性的,预设应用程序可以在启动后主动加载第一核心库,也可在检测到第一核心库的加载事件被触发时加载第一核心库。可选的,第二核心库可以与第一核心库的加载时机相同或不同。
步骤102、基于代理连接函数对应的预设注入方法,将自定义连接函数注入至第二核心库。
示例性的,代理连接函数对应的预设注入方法可以理解为能够将代理连接函数注入至第二核心库的注入方法,该方法可以根据实际需求编写,也可以复用操作系统提供的注入方法。可选的,所述预设注入方法包括操作系统提供的用于将第一核心库中的代理连接函数注入至第二核心库的方法。
示例性的,以安卓为例,预设注入方法包括NetdClientInitConnect方法。该方法是安卓操作系统对外公开的,预设应用程序可以获取到该方法,进而对该方法进行调用。
示例性的,可通过调用预设注入方法来将自定义连接函数注入至所述第二核心库。
本公开实施例中,可以在预设应用程序的开发阶段,预先编写自定义连接 函数,自定义连接函数的功能是实现自定义逻辑,自定义逻辑可理解为实现hook需要的逻辑,具体内容可以根据实际需求进行编写,此处不做限定,自定义逻辑可以以参数的形式存在于自定义连接函数中,也可称为自定义参数,自定义参数具体可以是用于实现自定义逻辑的函数或相关代码。
可选的,所述自定义连接函数以预设参数的形式进行注入。在调用预设注入方法时可以传入预设参数,预设参数可以理解为需要注入的对象。将自定义连接函数作为注入对象,也即将自定义连接函数传入预设注入方法中,以实现将自定义连接函数注入至第二核心库。
步骤103、检测到预设应用程序通过第二核心库调用预设连接函数时,替换为调用自定义连接函数来实现自定义逻辑,以对预设套接字进行检测。
示例性的,预设应用程序在发起网络请求时,若需要调用预设套接字,则需要通过第二核心库调用对应的预设连接函数,由于之前已经将自定义连接函数注入至第二核心库,因此,不会直接执行当前调用的原本的预设连接函数,而是先执行自定义连接函数,进而实现自定义逻辑,此时,由于预设连接函数未直接被执行,无法直接建立与预设套接字的连接,从而实现对预设套接字进行检测。
本公开实施例中提供的函数处理方法,在预设应用程序中加载第一核心库,其中,第一核心库通过将代理连接函数注入至第二核心库来实现对预设套接字的调用进行集中管理,第二核心库中包含用于建立与预设套接字的连接的预设连接函数,基于第一核心库对应的预设注入方法,将自定义连接函数注入至第二核心库,检测到预设应用程序通过第二核心库调用预设连接函数时,替换为调用自定义连接函数,以对预设套接字进行检测。通过采用上述技术方案,不需要针对每个需要调用套接字的地方注入自定义的代码以达到检测套接字的目 的,利用能够将代理连接函数注入至第二核心库的预设注入方法将自定义连接函数注入到第二核心库中,而使得自定义连接函数能够具备代理连接函数的功能来实现对预设套接字的调用进行集中管理,也即通过自定义连接函数的一次注入可以实现批量地注入多个预设套接字对应的检测代码的效果,减少用于检测套接字的代码的注入量,保证应用程序的稳定性和性能。
在一些实施例中,所述基于所述代理连接函数对应的预设注入方法,将自定义连接函数注入至所述第二核心库,包括:采用预设动态库符号函数查找所述代理连接函数对应的预设注入方法的地址;根据所述预设注入方法的地址调用所述预设注入方法,以将自定义连接函数注入至所述第二核心库。这样设置的好处在于,可以快速准确地查找到操作系统提供的预设注入方法的地址并对其进行调用。
其中,动态库符号(dynamic library symbol,dlsym)函数的功能是根据动态链接库操作句柄与符号,返回符号对应的地址,不但可以获取函数地址,也可以获取变量地址。预设动态库符号函数可理解为在预设应用程序开发阶段预先编写的用于查找预设注入方法的地址的dlsym函数,例如,用于查找NetdClientInitConnect方法的地址的dlsym函数。
在一些实施例中,在替换为调用所述自定义连接函数来实现所述自定义逻辑之后,还包括:执行所述预设连接函数的系统调用。这样设置的好处在于,防止在执行自定义连接函数完毕后再次调用预设连接函数,从而再次被替换为执行自定义连接函数,出现hook死循环调用的情况。
示例性的,系统调用(也可称为system call或syscall)是用户空间访问内核(kernel)的手段,是内核的合法入口。在正常调用预设连接函数的情况下,会继续通过执行对应的系统调用来调用系统底层(kernel层,又称内核层)的相 关函数,最终实现预设连接函数的功能。本公开实施例中,在调用自定义连接函数来实现自定义逻辑之后,直接执行预设连接函数的系统调用,而不是返回调用预设连接函数,防止无限死循环的情况发生,保证预设应用程序的正常运行。
在一些实施例中,当所述预设连接函数中的类型参数为网络套接字时,所述自定义逻辑包括将所述预设连接函数中的目的地址替换为本地服务器代理对应的目标地址。这样设置的好处在于,通过自定义逻辑可以将网络请求转至本地服务器代理,便于获取预设应用程序与真实服务器之间传送的数据,实现网络数据的获取。其中,网络套接字可以理解为普通套接字,用于不同计算机设备上运行的进程之间的通信。本地服务器代理(proxy)可以理解为在预设应用程序内部实现的代理服务器,真实服务器可理解为预设应用程序所需建立网络连接的远程服务器。在预设应用程序的开发阶段,可以预先编写实现本地服务器代理的相关代码,包括本地服务器代理对应的目标地址。可选的,目标地址可以包括电子设备的本地的网卡对应的网际协议(Internet Protocol,IP)地址,例如127.0.0.1。在预设应用程序启动后,可以在预设应用程序中启动本地服务器代理,并将本地服务器代理绑定至目标地址,进而通过本地服务器代理进行网络数据的获取,实现应用程序内部的网络数据获取。
在一些实施例中,当所述预设连接函数中的类型参数为本地套接字时,所述自定义逻辑包括将所述预设连接函数中的目的文件路径替换为本地域名服务器代理对应的目标文件路径。这样设置的好处在于,通过自定义逻辑可以将网络请求转至本地域名服务器代理,便于在域名解析阶段对网络流量进行控制。其中,本地套接字(local socket)又称为Unix域套接字,用于同一台计算机设备上运行的进程之间的通信。本地域名服务器代理具体可以是基于本地套接字 服务的域名服务器代理,可以理解为用于域名解析的local socket服务端。在预设应用程序的开发阶段,可以预先编写实现域名服务器代理的相关代码,包括域名服务器代理对应的目标文件路径。在预设应用程序启动后,可以启动域名服务器代理,并将域名服务器代理关联至目标文件路径,在调用本地套接字时,将对应的连接函数中的目的文件路径替换为目标文件路径,从而实现将预设应用程序(这里也可理解为预设应用程序进程中加载的域名解析阶段的客户端,如安卓操作系统中的NetdClient),避免直接连接到真实域名服务器(如安卓操作系统中的NetdServer)。
可选的,将预设连接函数中的目的地址替换为本地服务器代理对应的目标地址可记为第一自定义逻辑,对应的自定义连接函数记为第一自定义连接函数;将预设连接函数中的目的文件路径替换为本地域名服务器代理对应的目标文件路径可记为第二自定义逻辑,对应的自定义连接函数记为第二自定义连接函数。可预先将第一自定义连接函数和第二自定义连接函数注入至第二核心库。检测到预设应用程序通过第二核心库调用预设连接函数时,先获取预设连接函数中的类型参数,若类型参数为网络套接字,则替换为调用第一自定义连接函数来实现第一自定义逻辑;若类型参数为本地套接字,则替换为调用第二自定义连接函数来实现第二自定义逻辑。
需要说明的是,还可能存在其他自定义逻辑,上述第一自定义逻辑和第二自定义逻辑仅作为示意性说明,在实际应用时可以根据实际需求进行编写,本公开实施例具体不做限定。
图2为本公开实施例提供的一种函数处理方法的流程示意图,本公开实施例以上述实施例中各个可选方案为基础进行优化。图3为本公开实施例提供的一种函数处理方法的原理示意图,可结合图2和图3对本公开实施例进行理解。
具体的,以安卓操作系统为例,该方法包括如下步骤:
步骤201、预设应用程序启动后,在预设应用程序中加载第一核心库,其中,第一核心库通过将第一核心库中的代理连接函数注入至第二核心库来实现对预设套接字的调用进行集中管理,第二核心库中包含预设连接函数,预设连接函数用于建立与预设套接字的连接。
示例性的,预设应用程序启动后,主动加载NetdClient库,也即加载libnetd_client.so文件。
步骤202、采用预设动态库符号函数查找代理连接函数对应的预设注入方法的地址。
示例性的,可以在预设应用程序开发阶段预先编写预设dlsym函数,预设应用程序采用预设dlsym函数查找到NetdClientInitConnect方法的地址。
步骤203、根据预设注入方法的地址调用预设注入方法,以将自定义连接函数注入至第二核心库。
其中,自定义连接函数以预设参数的形式进行注入,自定义连接函数用于实现自定义逻辑。
如图3所示,预设应用程序通过调用第一核心库中的预设注入方法将自定义连接函数注入第二核心库。以安卓为例,预设应用程序可以调用NetdClient库中的NetdClientInitConnect方法,并传入自定义连接函数,将自定义连接函数注入至Bionic库。
步骤204、检测到预设应用程序通过第二核心库调用预设连接函数时,替换为调用自定义连接函数来实现自定义逻辑,以对预设套接字进行检测。
如图3所示,预设应用程序调用预设套接字时,通过第二核心库调用预设连接函数,此时,替换为调用自定义连接函数并执行相应的系统调用。
示例性的,预设应用程序发起网络请求时,可检测到预设应用程序调用Bionic库中的预设连接函数,此时,替换为调用自定义连接函数来实现hook需要的逻辑。
步骤205、执行预设连接函数的系统调用。
示例性的,在hook需要的逻辑执行完毕后,使用系统调用进行预设连接函数的底层操作,防止出现死循环调用。
本公开实施例提供的函数处理方法,应用程序启动后,查找到NetdClient库中的NetdClientInitConnect方法的地址,并通过调用NetdClientInitConnect方法的方式将用于实现自定义逻辑的自定义连接函数注入到Bionic库中,使得后续应用程序在调用Bionic库中原有的连接函数时,替换为调用自定义连接函数,以实现自定义逻辑,对socket的调用进行检测。通过采用该方案,无需在Bionic库中的每个需要调用预设连接函数的位置注入用于检测的代码,可减少检测代码的注入量,保证应用程序的稳定性和性能。
图4为本公开实施例提供的一种函数处理装置的结构框图,该装置可配置于预设应用程序,可由软件和/或硬件实现,一般可集成在电子设备中,可通过执行函数处理方法来进行函数处理。如图4所示,该装置包括:
加载模块401,用于在预设应用程序中加载第一核心库,其中,所述第一核心库通过将所述第一核心库中的代理连接函数注入至第二核心库来实现对预设套接字的调用进行集中管理,所述第二核心库中包含预设连接函数,所述预设连接函数用于建立与所述预设套接字的连接;
注入方法调用模块402,用于基于所述代理连接函数对应的预设注入方法,将自定义连接函数注入至所述第二核心库;
连接函数调用模块403,用于在检测到所述预设应用程序通过所述第二核心 库调用所述预设连接函数时,替换为调用所述自定义连接函数来实现自定义逻辑,以对所述预设套接字进行检测。
本公开实施例中提供的函数处理装置,不需要针对每个需要调用套接字的地方注入自定义的代码以达到检测套接字的目的,利用能够将代理连接函数注入至第二核心库的预设注入方法将自定义连接函数注入到第二核心库中,而使得自定义连接函数能够具备代理连接函数的功能来实现对预设套接字的调用进行集中管理,也即通过自定义连接函数的一次注入可以实现批量地注入多个预设套接字对应的检测代码的效果,减少用于检测套接字的代码的注入量,保证应用程序的稳定性和性能。
可选的,所述自定义连接函数以预设参数的形式进行注入。
可选的,所述预设注入方法包括操作系统提供的用于将所述代理连接函数注入至所述第二核心库的方法。
可选的,所述注入方法调用模块包括:
地址查找单元,用于采用预设动态库符号函数查找所述代理连接函数对应的预设注入方法的地址;
注入方法调用单元,用于根据所述预设注入方法的地址调用所述预设注入方法,以将自定义连接函数注入至所述第二核心库。
可选的,所述装置还包括:
系统调用执行模块,用于在替换为调用所述自定义连接函数来实现所述自定义逻辑之后,执行所述预设连接函数的系统调用。
可选的,所述操作系统包括安卓操作系统,所述第一核心库包括NetdClient库,所述第二核心库包括Bionic库,所述预设注入方法包括NetdClientInitConnect方法。
可选的,当所述预设连接函数中的类型参数为网络套接字时,所述自定义逻辑包括将所述预设连接函数中的目的地址替换为本地服务器代理对应的目标地址。
可选的,当所述预设连接函数中的类型参数为本地套接字时,所述自定义逻辑包括将所述预设连接函数中的目的文件路径替换为本地域名服务器代理对应的目标文件路径。
下面参考图5,其示出了适于用来实现本公开实施例的电子设备500的结构示意图。本公开实施例中的电子设备可以包括但不限于诸如移动电话、笔记本电脑、数字广播接收器、PDA(个人数字助理)、PAD(平板电脑)、PMP(便携式多媒体播放器)、车载终端(例如车载导航终端)等等的移动终端以及诸如数字TV、台式计算机等等的固定终端。图5示出的电子设备仅仅是一个示例,不应对本公开实施例的功能和使用范围带来任何限制。
如图5所示,电子设备500可以包括处理装置(例如中央处理器、图形处理器等)501,其可以根据存储在只读存储器(ROM)502中的程序或者从存储装置508加载到随机访问存储器(RAM)503中的程序而执行各种适当的动作和处理。在RAM 503中,还存储有电子设备500操作所需的各种程序和数据。处理装置501、ROM 502以及RAM 503通过总线504彼此相连。输入/输出(I/O)接口505也连接至总线504。
通常,以下装置可以连接至I/O接口505:包括例如触摸屏、触摸板、键盘、鼠标、摄像头、麦克风、加速度计、陀螺仪等的输入装置506;包括例如液晶显示器(LCD)、扬声器、振动器等的输出装置507;包括例如磁带、硬盘等的存储装置508;以及通信装置509。通信装置509可以允许电子设备500与其他设备进行无线或有线通信以交换数据。虽然图5示出了具有各种装置的电子设备 500,但是应理解的是,并不要求实施或具备所有示出的装置。可以替代地实施或具备更多或更少的装置。
特别地,根据本公开的实施例,上文参考流程图描述的过程可以被实现为计算机软件程序。例如,本公开的实施例包括一种计算机程序产品,其包括承载在非暂态计算机可读介质上的计算机程序,该计算机程序包含用于执行流程图所示的方法的程序代码。在这样的实施例中,该计算机程序可以通过通信装置509从网络上被下载和安装,或者从存储装置508被安装,或者从ROM 502被安装。在该计算机程序被处理装置501执行时,执行本公开实施例的方法中限定的上述功能。
需要说明的是,本公开上述的计算机可读介质可以是计算机可读信号介质或者计算机可读存储介质或者是上述两者的任意组合。计算机可读存储介质例如可以是——但不限于——电、磁、光、电磁、红外线、或半导体的系统、装置或器件,或者任意以上的组合。计算机可读存储介质的更具体的例子可以包括但不限于:具有一个或多个导线的电连接、便携式计算机磁盘、硬盘、随机访问存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、光纤、便携式紧凑磁盘只读存储器(CD-ROM)、光存储器件、磁存储器件、或者上述的任意合适的组合。在本公开中,计算机可读存储介质可以是任何包含或存储程序的有形介质,该程序可以被指令执行系统、装置或者器件使用或者与其结合使用。而在本公开中,计算机可读信号介质可以包括在基带中或者作为载波一部分传播的数据信号,其中承载了计算机可读的程序代码。这种传播的数据信号可以采用多种形式,包括但不限于电磁信号、光信号或上述的任意合适的组合。计算机可读信号介质还可以是计算机可读存储介质以外的任何计算机可读介质,该计算机可读信号介质可以发送、传播或者传输用于 由指令执行系统、装置或者器件使用或者与其结合使用的程序。计算机可读介质上包含的程序代码可以用任何适当的介质传输,包括但不限于:电线、光缆、RF(射频)等等,或者上述的任意合适的组合。
上述计算机可读介质可以是上述电子设备中所包含的;也可以是单独存在,而未装配入该电子设备中。
上述计算机可读介质承载有一个或者多个程序,当上述一个或者多个程序被该电子设备执行时,使得该电子设备:在预设应用程序中加载第一核心库,其中,所述第一核心库通过将所述第一核心库中的代理连接函数注入至第二核心库来实现对预设套接字的调用进行集中管理,所述第二核心库中包含预设连接函数,所述预设连接函数用于建立与所述预设套接字的连接;基于所述代理连接函数对应的预设注入方法,将自定义连接函数注入至所述第二核心库;检测到所述预设应用程序通过所述第二核心库调用所述预设连接函数时,替换为调用所述自定义连接函数来实现自定义逻辑,以对所述预设套接字进行检测。
可以以一种或多种程序设计语言或其组合来编写用于执行本公开的操作的计算机程序代码,上述程序设计语言包括但不限于面向对象的程序设计语言—诸如Java、Smalltalk、C++,还包括常规的过程式程序设计语言—诸如“C”语言或类似的程序设计语言。程序代码可以完全地在用户计算机上执行、部分地在用户计算机上执行、作为一个独立的软件包执行、部分在用户计算机上部分在远程计算机上执行、或者完全在远程计算机或服务器上执行。在涉及远程计算机的情形中,远程计算机可以通过任意种类的网络——包括局域网(LAN)或广域网(WAN)—连接到用户计算机,或者,可以连接到外部计算机(例如利用因特网服务提供商来通过因特网连接)。
附图中的流程图和框图,图示了按照本公开各种实施例的系统、方法和计 算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段、或代码的一部分,该模块、程序段、或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个接连地表示的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图和/或流程图中的每个方框、以及框图和/或流程图中的方框的组合,可以用执行规定的功能或操作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。
描述于本公开实施例中所涉及到的模块可以通过软件的方式实现,也可以通过硬件的方式来实现。其中,模块的名称在某种情况下并不构成对该模块本身的限定,例如,加载模块还可以被描述为“在预设应用程序中加载第一核心库的模块,其中,所述第一核心库通过将所述第一核心库中的代理连接函数注入至第二核心库来实现对预设套接字的调用进行集中管理,所述第二核心库中包含预设连接函数,所述预设连接函数用于建立与所述预设套接字的连接”。
本文中以上描述的功能可以至少部分地由一个或多个硬件逻辑部件来执行。例如,非限制性地,可以使用的示范类型的硬件逻辑部件包括:现场可编程门阵列(FPGA)、专用集成电路(ASIC)、专用标准产品(ASSP)、片上系统(SOC)、复杂可编程逻辑设备(CPLD)等等。
在本公开的上下文中,机器可读介质可以是有形的介质,其可以包含或存储以供指令执行系统、装置或设备使用或与指令执行系统、装置或设备结合地使用的程序。机器可读介质可以是机器可读信号介质或机器可读储存介质。机器可读介质可以包括但不限于电子的、磁性的、光学的、电磁的、红外的、或 半导体系统、装置或设备,或者上述内容的任何合适组合。机器可读存储介质的更具体示例会包括基于一个或多个线的电气连接、便携式计算机盘、硬盘、随机存取存储器(RAM)、只读存储器(ROM)、可擦除可编程只读存储器(EPROM或快闪存储器)、光纤、便捷式紧凑盘只读存储器(CD-ROM)、光学储存设备、磁储存设备、或上述内容的任何合适组合。
根据本公开的一个或多个实施例,提供了一种函数处理方法,包括:
在预设应用程序中加载第一核心库,其中,所述第一核心库通过将所述第一核心库中的代理连接函数注入至第二核心库来实现对预设套接字的调用进行集中管理,所述第二核心库中包含预设连接函数,所述预设连接函数用于建立与所述预设套接字的连接;
基于所述代理连接函数对应的预设注入方法,将自定义连接函数注入至所述第二核心库;
检测到所述预设应用程序通过所述第二核心库调用所述预设连接函数时,替换为调用所述自定义连接函数来实现自定义逻辑,以对所述预设套接字进行检测。
进一步的,所述自定义连接函数以预设参数的形式进行注入。
进一步的,所述预设注入方法包括操作系统提供的用于将所述代理连接函数注入至所述第二核心库的方法。
进一步的,所述基于所述代理连接函数对应的预设注入方法,将自定义连接函数注入至所述第二核心库,包括:
采用预设动态库符号函数查找所述代理连接函数对应的预设注入方法的地址;
根据所述预设注入方法的地址调用所述预设注入方法,以将自定义连接函 数注入至所述第二核心库。
进一步的,在替换为调用所述自定义连接函数来实现自定义逻辑之后,还包括:
执行所述预设连接函数的系统调用。
进一步的,所述操作系统包括安卓操作系统,所述第一核心库包括NetdClient库,所述第二核心库包括Bionic库,所述预设注入方法包括NetdClientInitConnect方法。
进一步的,当所述预设连接函数中的类型参数为网络套接字时,所述自定义逻辑包括将所述预设连接函数中的目的地址替换为本地服务器代理对应的目标地址。
进一步的,当所述预设连接函数中的类型参数为本地套接字时,所述自定义逻辑包括将所述预设连接函数中的目的文件路径替换为本地域名服务器代理对应的目标文件路径。
根据本公开的一个或多个实施例,提供了一种函数处理装置,包括:
加载模块,用于在所述预设应用程序中加载第一核心库,其中,所述第一核心库通过将所述第一核心库中的代理连接函数注入至第二核心库来实现对预设套接字的调用进行集中管理,所述第二核心库中包含预设连接函数,所述预设连接函数用于建立与所述预设套接字的连接;
注入方法调用模块,用于基于所述代理连接函数对应的预设注入方法,将自定义连接函数注入至所述第二核心库;
连接函数调用模块,用于在检测到所述预设应用程序通过所述第二核心库调用所述预设连接函数时,替换为调用所述自定义连接函数来实现自定义逻辑,以对所述预设套接字进行检测。
以上描述仅为本公开的较佳实施例以及对所运用技术原理的说明。本领域技术人员应当理解,本公开中所涉及的公开范围,并不限于上述技术特征的特定组合而成的技术方案,同时也应涵盖在不脱离上述公开构思的情况下,由上述技术特征或其等同特征进行任意组合而形成的其它技术方案。例如上述特征与本公开中公开的(但不限于)具有类似功能的技术特征进行互相替换而形成的技术方案。
此外,虽然采用特定次序描绘了各操作,但是这不应当理解为要求这些操作以所示出的特定次序或以顺序次序执行来执行。在一定环境下,多任务和并行处理可能是有利的。同样地,虽然在上面论述中包含了若干具体实现细节,但是这些不应当被解释为对本公开的范围的限制。在单独的实施例的上下文中描述的某些特征还可以组合地实现在单个实施例中。相反地,在单个实施例的上下文中描述的各种特征也可以单独地或以任何合适的子组合的方式实现在多个实施例中。
尽管已经采用特定于结构特征和/或方法逻辑动作的语言描述了本主题,但是应当理解所附权利要求书中所限定的主题未必局限于上面描述的特定特征或动作。相反,上面所描述的特定特征和动作仅仅是实现权利要求书的示例形式。
Claims (11)
- 一种函数处理方法,其特征在于,包括:在预设应用程序中加载第一核心库,其中,所述第一核心库通过将所述第一核心库中的代理连接函数注入至第二核心库来实现对预设套接字的调用进行集中管理,所述第二核心库中包含预设连接函数,所述预设连接函数用于建立与所述预设套接字的连接;基于所述代理连接函数对应的预设注入方法,将自定义连接函数注入至所述第二核心库;检测到所述预设应用程序通过所述第二核心库调用所述预设连接函数时,替换为调用所述自定义连接函数来实现自定义逻辑,以对所述预设套接字进行检测。
- 根据权利要求1所述的方法,其特征在于,所述自定义连接函数以预设参数的形式进行注入。
- 根据权利要求1所述的方法,其特征在于,所述预设注入方法包括操作系统提供的用于将所述代理连接函数注入至所述第二核心库的方法。
- 根据权利要求3所述的方法,其特征在于,所述基于所述代理连接函数对应的预设注入方法,将自定义连接函数注入至所述第二核心库,包括:采用预设动态库符号函数查找所述代理连接函数对应的预设注入方法的地址;根据所述预设注入方法的地址调用所述预设注入方法,以将自定义连接函数注入至所述第二核心库。
- 根据权利要求1所述的方法,其特征在于,在替换为调用所述自定义连 接函数来实现自定义逻辑之后,还包括:执行所述预设连接函数的系统调用。
- 根据权利要求3所述的方法,其特征在于,所述操作系统包括安卓操作系统,所述第一核心库包括NetdClient库,所述第二核心库包括Bionic库,所述预设注入方法包括NetdClientInitConnect方法。
- 根据权利要求1-6任一所述的方法,其特征在于,当所述预设连接函数中的类型参数为网络套接字时,所述自定义逻辑包括将所述预设连接函数中的目的地址替换为本地服务器代理对应的目标地址。
- 根据权利要求1-6任一所述的方法,其特征在于,当所述预设连接函数中的类型参数为本地套接字时,所述自定义逻辑包括将所述预设连接函数中的目的文件路径替换为本地域名服务器代理对应的目标文件路径。
- 一种函数处理装置,其特征在于,包括:加载模块,用于在预设应用程序中加载第一核心库,其中,所述第一核心库通过将所述第一核心库中的代理连接函数注入至第二核心库来实现对预设套接字的调用进行集中管理,所述第二核心库中包含预设连接函数,所述预设连接函数用于建立与所述预设套接字的连接;注入方法调用模块,用于基于所述代理连接函数对应的预设注入方法,将自定义连接函数注入至所述第二核心库;连接函数调用模块,用于在检测到所述预设应用程序通过所述第二核心库调用所述预设连接函数时,替换为调用所述自定义连接函数来实现自定义逻辑,以对所述预设套接字进行检测。
- 一种电子设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,其特征在于,所述处理器执行所述计算机程序时实现如 权利要求1-8任一项所述的方法。
- 一种计算机可读存储介质,其上存储有计算机程序,其特征在于,该程序被处理器执行时实现如权利要求1-8任一项所述的方法。
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111598174.9 | 2021-12-24 | ||
CN202111598174.9A CN116340014A (zh) | 2021-12-24 | 2021-12-24 | 函数处理方法、装置、设备及存储介质 |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2023116503A1 true WO2023116503A1 (zh) | 2023-06-29 |
Family
ID=85775706
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2022/138605 WO2023116503A1 (zh) | 2021-12-24 | 2022-12-13 | 函数处理方法、装置、设备及存储介质 |
Country Status (3)
Country | Link |
---|---|
US (1) | US11620170B1 (zh) |
CN (1) | CN116340014A (zh) |
WO (1) | WO2023116503A1 (zh) |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1725757A (zh) * | 2004-07-21 | 2006-01-25 | 三星电子株式会社 | 管理和检查套接字连接 |
US20160087868A1 (en) * | 2014-09-19 | 2016-03-24 | Splunk Inc. | Injecting Custom Classes In Application Code To Facilitate Network Traffic Monitoring |
CN113556260A (zh) * | 2020-04-24 | 2021-10-26 | 北京三快在线科技有限公司 | 一种流量监控方法、装置、存储介质及电子设备 |
Family Cites Families (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US9367331B2 (en) * | 2009-07-20 | 2016-06-14 | Google Technology Holdings LLC | Multi-environment operating system |
US9116717B2 (en) * | 2011-05-27 | 2015-08-25 | Cylance Inc. | Run-time interception of software methods |
US10305937B2 (en) * | 2012-08-02 | 2019-05-28 | CellSec, Inc. | Dividing a data processing device into separate security domains |
US9465717B2 (en) * | 2013-03-14 | 2016-10-11 | Riverbed Technology, Inc. | Native code profiler framework |
US9846730B2 (en) * | 2013-11-21 | 2017-12-19 | Sap Se | Interacting with resources exchanged using open data protocol |
US10277717B2 (en) * | 2013-12-15 | 2019-04-30 | Nicira, Inc. | Network introspection in an operating system |
US9735943B2 (en) * | 2015-05-11 | 2017-08-15 | Citrix Systems, Inc. | Micro VPN tunneling for mobile platforms |
-
2021
- 2021-12-24 CN CN202111598174.9A patent/CN116340014A/zh active Pending
-
2022
- 2022-04-13 US US17/719,666 patent/US11620170B1/en active Active
- 2022-12-13 WO PCT/CN2022/138605 patent/WO2023116503A1/zh unknown
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1725757A (zh) * | 2004-07-21 | 2006-01-25 | 三星电子株式会社 | 管理和检查套接字连接 |
US20160087868A1 (en) * | 2014-09-19 | 2016-03-24 | Splunk Inc. | Injecting Custom Classes In Application Code To Facilitate Network Traffic Monitoring |
CN113556260A (zh) * | 2020-04-24 | 2021-10-26 | 北京三快在线科技有限公司 | 一种流量监控方法、装置、存储介质及电子设备 |
Non-Patent Citations (1)
Title |
---|
LI, ZHE: "Research and Implementation of Online Electronic Map Service System Based on CIPE in Car Environments", INFORMATION & TECHNOLOGY, CHINA MASTER'S THESES FULL-TEXT DATABASE (MONTHLY), no. 5, 1 April 2011 (2011-04-01), CN, pages 1 - 49, XP009546873 * |
Also Published As
Publication number | Publication date |
---|---|
CN116340014A (zh) | 2023-06-27 |
US11620170B1 (en) | 2023-04-04 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US20140006598A1 (en) | Methods, apparatuses and computer program products for facilitating dynamic origin-based domain allocation | |
WO2023273725A1 (zh) | 文件下载方法、装置、存储介质及电子设备 | |
WO2022111290A1 (zh) | 展示方法、装置和电子设备 | |
CN110704833A (zh) | 数据权限配置方法、设备、电子设备及存储介质 | |
CN111079125A (zh) | 一种应用程序调用第三方库动态提升权限的方法及装置 | |
CN111400068B (zh) | 接口的控制方法、装置、可读介质和电子设备 | |
WO2022193913A1 (zh) | 热修复方法、装置、设备及存储介质 | |
US20240104671A1 (en) | Method and apparatus for group management, electronic device, and storage medium | |
US11100243B2 (en) | Selective persistence of data utilized by software containers | |
CN113391860B (zh) | 服务请求处理方法、装置、电子设备及计算机存储介质 | |
WO2023109311A1 (zh) | 资源访问方法、装置、存储介质以及电子设备 | |
WO2023207788A1 (zh) | 信息处理方法、装置、电子设备和存储介质 | |
WO2023116503A1 (zh) | 函数处理方法、装置、设备及存储介质 | |
CN112131181A (zh) | 存储路径的展示方法、装置以及电子设备 | |
WO2023072070A1 (zh) | 显示控制方法、装置和电子设备 | |
Ahmad et al. | Comparative analysis of operating system of different smart phones | |
US11782797B2 (en) | Achieving activity centric computing using portable containers | |
WO2023116513A1 (zh) | 网络请求处理方法、装置、设备及存储介质 | |
US20220309156A1 (en) | Identification and mitigation of permissions elevating attack vector | |
CN110086880B (zh) | 创建网络请求的实例的方法和装置 | |
CN111367590A (zh) | 中断事件处理方法及其装置 | |
CN111310175A (zh) | 基于插件化的iOS应用安全监测与防护方法及装置 | |
CN113778566A (zh) | 原生应用调用方法、装置、电子设备和计算机可读介质 | |
WO2023116167A1 (zh) | 生命周期事件管理方法、装置、存储介质以及电子设备 | |
WO2023116508A1 (zh) | 数据获取方法、装置、设备及存储介质 |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 22909817 Country of ref document: EP Kind code of ref document: A1 |
|
NENP | Non-entry into the national phase |
Ref country code: DE |