Function calling method and device, electronic equipment and storage medium

CN116974656BActive Publication Date: 2026-10-27TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210438860.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-22
Publication Date
2026-10-27
Estimated Expiration
2042-04-22

AI Technical Summary

Technical Problem

然而,这样静态链接的方式也在一定程度上局限了目标函数的选择,阻拦了可能存在的用于实现互联网产品的相关功能的更优函数

Benefits of technology

[0021]本申请借助属于同一文件的已知内存地址的关联函数,从文件的符号表中确定目标函数的内存地址,以实现针对目标函数的灵活调用。相较于相关技术中的静态链接的方式,本申请提高了确定待调用的目标函数的灵活性,进而能够以更具适应性的方式实现互联网产品的相关功能。同时,本申请降低了对于系统API的依赖,可以不需要依赖其以确定目标函数的内存地址,这样可以更好的满足一些动态化的业务需求。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116974656B_ABST
    Figure CN116974656B_ABST
Patent Text Reader

Abstract

The application relates to a function calling method and device, electronic equipment and a storage medium. The method comprises the following steps: in response to a function calling request, determining a target function to be called; in the case that the memory address of the target function is unknown, determining an associated function belonging to the same file as the target function; locating the file in the memory based on the memory address of the associated function and the file format of the file; locating the symbol table in the file based on the file format; determining the memory address of the target function from the symbol table; and calling the target function based on the memory address of the target function. The application can be applied to various scenes such as cloud technology, artificial intelligence, intelligent transportation and auxiliary driving. The application improves the flexibility of determining the target function to be called, and can further realize the related functions of the Internet product in a more adaptive manner. The application reduces the dependence on the system API, so that the dynamic business requirements can be better met.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of Internet communication technology, and in particular to a function call method, apparatus, electronic device and storage medium. Background Technology

[0002] With the development of internet communication technology, internet products are emerging in endless streams. The user experience of internet products is generally provided by their related functions, which are implemented through function calls. In related technologies, static linking is often used to associate the target function to be called with the relevant compiled source code to obtain an executable file. During the subsequent execution of this executable file, the target function is called to implement the relevant functions of the internet product. However, this static linking method also limits the selection of target functions to some extent, preventing the existence of potentially better functions for implementing the relevant functions of the internet product. Summary of the Invention

[0003] To address at least one of the aforementioned technical problems, this application provides a function call method, apparatus, electronic device, and storage medium:

[0004] According to a first aspect of this application, a function call method is provided, the method comprising:

[0005] In response to a function call request, determine the corresponding target function to be called;

[0006] If the memory address of the target function is unknown, determine the associated functions that belong to the same file as the target function; the file has been loaded into memory, and the memory address of the associated functions is known.

[0007] The file is located in memory based on the memory address of the association function and the file format of the file;

[0008] Based on the file format, the symbol table is located in the file; the symbol table is used to record information about functions belonging to the file.

[0009] The memory address of the target function is determined from the symbol table, and the target function is called based on the memory address of the target function.

[0010] According to a second aspect of this application, a function calling apparatus is provided, characterized in that the apparatus comprises:

[0011] Response module: Used to respond to function call requests and determine the corresponding target function to be called;

[0012] The associated function determination module is used to determine the associated functions belonging to the same file as the target function when the memory address of the target function is unknown; the file has been loaded into memory and the memory address of the associated function is known.

[0013] File location module: used to locate the file in memory based on the memory address of the association function and the file format of the file;

[0014] Symbol table location module: used to locate the symbol table in the file based on the file format; the symbol table is used to record information about functions belonging to the file;

[0015] Function call module: used to determine the memory address of the target function from the symbol table, and to call the target function based on the memory address of the target function.

[0016] According to a third aspect of this application, an electronic device is provided, the electronic device including at least one processor and a memory communicatively connected to the at least one processor; wherein the memory stores at least one instruction or at least one program segment, the at least one instruction or at least one program segment being loaded and executed by the at least one processor to implement the function call method as described in the first aspect.

[0017] According to a fourth aspect of this application, a computer-readable storage medium is provided, wherein at least one instruction or at least one program is stored therein, the at least one instruction or at least one program being loaded and executed by a processor to implement the function call method as described in the first aspect.

[0018] According to a fifth aspect of this application, a computer program product is provided, the computer program product comprising at least one instruction or at least one program segment, the at least one instruction or at least one program segment being loaded and executed by a processor to implement the function call method as described in the first aspect.

[0019] 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 application.

[0020] Implementing this application will have the following beneficial effects:

[0021] This application utilizes association functions with known memory addresses belonging to the same file to determine the memory address of the target function from the file's symbol table, enabling flexible invocation of the target function. Compared to the static linking method in related technologies, this application improves the flexibility in determining the target function to be invoked, thus enabling the implementation of related functions of Internet products in a more adaptive manner. Simultaneously, this application reduces dependence on system APIs, eliminating the need to rely on them to determine the memory address of the target function, thereby better meeting some dynamic business needs.

[0022] Other features and aspects of this application will become clear from the following detailed description of exemplary embodiments with reference to the accompanying drawings. Attached Figure Description

[0023] To more clearly illustrate the technical solutions and advantages in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0024] Figure 1 This diagram illustrates an application environment according to an embodiment of the present application.

[0025] Figure 2 A flowchart illustrating a function call method according to an embodiment of this application is shown;

[0026] Figure 3 A flowchart illustrating a positioning symbol table according to an embodiment of this application is shown;

[0027] Figure 4 A flowchart illustrating the second memory address locating symbol table according to an embodiment of this application is shown;

[0028] Figure 5 A schematic diagram of a positioning module according to an embodiment of this application is shown;

[0029] Figure 6 This diagram illustrates the composition of a Mach-O file according to an embodiment of this application.

[0030] Figure 7 This diagram illustrates the composition of a Mach-O file according to an embodiment of this application.

[0031] Figure 8 A schematic diagram showing the sliding distance according to an embodiment of this application is provided;

[0032] Figure 9 A schematic diagram illustrating the composition of a symbol table according to an embodiment of this application is shown;

[0033] Figure 10 A flowchart of a function call method according to an embodiment of this application is also shown;

