Code injection method and device, storage medium and computer equipment

By implementing unified registration and verification for clients, combined with a whitelist mechanism and a unified operating framework, the uncontrollability issues caused by spontaneous agent injection methods are resolved. This achieves unified management and controllable execution of the code injection process, thereby improving security and reliability.

CN121704852APending Publication Date: 2026-03-20GUANGZHOU PINWEI SOFTWARE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511991357.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-26
Publication Date
2026-03-20

AI Technical Summary

Technical Problem

The existing spontaneous agent injection method lacks a unified management and control mechanism, which makes the code injection process uncontrollable as a whole and prone to risks such as conflicts between injected code and uncontrollable execution order.

Method used

By uniformly registering and verifying client identifiers, runtime environment information, and permission information, the target client is identified. Combined with a preset whitelist mechanism, the accessible code repositories are limited. The injection code is compiled and integrated in a unified runtime framework to generate an injection agent that matches the target client. The injection results are then centrally distributed and monitored.

Benefits of technology

It achieves unified management and controllable execution of code injection objects, injection content, injection execution process and injection results, improves the security, controllability and maintainability of the code injection process, and avoids unpredictable behavior and uncontrollable execution problems caused by unrestrained injected code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121704852A_ABST
    Figure CN121704852A_ABST
Patent Text Reader

Abstract

The invention provides a code injection method and device, a storage medium and computer equipment, and the method comprises the steps: determining target clients passing verification based on a client identifier, operation environment information and authority information of each registered client, and determining a target code warehouse which is associated with each target client and accords with a preset white list; according to the code injection configuration of each target client, obtaining a target injection code of each target client from a corresponding target code warehouse; in the unified operation framework, compiling and integrating each target injection code, and generating a to-be-injected Agent matched with the corresponding target client; and distributing each to-be-injected Agent to the corresponding target client, and receiving an Agent injection result and an operation state returned by each target client, so as to confirm the Agent injection state of the corresponding target client. Therefore, unified management and controllable execution of code injection are realized, and the controllability of the code injection process is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of code injection, and particularly relates to a code injection method and device, a storage medium and a computer device. BACKGROUND

[0002] In the modern software development process, with the expansion of business scale and the improvement of system architecture complexity, the demand for function verification, risk control and rapid iteration of applications in the running process is increasing. In order to verify new functions and control release risks without interrupting business, code injection technology is widely used in A / B testing, gray release and function switch scenarios, which realizes flexible regulation and control of system behavior by dynamically loading or replacing part of the logic in the application runtime.

[0003] At present, the code injection is generally realized by using self-generated Agent, that is, each application or team independently deploys and maintains an independent injection Agent, and manages the corresponding injection configuration and injection code respectively. However, with the increase of the number of injection modules and the continuous evolution of injection logic, this method gradually exposes the problems of scattered configuration, high maintenance cost, difficult unified management of versions and lack of centralized monitoring of injection behavior. Especially in the case of multiple Agent parallel running, it is easy to cause mutual conflict between injection codes, uncontrollable execution sequence and other risks.

[0004] Therefore, the existing self-generated Agent injection method lacks unified management and control mechanism, resulting in that the code injection process is overall uncontrollable. SUMMARY

[0005] The present application aims to at least solve one of the above technical defects, in particular, the technical defect that the existing self-generated Agent injection method lacks unified management and control mechanism, resulting in that the code injection process is overall uncontrollable.

[0006] In a first aspect, the present application provides a code injection method, the method comprising:

[0007] Based on the client identifier, the running environment information and the permission information of each registered client, a target client passing the verification is determined, and a target code repository associated with each target client and meeting a preset white list is determined;

[0008] According to the code injection configuration of each target client, the target injection code of each target client is obtained from the corresponding target code repository, and the code injection configuration is used to limit the code range allowed to be injected by different target clients under the corresponding target application or running environment;

[0009] In the unified running framework, the target injection code is compiled and integrated to generate the to-be-injected Agent matched with the corresponding target client, and the unified running framework is used to provide consistent code injection execution forms for different target clients.

[0010] The to-be-injected Agent is distributed to the corresponding target client, and the Agent injection result and running state returned by each target client are received to confirm the Agent injection state of the corresponding target client.

[0011] In an embodiment, the step of determining the target code repository associated with each target client and meeting the preset white list comprises:

[0012] According to the client identifier of each target client, the candidate code repository associated with each target client is filtered out in the preset white list;

[0013] The version identifier and submission information corresponding to each candidate code in each candidate code repository are checked, and the candidate code repository that passes the check is determined as the target code repository.

[0014] In an embodiment, the step of obtaining the target injection code of each target client from the corresponding target code repository according to the code injection configuration of each target client comprises:

[0015] The pre-configured injection-allowed code type, target application identifier and applicable running environment identifier in the code injection configuration of each target client are read;

[0016] In the target code repository of each target client, the target injection code of each target client is filtered according to the corresponding code type identifier, target application identifier and applicable running environment identifier.

[0017] In an embodiment, the step of compiling and integrating each target injection code in the unified running framework to generate the to-be-injected Agent matched with the corresponding target client comprises:

[0018] Based on the unified interface specification and dependency constraint rules preset in the unified running framework, and combined with the running environment information of each target client, the target injection code is compiled and integrated to generate the to-be-injected Agent matched with the corresponding target client.

[0019] In an embodiment, the step of distributing each to-be-injected Agent to the corresponding target client comprises:

[0020] The preset distribution strategy and the corresponding injection instruction generated for each to-be-injected Agent are obtained;

[0021] According to a preset distribution strategy, each to-be-injected Agent and its injection instruction are distributed to a corresponding target client, so that each target client, after receiving the corresponding injection instruction, suspends application traffic, switches to the corresponding to-be-injected Agent, and then resumes application traffic.

[0022] In one embodiment, after the step of receiving the Agent injection result and the running state returned by each target client, the method further includes:

