Method, apparatus, electronic device and storage medium for interaction inside and outside a virtual machine

By generating serial port simulation devices inside the virtual machine and generating simulation pipelines outside the virtual machine, the stability and scalability problems of data exchange inside and outside the virtual machine are solved, and stable and reliable data transmission is achieved.

CN114816649BActive Publication Date: 2025-07-08QI-ANXIN LEGENDSEC INFORMATION TECH (BEIJING) INC +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110082386.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-01-21
Publication Date
2025-07-08
Estimated Expiration
2041-01-21

AI Technical Summary

Technical Problem

The existing data exchange methods inside and outside virtual machines have problems such as large workload, poor stability and weak scalability, making it difficult to achieve stable and reliable data exchange.

Method used

通过在虚拟机内部生成串口模拟设备,并在外部生成模拟管道,利用硬件虚拟化方式进行数据交互,实现虚拟机内部和外部程序的数据交换。

Benefits of technology

It provides stable, reliable and fast data transmission, avoids the impact on the integrity and stability of the operating system, and improves the efficiency of data exchange inside and outside the virtual machine.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114816649B_ABST
    Figure CN114816649B_ABST
Patent Text Reader

Abstract

An embodiment of the present invention provides a method, apparatus, electronic device, and storage medium for internal and external interaction of virtual machines. The method includes: generating a serial port simulation device inside the virtual machine through hardware virtualization; generating a simulation pipeline outside the virtual machine through hardware virtualization; and performing data interaction between the internal program of the virtual machine and the external program of the virtual machine based on the serial port simulation device and the simulation pipeline. By directly modifying the virtual machine program, the present invention simulates a general serial port on the virtual machine and simulates a pipeline outside the virtual machine, enabling both internal and external programs to achieve data exchange through a general interface. The present invention is implemented based on simulating general hardware, without requiring programmers to modify the internal and external interaction program codes again, without affecting the integrity and stability of the operating system, and capable of achieving stable, reliable, and fast data transmission, thereby providing good support for data exchange inside and outside the virtual machine.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technologies, and in particular, to a method, apparatus, electronic device, and storage medium for interaction between inside and outside of a virtual machine. Background Art

[0002] Data exchange between inside and outside of a virtual machine is one of the main problems that need to be solved by software analysis tools based on virtual machines. Currently, data exchange between inside and outside of a virtual machine mainly includes a data exchange method based on shared memory and a data exchange method based on network (socket).

[0003] The data exchange method based on shared memory is a traditional data exchange solution. Currently, both VMWare virtual machines and VirtualBox virtual machines mainly implement data exchange through shared memory. The method is to install a driver program in the system, and through this driver program, mark a specific memory area of the virtual machine as an exchange area. When external data exchange is required, a corresponding request is sent, and the external data is written into this area, and data reading and writing are realized based on signals. Although this method forms a data exchange framework represented by VMware, it needs to write a dedicated driver program for each different operating system, which is complex and prone to cause system instability or conflict with security software, and problems such as data loss during data transmission and virtual machine freezing often occur. The data exchange based on socket is a currently widely used data transmission method, and currently, data exchange implemented based on virtual machines such as Qemu is realized based on this principle. Its idea is similar to the implementation idea of a Trojan program. A simplified remotely controlled client program is written in the virtual machine, and another control end program is used to communicate with it outside the virtual machine, and the two communicate based on the socket of the virtual machine and the external host. Due to the simulation problem of the virtual machine itself, the socket is often unstable. After disconnection, due to the influence of mechanisms such as network protocol timeout, even if disconnection is detected, it is impossible to achieve fast connection recovery. Therefore, it is very difficult to achieve stable and fast data exchange between inside and outside of a virtual machine based on the network.

[0004] It can be seen that whether it is a data exchange method based on memory mapping or a data exchange method based on network, there are defects such as large workload, difficulty in ensuring efficiency and stability during data connection and transmission processes, poor scalability, and difficulty in achieving agile, stable, and scalable data exchange. Therefore, it is difficult to meet the requirements of stable and reliable data exchange between inside and outside of a virtual machine. Summary of the Invention

[0005] In view of the problems in the prior art, embodiments of the present invention provide a method, apparatus, electronic device, and storage medium for interaction between inside and outside of a virtual machine.

[0006] Specifically, embodiments of the present invention provide the following technical solutions:

[0007] In a first aspect, an embodiment of the present invention provides a method for interacting inside and outside a virtual machine, including:

[0008] Generating a serial port simulation device inside the virtual machine through hardware virtualization;

[0009] Generating a simulation pipeline outside the virtual machine through hardware virtualization;

[0010] Performing data interaction between an internal program of the virtual machine and an external program of the virtual machine based on the serial port simulation device and the simulation pipeline.

[0011] Further, generating a serial port simulation device inside the virtual machine through hardware virtualization specifically includes:

[0012] Generating a general serial port, a receive status register of the general serial port, a transmit status register of the general serial port, and an output buffer inside the virtual machine through hardware virtualization.

[0013] Further, generating a simulation pipeline outside the virtual machine through hardware virtualization specifically includes:

[0014] Generating an input simulation pipeline, an output simulation pipeline, and an input buffer outside the virtual machine through hardware virtualization.

[0015] Further, performing data interaction between an internal program of the virtual machine and an external program of the virtual machine based on the serial port simulation device and the simulation pipeline specifically includes:

[0016] When the internal program of the virtual machine sends a first data to the external program of the virtual machine, sending the first data to the output buffer based on the general serial port and the transmit status register, and performing data verification in the output buffer. If the verification passes, modifying the pipeline state of the output simulation pipeline so that the external program of the virtual machine receives the first data;

