ingridbruton

July 31, 2010

Spear and shield of the contest - CRC principle Posts

Filed under: Uncategorized

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>> 8) & 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>> 8) & 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

49 Comments »

The URI to TrackBack this entry is: http://ingridbrutonsc.blogsome.com/2010/07/31/spear-and-shield-of-the-contest-crc-principle-posts/trackback/

  1. more feminine side of her eyes. “The little East - you put a bad thing for me?” Chapter VIII scholarly body of housing Updated :2010-10-23 10:37:22 number of words in this chapter: 3532,

    Comment by birkenstock outlet — June 14, 2011 @ 8:19 am

  2. up and down the Yang-hi about it, nodded:” Yes, fat, and I’m also relieved. “NAVAL very disagreeable and engage in quite concerned about their looks Zhesi like, do not think they can not

    Comment by Oakley Sunglasses Cheap — June 29, 2011 @ 6:18 am

  3. So wonderful!Very worth to read.

    Comment by canada goose parka — July 2, 2011 @ 3:52 am

  4. Thank you for your useful information.

    Comment by juicy couture outlet online — July 2, 2011 @ 3:52 am

  5. After read your post,i have learned a lot,thank you.

    Comment by juicy couture outlet — July 2, 2011 @ 3:52 am

  6. shopping Birkenstock Shoes

    Comment by Birkenstock Outlet — July 8, 2011 @ 1:12 am

  7. shopping the Reva Flats Shoes

    Comment by Reva Flats — July 8, 2011 @ 1:12 am

  8. I liked your project in your page, you are standing up with knowledge!
    It turns out we had the same taste in movies. Lorelei liked Action movies and Science Fiction thrillers. She wasn’t into Chick Flicks. That’s really good, because I’m really not into those kinds of movies. Everyday life was boring enough, thank you very much. Lorelei and I became inseparable. We would go to class together, hand in hand.

    Comment by cheap DC Hats — July 11, 2011 @ 7:18 am

  9. I am going to start a small Blog course work using your site I hope you enjoy blogging with the popular net.The thoughts you express are really awesome. Hope you will right some more posts.Thanks for good news! Your site is very useful for me.Welcome to my blog.

    Comment by Cheap tiffany Jewelry SET — July 16, 2011 @ 2:49 am

  10. live up to the expectations of her mother.” “Ok, Mom, how many times you have said, I will work hard, and to your daughter My talent, will not let you down your friends. “mom these days has

    Comment by North Face — July 25, 2011 @ 1:47 am

  11. Thanks for you sharing.That is good article.I like it.

    Comment by UGG UK — July 26, 2011 @ 3:57 am

  12. nice post!!!!!

    Comment by Red Bottom Heels — July 26, 2011 @ 3:58 am

  13. see several people who lead the way in the past looked at the third brother and the others came back Fuer whispered to the fine, said a few tall, tall, thin face with change, but also the man said

    Comment by North Face — July 29, 2011 @ 3:07 am

  14. unbearable in the bottom of my heart took root Momo Yang nightmare. Momo was brought by the mother, Yang was brought up alone, you can have peace even if the growth to the twenty-year-old,

    Comment by Global UGGs — July 29, 2011 @ 4:05 am

  15. My programmer is trying to persuade me to move to .net from PHP. I have always disliked the idea because of the costs. But he’s tryiong none the less. I’ve been using Movable-type on a number of websites for about a year and am concerned about switching to another platform. I have heard good things about blogengine.net. Is there a way I can transfer all my wordpress content into it? Any help would be really appreciated!

    Comment by Cheap Hats — August 3, 2011 @ 7:15 am

  16. I am New Here,My name is Jesse and this is my first entry here. feel sometimes, that I have to learn a lot, hope you guys have patient on me.Thank you for sharing the post.

    Comment by Chanel CoCo — August 10, 2011 @ 7:59 am

  17. Non-surgical hair replacement popularly uses a system which are usually called hairpieces, wigs, toupees and hair extensions. When you choose this method to solve balding head, you are faced with many options. What type of system should you wear? What materials should you choose? What base is right for you? In reality however, you only need to see two things when choosing hair replacement system. These two criteria are: natural looking and less maintenance.

    Comment by wigs — August 23, 2011 @ 8:22 am

  18. Wonderful!!! Very worth to read. I like this post.

    Comment by Burberry Sale — August 31, 2011 @ 7:36 am

  19. n-surgical hair replacement popularly uses a system which are usually called hairpieces, wigs, toupees and hair extensions. When you choose this method to solve balding head, you are faced with many options. What type of system should you wear? What materials should you choose? What base is right for you? In reality however, you only n

    Comment by Supra Footwear — October 22, 2011 @ 11:41 am

  20. ms up my feelings as well: I don’t want anyone to feel left out, because I hate to seem like I’m playing fav

    Comment by oakley sunglasses men — November 4, 2011 @ 9:08 am

  21. This layout is so stellar. How did you manage to make a blog thats as smart as it is sleek? I mean, its like an Aston Martin –smart and sexy at the same time. Ive got to say, the layout alone made me come back to this blog again. But now that Ive read what youve got to say, Ive got to share it with the world!

    Comment by UGGs Clearance — November 5, 2011 @ 2:19 am

  22. An individual blog site is extremely eye-catching the fact that communicate the word what out my personal four week period. . My spouse and I bookmarkt you actually to make certain that you can easliy speak about the application throughout information, I actually simply can’t assistance myself personally nonetheless must get away from a good provide feedback,that you’re so competent.

    Comment by christian louboutin sale — November 7, 2011 @ 1:21 am

  23. Access to new information technologies, and it’s important not superficial - it’s a life preserver in a sea of ​​useless information!

    Comment by writers company — November 10, 2011 @ 12:07 pm

  24. When we were searching for Christmas Gifts for our friend, we remembered that he liked True Religion Jeans.

    Comment by True religion jeans outlet — November 15, 2011 @ 8:42 am

  25. Nice to such useful and informative article.thank you!

    Comment by moncler outlet — November 18, 2011 @ 6:11 am

  26. Nice to such useful and informative article.thank you!

    Comment by moncler outlet — November 18, 2011 @ 6:15 am

  27. thanks for your article,its great!

    Comment by burberry trench coats — November 18, 2011 @ 6:25 am

  28. You blog is so lovely that speak the words right out my month. I bookmark you so that we can talk about it in details, I really can’t help myself but have to leave a comment, you are so good

    Comment by the north face outlet — November 24, 2011 @ 7:49 pm

  29. Aw, it was a top quality content. Actually I would like to write like this as well - taking time and real energy to bring about an excellent

    post… however what can I say… I procrastinate an awful lot and by no means appear to get things completed…

    Comment by north face coats — November 28, 2011 @ 10:40 am

  30. The cheap oakley sunglasses are no exception to the highest of quality that Oakley produces.

    Comment by cheap oakley sunglasses — December 14, 2011 @ 3:32 am

  31. Bloggers interesante articulo, y el análisis de muy buena, muy agradable lectura.

    Comment by justting — January 4, 2012 @ 9:12 am

  32. They make you look like celebrity, disguise your last-night-late-party-eye bags and give you the aura of an outspoken attitude with their stunning and beautifully crafted shades.

    Comment by Oakley Sunglasses Outlet — January 16, 2012 @ 8:41 am

  33. Valuable information ..I am delighted to read this article..thank you for giving us this useful information. Great walk-through. I value this post.

    Comment by Microsoft Office — January 30, 2012 @ 12:53 am

  34. The Convert to Shapes feature turns your Smart Art diagram

    Comment by Office 2010 — February 16, 2012 @ 2:45 am

  35. Supra Bandit Mid With versatile boot-inspired conceive, the newest Supra Bandit Mid displays actually a exclusive outstanding mild silhouette.Without a question

    Comment by Cheap Supra Shoes — February 28, 2012 @ 1:06 am

  36. when skiing generated a vaster following, this made the conception of Supra Skytop to be various from the universal prototype. What practiced to be fashioned of leather

    Comment by christian louboutin discount — February 28, 2012 @ 1:13 am

  37. Jordan 11 cool grey hot sale online, All air jordan 11 shoes include jordan retro 11 ,jordan cool grey 11 are 40% - 60% price off discount!

    Comment by jordan 11 — February 29, 2012 @ 8:49 am

  38. True Religion jeans are available in different colors and it helps you, in selecting the one of your own choice. If you are also one of the fans of True Religion jeans, then you can easily purchase one for yourself, from true religion jeans outlet or you can also buy them over Internet.

    Comment by true religion outlet — February 29, 2012 @ 8:50 am

  39. Coming with the lovely floral print, this silk is characterized by a silk button front

    Comment by The North Face — March 9, 2012 @ 8:18 am

  40. Enjoy most of your articles, Thanks.

    Comment by Coach Outlet — March 13, 2012 @ 2:53 am

  41. I like the information you provide.

    Comment by cheap beats by dre — March 13, 2012 @ 4:00 am

  42. Thank You very much for this post. I have learned a great deal from it. Keep up the good work and all the best.

    Comment by beats by dre headphones — March 13, 2012 @ 4:04 am

  43. dark marks on your credit history, no forgetting to pay your bills

    Comment by Tory Burch Outlet — March 21, 2012 @ 7:24 am

  44. 1point, because now, copy is color with the flowers are very close.

    Comment by Christian Louboutin Outlet — April 5, 2012 @ 3:53 am

  45. http://www.louboutinzapatos.net

    Comment by Barato Louboutin Zapatos — April 5, 2012 @ 7:31 am

  46. http://www.pumachaussurestore.com

    Comment by Puma Chaussure — April 5, 2012 @ 7:32 am

  47. Hxing4 With a great choice of handbags from Michael Kors, there’s no reason to buy a fake handbag.

    Counterfeit handbags support terrorism, child abuse, drug abuse and so many more horrific crimes. Help

    combat the counterfeit industry and buy authentic designer handbags only.

    Comment by Cheap Supra Shoes — April 12, 2012 @ 6:55 am

  48. Scarpe Timberland ancora una nuova ondata su questo pianeta, con così tanti scarponi

    Comment by timberland scarpe — April 25, 2012 @ 6:34 am

  49. Scarpe Timberland ancora una nuova ondata su questo pianeta, con così tanti scarponi

    Comment by scarpe nike — April 25, 2012 @ 6:35 am

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.

Get free blog up and running in minutes with Blogsome
Theme designed by Gary Rogers