Front-end hook dynamic injection method and device, electronic equipment and readable storage medium
By configuring the entry file and loading hook functions in the front-end basic service, the code neatness and maintainability problems caused by embedding too much business logic in the front-end basic service in the existing technology are solved, and the clear separation and unified management of front-end business services are achieved, and the development efficiency is improved.
Patent Information
- Application Number
- CN202510094989.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-21
- Publication Date
- 2025-04-29
AI Technical Summary
In the prior art, embedding too much business special logic in front-end basic services leads to reduced code tidyness and maintainability, and the code duplication and logic complex between various business services leads to low development efficiency.
By configuring the entry file in the front-end basic service, obtaining the access path of the front-end business service, loading the corresponding front-end business service and injecting hook functions, and using the hook dynamic link library to embed the front-end business service into the front-end basic service.
It realizes clear separation and unified management of front-end basic services and business services, reduces code redundancy and logical confusion, and improves development efficiency.
Smart Images

Figure CN119902819A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a front-end hook dynamic injection method, device, electronic device and readable storage medium. Background Art
[0002] Currently, the front-end services in the front-end architecture share the same set of basic functions, and other front-end business services need to be customized on top of the front-end basic services. The practice patterns in related technologies tend to embed too much business-specific logic directly in the basic services, which not only affects the code cleanliness and maintainability of the basic services, but also leads to unnecessary code duplication and complex conditional judgment logic between business services. The code chaos of the above direct logic embedding method limits the clear separation and unified management of basic functions and business-specific processing logic, forcing developers to continuously add business-specific attributes to basic services, resulting in the increasingly prominent problem of logical mutual exclusion between various front-end business services, reducing development efficiency. Summary of the invention
[0003] The present application provides a front-end hook dynamic injection method, device, electronic device and readable storage medium, which can establish a connection between the front-end basic service and various business services to improve development efficiency.
[0004] The technical solution of the embodiment of the present application is as follows: In a first aspect, an embodiment of the present application provides a front-end hook dynamic injection method, which is applied to a front-end server, and the method includes: Configure an entry file in the front-end basic service, wherein the entry file includes information of the target object to be injected; Get the access path of the front-end business service configuration; Loading a corresponding front-end business service according to the access path, wherein the front-end business service includes a hook function, and the hook function is used to respond to business information across the front-end basic service; Injecting a preset hook dynamic link library into the front-end basic service, and starting the hook dynamic link library to inject the hook function into the front-end basic service corresponding to the target object information; A front-end business submission request is received, and the front-end basic service and the front-end business service are submitted.
[0005] In the above technical scheme, firstly, an entry file is configured in the front-end basic service, and the entry file includes the target object information to be injected. By configuring the entry file to indicate the target object information, a location for adding other services is provided, which can avoid logical mutual exclusion problems; the access path configured by the front-end business service is obtained so as to subsequently obtain the front-end business service; the corresponding front-end business service is loaded according to the access path, and the front-end business service includes a hook function, which is used to respond to business information across the front-end basic services. The front-end business service is defined through the hook function so that it can be embedded in the front-end basic service; the preset hook dynamic link library is injected into the front-end basic service, and the hook dynamic link library is started to inject the hook function into the front-end basic service corresponding to the target object information, and the front-end business service is embedded in the front-end basic service through the hook dynamic link library, so that each front-end business service is clearly separated, which can not only be managed in a unified manner, but also reduce code redundancy and logical confusion, thereby improving development efficiency; the front-end business submission request is received, and the front-end basic service and the front-end business service are submitted for front-end application.
[0006] In some embodiments of the present application, the corresponding front-end business service is loaded according to the access path, and the front-end business service includes a hook function, and the hook function is used to respond to the business information across the front-end basic service, including: Load the front-end business service corresponding to the access path using preset dynamic import and optional chaining operators; The hook function is stored in the object of the front-end basic service, and the front-end business service is read through a preset access interface.
[0007] In the above technical solution, in the process of loading the front-end business service, the preset dynamic import means dynamically loading modules or resources as needed when the program is running. The front-end business service is loaded by dynamic import, and in this process, the front-end business service corresponding to the access path is loaded by using the optional chain operator to verify the access path, so as to ensure the security of obtaining the front-end business service. The hook function in the loaded front-end business service is stored in the object created by the front-end basic service, and the front-end business service is read through the preset access interface, so that the connection between the front-end basic business and the front-end business service can be established through the dynamic link library later.
[0008] In some embodiments of the present application, the method of loading the front-end business service corresponding to the access path by using a preset dynamic import and an optional chaining operator includes: The access path is verified using the optional chaining operator, and when the return value of the optional chaining operator is normal, the front-end business service corresponding to the access path is loaded using a preset dynamic import.
[0009] In the above technical solution, the optional chaining operator can safely access the properties or methods of deeply nested objects without explicitly verifying whether each layer exists. The access path is verified by the optional chaining operator, and the return value is returned, which is conducive to subsequent business judgment based on the return value. When the return value of the optional chaining operator is normal, it indicates that the access path exists and is correct, and the corresponding front-end business service can be obtained from the access path, and the front-end business service corresponding to the access path can be loaded using the preset dynamic import. By loading the front-end business service, the connection between the front-end basic service and each front-end business service can be established later.
[0010] In some embodiments of the present application, after verifying the access path using the optional chaining operator, the method further includes: When the return value of the select chain operator is abnormal, the access path cannot obtain the front-end business service.
[0011] In the above technical solution, when the return value of the optional chain operator is abnormal, it indicates that the access path may not exist, or the file does not exist, and the corresponding front-end business service cannot be obtained from the access path. By performing verification, the embedded security and system stability can be guaranteed.
[0012] In some embodiments of the present application, the process of defining the hook function includes: Instantiate and apply the hook function to obtain function logic; The function logic is encapsulated using a preset built-in hook to obtain the hook function.
[0013] In the above technical solution, the hook function is a function that is automatically called at a specific time point, which is used to intercept or extend certain operations in the program. It is usually used in frameworks, libraries or operating systems to provide extensibility and the ability to customize behavior. Through the hook function, various front-end business services can be embedded in the front-end basic services. First, the hook function is constructed, which can be set in JavaScript language. Through the options in the Vue.js definition function, the definition of the instantiated application is performed to realize the front-end page call at different stages. By defining the function, the function logic is obtained, and the function logic is the logic for realizing the function. By executing the function logic, the corresponding instance application function can be realized. Then the preset built-in hook function is used to encapsulate the obtained function logic, realize the encapsulation and adjustment of the hook, and obtain the hook function. By defining and encapsulating the hook function, the hook function can be used to establish the connection between the front-end businesses in the future.
[0014] In some embodiments of the present application, injecting a preset hook dynamic link library into the front-end basic service and starting the hook dynamic link library to inject the hook function into the front-end basic service corresponding to the target object information includes: Using the preset loading interface in the front-end basic service to load the hook dynamic link library, the address of the hook function is obtained, and the preset loading interface is the ffi-napi interface; The hook dynamic link library is loaded and started to inject the hook function into the front-end basic service corresponding to the target object information.
[0015] In the above technical solution, the hook dynamic link library is loaded through the ffi-napi interface. First, ffi-napi and ref-napi are installed and configured in the front-end project. Fffi-napi can be used to load the hook dynamic link library and define how to call the function therein, obtain the address of the hook function, and call the hook function according to the address of the hook function to run the front-end business service. The hook dynamic link library is loaded and started to inject the hook function into the front-end basic service corresponding to the target object information to run the front-end business service. It can avoid unclear logic and perform unified management.
[0016] In some embodiments of the present application, before configuring the entry file in the front-end basic service, the method further includes: Performing authority verification on the target object information of the injection, and in the case of having injection authority, the target object information indicates the injection object; In the case of not having the injection authority, adjusting the injection authority.
[0017] In the above technical solution, before configuring the entry file in the front-end basic service, the target object information for injection can be verified for permissions. If the injection permission is not available, it indicates that the permission of the process or module is low, or the process or module does not have the running permission, and the injection permission can be adjusted. By obtaining the permissions of the process and running the program as an administrator, the permissions of the process can be adjusted to enable the embedding operation of other front-end business services. Or according to the injection requirements, if the injection permission is not available, the injection permission may not be adjusted, and the injection fails, and the injection code is not set for the process or module.
[0018] In a second aspect, an embodiment of the present application provides a front-end hook dynamic injection device, which is applied to a front-end server, and the device includes: A file configuration module is used to configure an entry file in the front-end basic service, wherein the entry file includes information of the target object to be injected; Path acquisition module, used to obtain the access path of the front-end business service configuration; A service loading module, used to load the corresponding front-end business service according to the access path, wherein the front-end business service includes a hook function, and the hook function is used to respond to business information across the front-end basic service; An injection module, used to inject a preset hook dynamic link library into the front-end basic service, and start the hook dynamic link library to inject the hook function into the front-end basic service corresponding to the target object information; The business submission module is used to receive a front-end business submission request and submit the front-end basic service and the front-end business service.
[0019] In a third aspect, an embodiment of the present application provides an electronic device, comprising a processor, a memory, a user interface, a communication bus and a network interface, wherein the processor, the memory, the user interface and the network interface are respectively connected to the communication bus, the memory is used to store instructions, the user interface and the network interface are used to communicate with other devices, and the processor is used to execute the instructions stored in the memory so that the electronic device executes any one of the methods provided in the first aspect.
[0020] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores instructions, and when the instructions are executed, any one of the methods provided in the first aspect is executed.
[0021] In summary, one or more technical solutions provided in the embodiments of the present application have at least the following technical effects or advantages: 1. As the entry file is configured in the front-end basic service first, the entry file includes the target object information to be injected. By configuring the entry file to indicate the target object information, other service addition locations are provided, which can avoid the problem of logical mutual exclusion; the access path configured by the front-end business service is obtained so as to obtain the front-end business service later; the corresponding front-end business service is loaded according to the access path, and the front-end business service includes a hook function, which is used to respond to the business information across the front-end basic service. The front-end business service is defined through the hook function so that it can be embedded in the front-end basic service; the preset hook dynamic link library is injected into the front-end basic service, and the hook dynamic link library is started to inject the hook function into the front-end basic service corresponding to the target object information, and the front-end business service is embedded in the front-end basic service through the hook dynamic link library, so that each front-end business service is clearly separated, which can not only be managed in a unified manner, but also reduce the redundancy and logical confusion of the code, thereby improving the development efficiency; the front-end business submission request is received, and the front-end basic service and the front-end business service are submitted so as to run the front-end application. Therefore, the problem of logical mutual exclusion between each front-end business service in the related technology is effectively solved, and the problem of reducing the development efficiency is reduced.
[0022] 2. The access path is verified through the optional chaining operator to ensure the security and reliability of program operation. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 It is a flowchart of a front-end hook dynamic injection method provided by an embodiment of the present application; Figure 2 yes Figure 1 A schematic flow chart of a sub-step of step S300; Figure 3 yes Figure 2 A schematic flow chart of a sub-step of step S310; Figure 4 yes Figure 1 A schematic flow chart of a sub-step of step S400; Figure 5 It is a structural schematic diagram of a front hook dynamic injection device provided by an embodiment of the present application; Figure 6 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0024] In order to enable technicians in this field to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this application, not all of the embodiments.
[0025] In the description of the embodiments of the present application, words such as "for example" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "for example" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "for example" or "for example" is intended to present related concepts in a specific way.
[0026] In the description of the embodiments of the present application, the meaning of the term "multiple" refers to two or more. For example, multiple systems refer to two or more systems, and multiple screen terminals refer to two or more screen terminals. In addition, the terms "first" and "second" are used for descriptive purposes only and cannot be understood as indicating or implying relative importance or implicitly indicating the indicated technical features. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. The terms "include", "comprise", "have" and their variations all mean "including but not limited to", unless otherwise specifically emphasized.
[0027] The embodiment of the present application provides a front-end hook dynamic injection method, device, electronic device and readable storage medium. The front-end hook dynamic injection method first configures an entry file in the front-end basic service, the entry file includes the target object information to be injected, and by configuring the entry file to indicate the target object information, provides other service addition locations, and can avoid logical mutual exclusion problems; obtains the access path configured by the front-end business service so as to subsequently obtain the front-end business service; loads the corresponding front-end business service according to the access path, the front-end business service includes a hook function, the hook function is used to respond to business information across the front-end basic service, and the front-end business service is defined by the hook function so that it can be embedded in the front-end basic service; injects a preset hook dynamic link library into the front-end basic service, and starts the hook dynamic link library to inject the hook function into the front-end basic service corresponding to the target object information, and embeds the front-end business service into the front-end basic service through the hook dynamic link library, so that each front-end business service is clearly separated, which can not only be managed in a unified manner, but also can reduce code redundancy and logical confusion, thereby improving development efficiency; receives a front-end business submission request, submits the front-end basic service and the front-end business service, so as to run the front-end application.
[0028] It should be noted that the front-end hook dynamic injection method is applied to front-end development, which can establish the connection between various front-end business services, avoid logical confusion, and improve development efficiency. It can also be applied to debugging and testing in front-end development, which can clearly track and locate, facilitate testing, and ensure the stability of the code.
[0029] The technical solution provided in the embodiments of the present application is further described below in conjunction with the accompanying drawings.
[0030] Reference Figure 1 , Figure 1 It is a flow chart of the front-end hook dynamic injection method provided by the embodiment of the present application. The front-end hook dynamic injection method is applied to the front-end hook dynamic injection device, and the front-end hook dynamic injection device is applied to the front-end server, and the front-end hook dynamic injection method is executed by a processor in an electronic device or a readable storage medium. The front-end hook dynamic injection method includes steps S100, S200, S300, S400 and S500.
[0031] Step S100, configuring an entry file in the front-end basic service, the entry file including information of the target object to be injected.
[0032] In one embodiment, the entry file includes the target object information of the injection, which indicates the specified process or module into which the hook function code is to be injected, such as the path or version. The purpose of configuring the entry file is to clearly indicate the injection tool or code location of the subsequent hook dynamic link library, and which programs or processes are the injection targets. Configuring the entry file in the front-end basic service helps to accurately inject the code into the specified process or module, thereby realizing the front-end business service with specific functions embedded in the front-end basic service.
[0033] In one embodiment, before configuring the entry file in the front-end basic service, the front-end hook dynamic injection method also includes but is not limited to: performing permission verification on the injected target object information. If the injection permission is available, the target object information indicates the injection object; if the injection permission is not available, the injection permission is adjusted.
[0034] In some possible embodiments of the present application, before configuring the entry file in the front-end basic service, the target object information for injection can be verified for permissions, specifically: the target object information can be process information, first obtain the process's running permissions or protection mechanism, the process's running permissions can prevent low-privilege processes from injecting code into high-privilege processes; the protection mechanism can prevent unreasonable code injection through security software. According to the process's running permissions or protection mechanism, if it is determined that the process has injection permissions, the target object information indicates the injection object, and the injection object provides a destination address for embedding other front-end business services, ensuring the logic of the embedded code.
[0035] In some other possible embodiments of the present application, before configuring the entry file in the front-end basic service, the target object information to be injected can be verified for permissions. If the injection permission is not available, it indicates that the permission of the process or module is low, or the process or module does not have the running permission, and the injection permission can be adjusted. By obtaining the permission of the process and running the program as an administrator, the permission of the process can be adjusted to enable the embedding operation of other front-end business services. Or according to the injection requirements, if the injection permission is not available, the injection permission may not be adjusted, and the injection fails, and the injection code is not set for the process or module.
[0036] Step S200, obtaining the access path configured for the front-end business service.
[0037] In one embodiment, the access path is the loading path of the front-end business service. The corresponding front-end business service can be found according to the access path. The access path can be stored in a path configuration file in advance, and one or more configuration files are maintained. The configuration files are dynamically loaded and parsed in the front-end code to obtain the front-end business service. It is also possible to set environment variables in the code to implement access calls of relative paths or absolute paths. When running the corresponding code, the configured access path is obtained to obtain the front-end business service. By obtaining the access path configured by the front-end business service, it is convenient to load the front-end business service according to the access path in the future, and provide support for establishing connections between subsequent services.
[0038] Step S300, loading the corresponding front-end business service according to the access path, the front-end business service includes a hook function, and the hook function is used to respond to the business information across the front-end basic services.
[0039] In one embodiment, the access path can be a web link or a path set by an environment variable, such as a relative path and an absolute path. In the case where the access path is a web link, the corresponding front-end business service is loaded according to the access path. First, the path of the web link is rendered and parsed using routing, and the content corresponding to the web link is accessed through the back end to return the corresponding web page, which is the front-end business service. In the case of a relative path or an absolute path, the access path is parsed and the front-end business service stored under the path is loaded.
[0040] like Figure 2 As shown, the corresponding front-end business service is loaded according to the access path. The front-end business service includes a hook function. The hook function is used to respond to business information across front-end basic services, including but not limited to the following steps: Step S310: Use the preset dynamic import and optional chaining operators to load the front-end business service corresponding to the access path.
[0041] In some possible embodiments of the present application, in the process of loading the front-end business service, the preset dynamic import means dynamically loading modules or resources as needed when the program is running. The front-end business service is loaded by dynamic import, and in this process, the front-end business service corresponding to the access path is loaded by using the optional chaining operator to verify the access path, thereby ensuring the security of obtaining the front-end business service.
[0042] Step S320, storing the hook function in the object of the front-end basic service, and reading the front-end business service through a preset access interface.
[0043] In some possible embodiments of the present application, since the front-end business service includes a hook function, the hook function is used to respond to business information across the front-end basic service, the hook function in the loaded front-end business service is stored in the object created by the front-end basic service, and the front-end business service is read through a preset access interface. Among them, the preset access interface is the system application programming interface used, and the hook operation is performed through the application programming interface by injecting the hook function, and the front-end business service can be read, so that the connection between the front-end basic business and the front-end business service can be established through the dynamic link library later.
[0044] In one embodiment, the process of defining the hook function includes but is not limited to: instantiating and applying the definition of the hook function to obtain the function logic; and encapsulating the function logic using a preset built-in hook to obtain the hook function.
[0045] In some possible embodiments of the present application, a hook function is a function that is automatically called at a specific time point, used to intercept or extend certain operations in a program, and is usually used in a framework, library, or operating system to provide extensibility and the ability to customize behavior. Each front-end business service can be embedded in the front-end basic service through the hook function. First, a hook function is constructed, which can be set in JavaScript language, and the options in the Vue.js definition function are used to define the instantiated application. The instantiated application can be determined according to the specific implementation functions of each front-end business service, which will not be described here, so as to realize the front-end page call at different stages. By performing function definition, a function logic is obtained, and the function logic is the logic for realizing the function. By executing the function logic, the corresponding instance application function can be realized. Then the preset built-in hook function is used to encapsulate the obtained function logic to obtain a hook function. Wherein the encapsulation can adopt a custom encapsulation to realize the reuse of the code. For example, by custom encapsulating the state related to the business logic, first define an asynchronous function, set isLoading to yes, indicating that it is loading, and then send a network request to the designated web page link to be accessed. If the request is successful, the result is stored, and if the request fails, the loading is completed; finally, the web page link is used as a parameter to obtain the corresponding data, implement the encapsulation and adjustment of the hook, and obtain the hook function. By defining and encapsulating the hook function, the hook function can be used to establish the connection between the front-end businesses in the future.
[0046] like Figure 3 As shown, the front-end business service corresponding to the access path is loaded using the preset dynamic import and optional chaining operators, including but not limited to the following steps: Step S311, verifying the access path using the optional chaining operator.
[0047] In some possible embodiments of the present application, the optional chaining operator can safely access the properties or methods of deeply nested objects without explicitly verifying whether each layer exists. For the access path, it includes multiple layers of access. Exemplarily, the absolute path includes disk, folder and file layers. The access path is verified by the optional chaining operator. Specifically, it can be verified in array form or in combination with the null value merging operator, and the verification value, i.e., the return value, is returned, which is conducive to subsequent business judgment based on the return value. It should be noted that the optional chaining operator can also verify multiple layers of properties, objects, arrays, etc. in the web page and give a return result.
[0048] Step S312: when the return value of the optional chain operator is normal, the front-end business service corresponding to the access path is loaded by using the preset dynamic import.
[0049] In some possible embodiments of the present application, according to the verification return value obtained in step S311, when the return value of the optional chaining operator is normal, it indicates that the access path exists and is correct, and the corresponding front-end business service can be obtained from the access path, and the front-end business service corresponding to the access path is loaded using the preset dynamic import. By loading the front-end business service, the connection between the front-end basic service and each front-end business service can be established later.
[0050] In another embodiment, after verifying the access path using the optional chaining operator, the front-end hook dynamic injection method further includes but is not limited to the following steps: Step S313: When the return value of the chaining operator is abnormal, the access path cannot obtain the front-end business service.
[0051] In some possible embodiments of the present application, according to the verification return value obtained in step S311, when the return value of the optional chaining operator is abnormal, it indicates that the access path may not exist, or the file does not exist, and the corresponding front-end business service cannot be obtained from the access path, and the access path cannot obtain the front-end business service. By performing verification, the embedded security and system stability can be guaranteed.
[0052] Step S400, injecting a preset hook dynamic link library into the front-end basic service, and starting the hook dynamic link library to inject the hook function into the front-end basic service corresponding to the target object information.
[0053] In one embodiment, in the front-end basic service, according to the target object information indicated by the entry file configured by the front-end basic service, the dynamic link library is used to inject the process indicated by the target object information, and the dynamic link library is started to inject the defined instantiation hook function into the process. By injecting the core code dynamic link library into the process, the connection between the front-end basic service and each front-end business service can be realized to avoid logical confusion. Through the hook function, all the system application programming interfaces used indicated by the target object information are hooked to take over the system application programming interface. After taking over the system application programming interface, the corresponding front-end business service can be run, avoiding unclear logic in the program and enabling unified management.
[0054] like Figure 4 As shown, the preset hook dynamic link library is injected into the front-end basic service, and the hook dynamic link library is started to inject the hook function into the front-end basic service corresponding to the target object information, including but not limited to the following steps: Step S410, using the preset loading interface in the front-end basic service to load the hook dynamic link library to obtain the address of the hook function, the preset loading interface is the ffi-napi interface.
[0055] In some possible embodiments of the present application, the trigger time of the hook function and how to interact with the front-end business service are configured in the entry file of the front-end basic service. The hook dynamic link library is loaded through the ffi-napi interface. First, ffi-napi and ref-napi are installed and configured in the front-end project. The ffi-napi can be used to load the hook dynamic link library and define how to call the function therein, get the address of the hook function, and call the hook function according to the address of the hook function to run the front-end business service.
[0056] Step S420, loading the hook dynamic link library, starting the hook dynamic link library, so as to inject the hook function into the front-end basic service corresponding to the target object information.
[0057] In some possible embodiments of the present application, the hook dynamic link library is loaded according to step S410, and the hook dynamic link library is started to inject the hook function into the front-end basic service corresponding to the target object information to run the front-end business service. Through the hook function, all the system application programming interfaces used indicated by the target object information are hooked to take over the system application programming interface. After taking over the system application programming interface, the corresponding front-end business service can be run, avoiding unclear logic in the program and enabling unified management.
[0058] Step S500: receiving a front-end business submission request, and submitting the front-end basic service and the front-end business service.
[0059] In one embodiment, the front-end business submission request is the demand of the front-end running program, which is the demand generated when the front-end basic service interacts with each front-end business service. According to the configuration of the front-end basic service and the hook function of the front-end business service, the instance application setting is set, and the set front-end basic service and front-end business service are submitted to complete the development and design of the connection between the front-end business services to ensure the stable operation of the program.
[0060] like Figure 5As shown, the embodiment of the present application provides a front-end hook dynamic injection device 100, which configures an entry file in the front-end basic service through a file configuration module 110. The entry file includes the target object information to be injected. By configuring the entry file to indicate the target object information, other service addition locations are provided, which can avoid logical mutual exclusion problems; the access path configured by the front-end business service is obtained through the path acquisition module 120, so as to subsequently obtain the front-end business service; and then the service loading module 130 is used to load the corresponding front-end business service according to the access path. The front-end business service includes a hook function, which is used to respond to the business across the front-end basic service. Information, define the front-end business service through the hook function so that it can be embedded in the front-end basic service; use the injection module 140 to inject the preset hook dynamic link library into the front-end basic service, and start the hook dynamic link library to inject the hook function into the front-end basic service corresponding to the target object information, and embed the front-end business service into the front-end basic service through the hook dynamic link library, so that each front-end business service is clearly separated, which can not only be managed in a unified manner, but also can reduce code redundancy and logical confusion, thereby improving development efficiency; receive the front-end business submission request through the business submission module 150, submit the front-end basic service and the front-end business service, so as to run the front-end application.
[0061] It should be noted that the file configuration module 110 is connected to the path acquisition module 120 , the path acquisition module 120 is connected to the service loading module 130 , the service loading module 130 is connected to the injection module 140 , and the injection module 140 is connected to the business submission module 150 . The front-end hook dynamic injection method is applied to the front-end hook dynamic injection device 100. The front-end hook dynamic injection device 100 first configures an entry file in the front-end basic service. The entry file includes the target object information to be injected. By configuring the entry file to indicate the target object information, other service addition locations are provided, which can avoid logical mutual exclusion problems; obtain the access path configured by the front-end business service so as to subsequently obtain the front-end business service; load the corresponding front-end business service according to the access path, the front-end business service includes a hook function, and the hook function is used to respond to business information across the front-end basic service. The front-end business service is defined through the hook function so that it can be embedded in the front-end basic service; inject a preset hook dynamic link library into the front-end basic service, and start the hook dynamic link library to inject the hook function into the front-end basic service corresponding to the target object information, and embed the front-end business service into the front-end basic service through the hook dynamic link library, so that each front-end business service is clearly separated, which can not only be managed in a unified manner, but also reduce code redundancy and logical confusion, thereby improving development efficiency; receive a front-end business submission request, submit the front-end basic service and the front-end business service, so as to run the front-end application.
[0062] Among them, the service loading module 130 specifically loads the front-end business service by using dynamic import, and in this process, the front-end business service corresponding to the access path can be loaded by using the optional chain operator to verify the access path, ensuring the security of obtaining the front-end business service. Among them, the optional chain operator can safely access the properties or methods of deeply nested objects without explicitly verifying whether each layer exists. For the access path, it includes multi-layer access. For example, the absolute path includes disk, folder and file layers. The access path is verified by the optional chain operator, which can be verified in array form or in combination with the null value merging operator, and the verification value, that is, the return value, is returned, which is conducive to subsequent business judgment based on the return value. It should be noted that the optional chain operator can also verify the multi-layer attributes, objects, arrays, etc. in the web page and give a return result. When the return value of the optional chain operator is normal, it indicates that the access path exists and is correct, and the corresponding front-end business service can be obtained from the access path, and the front-end business service corresponding to the access path is loaded by the preset dynamic import. By loading the front-end business service, the connection between the front-end basic service and each front-end business service can be established later. When the return value of the optional chaining operator is abnormal, it indicates that the access path may not exist, or the file does not exist, and the corresponding front-end business service cannot be obtained from the access path. By performing verification, the embedded security and system stability can be guaranteed.
[0063] The service loading module 130 is also specifically used to respond to the business information across the front-end basic services through the hook function, store the hook function in the loaded front-end business service into the object created by the front-end basic service, and read the front-end business service through the preset access interface. Among them, the preset access interface is the system application programming interface used, and the hook operation is performed through the application programming interface by injecting the hook function, so that the front-end business service can be read, so as to establish the connection between the front-end basic business and the front-end business service through the dynamic link library.
[0064] The injection module 140 specifically loads the hook dynamic link library through the ffi-napi interface. First, install and configure ffi-napi and ref-napi in the front-end project. You can use ffi-napi to load the hook dynamic link library and define how to call the function therein, get the address of the hook function, and call the hook function according to the address of the hook function to run the front-end business service. According to the above loading of the hook dynamic link library, start the hook dynamic link library to inject the hook function into the front-end basic service corresponding to the target object information to run the front-end business service. Through the hook function, all the system application programming interfaces used indicated by the target object information are hooked to take over the system application programming interface. After taking over the system application programming interface, the corresponding front-end business service can be run, avoiding unclear logic in the program and enabling unified management.
[0065] It should also be noted that: when the device provided in the above embodiment realizes its function, only the division of the above functional modules is used as an example. In actual application, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the device and method embodiments provided in the above embodiment belong to the same concept, and the specific implementation process is detailed in the method embodiment, which will not be repeated here.
[0066] The present application also discloses an electronic device. Figure 6 , Figure 6 The electronic device 500 may include: at least one processor 501 , at least one network interface 504 , a user interface 503 , a memory 505 , and at least one communication bus 502 .
[0067] The communication bus 502 is used to realize the connection and communication between these components.
[0068] The user interface 503 may include a display screen (Display) and a camera (Camera). Optionally, the user interface 503 may also include a standard wired interface and a wireless interface.
[0069] The network interface 504 may optionally include a standard wired interface or a wireless interface (such as a WI-FI interface).
[0070] Among them, the processor 501 may include one or more processing cores. The processor 501 uses various interfaces and lines to connect various parts in the entire server, and executes various functions of the server and processes data by running or executing instructions, programs, code sets or instruction sets stored in the memory 505, and calling data stored in the memory 505. Optionally, the processor 501 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 501 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 501, and it can be implemented separately through a chip.
[0071] Among them, the memory 505 may include a random access memory (Random Access Memory, RAM) and may also include a read-only memory (Read-Only Memory). Optionally, the memory 505 includes a non-transitory computer-readable storage medium. The memory 505 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 505 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory 505 may also be optionally at least one storage device located away from the aforementioned processor 501. Refer to Figure 6 , the memory 505 as a computer storage medium may include an operating system, a network communication module, a user interface module and an application program of a front-end hook dynamic injection method.
[0072] exist Figure 6In the electronic device 500 shown, the user interface 503 is mainly used to provide an input interface for the user and obtain the data input by the user; and the processor 501 can be used to call an application program storing a front-end hook dynamic injection method in the memory 505, and when executed by one or more processors 501, the electronic device 500 executes one or more methods in the above-mentioned embodiments. It should be noted that for the aforementioned method embodiments, for the sake of simple description, they are all expressed as a series of action combinations, but those skilled in the art should know that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required for the present application.
[0073] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0074] In the several embodiments provided in this application, it should be understood that the disclosed devices can be implemented in other ways. For example, the device embodiments described above are only schematic, such as the division of units, which is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some service interfaces, and the indirect coupling or communication connection of devices or units can be electrical or other forms.
[0075] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0076] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0077] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a memory and includes several instructions for a computer device (which can be a personal computer, server or network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned memory includes: various media that can store program codes, such as USB flash drives, mobile hard drives, magnetic disks or optical disks.
[0078] The above are only exemplary embodiments of the present disclosure and cannot be used to limit the scope of the present disclosure. That is, any equivalent changes and modifications made according to the teachings of the present disclosure are still within the scope of the present disclosure. After considering the disclosure of the specification and the truth of practice, those skilled in the art will easily think of other embodiments of the present disclosure.
[0079] This application is intended to cover any variation, use or adaptation of the present disclosure, which follows the general principles of the present disclosure and includes common knowledge or customary technical means in the art not described in the present disclosure. The description and examples are to be regarded as exemplary only, and the scope and spirit of the present disclosure are defined by the claims.
Claims
1. A front-end hook dynamic injection method, characterized in that: Applied to a front-end server, the method comprises: Configure an entry file in the front-end basic service, wherein the entry file includes information of the target object to be injected; Get the access path of the front-end business service configuration; Loading a corresponding front-end business service according to the access path, wherein the front-end business service includes a hook function, and the hook function is used to respond to business information across the front-end basic service; Injecting a preset hook dynamic link library into the front-end basic service, and starting the hook dynamic link library to inject the hook function into the front-end basic service corresponding to the target object information; A front-end business submission request is received, and the front-end basic service and the front-end business service are submitted.
2. The method according to claim 1, characterized in that Loading a corresponding front-end business service according to the access path, wherein the front-end business service includes a hook function, and the hook function is used to respond to business information across the front-end basic service, including: Load the front-end business service corresponding to the access path using preset dynamic import and optional chaining operators; The hook function is stored in the object of the front-end basic service, and the front-end business service is read through a preset access interface.
3. The method according to claim 2, characterized in that The method of loading the front-end business service corresponding to the access path by using the preset dynamic import and the optional chaining operator includes: The access path is verified using the optional chaining operator, and when the return value of the optional chaining operator is normal, the front-end business service corresponding to the access path is loaded using a preset dynamic import.
4. The method according to claim 3, characterized in that After verifying the access path using the optional chaining operator, the method further includes: When the return value of the select chain operator is abnormal, the access path cannot obtain the front-end business service.
5. The method according to claim 1, characterized in that The definition process of the hook function includes: Instantiate and apply the hook function to obtain function logic; The function logic is encapsulated using a preset built-in hook to obtain the hook function.
6. The method according to claim 1, characterized in that The step of injecting a preset hook dynamic link library into the front-end basic service and starting the hook dynamic link library to inject the hook function into the front-end basic service corresponding to the target object information includes: Using the preset loading interface in the front-end basic service to load the hook dynamic link library, the address of the hook function is obtained, and the preset loading interface is the ffi-napi interface; The hook dynamic link library is loaded and started to inject the hook function into the front-end basic service corresponding to the target object information.
7. The method according to claim 1, characterized in that Before configuring the entry file in the front-end basic service, the method further includes: Performing authority verification on the target object information of the injection, and in the case of having injection authority, the target object information indicates the injection object; In the case of not having the injection authority, adjusting the injection authority.
8. A front hook dynamic injection device, characterized in that: Applied to a front-end server, the device comprises: A file configuration module (110), used to configure an entry file in the front-end basic service, wherein the entry file includes information of an injected target object; A path acquisition module (120), used to acquire the access path configured by the front-end business service; A service loading module (130), used for loading a corresponding front-end business service according to the access path, wherein the front-end business service includes a hook function, and the hook function is used for responding to business information across the front-end basic service; An injection module (140) is used to inject a preset hook dynamic link library into the front-end basic service, and start the hook dynamic link library to inject the hook function into the front-end basic service corresponding to the target object information; The business submission module (150) is used to receive a front-end business submission request and submit the front-end basic service and the front-end business service.
9. An electronic device, characterized in that: The electronic device (500) comprises a processor (501), a memory (505), a user interface (503), a communication bus (502) and a network interface (504), wherein the processor (501), the memory (505), the user interface (503) and the network interface (504) are respectively connected to the communication bus (502), the memory (505) is used to store instructions, the user interface (503) and the network interface (504) are used to communicate with other devices, and the processor (501) is used to execute the instructions stored in the memory (505) so that the electronic device (500) executes the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, and when the instructions are executed, the method according to any one of claims 1 to 7 is executed.