[0017] And / or,

[0018] When the external program of the virtual machine sends a second data to the internal program of the virtual machine, sending the second data to the input buffer based on the input simulation pipeline, and performing data verification in the input buffer. If the verification passes, modifying the state of the receive status register so that the internal program of the virtual machine receives the second data.

[0019] Further, when the internal program of the virtual machine sends the first data to the external program of the virtual machine, the first data is sent to the output buffer based on the general serial port and the send status register, and data verification is performed in the output buffer. If the verification passes, the pipeline state of the output simulation pipeline is modified so that the external program of the virtual machine can receive the first data. Specifically, it includes:

[0020] When the internal program of the virtual machine sends the first data to the external program of the virtual machine, the first data, the length information of the first data, and the checksum information are sent to the output buffer based on the general serial port and the send status register, and length and checksum verification are performed in the output buffer. If the verification passes, the pipeline state of the output simulation pipeline is modified so that the external program of the virtual machine can receive the first data; wherein, the output buffer verifies whether the response flag is successful during the process of receiving the first data and stops receiving the first data when detecting the end-of-data-fragmentation flag.

[0021] Further, the output simulation pipeline and the input simulation pipeline are opened by the external communication program of the virtual machine in a file interface manner.

[0022] Further, modifying the pipeline state of the output simulation pipeline so that the external program of the virtual machine can receive the first data includes:

[0023] Modifying the file handle state corresponding to the output simulation pipeline so that the external program of the virtual machine can actively read the first data.

[0024] Further, when the external program of the virtual machine sends the second data to the internal program of the virtual machine, the second data is sent to the input buffer based on the input simulation pipeline, and data verification is performed in the input buffer. If the verification passes, the state of the receive status register is modified so that the internal program of the virtual machine can receive the second data. Specifically, it includes:

[0025] When the external program of the virtual machine sends the second data to the internal program of the virtual machine, the second data, the length information of the second data, and the checksum information are sent to the input buffer based on the input simulation pipeline, and length and checksum verification are performed in the input buffer. If the verification passes, the state of the receive status register is modified so that the internal program of the virtual machine can receive the second data; wherein, the input buffer verifies whether the response flag is successful during the process of receiving the second data and stops receiving the second data when detecting the end-of-data-fragmentation flag.

[0026] Further, generating a general serial port, a receive status register of the general serial port, a transmit status register of the general serial port, and an output buffer inside the virtual machine through hardware virtualization specifically includes:

[0027] Generating a general serial port, a receive status register of the general serial port, a transmit status register of the general serial port, and an output buffer inside the virtual machine by modifying the serial port simulation code of the virtual machine.

[0028] Further, generating an input simulation pipeline, an output simulation pipeline, and an input buffer outside the virtual machine through hardware virtualization specifically includes:

[0029] Constructing an input simulation pipeline and an output simulation pipeline outside the virtual machine, and setting an input buffer, pipeline data notification information, and a callback function for data transmission and reception using an interface defined by the operating system.

[0030] In a second aspect, an embodiment of the present invention further provides a virtual machine internal and external interaction device, including:

[0031] A first generation module, configured to generate a serial port simulation device inside the virtual machine through hardware virtualization;

[0032] A second generation module, configured to generate a simulation pipeline outside the virtual machine through hardware virtualization;

[0033] An interaction processing module, configured to perform data interaction between an internal program of the virtual machine and an external program of the virtual machine based on the serial port simulation device and the simulation pipeline.

[0034] In a third aspect, an embodiment of the present invention further provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, the steps of the virtual machine internal and external interaction method described in the first aspect are implemented.

[0035] In a fourth aspect, an embodiment of the present invention further provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the virtual machine internal and external interaction method described in the first aspect are implemented.

[0036] In a fifth aspect, an embodiment of the present invention further provides a computer program product, the computer program product including a computer program. When the computer program is executed by a processor, the steps of the virtual machine internal and external interaction method described in the first aspect are implemented.

[0037] As can be seen from the above technical solutions, the method, device, electronic device, and storage medium for internal and external interaction of virtual machines provided by the embodiments of the present invention generate a serial port simulation device inside the virtual machine through hardware virtualization, generate a simulation pipeline outside the virtual machine through hardware virtualization, and then perform data interaction between the internal program of the virtual machine and the external program of the virtual machine based on the serial port simulation device and the simulation pipeline. It can be seen that the embodiments of the present invention simulate a general serial port on the virtual machine by directly modifying the virtual machine program and simulate a pipeline outside the virtual machine, enabling both internal and external programs to achieve data exchange through a general interface. Therefore, the embodiments of the present invention are implemented based on simulating general hardware, without requiring programmers to modify the internal and external interaction program codes again, without affecting the integrity and stability of the operating system, and capable of achieving stable, reliable, and fast data transmission, thus being able to provide good support for data exchange inside and outside the virtual machine. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0039] Figure 1 It is a flowchart of the method for internal and external interaction of virtual machines provided by an embodiment of the present invention;

[0040] Figure 2 It is a schematic diagram of the principle of the method for internal and external interaction of virtual machines provided by an embodiment of the present invention;

[0041] Figure 3 It is a schematic diagram of the process of the internal program of the virtual machine initiating a data sending request provided by an embodiment of the present invention;

[0042] Figure 4 It is a schematic diagram of the process of the external program of the virtual machine initiating a data sending request provided by an embodiment of the present invention;

[0043] Figure 5 It is a schematic diagram of the structure of the device for internal and external interaction of virtual machines provided by an embodiment of the present invention;

[0044] Figure 6 It is a schematic diagram of the structure of the electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0045] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.

