Application format conversion method, apparatus, device, and storage medium
By extracting the constant pool and class information from the Java Card's class file, determining the Java method bytecode, and converting it into an object file, the recompilation problem when Java Card is applied to non-Java Virtual Machines is solved, achieving rapid conversion and cost savings.
Patent Information
- Application Number
- CN202111657812.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-30
- Publication Date
- 2025-12-16
- Estimated Expiration
- 2041-12-30
AI Technical Summary
In existing technologies, Java Card compiled language applications need to be recompiled when ported to virtual machines other than the Java Virtual Machine, resulting in high development costs, time and effort, and a poor user experience.
By extracting constant pool and class information from the class file, the inheritance relationship between classes, interfaces, and methods is obtained, the Java method bytecode is determined, and it is converted into the target file of the language to be converted, thus avoiding recompilation.
It enables rapid conversion of application files without recompiling, saving development costs, speeding up format conversion, and improving the user experience.
Smart Images

Figure CN114327482B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of smart card virtual machine, and particularly relates to an application format conversion method and device, equipment and a storage medium. BACKGROUND
[0002] At present, Java Card technology is a Java technology for smart cards, and is a widely used smart card general programming platform. As a programming platform based on a virtual machine, Java source code is first compiled into byte code, and then runs on a virtual machine that interprets the byte code.
[0003] The compiled language used by a small application (Applet) of Java Card is java language, which is suitable for use on a Java virtual machine. However, when the application needs to be transplanted to other types of virtual machines for use, the application program needs to be recompiled before use, which brings a lot of unnecessary development burden and development cost to the developer. SUMMARY
[0004] The main purpose of the present application is to provide an application format conversion method, device, equipment and storage medium, which aims to solve the technical problems that the Java Card compiled language application needs to be recompiled when it is used on virtual machines other than the Java virtual machine, which is time-consuming and laborious, has a large development and research cost, and has poor use experience.
[0005] In a first aspect, the present application provides an application format conversion method, which comprises the following steps:
[0006] Extracting constant pool information and class information from a class file according to preset parameters;
[0007] Obtaining the inheritance relationship between classes, interfaces and methods in the class file, and determining Java method byte code according to the constant pool information, the class information and the inheritance relationship;
[0008] Converting the Java method byte code into a target file corresponding to a to-be-converted language.
[0009] Optionally, the extracting of the constant pool information and the class information from the input class file according to the preset parameters comprises:
[0010] Reading a class file from a Java Applet according to a conversion tool, and obtaining a class file structure from preset parameters;
[0011] Parsing the constant pool information and the class information from the class file according to the class file structure.
[0012] Optionally, the parsing of the constant pool information and the class information from the class file according to the class file structure comprises:
[0013] The number of the constant pool is parsed from the class file according to the class file structure, a constant pool storage table is established, and the constant pool storage table is taken as the constant pool information;
[0014] An index value describing a class is obtained from the constant pool storage table, and the index value is parsed into corresponding string class information;
[0015] The index values in the fields, methods and interfaces in the class are parsed into string description of the pre-inheritance relationship information;
[0016] The class information is determined according to the string description of the class information and the pre-inheritance relationship information.
[0017] Optionally, the determination of the class information according to the string description of the class information and the pre-inheritance relationship information comprises:
[0018] The parent class in the class is parsed from the class file according to the string description of the class information and the pre-inheritance relationship information;
[0019] The number of interfaces, the interface index, the static member variable and the non-static member variable of the field, the class method attribute, the bytecode implementation method and the additional attribute table of the class are parsed from the class file;
[0020] The number of interfaces, the interface index, the static member variable, the non-static member variable, the class method attribute, the bytecode implementation method and the additional attribute table are taken as the class information.
[0021] Optionally, the obtaining of the inheritance relationship among the class, the interface and the method in the class file, and the determination of the Java method bytecode according to the constant pool information, the class information and the inheritance relationship comprise:
[0022] 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 string description;
[0023] Whether the current class has a parent class is judged according to the inheritance relationship, the constant pool information and the class information;
[0024] When the current class has a parent class, the output mode of the current class is determined, and the member function of the current class is determined according to the output mode;
[0025] The corresponding Java method bytecode is extracted from the class file according to the member function.
[0026] Optionally, when the current class has a parent class, the output mode of the current class is determined, and a member function of the current class is determined according to the output mode, comprising:
[0027] When the current class has a parent class and the class method attribute is static, a static method table of the topmost parent class is established;
[0028] When the current class has a parent class and the class method attribute is non-static, a virtual method table of the topmost parent class is established;
[0029] A static member variable of the current class is added to a class variable table, and a non-static variable of the current class is added to a class instance variable;
[0030] When the current class has a child class, the number of methods and variables in the current child class is recorded, the methods and variables of the parent class are copied to a method table of the current child class, and the number of methods and variables in the current child class is stored;
[0031] An interface method in the current virtual method table is marked;
[0032] *.h files and *.c files corresponding to the current conversion class are output, and a member function declaration 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 instance structure corresponding to the instance variable, a static variable initialization function, a loading initialization function corresponding to the current class, a constructor function and a class static field initialization function are output;
[0033] A member function corresponding to the current class is generated according to the member function declaration, the static variable structure, the virtual method structure, the instance structure, the static variable initialization function, the loading initialization function, the constructor function and the class static field initialization function.
[0034] Optionally, the Java method bytecode is converted into a target file corresponding to a language to be converted, comprising:
[0035] 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 a conversion tool through a unique function name;
[0036] When the class method attribute is non-static, the Java method bytecode is converted into a target file corresponding to a language to be converted by a conversion tool through a unique function name.
[0037] In a second aspect, in order to achieve the above object, the application further provides an application format conversion device, which comprises:
[0038] The information extraction module is configured to extract constant pool information and class information from the class file according to preset parameters.
[0039] The bytecode determination module is configured to obtain inheritance relationships among classes, interfaces and methods in the class file, and determine Java method bytecode according to the constant pool information, the class information and the inheritance relationships.
[0040] The format conversion module is configured to convert the Java method bytecode into a target file corresponding to a language to be converted.
[0041] In a third aspect, an application format conversion device is provided, which comprises a memory, a processor and an application format conversion program stored in the memory and executable on the processor, and the application format conversion program is configured to implement the steps of the application format conversion method.
[0042] In a fourth aspect, a storage medium is provided, which stores an application format conversion program, and the application format conversion program is configured to implement the steps of the application format conversion method when executed by a processor.
[0043] The application format conversion method can quickly convert a compiled application file into a file in a specified format without recompilation, thereby saving development cost, accelerating format conversion speed, improving conversion efficiency, having strong adaptability and improving user experience. BRIEF DESCRIPTION OF DRAWINGS
[0044] Figure 1 The device structure diagram of a hardware running environment related to an embodiment of the application is shown.
[0045] Figure 2 The flowchart of the first embodiment of the application format conversion method is shown.
[0046] Figure 3 The flowchart of the second embodiment of the application format conversion method is shown.
[0047] Figure 4 The flowchart of the third embodiment of the application format conversion method is shown.
[0048] Figure 5A flowchart of the fourth embodiment of the format conversion method of the application is shown in the figure;
[0049] Figure 6 A flowchart of the fifth embodiment of the format conversion method of the application is shown in the figure;
[0050] Figure 7 A class startup loading flowchart in the format conversion method of the application is shown in the figure;
[0051] Figure 8 A functional module diagram of the first embodiment of the format conversion device of the application is shown in the figure.
[0052] The implementation, functional features and advantages of the application will be further described with reference to the embodiments and the accompanying drawings. DETAILED DESCRIPTION
[0053] It should be understood that the specific embodiments described herein are merely intended to explain the application and not to limit the application.
[0054] The solution of the embodiments of the application is mainly: extracting constant pool information and class information from a class file according to preset parameters; obtaining inheritance relationships among classes, interfaces and methods in the class file, determining Java method bytecodes according to the constant pool information, the class information and the inheritance relationships; and converting the Java method bytecodes into target files corresponding to a to-be-converted language, which can quickly convert a compiled application file into a file in a specified format without recompilation, saves development cost, speeds up the format conversion, has high conversion efficiency, has strong adaptability, improves user experience, and solves the technical problems of the prior art, i.e., when a Java Card compiled language application is used until other virtual machines except for a Java virtual machine, the application program needs to be recompiled, which is time-consuming and laborious, has large development and research cost, and has poor user experience.
[0055] Reference Figure 1 , Figure 1 A device structure diagram of a hardware running environment related to the embodiment of the application is shown in the figure.
[0056] As Figure 1As shown in the figure, the device can include a processor 1001, such as a CPU, a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. The communication bus 1002 is used to realize the connection communication between these components. The user interface 1003 can include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 can also include a standard wired interface, a wireless interface. The network interface 1004 can optionally include a standard wired interface, a wireless interface (such as a Wi-Fi interface). The memory 1005 can be a high-speed RAM memory, or a stable memory (Non-Volatile Memory), such as a magnetic disk memory. The memory 1005 can also be an optional storage device independent of the aforementioned processor 1001.
[0057] Those skilled in the art can understand that, Figure 1 The device structure shown in the figure does not constitute a limitation on the device, and can include more or fewer components than the figure, or combine certain components, or different component arrangements.
[0058] As Figure 1 As shown, the memory 1005 as a storage medium can include an operating system, a network communication module, a user interface module, and an application format conversion program.
[0059] The device of the application calls the application format conversion program stored in the memory 1005 through the processor 1001, and performs the following operations:
[0060] Extracting constant pool information and class information from the class file according to the preset parameters;
[0061] Obtaining the inheritance relationship between classes, interfaces and methods in the class file, and determining the Java method bytecode according to the constant pool information, the class information and the inheritance relationship;
[0062] Converting the Java method bytecode into a target file corresponding to the language to be converted.
[0063] The device of the application calls the application format conversion program stored in the memory 1005 through the processor 1001, and also performs the following operations:
[0064] Reading the class file from the JavaApplet according to the conversion tool, and obtaining the class file structure from the preset parameters;
[0065] According to the class file structure, the constant pool information and the class information are parsed from the class file.
[0066] The application format conversion program stored in the memory 1005 is called by the processor 1001, and the following operations are further performed:
[0067] The number of constant pools is parsed from the class file according to the class file structure, a constant pool storage table is established, and the constant pool storage table is taken as constant pool information;
[0068] An index value describing a class is obtained from the constant pool storage table, and the index value is parsed into corresponding string description class information;
[0069] The index values in the fields, methods and interfaces of the class are parsed into string description pre-inheritance relationship information;
[0070] The class information is determined according to the string description class information and the pre-inheritance relationship information.
[0071] The application format conversion program stored in the memory 1005 is called by the processor 1001, and the following operations are further performed:
[0072] The parent class in the class is parsed from the class file according to the string description class information and the pre-inheritance relationship information;
[0073] The number of interfaces, interface indexes, static member variables and non-static member variables of fields, class method attributes, bytecode implementation methods and additional attribute tables of the class are parsed from the class file;
[0074] The number of interfaces, the interface indexes, the static member variables, the non-static member variables, the class method attributes, the bytecode implementation methods and the additional attribute tables are taken as class information.
[0075] The application format conversion program stored in the memory 1005 is called by the processor 1001, and the following operations are further performed:
[0076] 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 string description;
[0077] Whether the current class has a parent class is judged according to the inheritance relationship, the constant pool information and the class information;
[0078] When the current class has a parent class, the output mode of the current class is determined, and the member function of the current class is determined according to the output mode;
[0079] The corresponding Java method bytecode is extracted from the class file according to the member function.
[0080] The application device calls an application format conversion program stored in the memory 1005 through the processor 1001, and further performs the following operations:
[0081] When the current class has a parent class and the class method attribute is static, a static method table of the topmost parent class is established;
[0082] When the current class has a parent class and the class method attribute is non-static, a virtual method table of the topmost parent class is established;
[0083] The static member variable of the current class is added to the class variable table, and the non-static variable of the current class is added to the class instance variable;
[0084] When the current class has a child class, the number of methods and variables in the current child class is recorded, the methods and variables of the parent class are copied to the method table of the current child class, and the number of methods and variables in the current child class is stored;
[0085] The interface method in the current virtual method table is marked;
[0086] The *.h file and the *.c file corresponding to the current conversion class are output, and the member function declaration corresponding to the current class, the static variable structure corresponding to the static method table, the virtual method structure corresponding to the virtual method table, the instance structure corresponding to the instance variable, the static variable initialization function, the loading initialization function corresponding to the current class, the constructor function and the class static field initialization function are output;
[0087] The member function corresponding to the current class is generated according to the member function declaration, the static variable structure, the virtual method structure, the instance structure, the static variable initialization function, the loading initialization function, the constructor function and the class static field initialization function.
[0088] The application device calls an application format conversion program stored in the memory 1005 through the processor 1001, and further performs the following operations:
[0089] When the class method attribute is static, the Java method bytecode is converted into a target file corresponding to the to-be-converted language through a conversion tool by using a unique function name;
[0090] When the class method attribute is non-static, the Java method bytecode is converted into a target file corresponding to the to-be-converted language through a conversion tool by using a unique function name.
[0091] The embodiment extracts constant pool information and class information from a class file according to preset parameters, obtains inheritance relationships among classes, interfaces and methods in the class file, determines Java method bytecode according to the constant pool information, the class information and the inheritance relationships, converts the Java method bytecode into a target file corresponding to a language to be converted, and can quickly convert a compiled application file into a file in a specified format without recompilation, thereby saving development cost, accelerating format conversion speed, improving conversion efficiency, being highly adaptable and improving user experience.
[0092] Based on the hardware structure, the application provides the format conversion method.
[0093] Reference Figure 2 , Figure 2 The flowchart of the first embodiment of the application is shown in the figure.
[0094] In the first embodiment, the application format conversion method comprises the following steps:
[0095] In step S10, constant pool information and class information are extracted from a class file according to preset parameters.
[0096] It should be noted that the constant pool information and the class information can be extracted from the input class file according to preset parameters, that is, the constant pool and class-related information can be extracted from the already compiled *.class file.
[0097] In step S20, inheritance relationships among classes, interfaces and methods in the class file are obtained, and Java method bytecode is determined according to the constant pool information, the class information and the inheritance relationships.
[0098] It can be understood that the inheritance relationships are relationships for describing inheritance relationships among classes, methods and interfaces, and the Java method bytecode can be quickly determined from the class file according to the constant pool information, the class information and the inheritance relationships.
[0099] In step S30, the Java method bytecode is converted into a target file corresponding to a language to be converted.
[0100] It should be understood that the Java method bytecode can be quickly converted into a target file corresponding to a to-be-converted language in different application scenarios. Generally, the target file can be a c file, that is, Java to C conversion is implemented, so as to facilitate technical personnel to quickly perform application operations. Different to-be-converted languages correspond to different target files. The to-be-converted language is the current Java language converted into a target language in a format to be converted. The to-be-converted language can be a Python language, a database development language such as SQL, Visual Basic, Access, or other to-be-converted languages, which are not limited in the embodiment.
[0101] According to the above scheme, the constant pool information and the class information are extracted from the class file according to the preset parameters, the inheritance relationship among classes, interfaces and methods in the class file is obtained, the Java method bytecode is determined according to the constant pool information, the class information and the inheritance relationship, and the Java method bytecode is converted into a target file corresponding to a to-be-converted language. The compiled application file can be quickly converted into a file in 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.
[0102] Further, Figure 3 The flowchart of the application format conversion method second embodiment of the present application is shown in FIG. 2. Figure 3 The application format conversion method second embodiment of the present application is based on the first embodiment. In the embodiment, the step S10 specifically includes the following steps.
[0103] In step S11, the class file is read from the JavaApplet according to the conversion tool, and the class file structure is obtained from the preset parameters.
[0104] It should be noted that the *.class file already compiled in the JavaApplet is read by 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.
[0105] In step S12, the constant pool information and the class information are parsed from the class file according to the class file structure.
[0106] It should be understood that the constant pool information and the class information are parsed from the class file according to the class file structure, that is, the constant pool related information and the class related information.
[0107] The embodiment reads the class file from the JavaApplet through the conversion tool, obtains the class file structure from the preset parameters, and quickly parses the constant pool information and the class information from the class file according to the class file structure, so that the constant pool information and the class information can be quickly parsed from the class file, a basis is provided for subsequent format conversion, and the speed and efficiency of application format conversion are further improved.
[0108] Further, Figure 4 The flowchart of the third embodiment of the application format conversion method is shown in the figure. Figure 4 The third embodiment of the application format conversion method is proposed based on the second embodiment, and in the embodiment, the step S12 specifically includes the following steps.
[0109] In step S121, the number of constant pools is parsed from the class file according to the class file structure, a constant pool storage table is established, and the constant pool storage table is taken as the constant pool information.
[0110] 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, and the constant pool storage table is taken as the constant pool information.
[0111] In step S122, an index value describing a class is obtained from the constant pool storage table, and the index value is parsed into corresponding string description class information.
[0112] It can be understood that the index value describing the class is obtained from the constant pool storage table, the index value in the constant pool table related to the description of the class is parsed into corresponding related string description information, that is, the string description class information, so as to describe the character name of the current class.
[0113] In step S123, the index values in the fields, methods and interfaces of the class are parsed into string description before the inheritance relationship information.
[0114] It should be understood that the index values in the fields, methods and interfaces of the class are parsed into specific string description information, which can be used to describe the inheritance relationship before the class, method and interface, that is, the inheritance relationship information before the string description.
[0115] In step S124, the class information is determined according to the string description class information and the inheritance relationship information.
[0116] It can be understood that the class information can be determined according to the string description class information.
[0117] Further, the step S124 specifically includes the following steps:
[0118] According to the string description class information and the previous inheritance relationship information, a parent class in the class is parsed from the class file;
[0119] and the number of interfaces, the interface index, the static member variable and the non-static member variable of the field, the class method attribute, the bytecode implementation method and the additional attribute table of the class are parsed from the class file;
[0120] The number of interfaces, the interface index, the static member variable, the non-static member variable, the class method attribute, the bytecode implementation method and the additional attribute table are taken as the class information.
[0121] It should be understood that the parent class in the class is parsed from the class file structure, so that the parent class of the current class can be recorded; the number of interfaces and the interface index in the class are parsed from the class file structure; the string description information is parsed according to the index value in the constant pool; the field in the class is parsed from the class file structure, which generally includes the static and non-static member variables, and the corresponding string description information is parsed according to the index value in the constant pool; the method in the class is parsed from the class file structure, and the class method includes the method attribute and the bytecode implementation; according to the package name, the class name and the method name, the method parameter type, the return value, the uniqueness of the C corresponding function is determined according to the part of the field; the additional attribute table is parsed from the class file structure, and the additional attribute table is used to describe the current class file name.
[0122] According to the above scheme, the number of constant pools is parsed from the class file according to the class file structure, the constant pool storage table is established, the constant pool storage table is taken as the constant pool information, the index value describing the class is obtained from the constant pool storage table, the index value is parsed into the corresponding string description class information, the index value in the field, the method and the interface of the class is parsed into the previous inheritance relationship information before the string description, the class information is determined according to the string description class information and the previous inheritance relationship information, the constant pool information and the class information can be quickly parsed from the class file, which provides a basis for subsequent format conversion, and further improves the speed and efficiency of application format conversion.
[0123] Further, Figure 5 The flowchart of the fourth embodiment of the application format conversion method is shown in FIG. 4, which is based on the first embodiment. Figure 5 The step S20 specifically includes the following steps in the fourth embodiment of the application format conversion method:
[0124] Step S21, determining the inheritance relationship between the class, method and interface of the class file according to the pre-inheritance relationship information.
[0125] It should be noted that the inheritance relationship between the class, method and interface in the class file can be determined according to the pre-inheritance relationship information before the string description.
[0126] Step S22, judging whether the current class has a parent class according to the inheritance relationship, the constant pool information and the class information.
[0127] It can be understood that whether the current class in the class has a parent class can be determined according to the inheritance relationship, the constant pool information and the class information.
[0128] Step S23, when the current class has a parent class, determining the output mode of the current class, and determining the member function of the current class according to the output mode.
[0129] It should be understood that when the current class has a parent class, the step of recursively jumping to the constant pool and class information confirmation can be performed, the class and interface related information can be stored into the storage structure table again, and then the output mode of the current class can be determined, and the member function of the current class can be determined according to the output mode.
[0130] Further, the step S23 specifically includes the following steps:
[0131] When the current class has a parent class and the class method attribute is static, a static method table of the topmost parent class is established;
[0132] When the current class has a parent class and the class method attribute is non-static, a virtual method table of the topmost parent class is established;
[0133] The static member variable of the current class is added to the class variable table, and the non-static variable of the current class is added to the class instance variable;
[0134] When the current class has a child class, the number of methods and variables in the current child class is recorded, the methods and variables of the parent class are copied to the method table of the current child class, and the number of methods and variables in the current child class is stored;
[0135] The interface method in the current virtual method table is marked;
[0136] The *.h file and the *.c file corresponding to the current conversion class are output, and the member function declaration corresponding to the current class, the static variable structure corresponding to the static method table, the virtual method structure corresponding to the virtual method table, the instance structure corresponding to the instance variable, the static variable initialization function, the loading initialization function corresponding to the current class, the constructor function and the class static field initialization function are output.
[0137] According to the member function declaration, the static variable structure, the virtual method structure, the instance structure, the static variable initialization function, the loading initialization function, the constructor function and the class static field initialization function, the member function corresponding to the current class is generated.
[0138] It can be understood that the parent class in the class is parsed from the class file structure, and the parent class of the current class can be recorded. Whether the current class has a parent class, if the parent class exists, the step of S10 is recursively jumped to, and then the parent class file structure is loaded, and the class and interface related information are stored in the storage structure table.
[0139] It should be understood that the method table of the top-level parent class can be established first. If it is a static method, it is added to the static method table. If it is a non-static method, the method is added to the virtual method table. The variable mapping table is established. If it is a static member in the class, the static variable is added to the class variable table. If it is a non-static variable, the member is added to the class instance variable. Whether the class has a subclass, if the subclass exists, recursively jump to the step of "first establish the method table of the top-level parent class. If it is a static method, it is added to the static method table. If it is a non-static method, the method is added to the virtual method table". The number of methods and variables in the current subclass is recorded, and the static method, variable and non-static method, variable are distinguished.
[0140] It can be understood that the methods and variables of the parent class are copied to the method table of the current subclass first, and then the methods and variables of the current subclass are stored, and the static and non-static methods and variables are distinguished. The interface method in the current virtual method table is marked. The *.h file corresponding to the current conversion class is output, and the member function declaration corresponding to the current class is output. Including static method and non-static method, constructor, etc. The structure corresponding to the virtual method table in the current class is output. If the current class contains static variables, a structure is output. The members of the structure describe the corresponding static variables in the current class. The class variable structure is output. The members in it include the current class structure, the virtual method structure in the current class, and the structure containing static variables in the current class.
[0141] In a specific implementation, the members of the class structure body include a loading initialization function of the current class, a class constructor, a static variable initialization function, and a static method table structure body; an instance structure body corresponding to the current class is output, and the members of the structure body include a class variable structure body and corresponding class member variables in the current class; a *.c file corresponding to the class is output; an interface structure body is output, and the members of the structure body are a unique function name of an interface name determined by a package name, a class name, and a method name, a parameter value, and a return value of the current implementation interface, and another member corresponds to an actual physical address of the implementation interface in the current class; a static variable initialization function in the current class is output, and the function initializes the value of the final static variable corresponding to the current class; a class structure structure body is initialized, and the loading initialization function clint, the constructor init, the class static field initialization function, and the static function address corresponding to the class of the current class are assigned to the function pointer member variable in the current class.
[0142] In step S24, the corresponding Java method bytecode is extracted from the class file according to the member function.
[0143] It should be understood that the corresponding Java method bytecode can be extracted from the class file through the member function, that is, the implemented Java method bytecode in the class method is extracted from the *.class source file, and then the Java method bytecode can be translated into the corresponding c source code process according to the Java method bytecode.
[0144] According to the above scheme, the inheritance relationship among the classes, methods and interfaces of the class file is determined according to the preceding inheritance relationship information of the string description; whether the current class has a parent class is judged according to the inheritance relationship, the constant pool information and the class information; when the current class has a parent class, the output mode of the current class is determined, and the member function of the current class is determined according to the output mode; and the corresponding Java method bytecode is extracted from the class file according to the member function, so that the Java method bytecode can be accurately and quickly extracted, the development cost is saved, the format conversion speed is accelerated, and the use experience is improved.
[0145] Further, Figure 6 The flowchart of the application of the format conversion method according to the fifth embodiment of the application is shown in FIG. 5. Figure 6 As shown in FIG. 5, the application of the format conversion method according to the fifth embodiment of the application is based on the first embodiment, and the step S30 specifically includes the following steps:
[0146] In step S31, when the class method attribute is static, the Java method bytecode is converted into a target file corresponding to the to-be-converted language by using the unique function name through a conversion tool.
[0147] It should be noted that after the member function corresponding to the current class is generated, the implemented Java method bytecode in the class method can be extracted from the *.class source file, and the corresponding target source code flow is translated according to the Java method bytecode, if it is C language, the corresponding C source code flow; that is, when the class method attribute is static, the unique function name is used to convert the Java method bytecode into the target file corresponding to the to-be-converted language, the to-be-converted language is the current Java language converted into the target language of the application format to be converted, and the to-be-converted language can be Python language, or a database development language such as SQL, Visual Basic, Access and the like, or other to-be-converted languages, and the embodiment is not limited thereto.
[0148] In a specific implementation, if there is a static function call in the current method, the bytecode corresponding to the static function is invokestatic; since the converted static function name is package name+class name+method name+return value+parameter type value (package name+class name+method name+return value+parameter value), the uniqueness of the function name is determined, and there is no problem of duplicate names, so the function can be directly called.
[0149] Step S32, when the class method attribute is non-static, the unique function name is used to convert the Java method bytecode into the target file corresponding to the to-be-converted language by a conversion tool.
[0150] It can be understood that when the class method attribute is non-static, the unique function name is used to convert the Java method bytecode into the target file corresponding to the to-be-converted language by a conversion tool, that is, if the current method is a virtual method, the corresponding bytecode is invokevirtual, and as described above, since the uniqueness of the function name is determined by the conversion mechanism during conversion, the method call is completed by the function name corresponding to the C language.
[0151] 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 by a conversion tool, and when called, the corresponding interface method entry is found in the interface function table of the class where the current interface is located; a self-developed compiler is used to compile a target binary file, and the binary file is downloaded to a card resource, and can be downloaded to the card after the card, and related running and loading are performed.
[0152] In a specific implementation, Figure 7 The class startup loading flowchart in the application format conversion method of the application is as follows: Figure 7As shown, where CreaditApplet is the current class, javacard.framework.Applet is the subclass of CreaditApplet, where the class instantiation process is as follows, where the JavaApplet application is installed through the self-provided install method, and the corresponding class instance is constructed during installation; and the following process can be executed:
[0153] 1. When the Java application is installed, the install method is called to install the application; the constructor of CreaditApplet is called.
[0154] 2. Whether the current class has a parent class, if the parent class exists, the constructor of the parent class is recursively called. Since the current class CreaditApplet stores the constructor, the constructor of the parent class javacard.framwork.Applet is called.
[0155] 3. In the constructor of the current class <init>In the method, instance initialization of the current class is performed, which mainly associates the class initialization function, instance initialization function, static member field initialization and static method of the current class; that is, dynamic loading of the class is performed.
[0156] 4. If there is a class static member in the current class, the class static member of the current class is called. <clinit>The function performs the initialization of static members, assigning initial values to static class member variables.
[0157] 5 Recursive jump to step 3, current class executes constructor <init>
[0158] The embodiment can quickly convert the compiled application file into a file in a specified format without recompilation, thereby saving development cost, accelerating format conversion speed, being high in conversion efficiency, being strong in adaptability, and improving user experience.
[0159] Correspondingly, the application further provides an application format conversion device.
[0160] Referring to Figure 8 , Figure 8 is a function module diagram of the first embodiment of the application format conversion device.
[0161] In the first embodiment of the application format conversion device, the application format conversion device comprises:
[0162] An information extraction module 10 is configured to extract constant pool information and class information from a class file according to preset parameters.
[0163] A bytecode determination module 20 is configured to obtain an inheritance relationship among classes, interfaces and methods in the class file, and determine Java method bytecode according to the constant pool information, the class information and the inheritance relationship.
[0164] A format conversion module 30 is configured to convert the Java method bytecode into a target file corresponding to a language to be converted.
[0165] The information extraction module 10 is further configured to read a class file from a Java Applet according to a conversion tool, obtain a class file structure from preset parameters, and parse constant pool information and class information from the class file according to the class file structure.
[0166] The information extraction module 10 is further configured to parse a constant pool number from the class file according to the class file structure, establish a constant pool storage table, take the constant pool storage table as the constant pool information, obtain an index value describing a class from the constant pool storage table, parse the index value into corresponding string description class information, parse index values in domains, methods and interfaces in the class into string description pre-inheritance relationship information, and determine the class information according to the string description class information and the pre-inheritance relationship information.
[0167] The information extraction module 10 is further configured to parse a parent class in the class from the class file according to the string description class information and the previous inheritance relationship information; and parse the number of interfaces, the interface index, the static member variable and the non-static member variable of the domain, the class method attribute, the bytecode implementation method and the additional attribute table of the class from the class file; and take the number of interfaces, the interface index, the static member variable, the non-static member variable, the class method attribute, the bytecode implementation method and the additional attribute table of the class as the class information.
[0168] The bytecode determination module 20 is further configured to determine the inheritance relationship among the class, the method and the interface of the class file according to the previous inheritance relationship information before the string description; determine whether the current class has a parent class according to the inheritance relationship, the constant pool information and the class information; when the current class has a parent class, determine the output mode of the current class, and determine the member function of the current class according to the output mode; and extract the corresponding Java method bytecode from the class file according to the member function.
[0169] The bytecode determination module 20 is further configured to, when the current class has a parent class and the class method attribute is static, establish a static method table of the topmost parent class; when the current class has a parent class and the class method attribute is non-static, establish a virtual method table of the topmost parent class; add the static member variable of the current class to a class variable table, and add the non-static variable of the current class to a class instance variable; when the current class has a child class, record the number of methods and variables in the current child class, copy the methods and variables of the parent class to the method table of the current child class, and store the number of methods and variables in the current child class; mark the interface method in the current virtual method table; output the *.h file and the *.c file corresponding to the current conversion class, output the member function declaration corresponding to the current class, the static variable structure corresponding to the static method table, the virtual method structure corresponding to the virtual method table, the instance structure corresponding to the instance variable, the static variable initialization function, the loading initialization function corresponding to the current class, the constructor function and the class static domain initialization function; and generate the member function corresponding to the current class according to the member function declaration, the static variable structure, the virtual method structure, the instance structure, the static variable initialization function, the loading initialization function, the constructor function and the class static domain initialization function.
[0170] The format conversion module 30 is further configured to: when the class method attribute is static, invoke a static function in the member function to convert the Java method bytecode into a target file corresponding to a language to be converted; and when the class method attribute is non-static, invoke a virtual function in the member function to convert the Java method bytecode into a target file corresponding to a language to be converted.
[0171] The steps implemented by each functional module of the application format conversion device can refer to the steps implemented by each embodiment of the application format conversion method, which will not be repeated here.
[0172] In addition, an embodiment of the application further provides a storage medium, and the storage medium stores an application format conversion program.
[0173] Extract constant pool information and class information from the class file according to preset parameters;
[0174] Obtain inheritance relationships among classes, interfaces and methods in the class file, and determine Java method bytecode according to the constant pool information, the class information and the inheritance relationships;
[0175] Convert the Java method bytecode into a target file corresponding to a language to be converted.
[0176] Further, the application format conversion program is executed by the processor to further implement the following operations:
[0177] Read a class file from a Java Applet according to a conversion tool, and obtain a class file structure from preset parameters;
[0178] Parse constant pool information and class information from the class file according to the class file structure.
[0179] Further, the application format conversion program is executed by the processor to further implement the following operations:
[0180] Parse a constant pool number from the class file according to the class file structure, establish a constant pool storage table, and use the constant pool storage table as the constant pool information;
[0181] Obtain an index value describing a class from the constant pool storage table, and parse the index value into corresponding string description class information;
[0182] Parse index values in a class, a method and an interface into string description before inheritance relationship information;
[0183] Determine class information according to the string description class information and the inheritance relationship information.
[0184] Further, the application format conversion program, when executed by the processor, further implements the following operations:
[0185] According to the string description class information and the previous inheritance relationship information, the parent class in the class is parsed from the class file;
[0186] And the number of interfaces, interface index, static member variables and non-static member variables of the domain, class method attribute, bytecode implementation method and additional attribute table of the class are parsed from the class file;
[0187] The number of interfaces, interface index, static member variables, non-static member variables, class method attribute, bytecode implementation method and additional attribute table are used as class information.
[0188] Further, the application format conversion program, when executed by the processor, further implements the following operations:
[0189] According to the previous inheritance relationship information before the string description, the inheritance relationship between the class, method and interface of the class file is determined;
[0190] According to the inheritance relationship, the constant pool information and the class information, it is judged whether the current class has a parent class;
[0191] When the current class has a parent class, the output mode of the current class is determined, and the member function of the current class is determined according to the output mode;
[0192] According to the member function, the corresponding Java method bytecode is extracted from the class file.
[0193] Further, the application format conversion program, when executed by the processor, further implements the following operations:
[0194] When the current class has a parent class and the class method attribute is static, a static method table of the top-level parent class is established;
[0195] When the current class has a parent class and the class method attribute is non-static, a virtual method table of the top-level parent class is established;
[0196] The static member variable of the current class is added to the class variable table, and the non-static variable of the current class is added to the class instance variable;
[0197] When the current class has a child class, the number of methods and variables in the current child class is recorded, the methods and variables of the parent class are copied to the method table of the current child class, and the number of methods and variables in the current child class is stored;
[0198] Marking the interface method in the current virtual method table;
[0199] Outputting the *.h file and the *.c file corresponding to the current conversion class, outputting the member function declaration corresponding to the current class, the static variable structure corresponding to the static method table, the virtual method structure corresponding to the virtual method table, the instance structure corresponding to the instance variable, the static variable initialization function, the loading initialization function corresponding to the current class, the constructor function and the class static field initialization function;
[0200] Generating the member function corresponding to the current class according to the member function declaration, the static variable structure, the virtual method structure, the instance structure, the static variable initialization function, the loading initialization function, the constructor function and the class static field initialization function.
[0201] Further, the application format conversion program is further implemented to perform the following operations when executed by the processor:
[0202] When the class method attribute is static, the static function in the member function is called to convert the Java method bytecode into the target file corresponding to the language to be converted;
[0203] When the class method attribute is non-static, the virtual function in the member function is called to convert the Java method bytecode into the target file corresponding to the language to be converted.
[0204] The embodiment extracts the constant pool information and the class information from the class file according to the preset parameters, obtains the inheritance relationship among the classes, interfaces and methods in the class file, determines the Java method bytecode according to the constant pool information, the class information and the inheritance relationship, and converts the Java method bytecode into the target file corresponding to the language to be converted, so that the compiled application file can be quickly converted into the file in the specified format, without recompilation, thereby saving the development cost, accelerating the format conversion speed, improving the conversion efficiency, being strong in adaptability and improving the use experience.
[0205] It should be noted that in this document, the terms "comprise", "comprise", or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or other elements inherent to such a process, method, article or system. Without more limitations, the element defined by the statement "comprises a" does not exclude the presence of another identical element in the process, method, article or system including the element.
[0206] The above-mentioned embodiment numbers of the application are only for description, and do not represent the advantages and disadvantages of the embodiments.
[0207] The above merely provides the preferred embodiments of the present application, and is not intended to limit the patent scope of the present application. Any equivalent structure or equivalent flowchart transformation, or direct or indirect application in other related technical fields, which is made based on the contents of the present application specification and drawings, shall be included in the patent protection scope of the present application.< / init> < / clinit> < / init>
Claims
1. An application format conversion method characterized by, The application format conversion method comprises: extracting constant pool information and class information from the class file according to preset parameters; obtaining inheritance relationships among classes, interfaces and methods in the class file, and determining Java method bytecode according to the constant pool information, the class information and the inheritance relationships; wherein the determining of the Java method bytecode according to the constant pool information, the class information and the inheritance relationships comprises: judging whether the current class has a parent class according to the inheritance relationships, 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 member functions of the current class according to the output mode; wherein the determining of the output mode of the current class and the member functions of the current class according to the output mode when the current class has a parent class comprises: when the current class has a parent class and the class method attribute is static, establishing a static method table of the topmost 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 topmost parent class; adding static member variables of the current class to a class variable table, and adding non-static variables of the current class to a class instance variable; when the current class has a child class, recording the number of methods and variables in the current child class, copying the methods and variables of the parent class to a method table of the current child class, and storing the number of methods and variables in the current child class; marking interface methods in the current virtual method table; outputting *.h files and *.c files corresponding to the current conversion class, and outputting member function declarations of the current class, static variable structures corresponding to the static method table, virtual method structures corresponding to the virtual method table, instance structures corresponding to the instance variable, a static variable initialization function, a loading initialization function of the current class, a constructor function and a class static field initialization function; generating member functions of the current class according to the member function declarations, the static variable structures, the virtual method structures, the instance structures, the static variable initialization function, the loading initialization function, the constructor function and the class static field initialization function; converting the Java method bytecode into target files corresponding to a language to be converted.
2. The application format conversion method of claim 1, wherein, The extracting of the constant pool information and the class information from the input class file according to the preset parameters comprises: reading a class file from a Java Applet according to a conversion tool, and obtaining a class file structure from preset parameters; parsing 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 of the constant pool information and the class information from the class file according to the class file structure comprises: parsing a constant pool number from the class file according to the class file structure, establishing a constant pool storage table, and taking the constant pool storage table as the constant pool information; obtaining an index value describing a class from the constant pool storage table, and parsing the index value into corresponding string class information; Resolving the index value in the field, method and interface in the class into the preceding inheritance information before the string description of the class information; Determine the class information according to the string description of the class information and the preceding inheritance information.
4. The application format conversion method of claim 3, wherein, The determining of the class information according to the string description of the class information and the preceding inheritance information comprises: Resolving the parent class in the class from the class file according to the string description of the class information and the preceding inheritance information; And resolving the number of interfaces, interface index, static member variable and non-static member variable of the field, class method attribute, bytecode implementation method and additional attribute table of the class from the class file; Taking the number of interfaces, the interface index, the static member variable, the non-static member variable, the class method attribute, the bytecode implementation method and the additional attribute table as the class information.
5. The application format conversion method of claim 4, wherein, The determining of the class information according to the string description of the class information and the preceding inheritance information comprises: Determine the inheritance relationship among the class, method and interface of the class file according to the preceding inheritance information before the string description; Extract the corresponding Java method bytecode from the class file according to the member function.
6. The application format conversion method of claim 1, wherein, The converting of the Java method bytecode into the target file corresponding to the language to be converted comprises: When the class method attribute is static, convert the Java method bytecode into the target file corresponding to the language to be converted by using the unique function name through the conversion tool; When the class method attribute is non-static, convert the Java method bytecode into the target file corresponding to the language to be converted by using the unique function name through the conversion tool.
7. An application format conversion apparatus characterized by comprising: The application format conversion device comprises: An information extraction module configured to extract constant pool information and class information from a class file according to preset parameters; A bytecode determination module configured to determine Java method bytecode according to the constant pool information, the class information and the inheritance relationship among the class, interface and method in the class file; A format conversion module configured to convert the Java method bytecode into a target file corresponding to a language to be converted; The bytecode determination module is further configured to determine whether a current class has a parent class according to the inheritance relationship, the constant pool information and the class information; when the current class has the parent class, determine the output mode of the current class, and determine a member function of the current class according to the output mode; The bytecode determination module is further configured to: when the current class has a parent class and the class method attribute is static, 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 non-static, establish a virtual method table of the top-level parent class; add static member variables of the current class to a class variable table and add non-static variables of the current class to a class instance variable; when the current class has a child class, record the number of methods and variables in the current child class, copy the methods and variables of the parent class to the method table of the current child class, and store the number of methods and variables in the current child class; mark interface methods in the virtual method table; output a *.h file and a *.c file corresponding to the current conversion class, output member function declarations corresponding to the current class, static variable structures corresponding to the static method table, virtual method structures corresponding to the virtual method table, instance structures corresponding to the instance variable, a static variable initialization function, a loading initialization function corresponding to the current class, a constructor, and a class static field initialization function; and generate member functions corresponding to the current class according to the member function declarations, the static variable structures, the virtual method structures, the instance structures, the static variable initialization function, the loading initialization function, the constructor, and the class static field initialization function.
8. An application format conversion apparatus characterized by comprising: The application format conversion device comprises a memory, a processor, and an application format conversion program stored on the memory and executable on the processor, and the application format conversion program is configured to implement the steps of the application format conversion method according to any one of claims 1 to 6.
9. A storage medium, characterized by The storage medium stores an application format conversion program, and the application format conversion program implements the steps of the application format conversion method according to any one of claims 1 to 6 when executed by the processor.
Citation Information
Patent Citations
Method and device for obtaining code dependency relationship and electronic device
CN110007920A
Android source code protection method and device
CN111597514A
Java decompilation implementation method, system and device and storage medium
CN111666095A