git-svn: trunk@4015
aCaB authored on 2008/07/29 11:11:17... | ... |
@@ -1,3 +1,8 @@ |
1 |
+Tue Jul 29 03:53:31 CEST 2008 (acab) |
|
2 |
+------------------------------------ |
|
3 |
+ * libclamav/disasm.c: change output struct |
|
4 |
+ * unit_tests/check_disasm.c: actually check something (more to come) |
|
5 |
+ |
|
1 | 6 |
Tue Jul 29 02:44:53 CEST 2008 (acab) |
2 | 7 |
------------------------------------ |
3 | 8 |
* test: add clam.d64.zip |
... | ... |
@@ -1673,9 +1673,9 @@ void disasmbuf(uint8_t *buff, unsigned int len, int fd) { |
1673 | 1673 |
uint8_t adsize; |
1674 | 1674 |
uint8_t segment; |
1675 | 1675 |
|
1676 |
- uint8_t arg[3][11]; |
|
1676 |
+ uint8_t arg[3][10]; |
|
1677 | 1677 |
|
1678 |
- uint8_t extra[26]; |
|
1678 |
+ uint8_t extra[29]; |
|
1679 | 1679 |
} w; |
1680 | 1680 |
|
1681 | 1681 |
memset(&w.extra[0], 0, sizeof(w.extra)); |
... | ... |
@@ -1703,16 +1703,19 @@ void disasmbuf(uint8_t *buff, unsigned int len, int fd) { |
1703 | 1703 |
for (i=0; i<3; i++) { |
1704 | 1704 |
w.arg[i][0] = s.args[i].access; |
1705 | 1705 |
w.arg[i][1] = s.args[i].size; |
1706 |
- w.arg[i][2] = s.args[i].reg; |
|
1707 |
- if(s.args[i].access==ACCESS_MEM) { |
|
1706 |
+ switch(s.args[i].access) { |
|
1707 |
+ case ACCESS_MEM: |
|
1708 |
+ w.arg[i][2]=s.args[i].arg.marg.r1; |
|
1708 | 1709 |
w.arg[i][3]=s.args[i].arg.marg.r1; |
1709 |
- w.arg[i][4]=s.args[i].arg.marg.r1; |
|
1710 |
- w.arg[i][5]=s.args[i].arg.marg.scale; |
|
1710 |
+ w.arg[i][4]=s.args[i].arg.marg.scale; |
|
1711 |
+ w.arg[i][5]=0; |
|
1711 | 1712 |
cli_writeint32(&w.arg[i][6], s.args[i].arg.marg.disp); |
1712 |
- w.arg[i][10]=0; |
|
1713 |
- } else { |
|
1714 |
- cli_writeint32(&w.arg[i][3], s.args[i].arg.d); |
|
1715 |
- cli_writeint32(&w.arg[i][7], s.args[i].arg.q>>32); |
|
1713 |
+ break; |
|
1714 |
+ case ACCESS_REG: |
|
1715 |
+ w.arg[i][1] = s.args[i].reg; |
|
1716 |
+ default: |
|
1717 |
+ cli_writeint32(&w.arg[i][2], s.args[i].arg.d); |
|
1718 |
+ cli_writeint32(&w.arg[i][6], s.args[i].arg.q>>32); |
|
1716 | 1719 |
} |
1717 | 1720 |
} |
1718 | 1721 |
cli_writen(fd, &w, sizeof(w)); |
... | ... |
@@ -30,14 +30,20 @@ |
30 | 30 |
#include <stdlib.h> |
31 | 31 |
#include <sys/types.h> |
32 | 32 |
#include <unistd.h> |
33 |
+#include <string.h> |
|
33 | 34 |
|
34 | 35 |
#include "../libclamav/clamav.h" |
35 | 36 |
#include "../libclamav/others.h" |
36 | 37 |
#include "../libclamav/disasm.h" |
38 |
+#include "checks.h" |
|
37 | 39 |
|
38 | 40 |
START_TEST (test_disasm_basic) { |
39 | 41 |
char file[]="disasmXXXXXX"; |
40 |
- char ref[]="\xc2\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x02\x00\x00"; |
|
42 |
+ char ref[]="\xc2\x00\x00\x00\x00\ |
|
43 |
+\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\ |
|
44 |
+\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\ |
|
45 |
+\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ |
|
46 |
+\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; |
|
41 | 47 |
int fd = mkstemp(file); |
42 | 48 |
uint8_t buf[] = {0x33, 0xc0}; |
43 | 49 |
off_t *d; |
... | ... |
@@ -45,12 +51,13 @@ START_TEST (test_disasm_basic) { |
45 | 45 |
|
46 | 46 |
disasmbuf(buf, 2, fd); |
47 | 47 |
size = lseek(fd, 0, SEEK_CUR); |
48 |
- fail_unless(size==64, "disasm size"); |
|
48 |
+ fail_unless(size==sizeof(ref)-1, "disasm size mismatch(value %u, expected: %u)", size, sizeof(ref)-1); |
|
49 | 49 |
lseek(fd, 0, SEEK_SET); |
50 | 50 |
d=malloc(size); |
51 |
- fail_unless(d, "disasm malloc"); |
|
52 |
- fail_unless(read(fd, d, size)==size, "disasm read"); |
|
51 |
+ fail_unless(d!=NULL, "disasm malloc(%u) failed", size); |
|
52 |
+ fail_unless(read(fd, d, size)==size, "disasm read failed"); |
|
53 | 53 |
close(fd); |
54 |
+ fail_unless(!memcmp(d, ref, size), "disasm read failed"); |
|
54 | 55 |
free(d); |
55 | 56 |
unlink(file); |
56 | 57 |
} |