예제 #1
0
        /// <summary>
        /// <inheritDoc></inheritDoc>
        /// <p>
        /// This implementation returns DUMMY_HANDLER for databases with no encoding
        /// and UNSUPPORTED_HANDLER for databases with any encoding.
        /// </summary>
        /// <exception cref="System.IO.IOException"></exception>
        public virtual CodecHandler CreateHandler(PageChannel channel, Encoding charset)
        {
            JetFormat format = channel.GetFormat();

            switch (format.CODEC_TYPE)
            {
            case JetFormat.CodecType.NONE:
            {
                // no encoding, all good
                return(DUMMY_HANDLER);
            }

            case JetFormat.CodecType.JET:
            {
                // check for an encode key.  if 0, not encoded
                ByteBuffer bb = channel.CreatePageBuffer();
                channel.ReadPage(bb, 0);
                int codecKey = bb.GetInt(format.OFFSET_ENCODING_KEY);
                return((codecKey == 0) ? DUMMY_HANDLER : UNSUPPORTED_HANDLER);
            }

            case JetFormat.CodecType.MSISAM:
            {
                // always encoded, we don't handle it
                return(UNSUPPORTED_HANDLER);
            }

            default:
            {
                throw new RuntimeException("Unknown codec type " + format.CODEC_TYPE);
            }
            }
        }
예제 #2
0
        /// <exception cref="System.IO.IOException"></exception>
        public virtual CodecHandler CreateHandler(PageChannel channel, Encoding charset)
        {
            JetFormat format = channel.GetFormat();

            switch (format.CODEC_TYPE)
            {
            case JetFormat.CodecType.NONE:
            {
                // no encoding, all good
                return(DefaultCodecProvider.DUMMY_HANDLER);
            }

            case JetFormat.CodecType.JET:
            {
                return(JetCryptCodecHandler.Create(channel));
            }

            case JetFormat.CodecType.MSISAM:
            {
                return(MSISAMCryptCodecHandler.Create(GetPassword(), channel, charset));
            }

            default:
            {
                throw new RuntimeException("Unknown codec type " + format.CODEC_TYPE);
            }
            }
        }
예제 #3
0
        /// <param name="database">database that contains this usage map</param>
        /// <param name="pageNum">Page number that this usage map is contained in</param>
        /// <param name="rowNum">Number of the row on the page that contains this usage map</param>
        /// <returns>
        /// Either an InlineUsageMap or a ReferenceUsageMap, depending on
        /// which type of map is found
        /// </returns>
        /// <exception cref="System.IO.IOException"></exception>
        public static HealthMarketScience.Jackcess.UsageMap Read(Database database, int pageNum
                                                                 , int rowNum, bool assumeOutOfRangeBitsOn)
        {
            JetFormat   format      = database.GetFormat();
            PageChannel pageChannel = database.GetPageChannel();
            ByteBuffer  tableBuffer = pageChannel.CreatePageBuffer();

            pageChannel.ReadPage(tableBuffer, pageNum);
            short rowStart = Table.FindRowStart(tableBuffer, rowNum, format);
            int   rowEnd   = Table.FindRowEnd(tableBuffer, rowNum, format);

            tableBuffer.Limit(rowEnd);
            byte mapType = tableBuffer.Get(rowStart);

            HealthMarketScience.Jackcess.UsageMap rtn = new HealthMarketScience.Jackcess.UsageMap
                                                            (database, tableBuffer, pageNum, rowStart);
            rtn.InitHandler(mapType, assumeOutOfRangeBitsOn);
            return(rtn);
        }
예제 #4
0
        /// <exception cref="System.IO.IOException"></exception>
        public static CodecHandler Create(PageChannel channel)
        {
            ByteBuffer buffer = ReadHeaderPage(channel);
            JetFormat  format = channel.GetFormat();

            byte[] encodingKey = new byte[ENCODING_KEY_LENGTH];
            buffer.Position(format.OFFSET_ENCODING_KEY);
            buffer.Get(encodingKey);
            bool clearData = true;

            foreach (byte byteVal in encodingKey)
            {
                if (byteVal != 0)
                {
                    clearData = false;
                }
            }
            return(clearData ? DefaultCodecProvider.DUMMY_HANDLER : new HealthMarketScience.Jackcess.JetCryptCodecHandler
                       (encodingKey));
        }
 private static byte[] GetOldDecryptionKey(ByteBuffer buffer, JetFormat format)
 {
     byte[] encodingKey = new byte[JetCryptCodecHandler.ENCODING_KEY_LENGTH];
     buffer.Position(SALT_OFFSET);
     buffer.Get(encodingKey);
     {
         // Hash the salt. Step 1.
         byte[] fullHashData = new byte[format.SIZE_PASSWORD * 2];
         buffer.Position(format.OFFSET_PASSWORD);
         buffer.Get(fullHashData);
         // apply additional mask to header data
         byte[] pwdMask = Database.GetPasswordMask(buffer, format);
         if (pwdMask != null)
         {
             for (int i = 0; i < format.SIZE_PASSWORD; ++i)
             {
                 fullHashData[i] ^= pwdMask[i % pwdMask.Length];
             }
             int trailingOffset = fullHashData.Length - TRAILING_PWD_LEN;
             for (int i_1 = 0; i_1 < TRAILING_PWD_LEN; ++i_1)
             {
                 fullHashData[trailingOffset + i_1] ^= pwdMask[i_1 % pwdMask.Length];
             }
         }
         byte[] hashData = new byte[format.SIZE_PASSWORD];
         for (int pos = 0; pos < format.SIZE_PASSWORD; pos++)
         {
             hashData[pos] = fullHashData[pos * 2];
         }
         HashSalt(encodingKey, hashData);
     }
     {
         // Hash the salt. Step 2
         byte[] jetHeader = new byte[JetFormat.LENGTH_ENGINE_NAME];
         buffer.Position(JetFormat.OFFSET_ENGINE_NAME);
         buffer.Get(jetHeader);
         HashSalt(encodingKey, jetHeader);
     }
     return(encodingKey);
 }
예제 #6
0
        /// <exception cref="System.IO.IOException"></exception>
        protected internal Index(ByteBuffer tableBuffer, IList <IndexData> indexDatas, JetFormat
                                 format)
        {
            ByteUtil.Forward(tableBuffer, format.SKIP_BEFORE_INDEX_SLOT);
            //Forward past Unknown
            _indexNumber = tableBuffer.GetInt();
            int indexDataNumber = tableBuffer.GetInt();
            // read foreign key reference info
            byte relIndexType       = tableBuffer.Get();
            int  relIndexNumber     = tableBuffer.GetInt();
            int  relTablePageNumber = tableBuffer.GetInt();
            byte cascadeUpdatesFlag = tableBuffer.Get();
            byte cascadeDeletesFlag = tableBuffer.Get();

            _indexType = tableBuffer.Get();
            if ((_indexType == FOREIGN_KEY_INDEX_TYPE) && (relIndexNumber != INVALID_INDEX_NUMBER
                                                           ))
            {
                _reference = new Index.ForeignKeyReference(relIndexType, relIndexNumber, relTablePageNumber
                                                           , (cascadeUpdatesFlag == CASCADE_UPDATES_FLAG), (cascadeDeletesFlag == CASCADE_DELETES_FLAG
                                                                                                            ));
            }
            else
            {
                _reference = null;
            }
            ByteUtil.Forward(tableBuffer, format.SKIP_AFTER_INDEX_SLOT);
            //Skip past Unknown
            _data = indexDatas[indexDataNumber];
            _data.AddIndex(this);
        }