/*---------------------------------------------------------------------------- Radical Dreamers(R) script decompression written by Maximilian Rehkopf following given specs by Steve Demeter , which have been partially corrected. status: working flawlessly according to given specs. input : raw dump of RD text segment as file "text", beginning w/ a stub output: decompressed dump of input file as file "text.dec" target: DOS real / protected 32-bit protected mode compiling recommended ANSI-C compatible code ----------------------------------------------------------------------------*/ #include #include char *dcpb; FILE *in,*out; long flen,foff; long decsize=0; long decptr=0; unsigned char c1; // stub (a), (b) unsigned char c2,c3; // stub (c), (d) unsigned char sl,ssl; // stringlength, substringlength unsigned short jmp; // jump value unsigned char cs[31],css[11]; // string, substring void main() { in=fopen("text","rb"); out=fopen("text.dec","wb"); foff=0; fseek(in,0,SEEK_END); flen=ftell(in); fseek(in,0,SEEK_SET); while(foff>3; ssl=4+(c1&7); // This is the line I got wrong previously! jmp=c2+(c3<<8); decsize+=(sl+(jmp?ssl:0)); printf("[%05X] stub 0x%02X%02X%02X : SL: %02X SSL: %02X JMP: %04X dec: %04lX\n",ftell(in)-3,c1, c2,c3,sl,ssl,jmp,decsize); // getch(); if(sl)fseek(in,sl,SEEK_CUR); foff+=sl; } printf("decompressed size: %lu\n",decsize); foff=0; dcpb=malloc(decsize+4096); fseek(in,0,SEEK_SET); while(foff>3; ssl=4+(c1&7); // And here, once again! jmp=c2+(c3<<8); // printf("Stub info: SL: %02X SSL: %02X JMP: %04X. committing process...\n",sl,ssl,jmp); // getch(); if(jmp && (jmp<=(decptr))) //just to prevent exceptions //(negative memory offsets are no good ^^) { memcpy(css,dcpb+(decptr-jmp),ssl); memcpy(dcpb+decptr,css,ssl); decptr+=ssl; } if(sl) { fread(cs,sl,1,in); memcpy(dcpb+decptr,cs,sl); foff+=sl; decptr+=sl; } } fwrite(dcpb,decsize,1,out); fclose(out); fclose(in); free(dcpb); }