[0046] It should be noted that in view of the limited communication methods between the inside and outside of the current virtual machine, it is necessary to write interaction drivers for each monitored operating system one by one, the communication interface is unstable, and it is difficult to exchange data between the inside and outside of the virtual machine. By adding new communication hardware to the virtual machine hardware simulation method and implementing the corresponding communication method of the virtual machine hardware, the purpose of realizing data interaction between the inside and outside of the virtual machine through the communication hardware is achieved. Based on this technology, a set of data interaction interfaces is implemented, and the corresponding communication module is developed to realize stable and reliable data interaction between the virtual machine and the external host program. The data transmission stability and reliability of the program analysis system based on virtualization are greatly improved. The following will explain and illustrate the solution provided by the present invention in detail through specific embodiments.

[0047] Figure 1 The flowchart of the method for interaction between the inside and outside of the virtual machine provided by the embodiment of the present invention is shown. As Figure 1 shown, the method for interaction between the inside and outside of the virtual machine provided by the embodiment of the present invention includes the following steps:

[0048] Generate a serial port simulation device inside the virtual machine through hardware virtualization;

[0049] Generate a simulation pipeline outside the virtual machine through hardware virtualization;

[0050] Based on the serial port simulation device and the simulation pipeline, perform data interaction between the program inside the virtual machine and the program outside the virtual machine.

[0051] In this embodiment, it should be noted that for the existing data exchange technology based on memory mapping or network implementation, it is necessary to write interaction drivers for each monitored operating system one by one, and the stability is poor, and it is difficult to achieve scalable and stable data interaction. This embodiment provides a data exchange method based on virtualized hardware. This method directly modifies the virtual machine program, simulates a general serial port on the virtual machine, and simulates a pipeline outside the virtual machine, so that both internal and external programs can achieve data exchange through a general interface.

[0052] In this embodiment, inside the virtual machine, a serial port device is simulated through hardware virtualization technology. Outside the virtual machine, data is input and output by connecting to the simulated serial port device of the virtual machine, so as to achieve fast and stable data transmission.

[0053] It can be understood that to simulate a serial port device inside the virtual machine in this embodiment, the way that can be adopted is to modify the serial port simulation code of the virtual machine and add a serial port device in the virtual machine's simulated hardware. For example, the main content to be modified may include: the input and output hardware buffers of the serial port, the status register of the serial port, and relevant settings such as the word length, baud rate, parity bit, and data control bit of the serial port data transmission. In addition, it can be understood that this embodiment modifies the serial port status register of the virtual machine. During a single data transmission process, information such as the simulated word length, baud rate, parity bit, and data control bit can be used. When the host inside the virtual machine uses this configuration to set the serial port, the virtual machine can identify this serial port as a data communication serial port. This embodiment realizes data transmission through a buffer. When the serial port is transmitting, when the data fragment end marker in the communication protocol is not received, the data reception state is maintained, and new data is continuously received. When the data fragment end marker is detected, the state of the serial port register is modified to mark that there is data to be received in the serial port, and the internal communication program of the virtual machine performs reading and writing.

[0054] In this embodiment, when generating a simulated pipeline through hardware virtualization outside the virtual machine, the way that can be adopted is to utilize the pipeline creation function provided by the operating system, such as the pipe() function in the Linux system, to construct a virtual pipeline, and then use the interfaces defined by the operating system to set functions such as the buffer used by the virtual pipeline, the pipeline data notification information, and the callback functions for data sending and receiving, so as to enable data interaction between the internal program and the external program of the virtual machine based on the serial port simulation device and the simulated pipeline.

[0055] As can be seen from the above technical solutions, the method for internal and external interaction of the virtual machine provided by the embodiment of the present invention generates a serial port simulation device through hardware virtualization inside the virtual machine and generates a simulated pipeline through hardware virtualization outside the virtual machine, and then performs data interaction between the internal program and the external program of the virtual machine based on the serial port simulation device and the simulated pipeline. Thus, it can be seen that the embodiment of the present invention directly modifies the virtual machine program to simulate a general serial port on the virtual machine and simulate a pipeline outside the virtual machine, enabling both internal and external programs to achieve data exchange through a general interface. Therefore, it can be seen that the embodiment of the present invention is based on simulating general hardware, without the need for programmers to modify the internal and external interaction program codes again, without affecting the integrity and stability of the operating system, and can achieve stable, reliable, and fast data transmission, thus being able to provide good support for data exchange inside and outside the virtual machine.

[0056] Based on the content of the above embodiments, in this embodiment, a serial port simulation device is generated inside the virtual machine through hardware virtualization, specifically including: generating a general serial port, a receive status register of the general serial port, a transmit status register of the general serial port, and an output buffer inside the virtual machine through hardware virtualization.

[0057] An analog pipeline is generated outside the virtual machine through hardware virtualization, specifically including: generating an input analog pipeline, an output analog pipeline, and an input buffer outside the virtual machine through hardware virtualization.

[0058] In this embodiment, the input buffer and output buffer of the virtual serial port are independent of each other. While realizing duplex communication, it can avoid interference between the input and output of the serial port.

[0059] In this embodiment, the input pipeline and output pipeline are separated, and the two pipelines are not shared, avoiding interference between the data transmitted in and out of the pipelines.

[0060] In this embodiment, the receive status register and transmit status register are simulated. During the process of specific data communication, the status of the serial port register of the virtual machine can be modified to control data transmission. During a single data transmission, information such as the simulated word length, baud rate, parity bit, and data control bit is used. When the host inside the virtual machine uses this configuration to set the serial port, the virtual machine can identify this serial port as a data communication serial port.

[0061] In addition, this embodiment realizes data transmission through a buffer. When the serial port is transmitting, when the data fragment end marker in the communication protocol is not received, the data reception status is maintained, and new data is continuously received. When the data fragment end marker is detected, the status of the serial port register is modified to mark that there is data to be received in the serial port, and it is read and written by the internal communication program of the virtual machine.

[0062] Based on the content of the above embodiments, in this embodiment, data interaction between the internal program of the virtual machine and the external program of the virtual machine is performed based on the serial port simulation device and the analog pipeline, specifically including:

[0063] When the internal program of the virtual machine sends the first data to the external program of the virtual machine, the first data is sent to the output buffer based on the general serial port and the transmit status register, and data verification is performed in the output buffer. If the verification passes, the pipeline status of the output analog pipeline is modified so that the external program of the virtual machine can receive the first data;

[0064] and / or,

[0065] When an external virtual machine program sends second data to an internal virtual machine program, the second data is sent to the input buffer based on the input simulation pipeline, and data verification is performed in the input buffer. If the verification passes, the state of the receive status register is modified so that the internal virtual machine program can receive the second data.

[0066] In this embodiment, after the buffer receives and verifies the data, the status register is actively changed to notify the internal communication program of the virtual machine, and the internal communication program realizes program sending and receiving. In this embodiment, the serial port simulated inside the virtual machine has different serial port registers and transceiver buffers from the physical hardware. The serial port register does not represent the real-time state of the current serial port hardware, but represents the data transfer state of the serial port transceiver buffer, and its method is different from the existing serial port simulation method.

[0067] In this embodiment, the transceiver buffer simulated in the serial port has functions such as data length matching, checksum calculation, and end marker detection. This function corresponds to the transmission protocol, while traditional serial port simulation does not have this mechanism.

[0068] In this embodiment, the state change of the simulation pipeline is not actively notified to the external communication program, but the external communication program detects the pipeline state by itself to implement data sending and receiving. This method avoids the problem of how to reliably transmit the notification message to the external communication program brought by the active notification mode.

[0069] It can be seen that this embodiment is implemented based on simulating general hardware, without the need for program developers to modify the internal and external interaction program codes again, and does not affect the integrity and stability of the operating system; by modifying the transmission protocol and detecting the integrity and effectiveness of the transmission process therein, stable and fast data transmission is achieved. This technical solution can provide good support for data exchange inside and outside the virtual machine.

[0070] Based on the content of the above embodiment, in this embodiment, when an internal virtual machine program sends first data to an external virtual machine program, the first data is sent to the output buffer based on the general serial port and the send status register, and data verification is performed in the output buffer. If the verification passes, the pipeline state of the output simulation pipeline is modified so that the external virtual machine program can receive the first data, specifically including:

[0071] When the internal program of the virtual machine sends the first data to the external program of the virtual machine, the first data, the length information of the first data, and the checksum information are sent to the output buffer based on the general serial port and the sending status register, and the length and checksum are verified in the output buffer. If the verification passes, the pipeline state of the output analog pipeline is modified so that the external program of the virtual machine can receive the first data; wherein, the output buffer verifies whether the response flag is successful during the process of receiving the first data and stops receiving the first data when detecting the data fragmentation end flag;

[0072] When the external program of the virtual machine sends the second data to the internal program of the virtual machine, the second data is sent to the input buffer based on the input analog pipeline, and data verification is performed in the input buffer. If the verification passes, the state of the receiving status register is modified so that the internal program of the virtual machine can receive the second data, specifically including:

[0073] When the external program of the virtual machine sends the second data to the internal program of the virtual machine, the second data, the length information of the second data, and the checksum information are sent to the input buffer based on the input analog pipeline, and the length and checksum are verified in the input buffer. If the verification passes, the state of the receiving status register is modified so that the internal program of the virtual machine can receive the second data; wherein, the input buffer verifies whether the response flag is successful during the process of receiving the second data and stops receiving the second data when detecting the data fragmentation end flag.

[0074] In this embodiment, the transceiver buffer simulated in the serial port has functions such as data length matching, checksum calculation, and end flag detection, and this function corresponds to the transmission protocol. Traditional serial port simulation does not have this mechanism. In this embodiment, the virtual machine program implements fast transmission under the condition of confirming data integrity. The solution for implementing fast transmission under the condition of confirming data integrity in this embodiment is: when formulating the data transmission protocol, in addition to the data check bits defined by the serial port, the length of data fragmentation, the end flag, the checksum, and the success / failure response flag are additionally defined. During each data fragmentation transmission process, it is detected whether the data fragmentation length is accurately received, whether the end flag is correct, and whether the checksum is correct, and according to the success and failure and response rules, the data receiving end responds to the data sending end, effectively ensuring the accuracy of data transmission.

[0075] In this embodiment, the data transmission protocol inside the virtual machine is modified to implement a data transmission method with fault tolerance and detection capabilities, which has the capabilities of stable and fast data transmission and good scalability. In this embodiment, the serial port status register of the virtual machine is modified. During the process of single data transmission, information such as the simulated word length, baud rate, parity bit, and data control bit is used. When the host inside the virtual machine sets the serial port using this configuration, the virtual machine can identify that this serial port is a data communication serial port. In this embodiment, data transmission is achieved through a buffer. When transmitting through the serial port, when the data fragment end marker in the communication protocol is not received, the data reception state is maintained and new data is continuously received. When the data fragment end marker is detected, the status of the serial port register is modified to mark that there is data to be received in the serial port, and the internal communication program inside the virtual machine performs reading and writing.

[0076] See Figure 2 the schematic diagram shown, where the simulated serial port hardware and simulated pipeline are implemented in the virtual machine program, and the internal communication program and external communication program inside the virtual machine are independent data transceiver programs. The receive status register and transmit status register of the serial port simulation hardware are both simulated and are not consistent with the actual transceiver status. Only after the data reception is completed, stored in the buffer and verified, will the status register be changed to prompt the internal communication program to perform transceiver operations. The external simulated pipeline is also based on simulation. By setting the pipeline buffer in the program, when the data reception is completed, stored in the buffer, and the data verification is completed, the corresponding data will be sent to the pipeline.

[0077] Figure 3 shows the process of the internal program inside the virtual machine initiating a data transmission request. Figure 4 shows the process of the external program outside the virtual machine initiating a data transmission request.

[0078] As Figure 3 shown, when the internal program inside the virtual machine initiates a transmission request, first, the buffer of the virtual serial port receives the data length and checksum information, and then the data to be transmitted is saved into the buffer. During the saving process, the data marker is continuously detected. If the end marker can be detected, the subsequent input data will be discarded. Then, the length calculation starts for the data that has been received currently. If the length is consistent, the checksum of this part of the data is calculated. If the checksum is the same as that during the transmission process, it is considered that the data reception is correct, and the pipeline status is modified, and the corresponding data is received by the external program.

[0079] As Figure 4As shown, when a program outside the virtual machine initiates a send request, first, the buffer of the virtual pipeline receives the data length and checksum information, and then saves the data to be transmitted into the buffer. During the saving process, the data marker is continuously detected. If the end marker can be detected, the subsequent input data is discarded. Then, the length calculation starts for the data that has been received. If the length is correct, the checksum of this part of the data is calculated. If the checksum is consistent with that during the transmission process, it is considered that the data is received correctly, and the status of the internal virtual serial port register is modified, and the corresponding data is received by the internal program.

[0080] In this embodiment, a serial port simulation device is generated inside the virtual machine through hardware virtualization, and a simulation pipeline is generated outside the virtual machine through hardware virtualization. Then, data interaction between the internal program and the external program of the virtual machine is carried out based on the serial port simulation device and the simulation pipeline. It can be seen that in the embodiment of the present invention, by directly modifying the virtual machine program, a general serial port is simulated on the virtual machine, and a pipeline is simulated outside the virtual machine, so that both the internal and external programs can achieve data exchange through a general interface. It can be seen that the embodiment of the present invention is implemented based on simulating general hardware, without the need for programmers to modify the internal and external interaction program codes again, and does not affect the integrity and stability of the operating system; by modifying the transmission protocol and detecting the integrity and effectiveness of the transmission process therein, stable and fast data transmission is achieved. This technical solution can provide good support for data exchange inside and outside the virtual machine.

[0081] Based on the content of the above embodiment, in this embodiment, the output simulation pipeline and the input simulation pipeline are opened by the communication program outside the virtual machine using the file interface method.

[0082] In this embodiment, the output simulation pipeline and the input simulation pipeline are opened by the communication program outside the virtual machine using the file interface method, so that the external communication program can directly open the input pipeline and the output pipeline in the form of files without special settings, reducing the complexity of system design.

[0083] Based on the content of the above embodiment, in this embodiment, modifying the pipeline state of the output simulation pipeline so that the external program of the virtual machine receives the first data includes:

[0084] Modifying the status of the file handle corresponding to the output simulation pipeline so that the external program of the virtual machine actively reads the first data.

[0085] In this embodiment, when the virtual machine internal communication program sends data to the virtual machine external communication program, data transmission is achieved through a buffer. When transmitting through a pipe, the end marker of data transmission in the protocol is also detected. When the end marker of data fragmentation in the communication protocol is not received, the data receiving state is maintained, and new data is continuously received. When the end marker of data fragmentation is detected, the status of the virtual file handle is modified to mark that there is data to be received in the pipe, and the virtual machine external communication program performs reading and writing.

[0086] It should be noted that the simulated pipe in this embodiment provides data transmission and detection of the presence or absence of data in the form of a file status. By simulating the file kernel object data in the operating system, the change and representation of the status are achieved. In the simulated pipe in this embodiment of China, its status change does not actively notify the external communication program, and the external communication program detects the pipe status by itself to implement data sending and receiving.

[0087] It should be noted that the solution for implementing fast transmission by the virtual machine program described in this embodiment under the condition of confirming data integrity is as follows: When formulating the data transmission protocol, in addition to the data check bits defined by the serial port, the length of data fragmentation, end marker, checksum, and success / failure response marker are also defined. During each data fragmentation transmission process, it is detected whether the length of data fragmentation is accurately received, whether the end marker is correct, and whether the checksum is correct. According to the success and failure and response rules, the data receiving end responds to the data sending end, effectively ensuring the accuracy of data transmission.

[0088] Based on the content of the above embodiment, in this embodiment, generating a general-purpose serial port, a receive status register of the general-purpose serial port, a transmit status register of the general-purpose serial port, and an output buffer inside the virtual machine through hardware virtualization specifically includes:

[0089] Inside the virtual machine, a general-purpose serial port, a receive status register of the general-purpose serial port, a transmit status register of the general-purpose serial port, and an output buffer are generated by modifying the serial port simulation code of the virtual machine.

