The content of the invention
It is an object of the invention to provide a kind of method of the compatible different file format java applications of Dalvik virtual machine andDevice, can preferably solve the problems, such as the compatible different file format java applications of Dalvik virtual machine.
According to an aspect of the invention, there is provided a kind of compatible different file format java applications of Dalvik virtual machineMethod, comprise the following steps:
Dalvik virtual machine is judged the file format from outside java programs;
If judging the form of the java programs for dex file formats, the java programs are examined by dex file formatsTest, and it is loaded after verifying successfully;
If judging the form of the java programs for jar file form, the java programs are examined by jar file formTest, and it is loaded after verifying successfully.
Preferably, Dalvik virtual machine reads the file header of java programs, and according to the file header read, described in judgementThe form of java programs is dex file formats or jar file form.
Preferably, described the step of being tested by jar file form to the java programs, includes:
Dalvik virtual machine creates jar checkers, and the metadata of the java programs is entered using the jar checkersRow verification.
Preferably, after to the java program ver-ifies success of the jar file form, in addition to:
Dalvik virtual machine judges with the presence or absence of digital signature the java programs of the jar file form, andWhen judging that the java programs have digital signature, the digital signature is verified.
Preferably, the load step includes:
Dalvik virtual machine using jar file form Classloader loading jar file form java programs, and according toJar file format analysis simultaneously performs loaded java programs.
Preferably, described the step of being verified by dex file formats to the java programs, includes:
Dalvik virtual machine carries out school using its dex checker to the metadata of the java programs of the dex file formatsTest.
Preferably, after to the java program ver-ifies success of the dex file formats, in addition to:
Dalvik virtual machine judges with the presence or absence of digital signature the java programs of the dex file formats, andWhen judging that the java programs have digital signature, the digital signature is verified.
Preferably, the load step includes:
Dalvik virtual machine using dex file formats Classloader loading dex file formats java programs, and according toDex File Format Analysis simultaneously performs loaded java programs.
According to another aspect of the present invention, there is provided a kind of compatible different file format java applications of Dalvik virtual machineDevice, including:
Form judge module, for judging the file format from outside java programs;
Dex file format java program processing modules, in the form for judging the java programs for dex file formatsWhen, the java programs are tested by dex file formats, and it is loaded after verifying successfully;
Jar file form java program processing modules, in the form for judging the java programs for jar file formWhen, the java programs are tested by jar file form, and it is loaded after verifying successfully.
Preferably, in addition to:
Digital signature processing module, for the java programs to Dex file formats or jar file form with the presence or absence of numeralSignature is judged, and when judging that the java programs have digital signature, the digital signature is verified.
Compared with prior art, the beneficial effects of the present invention are:The present invention can make dalvik virtual machine compatibilities jarThe java programs of bytecode format.
Embodiment
Below in conjunction with accompanying drawing to a preferred embodiment of the present invention will be described in detail, it will be appreciated that described below is excellentSelect embodiment to be merely to illustrate and explain the present invention, be not intended to limit the present invention.
Fig. 1 is the Method And Principle of the compatible different file format java applications of Dalvik virtual machine provided in an embodiment of the present inventionBlock diagram, as shown in figure 1, step includes:
Step 101, Dalvik virtual machine are judged the file format from outside java programs.
In the step 101, Dalvik virtual machine reads the file header of java programs, and according to the file readHead, the form for judging the java programs are dex file formats or jar file form.
Step 102, if the forms of the java programs is judged for dex file formats, by dex file formats to the java journeysSequence is tested, and it is loaded after verifying successfully.
In the step 102, first, Dalvik virtual machine creates jar checkers, and utilizes the jar checkers pairThe metadata of the java programs is verified.Secondly, the java programs are judged with the presence or absence of digital signature, andWhen judging that the java programs have digital signature, the digital signature is verified.Then, the class of jar file form is utilizedLoader loads the java programs of jar file form, and according to jar file format analysis and performs loaded java programs.
Step 103, if the forms of the java programs is judged for jar file form, by jar file form to the java journeysSequence is tested, and it is loaded after verifying successfully.
In the step 103, first, Dalvik virtual machine is using its dex checker to the dex file formatsThe metadata of java programs is verified.Secondly, the java programs of the dex forms are sentenced with the presence or absence of digital signatureIt is disconnected, and when judging that the java programs have digital signature, the digital signature is verified.Then, dex trays are utilizedThe java programs of the Classloader loading dex file formats of formula, and according to dex File Format Analysis and perform loaded javaProgram.
That is, java programs have file header, for the java programs of jar bytecode formats, its file header using PK asMagic number start, and for the java programs of Dex bytecode formats, its file header is started with dex.Therefore, by rightThe file header of java programs is verified, and can distinguish the file format of java programs, so as to be solved according to different standardsRelease.
Fig. 2 is the flow chart of the compatible different file format java applications of Dalvik virtual machine provided in an embodiment of the present invention,As shown in Fig. 2 including:
Step 200, Dalvik virtual machine judge that the file format of java programs is dex bytecode formats or jar bytesCode form, and when it is dex bytecode formats to judge the java programs, execution step 202, judging that the java programs areDuring jar bytecode formats, step 201 is performed.
Step 201, when the java programs are the java programs of jar bytecode formats, create first for parsing instituteThe jar checkers of java programs are stated, and perform step 203.
Step 202, when the java programs are the java programs of dex bytecode formats, utilize its dex checker, solutionThe metadata of the java programs of analysis verification dex bytecode formats, and perform step 204.
Step 203, utilize created jar checkers, first number of the java programs of parsing verification jar bytecode formatsAccording to, and perform step 205.
Step 204, after verifying successfully, Dalvik virtual machine judges whether the java programs of the dex bytecode formats haveThere is digital signature, if digital signature be present, the digital signature is verified, and after verifying successfully, perform step206, if digital signature is not present, directly perform step 206.
Step 205, after verifying successfully, Dalvik virtual machine judges whether the java programs of the jar bytecode formats haveThere is digital signature, if digital signature be present, the digital signature is verified, and after verifying successfully, perform step207, if digital signature is not present, directly perform step 207.
Step 206, using dex Classloaders, load the java programs of dex bytecode formats, and perform step 208.
Step 207, using jar Classloaders, load the java programs of jar bytecode formats, and perform step 209.
Step 208, according to dex bytecode formats, parse and perform the java programs of loaded dex bytecode formats.
Step 209, according to jar bytecode formats, parse and perform the java programs of loaded jar bytecode formats.
Fig. 3 is the judgement flow provided in an embodiment of the present invention to the loading of java programs, as shown in figure 3, including:
Step 301, judge java program file heads before four bytes whether matched with magic number.
By reading preceding 4 bytes of java program file heads, judge whether java programs are jar file form or dexFile format, if preceding 4 bytes are exactly magic number, judged result is matching, and performs step 302, is otherwise performedStep 308.
Step 302, judge whether to need to create jar checkers.
If the java programs of dex file formats, then java programs are verified by dex file formats, and press original flowCarry out, if the java programs of jar file form, then create jar checkers, and perform step 303, otherwise, perform step308。
The metadata of step 303, parsing verification java programs.
Created jar checkers are utilized, the java programs of the jar file form are verified, if verifying successfully,Step 304 is then performed, otherwise, performs step 308.
Step 304, judge whether the java programs have digital signature.
After metadata according to the java programs of specification validation jar file form, determine whether the java programs haveDigital signature, if digital signature be present, checking treatment is carried out to the digital signature, and perform step successively after verifying successfullyRapid 305, to step 307, otherwise, perform step 308, if digital signature is not present, perform step 305 successively to step 307.
After step 305, verification pass through, the java programs of jar file form are loaded using jar Classloaders.
Step 306, the execution java programs are explained according to jar file form, i.e., according to the java programs, generationThe object code of jar bytecode formats.
Step 307, the operation java programs, that is to say, that when performing jar bytecodes, jar bytecodes are construed toMachine instruction performs.
Step 308, there is mistake, exit flow.
Fig. 4 is the device frame of the compatible different file format java applications of Dalvik virtual machine provided in an embodiment of the present inventionFigure, as shown in figure 4, including:
Form judge module 401, for judging the file format from outside java programs;
Dex file format java programs processing module 403, in the form for judging the java programs for dex traysDuring formula, the java programs are tested by dex file formats, and it is loaded after verifying successfully;
Jar file form java programs processing module 402, in the form for judging the java programs for jar file latticeDuring formula, the java programs are tested by jar file form, and it is loaded after verifying successfully;
Digital signature processing module 404, for whether there is to the java programs of dex file formats or jar file formDigital signature is judged, and when judging that the java programs have digital signature, the digital signature is verified.
The form judge module 401 judges the file format of java programs, and according to obtained different judged results, byDifferent processing module processing java programs, that is, when being judged as jar file form, mould is handled by jar file form java programsBlock 402 handles java programs, and when being judged as dex file formats, java journeys are handled by dex file format java program modules 403Sequence.When jar file form java programs processing module 402 handles the java programs of jar file form, jar verifications are created firstDevice, and checking treatment is carried out to the metadata of java programs using the jar checkers, and after verifying successfully, utilize jar classesLoader, the java programs are loaded, and the java programs to being loaded explain execution.Dex file format java programsWhen processing module 403 handles the java programs of dex file formats, first number using the dex checkers of its own to java programsAccording to carrying out checking treatment, and after verifying successfully, using dex Classloaders, load the java programs, and to being loadedJava programs explain execution.
When the java programs have digital signature, before the loading of java programs, digital signature processing mould can be usedBlock 404 confirms to the legitimacy of the java programs, and after confirming successfully, then carry out the subsequent treatment step of java programsSuddenly.
Although the present invention is described in detail above, the invention is not restricted to this, those skilled in the art of the present techniqueVarious modifications can be carried out according to the principle of the present invention.Therefore, all modifications made according to the principle of the invention, all should be understood toFall into protection scope of the present invention.