[0023] For each target client, when it is determined that the target client has failed in Agent injection according to the received Agent injection result and the running state, triggering the target client to perform a retry operation, and generating an alarm information to prompt the code injection exception of the target client.

[0024] In one embodiment, the method further includes:

[0025] For each target client, according to the target application identifier corresponding to the target client, checking the configuration permission of the current operation user account, and when the checking is passed, allowing the current operation user account to perform a code injection configuration modification operation.

[0026] In a second aspect, the present application provides a code injection device, the device comprising:

[0027] A target code repository determination module is configured to determine a target client that passes the verification based on the client identifier, the running environment information and the permission information of each registered client, and determine a target code repository associated with each target client and meeting a preset white list;

[0028] A target injection code acquisition module is configured to acquire the target injection code of each target client from the corresponding target code repository according to the code injection configuration of each target client, the code injection configuration being configured to limit the code range allowed to be injected by different target clients under the corresponding target application or running environment;

[0029] A to-be-injected Agent generation module is configured to compile and integrate each target injection code in a unified running framework to generate a to-be-injected Agent matched with the corresponding target client, the unified running framework being configured to provide a consistent code injection execution form for different target clients;

[0030] A to-be-injected Agent distribution module is configured to distribute each to-be-injected Agent to the corresponding target client, and receive the Agent injection result and the running state returned by each target client to confirm the Agent injection state of the corresponding target client.

[0031] In a third aspect, the present application provides a storage medium, the storage medium storing computer readable instructions, the computer readable instructions, when executed by one or more processors, causing the one or more processors to perform the steps of any of the above code injection methods.

[0032] In a fourth aspect, the present application provides a computer device, comprising: one or more processors, and a memory;

[0033] The memory stores computer readable instructions, the computer readable instructions, when executed by the one or more processors, performing the steps of any of the above code injection methods.

[0034] From the above technical solutions, the embodiments of the present application have the following advantages:

[0035] The code injection method, device, storage medium and computer device provided by the present application avoid the disorderly spread of injection objects and injection sources from the source by uniformly registering and verifying the client before code injection, and determining the controllable target client based on the client identifier, running environment information and permission information, and combining the preset whitelist mechanism to limit the accessible code repository; on this basis, the code injection configuration is further used to explicitly limit the code range allowed to be injected by different target clients under the corresponding target application or running environment, so that the injection content matches the client capability and running environment, avoiding the unpredictable behavior caused by the uncontrolled injection code in the spontaneous injection; at the same time, the target injection code is uniformly placed in the same running framework for compilation and integration to generate the to-be-injected Agent matching the target client, so that the code injection process of different clients has consistent execution form, thereby eliminating the execution uncontrollable problem caused by the dispersion of injection methods; finally, the to-be-injected Agent is distributed centrally and the injection results and running states returned by each target client are uniformly received, so as to realize the centralized monitoring and state confirmation of the whole code injection process. Thus, the present application effectively solves the technical problem that the existing spontaneous Agent injection method lacks unified management and control mechanism, resulting in the whole uncontrollable code injection process, realizes the unified management and controllable execution of the code injection object, injection content, injection execution process and injection result, and significantly improves the safety, controllability and operability of the code injection process. BRIEF DESCRIPTION OF DRAWINGS

[0036] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed in the embodiments or prior art description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and those skilled in the art can obtain other drawings according to these drawings without creative labor.

[0037] Figure 1 A flowchart of a code injection method provided for an embodiment of the present application is shown in FIG. 1.

[0038] Figure 2 A structural diagram of a code injection device provided for an embodiment of the present application is shown in FIG. 2.

[0039] Figure 3 An internal structural diagram of a computer device provided for an embodiment of the present application is shown in FIG. 3. DETAILED DESCRIPTION

[0040] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by a person of ordinary skill in the art without creative work fall within the scope of protection of the present application.

[0041] The present application provides a code injection method. The following embodiments are described by taking the application of the method to a computer device as an example. It can be understood that the computer device can be various devices with data processing functions, which can be, but are not limited to, a single server, a server cluster, a personal notebook computer, a desktop computer, etc. As shown in FIG. 1, the method can include the following steps: Figure 1

[0042] S101: determining a target client that passes the verification based on the client identifier, the running environment information and the permission information of each registered client, and determining a target code repository associated with each target client and meeting a preset white list.

[0043] The client identifier is identification information for uniquely identifying a client instance in the code injection system, which is used to distinguish different access subjects. The running environment information is environmental parameter information reflecting the current running condition of the client, which is used to represent the operating system type, the running platform features and the deployment environment of the target application in which the client is located. The permission information is authorization information for limiting the executable operation range and the accessible resource range of the client. The target client refers to a client that is allowed to participate in the code injection process after the verification of the client identifier, the running environment information and the permission information. The preset white list is a code repository set pre-configured for limiting the legal code sources. The target code repository refers to a code storage location that is associated with the target client and is allowed to provide injection code to the target client within the preset white list.

[0044] ​In the implementation process, first, the client identifier, running environment information and permission information uploaded by the registered client are received, and the received data is parsed and stored to form a client basic information set for subsequent processing. The client identifier is used to determine the unique identity of the client, the running environment information is used to reflect the current application scenario and running condition of the client, and the permission information is used to indicate the authorization level of the client in the system.

[0045] After completing the information reception, the client is subjected to a verification process. In the verification process, the client identifier is compared with the registered information to confirm the legality of the client source; at the same time, the running environment information is compared with the pre-set environment matching rule to determine whether the current running condition of the client meets the execution requirement of code injection; and based on the permission information, it is judged whether the client has the authorization to execute the code injection related operation. When the client meets the verification conditions in terms of identity legality, environment adaptability and permission compliance, the client is determined as the target client.

[0046] After the target client is determined, the code repository is further associated. According to the client identifier, running environment information and permission information corresponding to the target client, the code repository matched with the target client is selected from the pre-set white list, and the association between the target client and the selected code repository is established, so as to determine the target code repository accessible by the target client. In this way, it is ensured that the target client can only obtain the injection code from the allowed code source, and a controlled data basis is provided for the subsequent code injection process.