[0090] In this embodiment, a general-purpose serial port, a receive status register of the general-purpose serial port, a transmit status register of the general-purpose serial port, and an output buffer can be generated by modifying the serial port simulation code of the virtual machine. For example, the main modified contents can include: the input and output hardware buffers of the serial port, the status register of the serial port, and related settings such as the word length, baud rate, parity bit, and data control bit of serial port data transmission. It can be understood that in this embodiment, the serial port status register of the virtual machine is modified. During a single data transmission process, information such as the simulated word length, baud rate, parity bit, and data control bit is used. When the host inside the virtual machine sets the serial port using this configuration, the virtual machine can identify that this serial port is a data communication serial port.

[0091] Based on the content of the above embodiments, in this embodiment, generating an input simulation pipeline, an output simulation pipeline, and an input buffer in a hardware virtualization manner outside the virtual machine specifically includes:

[0092] Construct an input simulation pipeline and an output simulation pipeline outside the virtual machine, and use the interfaces defined by the operating system to set the input buffer, pipeline data notification information, and callback functions for data sending and receiving.

[0093] In this embodiment, when constructing the input simulation pipeline and the output simulation pipeline outside the virtual machine, the method used is to construct a virtual pipeline, and use the interfaces defined by the operating system to set the buffer used by the virtual pipeline, pipeline data notification information, and callback functions for data sending and receiving, so as to cooperate with the serial port simulation device inside the virtual machine to complete the data sending and receiving functions.

[0094] It should be noted that the embodiments of the present invention are directed to the problems of the existing data exchange technology based on memory mapping or network implementation, which requires writing interaction drivers for each monitored operating system one by one, and has poor stability and is difficult to achieve scalable and stable data interaction. A data exchange method based on virtualized hardware is provided. The embodiments of the present invention directly modify the virtual machine program, simulate a general serial port on the virtual machine, and simulate a bidirectional pipeline outside the virtual machine, so that both internal and external programs can implement data exchange through a general interface; modify the data transmission protocol inside the virtual machine, and implement a data transmission method with fault tolerance and detection capabilities, with the capabilities of stable and fast data transmission, and good scalability.

[0095] Figure 5 The structure diagram of the virtual machine internal and external interaction device provided by the embodiments of the present invention is shown. As Figure 5 shown, the virtual machine internal and external interaction device provided in this embodiment includes: a first generation module 21, a second generation module 22, and an interaction processing module 23, where:

[0096] The first generation module 21 is used to generate a serial port simulation device inside the virtual machine through a hardware virtualization manner;

[0097] The second generation module 22 is used to generate a simulation pipeline outside the virtual machine through a hardware virtualization manner;

[0098] The interaction processing module 23 is used to perform data interaction between the internal program of the virtual machine and the external program of the virtual machine based on the serial port simulation device and the simulation pipeline.

[0099] Based on the content of the above embodiments, in this embodiment, the first generation module 21 is specifically used for:

[0100] Inside the virtual machine, a general - purpose serial port, a receive status register of the general - purpose serial port, a transmit status register of the general - purpose serial port, and an output buffer are generated through hardware virtualization.

[0101] Based on the content of the above - mentioned embodiment, in this embodiment, the second generation module 22 is specifically used for:

[0102] Outside the virtual machine, an input simulation pipeline, an output simulation pipeline, and an input buffer are generated through hardware virtualization.

[0103] Based on the content of the above - mentioned embodiment, in this embodiment, the interaction processing module 23 is specifically used for:

[0104] When the program inside the virtual machine sends the first data to the program outside the virtual machine, based on the general - purpose serial port and the transmit status register, the first data is sent to the output buffer, and data verification is performed in the output buffer. If the verification passes, the pipeline state of the output simulation pipeline is modified so that the program outside the virtual machine can receive the first data;

[0105] and / or,

[0106] When the program outside the virtual machine sends the second data to the program inside the virtual machine, based on the input simulation pipeline, the second data is sent to the input buffer, and data verification is performed in the input buffer. If the verification passes, the state of the receive status register is modified so that the program inside the virtual machine can receive the second data.

[0107] Based on the content of the above - mentioned embodiment, in this embodiment, when the program inside the virtual machine sends the first data to the program outside the virtual machine, based on the general - purpose serial port and the transmit status register, the first data is sent to the output buffer, and data verification is performed in the output buffer. If the verification passes, the pipeline state of the output simulation pipeline is modified so that the program outside the virtual machine can receive the first data, which specifically includes:

[0108] When the program inside the virtual machine sends the first data to the program outside the virtual machine, based on the general - purpose serial port and the transmit status register, the first data, the length information of the first data, and the checksum information are sent to the output buffer, and length and checksum verification are performed in the output buffer. If the verification passes, the pipeline state of the output simulation pipeline is modified so that the program outside the virtual machine can receive the first data; wherein, the output buffer verifies whether the response mark is successful during the process of receiving the first data and stops receiving the first data when detecting the end - of - data - fragmentation mark.

[0109] Based on the content of the above embodiments, in this embodiment, the output simulation pipeline and the input simulation pipeline are opened by the communication program outside the virtual machine in a file interface manner.

[0110] Based on the content of the above embodiments, in this embodiment, modifying the pipeline state of the output simulation pipeline so that the external program of the virtual machine receives the first data includes:

[0111] Modifying the file handle state corresponding to the output simulation pipeline so that the external program of the virtual machine actively reads the first data.

[0112] Based on the content of the above embodiments, in this embodiment, when the external program of the virtual machine sends the second data to the internal program of the virtual machine, the second data is sent to the input buffer based on the input simulation pipeline, and data verification is performed in the input buffer. If the verification passes, the state of the receive status register is modified so that the internal program of the virtual machine receives the second data. Specifically, it includes:

[0113] When the external program of the virtual machine sends the second data to the internal program of the virtual machine, the second data, the length information of the second data, and the checksum information are sent to the input buffer based on the input simulation pipeline, and length and checksum verification are performed in the input buffer. If the verification passes, the state of the receive status register is modified so that the internal program of the virtual machine receives the second data; wherein, the input buffer verifies the success or failure of the response mark during the process of receiving the second data and stops receiving the second data when detecting the end mark of data fragmentation.

[0114] Based on the content of the above embodiments, in this embodiment, generating a general serial port, a receive status register of the general serial port, a transmit status register of the general serial port, and an output buffer through hardware virtualization inside the virtual machine specifically includes:

[0115] Generating a general serial port, a receive status register of the general serial port, a transmit status register of the general serial port, and an output buffer by modifying the serial port simulation code of the virtual machine inside the virtual machine.

[0116] Based on the content of the above embodiments, in this embodiment, generating an input simulation pipeline, an output simulation pipeline, and an input buffer through hardware virtualization outside the virtual machine specifically includes:

[0117] Constructing an input simulation pipeline and an output simulation pipeline outside the virtual machine, and setting an input buffer, pipeline data notification information, and a callback function for data transmission and reception using an interface defined by the operating system.

[0118] In this embodiment, aiming at the problems of limited communication methods between the inside and outside of the current virtual machine, unstable communication interfaces, and difficult data exchange between the inside and outside of the virtual machine, a new communication hardware is added to the virtual machine hardware simulation method, and the corresponding data acquisition method of the virtual machine hardware and the communication method of the virtual machine hardware are implemented, so as to achieve the purpose of realizing data interaction between the inside and outside of the virtual machine by using the communication hardware. Based on this technology, a set of data interaction interfaces is implemented, and the corresponding communication module is developed to realize stable and reliable data interaction between the virtual machine and the external host program, greatly improving the data transmission stability and reliability of the program analysis system based on virtualization.

[0119] Since the virtual machine internal and external interaction device provided in the embodiment of the present invention can be used to execute the virtual machine internal and external interaction method described in the above embodiment, and its working principle and beneficial effects are similar, they will not be elaborated here. For specific content, please refer to the introduction of the above embodiment.

[0120] In this embodiment, it should be noted that the various modules in the device of the embodiment of the present invention can be integrated into one body or separated and deployed. The above modules can be combined into one module or further split into multiple sub-modules.

[0121] Based on the same inventive concept, another embodiment of the present invention provides an electronic device, see Figure 6 , the electronic device specifically includes the following: a processor 301, a memory 302, a communication interface 303, and a communication bus 304;

[0122] Among them, the processor 301, the memory 302, and the communication interface 303 complete mutual communication through the communication bus 304;

[0123] The processor 301 is used to call the computer program in the memory 302. When the processor executes the computer program, all steps of the above virtual machine internal and external interaction method are implemented. For example, when the processor executes the computer program, the following process is implemented: a serial port simulation device is generated inside the virtual machine through hardware virtualization; a simulation pipeline is generated outside the virtual machine through hardware virtualization; data interaction between the internal program of the virtual machine and the external program of the virtual machine is performed based on the serial port simulation device and the simulation pipeline.

[0124] It can be understood that the refined functions and extended functions that the computer program can execute can refer to the description of the above embodiment.

[0125] Based on the same inventive concept, another embodiment of the present invention provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, all steps of the above-mentioned method for internal and external interaction of virtual machines are implemented. For example, when the processor executes the computer program, the following process is implemented: generating a serial port simulation device inside the virtual machine through hardware virtualization; generating a simulation pipeline outside the virtual machine through hardware virtualization; and performing data interaction between the internal program of the virtual machine and the external program of the virtual machine based on the serial port simulation device and the simulation pipeline.

[0126] It can be understood that the refined functions and extended functions that the computer program can execute can refer to the description of the above embodiments.

[0127] Based on the same inventive concept, another embodiment of the present invention provides a computer program product, which includes a computer program. When the computer program is executed by a processor, all steps of the above-mentioned method for controlling the startup of associated applications are implemented. For example, when the processor executes the computer program, the following process is implemented: generating a serial port simulation device inside the virtual machine through hardware virtualization; generating a simulation pipeline outside the virtual machine through hardware virtualization; and performing data interaction between the internal program of the virtual machine and the external program of the virtual machine based on the serial port simulation device and the simulation pipeline.

[0128] It can be understood that the refined functions and extended functions that the computer program can execute can refer to the description of the above embodiments.

[0129] In addition, when the logical instructions in the above-mentioned memory are implemented in the form of software functional units and sold or used as an independent product, they can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), magnetic disks, or optical discs that can store program codes.

[0130] The device embodiments described above are merely illustrative. 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 to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of the embodiments of the present invention. A person of ordinary skill in the art can understand and implement it without creative effort.

[0131] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on such an understanding, the essence of the above technical solution, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the virtual machine internal and external interaction methods described in each embodiment or some parts of the embodiments.

[0132] In addition, in the present invention, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or also includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "including a..." does not exclude the existence of another identical element in the process, method, article or device including the said element.

[0133] In addition, in the present invention, the description with reference to terms such as "an embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described can be combined in a suitable manner in any one or more embodiments or examples. In addition, without contradiction, those skilled in the art can combine and combine the different embodiments or examples described in this specification and the features of different embodiments or examples.

