CN114327482A - Application format conversion method, device, equipment and storage medium - Google Patents

Application format conversion method, device, equipment and storage medium Download PDF

Info

Publication number
CN114327482A
CN114327482A CN202111657812.XA CN202111657812A CN114327482A CN 114327482 A CN114327482 A CN 114327482A CN 202111657812 A CN202111657812 A CN 202111657812A CN 114327482 A CN114327482 A CN 114327482A
Authority
CN
China
Prior art keywords
class
information
static
current
format conversion
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111657812.XA
Other languages
Chinese (zh)
Inventor
何杰
江俊
周杰
胡瑞璟
董逢华
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuhan Tianyu Information Industry Co Ltd
Original Assignee
Wuhan Tianyu Information Industry Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuhan Tianyu Information Industry Co Ltd filed Critical Wuhan Tianyu Information Industry Co Ltd
Priority to CN202111657812.XA priority Critical patent/CN114327482A/en
Publication of CN114327482A publication Critical patent/CN114327482A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Devices For Executing Special Programs (AREA)
  • Stored Programmes (AREA)

Abstract

The invention discloses an application format conversion method, an application format conversion device, application format conversion equipment and a storage medium, wherein the method comprises the steps of extracting constant pool information and class information from a class file according to preset parameters; acquiring inheritance relationships among classes, interfaces and methods in the class file, and determining Java method byte codes according to the constant pool information, the class information and the inheritance relationships; the Java method byte codes are converted into the target files corresponding to the languages to be converted, the compiled application files can be quickly converted into files in the specified format without recompilation, development cost is saved, format conversion speed is increased, conversion efficiency is high, adaptability is strong, and use experience is improved.

Description

Application format conversion method, device, equipment and storage medium
Technical Field
The invention relates to the technical field of smart card virtual machines, in particular to an application format conversion method, device, equipment and storage medium.
Background
Currently, the Java Card technology is a Java technology for smart cards, is a general-purpose programming platform for smart cards, and is used as a programming platform based on a virtual machine.
The compilation language used by the Applet (Applet) of the Java Card is Java language, which is suitable for being used on a Java virtual machine, but when the application needs to be transplanted to another type of virtual machine for use, the application needs to be recompiled to be used, so that a lot of unnecessary development burden and development cost are brought to developers.
Disclosure of Invention
The invention mainly aims to provide an application format conversion method, device, equipment and storage medium, and aims to solve the technical problems that in the prior art, when a Java Card compiling language application is applied to other virtual machines except a Java virtual machine, an application program needs to be recompiled, time and labor are wasted, development and research costs are high, and use experience is poor.
In a first aspect, the present invention provides an application format conversion method, including the steps of:
extracting constant pool information and class information from the class file according to preset parameters;
acquiring inheritance relationships among classes, interfaces and methods in the class file, and determining Java method byte codes according to the constant pool information, the class information and the inheritance relationships;
and converting the Java method byte codes into target files corresponding to the languages to be converted.
Optionally, the extracting constant pool information and class information from the input class file according to the preset parameter includes:
reading a class file from the JavaApplet according to a conversion tool, and obtaining a class file structure from preset parameters;
and analyzing constant pool information and class information from the class file according to the class file structure.
Optionally, the parsing out the constant pool information and the class information from the class file according to the class file structure includes:
analyzing the number of constant pools from the class file according to the class file structure, establishing a constant pool storage table, and taking the constant pool storage table as constant pool information;
obtaining an index value of a description class from the constant pool storage table, and analyzing the index value into corresponding character string description class information;
analyzing index values in domains, methods and interfaces in the classes into pre-inheritance relationship information before character string description;
and determining the class information according to the character string description class information and the pre-inheritance relationship information.
Optionally, the determining the class information according to the character string description class information and the pre-inheritance relationship information includes:
analyzing a parent class in the class from the class file according to the character string description class information and the pre-inheritance relationship information;
analyzing the number of interfaces of the class, the index of the interfaces, the static member variables and the non-static member variables of the domain, the attribute of the class method, the byte code implementation method and the additional attribute table from the class file;
and taking the interface number, the interface index, the static member variable, the non-static member variable, the class method attribute, the byte code implementation method and the additional attribute table as class information.
Optionally, the obtaining an inheritance relationship among classes, interfaces, and methods in the class file, and determining Java method bytecodes according to the constant pool information, the class information, and the inheritance relationship include:
determining the inheritance relationship among the class, the method and the interface of the class file according to the pre-inheritance relationship information before the description of the character string;
judging whether the current class has a parent class or not according to the inheritance relationship, the constant pool information and the class information;
when the current class has a parent class, determining an output mode of the current class, and determining a member function of the current class according to the output mode;
and extracting corresponding Java method byte codes from the class file according to the member functions.
Optionally, when the parent class exists in the current class, determining an output mode of the current class, and determining a member function of the current class according to the output mode includes:
when the current class has a parent class and the class method attribute is static, establishing a static method table of the top level parent class;
when the current class has a parent class and the class method attribute is non-static, establishing a virtual method table of the top level parent class;
adding the static member variable of the current class into a class variable table, and adding the non-static variable of the current class into a class instance variable;
when the current class has a subclass, recording the method of the current subclass and the number of variables in the subclass, copying the method and the variables of the parent class into a current subclass method table, and storing the method of the current subclass and the number of the variables in the subclass;
marking the interface method in the current virtual method table;
outputting a member function statement corresponding to the current class, a static variable structure corresponding to the static method table, a virtual method structure corresponding to the virtual method table, an example structure corresponding to the example variable, a static variable initialization function, a loading initialization function, a construction function and a class static domain initialization function corresponding to the current class;
and generating the member function corresponding to the current class according to the member function statement, the static variable structure, the virtual method structure, the instance structure, the static variable initialization function, the loading initialization function, the constructor and the class static domain initialization function.
Optionally, the converting the Java method bytecode into a target file corresponding to a language to be converted includes:
when the class method attribute is static, converting the Java method byte codes into a target file corresponding to the language to be converted by using a unique function name through a conversion tool;
and when the class method attribute is non-static, converting the Java method byte codes into a target file corresponding to the language to be converted by using the unique function name through a conversion tool.
In a second aspect, to achieve the above object, the present invention further provides an application format conversion apparatus, including:
the information extraction module is used for extracting constant pool information and class information from the class file according to preset parameters;
the bytecode determining module is used for acquiring inheritance relationships among classes, interfaces and methods in the class file and determining Java method bytecodes according to the constant pool information, the class information and the inheritance relationships;
and the format conversion module is used for converting the Java method byte codes into target files corresponding to the languages to be converted.
In a third aspect, to achieve the above object, the present invention further provides an application format conversion device, including: a memory, a processor and an application format conversion program stored on the memory and executable on the processor, the application format conversion program being configured to implement the steps of the application format conversion method as described above.
In a fourth aspect, to achieve the above object, the present invention further provides a storage medium, on which an application format conversion program is stored, and the application format conversion program, when executed by a processor, implements the steps of the application format conversion method as described above.
The application format conversion method provided by the invention extracts constant pool information and class information from a class file according to preset parameters; acquiring inheritance relationships among classes, interfaces and methods in the class file, and determining Java method byte codes according to the constant pool information, the class information and the inheritance relationships; the Java method byte codes are converted into the target files corresponding to the languages to be converted, the compiled application files can be quickly converted into files in the specified format without recompilation, development cost is saved, format conversion speed is increased, conversion efficiency is high, adaptability is strong, and use experience is improved.
Drawings
FIG. 1 is a schematic diagram of an apparatus architecture of a hardware operating environment according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating a first embodiment of a format conversion method according to the present invention;
FIG. 3 is a flowchart illustrating a format conversion method according to a second embodiment of the present invention;
FIG. 4 is a flowchart illustrating a third embodiment of a format conversion method according to the present invention;
FIG. 5 is a flowchart illustrating a fourth embodiment of a format conversion method according to the present invention;
FIG. 6 is a flowchart illustrating a fifth embodiment of a format conversion method according to the present invention;
FIG. 7 is a flowchart illustrating class startup loading in the application format conversion method according to the present invention;
FIG. 8 is a functional block diagram of a first embodiment of an apparatus for converting an application format according to the present invention.
The implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
The solution of the embodiment of the invention is mainly as follows: extracting constant pool information and class information from the class file according to preset parameters; acquiring inheritance relationships among classes, interfaces and methods in the class file, and determining Java method byte codes according to the constant pool information, the class information and the inheritance relationships; the Java method byte codes are converted into the target files corresponding to the languages to be converted, the compiled application files can be quickly converted into files in the specified format without recompilation, development cost is saved, format conversion speed is increased, conversion efficiency is high, adaptability is strong, use experience is improved, and the technical problems that when the Java Card compiling language is applied to other virtual machines except a Java virtual machine in the prior art, the application program needs to be recompiled, time and labor are wasted, development cost is high, and use experience is poor are solved.
Referring to fig. 1, fig. 1 is a schematic device structure diagram of a hardware operating environment according to an embodiment of the present invention.
As shown in fig. 1, the apparatus may include: a processor 1001, such as a CPU, a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Wherein a communication bus 1002 is used to enable connective communication between these components. The user interface 1003 may include a Display screen (Display), an input unit such as a Keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., a Wi-Fi interface). The Memory 1005 may be a high-speed RAM Memory or a Non-Volatile Memory (Non-Volatile Memory), such as a disk Memory. The memory 1005 may alternatively be a storage device separate from the processor 1001.
Those skilled in the art will appreciate that the configuration of the apparatus shown in fig. 1 is not intended to be limiting of the apparatus and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
As shown in fig. 1, a memory 1005, which is a storage medium, may include therein an operating system, a network communication module, a user interface module, and an application format conversion program.
The apparatus of the present invention calls an application format conversion program stored in the memory 1005 through the processor 1001, and performs the following operations:
extracting constant pool information and class information from the class file according to preset parameters;
acquiring inheritance relationships among classes, interfaces and methods in the class file, and determining Java method byte codes according to the constant pool information, the class information and the inheritance relationships;
and converting the Java method byte codes into target files corresponding to the languages to be converted.
The apparatus of the present invention calls the application format conversion program stored in the memory 1005 by the processor 1001, and also performs the following operations:
reading a class file from the JavaApplet according to a conversion tool, and obtaining a class file structure from preset parameters;
and analyzing constant pool information and class information from the class file according to the class file structure.
The apparatus of the present invention calls the application format conversion program stored in the memory 1005 by the processor 1001, and also performs the following operations:
analyzing the number of constant pools from the class file according to the class file structure, establishing a constant pool storage table, and taking the constant pool storage table as constant pool information;
obtaining an index value of a description class from the constant pool storage table, and analyzing the index value into corresponding character string description class information;
analyzing index values in domains, methods and interfaces in the classes into pre-inheritance relationship information before character string description;
and determining the class information according to the character string description class information and the pre-inheritance relationship information.
The apparatus of the present invention calls the application format conversion program stored in the memory 1005 by the processor 1001, and also performs the following operations:
analyzing a parent class in the class from the class file according to the character string description class information and the pre-inheritance relationship information;
analyzing the number of interfaces of the class, the index of the interfaces, the static member variables and the non-static member variables of the domain, the attribute of the class method, the byte code implementation method and the additional attribute table from the class file;
and taking the interface number, the interface index, the static member variable, the non-static member variable, the class method attribute, the byte code implementation method and the additional attribute table as class information.
The apparatus of the present invention calls the application format conversion program stored in the memory 1005 by the processor 1001, and also performs the following operations:
determining the inheritance relationship among the class, the method and the interface of the class file according to the pre-inheritance relationship information before the description of the character string;
judging whether the current class has a parent class or not according to the inheritance relationship, the constant pool information and the class information;
when the current class has a parent class, determining an output mode of the current class, and determining a member function of the current class according to the output mode;
and extracting corresponding Java method byte codes from the class file according to the member functions.
The apparatus of the present invention calls the application format conversion program stored in the memory 1005 by the processor 1001, and also performs the following operations:
when the current class has a parent class and the class method attribute is static, establishing a static method table of the top level parent class;
when the current class has a parent class and the class method attribute is non-static, establishing a virtual method table of the top level parent class;
adding the static member variable of the current class into a class variable table, and adding the non-static variable of the current class into a class instance variable;
when the current class has a subclass, recording the method of the current subclass and the number of variables in the subclass, copying the method and the variables of the parent class into a current subclass method table, and storing the method of the current subclass and the number of the variables in the subclass;
marking the interface method in the current virtual method table;
outputting a member function statement corresponding to the current class, a static variable structure corresponding to the static method table, a virtual method structure corresponding to the virtual method table, an example structure corresponding to the example variable, a static variable initialization function, a loading initialization function, a construction function and a class static domain initialization function corresponding to the current class;
and generating the member function corresponding to the current class according to the member function statement, the static variable structure, the virtual method structure, the instance structure, the static variable initialization function, the loading initialization function, the constructor and the class static domain initialization function.
The apparatus of the present invention calls the application format conversion program stored in the memory 1005 by the processor 1001, and also performs the following operations:
when the class method attribute is static, converting the Java method byte codes into a target file corresponding to the language to be converted by using a unique function name through a conversion tool;
and when the class method attribute is non-static, converting the Java method byte codes into a target file corresponding to the language to be converted by using the unique function name through a conversion tool.
According to the scheme, the constant pool information and the class information are extracted from the class file according to the preset parameters; acquiring inheritance relationships among classes, interfaces and methods in the class file, and determining Java method byte codes according to the constant pool information, the class information and the inheritance relationships; the Java method byte codes are converted into the target files corresponding to the languages to be converted, the compiled application files can be quickly converted into files in the specified format without recompilation, development cost is saved, format conversion speed is increased, conversion efficiency is high, adaptability is strong, and use experience is improved.
Based on the hardware structure, the embodiment of the application format conversion method is provided.
Referring to fig. 2, fig. 2 is a flowchart illustrating a first embodiment of the format conversion method according to the present invention.
In a first embodiment, the application format conversion method includes the steps of:
and step S10, extracting constant pool information and class information from the class file according to the preset parameters.
It should be noted that, the constant pool information and the class information may be extracted from the input class file according to the preset parameters, that is, the information related to the constant pool and the class is extracted from the already compiled class file.
And step S20, acquiring the inheritance relationship among the classes, the interfaces and the methods in the class file, and determining Java method byte codes according to the constant pool information, the class information and the inheritance relationship.
It is understood that the inheritance relationship is a relationship describing inheritance relationships among classes, methods and interfaces, and Java method bytecodes can be quickly determined from the class file through the constant pool information, the class information and the inheritance relationships.
And step S30, converting the Java method byte codes into target files corresponding to the languages to be converted.
It should be understood that, in different application scenarios, the Java method bytecode may be quickly converted into a target file corresponding to a language to be converted, where a general target file may be a C file, that is, conversion from Java to C language is implemented, so that a technician can conveniently and quickly perform application operations, different languages to be converted correspond to different target files, the language to be converted is a target language in which a current Java language is converted into an application format that needs to be converted, the language to be converted may be Python language, may also be a database development language, such as SQL, Visual Basic, Access, and other language types, and may also be other languages to be converted, which is not limited in this embodiment.
According to the scheme, the constant pool information and the class information are extracted from the class file according to the preset parameters; acquiring inheritance relationships among classes, interfaces and methods in the class file, and determining Java method byte codes according to the constant pool information, the class information and the inheritance relationships; the Java method byte codes are converted into the target files corresponding to the languages to be converted, the compiled application files can be quickly converted into files in the specified format without recompilation, development cost is saved, format conversion speed is increased, conversion efficiency is high, adaptability is strong, and use experience is improved.
Further, fig. 3 is a flowchart illustrating a second embodiment of the application format conversion method of the present invention, and as shown in fig. 3, the second embodiment of the application format conversion method of the present invention is provided based on the first embodiment, and in this embodiment, the step S10 specifically includes the following steps:
and step S11, reading the class file from the JavaApplet according to the conversion tool, and obtaining the class file structure from preset parameters.
It should be noted that the class file compiled in the JavaApplet is read through the conversion tool, that is, the class file is read from the JavaApplet according to the conversion tool, and the class file structure is obtained from the preset parameters.
And step S12, resolving constant pool information and class information from the class file according to the class file structure.
It can be understood that constant pool information and class information, i.e. constant pool related information and class related information, are parsed from the class file by the class file structure.
According to the scheme, the class file is read from the JavaApplet through the conversion tool, and the class file structure is obtained from the preset parameters; constant pool information and class information can be quickly analyzed from the class file according to the class file structure, the constant pool information and the class information can be quickly analyzed from the class file, a basis is provided for subsequent format conversion, and the speed and the efficiency of application format conversion are further improved.
Further, fig. 4 is a flowchart illustrating a third embodiment of the application format conversion method of the present invention, and as shown in fig. 4, the third embodiment of the application format conversion method of the present invention is provided based on the second embodiment, in this embodiment, the step S12 specifically includes the following steps:
and step S121, resolving the number of constant pools from the class file according to the class file structure, establishing a constant pool storage table, and taking the constant pool storage table as constant pool information.
It should be noted that the number of constant pools is parsed from the class file according to the class file structure, a constant pool storage table is established, that is, the number of constant pools is parsed according to the class file structure, a constant pool storage table is established, and the constant pool storage table can be used as constant pool information.
And step S122, obtaining the index value of the description class from the constant pool storage table, and analyzing the index value into corresponding character string description class information.
It can be understood that, the index value of the description class is obtained from the constant pool storage table, and the index value in the constant pool table related to the description class is resolved into corresponding related character string description information, that is, character string description class information, so as to describe the character name of the current class.
And S123, resolving index values in the domains, methods and interfaces in the classes into pre-inheritance relationship information before character string description.
It should be understood that resolving index values in domains, methods and interfaces in a class into specific character string description information may be used to describe inheritance relationships before classes, methods and interfaces, i.e. resolving into inheritance relationship information before character string description.
And step S124, determining class information according to the character string description class information and the pre-inheritance relationship information.
It is understood that the class information and the related information that can determine the class, i.e., the determination class information, are described according to the character string.
Further, the step S124 specifically includes the following steps:
analyzing a parent class in the class from the class file according to the character string description class information and the pre-inheritance relationship information;
analyzing the number of interfaces of the class, the index of the interfaces, the static member variables and the non-static member variables of the domain, the attribute of the class method, the byte code implementation method and the additional attribute table from the class file;
and taking the interface number, the interface index, the static member variable, the non-static member variable, the class method attribute, the byte code implementation method and the additional attribute table as class information.
It should be understood that, parsing out the parent class in the class from the class file structure can record the parent class of the current class; analyzing the interface number and the interface index in the class from the class file structure; resolving the character string description information according to the index value in the constant pool; resolving a domain in a class from a class file structure, wherein the domain generally comprises static and non-static member variables, and resolving corresponding character string description information according to an index value in a constant pool; analyzing a method in a class from a class file structure, wherein the class method comprises method attribute and byte code realization; according to the packet name, the class name, the method parameter type and the return value, determining the uniqueness of the function corresponding to the C according to the partial field; and parsing an additional attribute table from the class file structure, wherein the additional attribute table is used for describing the name of the current class file.
According to the scheme, the number of constant pools is analyzed from the class file according to the structure of the class file, a constant pool storage table is established, and the constant pool storage table is used as constant pool information; obtaining an index value of a description class from the constant pool storage table, and analyzing the index value into corresponding character string description class information; analyzing index values in domains, methods and interfaces in the classes into pre-inheritance relationship information before character string description; determining class information according to the character string description class information and the pre-inheritance relationship information, and quickly analyzing constant pool information and class information from the class file to provide a basis for subsequent format conversion, thereby further improving the speed and efficiency of application format conversion.
Further, fig. 5 is a schematic flowchart of a fourth embodiment of the application format conversion method of the present invention, and as shown in fig. 5, the fourth embodiment of the application format conversion method of the present invention is provided based on the first embodiment, and in this embodiment, the step S20 specifically includes the following steps:
and step S21, determining the inheritance relationship among the class, the method and the interface of the class file according to the pre-inheritance relationship information.
It should be noted that, the inheritance relationship between the class, the method and the interface in the class file can be determined according to the pre-inheritance relationship information before the description of the character string.
And step S22, judging whether the current class has a parent class according to the inheritance relationship, the constant pool information and the class information.
It can be understood that whether a parent class exists in the current class in the classes can be judged according to the inheritance relationship, the constant pool information and the class information.
And step S23, when the parent class exists in the current class, determining the output mode of the current class, and determining the member function of the current class according to the output mode.
It should be understood that, when the current class has a parent class, the method may recursively jump to the constant pool and the step of class information confirmation, and restore class and interface related information to the storage structure table, thereby determining an output mode of the current class, and determining a member function of the current class according to the output mode.
Further, the step S23 specifically includes the following steps:
when the current class has a parent class and the class method attribute is static, establishing a static method table of the top level parent class;
when the current class has a parent class and the class method attribute is non-static, establishing a virtual method table of the top level parent class;
adding the static member variable of the current class into a class variable table, and adding the non-static variable of the current class into a class instance variable;
when the current class has a subclass, recording the method of the current subclass and the number of variables in the subclass, copying the method and the variables of the parent class into a current subclass method table, and storing the method of the current subclass and the number of the variables in the subclass;
marking the interface method in the current virtual method table;
outputting a member function statement corresponding to the current class, a static variable structure corresponding to the static method table, a virtual method structure corresponding to the virtual method table, an example structure corresponding to the example variable, a static variable initialization function, a loading initialization function, a construction function and a class static domain initialization function corresponding to the current class;
and generating the member function corresponding to the current class according to the member function statement, the static variable structure, the virtual method structure, the instance structure, the static variable initialization function, the loading initialization function, the constructor and the class static domain initialization function.
It can be understood that the parent class in the class is analyzed from the class file structure, and the parent class of the current class can be recorded; if the current class has a parent class, recursively jumping to the step of S10, further loading a class file structure of the parent class, and storing class and interface related information in a storage structure table.
It should be understood that the method table of the top level parent class may be established first, and if the method is a static method, the method is added to the static method table; if the method is in a non-static mode, adding the method into a virtual method table; establishing a variable mapping table, and if the variable mapping table is a static member in the class, adding the static variable into the class variable table; if it is a non-static variable, adding the member to the class instance variable; if the subclass exists in the class, the method recursively jumps to the step of building a method table of the top level parent class first, and if the method is a static method, the method is added into the static method table. And if the method is in a non-static mode, adding the method into a virtual method table, recording the number of the methods and the variables in the class of the current subclass, and distinguishing the static method, the variables, the non-static method and the variables.
It can be understood that the method and variable of the parent class are copied to the current subclass method table, and then the method and variable of the current subclass are stored, so as to distinguish between static and non-static methods and variables; marking the interface method in the current virtual method table; and outputting the corresponding x, h file of the current conversion class and outputting the corresponding member function statement of the current class. Including static and non-static methods, constructors, etc.; outputting a structural body corresponding to the virtual method table in the current class; if the current class contains static variables, outputting a structure chart, wherein the structural member describes the corresponding static variables in the current class; and outputting a class variable structure, wherein the members in the class variable structure comprise a current class structure, a virtual method structure in the current class and a structure containing a static variable in the current class.
In a specific implementation, the members of the class structure include a load initialization function, a class construction function, a static variable initialization function, and a store static method table structure of the current class; outputting an example structure body corresponding to the current class, wherein the structure body members comprise a class variable structure body and class member variables corresponding to the current class; and outputting the c file of the corresponding class. Outputting an interface structure body, wherein members in the structure body determine a unique function name of an interface name for a package name, a class name, a method name, a parameter value and a return value corresponding to a current realization interface, and an actual physical address corresponding to the current class realization interface corresponding to the other member; outputting a static variable initialization function in the current class, wherein the function initializes the value with final static variable corresponding to the current class; initializing a current class structure body, and assigning a load initialization function clint, a construction function init, a class static domain initialization function and a static function address corresponding to a class corresponding to the current class to a function pointer member variable in the current class.
And step S24, extracting corresponding Java method byte codes from the class file according to the member functions.
It should be understood that, through the member function, the corresponding Java method bytecode may be extracted from the class file, that is, the Java method bytecode implemented in the class method is extracted from the class source file, and may be translated into the corresponding c-source code flow according to the Java method bytecode.
According to the scheme, the inheritance relationship among the class, the method and the interface of the class file is determined according to the pre-inheritance relationship information before the description of the character string; judging whether the current class has a parent class or not according to the inheritance relationship, the constant pool information and the class information; when the current class has a parent class, determining an output mode of the current class, and determining a member function of the current class according to the output mode; and extracting corresponding Java method byte codes from the class file according to the member functions, so that the Java method byte codes can be accurately and quickly extracted, the development cost is saved, the format conversion speed is increased, and the use experience is improved.
Further, fig. 6 is a flowchart illustrating a fifth embodiment of the application format conversion method of the present invention, and as shown in fig. 6, the fifth embodiment of the application format conversion method of the present invention is proposed based on the first embodiment, in this embodiment, the step S30 specifically includes the following steps:
and step S31, when the class method attribute is static, converting the Java method byte code into a target file corresponding to the language to be converted by using a unique function name through a conversion tool.
It should be noted that, after the member functions corresponding to the current class are generated, Java method bytecodes for implementation in the class method can be extracted from the class source file, and translated into a corresponding target source code flow according to the Java method bytecodes, and if the class source functions are in C language, the class source functions correspond to the C source code flow; that is, when the class method attribute is static, the Java method bytecode is converted into a target file corresponding to a language to be converted by using a unique function name through a conversion tool, the language to be converted is a target language for which the current Java language is converted into an application format that needs to be converted, the language to be converted may be Python language, may also be a database development language, for example, SQL, Visual Basic, Access, and other language types that need to be converted, and this embodiment does not limit this.
In a specific implementation, if a static function call exists in the current method, the bytecode corresponding to the static function is invokestatic; the converted static function name is the package name, the class name, the method name, the return value and the parameter type value (the package name, the class name, the method name, the return value and the parameter value), so that the uniqueness of the function name is determined, the problem of renaming does not exist, and the function can be directly called.
And step S32, when the class method attribute is non-static, converting the Java method byte code into a target file corresponding to the language to be converted by using a unique function name through a conversion tool.
It can be understood that when the class method attribute is non-static, the Java method bytecode is converted into a target file corresponding to the language to be converted by using a conversion tool through a unique function name, that is, if the current method is a virtual method, the corresponding bytecode is invokevirtual, and as above, because the uniqueness of the function name is determined by a conversion mechanism during conversion, the method invocation is directly completed through the function name corresponding to the c language.
It should be understood that, if the current method is to implement an interface, when the interface is called, the corresponding C function name of the interface is calculated through a conversion tool, and when the interface is called, the corresponding interface method entry is found according to the interface function table of the class where the current interface is located; and compiling a target binary file by using a self-developed compiler, downloading the binary file into a card resource, and performing related operation and loading and execution after downloading the binary file into a card.
In a specific implementation, fig. 7 is a flowchart of class startup loading in the application format conversion method of the present invention, as shown in fig. 7, where the creatitapplet is a current class, and the javacard.framework.applet is a subclass of the creatitapplet, where a class instantiation process is as follows, where javacapplet applications are all installed by a self-contained install method, and a corresponding class instance is constructed during installation; and may be performed by the following procedure:
1. when the Java application is installed, calling an install method to install the application; the constructor of the creatitapplet is called.
2. If the current class has a parent class, the constructor of the parent class is called recursively. Since the current class CreaditApplet stores constructors, a parent class javacard.
3. In the method of the current class structure function < init >, the instance initialization of the current class is carried out, and the part mainly relates the class initialization function, the instance initialization function, the static member domain initialization and the static method of the current class; i.e. to perform dynamic loading of classes.
4. If the class static member exists in the current class, calling a < clinit > function of the current class to initialize the static member, and assigning an initial value to a variable of the static class member.
5, the recursion jumps to 3 steps, and the current class executes the constructor < init >
According to the scheme, when the class method attribute is static, the static function in the member function is called to convert the Java method byte codes into the target file corresponding to the language to be converted; when the class method attribute is non-static, a virtual function in the member function is called to convert the Java method byte codes into a target file corresponding to the language to be converted, the compiled application file can be quickly converted into a file with a specified format without recompilation, development cost is saved, format conversion speed is accelerated, conversion efficiency is high, adaptability is strong, and use experience is improved.
Correspondingly, the invention further provides an application format conversion device.
Referring to fig. 8, fig. 8 is a functional block diagram of a first embodiment of the application format conversion device according to the present invention.
In a first embodiment of the application format conversion apparatus of the present invention, the application format conversion apparatus includes:
and the information extraction module 10 is used for extracting the constant pool information and the class information from the class file according to the preset parameters.
And the bytecode determining module 20 is configured to obtain an inheritance relationship among classes, interfaces and methods in the class file, and determine Java method bytecodes according to the constant pool information, the class information and the inheritance relationship.
And the format conversion module 30 is used for converting the Java method byte codes into target files corresponding to the languages to be converted.
The information extraction module 10 is further configured to read a class file from the JavaApplet according to the conversion tool, and obtain a class file structure from preset parameters; and analyzing constant pool information and class information from the class file according to the class file structure.
The information extraction module 10 is further configured to parse the number of constant pools from the class file according to the class file structure, establish a constant pool storage table, and use the constant pool storage table as constant pool information; obtaining an index value of a description class from the constant pool storage table, and analyzing the index value into corresponding character string description class information; analyzing index values in domains, methods and interfaces in the classes into pre-inheritance relationship information before character string description; and determining the class information according to the character string description class information and the pre-inheritance relationship information.
The information extraction module 10 is further configured to parse a parent class in the class file according to the string description class information and the inheritance relationship information; analyzing the number of interfaces of the class, the index of the interfaces, the static member variables and the non-static member variables of the domain, the attribute of the class method, the byte code implementation method and the additional attribute table from the class file; and taking the interface number, the interface index, the static member variable, the non-static member variable, the class method attribute, the byte code implementation method and the additional attribute table as class information.
The bytecode determining module 20 is further configured to determine an inheritance relationship between the class, the method, and the interface of the class file according to pre-inheritance relationship information before the description of the character string; judging whether the current class has a parent class or not according to the inheritance relationship, the constant pool information and the class information; when the current class has a parent class, determining an output mode of the current class, and determining a member function of the current class according to the output mode; and extracting corresponding Java method byte codes from the class file according to the member functions.
The bytecode determining module 20 is further configured to establish a static method table of the top level parent class when the current class has a parent class and the class method attribute is static; when the current class has a parent class and the class method attribute is non-static, establishing a virtual method table of the top level parent class; adding the static member variable of the current class into a class variable table, and adding the non-static variable of the current class into a class instance variable; when the current class has a subclass, recording the method of the current subclass and the number of variables in the subclass, copying the method and the variables of the parent class into a current subclass method table, and storing the method of the current subclass and the number of the variables in the subclass; marking the interface method in the current virtual method table; outputting a member function statement corresponding to the current class, a static variable structure corresponding to the static method table, a virtual method structure corresponding to the virtual method table, an example structure corresponding to the example variable, a static variable initialization function, a loading initialization function, a construction function and a class static domain initialization function corresponding to the current class; and generating the member function corresponding to the current class according to the member function statement, the static variable structure, the virtual method structure, the instance structure, the static variable initialization function, the loading initialization function, the constructor and the class static domain initialization function.
The format conversion module 30 is further configured to, when the class method attribute is static, call a static function in the member functions to convert the Java method bytecode into a target file corresponding to the language to be converted; and when the class method attribute is non-static, calling a virtual function in the member function to convert the Java method byte codes into a target file corresponding to the language to be converted.
The steps implemented by each functional module of the application format conversion device can refer to each embodiment of the application format conversion method of the present invention, and are not described herein again.
In addition, an embodiment of the present invention further provides a storage medium, where an application format conversion program is stored on the storage medium, and when executed by a processor, the application format conversion program implements the following operations:
extracting constant pool information and class information from the class file according to preset parameters;
acquiring inheritance relationships among classes, interfaces and methods in the class file, and determining Java method byte codes according to the constant pool information, the class information and the inheritance relationships;
and converting the Java method byte codes into target files corresponding to the languages to be converted.
Further, the application format conversion program when executed by the processor further performs the following operations:
reading a class file from the JavaApplet according to a conversion tool, and obtaining a class file structure from preset parameters;
and analyzing constant pool information and class information from the class file according to the class file structure.
Further, the application format conversion program when executed by the processor further performs the following operations:
analyzing the number of constant pools from the class file according to the class file structure, establishing a constant pool storage table, and taking the constant pool storage table as constant pool information;
obtaining an index value of a description class from the constant pool storage table, and analyzing the index value into corresponding character string description class information;
analyzing index values in domains, methods and interfaces in the classes into pre-inheritance relationship information before character string description;
and determining the class information according to the character string description class information and the pre-inheritance relationship information.
Further, the application format conversion program when executed by the processor further performs the following operations:
analyzing a parent class in the class from the class file according to the character string description class information and the pre-inheritance relationship information;
analyzing the number of interfaces of the class, the index of the interfaces, the static member variables and the non-static member variables of the domain, the attribute of the class method, the byte code implementation method and the additional attribute table from the class file;
and taking the interface number, the interface index, the static member variable, the non-static member variable, the class method attribute, the byte code implementation method and the additional attribute table as class information.
Further, the application format conversion program when executed by the processor further performs the following operations:
determining the inheritance relationship among the class, the method and the interface of the class file according to the pre-inheritance relationship information before the description of the character string;
judging whether the current class has a parent class or not according to the inheritance relationship, the constant pool information and the class information;
when the current class has a parent class, determining an output mode of the current class, and determining a member function of the current class according to the output mode;
and extracting corresponding Java method byte codes from the class file according to the member functions.
Further, the application format conversion program when executed by the processor further performs the following operations:
when the current class has a parent class and the class method attribute is static, establishing a static method table of the top level parent class;
when the current class has a parent class and the class method attribute is non-static, establishing a virtual method table of the top level parent class;
adding the static member variable of the current class into a class variable table, and adding the non-static variable of the current class into a class instance variable;
when the current class has a subclass, recording the method of the current subclass and the number of variables in the subclass, copying the method and the variables of the parent class into a current subclass method table, and storing the method of the current subclass and the number of the variables in the subclass;
marking the interface method in the current virtual method table;
outputting a member function statement corresponding to the current class, a static variable structure corresponding to the static method table, a virtual method structure corresponding to the virtual method table, an example structure corresponding to the example variable, a static variable initialization function, a loading initialization function, a construction function and a class static domain initialization function corresponding to the current class;
and generating the member function corresponding to the current class according to the member function statement, the static variable structure, the virtual method structure, the instance structure, the static variable initialization function, the loading initialization function, the constructor and the class static domain initialization function.
Further, the application format conversion program when executed by the processor further performs the following operations:
when the class method attribute is static, calling a static function in the member functions to convert the Java method byte codes into a target file corresponding to the language to be converted;
and when the class method attribute is non-static, calling a virtual function in the member function to convert the Java method byte codes into a target file corresponding to the language to be converted.
According to the scheme, the constant pool information and the class information are extracted from the class file according to the preset parameters; acquiring inheritance relationships among classes, interfaces and methods in the class file, and determining Java method byte codes according to the constant pool information, the class information and the inheritance relationships; the Java method byte codes are converted into the target files corresponding to the languages to be converted, the compiled application files can be quickly converted into files in the specified format without recompilation, development cost is saved, format conversion speed is increased, conversion efficiency is high, adaptability is strong, and use experience is improved.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (10)

