/* patch your proxy with this and it might work with ruff rose again */

#include <stdio.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char *argv[]){
  if (argc < 2){
    printf("usage: proxypatch <exe>n");
    return 0;
  }
  
  FILE *i=fopen(argv[1], "rb");
  if (!i){
    printf("could not open input file!n");
    return 0;
  }
  
  char fn[512];
  snprintf(fn, 512, "%s-patched.exe", argv[1]);
  FILE *o=fopen(fn, "wb");
  if (!o){
    fclose(i);
    printf("could not open output file!n");
    return 0;
  }
  
  unsigned char c[32] = {0x00,0x5e,0xbc,0xe2,0x61,0x3f,0xdd,0x83,0xc2,0x9c,0x7e,0x20,0xa3,0xfd,0x1f,0x41,
                         0x9d,0xc3,0x21,0x7f,0xfc,0xa2,0x40,0x1e,0x5f,0x01,0xe3,0xbd,0x3e,0x60,0x82,0xdc};
  unsigned char b[32];
  bool f=false;
  int n;
  while (!feof(i)){
    n=fread(b,1,32,i);
      
    if (memcmp(b,c,32) == 0 && n == 32){
      f=true;
      for(int k=0;k<32;k++)
        b[k]=k;
        
      fwrite(b,1,32,o);
    } else {
      fwrite(b,1,n,o);
    }
  }
  
  fclose(o);
  fclose(i);
  
  if (!f){
    printf( "signature not found, can't be patched!n" );
    unlink( fn );
  } else {
    printf( "file patched, written to: %sn", fn );
  }
  
  return 0;
}