[0034] Figure 11 This diagram illustrates a device block diagram according to an embodiment of the present application;

[0035] Figure 12 A schematic diagram of an electronic device according to an embodiment of this application is shown. Detailed Implementation

[0036] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.

[0037] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or server that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.

[0038] Various exemplary embodiments, features, and aspects of this application will now be described in detail with reference to the accompanying drawings. The same reference numerals in the drawings denote elements that have the same or similar functions. Although various aspects of the embodiments are shown in the drawings, they are not necessarily drawn to scale unless specifically indicated otherwise.

[0039] The term “exemplary” as used herein means “serving as an example, embodiment, or illustration.” Any embodiment illustrated herein as “exemplary” is not necessarily to be construed as superior to or better than other embodiments.

[0040] In this document, the term "and / or" is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent three cases: A alone, A and B simultaneously, and B alone. Furthermore, the term "at least one" in this document means any combination of at least two of any one or more elements. For example, including at least one of A, B, and C can mean including any one or more elements selected from the set consisting of A, B, and C.

[0041] Furthermore, to better illustrate this application, numerous specific details are provided in the following detailed description. Those skilled in the art should understand that this application can be implemented without certain specific details. In some instances, methods, means, components, and circuits well-known to those skilled in the art have not been described in detail in order to highlight the main points of this application.

[0042] Before providing a further detailed description of the embodiments of this application, the nouns and terms involved in the embodiments of this application will be explained, and the nouns and terms involved in the embodiments of this application shall be interpreted as follows.

[0043] Mach-O (Mach Object): It is the standard format for executable files, dynamic libraries, object files, and other files on Apple platforms (MacOS, iOS).

[0044] API (Application Programming Interface): An application programming interface is a set of predefined interfaces (such as functions or HTTP interfaces) or a set of conventions for connecting different components of a software system.

[0045] Objective-C: It is a successor to the C language and is primarily a programming language used to develop Apple's applications.

[0046] Compile: The process of compiling source code (text) into object files (binary files).

[0047] Object File: The object file (.o), the product of compilation, is a binary file format, but it cannot be run directly.

[0048] Link: Linking combines all the object files generated during compilation into a single executable file (ExecutableFile).

[0049] Linker: The linker is the program that performs the linking process. It is divided into static linkers (simply called linkers) and dynamic linkers. Static linkers are responsible for linking object files to generate executable files or dynamic libraries, while dynamic linkers are responsible for loading executable files and dynamic libraries into memory.

[0050] Executable File: An executable file is the final file formed by linking multiple object files. It can be run directly, and the execution of a process begins with an executable file.

[0051] Dynamic libraries, also known as dynamically linked libraries, are a type of Mach-O file that provides various APIs for executable files or other dynamic libraries to use. The various APIs provided by the operating system to developers are primarily in the form of dynamic libraries.

[0052] Module: A module is a general term for executable files or dynamic libraries.

[0053] Symbol: A symbol is a record formed after the functions and variables in the source code are compiled. A symbol includes fields such as name, address, and attributes. Calling a function (API) provided by the system library is essentially obtaining the symbol address corresponding to the function and then making the function call.

[0054] Symbol Table: A table in the module that records various symbols, abbreviated as "SYMTAB".

[0055] Text Segment: A code segment, the portion of CPU instructions in an executable file or dynamic library, named "__TEXT".

[0056] Data Segment: The data segment in an executable file or dynamic library (such as global variables, constants, etc.).

[0057] Load Address: Load address, load location, memory address, that is, the location in memory where a module is loaded.

[0058] Load Command: Loading command, the loading information provided to the dynamic linker in the Mach-O file, equivalent to the index or directory of the entire file.

[0059] Link Edit Segment: The link edit segment is where the dynamic linker loads a module into memory and then modifies some offsets and other data in this segment for the module to run correctly. The segment name is "__LINKEDIT".

[0060] Please see Figure 1 , Figure 1 The diagram illustrates an application environment according to an embodiment of this application. The application environment may include a client 10 and a server 20. The client 10 and server 20 can be directly or indirectly connected via wired or wireless communication. Related objects (such as users or simulators) trigger controls displayed on the interactive interface, generating function call requests. The interactive interface is provided by the client 10. In response to the function call request, the client 10 determines the corresponding target function to be called; then, if the memory address of the target function is unknown, it determines the associated function belonging to the same file as the target function; furthermore, based on the memory address of the associated function and the file format, it locates the file in memory; next, based on the file format, it locates the symbol table in the file; finally, it determines the memory address of the target function from the symbol table and calls the target function based on its memory address. It should be noted that... Figure 1 This is just one example.

[0061] Client 10 can be a physical device such as a smartphone, computer (e.g., desktop computer, tablet, laptop), augmented reality (AR) / virtual reality (VR) device, digital assistant, smart voice interaction device (e.g., smart speaker), smart wearable device, smart home appliance, in-vehicle terminal, etc., or software running on the physical device, such as a computer program. The operating system corresponding to Client 10 can be Android, iOS (a mobile operating system developed by Apple), Linux, Microsoft Windows, etc.

[0062] Server 20 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The server may include network communication units, processors, and memory, etc. Server 20 can provide backend services to the corresponding clients.

[0063] The function call scheme provided in this application can be used in internet products to provide related functions, especially functions that indicate dynamic business requirements (such as the requirement for web pages to be updated online). Internet products can be browser products, instant messaging products, navigation products, live streaming products, e-commerce products, etc. Taking a browser product as an example, the browser product is presented as an application, and the function indicating dynamic business requirements is a performance analysis function for mini-programs. In the mini-program inspection system SDK of the browser product, the function call scheme provided in this application can be used to determine the memory address of the screenshot API as the target function, and then the screenshot API can be called to take a screenshot of the mini-program page, thereby better realizing the performance analysis function for mini-programs.

[0064] It should be noted that for function call requests and other requests that are related to user information, when the embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.

[0065] Figure 2 This diagram illustrates a flowchart of a function call method according to an embodiment of this application, as shown below. Figure 2 As shown, the method includes:

[0066] S201: In response to a function call request, determine the corresponding target function to be called;

