Пример #1
0
        private ReplaceInstruction CreateReplaceInstruction(string[] tokens, int lineNumber)
        {
            // we need THREE tokens
            if (tokens.Length < 3)
            {
                Console.WriteLine("Instruction " + lineNumber + " is 'replace' but is missing anything to replace with");
                return(null);
            }
            if (tokens[1].Length != tokens[2].Length)
            {
                Console.WriteLine("Instruction " + lineNumber + " has key and replacement of different lengths: " + tokens[1] + " vs " + tokens[2]);
                return(null);
            }
            ReplaceInstruction r = new ReplaceInstruction(tokens[1], tokens[2]);

            return(r);
        }
Пример #2
0
        static private void ProcessInstructions(List <SearchInstruction> instructions, byte[] bytes)
        {
            int instrIndex = 0;
            int byteIndex  = 0;

            while (instrIndex < instructions.Count)
            {
                SearchInstruction current = instructions[instrIndex];
                Console.WriteLine(current.ToString());
                int newIndex = current.FindMatch(bytes, byteIndex);
                if (newIndex < 0)
                {
                    Console.WriteLine("Failed to find match for instruction " + instrIndex);
                    return;
                }
                if (current is ReplaceInstruction)
                {
                    ReplaceInstruction r = (current as ReplaceInstruction);
                    r.ReplaceAt(bytes, newIndex);
                }
                byteIndex = newIndex + current.MatchLength;
                instrIndex++;
            }
        }