Disclosure of Invention
In order to overcome the defects of the prior art, the application provides a file processing method, a file processing device and a storage medium, so as to avoid the problem that one library file cannot be commonly used due to different delphi versions among different users, and further reduce the workload and the use limitation of upstream and downstream users.
In a first aspect, an embodiment of the present invention provides a file processing method applied to a second device, where the second device is installed with a delphi, and the method includes:
acquiring a binary data file, wherein the binary data file is obtained by converting a dynamic library file, and the dynamic library file is used for providing a first function which can be called;
introducing the binary data file into a first code file, wherein the first code file comprises a source code of a first delphi program or a first dcu library file written based on the delphi, the first code file is used for calling at least one second function, and the second function is contained in the first function;
respectively modifying the function entry address of the at least one second function in the first code file into the address of data corresponding to the at least one second function in the binary data file to obtain a second code file;
compiling the second code file based on the delphi to obtain a second delphi program or a second dcu library file.
Optionally, the method further comprises:
acquiring a third file, wherein the third file is used for indicating a mapping relation between a function name and a function sequence number of a first function provided by the dynamic library file;
determining a function sequence number corresponding to the function name of each second function based on the mapping relation;
and determining the address of the data corresponding to each of the at least one second function in the binary data file based on the function sequence number of each of the at least one second function.
Optionally, the third function is any one of the at least one second function;
determining, based on the function sequence number of each of the at least one second function, an address of data in the binary data file corresponding to each of the at least one second function, including:
determining a first position of the binary data file in a first code file after the binary data file is introduced;
determining a second position of data corresponding to the third function in the binary data file based on the function sequence number of the third function;
and determining the address of the data corresponding to the third function based on the first position and the second position.
Optionally, the binary data file is obtained by converting a dynamic library file by a first device using a conversion program, the third file is generated by the first device, and the first device is a device used by a developer of the dynamic library file.
Optionally, the first device does not need to be installed with a delphi, and the delphi installed on the second device is any version of delphi.
Optionally, the second delphi program or the second dcu library file can be independently delivered to a third device, and the second delphi program can run on the third device; or,
the second delphi program or the second dcu library file can be used on the third device to develop a third delphi program or a third dcu library file based on delphi.
Optionally, the dynamic library file is suitable for a Windows operating system.
In a second aspect, an embodiment of the present invention further provides a file processing apparatus, which is applied to a second device, where the second device is installed with a delphi, and the file processing apparatus includes:
the system comprises an acquisition module, a storage module and a control module, wherein the acquisition module is configured to acquire a binary data file, the binary data file is obtained by converting a dynamic library file, and the dynamic library file is used for providing a first function which can be called;
an importing module configured to import the binary data file into a first code file, the first code file including a source code of a first delphi program or a first dcu library file written based on the delphi, the first code file being used to call at least one second function, the second function being included in the first function;
the compiling module is configured to modify the function entry addresses of the at least one second function in the first code file into addresses of data corresponding to the at least one second function in the binary data file respectively to obtain a second code file; and compiling the second code file based on the delphi;
and the output module is configured to output the compiled second delphi program or the compiled second dcu library file.
In a third aspect, an embodiment of the present invention further provides an electronic device, where the electronic device includes a processor and a memory, and is further installed with a delphi; the memory has stored thereon predetermined computer instructions for execution by the processor to perform some or all of the steps of any of the methods of the first aspect.
In a fourth aspect, the embodiments of the present invention also provide a computer-readable storage medium, on which computer-executable instructions are stored, and when the computer-executable instructions are executed by a processor, part or all of the steps of any one of the methods of the first aspect are implemented.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the drawings of the embodiments of the present invention.
Some concepts arising in the embodiments of the present invention will be briefly described below.
delphi: a visual development tool can be used in environments such as Windows3.X, Windows95, Windows NT, Windows XP, Windows vista, Windows7, Windows8, Windows8.1, Windows10, Linux, OS X, iOS, Android and the like, adopts an object-oriented programming language ObjectPascal and a development structure frame based on components, and also provides various development tools including an integrated environment, a compiler, an Image editor (Image editor) and application programs of various development databases, such as desktop database explore and the like.
delphi program: the code written by Delphi is used, and the code can be compiled by a compiler in the Delphi to obtain an executable program. That is, the executable program developed using delphi is referred to herein as the delphi program.
dcu library file: library files developed using delphi, with delphi version information. Illustratively, the file suffix of the dcu library file may be.
Referring to fig. 1, fig. 1 is a schematic diagram of an exemplary application scenario for developing a dcu library file based on delphi. Among them, the device 1 is an electronic device used by a library file developer, the device 2 is an electronic device used by a downstream user, and the device 3 is an electronic device used by a downstream user (which may also be referred to as a downstream user) of the downstream user.
The devices 1, 2, 3 may include, but are not limited to, electronic devices such as mobile phones, tablet computers, Personal Computers (PCs), wearable devices, Augmented Reality (AR)/Virtual Reality (VR) devices, Personal Digital Assistants (PDAs), and the like, and the present application is not limited to a specific product form/type of the electronic device.
Delphi is installed in the device 1 and the device 2, respectively. The library file developer may compile a piece of compiled library code into a dcu library file (referred to as dcu library file 1 in this example for ease of distinction) with the delphi version information via a compiler in the delphi in the device (e.g., device 1) it uses. The dcu library file 1 may be delivered to downstream users. The downstream user may continue to develop or use the dcu library file 1 on the device (e.g., device 2) on which he is using, based on the delphi on device 2, to develop a delphi program (referred to as program 1 in this example for ease of distinction) or other dcu library files (referred to as dcu library file 2in this example for ease of distinction).
The installation of delphi on device 1 needs to be consistent with the delphi version installed on device 2 used by the downstream user. When the version information in the dcu library file 1 delivered to the downstream user by the library file developer is inconsistent with the delphi version used by the downstream user, the compiler of the delphi in the device 2 cannot compile the program code or library code written by the downstream user into a program (i.e., the program 1) or a dcu library file (i.e., the dcu library file 2) based on the dcu library file 1, and an error may occur. At this time, the downstream user often needs to feed back the error report condition to the library file developer, and the library file developer recompiles the source code by using the version-matched delphi and provides the version-matched dcu library file again, so that the downstream user can use the file normally. Since the library file developed by the library file developer may be provided to a plurality of different downstream users, when the versions of the delphi used by these downstream users are different, the library file developer needs to install a plurality of different versions of the delphi correspondingly in the device (e.g., device 1) used by the developer, and compile a plurality of dcu library files with different version information respectively so as to provide the dcu library files to different downstream users.
After developing the program 1 or the dcu library file 2, the downstream user may deliver it to a further downstream user together with the dcu library file 1. Further, the downstream user may directly run the program 1 on the device (e.g., the device 3) used by the downstream user, or, based on the delphi on the device 3, continue to develop or use the program 1 or the dcu library file 2 to develop a new delphi program (referred to as the program 2in this example for convenience of distinction) or other dcu library files (referred to as the dcu library file 3 in this example for convenience of distinction). It is understood that the downstream users may also deliver the products developed by the downstream users to the downstream users for use or development, and the process is similar to the foregoing process and will not be described herein again.
It can be seen that this approach can result in additional effort and cumbersome use limitations.
The invention provides a file processing method, a file processing device and a storage medium. The library file developer converts the dynamic library file into a binary data file and delivers the binary data file to a downstream user, so that the downstream user can avoid directly using the dcu library file, and the problem that the same dcu library file cannot be commonly used by the delphi versions of different users is avoided. By adopting the scheme, a library file developer can provide dcu library files with different versions for different users without installing delphi; downstream users may normally invoke library files provided by the library file developer based on any possible version of delphi. In addition, when the downstream user delivers the product to the downstream user, the dcu library file developed by the library file developer does not need to be delivered together. That is, with this scheme, the workload and the use restriction of the upstream and downstream can be reduced.
Referring to fig. 2, fig. 2 is a schematic diagram of an exemplary application scenario of the method provided in the embodiment of the present application.
The first device is an electronic device used by a library file developer. The first device may or may not have the delphi installed thereon, and the execution of the scheme is not affected whether the delphi is installed or not. The library file developer may use the electronic device to develop the dynamic library file, in which case the first device may have installed thereon the necessary development tools for developing the dynamic library file. Of course, the library file developer may also use other possible electronic devices to develop the dynamic library file.
The second device is an electronic device used by a downstream user. The second device is provided with the delphi, but the version of the delphi is not strictly required, and downstream users can select the version capable of meeting the requirements according to the actual requirements of the downstream users. That is, the delphi installed on the second device may be any possible version of delphi.
The third device is an electronic device used by a downstream user. It will be appreciated that when a further downstream user simply runs a product (e.g., a delphi program) delivered by the downstream user, there may be no requirement that a delphi be installed on the device. When a further downstream user needs to continue development based on the product (e.g., delphi program or dcu library file) delivered by the downstream user, delphi may also need to be installed on the third device.
The first device, the second device, and the third device may include, but are not limited to, electronic devices such as a mobile phone, a tablet Computer, a Personal Computer (PC), a wearable device, an Augmented Reality (AR)/Virtual Reality (VR) device, a Personal Digital Assistant (PDA), and the like, and the application is not limited to a specific product form/type of the electronic device.
It should be understood that fig. 2 is only an exemplary architecture, and in some cases, other necessary devices may be further included in the architecture, which is not limited in this application.
The method of the embodiment of the present invention will be explained in detail with reference to fig. 3 to 4.
A first aspect of the present invention, as shown in fig. 3, provides a file processing method, which can be applied to the aforementioned second device. The method may include steps S10-S40.
Step S10, a binary data file is obtained, where the binary data file is obtained by converting a dynamic library file, and the dynamic library file is used to provide a first function that can be called.
Dynamic library files, in general, may contain functions and/or resources, etc. that allow the program to operate. Illustratively, the dynamic library files under the Windows system contain many functions and resources that allow Windows-based programs to operate in the Windows environment. In Windows, dynamic library files are mostly files with dll extensions; in the Linux system, dynamic library files are mostly files with the.so extension.
The dynamic library file in the embodiment of the present application is a file developed by a library file developer. In some exemplary embodiments, one or more functions are included in the dynamic library file, and different functions may be used to implement the same or different functions. These functions may be preset by the library file developer. For convenience of distinction and description, in the embodiment of the present application, a function that can be called and is provided in a certain dynamic library file is referred to as a first function, and the dynamic library file is also used as an example to describe the file processing method provided in the present application.
In some exemplary embodiments, a development tool suitable for the Windows operating system is installed on the first device, and the dynamic library file can be developed through the development tool. The development tool may be a prior art tool for developing dynamic libraries, such as a visualstudio or the like.
A binary data file generally refers to a file containing data or program instructions written in ASCII and extended ASCII characters.
In embodiments of the present application, a library file developer may convert a dynamic library file into a corresponding binary data file on a first device. The functions that can be implemented by the binary data file are consistent with the corresponding dynamic library file.
Illustratively, the dynamic library file generated by the library file developer through the development tool under the Windows system may be a dynamic library file suffixed with dll, and the dynamic library file is converted into a binary data file through a conversion program such as dll2 Inc.
The binary data file may be delivered to downstream users by the library file developer in any possible manner. In some implementations, the library file developer may use an electronic device (e.g., the aforementioned first device) to communicate the binary data file over a network to a second device used by a downstream user to complete the delivery. In other implementations, the library file developer may also implement the delivery by a copy of the storage medium, among other possible ways. When the downstream user needs to use the binary data file on the second device, the binary data file is retrieved from the storage medium.
In some implementations, the library file developer may further generate a third file on the first device, where the third file is used to indicate a mapping relationship between a function name and a function sequence number of the first function provided by the dynamic library file. At the time of delivery, the library file developer may deliver the third file to the downstream user, either along with the binary data file or separately, for use by the downstream user.
Step S20, introducing the binary data file into a first code file, where the first code file includes a source code of a first delphi program or a first dcu library file written based on the delphi, and the first code file is used to call at least one second function, where the second function is included in the first function.
The downstream user may write code to develop a delphi program or a dcu library file based on the delphi installed on the second device or possibly other devices. These delphi programs or dcu library files may need to call library files provided by the library file developer. The downstream user can call one or more functions in the library file according to different requirements.
For convenience of distinguishing and describing, a certain delphi program which needs to call the dynamic library file is called a first delphi program, and a certain dcu library file which needs to call the dynamic library file is called a first dcu library file; the function in the dynamic library file called by the first delphi program or the first dcu library file is referred to as a second function. It is understood that the second function is necessarily a function of the first function included in the dynamic library file, that is, the second function is included in the first function.
In some exemplary embodiments, the first code file contains the source code of a first delphi program or a first dcu library file developed by a downstream user using delphi. It will be appreciated that the first code file includes a code segment therein for invoking at least one second function, such that the first code file can be used to invoke the at least one second function.
In some exemplary embodiments, the binary data file may be introduced by adding a piece of functional code in the first code file. For example, the first code file may be the source code of a program a developed by a downstream user using delphi, adding an Include () code or { $ I binary. inc file } code to the program a code, etc., in such a way that a binary data file can be introduced into the program a code. It will be appreciated that the second device may also employ other possible implementations for introducing the binary data file into the first code file.
Step S30, modifying the function entry address of the at least one second function in the first code file into an address of data corresponding to the at least one second function in the binary data file, respectively, to obtain a second code file.
As mentioned before, the first code file comprises a code section for calling at least one second function, wherein function entry addresses for these second functions are referred to. The function address entries for these second functions may be written based on the manner in which the dynamic library file is called. After the dynamic library file is converted into a binary data file and introduced into the first code file, the function address entries of the second functions need to be modified accordingly to obtain a second code file. Therefore, the corresponding second function can be called smoothly when the product compiled based on the second code file is executed subsequently.
In some exemplary embodiments, the dynamic library file generated by the library file developer is preset with a mapping relationship between the function sequence number and the function name, and the mapping relationship is still maintained when the dynamic library file is converted into the binary data file. The mapping relation enables the second device to determine the address of the data corresponding to the second function in the binary data file according to the mapping relation, and further modify the function entry address of the second function into the address of the corresponding data.
In some exemplary embodiments, referring to fig. 4, the method performed by the second device may further include the following steps S50 to S70 to determine an address of data corresponding to the second function in the binary data file.
Step S50, a third file is obtained, where the third file is used to indicate a mapping relationship between a function name and a function sequence number of the first function provided by the dynamic library file.
In some exemplary embodiments, since the mapping relationship between the reserved function sequence number and the function name may not be directly read by the delphi on the second device, or the second device cannot determine which data block corresponds to which first function only according to the binary data file, a file for indicating the mapping relationship may be additionally added to cooperate with the binary data file for delivery.
Step S60, determining a function number corresponding to the function name of each of the at least one second function based on the mapping relationship.
Step S70, determining, based on the function serial number of each of the at least one second function, an address of data corresponding to each of the at least one second function in the binary data file.
In some exemplary embodiments, the second device may determine a function name of the second function referred to in the first code file based on the first code file. After the second device acquires the binary data file and the third file, function serial numbers corresponding to the function names of the second functions can be respectively determined based on the third file; and then determining the data blocks corresponding to the second functions from the binary data file based on the function serial numbers respectively, and further determining the addresses of the data corresponding to the second functions respectively.
In some exemplary embodiments, the third file may be a pas file, the pas file is generated by a library file developer and then delivered to a downstream user, the file has a Memory dll Loading Code mode, a function name may be obtained through getFunAddress, a corresponding function serial number may be determined through the function name, and an address of a function corresponding to one function serial number in the binary data file may be determined through @ Func ═ getFunAddress (PAnsiChar (serial number)).
In some exemplary embodiments, for convenience of differentiation and description, a function set called by a downstream user (i.e., any one of a set of second functions, referred to as a third function) may be used, where for each third function, it is necessary to determine an address of binary data corresponding to the third function, and then modify an entry address of the function in the first code file into an address of binary data corresponding to the function.
In one exemplary implementation, the method may include the following steps:
s701, determining a first position of a binary data file in a first code file after the binary data file is introduced;
s702, determining a second position of data corresponding to a third function in a binary data file based on the function serial number of the third function;
s703, determining an address of the data corresponding to the third function based on the first location and the second location.
Illustratively, following the aforementioned first code file as an example of the program a code, after introducing the binary data file, the downstream user can first determine the location of the binary data file in the entire program a code, then, based on the mapping relationship between the function serial number and the function name existing in the third function, can determine the location of the binary data corresponding to the third function in the binary data file, and finally, according to the two locations that can be determined, obtain the address of the binary data corresponding to the third function in the entire program a code.
It should be understood that, in the embodiment of the present application, the order between steps S50 to S70 and other steps is not limited as long as the steps are not logically contradictory. For example, the step S50 may be executed before or after the step S10, or may be executed simultaneously with the step S10. Also illustratively, steps S60 and S70 are necessarily performed after step S10, and are necessarily performed before step S40. Further exemplarily, step S701 is performed after step S20, and may be performed before or after S50 and S60, or may be performed simultaneously therewith.
And step S40, compiling the second code file based on the delphi to obtain a second delphi program or a second dcu library file.
The encoding and decoding based on delphi may be implemented by any encoding and decoding method available in the prior art, which is not limited in this application. The compiled delphi program or dcu library file can be realized by downstream users according to actual service requirements when compiling the first code file and/or compiling.
In some exemplary embodiments, after obtaining the second delphi program or the second dcu library file with the functions developed by the downstream user, etc., the downstream user may also pay the second delphi program or the second dcu library file separately to the downstream user without having to pay the dynamic library file, the binary data file, or the third file together to the downstream user.
The downstream user may run the second delphi program on a third device used by the downstream user, or continue to develop other programs or library files, such as a third delphi program or a third dcu file, based on the second delphi program or the second dcu library file. When the second delphi program or the second dcu library file is executed or called, the electronic device, such as a computer, may directly load the binary data file into the memory of the second delphi program or the program calling the second dcu library file for execution, and does not need to release the binary data file or the dynamic library file to the local computer.
It will be appreciated that when further downstream users need to continue development, the third device they use will need to have the necessary development tools installed. Especially, when a downstream user needs to call the second dcu library file, the third device used by the downstream user needs to install the delphi, and the version of the delphi installed in the third device needs to be consistent with that of the delphi in the second device.
It will also be appreciated that the programs that are being developed by downstream users may be delphi programs, or may be other types of programs, and the library files that are being developed may be dcu library files, or may be other types of library files.
A second aspect of the present invention, as shown in fig. 5, provides a document processing apparatus applied to a second device having a delphi mounted thereon, the document processing apparatus comprising:
the system comprises an acquisition module, a storage module and a control module, wherein the acquisition module is configured to acquire a binary data file, the binary data file is obtained by converting a dynamic library file, and the dynamic library file is used for providing a first function which can be called;
an importing module configured to import the binary data file into a first code file, the first code file including a source code of a first delphi program or a first dcu library file written based on the delphi, the first code file being used to call at least one second function, the second function being included in the first function;
the compiling module is configured to modify the function entry addresses of the at least one second function in the first code file into addresses of data corresponding to the at least one second function in the binary data file respectively to obtain a second code file; and compiling the second code file based on the delphi;
and the output module is configured to output the compiled second delphi program or the compiled second dcu library file.
Optionally, the obtaining module may be further configured to: acquiring a third file, wherein the third file is used for indicating a mapping relation between a function name and a function sequence number of a first function provided by the dynamic library file;
the processing apparatus further comprises: and determining a module. The determination module may be configured to: determining a function sequence number corresponding to the function name of each second function based on the mapping relation; and determining the address of the data corresponding to each of the at least one second function in the binary data file based on the function sequence number of each of the at least one second function.
Optionally, the determining module may be further configured to: determining a first position of the binary data file in a first code file after the binary data file is introduced; determining a second position of data corresponding to the third function in the binary data file based on the function sequence number of the third function; and determining the address of the data corresponding to the third function based on the first position and the second position. Wherein the third function is any one of the at least one second function.
Parts of the processing apparatus have the same characteristics as those of the processing method, and reference may be made to the description related to the foregoing method embodiments, which are not repeated herein.
In a third aspect of the invention, an electronic device is provided that includes a processor and a memory. Delphi is installed on the electronic equipment. The memory has stored thereon predetermined computer instructions for execution by the processor to perform some or all of the steps of any of the foregoing method embodiments.
In a fourth aspect of the present invention, there is provided a computer-readable storage medium having stored thereon computer-executable instructions which, when executed by a processor, implement some or all of the steps of any of the file processing methods described above.
In some embodiments, a processor executing computer-executable instructions may be a processing device including more than one general-purpose processing device, such as a microprocessor, Central Processing Unit (CPU), Graphics Processing Unit (GPU), or the like. More specifically, the processor may be a Complex Instruction Set Computing (CISC) microprocessor, Reduced Instruction Set Computing (RISC) microprocessor, Very Long Instruction Word (VLIW) microprocessor, processor running other instruction sets, or processors running a combination of instruction sets. The processor may also be one or more special-purpose processing devices such as an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA), a Digital Signal Processor (DSP), system on chip (SoC), or the like.
In some embodiments, the computer-readable storage medium may be a memory, such as a read-only memory (ROM), a random-access memory (RAM), a phase-change random-access memory (PRAM), a static random-access memory (SRAM), a dynamic random-access memory (DRAM), an electrically erasable programmable read-only memory (EEPROM), other types of random-access memory (RAM), a flash disk or other form of flash memory, a cache, a register, a static memory, a compact disc read-only memory (CD-ROM), a Digital Versatile Disc (DVD) or other optical storage, a tape cartridge or other magnetic storage device, or any other potentially non-transitory medium that may be used to store information or instructions that may be accessed by a computer device, and so forth.
In some embodiments, the computer-executable instructions may be implemented as a plurality of program modules that collectively implement the document processing method according to any one of the present disclosure.
The present disclosure describes various operations or functions that may be implemented as or defined as software code or instructions.
Such content may be source code or differential code ("delta" or "patch" code) that may be executed directly ("object" or "executable" form). A software implementation of the embodiments described herein may be provided through an article of manufacture having code or instructions stored thereon, or through a method of operating a communication interface to transmit data through the communication interface. A machine or computer-readable storage medium may cause a machine to perform the functions or operations described, and includes any mechanism for storing information in a form accessible by a machine (e.g., a computing display device, an electronic system, etc.), such as recordable/non-recordable media (e.g., Read Only Memory (ROM), Random Access Memory (RAM), magnetic disk storage media, optical storage media, flash memory display devices, etc.). The communication interface includes any mechanism for interfacing with any of a hardwired, wireless, optical, etc. medium to communicate with other display devices, such as a memory bus interface, a processor bus interface, an internet connection, a disk controller, etc. The communication interface may be configured by providing configuration parameters and/or transmitting signals to prepare the communication interface to provide data signals describing the software content. The communication interface may be accessed by sending one or more commands or signals to the communication interface.
The computer-executable instructions of embodiments of the present disclosure may be organized into one or more computer-executable components or modules. Aspects of the disclosure may be implemented with any number and combination of such components or modules. For example, aspects of the disclosure are not limited to the specific computer-executable instructions or the specific components or modules illustrated in the figures and described herein. Other embodiments may include different computer-executable instructions or components having more or less functionality than illustrated and described herein.
It is to be understood that, unless defined otherwise, technical or scientific terms used herein have the ordinary meaning as understood by one of ordinary skill in the art to which this application belongs. As used in this application, the terms "first," "second," and the like do not denote any order, quantity, or importance, but rather are used to distinguish one element from another. The word "comprising" or "comprises", and the like, means that the element or item appearing before the word covers the element or item listed after the word and its equivalents, but does not exclude other elements or items. The terms "connected" or "coupled" and the like are not restricted to physical or mechanical connections, but may also include electrical connections, whether direct or indirect.
It should be understood that the above embodiments are only exemplary embodiments of the present disclosure, and are not intended to limit the present disclosure, the scope of which is defined by the claims. Various modifications and equivalents of the disclosure may occur to those skilled in the art within the spirit and scope of the disclosure, and such modifications and equivalents are considered to be within the scope of the disclosure.