[0067] In this embodiment, the function call request can be generated based on request information for implementing a specified function, which indicates at least one specified function for implementing the specified function. Calling at least one specified function can implement the specified function. When the number of specified functions is greater than or equal to two, the request information for implementing the specified function also indicates the order in which the at least two specified functions are called. For the target function to be called as determined here, we can: 1) determine the specified function as the target function when the number of specified functions is equal to one; 2) determine any one of the at least two specified functions as the target function when the number of specified functions is greater than or equal to two; 3) determine that at least two specified functions are both target functions when the number of specified functions is greater than or equal to two; 4) determine whether there is a substitute function for the specified function based on current business requirements (such as timeliness requirements, resource saving requirements, etc.), and if so, determine the substitute function as the target function. Furthermore, if the number of specified functions is equal to 1, at least one substitute function is determined to be the target function; if the number of specified functions is greater than or equal to 2 and there exists at least one substitute function for all specified functions, at least one substitute function is determined to be the target function; if the number of specified functions is greater than or equal to 2 and there exists at least one substitute function for some specified functions, at least one substitute function is determined to be the target function, and some specified functions for which there is no substitute function are determined to be the target function.

[0068] It should be noted that if the number of determined objective functions is greater than or equal to two, subsequent steps S202-S205 are executed for each objective function separately. The execution order can be based on the order in which at least two objective functions are called to achieve the specified function.

[0069] S202: If the memory address of the target function is unknown, determine the associated function that belongs to the same file as the target function; the file has been loaded into memory, and the memory address of the associated function is known;

[0070] In this embodiment, calling the target function requires knowing its memory address. When the memory address of the target function is known, the target function is called based on its memory address. When the memory address of the target function is unknown, it is necessary to search for its memory address. It can be understood that, when determining whether the memory address of the target function is unknown, the name of the target function is used for searching; if the address is not found, it is determined that the memory address of the target function is unknown.

[0071] The process of identifying associated functions belonging to the same file as the target function can be done by first identifying multiple candidate files containing the target function; then, determining whether each candidate file contains a function with a known memory address; and finally, identifying the function with a known memory address in any candidate file as the associated function. Generally, a candidate file contains multiple functions, and the relationship between the names of the candidate files and the names of the individual functions can be determined. The memory address of a function can be checked using its name. Since the file containing the associated function needs to be loaded into memory, this determination step can start by identifying multiple candidate files containing the target function from the first file already loaded into memory. In practical applications, the file can be an executable file or a dynamic library.

[0072] S203: Locate the file in memory based on the memory address of the association function and the file format of the file;

[0073] In this embodiment, based on the relevant description in step S202 above, if the file's memory address (load address, load location) is known, step S203 can be skipped, and subsequent steps S204-S205 can be executed directly. However, if the file's memory address is unknown, it needs to be found. Therefore, the file's memory address is determined here based on the memory address of the association function and the file's format. The association function belongs to the file, and using the memory address of the association function can improve the efficiency of finding the file's memory address. This is because, compared to other functions whose memory addresses are known, the probability that the file's memory address is close to the memory address of the association function is higher. Based on this, combining the file's format can more accurately and effectively locate the file.

[0074] Generally, the memory address of a file refers to the memory address of its header. If the file format indicates a header marker, then locating the file in memory can include the following steps: First, starting from the memory address of the associated function, the header is located in memory in descending order of memory address until the header marker is determined; then, the file is located in memory based on the determined header marker.

[0075] The memory addresses involved in the file from the beginning to the end are allocated in ascending order of memory addresses. If the memory address of the associative function is 0x100000101, since the associative function is not in the file header, and the file's memory address indicates the file header, then the search proceeds backward from the memory address of the associative function, searching for the file header marker. The memory address of the found file header marker (e.g., 0x100000011) is the file's memory address, thus locating the file in memory. The memory address of the associative function can roughly determine the file's memory address, while combining it with the file header marker ensures the accuracy of determining the file's memory address, thus balancing speed and accuracy in file location.

[0076] In practical applications, a module may contain tens of thousands of system APIs. A module can be roughly located by finding the memory address of any commonly used API (and its corresponding associated function), and then the search can proceed backwards until the module's load address is found. (See [link to relevant documentation]). Figure 5 Taking a Mach-O file as an example, a Mach-O file consists of a Mach-O file header, several load commands, and a data area. See [link to Mach-O file]. Figure 6 The search can begin with the Mach-O header and then proceed backwards from the memory addresses of commonly used APIs to find the module's load address. The Mach-O header contains information such as the magic name, CPU type, Mach-O file type, and several flags. These values ​​are typically fixed; by verifying these values, it can be determined whether it is a Mach-O header, thus revealing its load address, which is the module's load address.

[0077] S204: Locate the symbol table in the file based on the file format; the symbol table is used to record information about functions belonging to the file.

[0078] In this embodiment, the file has been located in memory, and the symbol table in the file records information about functions belonging to the file. Therefore, the symbol table can be located within the file, and the memory address of the target function can be determined using the symbol table. To locate the symbol table within the file, the file format can be referenced for more accurate and efficient location.

[0079] In one embodiment, such as Figure 3 As shown, the file format indicates that the file includes a linking editing section and a load command, the file format indicates a load command flag for locating the load command, and the symbol table belongs to the linking editing section; locating the symbol table in the file based on the file format includes:

[0080] S301: Determine the load command flag in the file to locate the load command;

[0081] S302: Based on the load command, determine the first memory address indicating the linked edit segment, the first offset of the linked edit segment in the file, and the second offset of the symbol table in the file;

[0082] S303: Based on the difference between the first offset and the second offset, obtain the relative offset;

[0083] S304: Based on the first memory address and the relative offset, obtain the second memory address that indicates the symbol table;

[0084] S305: Locate the symbol table in the file based on the second memory address.

[0085] Based on the information indicated by the file format, we know that the symbol table belongs to the linker segment of the file. Therefore, we can first determine the memory address of the linker segment, then determine the memory address of the symbol table, and finally locate the symbol table based on its memory address.

[0086] The memory address of the linker segment can be determined by the load command. Specifically, it can be to determine the first type of load command flag related to the linker segment, then determine the first type of load command flag in the file to locate the first type of load command, and then determine the first memory address indicating the linker segment based on the first type of load command.

[0087] After determining the memory address of the linker segment, the memory address of the symbol table needs to be determined based on the association between the symbol table and the linker segment. This association can be the relative position of the symbol table and the linker segment, indicating their relative offsets within the file. The first offset of the linker segment in the file can be determined based on the first type of load command mentioned above. Determining the offset of the symbol table in the file can involve identifying the second type of load command flags related to the symbol table, then locating these flags within the file to pinpoint the second type of load command, and finally determining the second offset of the symbol table within the file based on the second type of load command. Generally, the relative offset = second offset - first offset. Accordingly, the second memory address indicating the symbol table can be obtained based on the first memory address and the relative offset.

[0088] Knowing that the file includes a linker section and a load command, and that the symbol table belongs to the linker section, the memory address and offset of the linker section, as well as the offset of the symbol table, are obtained through the load command. This allows for the successful location of the symbol table by obtaining its memory address. Referencing the file format and using this information to obtain location information improves the convenience and efficiency of locating the symbol table.

[0089] In practical applications, if the file is a Mach-O file, the Mach-O file format indicator symbol table is located in the Link Edit Segment of the data area. See [link to relevant documentation]. Figure 7 The data area stores code, constant variables, and other types of data, and the load commands are the index information of the data area. Locating the symbol table requires first finding the linker section, and then searching for the symbol table within the linker section. The load commands related to the linker section and the symbol table are shown in Table 1 below:

[0090]

[0091] Table 1

[0092] In this context, LINKEDIT.vmaddr corresponds to the first memory address mentioned above, LINKEDIT.fileoff corresponds to the first offset mentioned above, and SYMTAB.symoff corresponds to the second offset mentioned above. Accordingly, the relative offset SymbolTableOffset_In_LinkEdit = SYMTAB.symoff - LINKEDIT.fileoff. For example, if the file offset fileoff of the linker segment is 100, and the file offset symoff of the symbol table is 150, then the offset of the symbol table relative to the linker segment is 50. Since the memory address vmaddr of the linker segment indicates the location of that segment in memory, the memory address SymbolTableAddress = LINKEDIT.vmaddr + SymbolTableOffset_In_LinkEdit.

[0093] The positioning symbol table provided in steps S301-S305 above is a relatively ideal method. Based on this, two other positioning symbol table methods will be provided below:

[0094] 1) Achieve effective symbol table positioning by adjusting the file loading location:

[0095] like Figure 4 As shown, locating the symbol table in the file based on the second memory address includes:

[0096] S401: Access the second memory address;

[0097] S402: In the event of access failure, adjust the load position of the file to the third memory address indicating the code segment, and continue to access the second memory address to locate the symbol table in the file; the third memory address is the expected address set based on the target load command.

[0098] If the symbol table is read from the second memory address determined by steps S301-S304 above, and the read is successful, it can be considered that the symbol table has been successfully located and accessed. If the read fails (for example, the application crashes with the error message EXC_BAD_ACCESS), it can be considered that the access to the symbol table and the location of the symbol table have both failed, indicating that the second memory address is incorrect.

[0099] Based on the information indicated by the file format, it can be known that the file also includes a code segment, which is the beginning of the file. This process involves identifying third-class load command flags related to the code segment, then locating these flags within the file to pinpoint the third-class load command, and finally determining the third memory address indicating the code segment based on the third-class load command. Both the third memory address and the aforementioned first memory address are expected addresses, i.e., the locations where the expected code segment and linker segment are loaded.

[0100] If the second memory address is known to be incorrect, the likely cause of the access failure is that the linker segment was not loaded at the expected address. By adjusting the file's load position to align with the third memory address, the linker segment's memory address can be brought back to the expected address, ensuring the second memory address is correct and guaranteeing successful symbol table location. Handling symbol table access failures by adjusting the file's load position is direct and efficient.

[0101] In practical applications, if the file is a Mach-O file, the process of handling symbol table access failures includes printing memory address information and analyzing the printed results. The vmaddr of each segment of the Mach-O file being tested is printed out; the results on a 64-bit system are as follows:

[0102] first:

[0103] MachO.LoadAddress=0x102444000

[0104] TEXT.vmaddr = 0x100000000

[0105] LINKEDIT.vmaddr = 0x100010000

[0106] Second time:

[0107] MachO.LoadAddress=0x102904000

[0108] TEXT.vmaddr = 0x100000000

[0109] LINKEDIT.vmaddr = 0x100010000

[0110] As seen from the data above, the load address of the Mach-O file changes each time, but the addresses of the code segment and the linker segment remain constant. Furthermore, the addresses of both the code segment and the linker segment are outside the address range of the Mach-O file (before the file header). Therefore, a memory access out-of-bounds error occurs when attempting to read the symbol table. If the operating system loads the Mach-O file to a random location each time, and the code segment (TEXT) is the first data segment of the Mach-O file, then one can try using system commands to align the load location of the Mach-O file to the location specified by TEXT.vmaddr (i.e., 0x100000000), and then attempt to read the symbol table using the SymbolTableAddress calculated above. It's understandable that adjusting the file load location to achieve effective symbol table positioning is primarily used in debugging environments.

[0111] (ii) Achieving effective positioning of the symbol table through location difference information:

[0112] Based on the relevant description in section (a) above, the random loading characteristic of the operating system can affect the successful location of the symbol table. This paper proposes calculating the positional difference between the expected address and the actual address, and then using this difference to optimize the second memory address to ensure successful symbol table location. Considering the random loading characteristic, calculating the positional difference and updating the second memory address to obtain a new memory address ensures the adaptability of symbol table location and avoids interference with the operating system.

[0113] Before locating the symbol table in the file based on the second memory address, the process may include the following steps: First, obtaining the load position of the file and a third memory address indicating the code segment; the third memory address is the expected address set based on the target load command; then, obtaining position difference information based on the difference between the load position and the third memory address.

