5 extern unsigned char *asmb(unsigned char *a);
7 unsigned char *asmb_ref(unsigned char *s)
10 for (i=0; s[i]; i++) {
12 c += (c>='A' && c<='Z') ? 'a'-'A' : 0;
18 static char ascii(char s) {
19 if(s < 0x20) return '.';
20 if(s > 0x7E) return '.';
24 static void hexdump(void *d, int len) {
27 data = (unsigned char*)d;
28 for (off=0; off<len; off += 16) {
29 printf("\t%08x ",off);
31 if((i+off)>=len) printf(" ");
32 else printf("%02x ",data[off+i]);
36 if((i+off)>=len) printf(" ");
37 else printf("%c",ascii(data[off+i]));
42 static void fillregisters(void)
44 __asm__("push %rdx\n\t");
45 __asm__("mov $12345678, %rdx\n\t");
47 __asm__("movq %rdx, %xmm0\n\t");
48 __asm__("movq %rdx, %xmm1\n\t");
49 __asm__("movq %rdx, %xmm2\n\t");
50 __asm__("movq %rdx, %xmm3\n\t");
51 __asm__("movq %rdx, %xmm4\n\t");
52 __asm__("movq %rdx, %xmm5\n\t");
53 __asm__("movq %rdx, %xmm6\n\t");
54 __asm__("movq %rdx, %xmm7\n\t");
55 __asm__("movq %rdx, %xmm8\n\t");
56 __asm__("movq %rdx, %xmm9\n\t");
57 __asm__("movq %rdx, %xmm10\n\t");
58 __asm__("movq %rdx, %xmm11\n\t");
59 __asm__("movq %rdx, %xmm12\n\t");
60 __asm__("movq %rdx, %xmm13\n\t");
61 __asm__("movq %rdx, %xmm14\n\t");
62 __asm__("movq %rdx, %xmm15\n\t");
63 __asm__("pop %rdx\n\t");
67 #define NUM_TESTCASES 19
70 char *input[NUM_TESTCASES]={
78 "ASDFNERABHDFKHDFKLGJAHGLKAHGLKASHGEARNAKLVNLVAANLSADJVHASDLGH",
84 "ASDFASDFasdfasdfaBC\0AAAABBBBCCCC",
85 "ASDFASDFasdfasdfaBC0AAAABBBBCCCCmuhKA\0asASDFasdf",
89 "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ1234567890allyourbasearebelongtousALLYOURBASEAREBELONGTOUS1337423133711111!!!!elfeinscos(0)sin(M_PI/2)MASTEROFDESTRUCTIONlordoftheuniverseFA!LblogICANhascheezburgericanHASCHEEZBURGERRickROLLrollRICK O RLY? you got 288 IMiss Teen South Carolina"
91 int len[NUM_TESTCASES+1] = {
113 int off[NUM_TESTCASES+1] = {
135 char *output_our, *output_ref;
136 char *input_our, *input_ref;
137 int right=0, wrong=0, neither=0, i;
139 for(i = 0; i < NUM_TESTCASES+1; i++) {
140 input_our = (char *) calloc (len[i], 16);
141 input_ref = (char *) calloc (len[i], 16);
143 if(i == NUM_TESTCASES) {
145 for(u=0; u < len[i]; u++) {
146 input_our[u] = input_ref[u] = 'S';
148 input_our[len[i]] = input_ref[len[i]] = '\0';
150 (void) memcpy(input_our, input[i], len[i]+1);
151 (void) memcpy(input_ref, input[i], len[i]+1);
155 output_our = (char *) asmb((unsigned char *) input_our+off[i]);
156 output_ref = (char *) asmb_ref((unsigned char *) input_ref+off[i]);
158 if(memcmp(output_our,output_ref, len[i]) != 0) {
159 if(strncmp(output_our, output_ref, len[i]) == 0) {
161 printf("Testfall%02i nach Nullbyte ungleich\n", i);
165 printf("Testfall%02i falsch!\n", i);
168 if (i < NUM_TESTCASES) {
169 /* beim "spezialfall" wuerde das boese enden */
170 printf("Input(\"%s\"):\n", input[i]);
171 hexdump(input[i], len[i]);
174 printf("\nerwartet:\n");
175 hexdump(output_ref, len[i]);
177 printf("\ntatsaechliches Ergebnis:\n");
178 hexdump(output_our, len[i]);
183 printf("Testfall%02i korrekt\n", i);
188 printf("========\n%2i Testfaelle sind korrekt\n%2i Testfaelle sind nach dem Nullbyte ungleich\n"
189 "%2i Testfaelle sind falsch\n", right, neither, wrong);