Changeset 1069


Ignore:
Timestamp:
Jan 12, 2010, 11:57:47 AM (12 years ago)
Author:
arnold
Message:

some little changes

Location:
trunk/CrypPlugins/KeySearcher
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/KeySearcher/KeyPattern.cs

    r1044 r1069  
    630630        #region Serialization methods and auxiliary variables
    631631
    632         /// <summary>
    633         /// Used for serializing/deserializing the KeyPattern object. This string separates Key from Pattern. Example: [key]kpSeparator[pattern]
    634         /// </summary>
    635         private string kpSeperator = "#;#";
     632        /* Serialization information:
     633         * 1st byte: Byte-Length of the WildCardKey
     634         * 2nd - wildcardLen: WildCardKey Byte representation
     635         * wildcardLen + 1: Byte-Length of the Pattern
     636         * wildcardLen + 2 - wildcardLen+2+patternLen: Pattern Byte representation
     637         *  -------------------------------------------------------------
     638         * | wildcardkey length | wildcardkey | pattern length | pattern |
     639         *  -------------------------------------------------------------  */
    636640        private Encoding encoder = UTF8Encoding.UTF8;
    637 
    638         /// <summary>
    639         /// Serialize all needful information to rebuild the existing pattern elsewhere
    640         /// </summary>
    641         /// <returns>string representation of all the needful information of the actual KeyPattern</returns>
    642         public string SerializeToString()
    643         {
    644             return (string)Serialize(false);
    645         }
    646641
    647642        /// <summary>
     
    649644        /// </summary>
    650645        /// <returns>byte representation of all the needful information of the actual KeyPattern</returns>
    651         public byte[] SerializeToByte()
    652         {
    653             return (byte[])Serialize(true);
    654         }
    655 
    656         /// <summary>
    657         /// The whole serializing process.
    658         /// </summary>
    659         /// <param name="returnByte">Choose true, to get a KeyPattern serialized as an byte array, otherwise you will get a string.</param>
    660         /// <returns></returns>
    661         private object Serialize(bool returnByte)
    662         {
    663             object objReturn = null;
     646        public byte[] Serialize()
     647        {
     648            byte[] retByte;
    664649            string wildcardKey = this.WildcardKey;
    665650            if (wildcardKey != null && this.pattern != null)
     
    667652                if (testWildcardKey(wildcardKey))
    668653                {
    669                     if (returnByte)
    670                         objReturn = encoder.GetBytes(wildcardKey + kpSeperator + pattern);
    671                     else
    672                         objReturn = wildcardKey + kpSeperator + pattern;
     654                    byte[] byteWildCard = encoder.GetBytes(wildcardKey);
     655                    byte[] bytePattern = encoder.GetBytes(pattern);
     656                    retByte = new byte[byteWildCard.Length + bytePattern.Length + 2];
     657                    retByte[0] = (byte)byteWildCard.Length;
     658                    Buffer.BlockCopy(byteWildCard, 0, retByte, 1, byteWildCard.Length);
     659                    retByte[byteWildCard.Length + 1] = (byte)bytePattern.Length;
     660                    Buffer.BlockCopy(bytePattern, 0, retByte, byteWildCard.Length + 2, bytePattern.Length);
    673661                }
    674662                else
     
    682670                throw (new Exception("Serializing KeyPattern canceled, because Key and/or Pattern are NULL. WildcardKey: '" + wildcardKey + "'. Pattern: '" + pattern + "'."));
    683671            }
    684             return objReturn;
    685         }
    686 
    687         private KeyPattern Deserialize(object represenatation)
    688         {
    689             KeyPattern keyPatternToReturn;
    690 
    691             // casting stuff
    692             string sTemp = null;
    693             if (represenatation is byte[])
    694                 sTemp = encoder.GetString(represenatation as byte[]);
    695             else if (represenatation is string)
    696                 sTemp = represenatation as string;
    697             else
    698                 throw (new Exception("Deserializing KeyPattern canceled, because parameter neither a byte array nor a string!"));
    699 
    700             // disaggregate string representation
    701             string wildcardKey_temp = sTemp.Substring(0, sTemp.IndexOf(kpSeperator));
    702             int beginOfPattern = sTemp.IndexOf(kpSeperator) + kpSeperator.Length;
    703             string pattern_temp = sTemp.Substring(beginOfPattern, sTemp.Length - beginOfPattern);
    704 
    705             // test extracted pattern and wildcardKey!
    706             if (testWildcardKey(wildcardKey_temp))
    707             {
    708                 // TODO: use Pattern-property in future
    709                 keyPatternToReturn = new KeyPattern(pattern_temp);
    710                 // TODO: use WildcardKey-property in future
    711                 keyPatternToReturn.WildcardKey = wildcardKey_temp;
    712                 return keyPatternToReturn;
    713             }
    714             else
    715             {
    716                 throw (new Exception("Deserializing KeyPattern canceled, because WildcardKey or Pattern aren't valid. "
    717                     + "WildcardKey: '" + wildcardKey_temp + "', Pattern: '" + pattern_temp + "'.\n"));
    718             }
    719         }
    720 
    721         public KeyPattern DeserializeFromString(string sKeyPattern)
    722         {
    723             return Deserialize(sKeyPattern);
     672            return retByte;
    724673        }
    725674
     
    727676        /// Deserialize a byte-representation of an KeyPattern object. Returns a full-initialized KeyPattern object.
    728677        /// </summary>
    729         /// <param name="bKeyPattern">byte-representation of an keypattern object</param>
     678        /// <param name="serializedPattern">byte-representation of an keypattern object</param>
    730679        /// <returns>a full-initialized KeyPattern object</returns>
    731         public KeyPattern DeserializeFromByte(byte[] bKeyPattern)
    732         {
    733             return Deserialize(bKeyPattern);
     680        public KeyPattern Deserialize(byte[] serializedPattern)
     681        {
     682            KeyPattern keyPatternToReturn;
     683            string wildcardKey_temp;
     684            string pattern_temp;
     685
     686            int iWildCardLen = serializedPattern[0];
     687            wildcardKey_temp = encoder.GetString(serializedPattern, 1, iWildCardLen);
     688            int iPatternLen = serializedPattern[iWildCardLen + 1];
     689            pattern_temp = encoder.GetString(serializedPattern, iWildCardLen + 2, iPatternLen);
     690
     691            // test extracted pattern and wildcardKey!
     692            if (testWildcardKey(wildcardKey_temp))
     693            {
     694                keyPatternToReturn = new KeyPattern(pattern_temp);
     695                keyPatternToReturn.WildcardKey = wildcardKey_temp;
     696                return keyPatternToReturn;
     697            }
     698            else
     699            {
     700                throw (new Exception("Deserializing KeyPattern canceled, because WildcardKey or Pattern aren't valid. "
     701                    + "WildcardKey: '" + wildcardKey_temp + "', Pattern: '" + pattern_temp + "'.\n"));
     702            }
    734703        }
    735704
  • trunk/CrypPlugins/KeySearcher/KeySearcher.cs

    r1036 r1069  
    107107            settings = new KeySearcherSettings(this);
    108108            QuickWatchPresentation = new KeySearcherQuickWatchPresentation();
     109           
    109110        }
    110111
     
    758759        }
    759760
    760         // modified by Christian Arnold - 2009.12.07 (to public)
    761761        /// <summary>
    762762        /// used for delivering the results from the worker threads to the main thread:
  • trunk/CrypPlugins/KeySearcher/KeySearcherQuickWatchPresentation.xaml.cs

    r1030 r1069  
    2121    /// </summary>
    2222    public partial class KeySearcherQuickWatchPresentation : UserControl
    23     {
     23    {       
    2424        public ObservableCollection<ResultEntry> entries = new ObservableCollection<ResultEntry>();
    2525
Note: See TracChangeset for help on using the changeset viewer.