return s;
}
-#define NUM_TESTCASES 13
-int main() {
- char *input[NUM_TESTCASES]={"asdfABCDEFGHKL54",
+static char ascii(char s) {
+ if(s < 0x20) return '.';
+ if(s > 0x7E) return '.';
+ return s;
+}
+
+static void hexdump(void *d, int len) {
+ unsigned char *data;
+ int i, off;
+ data = (unsigned char*)d;
+ for (off=0; off<len; off += 16) {
+ printf("\t%08x ",off);
+ for(i=0; i<16; i++)
+ if((i+off)>=len) printf(" ");
+ else printf("%02x ",data[off+i]);
+
+ printf(" ");
+ for(i=0; i<16; i++)
+ if((i+off)>=len) printf(" ");
+ else printf("%c",ascii(data[off+i]));
+ printf("\n");
+ }
+}
+
+static void fillregisters(void)
+{
+ __asm__("push %rdx\n\t");
+ __asm__("mov $12345678, %rdx\n\t");
+
+ __asm__("movq %rdx, %xmm0\n\t");
+ __asm__("movq %rdx, %xmm1\n\t");
+ __asm__("movq %rdx, %xmm2\n\t");
+ __asm__("movq %rdx, %xmm3\n\t");
+ __asm__("movq %rdx, %xmm4\n\t");
+ __asm__("movq %rdx, %xmm5\n\t");
+ __asm__("movq %rdx, %xmm6\n\t");
+ __asm__("movq %rdx, %xmm7\n\t");
+ __asm__("movq %rdx, %xmm8\n\t");
+ __asm__("movq %rdx, %xmm9\n\t");
+ __asm__("movq %rdx, %xmm10\n\t");
+ __asm__("movq %rdx, %xmm11\n\t");
+ __asm__("movq %rdx, %xmm12\n\t");
+ __asm__("movq %rdx, %xmm13\n\t");
+ __asm__("movq %rdx, %xmm14\n\t");
+ __asm__("movq %rdx, %xmm15\n\t");
+ __asm__("pop %rdx\n\t");
+}
+
+
+#define NUM_TESTCASES 19
+int main()
+{
+ char *input[NUM_TESTCASES]={
+ "AAaaB\0BBUUUUZZZZ",
+ "AAaaBBB\0",
+ "AaA\0ABBB",
+ "A\0ABCDEF",
"foofuuMUHkk",
"AbC",
"BLA|MUHMKUH|KA",
"AbC\0AAAAAAAAAAAA",
"BLA|MUHMKUH|KAA\0",
"ASDFASDFasdfasdfaBC\0AAAABBBBCCCC",
- "ASDFASDFasdfasdfaBC0AAAABBBBCCCCmuhKA\0asASDFasdf" ,
- "ASas\0ASas"
+ "ASDFASDFasdfasdfaBC0AAAABBBBCCCCmuhKA\0asASDFasdf",
+ "ASas\0ASas",
+ "asdfABCDEFGHKL54",
+ "asdffvdfgerrggre\0",
+ "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ1234567890allyourbasearebelongtousALLYOURBASEAREBELONGTOUS1337423133711111!!!!elfeinscos(0)sin(M_PI/2)MASTEROFDESTRUCTIONlordoftheuniverseFA!LblogICANhascheezburgericanHASCHEEZBURGERRickROLLrollRICK O RLY? you got 288 IMiss Teen South Carolina"
};
- int len[NUM_TESTCASES] = {16,
+ int len[NUM_TESTCASES+1] = {
+ 16,
+ 8,
+ 8,
+ 8,
11,
3,
14,
16,
32,
48,
- 9
+ 9,
+ 16,
+ 17,
+ 296,
+ 31337
+ };
+ int off[NUM_TESTCASES+1] = {
+ 0,
+ 0,
+ 0,
+ 0,
+ 1,
+ 2,
+ 2,
+ 1,
+ 3,
+ 6,
+ 5,
+ 6,
+ 6,
+ 2,
+ 0,
+ 0,
+ 0,
+ 0,
+ 5,
+ 10,
};
char *output_our, *output_ref;
char *input_our, *input_ref;
+ int right=0, wrong=0, neither=0, i;
+
+ for(i = 0; i < NUM_TESTCASES+1; i++) {
+ input_our = (char *) calloc (len[i], 16);
+ input_ref = (char *) calloc (len[i], 16);
- int i,j;
- for(i = 0; i < NUM_TESTCASES; i++) {
- input_our = strndup(input[i], len[i]);
- input_ref = strndup(input[i], len[i]);
+ if(i == NUM_TESTCASES) {
+ long u;
+ for(u=0; u < len[i]; u++) {
+ input_our[u] = input_ref[u] = 'S';
+ }
+ input_our[len[i]] = input_ref[len[i]] = '\0';
+ } else {
+ (void) memcpy(input_our, input[i], len[i]+1);
+ (void) memcpy(input_ref, input[i], len[i]+1);
+ }
+
+ fillregisters();
+ output_our = (char *) asmb((unsigned char *) input_our+off[i]);
+ output_ref = (char *) asmb_ref((unsigned char *) input_ref+off[i]);
- output_our = (char *) asmb((unsigned char *) input_our);
- output_ref = (char *) asmb_ref((unsigned char *) input_ref);
if(memcmp(output_our,output_ref, len[i]) != 0) {
- printf("Testfall%02i falsch!\n Input(\"%s\"):\n\t", i, input[i]);
- for(j = 0; j <= len[i]; j++) {
- printf("%02X ", input[i][j]);
+ if(strncmp(output_our, output_ref, len[i]) == 0) {
+ neither++;
+ printf("Testfall%02i nach Nullbyte ungleich\n", i);
}
- printf("\nerwartet:\n\t");
- for(j = 0; j <= len[i]; j++) {
- printf("%02X ", output_ref[j]);
+ else {
+ wrong++;
+ printf("Testfall%02i falsch!\n", i);
}
- printf("\ntatsaechliches Ergebnis:\n\t");
- for(j = 0; j <= len[i]; j++) {
- printf("%02X ", output_our[j]);
+
+ if (i < NUM_TESTCASES) {
+ /* beim "spezialfall" wuerde das boese enden */
+ printf("Input(\"%s\"):\n", input[i]);
+ hexdump(input[i], len[i]);
}
+
+ printf("\nerwartet:\n");
+ hexdump(output_ref, len[i]);
+
+ printf("\ntatsaechliches Ergebnis:\n");
+ hexdump(output_our, len[i]);
printf("\n");
}
else {
+ right++;
printf("Testfall%02i korrekt\n", i);
}
free(input_our);
free(input_ref);
}
+ printf("========\n%2i Testfaelle sind korrekt\n%2i Testfaelle sind nach dem Nullbyte ungleich\n"
+ "%2i Testfaelle sind falsch\n", right, neither, wrong);
return 0;
}