[0114] Accordingly, the second memory address is updated using the location difference information to obtain the fourth memory address; then, the symbol table is located in the file based on the fourth memory address.

[0115] For the code segment and the third memory address, please refer to the relevant description in section (a) above, which will not be repeated here. The file's load location can be regarded as the actual address. After obtaining the file's load location, it can be determined whether the file's load location and the third memory address are the same. If they are the same, the second memory address can be accessed to locate the symbol table in the file; if they are different, the positional difference between the file's load location and the third address can be determined, and then the positional difference can be used to update the second memory address to obtain the new memory address and access it.

[0116] In practical applications, if the file is a Mach-O file, due to the random loading characteristics of the operating system, the load location of the Mach-O file and the vmaddr specified by the code segment (TEXT) will slide by a certain distance: Slide = MachO.LoadAddress - TEXT.vmaddr. (See also...) Figure 8 The sliding distance corresponds to the aforementioned positional difference information. It can be understood that when a module is generated by the static linker, it usually specifies a memory location where it is expected to be loaded. However, due to the operating system's random loading mechanism, there is a difference between the actual loaded location and the expected loaded location—this is the sliding distance. Because the Mach-O file slides this distance overall, the SymbolTableAddress calculated above also needs to be increased by this sliding distance. Therefore, the final symbol table memory address is: SymbolTableAddress = Slide + LINKEDIT.vmaddr + SymbolTableOffset_In_LinkEdit, SymbolTableAddress = MachO.LoadAddress - TEXT.vmaddr + LINKEDIT.vmaddr + SYMTAB.symoff - LINKEDIT.fileoff.

[0117] S205: Determine the memory address of the target function from the symbol table, and call the target function based on the memory address of the target function.

[0118] In this embodiment of the application, when the symbol table is located, the information of the target function is determined from the information of multiple functions belonging to the file recorded in the symbol table, and the memory address of the target function is determined from the information of the target function. Then, the target function is called based on the memory address of the target function.

[0119] In one embodiment, the symbol table includes an array of multiple symbol records and a string, each symbol record describing a symbol's string index and memory address, and the string recording the names corresponding to multiple symbols; determining the memory address of the target function from the symbol table may include the following steps:

[0120] 1) Select any one of the symbol records in the array as the first target symbol record;

[0121] 2) Based on the string index and end flag of the first target symbol record, locate the symbol name in the string to obtain the first candidate symbol name;

[0122] 3) If the first candidate symbol name matches the target function, determine the memory address of the first target symbol record as the memory address of the target function;

[0123] 4) If the first candidate symbol name does not match the target function, repeat the above steps of determining the first target symbol record to obtain the first candidate symbol name until the first candidate symbol name matches the target function, and determine the memory address of the first target symbol record as the memory address of the target function.

[0124] See Figure 9 The diagram shows the arrays and strings in the symbol table. Each row of the array (except the first row) corresponds to a symbol record. The data structure of a symbol record is shown in Table 2 below:

[0125]

[0126] Table 2

[0127] Any one of the symbol records in the array can be selected as the first target symbol record, for example... Figure 9 The third row of the array. The string index based on the first target symbol record (e.g., ...). Figure 9 The second row of the array (n_strx = 6) and the end marker (e.g., a space) are used to locate the symbol name in the string, obtaining the first candidate symbol name (e.g., "myfunction"). This name is obtained by locating the end of the string starting from the 7th character and following the ascending string index, based on the characters between the 7th character and the end marker. If the target function's name is "myfunction", then the first candidate symbol name matches the target function, and the corresponding memory address of the first target symbol (e.g., ...) is recorded. Figure 9The value of the second row of the array (value = 0x14000) represents the memory address of the target function. If the name of the target function is not "myfunction", then the first candidate symbol name does not match the target function. It is necessary to continue extracting symbol records from the array (the extracted symbol records are the first ones extracted) and obtaining the corresponding first candidate symbol names, until the obtained first candidate symbol names match the target function. Then, the memory address of the symbol record corresponding to the obtained first candidate symbol name is determined to be the memory address of the target function. Of course, if the first candidate symbol name corresponding to each symbol record in the array does not match the target function, then a first message indicating that the memory address determination has failed is generated.

[0128] The memory address of the target function can be determined by traversing the array. See also Figure 9 Taking the target function named "myfunction" as an example, starting from the first line, we find that n_strx = 17. The string from line 17 to the end is "hi", which is not the symbol we are looking for. Continuing from the second line, we find that n_strx = 0. The string from line 0 to the end is "hello", which is also not the symbol we are looking for. Continuing from the second line, we find that n_strx = 6. The string from line 6 to the end is "myfunction", which is the symbol we are looking for. The address of this symbol is n_value = 0x14000.

[0129] In practical applications, referring to the relevant description in step S204 above, the memory address of the string table is StringTableAddress = MachO.LoadAddress - TEXT.vmaddr + LINKEDIT.vmaddr + SYMTAB.stroff - LINKEDIT.fileoff. Based on the symbol record, the symbol name can be obtained as SymbolName = StringTableAddress + n_strx. This name is then compared with the name of the target function. If they are the same and the symbol is of an exported type, then this symbol is the one being searched for; otherwise, the search continues to the next symbol record until the last symbol record. If a symbol record satisfying the above requirements is found, then the memory address of this target function is TargetSymbolAddress = n_value + Slide = n_value + MachO.LoadAddress - TEXT.vmaddr.

[0130] Furthermore, before determining the memory address of the target function from the symbol table, the following steps may be included: First, determine any symbol record in the array as the second target symbol record; then, based on the string index and end flag of the second target symbol record, locate the symbol name in the string to obtain the second candidate symbol name; furthermore, if the second candidate symbol name does not match the associated function, repeat the above steps of determining the second target symbol record to obtain the second candidate symbol name until the second candidate symbol name matches the associated function, and when the memory address of the second target symbol record is different from the memory address of the associated function, generate second information indicating file location failure.

[0131] Any one of the symbol records in the array can be selected as the second target symbol record, for example... Figure 9 The second row of the array. The string index based on the second target symbol record (e.g., ...). Figure 9 The second row of the array contains n_strx = 0) and the end marker (e.g., a space). The symbol name is located in the string to obtain the second candidate symbol name (e.g., "hello", which is obtained by locating the end of the string in ascending order of the string index, starting from the first character, and based on the characters between the first character and the end marker).

