//------------------------------------------------ //--- 010 Editor v2.0 Binary Template // // File: CRX.bt // Authors: G Beier // Version: 1.1 // Purpose: Template for packaged Google Chrome // extensions. Basically a copy of ZIP.bt // with extra bits for Google Chrome // extensions. // Category: Software // File Mask: *.crx // ID Bytes: 43 72 32 34 //Cr24 // History: // 1.1 2016-02-11 SweetScape Software: Updated header for repository submission. // 1.0 G Beier: Initial release. //------------------------------------------------ // Define structures used in ZIP files //enum used for compression format typedef enum { COMP_STORED = 0, COMP_SHRUNK = 1, COMP_REDUCED1 = 2, COMP_REDUCED2 = 3, COMP_REDUCED3 = 4, COMP_REDUCED4 = 5, COMP_IMPLODED = 6, COMP_TOKEN = 7, COMP_DEFLATE = 8, COMP_DEFLATE64 = 9 } COMPTYPE; // Defines a file record typedef struct { // Header for the file char frSignature[4]; //0x04034b50 ushort frVersion; ushort frFlags; COMPTYPE frCompression; DOSTIME frFileTime; DOSDATE frFileDate; uint frCrc ; uint frCompressedSize; uint frUncompressedSize; ushort frFileNameLength; ushort frExtraFieldLength; if( frFileNameLength > 0 ) char frFileName[ frFileNameLength ]; if( frExtraFieldLength > 0 ) uchar frExtraField[ frExtraFieldLength ]; // Compressed data SetBackColor( cNone ); if( frCompressedSize > 0 ) uchar frData[ frCompressedSize ]; } ZIPFILERECORD ; // Defines an entry in the directory table typedef struct { char deSignature[4]; //0x02014b50 ushort deVersionMadeBy; ushort deVersionToExtract; ushort deFlags; COMPTYPE deCompression; DOSTIME deFileTime; DOSDATE deFileDate; uint deCrc ; uint deCompressedSize; uint deUncompressedSize; ushort deFileNameLength; ushort deExtraFieldLength; ushort deFileCommentLength; ushort deDiskNumberStart; ushort deInternalAttributes; uint deExternalAttributes; uint deHeaderOffset; if( deFileNameLength > 0 ) char deFileName[ deFileNameLength ]; if( deExtraFieldLength > 0 ) uchar deExtraField[ deExtraFieldLength ]; if( deFileCommentLength > 0 ) uchar deFileComment[ deFileCommentLength ]; } ZIPDIRENTRY ; // Defines the digital signature typedef struct { char dsSignature[4]; //0x05054b50 ushort dsDataLength; if( dsDataLength > 0 ) uchar dsData[ dsDataLength ]; } ZIPDIGITALSIG; // Defintes the Data descriptor typedef struct { char ddSignature[4]; //0x08074b50 uint ddCRC ; uint ddCompressedSize; uint ddUncompressedSize; } ZIPDATADESCR; // Defines the end of central directory locator typedef struct { char elSignature[4]; //0x06054b50 ushort elDiskNumber; ushort elStartDiskNumber; ushort elEntriesOnDisk; ushort elEntriesInDirectory; uint elDirectorySize; uint elDirectoryOffset; ushort elCommentLength; if( elCommentLength > 0 ) char elComment[ elCommentLength ]; } ZIPENDLOCATOR; //-------------------------------------------- // Custom read functions that allows the name of the // of the file to appear in the Template Results. string ReadZIPFILERECORD( ZIPFILERECORD &file ) { if( exists( file.frFileName ) ) return file.frFileName; else return ""; } string ReadZIPDIRENTRY( ZIPDIRENTRY &entry ) { if( exists( entry.deFileName ) ) return entry.deFileName; else return ""; } // Custom write function that allows changing // the name of the file - note that the file // name size cannot be increased void WriteZIPFILERECORD( ZIPFILERECORD &file, string s ) { local int len = Strlen( s ); if( exists( file.frFileName ) ) { Strncpy( file.frFileName, s, file.frFileNameLength ); if( len < file.frFileNameLength ) file.frFileName[len] = 0; //null terminate } } typedef struct { SetBackColor(0xd8e5ed); char magicNumber[4]; SetBackColor(0xd8edd8); uint32 version; SetBackColor(0xd8e5ed); uint32 pkLength; SetBackColor(0xd8edd8); uint32 sigLength; SetBackColor(0xf7d6c3); byte pubKey[pkLength]; SetBackColor(0xd8edd8); byte sig[sigLength]; } CRXHEADER; //-------------------------------------------- // Define the file SetBackColor(0xe8e8e8); CRXHEADER crxHeader; SetBackColor(cNone); local uint tag; LittleEndian(); while( !FEof() ) { // Read a tag tag = ReadUInt( FTell() ); // Read data depending upon tag - should start with 'PK'. // Note that when duplicate variables are defined, they // are made into an array (see 'Using Templates and Structs' // in the help file). if( tag == 0x04034b50 ) { SetBackColor( cLtGray ); ZIPFILERECORD record; } else if( tag == 0x08074b50 ) { SetBackColor( cLtGreen ); ZIPDATADESCR dataDescr; } else if( tag == 0x02014b50 ) { SetBackColor( cLtPurple ); ZIPDIRENTRY dirEntry; } else if( tag == 0x05054b50 ) { SetBackColor( cLtBlue ); ZIPDIGITALSIG digitalSig; } else if( tag == 0x06054b50 ) { SetBackColor( cLtYellow ); ZIPENDLOCATOR endLocator; } else { Warning( "Unknown ZIP tag encountered. Template stopped." ); return -1; } }