Created
March 3, 2010 20:00
-
-
Save skinner33/320941 to your computer and use it in GitHub Desktop.
asmbtest.c
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"); | |
} | |
} | |
#define NUM_TESTCASES 18 | |
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", | |
}; | |
int len[NUM_TESTCASES] = { | |
16, | |
8, | |
8, | |
8, | |
11, | |
3, | |
14, | |
61, | |
17, | |
16, | |
16, | |
16, | |
16, | |
32, | |
48, | |
9, | |
16, | |
17, | |
}; | |
char *output_our, *output_ref; | |
char *input_our, *input_ref; | |
int right=0, wrong=0, neither=0, i; | |
for(i = 0; i < NUM_TESTCASES; i++) { | |
input_our = (char *) malloc (len[i]); | |
input_ref = (char *) malloc (len[i]); | |
(void) memcpy(input_our, input[i], len[i]+1); | |
(void) memcpy(input_ref, input[i], len[i]+1); | |
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) { | |
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); | |
} | |
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