[0047] Through the joint verification of the client identifier, running environment information and permission information, the target client meeting the conditions can be selected before the code injection execution, and on this basis, the code source of the target client is limited within the pre-set white list range, so as to form a constraint mechanism at two levels of client access and code acquisition, avoiding the injection risk caused by the participation of unauthorized clients in code injection and the access of clients to unauthorized code repositories; thus, the code injection process has clear control boundary and unified management rules before execution, which improves the safety, controllability and stability of the code injection process, and provides a reliable premise for the standardized execution of subsequent injection operations.

[0048] S102: According to the code injection configuration of each target client, the target injection code of each target client is obtained from the corresponding target code repository. The code injection configuration is used to limit the code range allowed to be injected by different target clients in the corresponding target application or running environment.

[0049] The code injection configuration is configuration data corresponding to the target client, and is used to limit the code type, code range and applicable conditions allowed to be injected by the target client in a specific target application or running environment; the target injection code is code content that meets the injection conditions and is filtered and obtained from the target code repository according to the code injection configuration corresponding to the target client; the target application is an application program that needs to perform code injection and runs on the target client; and the running environment is the actual running condition and environment state of the target application in the target client.

[0050] In the implementation process, for each determined target client, the code injection configuration corresponding to the target client is first read and parsed to determine the code range allowed to be injected by the target client in the current target application or running environment. The code injection configuration is used to describe the injection boundary of different target clients in different application scenarios, so that the code injection behavior can be processed differently according to the differences between clients.

[0051] After parsing the code injection configuration, the code content in the target code repository is adaptively analyzed in combination with the target application information and the running environment information of the target client currently running. In the adaptive analysis process, each code item stored in the target code repository is matched with the injection conditions defined in the code injection configuration one by one to determine whether the corresponding code meets the injection requirements under the current running state of the target client, so as to filter out code content that does not meet the injection conditions.

[0052] After completing the adaptive analysis, the code content that passes the matching is further selected and integrated. In the selection and integration process, the matched code is reconfirmed according to the code type, applicable range and running environment constraints defined in the code injection configuration, so as to ensure that the selected code is consistent with the actual application scenario of the target client in terms of logical function and running condition. Through the multi-layer selection process, the obtained code content has clear injection specificity.

[0053] After the selection is completed, the code data corresponding to the selection result is read from the target code repository, and the read code data is stored and identified as the target injection code of the target client. The target injection code has been constrained in combination with the target application and the running environment of the target client in the acquisition process, thereby forming an injection code set corresponding to the target client one by one, providing a basic condition for subsequent generation of injection execution content matched with the target client.

[0054] By obtaining the target injection code from the target code repository based on code injection configuration, the range of code allowed to be injected by different target clients can be explicitly limited before code injection execution, so that the injection code is consistent with the target application and the running environment of the target client, thereby avoiding the case that the injection code does not match the running environment or exceeds the authorized range of the client in the code injection process. Therefore, fine-grained control of the source and content of the injection code is achieved, improving the pertinence, standardization and controllability of the code injection process, and providing reliable protection for the stable execution of subsequent injection operations.

[0055] S103: In the unified running framework, each target injection code is compiled and integrated to generate an Agent to be injected matched with the corresponding target client, and the unified running framework is used to provide consistent code injection execution forms for different target clients.

[0056] Among them, the unified running framework refers to a running environment for carrying code compilation, integration and injection execution rules, which is used to provide consistent code injection execution forms for different target clients; the Agent to be injected refers to an injection execution entity matched with the target client generated after the target injection code is compiled and integrated in the unified running framework.

[0057] In the specific implementation process, for each target injection code that has been obtained, the target injection code is first loaded into the unified running framework for processing. The unified running framework predefines the execution specification and compilation rules of code injection, so that target injection codes of different sources and different functions can be standardized in the same execution environment.

[0058] After the target injection code is loaded, the target injection code is compiled according to the compilation rules set in the unified running framework. During the compilation process, the target injection code is adaptively compiled in combination with the running environment characteristics of the target client, so that the compilation result can be correctly loaded and executed in the running environment corresponding to the target client. In this way, the problem of inconsistent code execution caused by differences in running environments is avoided.

[0059] After the compilation process is completed, the compiled code is further integrated. In the integration process, the target injection code is combined with the pre-installed injection execution logic in the unified running framework, so that the generated injection execution content has unified startup, unified life cycle management and unified execution interface, thereby forming an Agent to be injected matched with the target client. Through this integration process, the Agent to be injected remains consistent in execution form, while meeting the specific injection needs of the target client in function.

[0060] After generating the Agent to be injected, an association is established between each Agent and the corresponding target client, so that the Agent to be injected can correspond one-to-one with the target client during subsequent distribution and execution, thereby providing a foundation for the controllable management of the subsequent injection execution process.

[0061] By compiling and integrating the target injection code within a unified runtime framework, the injection code for different target clients can be standardized before the code injection is executed. This ensures that the generated injection agents maintain consistency in execution form while also adapting to the target client's runtime environment. This avoids execution differences and uncontrollable issues caused by different clients using decentralized compilation and injection methods. Consequently, a unified standard and centralized control of the code injection execution process are achieved, improving the stability, consistency, and manageability of the code injection process.

[0062] S104: Distribute each Agent to be injected to the corresponding target client, and receive the Agent injection result and running status returned by each target client to confirm the Agent injection status of the corresponding target client.

[0063] Among them, Agent injection result refers to the result information returned by the target client after executing the Agent to be injected, which is used to reflect whether the Agent to be injected has been successfully injected; running status refers to the actual running status of the Agent to be injected in the target client, which is used to characterize the execution status of the Agent to be injected after injection; Agent injection status refers to the status information determined based on Agent injection result and running status, which is used to reflect the Agent injection execution status in the target client.

