cielavenir

getjavacert

Dec 30th, 2011
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define BUFLEN (1<<16)
  4. unsigned char buf[BUFLEN];
  5. #define cbuf ((char*)buf)
  6.  
  7. int main(const int argc, const char **argv){
  8.     if(isatty(fileno(stdin))){fprintf(stderr,"unzip -p FILE.apk|jar \"META-INF/*.RSA\" | getjavacert\n");return -1;}
  9.     fread(buf,1,0x38,stdin);//fseek(stdin,0x38,SEEK_SET);
  10.     fread(buf+(BUFLEN/2),1,2,stdin);
  11.     if(buf[(BUFLEN/2)]!=0x30||buf[(BUFLEN/2)+1]>0x84){fprintf(stderr,"cannot parse header\n");return 1;}
  12.     u32 len=0;
  13.     if(buf[(BUFLEN/2)+1]<0x80)len=buf[(BUFLEN/2)+1];
  14.     u32 i=0,j=0;
  15.     for(;i<buf[(BUFLEN/2)+1]-0x80;i++){
  16.         buf[(BUFLEN/2)+2+i]=fgetc(stdin);len=(len<<8)+buf[(BUFLEN/2)+2+i];
  17.     }
  18.     if(len>BUFLEN/4){fprintf(stderr,"length too large (%d)\n",len);return 1;}
  19.     fread(buf+(BUFLEN/2)+2+i,1,len,stdin); //total=2+i+len
  20.     for(;j<2+i+len;j++){
  21.         int x=buf[(BUFLEN/2)+j]>>4,y=buf[(BUFLEN/2)+j]&0xf;
  22.         buf[2*j+0]=x>9?(x-10+'a'):(x+'0');
  23.         buf[2*j+1]=y>9?(y-10+'a'):(y+'0');
  24.     }
  25.     buf[2*j+0]=0;
  26.     puts(cbuf);
  27.    
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment