Il s'agit d'une version asm du crc32 présenté dans la rfc gzip (1952).

Code :Sélectionner tout -Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
 
format ELF64 executable 3
entry start
 
include 'include/linux/lin64a.inc'
interpreter '/lib64/ld-linux-x86-64.so.2'
needed 'libc.so.6'
import	printf
 
;-------------------------------------------------------------------------
segment readable executable
;-------------------------------------------------------------------------
 
start:
 
	mov	esi,buffer_len
	mov	edi,buffer
	call	update_crc
 
	mov	esi,eax
	mov	edi,formh
	xor	eax,eax
	call	[printf]
 
   exit:
	xor	edi,edi
	mov	eax,_exit
	syscall
 
 
 
update_crc:
	cmp	dword [crc_table_computed],0
	jnz	@f
	mov	ebp,esi
	call	make_crc_table
	mov	ecx,ebp
     @@:
	xor	eax,eax
	not	eax
	xor	edx,edx
     @@:
	mov	dl,al
	mov	bl,byte [edi]
	xor	dl,bl
	inc	edi
	mov	ebx,dword [esi+edx*4]
	shr	eax,8
	xor	eax,ebx
	dec	ecx
	jnz	@b
	xor	eax,0xffffffff
	ret
 
 
 
make_crc_table:
	mov	esi,crc_table
	xor	ecx,ecx
     A1:
	mov	eax,ecx
	mov	bl,8
     A2:
	mov	dl,al
	and	dl,1
	cmp	dl,1
	jnz	@f
	mov	edx,eax
	shr	edx,1
	mov	eax,0xedb88320
	xor	eax,edx
	jmp	A3
     @@:
	shr	eax,1
     A3:
	dec	bl
	jnz	A2
	mov	dword [esi+ecx*4],eax
	inc	cl
	jnz	A1
	mov	dword [crc_table_computed],1
	ret
 
;-------------------------------------------------------------------------
segment readable writeable
;-------------------------------------------------------------------------
 
crc_table rd 256
crc_table_computed dd 0
 
buffer db 'Life, the Universe and everything'
buffer_len = $-buffer
 
formh db '%08x',10,0


Le même crc32 mais en version x32 stack, sans buffer.
Code :Sélectionner tout -Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
 
format ELF executable 3
entry start
 
include 'include/linux/lin32a.inc'
interpreter '/lib/ld-linux.so.2'
needed 'libc.so.6'
 
import	printf
 
;-------------------------------------------------------------------------
segment readable executable
;-------------------------------------------------------------------------
 
start:
 
	mov	esi,buffer_len
	mov	edi,buffer
	call	update_crc
 
	invoke	printf,formh,eax
 
	xor	ebx,ebx
	mov	eax,_exit
	int	0x80
 
 
 
update_crc:
	cmp	dword [crc_table_computed],0
	jnz	@f
	mov	ebp,esi
	call	make_crc_table
	mov	ecx,ebp
     @@:
	sub	esp,8
	xor	eax,eax
	not	eax
	xor	edx,edx
     @@:
	mov	dl,al
	mov	bl,byte [edi]
	xor	dl,bl
	inc	edi
 
	neg	edx
	mov	ebx,dword [esp+edx*4]
	neg	edx
 
	shr	eax,8
	xor	eax,ebx
 
	dec	ecx
	jnz	@b
 
	xor	eax,0xffffffff
	add	esp,8
	ret
 
 
make_crc_table:
	xor	ecx,ecx
	sub	esp,4
     A1:
	mov	eax,ecx
	mov	bl,8
     A2:
	mov	dl,al
	and	dl,1
	cmp	dl,1
	jnz	@f
 
	mov	edx,eax
	shr	edx,1
	mov	eax,0xedb88320
	xor	eax,edx
	jmp	A3
     @@:
	shr	eax,1
     A3:
	dec	bl
	jnz	A2
 
	neg	ecx
	mov	dword [esp+ecx*4],eax
	neg	ecx
 
	inc	cl
	jnz	A1
 
	mov	dword [crc_table_computed],1
	add	esp,4
	ret
 
;-------------------------------------------------------------------------
segment readable writeable
;-------------------------------------------------------------------------
 
crc_table_computed dd 0
 
buffer db 'Life, the Universe and everything'
buffer_len = $-buffer
 
formh db '%08x',10,0