Game testing method and device, computer storage medium and electronic device
By injecting pre-defined code into the Python virtual machine of the game process, obtaining the address of the target function, and establishing a data transmission connection, the problems of low efficiency and low security in existing game testing technologies are solved, realizing efficient and secure Python script game testing and development.
Patent Information
- Application Number
- CN202210248943.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-14
- Publication Date
- 2026-03-17
- Estimated Expiration
- 2042-03-14
AI Technical Summary
Existing game testing methods are inefficient and insecure, and cannot be applied to games developed with Python scripts. In particular, when modifying or adding/deleting GM commands, repackaging is required, which affects testing efficiency and poses security risks.
Preset code is injected into the Python virtual machine of the game process to obtain the address of the target function and establish a data transmission connection. Test Python data is sent through the control terminal and executed in the virtual machine, thereby separating the test script from the game code and avoiding any impact on the game code.
It improves the efficiency and security of game testing, and can be applied to any game testing and development project that uses Python as the game script, without affecting the security of the game package.
Smart Images

Figure CN114610624B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and more specifically, to a game testing method, a game testing apparatus, a computer storage medium, and an electronic device. Background Technology
[0002] During the development, internal testing, public testing, and version upgrade processes, the game needs to undergo game testing to test the game server's response to user input and actions, in order to detect vulnerabilities or other defects in the game and ensure that the game can provide the best gaming experience when it is officially launched.
[0003] In related technologies, scripts that add GM commands to the game can be used to remotely call the interface provided by the test script through methods such as operating the GM command interface and transmitting commands over the network. However, this method requires repackaging when modifying or adding / deleting GM commands, which not only affects testing efficiency but is also limited by the operating system's requirements for the installation package and may even introduce risky factors into the game. Furthermore, the injection-based game testing methods in related technologies are not suitable for testing games developed with Python scripts.
[0004] It should be noted that the information in the background section above is only used to enhance the understanding of the background of this disclosure, and therefore may include information that does not constitute prior art known to those skilled in the art. Summary of the Invention
[0005] The purpose of this disclosure is to provide a game testing method and apparatus, computer storage medium and electronic device, thereby avoiding, to at least a certain extent, the problems of low testing efficiency, low security and inapplicability to game testing developed with Python scripts in related technologies.
[0006] Other features and advantages of this disclosure will become apparent from the following detailed description, or may be learned in part from practice of this disclosure.
[0007] According to one aspect of this disclosure, a game testing method is provided, comprising: injecting preset code into a Python virtual machine of a game process, the preset code being used to obtain the address of a target function in the Python virtual machine and to establish a data transmission connection between the game process and a control terminal, wherein the address of the target function is the function address corresponding to the target function of the Python script running in the Python virtual machine;
[0008] The system receives test Python data sent by the control terminal through the data transmission connection and executes the test Python data in the Python virtual machine based on the target function address.
[0009] In one exemplary embodiment of this disclosure, establishing a data transmission connection between the game process and the control terminal includes: writing the port information of the control terminal into a Python file and sending the Python file to the terminal where the game process is located; running the Python file through the preset code to establish a task listening thread in the game process; and the game process establishing a data transmission connection with the control terminal through the task listening thread.
[0010] In one exemplary embodiment of this disclosure, injecting preset code into the Python virtual machine of the game process includes: saving the current register environment; calling the memory mapping function mmap to allocate memory management space, injecting the preset code into the memory management space, and writing the code identifier of the preset code and the calling function corresponding to the preset code into the memory management space; remotely calling the preset code, and restoring the current register environment.
[0011] In one exemplary embodiment of this disclosure, before invoking the preset code and restoring the current register environment, the method further includes: invoking an injection file for assisting in obtaining the address of the target function, with the preset code as the input parameter.
[0012] In one exemplary embodiment of this disclosure, obtaining the target function address of the Python virtual machine through the preset code includes: obtaining the base address of the dynamic link library; obtaining the function offset address corresponding to the target function; and adding the base address of the dynamic link library to the function offset address to obtain the target function address.
[0013] In one exemplary embodiment of this disclosure, obtaining the function offset address of the target function includes: disassembling the binary file of the Python virtual machine of the game process to obtain disassembled code; comparing the disassembled code with the source code of the Python virtual machine, and determining the function offset address of the target function based on the comparison result, wherein the binary file of the Python virtual machine is a compiled file of the source code of the Python virtual machine.
[0014] In one exemplary embodiment of this disclosure, the game process establishes a socket connection with the control terminal through the task listening thread; the data transmission between the game process and the control terminal further includes: redirecting the execution result of the test Python data executed by the Python virtual machine to the socket connection through the task listening thread, so as to return to the control terminal through the socket connection.
[0015] In one exemplary embodiment of this disclosure, the method employs a Python process lock mechanism to establish the task listening thread in the game process, and uses the task listening thread to access memory data in the Python virtual machine.
[0016] According to one aspect of this disclosure, a game testing apparatus is provided, comprising: a code injection module for injecting preset code into a Python virtual machine of a game process, the preset code being used to obtain the address of a target function in the Python virtual machine and establish a data transmission connection between the game process and a control terminal, wherein the target function address is the function address corresponding to the target function of a Python script running in the Python virtual machine; and an instruction execution module for receiving test Python data sent by the control terminal through the data transmission connection, and executing the test Python data in the Python virtual machine based on the target function address.
[0017] According to one aspect of this disclosure, a computer storage medium is provided that stores a computer program thereon, which, when executed by a processor, implements the game testing method described in any of the preceding claims.
[0018] According to one aspect of this disclosure, an electronic device is provided, comprising: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to perform the game testing method described in any of the preceding claims by executing the executable instructions.
[0019] The game testing method in the exemplary embodiments of this disclosure injects preset code into the Python virtual machine in the game process. Based on the preset code, the target function address of the Python virtual machine is obtained, and a data transmission connection is established between the game process and the control terminal. After receiving test Python data sent by the control terminal, the test Python data is run in the Python virtual machine based on the target function address. On one hand, this disclosure separates the test script from the game code, enabling the development of test scripts according to testing requirements. Through the connection established with the Python virtual machine in the game process, test Python data is sent to the Python virtual machine for testing. The development and modification of the test Python data do not depend on the game code, thus not affecting the game code or introducing risk factors into the game package due to the addition of test Python data. This results in high testing efficiency and high security of the testing operation. On the other hand, this game testing method can also inject relevant game Python data for secondary development of the game into the Python virtual machine through the connection between the Python virtual machine and the control terminal. This allows for secondary development of the game by starting and running the game Python data in the Python virtual machine, improving game development efficiency. Furthermore, since game engines typically run in the Native layer of the Android architecture, and this disclosure injects code into a Python virtual machine, which falls within the Native layer of the Android architecture, the game testing method disclosed herein can be applied to any game testing and development project that uses Python as the game script.
[0020] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description
[0021] The above and other objects, features, and advantages of this disclosure will become readily apparent from the following detailed description of exemplary embodiments, taken in conjunction with the accompanying drawings. Several embodiments of this disclosure are illustrated in the drawings by way of example and not limitation, in which:
[0022] Figure 1 A flowchart of a game testing method according to an exemplary embodiment of this disclosure is shown;
[0023] Figure 2 A flowchart illustrating the establishment of a connection between a game process and a control terminal according to an exemplary embodiment of this disclosure is shown;
[0024] Figure 3 A flowchart illustrating the injection of preset code into a Python virtual machine in a game process according to an exemplary embodiment of the present disclosure is shown;
[0025] Figure 4 A flowchart illustrating the injection of preset code into a Python virtual machine in a game process according to another exemplary embodiment of this disclosure is shown;
[0026] Figure 5 A flowchart illustrating the process of obtaining the address of a target function of a Python virtual machine through preset code according to an exemplary embodiment of the present disclosure is shown.
[0027] Figure 6 A flowchart illustrating the process of obtaining the address of a target function of a Python virtual machine through preset code according to an exemplary embodiment of the present disclosure is shown.
[0028] Figure 7 A flowchart illustrating the acquisition of an information object according to an exemplary embodiment of this disclosure is shown;
[0029] Figure 8 A schematic diagram of the structure of a game testing apparatus according to an exemplary embodiment of the present disclosure is shown;
[0030] Figure 9 A system architecture diagram for game testing according to an exemplary embodiment of this disclosure is shown;
[0031] Figure 10 A schematic diagram of a storage medium according to an exemplary embodiment of the present disclosure is shown; and
[0032] Figure 11 A block diagram of an electronic device according to an exemplary embodiment of the present disclosure is shown.
[0033] In the accompanying drawings, the same or corresponding reference numerals indicate the same or corresponding parts. Detailed Implementation
[0034] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, exemplary embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be more comprehensive and complete, and will fully convey the concept of exemplary embodiments to those skilled in the art. The same reference numerals in the drawings denote the same or similar structures, and therefore their detailed description will be omitted.
[0035] Furthermore, the described features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. Numerous specific details are provided in the following description to give a thorough understanding of embodiments of this disclosure. However, those skilled in the art will recognize that the technical solutions of this disclosure can be practiced without one or more of the specific details described, or other methods, components, apparatuses, steps, etc., can be employed. In other instances, well-known structures, methods, apparatuses, implementations, or operations are not shown or described in detail to avoid obscuring various aspects of this disclosure.
[0036] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities can be implemented in software, or in one or more software-hardened modules, or in different network and / or processor devices and / or microcontroller devices.
[0037] In related technologies, game testing intervention methods include adding scripts for GM execution to the game and adding a GM command interface to the game interface or connecting to a remote control terminal via the network. Testers can then remotely call the interfaces provided by the test scripts to perform game testing by operating the GM command interface or transmitting commands over the network. However, this method has the following drawbacks: a. Since GM commands need to be packaged into the Android application package for execution, any modification or addition to the relevant GM command script requires repackaging, affecting testing efficiency; b. Adding too many GM command files will increase the package size, which is limited by the Android system's requirements for installation package size; c. The GM commands or command receiving ports existing in the package script pose security risks. If misused, they can lead to serious consequences, and adding GM command files may also introduce unnecessary vulnerability risks, posing security threats. As for process injection, since the game engine is packaged into a .so library file and runs in the Native layer of the Android architecture, testing intervention methods targeting the Java layer are not applicable to games developed using Python scripts.
[0038] Based on this, in the exemplary embodiments disclosed herein, a game testing method is first provided. (See reference...) Figure 1 As shown, the game testing method includes the following steps:
[0039] Step S110: Inject preset code into the Python virtual machine of the game process. The preset code is used to obtain the address of the target function in the Python virtual machine and establish a data transmission connection between the game process and the control terminal. The address of the target function is the address of the target function of the Python script running in the Python virtual machine.
[0040] Step S120: Receive test Python data sent by the control terminal through the data transmission connection, and execute the test Python data in the Python virtual machine based on the target function address;
[0041] According to the game testing method in this example embodiment, by separating the test script from the game code, the test script can be developed according to testing requirements. Test Python data is sent to the Python virtual machine (VM) within the game process via a connection established with the VM. The development and modification of the test Python data do not depend on the game code, thus not affecting the game code or introducing risks into the game package due to the addition of test Python data. This results in high testing efficiency and high security. Furthermore, this game testing method can also inject relevant game Python data for secondary game development into the VM via the connection between the VM and the control terminal. This allows for secondary game development by starting and running the game Python data within the VM, improving game development efficiency. In addition, since game engines typically run in the Native layer of the Android architecture, and this method injects code into the VM, falling within the Native layer of the Android architecture, the game testing method is applicable to any game testing and development project that uses Python as the game script.
[0042] The following is combined with Figure 1 The game testing method in the exemplary embodiments of this disclosure will be further described.
[0043] In step S110, preset code is injected into the Python virtual machine of the game process. The preset code is used to obtain the address of the target function in the Python virtual machine and to establish a data transmission connection between the game process and the control terminal. The address of the target function is the address of the target function of the Python script running in the Python virtual machine.
[0044] In the exemplary embodiments of this disclosure, the game process is the game to be tested or the game process to be further developed, and the Python virtual machine is one of the components of the game process. The Python virtual machine is a virtual execution environment for Python bytecode. Python does not compile Python files into machine code for execution; instead, the Python virtual machine interprets and executes the Python files line by line. The control terminal is used to provide an interactive interface for user operation and to send test Python data to the game process.
[0045] In one exemplary embodiment, a task listening thread can be established within the game process, and a connection with the control terminal can be established through this task listening thread. The task listening thread can be a shell thread. In this disclosure, a shell thread refers to a port that the control terminal listens on within the game process (the monitored end). The game process initiates requests to this port and forwards its command-line input and output to the control terminal. The control terminal can then send Python script data locally to the remote controlled end (the game process). In other words, by starting a shell thread within the game process, a data transmission connection between the game process and the control terminal is established. Of course, other types of task listening threads can be selected according to actual needs.
[0046] like Figure 2 A flowchart illustrating the establishment of a connection between the game process and the control terminal according to an exemplary embodiment of the present disclosure is shown, such as... Figure 2 As shown, the process includes the following steps:
[0047] In step S210, the port information of the control terminal is written to a Python file, and the Python file is sent to the terminal where the game process is located.
[0048] In the exemplary embodiments of this disclosure, the port information of the control terminal includes, but is not limited to, the Internet Protocol (IP) address, port name, and port number of the control terminal, and other relevant information that can be used to establish a data transmission connection. The port information is replaced by writing the control terminal's port information into a Python file within the game process. Specifically, the port information for the reverse connection can be searched line by line and replaced. By sending the Python file to the terminal where the game process resides, a data transmission connection between the control terminal and the game process can be established. The Python file can be a ReverseShell.py file; that is, the port information of the control terminal is written into the ReverseShell.py file, and the ReverseShell.py file is then sent to the terminal where the game process resides.
[0049] In an exemplary embodiment of this disclosure, a startup statement can also be written to a Python file simultaneously. After the Python file is sent to the terminal where the game process is located, the task listening thread can be started subsequently via the startup statement.
[0050] It should be noted that before writing the port information of the control terminal to the Python file, it is necessary to first obtain the relevant information of the initial local port of the control terminal, that is, to obtain the port information of the control terminal first, so as to ensure the accuracy and completeness of the port information of the control terminal written to the Python file.
[0051] In this exemplary embodiment, the port information of the control terminal is written to a Python file and sent to the terminal where the game process is located. This allows the subsequent running of the Python file to establish a data transmission connection between the game process and the control terminal, thereby injecting the script into the game process to achieve game testing or secondary development. This part will be introduced later and will not be repeated here.
[0052] In step S220, a Python file is run using preset code to establish a task listening thread in the game process.
[0053] In an exemplary embodiment of this disclosure, after a Python file containing port information of the control terminal is sent to the terminal where the game process is located, the Python file can be started and run on the terminal, thereby starting a task listening thread in the game process through the Python file.
[0054] In one exemplary embodiment, the task listening thread can connect to the control terminal via a socket connection and send a connection request to the control terminal. Upon receiving the connection request, the control terminal receives and establishes a data transmission connection with the task listening thread (game process). Here, a socket is an abstraction of an endpoint for bidirectional communication between application processes on different hosts in a network, used to complete data transmission between two applications. Correspondingly, the task listening thread in the game process can also listen for Python virtual machine test data sent via the socket port and redirect the execution results of the Python virtual machine test data to the socket connection to return data to the control terminal.
[0055] In this exemplary implementation, a Python file is run using preset code to start a task listening thread in the game process. This task listening thread acts as a bridge for data transmission between the game process and the control terminal, enabling bidirectional communication between the game process and the control terminal.
[0056] In step S230, the game process establishes a data transmission connection with the control terminal through the task listening thread.
[0057] In the exemplary embodiments disclosed herein, after a task listening thread is started in the game process, the game process can establish a data transmission connection with the control terminal through the task listening thread. Based on this data transmission connection, subsequent processes such as the distribution and execution of test Python data and secondary game development can be performed.
[0058] In the exemplary embodiments disclosed herein, the preset code is at least used to obtain the address of a target function in the Python virtual machine. The target function address is the address of the function corresponding to the target function running the Python script in the Python virtual machine. Code injection methods include, but are not limited to, system process zygote injection and ptrace injection. ptrace is a library function provided by Linux, providing a way for a parent process to control the execution of a child process and to access and modify data in memory and registers. The principle of this method is to issue an interrupt instruction to the process that can interrupt the interrupt handler, causing it to enter kernel mode from user mode, thereby enabling memory read / write, register read / write, etc., thus facilitating code injection.
[0059] In one exemplary embodiment, the ptrace injection method is used, and preset code is injected into the Python virtual machine in the game process through an injector. Figure 3 A flowchart illustrating the injection of preset code into a Python virtual machine in a game process via an injector, according to an exemplary embodiment of this disclosure, is shown, such as... Figure 3 As shown, the process includes:
[0060] In step S310, the current register environment is saved by the injector.
[0061] In an exemplary embodiment of this disclosure, before saving the current register environment via the injector, the injector first establishes a connection with the game process, for example, by connecting to the game process via ptrace attach. Then, ptracegetregs is used to save the current register environment. That is, when performing code injection, the game process needs to be paused, and in order for the game process to run normally after code injection, various information of the game process at this time, such as the current code context of the game process, is saved so that when the code injection is completed and the game process is restarted, it can run normally according to the state of the game process before being paused.
[0062] By using this exemplary embodiment, saving the current register environment can prevent the code injection process from affecting the game process, ensuring that the game process is not altered by code injection.
[0063] In step S320, the memory mapping function mmap is called to allocate memory management space, inject preset code into the memory management space, and write the code identifier of the preset code and the calling function corresponding to the preset code into the memory management space.
[0064] In the exemplary embodiments of this disclosure, the memory mapping function mmap is a method for memory-mapped files. By calling the memory mapping function mmap, a file or other object can be mapped into memory. This disclosure allocates memory management space by calling the memory mapping function mmap, injects preset code into the allocated memory management space, and writes the code identifier of the preset code and the corresponding calling function into the memory management space. That is, not only is the preset code written into the memory management space, but the code identifier of the preset code and the corresponding calling function are also declared in the memory management space so that subsequent processes such as process injection, obtaining the function address corresponding to the target function of the Python script running in the Python virtual machine, and starting and running test Python data can be implemented based on the preset code.
[0065] In one exemplary embodiment, the invocation of the memory mapping function mmap may include: obtaining a handle to Libc.so using dloopen, obtaining the mmap address using dlsym, querying the function offset address of mmap through the proc / pid / maps file in the game process, and finally completing the mmap function invocation based on the function offset address. This invocation process at least includes setting the register environment, waiting for execution completion, and returning the execution result to the injector. Furthermore, a predefined code identifier and corresponding function call can be written into the memory management space using ptracewritedada.
[0066] Through exemplary embodiments of this disclosure, preset code injection can be achieved by acquiring memory management space and writing preset code in the game process.
[0067] In step S330, a preset code is remotely invoked, and the current register environment is restored.
[0068] In the exemplary embodiments disclosed herein, preset code can be remotely invoked. This invocation process also includes setting the register environment, waiting for execution to complete, and returning the execution result to the injector. Afterward, the current register environment can be restored, and the injector can be disconnected from the game process, thus completing the process of injecting the preset code into the Python virtual machine within the game process. This process requires no adjustments to the game code, achieving separation between the test script and the game code. This not only facilitates flexible development of test Python data but also allows the acquisition of the target function address corresponding to the target function running the Python script in the Python virtual machine through process injection, thereby enabling the function of running test Python data within the Python virtual machine.
[0069] It should be noted that, in the exemplary embodiments disclosed herein, in addition to obtaining the function address corresponding to the target function running the Python script in the Python virtual machine, the preset code is also used to obtain the handle of the .so library of the compiled Python virtual machine, find and obtain the function call method of the Python script running in the Python virtual machine, and, based on the obtained .so library handle, target function address and call method, to run test Python data in the Python virtual machine.
[0070] In one exemplary embodiment, such as Figure 4 As shown, before remotely calling the preset code and restoring the current register environment, step S323 may be included, which calls the injection file used to assist in obtaining the address of the target function, and the input parameter is the preset code's .so file, and returns the injection file handle.
[0071] One approach is to open an injection module by remotely calling the dlopen function and obtain the address of the function to be called by remotely calling the dlsym function. The way to call the dlopen and dlsym functions is the same as the way to call mmap, so it will not be described again here.
[0072] Through this exemplary embodiment, since the preset code injected into the Python virtual machine may not be able to fully obtain the target function address and the target function calling method, etc., the injection file is called to assist in obtaining the target function address and other relevant function call information of the Python virtual machine, so as to further ensure that the test Python data expected by the user can be run in the Python virtual machine.
[0073] In step S120, test Python data sent by the control terminal is received through the data transmission connection, and the test Python data is executed in the Python virtual machine based on the target function address.
[0074] In exemplary embodiments of this disclosure, test Python data may include execution instructions (such as Python statements) or script files (such as Python script files). If the test Python data is an execution instruction, it is sent directly to the receiving end in the virtual machine via a task monitoring thread for execution, and the execution result is returned. If the test Python data is a script file, the Python script file is retrieved from a specified directory, and its contents are sent to the receiving end in the virtual machine for execution, and the execution result is returned. This disclosure may select different types of test Python data according to actual testing needs, and this disclosure does not impose any special limitations on this.
[0075] like Figure 5A flowchart illustrating how to obtain the address of a target function in a Python virtual machine through preset code, according to an exemplary embodiment of this disclosure, is shown, such as... Figure 5 As shown, the process includes at least the following steps: in step S510, obtaining the base address of the dynamic link library; in step S520, obtaining the function offset address corresponding to the target function; and in step S530, adding the base address of the dynamic link library to the function offset address to obtain the address of the target function.
[0076] The following example uses ptrace injection, combined with... Figure 6 The process of obtaining the address of the target function of the Python virtual machine through preset code is explained in detail, and the game engine packages the Python virtual machine into the client.so file.
[0077] In step S610, the base address of libclient.so, i.e., the base address of the dynamic link library, is obtained by retrieving the proc / pid / maps file. If the target functions are in the same .so file, their corresponding base addresses are the same.
[0078] In step S620, the global interpreter lock (Python GIL lock) is acquired, which is accomplished by calling the PyGILState_Ensure function. In the exemplary embodiments of this disclosure, based on the Python process lock mechanism, after one thread uses the global interpreter access right, other threads must wait for that thread to release the global interpreter access right before executing. Therefore, by establishing a task listening thread within the game process, this task listening thread competes for the global interpreter access right to access all Python objects stored in memory. In other words, this disclosure achieves access to all memory data in the Python virtual machine by creating a new thread within the game process.
[0079] In step S630, PyRunSimple_String is called to execute test Python data. The execution process requires calling the sub-functions of this function respectively.
[0080] In steps S640 to S670, the function offset addresses corresponding to the target functions are calculated respectively, such as the function offset addresses of PyImport_AddModule, PyModule_GetDict, PyRun_StringFlags, and PyFlushLines.
[0081] Optionally, the offset address can be calculated using IDA (Interactive Disassembler), and the APIs (Application Programming Interfaces) involved in the calculation process must include at least:
[0082] Table 1
[0083] function name Functionality get_strlist_qty Get the list of strings obtained from IDA analysis DataRefsTo Get a reference to this data segment get_func Get the base address of the function located at this address. CodeRefsTo Get the list of cross-references of functions
[0084] In an exemplary embodiment of this disclosure, obtaining the offset address of the target function may include the following steps: First, disassembling the binary file of the Python virtual machine in the game process to obtain disassembled code; second, comparing the disassembled code with the source code of the Python virtual machine, and determining the offset address of the target function based on the comparison result. Here, the binary file of the Python virtual machine is a compiled file of the Python virtual machine's source code, that is, the binary file of the Python virtual machine is the file obtained after compiling the source code of the Python virtual machine.
[0085] In an exemplary embodiment of this disclosure, determining the offset address of the target function based on the comparison results between the disassembled code and the source code of the Python virtual machine can include at least three cases:
[0086] 1) If the target string exists in the target function and the target string only exists in the target function, the offset address of the target function can be obtained directly through the target string reference relationship. Then, using the interface provided by idapython, DataRefsTo is first called to find the reference address of the target string, and get_func is called to get the base address of the function where the address is located.
[0087] 2) If the target string does not exist in the target function, the target function is split into multiple sub-functions, and the target string is checked in the sub-functions. If it exists, the execution process of the target function can be completed by directly calling the sub-functions.
[0088] 3) If the target string that appears in the target function also appears in other functions, the target function cannot be uniquely located by the target string. In this case, the target function can be split into sub-functions, and the target function can be located by combining the cross-call relationship (CodeRefsTo) of the sub-functions with the target string.
[0089] In step S680, the global interpreter lock, Python GIL lock (PyGILState_Release), is released so that the Python virtual machine can return to the running state before it acquired the lock.
[0090] In step S690, the function offset address of each objective function is added to the base address of the dynamic link library to obtain the objective function address of each objective function.
[0091] Through exemplary embodiments of this disclosure, test scripts are separated from game code, enabling the development of test scripts according to testing requirements. Test scripts are injected into the Python virtual machine (VM) within the game process via a connection established with the VM. The development and modification of test scripts do not depend on the game code, thus avoiding any impact on the game code or introducing risks into the game package. This results in high testing efficiency and operational security. Furthermore, since game engines typically run in the Native layer of the Android architecture, and this disclosure injects code into the Python VM, which is already within the Native layer of the Android architecture, it is applicable to testing any game that uses Python as its game script.
[0092] Furthermore, the game testing method disclosed herein can also be used to inject game scripts for secondary development of the game into the Python virtual machine through the connection between the Python virtual machine and the control terminal. This allows for secondary development of the game by starting and running the game scripts in the Python virtual machine, thereby improving game development efficiency.
[0093] In one exemplary embodiment, extension modules for providing basic functionality can be pre-developed, including various script files that can be injected into the Python virtual machine in the game process, including but not limited to functions for traversing Python virtual machine information (such as traversing module, unit, and object information), obtaining calls to module, unit, and object methods, providing function hook methods, etc.
[0094] The virtual machine information traversal includes traversing module (unit) information and object information. This traversal utilizes Python's object storage mechanism. All data in the Python virtual machine is stored in memory as objects, and the virtual machine stores all attributes of an object in a dictionary format. The `dir` function can retrieve all attribute attributes of an object. The `type` and `dir` functions are then used to obtain the type and sub-attributes of each attribute, enabling information collection or method traversal. The Python virtual machine uses an import mechanism, storing all imported modules in the global `sys.modules`. Each imported module is from the global module list, allowing for unrestricted access regardless of namespaces.
[0095] After obtaining a module instance or object instance, you can call module, unit, and object methods. For example... Figure 7A flowchart illustrating the acquisition of an information object according to an exemplary embodiment of this disclosure is shown, such as... Figure 7 As shown, the process includes:
[0096] In step S700, the type of the object to be obtained is determined, including static information modules and dynamically created objects.
[0097] In step S710, the static information module is checked in the current scope using the dir command.
[0098] In step S720, if a static information module exists in the current scope, the dir function is used to search for the attributes in the static information module to find the final static method or global variable.
[0099] In step S730, if the module does not exist, the module name is searched by traversing sys.modules.
[0100] In step S740, after a successful search, the data is imported into the current module via import. At this point, step S720 can be continued to complete the acquisition of static information module attributes.
[0101] If you need to provide access to dynamically created object instances, then do so via:
[0102] S750: Use dir to check if the object instance exists in the current module.
[0103] S760. If it exists, continue to traverse the properties of the object instance through the dir function, such as accessing the object instance by variable name, find the target information, and then obtain the information or call the method according to the actual needs.
[0104] S770. If it does not exist, check if the module name exists in the global variables. If it exists, proceed to step S720.
[0105] S780. If the object does not exist, iterate through sys.modules to find the module name where the object instance is located and import it into the current module. At this point, the object instance can be imported into a global function using global, or the object can be calculated by memory address using the methods provided by ctypes.
[0106] S790. Calculate the memory address of the object instance using the `id` function provided by `ctypes`, and use this memory address to obtain the object pointer via `PyObj_FromPtr`. Then perform the corresponding operations as per step S720.
[0107] S7100 accesses the object instance through its memory address.
[0108] In an exemplary embodiment, a function hook method may also be provided to inject the function hook method into the game process through the same process as the game testing method disclosed herein, thereby enabling secondary development of the game.
[0109] The function hook framework utilizes the decorator principle, leveraging the fact that all data in the Python virtual machine is stored as an object dictionary. Since functions in Python are also objects, and function objects are assigned to variables, the function can be called through the variable. During the hooking process, the function's name can be obtained through the function object's `_name_` attribute. This name is modified, a new function object is constructed, and the new function pointer is made to point to the original name, thus replacing the function pointer. The original function is then called within the new function, completing the function hook. Based on this principle, functions such as parameter retrieval and modification, and function return result retrieval and modification can be implemented. The specific steps are as follows:
[0110] 1) Enter the module to be hooked by traversing the module;
[0111] 2) Use `dir` to obtain the original function object and modify the `_name_` attribute name of the original function;
[0112] 3) Create a new function object and modify the _name_ attribute to the original function's name. Then, call the original function within this function object.
[0113] 4) The function intercepts and modifies function parameters before the original function is called, and also obtains the return value of the original function for printing or modification.
[0114] It should be noted that the above-mentioned methods for traversing Python virtual machine information, obtaining modules, units, and objects, and providing function hook methods are merely illustrative. Other functional extension types can be provided according to actual development needs. Any script file used for secondary development of the game and that can be injected into the Python virtual machine in the game process can be injected into the Python virtual machine in the game process through the same process of the game testing method disclosed herein, and the Python virtual machine will run such development script files to improve the efficiency of secondary development of the game. This disclosure includes, but is not limited to, the functional extension types provided above.
[0115] In an exemplary embodiment of this disclosure, a game testing apparatus is also provided. (See reference...) Figure 8 As shown, the game testing device 800 may include a code injection module 810 and an instruction execution module 820. Specifically,
[0116] The code injection module 810 is used to inject preset code into the Python virtual machine of the game process. The preset code is used to obtain the address of the target function in the Python virtual machine and establish a data transmission connection between the game process and the control terminal. The address of the target function is the function address corresponding to the target function of the Python script running in the Python virtual machine.
[0117] The instruction execution module 820 is used to receive test Python data sent by the control terminal through a data transmission connection, and execute the test Python data in the Python virtual machine based on the address of the target function.
[0118] In one exemplary embodiment, such as Figure 9 A system architecture diagram for game testing according to an exemplary embodiment of this disclosure is shown, such as... Figure 9 As shown, the injector (code injection module) injects preset code into the Python virtual machine within the game process. The Python virtual machine is an integral part of the game process. The preset code establishes a shell thread within the game process by calling and running the Python file (ReverseShell.py file). The game process then connects to the control end through the shell thread started on the receiving end (instruction execution module). The receiving end is also used to parse and execute the test Python data sent by the control end and feed the execution results back to the control end. Specifically, the preset shellcode is also used to obtain the function address of the target function. Thus, during the parsing and execution of the test Python data sent by the control end on the receiving end, the test Python data is executed in the Python virtual machine based on the target function address.
[0119] Since the functional modules in the game testing apparatus and game testing system of the exemplary embodiments of this disclosure are the same as those in the inventive embodiments of the game testing method described above, they will not be described again here.
[0120] It should be noted that although several modules or units of the game testing device and game testing system have been mentioned in the detailed description above, this division is not mandatory. In fact, according to the embodiments of this disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.
[0121] Furthermore, in exemplary embodiments of this disclosure, a computer storage medium capable of implementing the above-described methods is also provided. A program product capable of implementing the methods described in this specification is stored thereon. In some possible embodiments, various aspects of this disclosure can also be implemented as a program product including program code, which, when run on a terminal device, causes the terminal device to perform the steps described in the "Exemplary Methods" section of this specification according to various exemplary embodiments of this disclosure.
[0122] refer to Figure 10 As shown, a program product 1000 for implementing the above-described method according to an exemplary embodiment of the present disclosure is described. This product may employ a portable compact disc read-only memory (CD-ROM) and include program code, and may run on a terminal device, such as a personal computer. However, the program product of the present disclosure is not limited thereto. In this document, the readable storage medium may be any tangible medium containing or storing a program that may be used by or in conjunction with an instruction execution system, apparatus, or device.
[0123] The program product may employ any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection having one or more wires, a portable disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0124] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, carrying readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable signal medium may also be any readable medium other than a readable storage medium, capable of sending, propagating, or transmitting programs for use by or in conjunction with an instruction execution system, apparatus, or device.
[0125] The program code contained on the readable medium may be transmitted using any suitable medium, including but not limited to wireless, wired, optical fiber, RF, etc., or any suitable combination thereof.
[0126] Program code for performing the operations of this disclosure can be written in any combination of one or more programming languages, including object-oriented programming languages such as Java and C++, and conventional procedural programming languages such as C or similar languages. The program code can execute entirely on the user's computing device, partially on the user's computing device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0127] Furthermore, in exemplary embodiments of this disclosure, an electronic device capable of implementing the above-described methods is also provided. Those skilled in the art will understand that various aspects of this disclosure can be implemented as systems, methods, or program products. Therefore, various aspects of this disclosure can be specifically implemented as entirely hardware embodiments, entirely software embodiments (including firmware, microcode, etc.), or embodiments combining hardware and software aspects, collectively referred to herein as "circuit," "module," or "system."
[0128] The following reference Figure 11 To describe an electronic device 1100 according to such an embodiment of the present disclosure. Figure 11 The electronic device 1100 shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments disclosed herein.
[0129] like Figure 11 As shown, the electronic device 1100 is manifested in the form of a general-purpose computing device. The components of the electronic device 1100 may include, but are not limited to: at least one processing unit 1110, at least one storage unit 1120, a bus 1130 connecting different system components (including storage unit 1120 and processing unit 1110), and a display unit 1140.
[0130] The storage unit stores program code that can be executed by the processing unit 1110, causing the processing unit 1110 to perform the steps described in the "Exemplary Methods" section above, according to various exemplary embodiments of this disclosure.
[0131] Storage unit 1120 may include readable media in the form of volatile storage units, such as random access memory (RAM) 1121 and / or cache memory 1122, and may further include read-only memory (ROM) 1123.
[0132] Storage unit 1120 may also include a program / utility 1124 having a set (at least one) program module 1125, such program module 1125 including but not limited to: operating system, one or more application programs, other program modules and program data, each or some combination of these examples may include an implementation of a network environment.
[0133] Bus 1130 can represent one or more of several types of bus structures, including a memory cell bus or memory cell controller, a peripheral bus, a graphics acceleration port, a processing unit, or a local bus using any of the various bus structures.
[0134] Electronic device 1100 can also communicate with one or more external devices 1200 (e.g., keyboard, pointing device, Bluetooth device, etc.), one or more devices that enable a user to interact with electronic device 1100, and / or any device that enables electronic device 1100 to communicate with one or more other computing devices (e.g., router, modem, etc.). This communication can be performed via input / output (I / O) interface 1150. Furthermore, electronic device 1100 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 1160. As shown, network adapter 1160 communicates with other modules of electronic device 1100 via bus 1130. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with electronic device 1100, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0135] From the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of this disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, terminal device, or network device, etc.) to execute the methods according to the embodiments of this disclosure.
[0136] Furthermore, the above figures are merely illustrative of the processes included in the method according to exemplary embodiments of this disclosure and are not intended to be limiting. It is readily understood that the processes shown in the above figures do not indicate or limit the temporal order of these processes. Additionally, it is readily understood that these processes may be executed synchronously or asynchronously, for example, in multiple modules.
[0137] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and embodiments are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the claims.
[0138] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.
Claims
1. A game testing method characterized by comprising: The method comprises the following steps: injecting preset code into a python virtual machine of a game process, the preset code being used to obtain a target function address in the python virtual machine and establish a data transmission connection between the game process and a control terminal, wherein the target function address is a function address corresponding to a target function of a python script running in the python virtual machine; receiving test python data sent by the control terminal through the data transmission connection, and executing the test python data in the python virtual machine based on the target function address; wherein the target function address of the python virtual machine is obtained through the preset code, comprising: obtaining a base address of a dynamic link library; performing code reverse assembly on a binary file of the python virtual machine of the game process to obtain reverse assembly code, comparing the reverse assembly code with source code of the python virtual machine, and determining a function offset address of the target function according to the comparison result, wherein the binary file of the python virtual machine is a compiled file of the source code of the python virtual machine; adding the base address of the dynamic link library and the function offset address to obtain the target function address.
2. The method of claim 1, wherein, The establishment of the data transmission connection between the game process and the control terminal comprises: writing port information of the control terminal into a python file, and sending the python file to a terminal where the game process is located; running the python file through the preset code to establish a task listening thread in the game process; the game process establishes a data transmission connection with the control terminal through the task listening thread.
3. The method of claim 1, wherein, The injection of the preset code into the python virtual machine of the game process comprises: saving a current register environment; calling a memory mapping function mmap to allocate a memory management space, injecting the preset code into the memory management space, and writing a code identifier of the preset code and a calling function corresponding to the preset code into the memory management space; remotely calling the preset code and restoring the current register environment.
4. The method of claim 3, wherein, Before the remote calling of the preset code and the restoration of the current register environment, the method further comprises: calling an injection file used to assist in obtaining the target function address, and inputting a parameter of a so file of the preset code.
5. The method of claim 2, wherein, The game process establishes a socket connection with the control terminal through the task listening thread; The game process and the control terminal perform data transmission, further comprising: redirecting a running result of the python virtual machine executing the test python data to the socket connection through the task listening thread, so as to return to the control terminal through the socket connection.
6. The method of claim 2, wherein, The method adopts a python process lock mechanism to establish the task listening thread in the game process, and realizes access to memory data in the python virtual machine based on the task listening thread.
7. A game testing apparatus, characterized by comprising: The game testing device comprises: The code injection module is configured to inject preset code in a python virtual machine of the game process, the preset code being used to obtain a target function address in the python virtual machine and establish a data transmission connection between the game process and the control terminal, wherein the target function address is a function address corresponding to a target function of a python script running in the python virtual machine; The instruction running module is configured to receive test python data sent by the control terminal through the data transmission connection, and execute the test python data in the python virtual machine based on the target function address. The code injection module is configured to perform the following operations: Obtain a base address of a dynamic link library; Disassemble a binary file of the python virtual machine of the game process to obtain disassembled code, compare the disassembled code with source code of the python virtual machine, and determine a function offset address of the target function according to a comparison result, wherein the binary file of the python virtual machine is a compiled file of the source code of the python virtual machine; Add the base address of the dynamic link library and the function offset address to obtain the target function address.
8. A storage medium having a computer program stored thereon, the computer program being executed by a processor to implement the game testing method according to any one of claims 1 to 6.
9. An electronic device, comprising: comprise: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to execute the game testing method according to any one of claims 1 to 6 by executing the executable instructions.
Citation Information
Patent Citations
Method and device for interaction between operating system and game application
CN108654090A