Summary of the invention
Whether the object of the present invention is to provide a kind of source code integrality detection method and device, change after the pitching pile test to determine software source code, for this reason, the embodiment of the present invention adopts following technical scheme:
A kind of source code integrality detection method, be applied to the pitching pile test process of source code, comprising:
Generate the feature coding of the source code that does not carry out pitching pile, and described feature coding is recorded in the field that does not affect the source code execution in source code;
When being gone the stake operation, the feature coding recorded in the extraction source code, and this feature coding is deleted from source code;
The feature coding of the source code after stake is removed in generation, the feature coding recorded in the feature coding that removes the source code after stake and the source code extracted is compared, and determine the integrality of source code according to comparative result.
A kind of source code integrity detection device, be applied to the pitching pile test process of source code, comprising:
Generation module, for generating the feature coding of the source code that does not carry out pitching pile, and be recorded in described feature coding in the field that does not affect the source code execution in source code;
Extraction module, for when being gone the stake operation, the feature coding recorded in the extraction source code, and this feature coding is deleted from source code;
Comparison module, remove the feature coding of the source code after stake for generation, the feature coding recorded in the feature coding that removes the source code after stake and the source code extracted is compared, and determine the integrality of source code according to comparative result.
The above embodiment of the present invention, generate the feature coding of the source code that does not carry out pitching pile, and described feature coding is recorded in the field that does not affect the source code execution in source code, when being gone the stake operation, the feature coding recorded in the extraction source code, and the described feature coding recorded in source code is deleted, the feature coding of the source code after stake is removed in generation, the feature coding recorded in the feature coding that removes the source code after stake and the source code extracted is compared, and determine the integrality of source code according to comparative result.Thereby, can determine whether software source code is changed after the pitching pile test, and then can be replaced the source code that occurs to change, to prevent wrong source code, be published.
Embodiment
Below in conjunction with the accompanying drawing in the present invention, the technical scheme in the present invention is carried out to clear, complete description, obviously, described embodiment is a part of embodiment of the present invention, rather than whole embodiment.Embodiment based in the present invention, all other embodiment that those of ordinary skills obtain under the prerequisite of not making creative work, belong to the scope of protection of the invention.
Embodiment mono-
The embodiment of the present invention provides a kind of source code integrality detection method, is applied to the pitching pile test process of source code.The integrality of detection resources code, whether the detection resources code any change occurred.As shown in Figure 1, be the treatment scheme of the method, can comprise the following steps.
Step 101, generate the feature coding of the source code that does not carry out pitching pile, and this feature coding be recorded in the field that does not affect the source code execution in source code.
Wherein, this feature coding is one section the coding corresponding with this source code that adopts a kind of irreversible coding rule that former code is converted to, feature coding can have default regular length, and feature coding also can be called fingerprint or the summary of source code.According to this coding rule, each different source code has each self-corresponding unique feature coding, so if the feature coding difference can illustrate that corresponding source code exists different.Concrete, this feature coding can be MD5(Message Digest Algorithm 5, Message Digest Algorithm 5) coding, SHA(Secure Hash Algorithm, Secure Hash Algorithm) coding etc.
Concrete, feature coding being recorded in to the process in source code, can before the pitching pile operation, carry out, can also when operating, pitching pile carry out, can certainly after the pitching pile operation, carry out.Preferably, can be when carrying out the pitching pile operation, the generating feature coding, and the feature coding of generation is recorded in source code.On the one hand, the process of generation and recording feature coding carries out can saving corresponding system resource without the cache feature coding simultaneously, on the other hand, the operation of recording feature coding and pitching pile is carried out simultaneously, stake code and feature coding are write to the relevant position in source code simultaneously, can improve the treatment effeciency of this flow process.
The process of source code being carried out to the pitching pile test is: at first, the stake code is written to (being pitching pile) in tested source code, general stake code is written in the forefront of source code; Then, execution writes the source code after a code, first will carry out anterior stake code, then carry out the source code of back, to realize the test purpose to source code; Finally, the stake code is removed to (going stake).Visible, the record position of feature coding in source code, so long as in above-mentioned test process with pitching pile after the irrelevant field of the execution of source code just passable.Preferably, this field can be the field of the annotation information for storing source code, is about to feature coding and is recorded in the annotation information of source code.
Step 102, when being gone the stake operation, the feature coding recorded in the extraction source code, and this feature coding is deleted from source code.
Preferably, can first the feature coding recorded in source code be extracted from source code, then stake code and feature coding in source code be deleted simultaneously, can improve like this treatment effeciency of this flow process.
Step 103, generate the feature coding remove the source code after stake, the feature coding recorded in the feature coding that removes the source code after stake and the source code extracted compared, and determine the integrality of source code according to comparative result.
After the stake code and feature coding write, regenerate the feature coding of source code in deleting source code.Here the feature coding generated in step 101 is denoted as to feature coding 1, the feature coding regenerated is denoted as to feature coding 2.The contrast characteristic encodes 1 and feature coding 2, if identical, illustrate that its corresponding source code is also identical, be source code through pitching pile, go not change after the operation of stake, there is integrality, if not identical, illustrate that its corresponding source code is not identical, be source code through pitching pile, go to change after the operation of stake, do not there is integrality.
By the above-mentioned flow process of the embodiment of the present invention, can the integrality of carrying out the source code before and after pitching pile test be detected, if find to go the source code integrality existing problems after stake, can before the source code issue, it be replaced with to correct source code.But, also there is some situation, as script failure etc., cause the stake operation to be carried out unsuccessfully, and the integrity detection result is made mistakes.For this situation, the embodiment of the present invention has also proposed following solution.
When the stake code starts to carry out, judge whether current execution environment is test environment, if so, carry out the stake code, otherwise, skip a code, carry out source code.Specifically can add at the forefront of stake code the judgement statement, to judge current execution environment.If current execution environment is test environment, the execution environment of explanation stake code is correct, can sequentially carry out a code and source code.If current execution environment is operating environment, illustrate that the source code with the stake code is published, because the correct execution environment of stake code should be test environment, so this execution environment mistake, at this moment, if still carry out the stake code may cause program to report an error, can skip a code (not carrying out a code), carry out source code.
The above embodiment of the present invention, generate the feature coding of the source code that does not carry out pitching pile, and described feature coding is recorded in the field that does not affect the source code execution in source code, when being gone the stake operation, the feature coding recorded in the extraction source code, and the described feature coding recorded in source code is deleted, the feature coding of the source code after stake is removed in generation, the feature coding recorded in the feature coding that removes the source code after stake and the source code extracted is compared, and determine the integrality of source code according to comparative result.Thereby, can determine whether software source code is changed after the pitching pile test, and then can be replaced the source code that occurs to change, to prevent wrong source code, be published.
Embodiment bis-
As shown in Figure 2, the treatment scheme of source code integrality detection method in concrete application scenarios for the embodiment of the present invention provides, can comprise the following steps.
Step 201, the MD5 that generates the source code that does not carry out pitching pile encodes, and is denoted as coding A.
Step 202, by the coding A be written in the annotation information of source code, and by the stake code insertion in source code.General stake code can write on the forefront of source code.
Step 203, the source code after the execution pitching pile, tested source code.
Step 204 is extracted coding A from source code.
Step 205 is deleted stake code and coding A in source code.
Step 206, the MD5 coding of the source code after stake is removed in generation, is denoted as coding B.
Step 207, whether the coding A that judgement is extracted from source code is consistent with the value of removing the rear coding B generated of stake, if so, determines that source code does not change, otherwise, determine that source code changes.
The above embodiment of the present invention, generate the feature coding of the source code that does not carry out pitching pile, and described feature coding is recorded in the field that does not affect the source code execution in source code, when being gone the stake operation, the feature coding recorded in the extraction source code, and the described feature coding recorded in source code is deleted, the feature coding of the source code after stake is removed in generation, the feature coding recorded in the feature coding that removes the source code after stake and the source code extracted is compared, and determine the integrality of source code according to comparative result.Thereby, can determine whether software source code is changed after the pitching pile test, and then can be replaced the source code that occurs to change, to prevent wrong source code, be published.
Embodiment tri-
Technical conceive based on identical, the embodiment of the present invention also provides a kind of source code integrity detection device, is applied to the pitching pile test process of source code, as shown in Figure 3, comprising:
Generation module 310, for generating the feature coding of the source code that does not carry out pitching pile, and be recorded in described feature coding in the field that does not affect the source code execution in source code;
Extraction module 320, for when being gone the stake operation, the feature coding recorded in the extraction source code, and this feature coding is deleted from source code;
Comparison module 330, remove the feature coding of the source code after stake for generation, the feature coding recorded in the feature coding that removes the source code after stake and the source code extracted is compared, and determine the integrality of source code according to comparative result.
Preferably, described generation module 310, specifically for:
When carrying out the pitching pile operation, generate the feature coding of the source code that does not carry out pitching pile, and described feature coding is recorded in the field that does not affect the source code execution in source code.
Preferably, described generation module 310, specifically for:
Described feature coding is recorded in the annotation information of source code.
Preferably, described feature coding is specially MD5 coding or SHA coding.
Preferably, also comprise execution module, for:
When the stake code starts to carry out, judge whether current execution environment is test environment, if so, carry out described stake code, otherwise, skip described stake code, carry out source code.
The above embodiment of the present invention, generate the feature coding of the source code that does not carry out pitching pile, and described feature coding is recorded in the field that does not affect the source code execution in source code, when being gone the stake operation, the feature coding recorded in the extraction source code, and the described feature coding recorded in source code is deleted, the feature coding of the source code after stake is removed in generation, the feature coding recorded in the feature coding that removes the source code after stake and the source code extracted is compared, and determine the integrality of source code according to comparative result.Thereby, can determine whether software source code is changed after the pitching pile test, and then can be replaced the source code that occurs to change, to prevent wrong source code, be published.
It will be appreciated by those skilled in the art that the module in the device in embodiment can be distributed in the device of embodiment according to the embodiment description, also can carry out respective change and be arranged in the one or more devices that are different from the present embodiment.The module of above-described embodiment can be merged into a module, also can further split into a plurality of submodules.
The invention described above embodiment sequence number, just to describing, does not represent the quality of embodiment.
Through the above description of the embodiments, those skilled in the art can be well understood to the mode that the present invention can add essential general hardware platform by software and realize, can certainly pass through hardware, but in a lot of situation, the former is better embodiment.Understanding based on such, the part that technical scheme of the present invention contributes to prior art in essence in other words can embody with the form of software product, this computer software product is stored in a storage medium, comprise that some instructions are with so that a station terminal equipment (can be mobile phone, personal computer, server, or the network equipment etc.) the described method of execution each embodiment of the present invention.
The above is only the preferred embodiment of the present invention; it should be pointed out that for those skilled in the art, under the premise without departing from the principles of the invention; can also make some improvements and modifications, these improvements and modifications also should be looked protection scope of the present invention.