[0064] In the specific implementation process, for each Agent to be injected that has been generated and matched, it is distributed to the corresponding target client according to the pre-established association relationship. During the distribution process, the Agent to be injected is sent in an orderly manner by combining the communication status and reachability information of the target client, so that the Agent to be injected can be correctly received and loaded by the target client.

[0065] After the target client receives the Agent to be injected, the injection execution process of the Agent to be injected is triggered, and the Agent injection result corresponding to the injection process is generated after the injection execution is completed. At the same time, during the operation of the Agent to be injected, the running status information of the Agent to be injected in the target client is continuously collected, so that the running status can reflect the actual execution of the Agent to be injected.

[0066] After obtaining the Agent injection result and running state, the information returned by the target client is received and processed, and the received data is parsed and verified. By associating the Agent injection result with the running state, it is determined whether the injection of the to-be-injected Agent in the target client is completed and whether the running is in the expected state, so as to confirm the Agent injection state of the corresponding target client.

[0067] After confirming the Agent injection state, the confirmation result is stored in correspondence with the target client, which is used for subsequent unified management and state tracking of the injection execution, thereby forming a complete injection execution feedback link.

[0068] By distributing the to-be-injected Agent to the corresponding target client and receiving the returned Agent injection result and running state, the actual injection of the Agent in each target client can be confirmed in time after the injection execution is completed, so that the injection execution result and running state have feedback and traceability capabilities, thereby avoiding the problem that the injection process is only executed but lacks state confirmation. Therefore, the unified control of the Agent injection execution result is realized, and the controllability, reliability and operability of the code injection process are improved.

[0069] In the above embodiment, by uniformly registering and verifying the client before code injection, and determining the controllable target client based on the client identifier, running environment information and permission information, and combining the preset whitelist mechanism to limit the accessible code repository, the unordered diffusion of injection objects and injection sources is avoided from the source. On this basis, the code range allowed to be injected by different target clients in the corresponding target application or running environment is further limited by the code injection configuration, so that the injection content matches the client capability and running environment, and the unexpected behavior caused by unrestricted injection code in spontaneous injection is avoided. At the same time, the target injection code is uniformly placed in the same running framework for compilation and integration to generate a to-be-injected Agent matching the target client, so that the code injection process of different clients has consistent execution form, thereby eliminating the uncontrollable execution problem caused by dispersed injection methods. Finally, by centrally distributing the to-be-injected Agent and uniformly receiving the injection result and running state returned by each target client, centralized monitoring and state confirmation of the whole code injection process are realized. Therefore, the present application effectively solves the technical problem that the existing spontaneous Agent injection method lacks unified management and control mechanism, resulting in the whole uncontrollable code injection process, realizes the unified management and controllable execution of the code injection object, injection content, injection execution process and injection result, and significantly improves the safety, controllability and operability of the code injection process.

[0070] In one embodiment, the step of determining the target code repository associated with each target client and conforming to a preset whitelist includes:

[0071] Based on the client identifier of each target client, candidate code repositories associated with each target client are selected from a preset whitelist;

[0072] The version identifier and commit information corresponding to each candidate code in each candidate code repository are verified, and the candidate code repository that passes the verification is determined as the target code repository.

[0073] Among them, the candidate code repository refers to the code repository that is selected from the preset whitelist based on the client identifier and is associated with the target client; the candidate code refers to the code content stored in the candidate code repository; the version identifier is the identification information used to represent the version status of the candidate code; and the commit information refers to the code commit record information corresponding to the candidate code, which is used to reflect the source, changes and legality of the commit of the candidate code.

[0074] In the implementation process, the code repositories in the preset whitelist are first matched based on the client identifier corresponding to each target client. By comparing the client identifier with the client association information recorded in the whitelist, code repositories that are associated with the target client are filtered out, and the filtered results are determined as candidate code repositories. This process enables different target clients to be mapped to their respective range of allowed code repositories.

[0075] After the candidate code repositories are determined, the code content stored in each repository undergoes further verification. During verification, the version identifier and commit information corresponding to the candidate code are read and compared with pre-defined verification rules to confirm whether the version status of the candidate code meets the usage requirements and whether the code submission source meets the trust criteria. This verification process eliminates code content with version anomalies or whose commit information does not meet the requirements.

[0076] After candidate code verification is completed, the candidate code repositories are confirmed based on the verification results. If a candidate code repository contains at least one piece of code that meets the verification criteria, it is designated as the target code repository and used for code retrieval in the subsequent code injection process. This approach ensures that the determination of the target code repository simultaneously considers both client-side relationships and the legitimacy of the code itself.

[0077] By screening the candidate code repository from the preset whitelist based on the client identifier, and further checking the version identifier and submission information of the candidate code, the source of the code and the version state of the code can be controlled simultaneously before the code injection execution, avoiding the target client accessing the code repository that does not have an association or has a version anomaly, thereby reducing the injection risk caused by unknown code source or uncontrolled version; thus, the determination process of the target code repository has clear screening basis and verification conditions, improving the reliability and controllability of the code source in the code injection process, and providing a stable foundation for the safe execution of subsequent injection operations.

[0078] In one embodiment, according to the code injection configuration of each target client, the step of obtaining the target injection code of each target client from the corresponding target code repository includes:

[0079] Reading the pre-configured allowed injection code type, target application identifier and applicable running environment identifier in the code injection configuration of each target client;

[0080] In the target code repository of each target client, according to the corresponding code type identifier, target application identifier and applicable running environment identifier, the target injection code of each target client is screened.

[0081] Among them, the code type refers to the code category identifier used to distinguish different functions or purposes; the target application identifier is the identification information used to uniquely identify the application in the target client that needs to perform code injection; the applicable running environment identifier is the environment identification information used to identify the current running environment type of the target application in the target client.

[0082] In the specific implementation process, for each target client that has been determined, first read the code injection configuration corresponding to the target client, and parse the pre-configured allowed injection code type, target application identifier and applicable running environment identifier in the code injection configuration. Through this processing, the specific conditions of the target client that allow code injection to be performed in the current application scenario are determined, providing a constraint basis for subsequent code screening.

[0083] After completing the code injection configuration parsing, the code content stored in the repository is matched in combination with the target code repository corresponding to the target client. In the matching process, the code type identifier, target application identifier and applicable running environment identifier parsed from the code injection configuration are used as screening conditions to compare each code in the target code repository item by item to determine whether each code meets the injection requirements of the current target client.

[0084] After the matching processing is completed, the code content that meets the code type requirement, the target application matching requirement and the running environment adaptation requirement is screened out, and is determined as the target injection code corresponding to the target client. Through the screening process, the target injection code is consistent with the actual running situation of the target client in terms of function purpose, application object and running environment, thereby providing a reliable basis for subsequent generation of injection execution content.

[0085] By reading the allowed injection code type, target application identifier and applicable running environment identifier from the code injection configuration, and screening the target injection code in the target code repository accordingly, the injection code range of different target clients can be accurately limited before code injection execution, so that the injection code meets the pre-configured injection conditions in terms of function type, application object and running environment, thereby avoiding the problem of mismatch between the injection code and the target application or the running environment. Thus, fine screening and constraint of the injection code are realized, and the pertinence, standardization and controllability of the code injection process are improved.

[0086] In one embodiment, in the unified running framework, the step of compiling and integrating each target injection code to generate the to-be-injected Agent matching the corresponding target client includes:

[0087] Based on the unified interface specification and dependency constraint rules preset in the unified running framework, and in combination with the running environment information of each target client, each target injection code is compiled and integrated to generate the to-be-injected Agent matching the corresponding target client.

[0088] The unified interface specification refers to an interface definition rule for constraining the interface form and calling manner exposed by the target injection code to the outside; and the dependency constraint rule refers to a rule set for limiting the dependency relationship allowed to be used by the target injection code in the compiling and running process.

[0089] In the specific implementation process, for each determined target injection code, the pre-configured unified interface specification and dependency constraint rules in the unified running framework are first read, and the target injection code is loaded into the unified running framework for processing. Through the processing, the subsequent compiling and integrating process is performed under the unified interface constraint and dependency constraint conditions.

[0090] After the target injection code is loaded, adaptive compiling processing is performed on the target injection code in combination with the running environment information corresponding to the target client. In the compiling process, the target injection code is adapted to the environment according to the running environment information, and the interface calling involved in the code is verified and adjusted according to the unified interface specification, so that the compiling result can meet the unified interface requirement and be applicable to the running environment of the target client.

[0091] After the compiling process is completed, the compiling result is further integrated according to the dependency constraint rule. In the integration process, the dependency relationship involved in the target injection code is checked and arranged, so that the generated execution content only contains the dependency item that meets the dependency constraint rule, and is consistent with the execution structure of the unified running framework, thereby generating the to-be-injected Agent that matches the target client running environment.

[0092] After the to-be-injected Agent is generated, an association relationship between the to-be-injected Agent and the corresponding target client is established, so that the to-be-injected Agent can run in the target client in a unified execution form in the subsequent distribution and execution process.

[0093] By compiling and integrating the target injection code based on the unified interface specification and the dependency constraint rule, and combining the running environment information of the target client, the interface call and the dependency relationship can be uniformly constrained before the to-be-injected Agent is generated, so that the injection execution content of different target clients remains consistent in the execution form, and can also adapt to their respective running environments, thereby avoiding injection execution abnormities caused by non-uniform interfaces or dependency differences. Thus, the standardization and controllability of the code injection execution process are realized, and the environmental adaptability and running stability of the to-be-injected Agent are improved.

[0094] In one embodiment, the step of distributing each to-be-injected Agent to the corresponding target client comprises:

[0095] obtaining a preset distribution strategy and generating a corresponding injection instruction for each to-be-injected Agent;

[0096] According to the preset distribution strategy, each to-be-injected Agent and its injection instruction are distributed to the corresponding target client, so that each target client, when receiving the corresponding injection instruction, suspends the application traffic, switches to the corresponding to-be-injected Agent, and then restores the application traffic.

[0097] The preset distribution strategy refers to a rule set configured before the injection process starts, which is used to specify the sending order of the to-be-injected Agent, the target client selection, and the injection timing. The injection instruction refers to control information for guiding the target client to suspend the application traffic, switch to the to-be-injected Agent, and restore the traffic. The application traffic refers to the user request or data processing task normally processed by the target application in the target client.

[0098] In the specific implementation process, first, the corresponding injection instruction is generated for each to-be-injected Agent. In the generation process, the injection order, the target client matching information, and the injection operation steps are coded in combination with the preset distribution strategy, forming injection control information that can be correctly executed in the target client, so that the target client can execute the injection operation according to the predetermined process.

[0099] After the injection instruction is generated, each to-be-injected Agent and its injection instruction are distributed to the corresponding target client according to a preset distribution strategy. During the distribution process, the to-be-injected Agent and the injection instruction are transmitted reliably in combination with the online state and network reachability of the target client, so as to ensure that the target client can receive complete injection execution content in time.

[0100] When the target client receives the injection instruction, an execution process is triggered. During the execution process, the target client suspends application traffic first according to the injection instruction, so that the current request or task being processed is completed or safely stopped, and then switches to the corresponding to-be-injected Agent, so that code injection can be performed in a safe running environment. After the switching is completed, the application traffic is restored, so that the target client can continue to process normal requests under the control of the injection Agent, thereby ensuring the continuity and stability of the application.

[0101] During the entire distribution and execution process, the target client can complete code injection with minimized business interruption through the cooperation of the injection instruction and the to-be-injected Agent, while ensuring the controllability and execution safety of the injection operation.

