/// ------------------------------------------------------------------------------------ /// <summary> /// Return all matches of the text in specified text using the Boyer-Moore algorithm /// </summary> /// <param name="text">The input text.</param> /// <param name="pattern">The pattern to search.</param> /// <param name="startingIndex">The index to start search at.</param> /// <returns>Index of first occurence of <paramref name="pattern"/> in input /// <paramref name="text"/>, or -1 if it is not found. If <paramref name="pattern"/> /// is Empty, the return value is 0.</returns> /// ------------------------------------------------------------------------------------ public static int IndexOf(byte[] text, string pattern, int startingIndex) { if (pattern == null || pattern.Length == 0) { return(0); } BoyerMooreBinarySearch search = new BoyerMooreBinarySearch(pattern); return(search.IndexOf(text, 0)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Processes the data entry. /// </summary> /// ------------------------------------------------------------------------------------ private void ProcessDataEntry() { int nVirtualAddress = m_reader.ReadInt32(); int nSize = m_reader.ReadInt32(); long nTypeLibAddress = m_BaseAddress + nVirtualAddress - m_SectionBase; m_stream.Position = nTypeLibAddress; object obj = m_TypeStack[0]; if (obj is string && ((string)obj) == "TYPELIB") { // HACK: I can't find the spec for TypeLib, so we just search for // the typical string and zero out the date that follows, as well // as a few additional bytes that seem to change int nPos = BoyerMooreBinarySearch.IndexOf(m_reader.ReadBytes(nSize), "Created by MIDL version"); if (nPos > 0) { // Overwrite time stamp that MIDL compiler generated: // Created by MIDL version 6.00.0366 at Thu Jul 27 11:27:58 2006\n m_stream.Position = nTypeLibAddress + nPos + 37; byte[] buffer = new byte[32]; // Thu Jul 27 11:27:58 2006\n m_writer.Write(buffer); } } else if (obj is int) { int id = (int)obj; if (id == 16) // Version Info { ProcessVersionInfo(); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Return all matches of the text in specified text using the Boyer-Moore algorithm /// </summary> /// <param name="text">The input text.</param> /// <param name="pattern">The pattern to search.</param> /// <param name="startingIndex">The index to start search at.</param> /// <returns>Index of first occurence of <paramref name="pattern"/> in input /// <paramref name="text"/>, or -1 if it is not found. If <paramref name="pattern"/> /// is Empty, the return value is 0.</returns> /// ------------------------------------------------------------------------------------ public static int IndexOf(byte[] text, string pattern, int startingIndex) { if (pattern == null || pattern.Length == 0) return 0; BoyerMooreBinarySearch search = new BoyerMooreBinarySearch(pattern); return search.IndexOf(text, 0); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Return all matches of the text in specified text using the Boyer-Moore algorithm /// </summary> /// <param name="pattern">To pattern to search.</param> /// <param name="text">The text to search.</param> /// <returns>index of text matches</returns> /// ------------------------------------------------------------------------------------ public static int IndexOf(byte[] text, string pattern) { return(BoyerMooreBinarySearch.IndexOf(text, pattern, 0)); }