#include "extern.h" /* 13 functions; only on fridays... *\ \* HAVE FUN WITH MUCH PSEUDO CODE, */ FILE *fy,*fn; Pet *pet; uint pta=0; uint ptb=0; //backup uint max=4096; uchar *dir; uint dlen; ulong fp=0; /* "I hate declarations..." */ ///... /* "And I hate ""rm spin.c"" " */ ulong pu=0; uint *dex; /* logics array for indexing the start of search-sets see patdex(), sdex(x) and rdex(x). */ uint *bex; //to backup dex, because of rdex(x). #ifdef DEBUG /* (TM)-no.1 */ void dbg_dex() { uint p=DEX-1; uint i=0; fprintf(stderr,"[debug] dex\n "); p=0; while (p0) j=j*16; j=j+x; i++; } while (s[i]) { if (s[i]>0x2f && s[i]<0x3a) { ij(s[i]-0x30); continue; } switch(toupper(s[i])) { case 'A': ij(10); continue; case 'B': ij(11); continue; case 'C': ij(12); continue; case 'D': ij(13); continue; case 'E': ij(14); continue; case 'F': ij(15); continue; default: fprintf(stderr,"[error] supplied pattern is wicked.\n",s[i]); exit(1); } } return(j); } void smax(s) uchar *s; { uint i=0; max=0; void imax(uint x) { if (i>0) max=max*10; max=max+x; i++; } while (s[i]) { if (s[i]>0x2f && s[i]<0x3a) { imax(s[i]-0x30); } else { fprintf(stderr,"[error] -l got wicked.\n",s); exit(1); } } } void ipet(r,e) uchar r,e; { if (pta==MAS) { fprintf(stderr,"[error] pet: [%d] overflow.\n", MAS); exit(1); } pet[pta].r=r; pet[pta].e=e; pta++; if (pta==0) { panic("petpointer: buffer overflow.\n"); exit(1); } } void adpet(s) uchar *s; { uchar l[3]; l[2]=0; uchar c=0; uchar e=0; uint i=0; if (s[i]=='.') { panic(".dot at start, will do whatever wants-"); exit(1); } while (s[i]) { l[0]=s[i];i++; switch(l[0]) { case '.': if (s[i]=='.') { panic("met the two-dot.."); exit(1); } else if (s[i]==0) { /* '.' at end. */ ipet(6,e-1); } else { ipet(3,e-1); } e=0; break; default: l[1]=s[i];i++; if (l[1]==0) { fprintf(stderr,"[error] '%c' dangling single-hex.\n",l[0]); exit(1); } c=hex(l); pet[pta].b[e]=c; if (s[i]==0) { ipet(1,e); return; } else if ((e+1)%PAT==0) { if (s[i]=='.') { continue; } else { ipet(2,e); } } e++; } } } void petdex() { uint p=0,g=0,i=1,j=1; uchar t=0; pta=0; if (pet[0].r>0) dex[0]=1; while (p0) || (pet[i+(p*DP)].r==1 && pet[j+(g*DP)].r>0)) { t=1; } if (t==1) { pta++; dex[p]=dex[p]|(1<pta) { panic("internal sdex(x) > pta..."); exit(1); } while (1) { if (dex[p]>0) break; p++; if (p==DEX) { panic("internal sdex(x): no active pets"); exit(1); } } while (p%u,r:%u)\n",i+(p*i),y,pet[y].r); exit(1); } } } else x--; } i++; y++; y=y%MAS; } p++; i=0; } } /* maybe I*like*C++? "because C is dumb little shit, or because I am just too dumb! [...] and I wonder why they think all of this is necessary." */ uint sdex2(x) uint x; { uint p=0; uint i=0; uint y=0; if (x>pta) { panic("internal sdex(x) > pta..."); exit(1); } while (1) { if (dex[p]>0) break; p++; if (p==DEX) { panic("internal sdex(x): no active pets"); exit(1); } } while (p%u,r:%u)\n",i+(p*i),y,pet[y].r); exit(1); } } } else x--; } i++; y++; y=y%MAS; } p++; i=0; } } void xdex(x) uint x; { uint p=0; uint i=x%DP; while (p=MAS) { panic("internal rdex(x) > MAS..."); exit(1); } if (dex[p]&(1<uchar *c."); exit(1); } FILE *f; uint bs; uchar bp=0; uchar b[BUF]; uchar s=0; /* 0 no search (remove file) 1 active search (broken) 2 finished search (found) 3 PT()==6 long for end (found) */ uint sa=0;//sdex(x) x:address uint sb=0; uchar * spath(uchar *c, uchar *a, uchar *b) { #ifdef WIN32 snprintf(c,dlen,"%s\\%s",a,b); #else snprintf(c,dlen,"%s/%s",a,b); #endif return(c); } uchar * ifile(uchar *c, ulong i) { snprintf(c,dlen,"%016lx",i); return(c); } uchar * ipath(uchar *c, uchar *a, ulong i) { #ifdef WIN32 snprintf(c,dlen,"%s\\%016lx",a,i); #else snprintf(c,dlen,"%s/%016lx",a,i); #endif return(c); } void ipu() { pu++; if (pu==0) { fprintf(stderr," [offset overflow] +16EiB"); } return; } void bread() { bs=Fin(b); } void incb() { ipu(); bp++; if (bp%bs==0) { bp=0; if (bs!=0) bread(); } } void fink(uint i) { fclose(f); if(i==0) remove(ipath(c,dir,fp)); fp=fp+i; f=fopen(ipath(c,dir,fp),"wb"); } void done(uint i) { if (i==0) { fprintf(fn,"%s %u,%lx\n",ifile(c,fp),sb,pu); fprintf(stderr,"+%s (broken): %u,%lx\n",ifile(c,fp),sb,pu); fink(1); s=2; } else if (i==1) { fprintf(fy,"%s %u,%lx\n",ifile(c,fp),sb,pu); fprintf(stderr,"+%s (found): %u,%lx\n",ifile(c,fp),sb,pu); fink(1); s=2; } else if (i==2) { bp--; fprintf(fy,"%s %u,%lx\n",ifile(c,fp),sb,pu); fprintf(stderr,"+%s (found): %u,%lx\n",ifile(c,fp),sb,pu); s=2; } } void identify(uint x) { BUG( fprintf(stderr," %c:%u",b[bp],x) ); BUG( fprintf(stderr,"t.%u ",PT(x)) ); BUG( fprintf(stderr,"[%d %d]",PC(x),PE(x)) ); if (PC(x)==PE(x)) { BUG( fprintf(stderr,"u:%u\n",sb) ); if (PT(x)==1) { done(1); } else if (PT(x)==3) { s=1; xi=0; } else if (PT(x)==6) { s=3; xi=0; } petit(sdex(x)); if (s==1) { sb=sb+x; xdex(sdex(x)); } } else { PC(x)++; } } void work() { if (s==1||s==3) { xi++; if (xi==0) { panic("search()->xi overflow?!"); exit(1); } fputc(b[bp],f); if (s==3) { if (xi>max) done(1); return; } if (PB(0)==b[bp]) { identify(0); } else { if (xi>max) done(0); } } else if (PB(sa)==b[bp]) { fputc(b[bp],f); identify(sa); } else if (pta>0) { sb++; rdex(sdex(sa)); } else { fink(0); rvsx(); sb=0; s=0; } } freopen(NULL,"rb",stdin); fy=fopen(spath(c,dir,"found"),"w"); fprintf(fy,"FILE PARAM,FILE-OFFSET\n"); fn=fopen(spath(c,dir,"broken"),"w"); fprintf(fn,"FILE PARAM,FILE-OFFSET\n"); BUG( dbg_pet(1); dbg_pet(2); dbg_pet(0); dbg_dex(); fprintf(stderr,"sdex(0): %d\nsdex(1): %d\n",sdex(0),sdex(1)); rdex(sdex(1)); sdex(1); ) f=fopen(ipath(c,dir,fp),"wb"); bread(); while (bs) { if (s==2) { sb=0; s=0; rvsx(); } BUG( fprintf(stderr,"%u,%u:",(uint)s,pta) ); if (s==1||s==3) { work(); } else { sa=0; while (sa<=pta) { work(); if (s==0) sa++; else break; } } incb(); } if (s==3) { done(2); } fclose(f); if (s==0) remove(ipath(c,dir,fp)); if (s==1) { fprintf(fn,"%s ?\n",ipath(c,dir,fp)); fprintf(stderr,"+%s (broken)\n",ifile(c,fp)); } } int main(argc,argv) /* ^ i know, i know... i did not know of void. */ int argc; uchar **argv; { struct sigaction sig; sig.sa_handler=candleout; struct stat sm; uchar opt=1; uint i=0; uchar t=0; if (pet=malloc(sizeof(Pet)*MAS)) { } else { panic("malloc: pet failed."); return 1; } if (dex=malloc(sizeof(dex)*DEX)) { } else { panic("malloc: dex failed."); return 1; } if (bex=malloc(sizeof(dex)*DEX)) { } else { panic("malloc: bex failed."); return 1; } while (i