/* To compile, save this code as wbz2jpg.c */ /* Then run the command: gcc wbz2jpg.c -o wbz2jpg */ /* A program to convert .wbz files from webshots.com */ /* to .jpg files by stripping excess bytes before */ /* Jpeg Header and bytes for thumbnail image. */ /* */ /* The first format has the text Adobe in the file twice. */ /* A thumbnail is in between, which gets stripped. The */ /* The second type has encrypted header and so I decrypt */ /* with one of two keys. the first 100 bytes after WWBB0000 */ /* or WWBB1111 are replaced by the next 100 bytes which */ /* need to be decrypted first */ /* then the original 2nd 100 bytes then the rest of file. */ /* By Gyrf on 22 March 2001 */ #include #define ADOBE "Adobe" #define ALGO1 "WWBB0000" #define ALGO2 "WWBB1111" #define HDR1 0xFF #define HDR2 0xD8 int main (int argc,char *argv[]) { FILE *fp1, *fp2; char *infile, *outfile; char isalgo1[9]; char isadobe[6]; int letter,flag=0,flag1=0,ishdr1=0,ishdr2=0; int verwb=0,cnt=0,cnt1=0,A[100],B[100],counter=0; int magicvalue=0,C[100]; if(argc >= 3) { infile = argv[1]; outfile = argv[2]; } else { printf("Usage: wbz2 inputfile.wbz ouputfile.jpg\n"); exit (1); } if((fp1 =fopen(infile,"r")) == NULL) { printf("Can't open infile %s\n",infile); exit (0); } if((fp2 =fopen(outfile,"w")) == NULL) { printf("Can't open outfile %s\n",outfile); fclose(fp1); exit (0); } while((letter= fgetc(fp1)) != EOF) { if(letter==0xFF) /*first hex digit of jpeg */ { ishdr1= letter; ishdr2= fgetc(fp1); if(HDR1==ishdr1 && HDR2==ishdr2)flag=1; fseek(fp1,-1L,SEEK_CUR); /* back up one */ } if(letter==0x41) /* A in Adobe */ { isadobe[0]=letter; isadobe[1]= fgetc(fp1); isadobe[2]= fgetc(fp1); isadobe[3]= fgetc(fp1); isadobe[4]= fgetc(fp1); isadobe[5]='\0'; fseek(fp1,-4L,SEEK_CUR); /* back up four */ if(strcmp(ADOBE,isadobe)==0)flag1++; } if(flag == 1 && flag1 != 1) { fseek(fp1,-1L,SEEK_CUR); /* Back up and read */ letter=fgetc(fp1); /* byte just analyzed */ fputc(letter,fp2); /* and write it to .jpg */ } } if(flag == 1 && flag1 > 1){ printf("%s written, type 1 Adobe enbedded.\n",outfile); fclose(fp1); fclose(fp2); return 0;} else{ rewind(fp1); rewind(fp2); } while(cnt1<100 && ((letter= fgetc(fp1)) != EOF)) { if(letter==0x57) /* W in WWBBxxxx */ { isalgo1[0]=letter; isalgo1[1]= fgetc(fp1); isalgo1[2]= fgetc(fp1); isalgo1[3]= fgetc(fp1); isalgo1[4]= fgetc(fp1); isalgo1[5]= fgetc(fp1); isalgo1[6]= fgetc(fp1); isalgo1[7]= fgetc(fp1); isalgo1[8]='\0'; if(strcmp(ALGO1,isalgo1)==0) {flag1++;verwb=1;} if(strcmp(ALGO2,isalgo1)==0) {flag1++;verwb=2;} if(!verwb)fseek(fp1,-7L,SEEK_CUR); } /* matrix stuff goes here. write now decrypt next */ if(verwb>1) { if(verwb==1)magicvalue=0xA4; if(verwb==2)magicvalue=0xF2; while(cnt<100 && ((letter= fgetc(fp1)) != EOF)){ A[cnt]=letter;cnt++; } while(cnt1<100 && ((letter= fgetc(fp1)) != EOF)){ C[cnt1]=letter;B[cnt1]=letter;cnt1++; } /* decryption algorythm */ counter=0; while(counter<100){ A[counter] = ~A[counter]; B[counter] = B[counter] ^ A[counter]; B[counter] = B[counter] ^ magicvalue; counter++; } } } counter=0; /* altered 2nd 100 bytes */ while(counter<100) { letter=B[counter]; fputc(letter,fp2); counter++; } counter=0; /* saved 2nd 100 bytes */ while(counter<100) { letter=C[counter]; fputc(letter,fp2); counter++; } while((letter = fgetc(fp1)) != EOF) { fputc(letter,fp2); } printf("%s written, type %s encrypted.\n",outfile,isalgo1); fclose(fp1); fclose(fp2); return 0; }