Executable file processing system, processing method and embedded device
By preprocessing the executable files in the computer terminal, generating target executable files suitable for embedded devices, and storing and processing them in embedded devices, the problems of complex, slow download applications, and large storage occupancy of traditional smart card devices are solved, and the effect of simplifying the download process and improving efficiency is achieved.
Patent Information
- Application Number
- CN202411791688.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-06
- Publication Date
- 2025-03-18
AI Technical Summary
The process of downloading applications of traditional smart card devices is complicated, and the download speed is slow and occupies a large amount of storage resources.
An executable file processing system is provided to preprocess the executable files through a computer terminal, generate target executable files suitable for an embedded device, and store and process these files in the embedded device to simplify the downloading process.
It effectively simplifies the process of downloading applications on embedded devices, improves download speed, and reduces storage resource usage.
Smart Images

Figure CN119645525A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of embedded technology, and in particular to an executable file processing system, a processing method and an embedded device. Background Art
[0002] In traditional technology, the process of downloading applications to smart card devices is as follows: first, on the PC side, a compiler is used to generate an executable file of the application; then the executable file is sent from the PC side to the smart card device through a communication interface; during the process of downloading the executable file, the smart card device needs to check the validity of the format of the executable file and reorganize the data structure. These processes are performed in the RAM of the smart card device, and finally the data required for runtime is saved in the non-volatile memory of the smart card device.
[0003] The inventor of the present application noticed during research that the process of downloading applications to a smart card device in the traditional technology is complicated. Summary of the invention
[0004] In view of this, the embodiments of the present application provide an executable file processing system, a processing method and an embedded device, which can effectively simplify the process of downloading applications on the embedded device.
[0005] In a first aspect, an embodiment of the present application provides an executable file processing system, including: an embedded device and a computer terminal;
[0006] The computer terminal is used to pre-process the executable file according to the first preset processing mode and the second preset processing mode to obtain a target executable file suitable for the embedded device;
[0007] The embedded device is used to store the target executable file in a non-volatile memory included in the embedded device, so as to run a target application based on the target executable file.
[0008] In some embodiments, the first preset processing method is selected from one of validity check, data structure reorganization processing and application download instruction processing, and the second preset processing method is selected from the other of the validity check, the data structure reorganization processing and the application download instruction processing.
[0009] In some embodiments, the computer terminal is further used to match the target data reorganization method in the data reorganization methods of each preset file type according to the preset code in the executable file.
[0010] In some embodiments, the target executable file includes a plurality of segments;
[0011] The embedded device is also used to modify the offset address of each segment to the actual storage address in the non-volatile memory after storing the target executable file in the non-volatile memory, and store the actual storage address in the segment address table for query by the embedded device.
[0012] In some embodiments, if the first preset processing method or the second preset processing method is to perform a validity check on the executable file;
[0013] The computer terminal is specifically used to perform validity check on the executable file according to a preset file specification, using a preset tool or a preset programming language library.
[0014] In some embodiments, the target data reassembly method includes a plurality of segment reassembly methods;
[0015] The computer terminal is also specifically used for:
[0016] Parsing the executable file according to a preset file specification to obtain at least one segment;
[0017] According to the segment reorganization method corresponding to each segment, the data structure of each segment is reorganized to obtain the target executable file.
[0018] In some embodiments, the at least one segment includes: at least one of an import segment and a function segment;
[0019] The computer terminal is specifically used for:
[0020] According to the identifier of each segment, obtain the corresponding segment reorganization method;
[0021] Using the segment reorganization method of the import segment, sorting each import function in the import segment according to a preset order to obtain a corresponding index, and using the corresponding index to identify each import function; and / or,
[0022] By utilizing the segment reorganization method of the function segment, target parameters are extracted from each parameter in the function segment according to the usage frequency of each parameter in the function segment, and the target parameters are used as the final parameters of the function segment; wherein the target parameters include parameter type and parameter number.
[0023] In some embodiments, the at least one segment further comprises: at least one of a type segment, a table segment, an element segment, a memory segment, and a data segment;
[0024] The computer terminal is specifically used for:
[0025] Using the segment reorganization method of the type segment, converting the multi-byte code in the type segment into a single-byte code; and / or,
[0026] Using the segment reorganization method of the table segment, converting the multi-byte code in the table segment into a single-byte code or a double-byte code; and / or,
[0027] Using the segment reorganization method of the element segment, convert the multi-byte code in the element segment into a single-byte code or a double-byte code; integrating and storing the converted table segment and element segment; and / or,
[0028] Using the segment reorganization method of the memory segment, obtaining the current number of pages, the maximum number of pages and the number of bytes per page in the memory segment; converting the current number of pages and the maximum number of pages into single-byte encoding, and converting the number of bytes per page into double-byte encoding; and / or,
[0029] The multi-byte code in the data segment is converted into a double-byte code by utilizing the segment reorganization method of the data segment.
[0030] In a second aspect, an embodiment of the present application provides a data processing method applicable to an embedded device, the method comprising:
[0031] Download the target executable file to the embedded device, and store it in a non-volatile memory included in the embedded device after address processing of the target executable file; the target executable file is processed by a computer terminal in an executable file processing system provided in the first aspect of the present application.
[0032] In a third aspect, an embodiment of the present application provides an embedded device, the embedded device comprising a processor and a memory, the memory storing a computer program, and the processor being used to execute the computer program to implement a data processing method provided in the second aspect of the present application.
[0033] The embodiments of the present application have the following beneficial effects:
[0034] The computer terminal is used to pre-process the executable file according to the first preset processing mode and the second preset processing mode to obtain a target executable file suitable for the embedded device;
[0035] The embedded device is used to store the target executable file in a non-volatile memory included in the embedded device to run the target application based on the target executable file. The data parsing in the present application is performed in a computer terminal, which can effectively simplify the process of downloading applications to the embedded device. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0037] Figure 1 A structural block diagram of an executable file processing system according to an embodiment of the present application is shown;
[0038] Figure 2 A timing diagram of an executable file processing system according to an embodiment of the present application is shown;
[0039] Figure 3 Another timing diagram of the executable file processing system according to an embodiment of the present application is shown.
[0040] Description of main component symbols:
[0041] 100-computer terminal; 200-embedded device. DETAILED DESCRIPTION
[0042] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments.
[0043] The components of the embodiments of the present application generally described and shown in the drawings herein may be arranged and designed in various configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.
[0044] Hereinafter, the terms "including", "having" and their cognates that can be used in various embodiments of the present application are intended only to indicate specific features, numbers, steps, operations, elements, components or a combination of the foregoing items, and should not be understood as first excluding the existence of one or more other features, numbers, steps, operations, elements, components or a combination of the foregoing items or increasing the possibility of one or more features, numbers, steps, operations, elements, components or a combination of the foregoing items. In addition, the terms "first", "second", "third" and the like are only used to distinguish descriptions and cannot be understood as indicating or implying relative importance.
[0045] Unless otherwise defined, all terms (including technical terms and scientific terms) used herein have the same meanings as those generally understood by those skilled in the art to which the various embodiments of the present application belong. The terms (such as those defined in generally used dictionaries) will be interpreted as having the same meanings as the contextual meanings in the relevant technical field and will not be interpreted as having idealized meanings or overly formal meanings unless clearly defined in the various embodiments of the present application.
[0046] In conjunction with the accompanying drawings, some embodiments of the present application are described in detail below. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.
[0047] The present application provides an executable file processing system, a processing method and an embedded device, which can not only effectively simplify the process of downloading applications on embedded devices, but also effectively solve the problems of slow application downloading speed and large storage resource occupation on embedded devices.
[0048] The executable files in the embodiments of the present application include but are not limited to bytecode files. Bytecode files are composed of a series of byte sequences, which contain instructions, constants, and metadata of functions that define program logic and data. The bytecode file structure mainly includes the following key parts:
[0049] (1) Magic Number
[0050] For example, a wasm file starts with the string `wasm` (`77 61 72 6d` in hexadecimal), which is a version identifier indicating that the file format is WebAssembly.
[0051] (2) Version Number.
[0052] The second part is the version number, which indicates the version information of the file. This consists of two bytes, where the first byte represents the major version number and the second byte represents the minor version number.
[0053] (3) Sections.
[0054] (3-1) Import Section: Import declaration, used to describe the import of external resources, such as global variables, functions, types, etc. imported from JavaScript, other wasm modules, or other resources.
[0055] -Import declarations: define functions, tables, memories, and global variables imported from external modules.
[0056] -Format:
[0057] -Module name: The name of the import section.
[0058] -Item Name: The name of the imported item.
[0059] -descriptor: The descriptor specifies the type of the imported item (function, table, memory, or global variable).
[0060] (3-2) Type Section: used to define all data types within the module, including function types, global variable types, module internal types, etc.
[0061] -Type definition: defines the function type (function signature). Each entry contains a list of parameter types and a list of return value types.
[0062] -Purpose: Used to declare the signature of a function for reference by other parts.
[0063] (3-3) Function Section: used to define the functions in the module and their parameters and return value types.
[0064] -Function index: Each function is assigned an index, which corresponds to the type definition in the Type section.
[0065] -Purpose: Provides function indexes so that other parts can reference these functions.
[0066] (3-4) Table Section: used to describe the information of indirect method call dependencies.
[0067] -Table definition: Defines a table, which is an array of fixed or variable size used to store function references or other types of values.
[0068] -Format:
[0069] -Element Type: The type of element in the table (usually a function reference).
[0070] - Initial Size: The initial size of the table.
[0071] -maxsize: Maximum allowed size of the table (optional).
[0072] (3-5) Element Section: Each element of the element section consists of four parts: table index, offset in the table, number of elements, and element content. (3-6) Memory Section: It is used to describe the configuration information of the memory, including the initial size, maximum size, and alignment properties of the memory.
[0073] -Memory definition: Defines a linear memory area for storing data.
[0074] -Format:
[0075] - Initial size: The initial size of the memory (in pages).
[0076] -maxsize: The maximum allowed size of the memory (optional).
[0077] (3-7)Global Section: used to define the type and initial value of global variables.
[0078] -Global variable definition: Define global variables, which are visible throughout the program.
[0079] -Format:
[0080] -Type: The type of the global variable (such as i32, f64, etc.).
[0081] -Initial value: The initial value of the global variable.
[0082] (3-8) Export Section, which is used to specify which functions, global variables, and module types can be accessed externally, as well as their externally visible names.
[0083] -Export declaration: declares the functions, tables, memory and global variables provided by the module to the outside world.
[0084] -Format:
[0085] - Name: The name of the exported item.
[0086] -Descriptor: The descriptor specifies the type of the exported item (function, table, memory or global variable).
[0087] (3-9) Code Section, which contains the actual wasm instruction set and the functional code for executing the program.
[0088] (3-10) Data Section: Each data block in the data section consists of four parts: memory index, offset in memory, data length, and initialization data.
[0089] The executable file processing system is described below in conjunction with some specific embodiments.
[0090] Figure 1A structural block diagram of an executable file processing system of an embodiment of the present application is shown. Exemplarily, the executable file processing system includes: a computer terminal 100 and an embedded device 200. The embedded device 200 is connected to the computer terminal 100 for communication. The embedded device 200 of the present application includes but is not limited to a smart card.
[0091] The computer terminal 100, such as Figure 2 As shown, it is used to pre-process the executable file according to the first preset processing mode and the second preset processing mode to obtain a target executable file suitable for the embedded device 200. The executable file is obtained by compiling the target application of the embedded device 200 through a compiler.
[0092] Furthermore, the first preset processing method is selected from one of validity check, data structure reorganization processing and application download instruction processing, and the second preset processing method is selected from the other of the validity check, the data structure reorganization processing and the application download instruction processing.
[0093] The computer terminal 100, such as Figure 3 As shown, if the first preset processing method or the second preset processing method is to perform a validity check on the executable file.
[0094] The computer terminal 100 is specifically used to perform validity check on the received executable file according to a preset file specification, using a preset tool or using a preset programming language library.
[0095] Exemplarily, the executable file is a WebAssembly file. The preset file specification is the WebAssembly specification. The WebAssembly (abbreviated as Wasm) specification defines the structure, instruction set, binary and text format representation, and verification, instantiation, and execution semantics of the WebAssembly module. If the executable file complies with the WebAssembly specification, the executable file is valid and the executable file is a target executable file.
[0096] For example, the WABT (WebAssembly Binary Toolkit) tool is used to check the validity of executable files.
[0097] WABT is a set of tools for manipulating and validating WebAssembly executables. Use the `wasm-validate` command in WABT to check whether the file conforms to the Wasm specification. The specific steps include: 1) Install the WABT toolkit. For example, on Linux, you can install it through the package manager (such as `sudo apt-get install wabt`). 2) Prepare the WebAssembly file and make sure that the WebAssembly file (for example, `your_file.wasm`) exists in the environment. 3) Run the `wasm-validate` command:
[0098] ```sh
[0099] wasm-validate your_file.wasm
[0100] ```
[0101] If the executable file complies with the Wasm specification, the command will not output anything; if the executable file does not comply with the Wasm specification, the command will output detailed error information.
[0102] Another example is to use a programming language library to check the validity of an executable file. The following uses Python and Wasmer as examples: 1) Install the Wasmer library:
[0103] ```sh
[0104] pip install wasmer
[0105] ```
[0106] 2) Prepare a WebAssembly file, for example, `your_file.wasm`.
[0107] 3) Write a verification script:
[0108] ```Python
[0109] from wasmer import Store,Module,ImportObject,Instance
[0110] #Open and read WASM file
[0111] with open('your_file.wasm','rb')as f:
[0112] wasm_bytes = f.read()
[0113] #Create a store object
[0114] store = Store()
[0115] try:
[0116] #Try to load the module
[0117] module=Module(store,wasm_bytes)
[0118] print("The file complies with the Wasm specification")
[0119] except Exception as e:
[0120] print(f"Verification failed:{e}").
[0121] Through the above validity check, this application can ensure that the generated WebAssembly file can run reliably, thereby improving not only the quality of the code, but also the user experience and system security.
[0122] In one embodiment, the computer terminal 100 is further configured to match the target data reorganization method used in the data structure reorganization process in the data reorganization method of each preset file type according to the preset code in the executable file.
[0123] In the embodiment of the present application, a data reorganization method of multiple file types is preset, for example, the file type of the corresponding executable file is determined according to the file extension or file header of the received target executable file. For example, the executable file applicable to the smart card includes a WebAssembly file.
[0124] WebAssembly files contain file headers / magic numbers, which contain a specific byte sequence or "magic number" at the beginning of the executable file, and the type of the file can be identified by the byte sequence. For example, the magic number in the WebAssembly file can indicate the file type.
[0125] Further, the target data reorganization method includes multiple segment reorganization methods;
[0126] The computer terminal 100, such as Figure 3 As shown, it is also specifically used for:
[0127] Parsing the executable file according to a preset file specification to obtain at least one segment;
[0128] According to the segment reorganization method corresponding to each segment, the data structure of each segment is reorganized to obtain the target executable file.
[0129] The at least one segment includes: magic number, import segment, function segment, type segment, table segment, element segment, memory segment, global segment, code segment, data segment, and export segment.
[0130] Furthermore, for the lead-in segment, in order to reduce the size of the data structure in the lead-in segment, the computer terminal 100 is specifically used for:
[0131] According to the identifier of the import segment, the segment reorganization method corresponding to the import segment is obtained; the structure of the executable file of the Wasm file consists of multiple segments, each of which has a specific identifier and length. For example, the identifier of the import segment is 3 (also called segment ID).
[0132] By using the segment reorganization method of the import segment, each import function in the import segment is sorted according to a preset order to obtain a corresponding index, and each import function is identified by the corresponding index. The import segment includes multiple external import functions, and the external import functions need to be imported into the smart card to run in order to realize the functions of the application. Among them, multiple import function names are represented by a string, which occupies a large space. Therefore, the embodiment of the present application uses an index to identify the import function. The smart card locally defines and implements these external import functions in a native configuration file, and records the index of the corresponding import function. For example, an ID number is used to indicate which function the import function is in the import segment, and then when running the application, the corresponding import function is queried according to the ID number. In this way, the occupied space is reduced.
[0133] In the embodiment of the present application, by reorganizing the data of the import segment, the search cost at runtime is reduced and the execution efficiency is improved.
[0134] Furthermore, in order to find the function faster and reduce the space occupied by the function segment, the computer terminal 100 is specifically used for:
[0135] According to the identifier of the function segment, obtaining a segment reorganization method of the imported function;
[0136] Utilizing the segment reorganization method of the function segment, extracting target parameters from each parameter in the function segment according to the usage frequency of each parameter in the function segment;
[0137] The target parameter is used as the final parameter of the function segment; the target parameter includes a parameter type and a parameter number.
[0138] When a function in a function segment is called, some data in the type segment may be used, such as function parameter information, etc. Therefore, the embodiment of the present application will rearrange these data to reduce the space occupied by the function segment.
[0139] Furthermore, the computer terminal 100 is specifically used for:
[0140] Utilize the segment reorganization method of described type segment, the multi-byte encoding in described type segment is converted into single-byte encoding.A function type is included in the type segment, and this function has two parameters and a return value.For example, in the initial binary data adopted by the multi-byte encoding in the type segment, based on LEB128 (Little-Endian Base 128) encoding format (a 128-bit, variable-length encoding format represented based on the little end method), more bytes may be used to represent this information, especially when it comes to the number of parameters and return values and the number of units occupied by them.For example, in the segment reorganization method of type segment in the embodiment of the present application, the multi-byte encoding in the type segment can be converted into hexadecimal representation, so that the data used at high frequency in the type segment can be directly read, instead of needing to perform decoding operation every time reading, thereby can improve the execution efficiency at runtime.
[0141] Specifically, the type information of the parameters and return values in the type segment is extracted, for example: parameter type: 'i32,i64' (two parameters, occupying 4 bytes and 8 bytes respectively), return value type: 'f32' (one return value, occupying 4 bytes).
[0142] In the 'LEB128' encoding, these information will be represented by multiple bytes, but the embodiments of the present application always use single-byte encoding to represent the number of parameters and return values and the number of units they occupy. Specifically, the possible formats are as follows:
[0143] The first byte: the number of parameters and the number of return values (each represented by 4 bits), the upper 4 bits: represent the number of parameters (such as 2), the lower 4 bits: represent the number of return values (such as 1). For example, if there are 2 parameters and 1 return value, then this byte may be encoded as '0x21'.
[0144] The second byte: the total number of units occupied by the parameter. For example, 'i32' occupies 4 bytes, 'i64' occupies 8 bytes, and one unit refers to 4 bytes, so the total number of units is 3, so here it may be represented by one byte as '0x03'.
[0145] The third byte: the number of units occupied by the return value. For example, 'f32' occupies 4 bytes, one unit refers to 4 bytes, and the number of units occupied by the return value is 1, so it can be directly represented by one byte as '0x01'.
[0146] After the above data reorganization, the data in the type segment is compressed into a more compact format. Compared with 'LEB128' encoding, this method greatly reduces the space occupied by the type segment.
[0147] All the type segment information after data reorganization will be reorganized according to the structure of the type instance based on the needs of the target embedded device 200 to obtain the target binary data segment corresponding to the type segment (type segment).
[0148] In this application, the execution efficiency of the target executable file is improved by reorganizing the data of the type segment. For example, information not used during runtime, such as the type segment ID and the number of type elements, is removed, and the number of units occupied by parameters and return values is increased.
[0149] Through the above type segment optimization strategy, the size of the type segment can be effectively reduced, thereby reducing the application space occupied by the smart card.
[0150] Furthermore, the computer terminal 100 is specifically used for:
[0151] The multi-byte code in the table segment is converted into a single-byte code or a double-byte code by using the segment reorganization method of the table segment. The multi-byte code in the element segment is converted into a single-byte code or a double-byte code by using the segment reorganization method of the element segment; and the converted table segment and element segment are integrated and stored.
[0152] Specifically, the information contained in the table segment in the target executable file includes:
[0153] Current table size: 100.
[0154] Maximum table size: 200.
[0155] The index of each element: Assume the index values are '0, 1, 2, ...'.
[0156] The data structure of the table segment after data reorganization is:
[0157] 1-byte element type: Assume the value is '01', indicating that this is a table of function type.
[0158] 2-byte current table size: Use 2 bytes to represent the current table size, 100.
[0159] 2-byte maximum table size: Use 2 bytes to represent the maximum table size, 200.
[0160] Element instance: Contains the data of the element, which can be a function index.
[0161] After data reorganization, the entire table segment may be represented as: '01 00 64 00C8', where '01' indicates the element type, '00 64' indicates that the current table size is 100, and '00C8' indicates that the maximum table size is 200.
[0162] Before data reorganization, the element segment is used to initialize the table segment, which contains the element's address offset and function index.
[0163] The data structure of the element segment corresponding to the data segment after data reorganization is:
[0164] 1-byte identifier: Indicates the storage format used for the data. Assuming it is '01', it means that 1 byte is used to represent the element data.
[0165] 1-byte element type: indicates the type of the element. Assuming it is '01', it means it is a function type.
[0166] 2-byte current table size: consistent with the table segment, which is 100.
[0167] 2-byte maximum table size: consistent with the table segment, which is 200.
[0168] Element instance: Each instance is represented by 1 byte.
[0169] Assuming that the element instance is '0x01, 0x02', indicating two function indexes, the optimized target elem' may be represented as: '01 01 00 64 00C8 01 02'.
[0170] The target table segment for data reorganization is integrated and stored with the target element segment.
[0171] By reorganizing the data of table segments and element segments, the space occupied by table segments and element segments can be reduced, while improving the execution efficiency of the target smart card application. Through 1-byte or 2-byte data representation, data can be effectively compressed while still maintaining its functionality and usability.
[0172] Furthermore, the computer terminal 100 is specifically used for:
[0173] Utilize the segment reorganization method of the memory segment to obtain the current number of pages, the maximum number of pages, and the number of bytes per page in the memory segment; convert the current number of pages and the maximum number of pages into single-byte encoding, and convert the number of bytes per page into double-byte encoding. The memory segment is used to define the initial configuration of the memory in the module, such as the current number of pages, the maximum number of pages, and the number of bytes per page of the memory. The memory segment usually uses the variable-length LEB128 encoding format to represent these values. The embodiment of the present application uses a representation method that compresses these values into a fixed length to reorganize the data.
[0174] Specifically, assume that the memory segment contains the following information before data reorganization:
[0175] Current number of pages: 64 pages (usually expressed in LEB128 encoding format).
[0176] Maximum number of pages: 128 pages (usually expressed in LEB128 encoding format).
[0177] Bytes per page: 65536 bytes (64KB, the standard page size).
[0178] In the target executable, these values may occupy a different number of bytes. For example:
[0179] Current page number: 64 may be encoded as '0x40' (1 byte).
[0180] Maximum number of pages: 128 may be encoded as '0x80 0x01' (2 bytes).
[0181] Bytes per page: 65536 may be encoded as '0x80 0x80 0x01' (3 bytes).
[0182] For data reorganization, re-encode these values to fixed length:
[0183] Current page number: Use 1 byte to represent it, and directly write '0x40'.
[0184] Maximum number of pages: Use 1 byte to represent it, and directly write '0x80'.
[0185] The data structure of the memory segment after data reorganization is as follows:
[0186] Current page number: '0x40' (1 byte, indicating 64 pages).
[0187] Maximum number of pages: '0x80' (1 byte, indicating 128 pages).
[0188] Number of bytes per page: '0x00 0x10' (2 bytes).
[0189] When loading the memory segment in the smart card, the system will directly read these 4 bytes of optimized data:
[0190] Current page number: '0x40' is directly interpreted as 64 pages.
[0191] Maximum number of pages: '0x80' is directly interpreted as 128 pages.
[0192] Bytes per page: '0x00 0x10' is directly parsed as '65536' bytes.
[0193] Data reorganization of memory segments not only reduces the space occupied by memory segments, but also simplifies the parsing process because it is no longer necessary to process variable-length LEB128 encoding, making parsing more efficient and improving the running efficiency of the target executable file in the smart card.
[0194] By reorganizing the data of the memory segment, the current page number and the maximum page number are compressed to 1 byte, and the bytes per page are compressed to 2 bytes, so that it occupies less space and speeds up the parsing speed, so that the smart card can read and interpret the data faster when processing the memory configuration, thereby improving the overall performance.
[0195] Furthermore, the computer terminal 100 is further used for:
[0196] The global segment is divided into two parts: global data and global instance; global data is used to store the initial value corresponding to the global segment; global instance is used to store the running information corresponding to the global segment.
[0197] The global segment is used to define global variables. Global variables can be constant or variable and are used at runtime. The segment reorganization method based on the global segment divides the global segment into two parts: global data and global instance. The global data only has initialization values, and the global instance is the global instance structure used at runtime.
[0198] Specifically, the global segment in the target executable file usually contains the definitions of several global variables. The definition of each variable includes the type of the variable (such as integer or floating point number), the variability flag (constant or variable), and the initial value expression.
[0199] For each global variable corresponding to the global segment before data reorganization, extract its initial value and save these initial values as the global data part. This part of data only contains initial values because these values need to be initialized when loading the file.
[0200] For example, a global variable is defined as:
[0201] "'wasm
[0202] (global$g0(mut i32)(i32.const 10))
[0203] ”'
[0204] The initial value '10' is the global data.
[0205] The global instance is a structure used at runtime that contains all the necessary metadata information for accessing and modifying global variables. This instance structure typically contains the following fields:
[0206] The type of the variable (e.g. 'i32', 'f32', etc.).
[0207] Whether it is mutable (constant / mutable).
[0208] The current value of the variable (which may differ from the initial value at runtime).
[0209] The address or offset of the variable in memory
[0210] The global instance will include the following:
[0211]
[0212] A global instance is created for each global variable so that it can be managed at runtime.
[0213] In the global segment after data reorganization, the global data part only contains initial values, and all runtime information is encapsulated into the global instance. This reduces the amount of redundant data in the global segment and makes runtime access more efficient.
[0214] When the file is loaded into the smart card, the smart card will initialize the global instance according to the global data.
[0215] Assume the following initial global segment definition:
[0216] "'wasm
[0217] (global$g1 i32(i32.const 20))
[0218] (global$g2(mut f64)(f64.const 3.14))
[0219] ”'
[0220] The global segment after data reorganization includes:
[0221] -global data:
[0222] '20' (corresponds to the initial value of '$g1')
[0223] '3.14' (corresponds to the initial value of '$g2')
[0224] -global instance (created when the device loads):
[0225] "'c
[0226] struct GlobalInstance g1 = {20, false}; / / $g1: type i32, value 20, immutable
[0227] struct GlobalInstance g2 = {3.14, true}; / / $g2: type f64, value 3.14, variable
[0228] ”'
[0229] Data reorganization of the global segment not only reduces the file size, but also speeds up the initialization and access to global variables at runtime.
[0230] In the present application, the operation efficiency of the target executable file is improved by reorganizing (integrating) part or all of the data in the table segment, element segment, memory segment, data segment, and global data segment; the name string is removed by processing the import segment to optimize the occupied space; and the function call process is optimized by reorganizing the data of the function segment.
[0231] Furthermore, the computer terminal 100 is further used for:
[0232] The multi-byte code in the data segment is converted into a double-byte code by using the segment reorganization method of the data segment, wherein only the base address of the data represented by 2 bytes, the data length represented by 2 bytes and the initialization data part are retained in the data segment, and the redundant data in the rest part is cleared.
[0233] The embedded device 200 is used to store the target executable file in a non-volatile memory included in the embedded device 200 to run a target application based on the target executable file.
[0234] It can be understood that the target executable file includes multiple segments.
[0235] Furthermore, the embedded device 200 is also used to modify the offset address of each segment to the actual storage address in the non-volatile memory after storing the target executable file in the non-volatile memory, and store the actual storage address in the segment address table for query by the embedded device 200.
[0236] When processing each segment, the computer terminal 100 does not know the real storage address, so it gives each segment an offset address. After each segment is stored in the non-volatile memory, the corresponding actual address will be obtained, and the actual address will be stored in the segment address table, so as to quickly execute each functional segment at runtime, reduce address conversion at runtime, and improve operation efficiency.
[0237] The data processing method is described below in conjunction with some specific embodiments.
[0238] The present application also provides a data processing method. Exemplarily, the data processing method includes the following steps:
[0239] The target executable file is received and stored in a non-volatile memory included in the embedded device. The target executable file is obtained by processing the computer terminal 100 in the executable file processing system of the embodiment of the present application.
[0240] It can be understood that the method of this embodiment corresponds to the function implemented by the embedded device 200 in the executable file processing system of the above embodiment, and the optional items in the above embodiment are also applicable to this embodiment, so they will not be described repeatedly here.
[0241] The present application also provides an embedded device 200, which exemplarily includes a processor and a memory, wherein the memory stores a computer program, and the processor runs the computer program to enable the embedded device 200 to perform the above-mentioned data processing method or the function of the embedded device 200 in the above-mentioned executable file processing system. The embedded device 200 of the embodiment of the present application includes but is not limited to a smart card.
[0242] Among them, the processor can be an integrated circuit chip with signal processing capabilities. The processor can be a general-purpose processor, including a central processing unit (CPU), a graphics processing unit (GPU) and a network processor (NP), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or at least one of other programmable logic devices, discrete gates or transistor logic devices, and discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc., which can implement or execute the disclosed methods, steps and logic block diagrams in the embodiments of the present application.
[0243] The memory may be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), etc. The memory is used to store a computer program, and the processor may execute the computer program accordingly after receiving an execution instruction.
[0244] The present application also provides a computer-readable storage medium for storing the computer program used in the above-mentioned embedded device 200. For example, the computer-readable storage medium may include but is not limited to: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0245] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and structure diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in an alternative implementation, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the structure diagram and / or the flow diagram, and the combination of boxes in the structure diagram and / or the flow diagram, can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0246] In addition, the functional modules or units in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0247] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a smart phone, a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in the various embodiments of the present application.
[0248] The above description is only a specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application.
Claims
1. An executable file processing system, characterized in that: include: Embedded devices and computer terminals; The computer terminal is used to pre-process the executable file according to the first preset processing mode and the second preset processing mode to obtain a target executable file suitable for the embedded device; The embedded device is used to store the target executable file in a non-volatile memory included in the embedded device, so as to run a target application based on the target executable file.
2. The executable file processing system according to claim 1, characterized in that: The first preset processing method is selected from one of validity check, data structure reorganization processing and application download instruction processing, and the second preset processing method is selected from the other of the validity check, the data structure reorganization processing and the application download instruction processing.
3. The executable file processing system according to claim 1, characterized in that: The computer terminal is further used to match the target data reorganization method in the data reorganization methods of each preset file type according to the preset code in the executable file.
4. The executable file processing system according to claim 1, characterized in that: The target executable file includes a plurality of segments; The embedded device is also used to modify the offset address of each segment to the actual storage address in the non-volatile memory after storing the target executable file in the non-volatile memory, and store the actual storage address in the segment address table for query by the embedded device.
5. The executable file processing system according to any one of claims 1 to 4, characterized in that: If the first preset processing method or the second preset processing method is to perform validity check on the executable file; The computer terminal is specifically used to perform validity check on the executable file according to a preset file specification, using a preset tool or a preset programming language library.
6. The executable file processing system according to claim 3, characterized in that: The target data reorganization method includes multiple segment reorganization methods; The computer terminal is also specifically used for: Parsing the executable file according to a preset file specification to obtain at least one segment; According to the segment reorganization method corresponding to each segment, the data structure of each segment is reorganized to obtain the target executable file.
7. The executable file processing system according to claim 6, characterized in that: The at least one segment includes: at least one of an import segment and a function segment; The computer terminal is specifically used for: According to the identifier of each segment, obtain the corresponding segment reorganization method; Using the segment reorganization method of the import segment, sorting each import function in the import segment according to a preset order to obtain a corresponding index, and using the corresponding index to identify each import function; and / or, By utilizing the segment reorganization method of the function segment, target parameters are extracted from each parameter in the function segment according to the usage frequency of each parameter in the function segment, and the target parameters are used as the final parameters of the function segment; wherein the target parameters include parameter type and parameter number.
8. The executable file processing system according to claim 6 or 7, characterized in that: The at least one segment further comprises: at least one of a type segment, a table segment, an element segment, a memory segment, and a data segment; The computer terminal is specifically used for: Using the segment reorganization method of the type segment, converting the multi-byte code in the type segment into a single-byte code; and / or, Using the segment reorganization method of the table segment, converting the multi-byte code in the table segment into a single-byte code or a double-byte code; and / or, Using the segment reorganization method of the element segment, convert the multi-byte code in the element segment into a single-byte code or a double-byte code; integrating and storing the converted table segment and element segment; and / or, Using the segment reorganization method of the memory segment, obtaining the current number of pages, the maximum number of pages and the number of bytes per page in the memory segment; converting the current number of pages and the maximum number of pages into single-byte encoding, and converting the number of bytes per page into double-byte encoding; and / or, The multi-byte code in the data segment is converted into a double-byte code by utilizing the segment reorganization method of the data segment.
9. A data processing method, characterized in that: Applicable to embedded devices, the method comprises: Download the target executable file to the embedded device, and store it in the non-volatile memory included in the embedded device after address processing of the target executable file; the target executable file is obtained by processing the computer terminal in the executable file processing system described in any one of claims 1-8.
10. An embedded device, characterized in that: The embedded device comprises a processor and a memory, wherein the memory stores a computer program, and the processor is configured to execute the computer program to implement the data processing method described in claim 9.
Citation Information
Cited By
SD card starting method and device supporting file system, equipment and medium
CN119847621A