Scorpunduk

FIND_ZIP

Feb 22nd, 2023 (edited)
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.42 KB | Fixit | 0 0
  1. /*
  2.     программа выполняет поиск скрытых внутри jpg архивов
  3.     windows cmd -> folder -> program.exe *.jpg
  4.     ubuntu ctrl+alt+t -> folder -> ./program *.jpg
  5.     https://g-soft.info/articles/4887/kak-napisat-i-zapustit-programmu-na-yazyke-c-v-linux
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include "filedivingtools.h"
  11.  
  12. int main(int argc, char * argv[])
  13. {
  14.     FILE * target;
  15.     int execute_further = 0;
  16.     int file_has_hidden_zip = 0;
  17.     long long unsigned position = 0;
  18.     char choice = 0;
  19.  
  20.     // если в командной строке неверно заданы аргументы
  21.     if(argc != 2)
  22.     {
  23.         printf("Using program: %s\n", argv[0]);
  24.         printf("Please, launch program with file parameter\n");
  25.         printf("Template for launch:\n");
  26.         printf("on win: <program folder path> <program name> <space> <file for check>\n");
  27.         printf("on linux: <program folder path> ./ <program name> <space> <file for check>\n");
  28.         printf("or just drage and drop jpg on program\n");
  29.         exit(EXIT_FAILURE);
  30.     }
  31.  
  32.     // если невозможно открыть файл
  33.     if((target = fopen(argv[1], "rb")) == NULL)
  34.     {
  35.         printf("Can't open file %s\n", argv[1]);
  36.         exit(EXIT_FAILURE);
  37.     }
  38.  
  39.     // если файл не является jpg
  40.     if(!isJPG(target, 1))
  41.     {
  42.         exit(EXIT_FAILURE);
  43.     }
  44.  
  45.     printf("File volume: %llu bytes\n", get_file_bytes_value(target,0));
  46.  
  47.     file_has_hidden_zip = hasZIPinside(target, 1);
  48.  
  49.     // если найден скрытый zip-архив его можно вывести в папку с программой
  50.     if(file_has_hidden_zip)
  51.     {
  52.         printf("**************************************************\n");
  53.         printf("Do you want to pull out hidden zip-archive? (y/n)");
  54.         while((choice = getchar()) != EOF)
  55.         {
  56.             fflush(stdin);
  57.             if(choice != 'y' && choice != 'n')
  58.                 printf("...please, input only \"y\" or \"n\"\n");
  59.             else break;
  60.         }
  61.         if(choice == 'y')
  62.         {
  63.             position = jpgEndPosition(target);
  64.             pullOutHiddenZip(target, (long unsigned)position);
  65.             printf("ZIP-archive was pulled out. Check program folder.\n");
  66.         }
  67.     }
  68.  
  69.     fclose(target);
  70.     printf("Press any key to quite.\n");
  71.     getchar();
  72.     return 0;
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment