-
-
Save lewurm/321931 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
extern unsigned char *asmb(unsigned char *a); | |
unsigned char *asmb_ref(unsigned char *s) | |
{ | |
unsigned long i; | |
for (i=0; s[i]; i++) { | |
unsigned char c=s[i]; | |
c += (c>='A' && c<='Z') ? 'a'-'A' : 0; | |
s[i] = c; | |
} | |
return s; | |
} | |
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", | |
"ASDFNERABHDFKHDFKLGJAHGLKAHGLKASHGEARNAKLVNLVAANLSADJVHASDLGH", | |
"asdfABCDEFGHKL544", | |
"asdfA\0BCDEFGHKL5", | |
"foofuuMUHkk\0AAAA", | |
"AbC\0AAAAAAAAAAAA", | |
"BLA|MUHMKUH|KAA\0", | |
"ASDFASDFasdfasdfaBC\0AAAABBBBCCCC", | |
"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+1] = { | |
16, | |
8, | |
8, | |
8, | |
11, | |
3, | |
14, | |
61, | |
17, | |
16, | |
16, | |
16, | |
16, | |
32, | |
48, | |
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); | |
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]); | |
if(memcmp(output_our,output_ref, len[i]) != 0) { | |
if(strncmp(output_our, output_ref, len[i]) == 0) { | |
neither++; | |
printf("Testfall%02i nach Nullbyte ungleich\n", i); | |
} | |
else { | |
wrong++; | |
printf("Testfall%02i falsch!\n", i); | |
} | |
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; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment