<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[GMan's Mods & Stuff — Support for CRX (Chrome Extension Files)]]></title>
	<link rel="self" href="https://gprogs.com/extern.php?action=feed&amp;tid=471&amp;type=atom" />
	<updated>2013-02-13T15:41:48Z</updated>
	<generator>PunBB</generator>
	<id>https://gprogs.com/viewtopic.php?id=471</id>
		<entry>
			<title type="html"><![CDATA[Support for CRX (Chrome Extension Files)]]></title>
			<link rel="alternate" href="https://gprogs.com/viewtopic.php?pid=1756#p1756" />
			<content type="html"><![CDATA[<p>Hi there, </p><p>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.</p><div class="codebox"><pre><code>    

    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;
        
        &#039; 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); &#039; CRX Version
            zip_start_pos:+4;
            
            zip_start_pos:+ReadInt(zipFile); &#039; length of crx public key
            zip_start_pos:+4;
            
            zip_start_pos:+ReadInt(zipFile); &#039; length of crx signature
            zip_start_pos:+4;
            
            SeekStream(zipFile, zip_start_pos);
            magic_number:Int = ReadInt(zipFile);
            
        EndIf
        
        &#039; first check to see if its even a valid ZIP file
        If magic_number &lt;&gt; $04034b50 Then 
            DebugLog(&quot;Invalid ZIP file!&quot;)
            Return False
        EndIf
        
        Local header_start:Int = 0
        
        &#039; jump to the end
        SeekStream(zipFile, StreamSize(zipFile) - 4)
        
        &#039; seek the end central directory structure
        While Not StreamPos(zipFile) = 0
            Local sig:Int = ReadInt(zipFile)
            If sig = $06054b50 Then
                &#039; jump to start of central dir location    
                SeekStream(zipFile, StreamPos(zipFile) + 12)
                header_start = ReadInt(zipFile)
                Exit                
            Else
                &#039; rewind 3 bytes and try again
                SeekStream(zipFile, StreamPos(zipFile) - 5)
            EndIf
        EndWhile
    
        &#039; if we found the header, then process
        If Not header_start Then 
            DebugLog(&quot;unable to locate central directory!&quot;)
            Return False
        EndIf
        
        header_start:+zip_start_pos;
        
        &#039; 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)

                &#039; read filename
                entry.zipFileName = entry.header.FileName            
                extractFilename(entry)                                 
            Else
                Exit
            EndIf
        EndWhile
    
        Return True
    EndMethod</code></pre></div><p><img src="https://gprogs.com/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></content>
			<author>
				<name><![CDATA[paramausi]]></name>
				<uri>https://gprogs.com/profile.php?id=355</uri>
			</author>
			<updated>2013-02-13T15:41:48Z</updated>
			<id>https://gprogs.com/viewtopic.php?pid=1756#p1756</id>
		</entry>
</feed>