[0132] If the name of the associated function is "hello" and its memory address is 0x12000, then the second candidate symbol name matches the associated function and the memory address recorded by the second target symbol (e.g., Figure 9 If the value of the second row of the array (0x12000) is the same as the memory address of the associated function, the step of determining the memory address of the target function from the symbol table can be triggered.

[0133] If the name of the associated function is not "hello", then the second candidate symbol name does not match the associated function. It is necessary to continue extracting symbol records from the array (the extracted symbol records are the first ones extracted) and obtaining the corresponding second candidate symbol names, until the obtained second candidate symbol names match the associated function. Then, the memory address of the symbol record corresponding to the obtained second candidate symbol name is determined. If this memory address is different from the memory address of the associated function, a second message indicating file location failure is generated. It should be noted that when determining whether the memory address of the symbol record is the same as the memory address of the associated function, the random loading characteristics of the operating system need to be considered.

[0134] Before using the symbol table to determine the memory address of the target function, the symbol table is verified using associated functions with known memory addresses. This ensures the validity of subsequent use of the symbol table to determine the memory address of the target function. This is because the file located based on the file format may be problematic; for example, the flags used for location might match related data from other files.

[0135] In another embodiment, after determining the memory address of the target function from the symbol table, the process may include the following steps: First, in response to a function update instruction, determine the corresponding sample function; then, obtain the memory address of the sample function and replace the memory address of the target function with the memory address of the sample function to establish an association between the memory address of the sample function and the target function; or, delete the target function stored at the memory address of the target function and store the sample function at the memory address of the target function.

[0136] Based on the substitution function mentioned in step S201, a function update instruction can be triggered based on the determination of the substitution function. Of course, the function update instruction can also be determined for a static analysis scenario that implements a specific function. Correspondingly, the substitution function can be one type of sample function.

[0137] If the target function is function 1, its memory address is address 1, and the sample function is function 2, its memory address is address 2. After function update, address 2 replaces address 1 to establish the association between address 2 and function 1. Thus, subsequent calls to function 1 will essentially be calls to function 2. The method used in this application to obtain the memory address of the target function can also be referenced for obtaining the memory address of the sample function. Combining the array and string examples above, if the target function's name is "myfunction" and its address is n_value = 0x14000, and the sample function's name is "hello" and its address is value = 0x12000, after function update, the target function's name becomes "myfunction" and its address becomes n_value = 0x12000, meaning the original address of the target function is modified to point to the sample function. If the target function is function 1, its memory address is address 1, and the sample function is function 2, after function update, the function stored at address 1 becomes function 2, not function 1. Alternatively, function 1 can be stored at an address other than address 1. Function updates can improve the flexibility of function-related applications, such as hooking system APIs.

[0138] The function call method provided in this application can essentially be considered a symbol resolution method. For example... Figure 10As shown, when resolving the address of a target symbol (corresponding to a target function), the process begins with any commonly used symbol (corresponding to an associated function) in the same module as the target symbol. The load address of the module to which the target symbol belongs is found by matching the Mach-O file header backwards. Then, the symbol table is located based on the Mach-O file format. Since the symbol table is located in the linker section, a series of address calculations are required to find its location. Furthermore, due to the operating system's random loading mechanism, the position of the entire Mach-O file will slide relative to the position specified in the code segment (TEXT). Therefore, both the obtained symbol table location and the found symbol address need to have the slide added.

[0139] As can be seen from the technical solutions provided in the embodiments of this application above, the embodiments of this application utilize association functions with known memory addresses belonging to the same file to determine the memory address of the target function from the symbol table of the file, thereby enabling flexible invocation of the target function. Compared with the static linking method in related technologies, this application improves the flexibility in determining the target function to be invoked, thus enabling the implementation of related functions of Internet products in a more adaptive manner. At the same time, this application reduces the dependence on system APIs, eliminating the need to rely on them to determine the memory address of the target function, which better meets some dynamic business needs. The target function can be any function, thus ensuring the satisfaction of dynamic business needs.

[0140] This application also provides a function call device, such as... Figure 11 As shown, the function calling device 1100 includes:

[0141] Response module 1101: Used to determine the corresponding target function to be called in response to a function call request;

[0142] The associated function determination module 1102 is used to determine the associated functions belonging to the same file as the target function when the memory address of the target function is unknown; the file has been loaded into memory and the memory address of the associated functions is known;

[0143] File location module 1103: used to locate the file in memory based on the memory address of the association function and the file format of the file;

[0144] Symbol table location module 1104: used to locate the symbol table in the file based on the file format; the symbol table is used to record information about functions belonging to the file;

[0145] Function call module 1105: used to determine the memory address of the target function from the symbol table, and to call the target function based on the memory address of the target function.

[0146] It should be noted that the apparatus and method embodiments described in the device embodiments are based on the same inventive concept.

[0147] In some embodiments, the functions or modules of the apparatus provided in this application can be used to perform the methods described in the above method embodiments. The specific implementation can be referred to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.

[0148] This application also provides a computer-readable storage medium storing at least one instruction or at least one program segment, which is loaded and executed by a processor to implement the above-described method. The computer-readable storage medium may be a non-volatile computer-readable storage medium.

[0149] This application also provides an electronic device, which includes at least one processor and a memory communicatively connected to the at least one processor; wherein the memory stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by the at least one processor to implement the above method.

[0150] Electronic devices can be provided as terminals, servers, or other forms of devices.

[0151] Figure 12 A block diagram of an electronic device according to an embodiment of this application is shown. For example, electronic device 1900 may be provided as a server. (Refer to...) Figure 12 The electronic device 1900 includes a processing component 1922, which further includes one or more processors, and memory resources represented by memory 1932 for storing instructions, such as application programs, that can be executed by the processing component 1922. The application programs stored in memory 1932 may include one or more modules, each corresponding to a set of instructions. Furthermore, the processing component 1922 is configured to execute instructions to perform the methods described above.

[0152] Electronic device 1900 may also include a power supply component 1926 configured to perform power management of electronic device 1900, a wired or wireless network interface 1950 configured to connect electronic device 1900 to a network, and an input / output (I / O) interface 1958. Electronic device 1900 can operate on an operating system stored in memory 1932, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, or similar.

[0153] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 1932 including computer program instructions that can be executed by a processing component 1922 of an electronic device 1900 to perform the above-described method.

[0154] This application may be a system, method, and / or computer program product. A computer program product may include a computer-readable storage medium having computer-readable program instructions loaded thereon for causing a processor to implement various aspects of this application.

[0155] Computer-readable storage media can be tangible devices capable of holding and storing instructions for use by an instruction execution device. Computer-readable storage media can be, for example—but not limited to—electrical storage devices, magnetic storage devices, optical storage devices, electromagnetic storage devices, semiconductor storage devices, or any suitable combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), static random access memory (SRAM), portable compact disc read-only memory (CD-ROM), digital multifunction disc (DVD), memory sticks, floppy disks, mechanical encoding devices, such as punch cards or recessed protrusions storing instructions thereon, and any suitable combination thereof. The computer-readable storage media used herein are not to be construed as transient signals themselves, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through waveguides or other transmission media (e.g., light pulses through fiber optic cables), or electrical signals transmitted through wires.

