The previous section we introduced the junk code, but the junk code, after all, a very simple thing, basically into the door of Cracker can be dealt with. Therefore, we do need to own software with better protection. CRC check is a good method for them.
CRC is anything? In fact, we should not will it strange to recall? You used such as RAR and ZIP compression software? They are not always give you an annoying “CRC checksum error” message? I think you should get the point, CRC block of data is calculated, which stands for “Cyclic Redundancy Check”, Chinese name is “cyclic redundancy code”, “CRC check” is “cyclic redundancy check.” (Wow, really a mouthful, that we should not when I was a monk Tang Oh ??_^)
CRC What is the use? It is a very broad range of applications, the most common is the transmission of information in the network proofreading. In fact, we could apply it to software protection to, because its calculation is very, very strict. Strictly to what extent? Change your program as long as a byte (or even just the case of changes), its value will be different from the original. Hoho, it is not very powerful? So as long as your “original” program calculated the CRC value stored in one place, and then randomly in the program files CRC checksum again and then with the first CRC value generated and saved a good comparison, if the same If on the instructions of your program has not been modified / cracked-off, if unequal, then your program may have been infected with the virus, or 16 hex tool used by Cracker brute before.
Nonsense finished, let's take a look at the principles of CRC.
(CRC to achieve up to a certain extent because of the difficulty, so how to use it to protect specific files, leaving the next section talk anymore.)
First look at two formulas:
Type I: 9 / 3 = 3 (remainder = 0)
Type II: (9 + 2) / 3 = 3 (remainder = 2)
In elementary school we know, division operation is to repeatedly subtract the divisor minuend X times, then leave the remainder.
So the above two formulas can be calculated as binary: (What? You will not binary calculation? Me down ~ ~ ~)
Type 1:
1001 -> 9
0011 - -> 3
———
0110 -> 6
0011 - -> 3
———
0011 -> 3
0011 - -> 3
———
0000 -> 0, the remainder
Has reduced by 3 times, so business is 3, but the last time out by the results is 0, so the remainder is 0
Type II:
1011 -> 11
0011 - -> 3
———
1000 -> 8
0011 - -> 3
———
0101 -> 5
0011 - -> 3
———
0010 -> 2, the remainder
Has reduced by 3 times, so business is 3, and the results of the last cut out is 2, so the remainder is 2
See understand? Well, let's go on!
Binary subtraction rule is that if the situation encountered by 0-1, then from the high by 1, becomes (10 +0) -1 = 1
CRC calculation are any different? Let us look at the following example:
The use of formula 30 / 9, but please note the final remainder reader:
11110 -> 30
1001 - -> 9
———
1100 -> 12 (very strange, right? Why not 21 then?)
1001 - -> 9
——–
101 -> 3, the remainder -> the CRC!
The calculation of this formula is not strange then? It is not a direct cut, but the way to operations with XOR (XOR programmer should be very familiar with it), and finally get a remainder.
Yeah, this is the CRC computation method, understand? CRC is the essence for XOR, operation process, we do not cares, because the calculation process on the final result does not make sense; we are really only interested in the remainder by the end, the remainder is the CRC value.
For a CRC computation we need to select a divisor, this divisor we call it the “poly”, the width W is the highest position, so I cited the example of the divisor 9, the W-poly 1001 is 3, not 4 , note that the highest bit is always 1. (Do not ask why, this is a requirement)
If we want to compute a bit string of the CRC code, we want to make sure every bit is being processed, so we have to add the words in the target bit string W a 0. Let us now look at CRC codes to rewrite the above example:
Poly = 1001, width W = 3
Bit String Bitstring = 11110
Bitstring + W zeroes = 11110 + 000 = 11110000
11,110,000
1001 | | | | -
————-
1100 | | |
1001 | | | -
————
1010 | |
1001 | | -
———–
0110 |
0000 | -
———-
1100
1001 -
———
101 -> 3, the remainder -> the CRC!
There are two important statement as follows:
1, the highest level only when Bitstring 1, we carried it with poly XOR, or we just will Bitstring left one.
2, XOR operation result is a bit string Bitstring be operated with low-poly W bits XOR operation, because the highest bit is always 0.
Oh, is it not Touyunnaozhang feel it? Can not read it, then go over from scratch, is well understood. (Is an XOR operation it!)
Well, the principle introduced here, here how I talk about specific programming.
Because the relationship between speed, CRC implementation mainly through look-up table for CRC-16 and CRC-32, each of which has a ready-made table, we can use directly into the program. (These two tables too long, not listed here, please readers find themselves on the network, it is easy to find.)
If we do not have the table how to do? Or you, like me, too lazy to enter their own? Do not worry, we can “do it yourself and clothing.”
You may say that their programming to generate the table, will not slow? Actually need not worry because we are in the compilation of code that operate on the level, and this table is only a mere 256 pairs of words, simply not affect speed.
The C language described in this table are as follows:
for (i = 0; i <256; i + +)
(
crc = i;
for (j = 0; j <8; j + +)
(
if (crc & 1)
crc = (crc>> 1) ^ 0xEDB88320;
else
crc>> = 1;
)
crc32tbl [i] = crc;
)
After generating the table, the operation can be a.
Our algorithm is as follows:
1, will move to the right, a byte register.
2, just out of the byte string in our new byte XOR operation, we reached a point value table table [0 .. 255] index.
3, the index value and the register referred to in the table to do XOR operation.
4, if not all processed data, then skip to step 1.
C language description of this algorithm is as follows:
temp = (oldcrc ^ abyte) & 0x000000FF;
crc = ((oldcrc>>
& 0x00FFFFFF) ^ crc32tbl [temp];
return crc;
Well, all the stuff said Wan La, the last offer a complete Win32Asm example, the reader examine it!
(CRC-32 compilation of information on aspects of little ah, I personally think that given below is very valuable information.)
;************************************************* ***
; Program name: CRC32 principle demonstration
; Of: Luo Cong
; Date :2002-8-24
; Source: http://laoluoc.yeah.net (Luo's Fun World)
; Note: For reprint requests to maintain the integrity of this process, and indicate: Reprinted from the “Old Luo's Fun World” (http://laoluoc.yeah.net)
;
; Special thanks Win32ASM master - dREAMtHEATER made for my very good code optimization!
; Please go http://NoteXPad.yeah.net download his compact “cool notebook” - NoteXPad to try! (100% Win32ASM preparation)
;
;************************************************* ***
.386
. Model flat, stdcall
option casemap: none
include windows.inc
include kernel32.inc
include user32.inc
includelib kernel32.lib
includelib user32.lib
WndProc proto: DWORD,: DWORD,: DWORD,: DWORD
init_crc32table proto
arraycrc32 proto
. Const
IDC_BUTTON_OPEN equ 3000
IDC_ED99v_INPUT equ 3001
. Data
szDlgName db “lc_dialog”, 0
szTitle db “CRC demo by LC”, 0
szTemplate db “string” “% s” “The CRC32 value is:% X”, 0
crc32tbl dd 256 dup (0); CRC-32 table
szBuffer db 255 dup (0)
. Data?
szText db 300 dup (?)
. Code
main:
invoke GetModuleHandle, NULL
invoke DialogBoxParam, eax, offset szDlgName, 0, WndProc, 0
invoke ExitProcess, eax
WndProc proc uses ebx hWnd: HWND, uMsg: UINT, wParam: WPARAM, lParam: LPARAM
. If uMsg == WM_CLOSE
invoke EndDialog, hWnd, 0
. Elseif uMsg == WM_COMMAND
mov eax, wParam
mov edx, eax
shr edx, 16
movzx eax, ax
. If edx == BN_CLICKED
. IF eax == IDCANCEL
invoke EndDialog, hWnd, NULL
. ELSEIF eax == IDC_BUTTON_OPEN | | eax == IDOK
;******************************************
; Key code start: (Dangdang Dangdang … …)
;******************************************
; Get user input string:
invoke GetDlgItemText, hWnd, IDC_ED99v_INPUT, addr szBuffer, 255
; Initialization crc32table:
invoke init_crc32table
; The following assignment to the register ebx, for crc32 conversion:
; EBX is the string to be converted first address:
lea ebx, szBuffer
; For crc32 conversion:
invoke arraycrc32
; Formatted output:
invoke wsprintf, addr szText, addr szTemplate, addr szBuffer, ea
; Well, let us show the results:
invoke MessageBox, hWnd, addr szText, addr szTitle, MB_OK
. ENDIF
. Endif
. ELSE
mov eax, FALSE
ret
. ENDIF
mov eax, TRUE
ret
WndProc endp
;************************************************* *********
; Function function: generate CRC-32 table
;************************************************* *********
init_crc32table proc
; If using C language that should be as follows:
;
; For (i = 0; i <256; i + +)
; (
; Crc = i;
; For (j = 0; j <8; j + +)
; (
; If (crc & 1)
; Crc = (crc>> 1) ^ 0xEDB88320;
; Else
; Crc>> = 1;
;)
; Crc32tbl [i] = crc;
;)
;
; Oh, let us change the assembly of the above statement:
mov ecx, 256; repeat for every DWORD in table
mov edx, 0EDB88320h
$ BigLoop:
lea eax, [ecx-1]
push ecx
mov ecx, 8
$ SmallLoop:
shr eax, 1
jnc @ F
xor eax, edx
@ @:
dec ecx
jne $ SmallLoop
pop ecx
mov [crc32tbl + ecx * 4-4], eax
dec ecx
jne $ BigLoop
ret
init_crc32table endp
;************************************************* *************
; Function features: calculating CRC-32
;************************************************* *************
arraycrc32 proc
; Calculated CRC-32, I used the whole string as an array, then assign the array's first address to the EBX, to array the length of the assignment to ECX, then loop calculation, the return value (calculated by the CRC- 32 value) stored in the EAX in:
;
; Parameters:
; EBX = address of first byte
; Return value:
; EAX = CRC-32 of the entire array
; EBX =?
; ECX = 0
; EDX =?
mov eax, -1; first initialize eax
or ebx, ebx
jz $ Done; avoid a null pointer
@ @:
mov dl, [ebx]
or dl, dl
je $ Done; to determine whether the scan is completed on a string
; Here I use look-up table method to calculate the CRC-32, so very fast:
; Because it is the assembly code, so this process does not need to pass parameters, just make oldcrc assigned to EAX, and the byte assigned to the DL:
;
; In the C language in the form of:
;
; Temp = (oldcrc ^ abyte) & 0x000000FF;
; Crc = ((oldcrc>>
& 0x00FFFFFF) ^ crc32tbl [temp];
;
; Parameters:
; EAX = old CRC-32
; DL = a byte
; Return value:
; EAX = new CRC-32
; EDX =?
xor dl, al
movzx edx, dl
shr eax, 8
xor eax, [crc32tbl + edx * 4]
inc ebx
jmp @ B
$ Done:
not eax
ret
arraycrc32 endp
end main
;******************** Over backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google. html.md5 log maint news: 10 news: 11 news: 12 news: 13 news: 14 news: 15 news: 16 news: 17 news: 18 news: 2 news: 3 news: 4 news: 5 news: 6 news: 7 news: 8 news: 9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6-tar.gz xml2dict-read-only
; By LC
Here is it. Rc files:
# Include “resource.h”
# Define IDC_BUTTON_OPEN 3000
# Define IDC_ED99v_INPUT 3001
# Define IDC_STATIC -1
LC_DIALOG DIALOGEX 10, 10, 195, 60
STYLE DS_SETFONT | DS_CENTER | WS_MINIMIZEBOX | WS_VISIBLE | WS_CAPTION |
WS_SYSMENU
CAPTION “lc's assembly framework”
FONT 9, “Arial”, 0, 0, 0x0
BEGIN
LTEXT “Enter a string (case sensitive):”, IDC_STATIC, 11,7,130,10
ED99vTEXT IDC_ED99v_INPUT, 11,20,173,12, ES_AUTOHSCROLL
DEFPUSHBUTTON “Ca & lc”, IDC_BUTTON_OPEN, 71,39,52,15
????:
“Mom” To Baidu was “angry”
Fireworks 8 dream trip (5): the new changes in the menu
Mkv File
Good Password Managers
Jie Mi Foxconn employees jumped the truth
Photoshop to create Beauty facial skin texture
How to obtain THE state of flip
Large LCD and plasma WAS born in the price of 30,000 yuan or more Changhong
Compare Reference Tools
m4a to MP3
Graphical Modeling AutoCAD2000 Football
Mkv
.mkv