[0134] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for interaction between a virtual machine and the outside, characterized in that Including: Generating a serial port simulation device inside the virtual machine through hardware virtualization; Generating a simulation pipeline outside the virtual machine through hardware virtualization; Based on the serial port simulation device and the simulation pipeline, performing data interaction between the program inside the virtual machine and the program outside the virtual machine; Generating a serial port simulation device inside the virtual machine through hardware virtualization, specifically including: Generating a general serial port, a receive status register of the general serial port, a transmit status register of the general serial port, and an output buffer inside the virtual machine through hardware virtualization; Generating a simulation pipeline outside the virtual machine through hardware virtualization, specifically including: Generating an input simulation pipeline, an output simulation pipeline, and an input buffer outside the virtual machine through hardware virtualization; Based on the serial port simulation device and the simulation pipeline, performing data interaction between the program inside the virtual machine and the program outside the virtual machine, specifically including: When the program inside the virtual machine sends the first data to the program outside the virtual machine, based on the general serial port and the transmit status register, sending the first data to the output buffer, and performing data verification in the output buffer. If the verification passes, modifying the pipeline state of the output simulation pipeline so that the program outside the virtual machine can receive the first data; And / or When the program outside the virtual machine sends the second data to the program inside the virtual machine, based on the input simulation pipeline, sending the second data to the input buffer, and performing data verification in the input buffer. If the verification passes, modifying the state of the receive status register so that the program inside the virtual machine can receive the second data.

2. The virtual machine internal and external interaction method according to claim 1, wherein When the program inside the virtual machine sends the first data to the program outside the virtual machine, based on the general serial port and the transmit status register, sending the first data to the output buffer, and performing data verification in the output buffer. If the verification passes, modifying the pipeline state of the output simulation pipeline so that the program outside the virtual machine can receive the first data, specifically including: When the program inside the virtual machine sends the first data to the program outside the virtual machine, based on the general serial port and the transmit status register, sending the first data, the length information of the first data, and the checksum information to the output buffer, and performing length and checksum verification in the output buffer. If the verification passes, modifying the pipeline state of the output simulation pipeline so that the program outside the virtual machine can receive the first data; wherein, the output buffer verifies whether the response mark is successful during the process of receiving the first data and stops receiving the first data when detecting the end mark of data fragmentation.

3. The virtual machine internal and external interaction method according to claim 2, characterized in that The output simulation pipeline and the input simulation pipeline are opened by the communication program outside the virtual machine using the file interface method.

4. The method for interaction between inside and outside of a virtual machine according to claim 3, wherein Modifying the pipeline state of the output simulation pipeline so that the program outside the virtual machine can receive the first data includes: Modifying the file handle state corresponding to the output simulation pipeline so that the program outside the virtual machine can actively read the first data.

5. The virtual machine internal and external interaction method according to claim 1, characterized in that When a virtual machine external program sends second data to a virtual machine internal program, the second data is sent to the input buffer based on the input simulation pipeline, and data verification is performed in the input buffer. If the verification passes, the state of the receive status register is modified so that the virtual machine internal program can receive the second data. Specifically, it includes: When a virtual machine external program sends second data to a virtual machine internal program, the second data, the length information of the second data, and the checksum information are sent to the input buffer based on the input simulation pipeline, and length and checksum verification are performed in the input buffer. If the verification passes, the state of the receive status register is modified so that the virtual machine internal program can receive the second data; wherein, during the process of receiving the second data, the input buffer verifies whether the response mark is successful and stops receiving the second data when detecting the data fragmentation end mark.

6. The method for interaction between inside and outside of a virtual machine according to claim 1, wherein The generation of a general serial port, a receive status register of the general serial port, a transmit status register of the general serial port, and an output buffer through hardware virtualization inside the virtual machine specifically includes: Inside the virtual machine, a general serial port, a receive status register of the general serial port, a transmit status register of the general serial port, and an output buffer are generated by modifying the serial port simulation code of the virtual machine.

7. The virtual machine internal and external interaction method according to claim 1, characterized in that The generation of an input simulation pipeline, an output simulation pipeline, and an input buffer through hardware virtualization outside the virtual machine specifically includes: Outside the virtual machine, an input simulation pipeline and an output simulation pipeline are constructed, and the input buffer, the pipeline data notification information, and the callback functions for data transmission and reception are set using the interfaces defined by the operating system.

8. A virtual machine internal and external interaction device, characterized in that It includes: A first generation module for generating a serial port simulation device through hardware virtualization inside the virtual machine; A second generation module for generating a simulation pipeline through hardware virtualization outside the virtual machine; An interaction processing module for performing data interaction between the virtual machine internal program and the virtual machine external program based on the serial port simulation device and the simulation pipeline; The first generation module specifically is used for: Generating a general serial port, a receive status register of the general serial port, a transmit status register of the general serial port, and an output buffer through hardware virtualization inside the virtual machine; The second generation module specifically is used for: Generating an input simulation pipeline, an output simulation pipeline, and an input buffer through hardware virtualization outside the virtual machine; The interaction processing module specifically is used for: When the virtual machine internal program sends first data to the virtual machine external program, the first data is sent to the output buffer based on the general serial port and the transmit status register, and data verification is performed in the output buffer. If the verification passes, the pipeline state of the output simulation pipeline is modified so that the virtual machine external program can receive the first data; and / or When an external program of the virtual machine sends second data to an internal program of the virtual machine, the second data is sent to the input buffer based on the input simulation pipeline, and data verification is performed in the input buffer. If the verification passes, the state of the reception status register is modified so that the internal program of the virtual machine receives the second data.

9. An electronic device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the program, the steps of the virtual machine internal and external interaction method according to any one of claims 1 to 7 are implemented.

10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, the steps of the virtual machine internal and external interaction method according to any one of claims 1 to 7 are implemented.

11. A computer program product, the computer program product comprising a computer program, characterized in that, When the computer program is executed by a processor, the steps of the virtual machine internal and external interaction method according to any one of claims 1 to 7 are implemented.