[0102] By generating the injection instruction according to the preset distribution strategy and distributing the to-be-injected Agent and the injection instruction to the corresponding target client, the suspension and restoration of application traffic can be effectively controlled during the injection process, the ordered execution of the injection operation can be realized, the target client can complete code switching in a safe and controllable state, application abnormalities or interruptions caused by the injection operation can be avoided, and thus the safety, controllability and business continuity of the code injection process are improved.

[0103] In one embodiment, after the step of receiving the Agent injection result and the running state returned by each target client, the method further comprises:

[0104] For each target client, when it is determined that the target client has failed in Agent injection according to the received Agent injection result and the running state, the target client is triggered to perform a retry operation, and an alarm information is generated to prompt the code injection exception of the target client.

[0105] The Agent injection failure refers to a situation that the target client fails to complete code injection after comprehensive analysis of the Agent injection result and the running state; the retry operation refers to an operation of re-executing the injection process for the target client that has failed in Agent injection; and the alarm information refers to notification information generated when the Agent injection failure is detected, which is used to prompt the code injection exception of the target client or the management system.

[0106] In the specific implementation process, first, the Agent injection result and running state information returned by each target client are received, and the received data is parsed and analyzed. In the parsing process, the Agent injection result and the running state are compared to determine whether the target client successfully completes the execution of the Agent to be injected. If the analysis result shows that the target client has an exception during execution or does not reach the expected execution state, it is determined that the target client has an Agent injection failure.

[0107] After determining that the Agent injection fails, the target client is triggered to perform a retry operation. The retry operation re-sends the Agent to be injected according to the preset retry strategy, and restarts the injection execution process to attempt to correct the first injection failure. During the execution of the retry process, the running state and injection execution of the target client are continuously monitored to ensure that the retry operation can be performed in a safe and controllable environment.

[0108] At the same time, when the Agent injection failure is detected, corresponding alarm information is generated. The alarm information includes target client identification, failure time, failure type, and injection operation state, and is sent to the management system or record storage for prompting the system administrator or automatic management system to pay attention to the code injection exception of the client, and further processing or analysis.

[0109] Through the processing flow, real-time response to injection failure is realized, so that the retry operation can be triggered as soon as possible, and the alarm information provides traceability and manageability, providing data support and operation basis for injection process exception handling.

[0110] By determining the injection failure according to the Agent injection result and running state and triggering the retry operation, and generating alarm information, quick response and correction can be realized when the target client injection is abnormal, so that the code injection process has self-repairing ability, and abnormal prompt and data record are provided, improving the reliability, controllability and operability of the code injection process, and reducing the risk of system unavailability or business interruption caused by injection failure.

[0111] In one embodiment, the method further comprises:

[0112] For each target client, according to the target application identification corresponding to the target client, the configuration permission of the current operation user account is checked, and when the check is passed, the current operation user account is allowed to perform code injection configuration modification operation.

[0113] The current operation user account refers to the operation user identity information initiating the code injection configuration modification request; the configuration permission refers to permission information corresponding to the current operation user account, used to limit whether the current operation user account has the right to modify the code injection configuration of the target client; and the code injection configuration modification operation refers to an operation behavior of adding, deleting, or updating the content of the code injection configuration of the target client.

[0114] In the implementation process, first, the code injection configuration modification request initiated by the current operation user account is acquired, and the target application identifier corresponding to the target client is extracted. Then, by comparing the configuration permission information of the current operation user account with the permission requirement of the target application identifier, the operation qualification of the current operation user account is verified. The verification is used to ensure that only in the case where the permission allows, the operation user can modify the code injection configuration, thereby preventing unauthorized configuration changes.

[0115] In the verification process, whether the current operation user account has the management or modification permission of the corresponding application is determined according to the target application identifier, and the validity and integrity of the permission information are verified. If the verification passes, the current operation user account is allowed to perform the code injection configuration modification operation, the modification request is mapped to the code injection configuration corresponding to the target client, and the configuration content is updated for subsequent injection processes. Through the operation, it is ensured that the code injection configuration of the target client can only be modified by a user with a legal permission, thereby maintaining the security and consistency of the configuration management.

[0116] When the verification fails, the configuration modification request of the current operation user account is rejected, and an operation log is recorded for tracking the permission abnormal operation, preventing unauthorized code injection configuration changes from affecting the system security, and providing an audit basis for the system administrator.

[0117] By verifying the configuration permission of the current operation user account according to the target application identifier and allowing the code injection configuration modification when the verification passes, it is ensured that the modification operation of the code injection configuration is only performed by a user with a legal permission, thereby preventing unauthorized configuration changes from causing injection operation abnormalities or security risks, achieving safe control of the code injection configuration management, and improving the controllability, reliability, and security of the system.

[0118] To facilitate understanding of the scheme of the present application, specific examples are provided below for illustration.

[0119] When the client registers with the center server, each code injection client needs to provide its own identity, associated code repository, supported injection types, and version information. During the registration process, the client sends the above information to the center server through a predefined interface and a secure transmission protocol. The server verifies the integrity and accuracy of the received data to ensure that the registration information has not been tampered with, and authenticates and authorizes the client identity. The implementation of authentication and authorization relies on the strict control mechanism of the injection process, while requiring the client-provided code to meet the configuration item conditions to ensure that only code that meets the pre-set whitelist and audited version is allowed to pass through injection. The packaging and integration level strictly controls the user-submitted code repository, version, and last commit, and new submitted code must pass the Review audit to prevent potential problems or conflicting code from entering the injection process.

[0120] The center server uniformly manages all code injection configurations, including allowed injection code, target applications, and trigger conditions. The configurations are stored in the center server, allowing only whitelisted module code to be injected, and automatically packaging and integrating the latest to-be-injected Agent when the configurations are updated. Each new version of module submission is associated with a unique version number, and when a new application successfully starts and completes injection, the client will call back to notify the center server to confirm the successful injection, realizing version management and state tracking.

[0121] During the automatic packaging process, the center server will pull the code from the user-configured code repository based on the underlying base version, and selectively package the required functional modules for different applications. During the compilation and integration process, the unified base version and interface constraints can avoid most code conflicts, and the interfaces used during development are provided by the unified base. If conflicts are found during compilation, they can be resolved before going online. For gray environment release, the center server uses a batch release strategy, first releasing the new version to some clients and using regression test traffic to verify the function, and then gradually expanding the release range after confirming that there are no problems, so that the formal traffic is gradually switched to the new version, thereby ensuring the safety and stability of injection.

[0122] The center server determines the task distribution strategy and priority based on the configuration information, and by default performs full injection, and for performance-sensitive applications, some modules can be selectively turned off. The client receives the task and executes the injection operation according to the injection instructions in the task to realize code replacement and function upgrade. The injection operation is transparently handled, and manual injection options can be provided for users who do not want to be injected by default. The platform also has an injection failure retry and alarm mechanism to ensure that abnormal situations are handled in a timely manner.

[0123] In the dynamic adjustment of the client function and configuration, the center server supports hot update, suspends the target application traffic first, unloads the original function module, and then injects the latest version of the configuration update into the switch to realize the function replacement without stopping. After the update is completed, the application traffic is restored to ensure the stability of the client and the consistency of the data, and to avoid errors or data loss caused by hot update.

[0124] For permission control, each application domain name is configured with a corresponding responsible person, and the center server relies on the application-responsible person service to realize permission verification. Only the relevant responsible person account is allowed to access and modify the corresponding configuration, so as to ensure the safe and reliable access and modification of the code injection configuration by different users.

[0125] The code injection device provided by the embodiments of the application is described below. The code injection device described below can be referred to in conjunction with the code injection method described above. As shown in Figure 2 The application provides a code injection device, which comprises:

[0126] The target code repository determination module 201 is configured to determine the target client that passes the verification based on the client identifier, the running environment information, and the permission information of each registered client, and determine the target code repository associated with each target client and meeting the preset white list;

[0127] The target injection code acquisition module 202 is configured to acquire the target injection code of each target client from the corresponding target code repository according to the code injection configuration of each target client, and the code injection configuration is used to limit the code range allowed to be injected by different target clients under the corresponding target application or running environment;

[0128] The to-be-injected Agent generation module 203 is configured to compile and integrate each target injection code in a unified running framework to generate a to-be-injected Agent matched with the corresponding target client, and the unified running framework is used to provide consistent code injection execution forms for different target clients;

[0129] The to-be-injected Agent distribution module 204 is configured to distribute each to-be-injected Agent to the corresponding target client, and receive the Agent injection result and running state returned by each target client to confirm the Agent injection state of the corresponding target client.

[0130] In one embodiment, the target code repository determination module 201 comprises:

[0131] The candidate code repository screening unit is configured to screen the candidate code repository associated with each target client from the preset white list according to the client identifier of each target client;

[0132] The target code repository determining unit is configured to check the version identifier and the commit information corresponding to each candidate code in each candidate code repository, and determine a candidate code repository that passes the check as a target code repository.

[0133] In one embodiment, the target injection code obtaining module 202 includes:

[0134] The code injection configuration reading unit is configured to read the preconfigured injection-allowed code type, target application identifier, and applicable running environment identifier in the code injection configuration of each target client.

[0135] The target injection code obtaining unit is configured to filter the target injection code of each target client in the target code repository of each target client according to the corresponding code type identifier, target application identifier, and applicable running environment identifier.

[0136] In one embodiment, the to-be-injected Agent generating module 203 includes:

[0137] The to-be-injected Agent generating unit is configured to compile and integrate each target injection code based on the unified interface specification and dependency constraint rule preset by the unified running framework and in combination with the running environment information of each target client, to generate a to-be-injected Agent matched with the corresponding target client.

[0138] In one embodiment, the to-be-injected Agent distribution module 204 includes:

[0139] The injection instruction generating unit is configured to obtain a preset distribution strategy and generate a corresponding injection instruction for each to-be-injected Agent.

[0140] The to-be-injected Agent distribution unit is configured to distribute each to-be-injected Agent and its injection instruction to the corresponding target client according to the preset distribution strategy, so that each target client resumes the application traffic after pausing the application traffic and switching to the corresponding to-be-injected Agent upon receiving the corresponding injection instruction.

[0141] In one embodiment, the to-be-injected Agent distribution module 204 includes:

[0142] The retry operation triggering module is configured to, for each target client, trigger the target client to perform a retry operation and generate an alarm information to prompt a code injection exception of the target client when it is determined that the target client has an Agent injection failure according to the received Agent injection result and running state.

[0143] In one embodiment, the apparatus further includes:

[0144] The configuration permission checking module is configured to, for each target client, check the configuration permission of a current operation user account according to a target application identifier corresponding to the target client, and allow the current operation user account to perform a code injection configuration modification operation when the checking is passed.

[0145] In one embodiment, the present application further provides a storage medium having computer readable instructions stored therein, which, when executed by one or more processors, cause the one or more processors to perform the steps of the code injection method according to any one of the above embodiments.

[0146] In one embodiment, the present application further provides a computer device having computer readable instructions stored therein, which, when executed by one or more processors, cause the one or more processors to perform the steps of the code injection method according to any one of the above embodiments.

[0147] As shown in Figure 3 , Figure 3 Fig. 3 is a schematic diagram of an internal structure of a computer device according to an embodiment of the present application. The computer device 300 can be provided as a server. As shown in Figure 3 , the computer device 300 includes a processing assembly 302, which further includes one or more processors, and a memory resource represented by a memory 301, for storing instructions executable by the processing assembly 302, such as an application program. The application program stored in the memory 301 can include one or more than one module each corresponding to a set of instructions. In addition, the processing assembly 302 is configured to execute the instructions to perform the code injection method of any of the above embodiments.

