First, share == free?
With the Internet, the "Sharing Registration" model has become the main means of programmers to publish their own software, but the cracks that come with the crack are getting higher and higher. How to protect your labor results are not crack or modified? Validation with MD5 Summary is a very common method.
As an open algorithm, MD5 is a lot of ways, such as open source software, Windows comes with API, etc., C Builder and Delphi integrated Indy have ready-made MD5 controls. Using the API implementation of MD5 although high efficiency, it is too cumbersome, and the specific method can refer to the function description of the CRYPT starting on MSDN. Although the MD5 control with C Builder is convenient, but the speed is slow, and only the string ending with '/ 0', so it is necessary to use this control to do some prerequisites to verify data. The key to the pretreatment is to put more important content to calculate. On the other hand, the '/ 0' can be removed, and the other hand can greatly reduce the length of the content to be verified, only the summary value of the critical code is calculated.
Second, the source program Xiang solution
First, the online and borland help is very small. This program is basically my own exploration result, and running in C Biulder 6.0 and INDY 6.0.
First drag an MD5 control in Indy Misc, assume that its Name is Cipher, the program is as follows:
/ *
MD5 calculation function by daydreamer 2004-04
Function: Calculate 16-word DV5 value for files named FNAME, put it in Result
Enter: Pointer Char * FNAME pointing to the file name
Output: MD5 value is placed in the buffer pointing in Result
Return Value: Returns true if the MD5 value is correctly calculated, otherwise returns false
* /
Bool MD5 (Char * Fname, Char * Result)
{
unsigned int i = 0; // Used to record the size of the read file
Bool flag = false; / / When the MD is calculated correctly,
Static Ansistring SS; // Used to temporarily store the MD5 value
Char * buffer = new char [myfile_size]; // Used to read the target file, the file size cannot exceed myFile_size
TFileStream * TT = New TFileStream (FNAME, FMOPENREAD); // Used to read all content of the target file, use this method simple, you can also read with standard CreateFile ()
i = tt-> read (buffer, myfile_size); // i saves the number of bytes that actually read
IF ((i) && (i! = 1)) // If the number of readout bytes is not 0 or 1, processes
{i = i-1; // The last byte must be left for end of the conclusion
_ASM {// This paragraph is mainly used to pretrece file pretreatment
MOV ECX, I; // set counter
MOV EBX, BUFFER; // Source address pointer
MOV EDX, Buffer; // destination address pointer
L1: MOV Al, [EBX]; // Take a byte, because if the file is too large, it is necessary to deepen the source string by finer granulation.
CMP Al, 0x70; // Only bytes greater than 0x70 and less than 0x91 is summarized JB L2; // Because of the main transfer command (JZ, JNZ), the empty operation instruction (NOP) is greater than 0x70 less than 0x91
CMP Al, 0x91; // can also be replaced with a more loose condition, but at least 0x00 should be filtered off because it is considered endorsement
JNB L2;
MOV [EDX], Al; / / Equivalent byte is saved to wait for verification
Inc EDX;
L2: Inc EBX;
Dec ECX;
JNZ L1;
MOV BYTE PTR [EDX 1], 0; // At the end of the end of the end value '/ 0'
}
Cipher-> reset (); // You should reset some of the parameters inside each time you use this control
Cipher-> autocompleteinput = false; // only get results when calling completedInput ()
Cipher-> codestring (buffer); / / Enter the pre-processed data
SS = Cipher-> CompletedInput (); // Enter completed, get a summary code
IF (s.length () = md5_lenghth) // If the summary code is normal (ie 16 bits), save it
{Flag = true; // Place the correct sign
Memcpy (result, ss.c_str (), 16); // Put the result into the Result
} // end if
} // end if
DELETE TT;
DELETE [] BUFFER;
Return flag;
}
You can use Application-> Exename.c_str () as a FNAME in the time of call, pay attention to direct Run in C BiUlder, this will cause an exception, which does not matter, published programs do not have problems. Here, for the sake of brevity, there is no saving and recovery register in the assembly code. You can add it when you are using, or when you publish the Register Variables in Optionsèadvanced Complier to NONE.
The method of using this control in Delphi is similar, and it will not be described again.
Third, how to use
There are many ways to protect shared software using MD5 values. The simplest, such as the normal execution module's MD5 summary value is static in an external file (such as included in the registration file), calculate its own MD5 each time. In contrast, it is determined whether it is modified. The high-profile such as the correct MD5 to restore the correct entry address, or participate in the registration code / machine code calculation. It is best to add a shell with the compression software such as ASPROTECT or Aspack after adding its own MD5 verification, so that once Cracker takes the shell with shelling software, the software will not perform normally, for many CRACK Newbie ten eight nine Will doubt the shell failed and put it.
In fact, software protection and cracks will always be a pair of contradictions in the magic road, no matter how strict precautions, certain people can break. What we have to do is to block a lot of rookie Cracker. If you are not fortunate to be eye-stayed, congratulations: This shows that your software is really valuable.