1 (edited by paramausi 2013-02-13 09:44:07)

Topic: Support for CRX (Chrome Extension Files)

Hi there,

the method ScanCentralHeader of Type TZipFileList can be changed to the following code (or similar), in order to make extraction of CRX (Chrome Extension Files) possible via zipengine.

    

    Rem
        bbdoc: Scans the central header for files.  Returns true if successful.
    End Rem
    Method ScanCentralHeader:Int()
    
        SeekStream(zipFile, 0)
        Local magic_number:Int = ReadInt(zipFile);
        Local zip_start_pos:Int = 0;
        
        ' CRX FILE (Google Chrome Extension File), see: http://developer.chrome.com/extensions/crx.html
        If magic_number = $34327243 Then
            
            zip_start_pos:+4;
            
            ReadInt(zipFile); ' CRX Version
            zip_start_pos:+4;
            
            zip_start_pos:+ReadInt(zipFile); ' length of crx public key
            zip_start_pos:+4;
            
            zip_start_pos:+ReadInt(zipFile); ' length of crx signature
            zip_start_pos:+4;
            
            SeekStream(zipFile, zip_start_pos);
            magic_number:Int = ReadInt(zipFile);
            
        EndIf
        
        ' first check to see if its even a valid ZIP file
        If magic_number <> $04034b50 Then 
            DebugLog("Invalid ZIP file!")
            Return False
        EndIf
        
        Local header_start:Int = 0
        
        ' jump to the end
        SeekStream(zipFile, StreamSize(zipFile) - 4)
        
        ' seek the end central directory structure
        While Not StreamPos(zipFile) = 0
            Local sig:Int = ReadInt(zipFile)
            If sig = $06054b50 Then
                ' jump to start of central dir location    
                SeekStream(zipFile, StreamPos(zipFile) + 12)
                header_start = ReadInt(zipFile)
                Exit                
            Else
                ' rewind 3 bytes and try again
                SeekStream(zipFile, StreamPos(zipFile) - 5)
            EndIf
        EndWhile
    
        ' if we found the header, then process
        If Not header_start Then 
            DebugLog("unable to locate central directory!")
            Return False
        EndIf
        
        header_start:+zip_start_pos;
        
        ' seek to the start of the central directory
        SeekStream(zipFile, header_start)
        
        While True And Not Eof(zipFile)
            Local entry:SZipFileEntry = SZipFileEntry.Create()
            If entry.header.fill(zipFile) Then
                FileList.AddLast(entry)

                ' read filename
                entry.zipFileName = entry.header.FileName            
                extractFilename(entry)                                 
            Else
                Exit
            EndIf
        EndWhile
    
        Return True
    EndMethod

smile