[0156] The computer-readable program instructions described herein can be downloaded from computer-readable storage media to various computing / processing devices, or downloaded via a network, such as the Internet, local area network, wide area network, and / or wireless network, to an external computer or external storage device. The network may include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers, and / or edge servers. A network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards them to the computer-readable storage media in the respective computing / processing device.

[0157] The computer program instructions used to perform the operations of this application may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, status setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Smalltalk, C+, etc., and conventional procedural programming languages ​​such as the "C" language or similar programming languages. The computer-readable program instructions may be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or may be connected to an external computer (e.g., via the Internet using an Internet service provider). In some embodiments, electronic circuits, such as programmable logic circuits, field-programmable gate arrays (FPGAs), or programmable logic arrays (PLAs), are personalized by utilizing the status information of the computer-readable program instructions. These electronic circuits can execute the computer-readable program instructions to implement various aspects of this application.

[0158] Various aspects of this application are described herein with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer-readable program instructions.

[0159] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that, when executed by the processor of the computer or other programmable data processing apparatus, they create means for implementing the functions / actions specified in one or more blocks of the flowchart and / or block diagram. These computer-readable program instructions can also be stored in a computer-readable storage medium that causes a computer, programmable data processing apparatus, and / or other device to operate in a particular manner; thus, the computer-readable medium storing the instructions comprises an article of manufacture that includes instructions for implementing aspects of the functions / actions specified in one or more blocks of the flowchart and / or block diagram.

[0160] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to perform the functions / actions specified in one or more boxes of a flowchart and / or block diagram.

[0161] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of an instruction, which includes one or more executable instructions for implementing a specified logical function. In some alternative implementations, the functions specified in the blocks may occur in a different order than those specified in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0162] The various embodiments of this application have been described above. These descriptions are exemplary and not exhaustive, nor are they limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen to best explain the principles, practical applications, or technological improvements to the embodiments in the market, or to enable others skilled in the art to understand the embodiments disclosed herein.

Claims

1. A function call method, characterized in that, The method includes: In response to a function call request, determine the corresponding target function to be called; When the memory address of the target function is unknown, the associated function belonging to the same file as the target function is determined: multiple candidate files containing the target function are identified, and it is determined whether each candidate file contains a function with a known memory address; the function with a known memory address contained in any candidate file is identified as the associated function; if a memory address lookup using the name of the target function fails, it is determined that the memory address of the target function is unknown, and the file has been loaded into memory. When the memory address of the file is unknown and the file format indicates a file header flag, the file header is located in memory starting from the memory address of the association function and proceeding in descending order of memory address until the file header flag is determined; the file is located in memory based on the determined file header flag; the memory addresses involved from the beginning to the end of the file are allocated in ascending order of memory address. Based on the file format, the symbol table is located in the file; the symbol table is used to record information about functions belonging to the file. The memory address of the target function is determined from the symbol table, and the target function is called based on the memory address of the target function.

2. The method according to claim 1, characterized in that, The file format indicates that the file includes a linked editing section and a load command, the file format indicates a load command flag that locates the load command, and the symbol table belongs to the linked editing section; The step of locating the symbol table in the file based on the file format includes: The load command flag is identified in the file to locate the load command; Based on the load command, determine the first memory address of the linked edit segment, the first offset of the linked edit segment in the file, and the second offset of the symbol table in the file; The relative offset is obtained based on the difference between the first offset and the second offset; Based on the first memory address and the relative offset, a second memory address indicating the symbol table is obtained; The symbol table is located in the file based on the second memory address.

3. The method according to claim 2, characterized in that, The file format also indicates that the file includes a code segment, which is the beginning of the file; The step of locating the symbol table in the file based on the second memory address includes: Access the second memory address; In the event of access failure, the file loading position is adjusted to a third memory address indicating the code segment, and access to the second memory address continues to locate the symbol table in the file; the third memory address is the expected address set based on the target load command.

4. The method according to claim 2, characterized in that: The file format also indicates that the file includes a code segment, which is the beginning of the file; The step of locating the symbol table in the file based on the second memory address includes: Obtain the loading location of the file and the third memory address indicating the code segment; the third memory address is the expected address set based on the target loading command; Based on the difference between the loading location and the third memory address, location difference information is obtained; The step of locating the symbol table in the file based on the second memory address includes: updating the second memory address using the location difference information to obtain a fourth memory address; The symbol table is located in the file based on the fourth memory address.

5. The method according to any one of claims 1-4, characterized in that, The symbol table includes an array consisting of multiple symbol records and a string. Each symbol record describes the string index and memory address of a symbol, and the string records the names corresponding to multiple symbols. Determining the memory address of the target function from the symbol table includes: Select any one of the symbol records in the array as the first target symbol record; Based on the string index and end flag of the first target symbol record, the symbol name is located in the string to obtain the first candidate symbol name; If the first candidate symbol name matches the target function, the memory address of the first target symbol record is determined to be the memory address of the target function; If the first candidate symbol name does not match the target function, repeat the steps of determining the first target symbol record to obtain the first candidate symbol name until the first candidate symbol name matches the target function, and determine the memory address of the first target symbol record as the memory address of the target function.