1. An application format conversion method, characterized in that the application format conversion method comprises:
extracting constant pool information and class information from the class file according to preset parameters;
acquiring inheritance relationships among classes, interfaces and methods in the class file, and determining Java method byte codes according to the constant pool information, the class information and the inheritance relationships;
and converting the Java method byte codes into target files corresponding to the languages to be converted.
2. The method for converting an application format according to claim 1, wherein the extracting constant pool information and class information from the input class file according to the preset parameters comprises:
reading a class file from the JavaApplet according to a conversion tool, and obtaining a class file structure from preset parameters;
and analyzing constant pool information and class information from the class file according to the class file structure.
3. The application format conversion method of claim 2, wherein the parsing out constant pool information and class information from the class file according to the class file structure comprises:
analyzing the number of constant pools from the class file according to the class file structure, establishing a constant pool storage table, and taking the constant pool storage table as constant pool information;
obtaining an index value of a description class from the constant pool storage table, and analyzing the index value into corresponding character string description class information;
analyzing index values in domains, methods and interfaces in the classes into pre-inheritance relationship information before character string description;
and determining the class information according to the character string description class information and the pre-inheritance relationship information.
4. The application format conversion method according to claim 3, wherein the determining class information from the character string description class information and the pre-inheritance relationship information includes:
analyzing a parent class in the class from the class file according to the character string description class information and the pre-inheritance relationship information;
analyzing the number of interfaces of the class, the index of the interfaces, the static member variables and the non-static member variables of the domain, the attribute of the class method, the byte code implementation method and the additional attribute table from the class file;
and taking the interface number, the interface index, the static member variable, the non-static member variable, the class method attribute, the byte code implementation method and the additional attribute table as class information.
5. The application format conversion method according to claim 4, wherein the obtaining of the inheritance relationship among the class, the interface and the method in the class file and the determining of the Java method bytecode according to the constant pool information, the class information and the inheritance relationship comprise:
determining the inheritance relationship among the class, the method and the interface of the class file according to the pre-inheritance relationship information before the description of the character string;
judging whether the current class has a parent class or not according to the inheritance relationship, the constant pool information and the class information;
when the current class has a parent class, determining an output mode of the current class, and determining a member function of the current class according to the output mode;
and extracting corresponding Java method byte codes from the class file according to the member functions.
6. The method as claimed in claim 5, wherein the determining an output mode of the current class when the parent class exists in the current class and determining a member function of the current class according to the output mode comprises:
when the current class has a parent class and the class method attribute is static, establishing a static method table of the top level parent class;
when the current class has a parent class and the class method attribute is non-static, establishing a virtual method table of the top level parent class;
adding the static member variable of the current class into a class variable table, and adding the non-static variable of the current class into a class instance variable;
when the current class has a subclass, recording the method of the current subclass and the number of variables in the subclass, copying the method and the variables of the parent class into a current subclass method table, and storing the method of the current subclass and the number of the variables in the subclass;
marking the interface method in the current virtual method table;
outputting a member function statement corresponding to the current class, a static variable structure corresponding to the static method table, a virtual method structure corresponding to the virtual method table, an example structure corresponding to the example variable, a static variable initialization function, a loading initialization function, a construction function and a class static domain initialization function corresponding to the current class;
and generating the member function corresponding to the current class according to the member function statement, the static variable structure, the virtual method structure, the instance structure, the static variable initialization function, the loading initialization function, the constructor and the class static domain initialization function.
7. The application format conversion method according to claim 6, wherein the converting the Java method bytecode into the target file corresponding to the language to be converted includes:
when the class method attribute is static, converting the Java method byte codes into a target file corresponding to the language to be converted by using a unique function name through a conversion tool;
and when the class method attribute is non-static, converting the Java method byte codes into a target file corresponding to the language to be converted by using the unique function name through a conversion tool.
8. An application format conversion apparatus, characterized in that the application format conversion apparatus comprises:
the information extraction module is used for extracting constant pool information and class information from the class file according to preset parameters;
the bytecode determining module is used for acquiring inheritance relationships among classes, interfaces and methods in the class file and determining Java method bytecodes according to the constant pool information, the class information and the inheritance relationships;
and the format conversion module is used for converting the Java method byte codes into target files corresponding to the languages to be converted.
9. An application format conversion device characterized by comprising: memory, a processor and an application format conversion program stored on the memory and executable on the processor, the application format conversion program being configured to implement the steps of the application format conversion method according to any of claims 1 to 7.
10. A storage medium having stored thereon an application format conversion program which, when executed by a processor, implements the steps of the application format conversion method according to any one of claims 1 to 7.
CN202111657812.XA 2021-12-30 2021-12-30 Application format conversion method, device, equipment and storage medium Pending CN114327482A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111657812.XA CN114327482A (en) 2021-12-30 2021-12-30 Application format conversion method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111657812.XA CN114327482A (en) 2021-12-30 2021-12-30 Application format conversion method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114327482A true CN114327482A (en) 2022-04-12

