fork download
  1. #include <windows.h>
  2. #include <stdio.h>
  3.  
  4. int main(int argc, char *argv[]){
  5. if(argc < 2){
  6. printf("Usage: <Win32UnpackableUPX.exe> <file>\n");
  7. }else{
  8. FILE *fFile = fopen(argv[1], "rb");
  9. if(fFile != NULL){
  10. printf("File (modified): %s\n", argv[1]);
  11.  
  12. fseek(fFile, 0, SEEK_END);
  13. long lSize = ftell(fFile);
  14. rewind(fFile);
  15.  
  16. char *cBuffer = (char *)malloc(lSize*sizeof(char *));
  17. if(cBuffer != NULL){
  18. fread(cBuffer, 1, lSize, fFile);
  19. fclose(fFile);
  20.  
  21. BOOL bUPX = FALSE;
  22.  
  23. for(int i=0; i < lSize; i++){
  24. if((cBuffer[i] == 0x55) && (cBuffer[i + 1] == 0x50) && (cBuffer[i + 2] == 0x58) && cBuffer[i + 3] == 0x30){
  25. printf("Found byte pattern at offset: %i\n", i);
  26. // This is the only value we need to change (UPX0), not (UPX1) or (UPX!)
  27. cBuffer[i] = 0x41; // Change U (0x55) to A (0x41).
  28.  
  29. bUPX = TRUE;
  30. }
  31. }
  32.  
  33. if(bUPX == TRUE){
  34. fFile = fopen(argv[1], "wb");
  35. if(fFile != NULL){
  36. fwrite(cBuffer, 1, lSize, fFile);
  37. free(cBuffer);
  38. fclose(fFile);
  39.  
  40. printf("File %s should be successfully patched!", argv[1]);
  41. }else{
  42. printf("Unable to open file (write binary).\n");
  43. return 0;
  44. }
  45. }else{
  46. printf("File is not packed by UPX.\n");
  47. free(cBuffer);
  48.  
  49. return 0;
  50. }
  51. }else{
  52. printf("Error at: malloc()\n");
  53. return 0;
  54. }
  55. }else{
  56. printf("Unable to open file (read binary).\n");
  57. return 0;
  58. }
  59. }
  60.  
  61. }
  62.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:1:21: error: windows.h: No such file or directory
prog.c: In function ‘main’:
prog.c:16: warning: implicit declaration of function ‘malloc’
prog.c:16: warning: incompatible implicit declaration of built-in function ‘malloc’
prog.c:21: error: ‘BOOL’ undeclared (first use in this function)
prog.c:21: error: (Each undeclared identifier is reported only once
prog.c:21: error: for each function it appears in.)
prog.c:21: error: expected ‘;’ before ‘bUPX’
prog.c:23: error: ‘for’ loop initial declaration used outside C99 mode
prog.c:29: error: ‘bUPX’ undeclared (first use in this function)
prog.c:29: error: ‘TRUE’ undeclared (first use in this function)
prog.c:37: warning: implicit declaration of function ‘free’
prog.c:37: warning: incompatible implicit declaration of built-in function ‘free’
prog.c:47: warning: incompatible implicit declaration of built-in function ‘free’
prog.c:18: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result
stdout
Standard output is empty