6. The method according to claim 5, characterized in that, Before determining the memory address of the target function from the symbol table, the process includes: Select any one of the symbol records in the array as the second target symbol record; Based on the string index and end flag of the second target symbol record, the symbol name is located in the string to obtain the second candidate symbol name; If the second candidate symbol name does not match the association function, repeat the steps of determining the second target symbol record to obtain the second candidate symbol name until the second candidate symbol name matches the association function, and generate second information indicating file location failure when the memory address of the second target symbol record is different from the memory address of the association function.

7. The method according to any one of claims 1-4, characterized in that, After determining the memory address of the target function from the symbol table, the process includes: In response to a function update instruction, determine the corresponding sample function; Obtain the memory address of the sample function, and replace the memory address of the target function with the memory address of the sample function to establish the association between the memory address of the sample function and the target function; Alternatively, delete the target function stored at the memory address of the target function, and store the sample function at the memory address of the target function.

8. A function call device, characterized in that, The device includes: Response module: Used to respond to function call requests and determine the corresponding target function to be called; The associated function determination module is used to determine the associated function belonging to the same file as the target function when the memory address of the target function is unknown. This involves determining multiple candidate files containing the target function, and judging whether each candidate file contains a function with a known memory address. The module then determines that any function with a known memory address contained in any candidate file is the associated function. If a memory address lookup using the name of the target function fails, it is determined that the memory address of the target function is unknown, and the file has been loaded into memory. File location module: When the memory address of the file is unknown and the file format indicates a file header flag, it locates the file header in memory starting from the memory address of the association function and proceeding in descending order of memory address until the file header flag is determined; it then locates the file in memory based on the determined file header flag; the memory addresses involved from the beginning to the end of the file are allocated in ascending order of memory address. Symbol table location module: used to locate the symbol table in the file based on the file format; the symbol table is used to record information about functions belonging to the file; Function call module: used to determine the memory address of the target function from the symbol table, and to call the target function based on the memory address of the target function.

9. The apparatus according to claim 8, characterized in that, The file format indicates that the file includes a linked editing section and a load command; the file format indicates a load command flag for locating the load command; the symbol table belongs to the linked editing section; the symbol table location module is further used for: The load command flag is identified in the file to locate the load command; Based on the load command, determine the first memory address of the linked edit segment, the first offset of the linked edit segment in the file, and the second offset of the symbol table in the file; The relative offset is obtained based on the difference between the first offset and the second offset; Based on the first memory address and the relative offset, a second memory address indicating the symbol table is obtained; The symbol table is located in the file based on the second memory address.

10. The apparatus according to claim 9, characterized in that, The file format also indicates that the file includes a code segment, which is the beginning of the file; the symbol table positioning module is further used for: Access the second memory address; In the event of access failure, the file loading position is adjusted to the third memory address indicating the code segment, and access to the second memory address is continued to locate the symbol table in the file; The third memory address is the expected address set based on the target load command.

11. The apparatus according to claim 9, characterized in that, The file format also indicates that the file includes a code segment, which is the beginning of the file; the symbol table positioning module is further used for: Before locating the symbol table in the file based on the second memory address, the load position of the file and a third memory address indicating the code segment are obtained; the third memory address is the expected address set based on the target load command. Based on the difference between the loading location and the third memory address, location difference information is obtained; The step of locating the symbol table in the file based on the second memory address includes: updating the second memory address using the location difference information to obtain a fourth memory address; The symbol table is located in the file based on the fourth memory address.

12. The apparatus according to any one of claims 8-11, characterized in that, The symbol table includes an array of multiple symbol records and a string. Each symbol record describes the string index and memory address of a symbol, and the string records the names corresponding to multiple symbols. The function call module is further used for: Select any one of the symbol records in the array as the first target symbol record; Based on the string index and end flag of the first target symbol record, the symbol name is located in the string to obtain the first candidate symbol name; If the first candidate symbol name matches the target function, the memory address of the first target symbol record is determined to be the memory address of the target function; If the first candidate symbol name does not match the target function, repeat the steps of determining the first target symbol record to obtain the first candidate symbol name until the first candidate symbol name matches the target function, and determine the memory address of the first target symbol record as the memory address of the target function.

13. The apparatus according to claim 12, characterized in that, The apparatus is further configured to: before determining the memory address of the target function from the symbol table, determine any one of the symbol records in the array as a second target symbol record; Based on the string index and end flag of the second target symbol record, the symbol name is located in the string to obtain the second candidate symbol name; If the second candidate symbol name does not match the association function, repeat the steps of determining the second target symbol record to obtain the second candidate symbol name until the second candidate symbol name matches the association function, and generate second information indicating file location failure when the memory address of the second target symbol record is different from the memory address of the association function.

14. The apparatus according to any one of claims 8-11, characterized in that, The apparatus is further configured to: after determining the memory address of the target function from the symbol table, in response to a function update instruction, determine the corresponding sample function; Obtain the memory address of the sample function, and replace the memory address of the target function with the memory address of the sample function to establish the association between the memory address of the sample function and the target function; Alternatively, delete the target function stored at the memory address of the target function, and store the sample function at the memory address of the target function.

15. An electronic device, characterized in that, The electronic device includes at least one processor and a memory communicatively connected to the at least one processor; wherein the memory stores at least one instruction or at least one program, the at least one instruction or at least one program being loaded and executed by the at least one processor to implement the function call method as described in any one of claims 1-7.

16. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one instruction or at least one program, which is loaded and executed by a processor to implement the function call method as described in any one of claims 1-7.

17. A computer program product, characterized in that, The computer program product includes at least one instruction or at least one program segment, which is loaded and executed by a processor to implement the function call method as described in any one of claims 1-7.

Citation Information

Patent Citations

  • Systems and methods for determining an address for a private function

    US20140122454A1