[0148] The computer device 300 can further include a power supply assembly 303 configured to perform power management of the computer device 300, a wired or wireless network interface 304 configured to connect the computer device 300 to a network, and an input / output (I / O) interface 305. The computer device 300 can operate based on an operating system stored in the memory 301, such as Windows Server TM, Mac OS X TM, Unix TM, Linux TM, Free BSD TM, or the like.

[0149] Those skilled in the art can understand Figure 3 that the structure shown in the above

[0150] Finally, it should be noted that the terms "first" and "second", and the like, herein do not denote any order, quantity, combination or importance, but are used to identify one element from another, and do not imply that the specific identities thereof are essential or that the identities are chronological or related in their occurrence. Also, the terms "comprises", "comprising", or any other variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but can also include other elements not expressly listed or inherent to such process, method, article, or apparatus. An element proceeded by "comprises... a" does not, without more constraints, exclude the existence of additional identical elements in the process, method, article, or apparatus that comprises the recited element. Also, "a", "an", "the", and "said" are used to refer to one or more than one (i.e., to "at least one") of the referenced elements, unless otherwise specified. A plurality also means two or more, such as 2, 3, 5, or 8, etc. "And / or" includes any and all combinations of one or more of the associated listed items.

[0151] The various embodiments described in this specification are presented by way of example, and are not intended to limit the scope of the application. Each embodiment is presented in a way that emphasizes the differences between the embodiments and the other embodiments, but the embodiments can be combined according to the needs of the user, and the same or similar parts are cross-referenced.

[0152] The above description of disclosed embodiments provides enabling disclosure sufficient for one of ordinary skill in the art to implement or use the application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and generic principles defined herein can be applied to other embodiments without departing from the spirit or scope of the application. Thus, the present application is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A code injection method, characterized in that, The method includes: Based on the client identifier, runtime environment information, and permission information of each registered client, the target client that passes the verification is determined, and the target code repository associated with each target client and conforming to the preset whitelist is determined. Based on the code injection configuration of each target client, the target injection code for each target client is obtained from the corresponding target code repository. The code injection configuration is used to limit the range of code that is allowed to be injected by different target clients in the corresponding target application or runtime environment. Within the unified runtime framework, the injection code for each target is compiled and integrated to generate an Agent to be injected that matches the corresponding target client. The unified runtime framework is used to provide a consistent code injection execution form for different target clients. Each Agent to be injected is distributed to the corresponding target client, and the Agent injection result and running status returned by each target client are received to confirm the Agent injection status of the corresponding target client.

2. The code injection method according to claim 1, characterized in that, The step of determining the target code repository associated with each target client and conforming to the preset whitelist includes: Based on the client identifier of each target client, candidate code repositories associated with each target client are selected from the preset whitelist; The version identifier and commit information corresponding to each candidate code in each candidate code repository are verified, and the candidate code repository that passes the verification is determined as the target code repository.

3. The code injection method according to claim 1, characterized in that, The step of obtaining the target injection code for each target client from the corresponding target code repository according to the code injection configuration of each target client includes: Read the pre-configured allowed code types, target application identifiers, and applicable runtime environment identifiers from the code injection configuration of each target client; In the target code repository of each target client, the target injection code of each target client is filtered according to the corresponding code type identifier, target application identifier, and applicable runtime environment identifier.

4. The code injection method according to claim 1, characterized in that, The step of compiling and integrating the injection code for each target within the unified operating framework to generate an injection agent matching the corresponding target client includes: Based on the unified interface specifications and dependency constraint rules preset by the unified operation framework, and combined with the runtime environment information of each target client, the injection code of each target is compiled and integrated to generate an Agent to be injected that matches the corresponding target client.

5. The code injection method according to claim 1, characterized in that, The step of distributing each Agent to be injected to the corresponding target client includes: Obtain the preset distribution strategy and generate corresponding injection instructions for each Agent to be injected; According to the preset distribution strategy, each Agent to be injected and its injection instruction are distributed to the corresponding target client, so that when each target client receives the corresponding injection instruction, it pauses application traffic, switches to the corresponding Agent to be injected, and then resumes application traffic.

6. The code injection method according to claim 1, characterized in that, After the step of receiving the Agent injection result and running status returned by each target client, the following steps are included: For each target client, when it is determined that the target client has experienced Agent injection failure based on the received Agent injection result and running status, the target client is triggered to retry the operation and an alarm message is generated to indicate that the target client has a code injection exception.

7. The code injection method according to any one of claims 1 to 6, characterized in that, The method further includes: For each target client, the configuration permissions of the current user account are verified based on the target application identifier corresponding to the target client. If the verification is successful, the current user account is allowed to perform code injection and configuration modification operations.

8. A code injection device, characterized in that, The device includes: The target code repository determination module is used to determine the target clients that pass the verification based on the client identifier, runtime environment information and permission information of each registered client, and to determine the target code repositories associated with each target client and that conform to the preset whitelist. The target injection code acquisition module is used to acquire the target injection code of each target client from the corresponding target code repository according to the code injection configuration of each target client. The code injection configuration is used to limit the range of code that is allowed to be injected by different target clients in the corresponding target application or runtime environment. The Agent to be injected module is used to compile and integrate the injection code of each target in a unified running framework to generate an Agent to be injected that matches the corresponding target client. The unified running framework is used to provide a consistent code injection execution form for different target clients. The Agent to be injected distribution module is used to distribute each Agent to be injected to the corresponding target client, and receive the Agent injection result and running status returned by each target client to confirm the Agent injection status of the corresponding target client.

9. A storage medium, characterized in that: The storage medium stores computer-readable instructions that, when executed by one or more processors, cause the one or more processors to perform the steps of the code injection method as described in any one of claims 1 to 7.

10. A computer device, characterized in that, include: One or more processors, and memory; The memory stores computer-readable instructions that, when executed by the one or more processors, perform the steps of the code injection method as described in any one of claims 1 to 7.