Family

ID=81018812

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111657812.XA Pending CN114327482A (en) 2021-12-30 2021-12-30 Application format conversion method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114327482A (en)

Similar Documents

Publication Publication Date Title
AU771699B2 (en) Token-based linking
US6704927B1 (en) Static binding of dynamically-dispatched calls in the presence of dynamic linking and loading
US5590331A (en) Method and apparatus for generating platform-standard object files containing machine-independent code
US5784553A (en) Method and system for generating a computer program test suite using dynamic symbolic execution of JAVA programs
US6381737B1 (en) Automatic adapter/stub generator
CN112052006B (en) Software code compiling method and system
US8042103B2 (en) Pre-translated files used in a virtual machine
WO2006009287A1 (en) Automatic converting program and program conversion server
US11726849B2 (en) Executing a parametric method within a specialized context
US20030018959A1 (en) Customization of Java runtime environments
CN112612502A (en) Patch generation method, device, equipment and storage medium
CN113703779B (en) Cross-platform multi-language compiling method and ultra-light Internet of things virtual machine
US20030041321A1 (en) Frameworks for generation of java macro instructions in java computing environments
CA2428558C (en) System and method for defining and using subclasses declaratively within markup
CN111913741B (en) Object interception method, device, medium and electronic equipment
EP0950947B1 (en) Static binding of dynamically dispatched calls in the presence of dynamic linking and loading
Alves et al. Comparative analysis of porting strategies in J2ME games
CN114327482A (en) Application format conversion method, device, equipment and storage medium
EP1136910A2 (en) A method of compiling code in an object oriented programming language
CN114706586A (en) Code compiling method, code running method, code compiling device, code running device, computer equipment and storage medium
US20030041322A1 (en) Frameworks for generation of java macro instructions for instantiating java objects
CN114020278A (en) Data processing method, device, equipment and storage medium
CN114327415B (en) Compiling method and device for compiling java file
CN117235746B (en) Source code safety control platform based on multidimensional AST fusion detection
Brykin et al. New Generation of B Programming Language for Data Analysis Tasks

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination