Explorar el Código

add base64 scanner

master
Felix von Leitner hace 18 años
padre
commit
c51187748f
Se han modificado 4 ficheros con 45 adiciones y 28 borrados
  1. +11
    -23
      t.c
  2. +0
    -4
      textcode/fmt_base64.c
  3. +34
    -0
      textcode/scan_base64.c
  4. +0
    -1
      textcode/scan_uuencoded.c

+ 11
- 23
t.c Ver fichero

@@ -17,30 +17,18 @@
__asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")

int main(int argc,char* argv[]) {
unsigned long size;
char* buf=mmap_read(argv[1],&size);
if (buf) {
const char* c=buf;
const char* max=buf+size;
while (c<max) {
char tmp[100];
unsigned int scanned;
unsigned int x=scan_uuencoded(c,tmp,&scanned);
if (!x) {
if (!strncmp(c,"end\n",4))
return 0;
else {
parseerror:
buffer_putsflush(buffer_2,"parse error!\n");
exit(1);
}
}
write(1,tmp,scanned);
c+=x;
if (*c!='\n') goto parseerror;
++c;
}
char buf[100];
char buf2[100];
unsigned int len,len2;
buf[fmt_base64(buf,"foo:bar",7)]=0;
buffer_puts(buffer_1,buf);
buffer_putsflush(buffer_1,"\n");
if ((buf[len2=scan_base64(buf,buf2,&len)])!=0) {
buffer_putsflush(buffer_2,"parse error!\n");
return 1;
}
buffer_put(buffer_1,buf2,len2);
buffer_putsflush(buffer_1,"\n");
return 0;
#if 0
unsigned long size;


+ 0
- 4
textcode/fmt_base64.c Ver fichero

@@ -2,10 +2,6 @@
#include "textcode.h"
#include "haveinline.h"

static inline unsigned int enc(unsigned char x) {
return ((x-1)&077)+'!';
}

unsigned int fmt_base64(char* dest,const char* src,unsigned int len) {
register const unsigned char* s=(const unsigned char*) src;
unsigned short bits=0,temp=0;


+ 34
- 0
textcode/scan_base64.c Ver fichero

@@ -0,0 +1,34 @@
#include "textcode.h"
#include "haveinline.h"

static inline int dec(unsigned char x) {
if (x>='A' && x<='Z') return x-'A';
if (x>='a' && x<='z') return x-'a'+26;
if (x>='0' && x<='9') return x-'0'+26+26;
switch (x) {
case '+': return 62;
case '/': return 63;
default: return -1;
}
}

unsigned int scan_base64(const char *src,char *dest,unsigned int *destlen) {
unsigned short tmp=0,bits=0;
register const unsigned char* s=(const unsigned char*) src;
const char* orig=dest;
for (;;) {
int a=dec(*s);
if (a<0) {
while (*s=='=') ++s;
break;
}
tmp=(tmp<<6)|a; bits+=6;
++s;
if (bits>=8) {
*dest=(tmp>>(bits-=8));
++dest;
}
}
*destlen=dest-orig;
return (const char*)s-src;
}

+ 0
- 1
textcode/scan_uuencoded.c Ver fichero

@@ -1,5 +1,4 @@
#include "textcode.h"
#include "haveinline.h"

unsigned int scan_uuencoded(const char *src,char *dest,unsigned int *destlen) {
unsigned int len;


Cargando…
Cancelar
Guardar