Author: colossus
Date: 2008-06-27 12:42:07 +0000 (Fri, 27 Jun 2008)
New Revision: 27162

Modified:
   xarchiver/trunk/TODO
   xarchiver/trunk/src/archive.c
   xarchiver/trunk/src/archive.h
   xarchiver/trunk/src/main.c
   xarchiver/trunk/src/window.c
Log:
Xarchiver now detects ARJ and ZIP password protected archives when using the 
switches -x and -e.
Updated TODO file.


Modified: xarchiver/trunk/TODO
===================================================================
--- xarchiver/trunk/TODO        2008-06-27 11:57:29 UTC (rev 27161)
+++ xarchiver/trunk/TODO        2008-06-27 12:42:07 UTC (rev 27162)
@@ -1,4 +1,3 @@
-- to fix missed password detection when working with cmd-line switches.
 - add ability to add files in specific archive directories.
 - enrich the status bar
 - to fix the arrow buttons

Modified: xarchiver/trunk/src/archive.c
===================================================================
--- xarchiver/trunk/src/archive.c       2008-06-27 11:57:29 UTC (rev 27161)
+++ xarchiver/trunk/src/archive.c       2008-06-27 12:42:07 UTC (rev 27162)
@@ -699,3 +699,87 @@
        return;
 }
 
+gboolean xa_detect_encrypted_archive (XArchive *archive)
+{
+       FILE *file;
+    unsigned int fseek_offset;
+    unsigned short int password_flag;
+    unsigned int compressed_size;
+    unsigned int uncompressed_size;
+    unsigned short int file_length;
+    unsigned short int extra_length;
+
+       unsigned char sig[2];
+       unsigned short int basic_header_size;
+       unsigned short int extended_header_size;
+       unsigned int basic_header_CRC;
+       unsigned int extended_header_CRC;
+       unsigned char arj_flag;
+       unsigned char magic[3];
+       gboolean flag = FALSE;
+
+       file = fopen (archive->path,"r");
+       fread (magic,1,4,file);
+       
+       fseek (file,6,SEEK_SET);
+       if (archive->type == XARCHIVETYPE_ZIP)
+       {
+               while (memcmp (magic,"\x50\x4b\x03\x04",4) == 0  || memcmp 
(magic,"\x50\x4b\x05\x06",4) == 0)
+               {
+                       fread (&password_flag,1,2,file);
+                       if ((password_flag & ( 1<<0) ) > 0)
+                       {
+                               flag = TRUE;
+                               break;
+                       }
+                       fseek (file,10,SEEK_CUR);
+                       fread (&compressed_size,1,4,file);
+                       fread (&uncompressed_size,1,4,file);
+                       fread (&file_length,1,2,file);
+                       /* If the zip archive is empty (no files) it should 
return here */
+                       if (fread (&extra_length,1,2,file) < 2)
+                       {
+                               flag = FALSE;
+                               break;
+                       }
+                       fseek_offset = compressed_size + file_length + 
extra_length;
+                       fseek (file,fseek_offset,SEEK_CUR);
+                       fread (magic,1,4,file);
+                       fseek (file,2,SEEK_CUR);
+               }
+       }
+       else if (archive->type == XARCHIVETYPE_ARJ)
+       {
+               fseek (file,magic[2]+magic[3],SEEK_CUR);
+               fseek (file,2,SEEK_CUR);
+               fread (&extended_header_size,1,2,file);
+               if (extended_header_size != 0)
+                       fread (&extended_header_CRC,1,4,file);
+               fread (&sig,1,2,file);
+               while ( memcmp (sig,"\x60\xea",2) == 0)
+               {
+                       fread ( &basic_header_size,1,2,file);
+                       if ( basic_header_size == 0 )
+                               break;
+                       fseek ( file , 4 , SEEK_CUR);
+                       fread (&arj_flag,1,1,file);
+                       if ((arj_flag & ( 1<<0) ) > 0)
+                       {
+                               flag = TRUE;
+                               break;
+                       }
+                       fseek (file,7,SEEK_CUR);
+                       fread (&compressed_size,1,4,file);
+                       fseek (file,basic_header_size - 16,SEEK_CUR);
+                       fread (&basic_header_CRC,1,4,file);
+                       fread (&extended_header_size,1,2,file);
+                       if (extended_header_size != 0)
+                               fread (&extended_header_CRC,1,4,file);
+                       fseek (file,compressed_size,SEEK_CUR);
+                       fread (&sig,1,2,file);
+               }
+       }
+       fclose (file);
+       return flag;
+}
+

Modified: xarchiver/trunk/src/archive.h
===================================================================
--- xarchiver/trunk/src/archive.h       2008-06-27 11:57:29 UTC (rev 27161)
+++ xarchiver/trunk/src/archive.h       2008-06-27 12:42:07 UTC (rev 27162)
@@ -141,5 +141,6 @@
 gchar *xa_build_full_path_name_from_entry(XEntry *entry);
 void xa_fill_list_with_recursed_entries(XEntry *entry,GString 
**p_file_list,gchar *current_path);
 void xa_entries_to_filelist(XEntry *, GString **, gchar *);
+gboolean xa_detect_encrypted_archive (XArchive *archive);
 XArchive *archive[100];
 #endif

Modified: xarchiver/trunk/src/main.c
===================================================================
--- xarchiver/trunk/src/main.c  2008-06-27 11:57:29 UTC (rev 27161)
+++ xarchiver/trunk/src/main.c  2008-06-27 12:42:07 UTC (rev 27162)
@@ -125,8 +125,9 @@
                                response = xa_show_message_dialog 
(NULL,GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("Can't extract files 
from the archive:"),_("You missed the archive name!\n"));
                                return -1;
                        }
-                       if (archive->has_passwd)
+                       if (xa_detect_encrypted_archive (archive))
                        {
+                               archive->has_passwd = TRUE;
                                archive->passwd = password_dialog (archive);
                                if (archive->passwd == NULL)
                                        goto done;
@@ -142,13 +143,16 @@
                        }
                }
                /* Switch -e */
-               else if (ask_and_extract)
+               else if (ask_and_extract && archive != NULL)
                {
                        if (argv[1] == NULL)
                        {
                                response = xa_show_message_dialog 
(NULL,GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("Can't extract files 
from the archive:"),_("You missed the archive name!\n"));
                                return -1;
                        }
+                       if (xa_detect_encrypted_archive (archive))
+                               archive->has_passwd = TRUE;
+
                        extract_window = xa_create_extract_dialog (0,archive);
                        xa_parse_extract_dialog_options 
(archive,extract_window,NULL);
                        gtk_widget_destroy (extract_window->dialog1);

Modified: xarchiver/trunk/src/window.c
===================================================================
--- xarchiver/trunk/src/window.c        2008-06-27 11:57:29 UTC (rev 27161)
+++ xarchiver/trunk/src/window.c        2008-06-27 12:42:07 UTC (rev 27162)
@@ -1246,11 +1246,8 @@
        stop_flag = TRUE;
        if (archive[idx]->child_pid)
        {
-               if (kill (archive[idx]->child_pid,SIGABRT) < 0)
-               {
-                       response = xa_show_message_dialog (GTK_WINDOW 
(xa_main_window),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("An error 
occurred while trying to kill the process:"),g_strerror(errno));
-                       return;
-               }
+               kill (archive[idx]->child_pid,SIGABRT);
+               archive[idx]->child_pid = 0;
        }
        /* This in case the user cancels the opening of a password protected 
archive */
        if (archive[idx]->status != XA_ARCHIVESTATUS_ADD)

_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to