示例#1
0
        public void Upsert_All_Frames_At_The_Current_Position()
        {
            var options = new IndexOptions()
            {
                MemoryRanges = new []
                {
                    new MemoryRange(0x100, 0x200),
                }
            };
            var indexMethod = new IndexMethod();
            var sc          = new ServerClientBuilder();

            sc.WithUpsertFrames(() =>
            {
            });
            sc.WithAddMemoryRange();
            var ttf = new TimeTravelFacadeBuilder();

            ttf.WithPositions(new PositionsResult(new[]
            {
                new PositionsRecord(1, new Position(1, 1), true),
                new PositionsRecord(2, new Position(1, 1), false),
            }));
            var dbg = new DebugEngineProxyBuilder();

            dbg.WithReadVirtualMemory(new byte[] { 0x00, 0x11 });
            indexMethod.ServerClient     = sc.Build();
            indexMethod.TimeTravelFacade = ttf.Build();
            indexMethod.DebugEngineProxy = dbg.Build();

            indexMethod.UpsertCurrentPosition(options);
            sc.Mock.Verify(client => client.UpsertFrames(It.Is <IEnumerable <Frame> >(frames => frames.Count() == 2)), Times.Once);
            sc.Mock.Verify(client => client.AddMemoryRange(It.IsAny <MemoryChunk>()), Times.Once);
        }
示例#2
0
        public void Process_Command_Line_Arguments_Properly()
        {
            var indexMethod = new IndexMethod();

            {
                var options = indexMethod.ExtractIndexOptions(new string[] { });
                options.AccessBreakpoints.Should().BeNull();
                options.End.Should().BeNull();
                options.BreakpointMasks.Should().BeNull();
                options.IsAllPositionsInRange.Should().BeFalse();
                options.Step.Should().Be(0);
                options.Start.Should().BeNull();
                options.MemoryRanges.Should().BeNull();
            }

            {
                var options = indexMethod.ExtractIndexOptions(new[]
                {
                    "-s", "0:0", "-m", "abc123L50", "def341:def441", "-e", "1:0", "--step", "1", "--ba", "rw8:abc120",
                    "--bm", "kernel32!*", "-a"
                });
                options.AccessBreakpoints.Should().HaveCount(1);
                options.End.Should().Be(new Position(1, 0));
                options.BreakpointMasks.Should().HaveCount(1);
                options.IsAllPositionsInRange.Should().BeTrue();
                options.Step.Should().Be(1);
                options.Start.Should().Be(new Position(0, 0));
                options.MemoryRanges.Should().HaveCount(2);
            }
        }
示例#3
0
        public void Extract_The_Desired_Step_From_Args()
        {
            var indexMethod = new IndexMethod();

            {
                var options = new IndexOptions();
                var args    = new[] { "--ba", "-s", "0:0", "-e", "42:10", "--step", "1" };
                var index   = indexMethod.ExtractStep(args, 5, options);
                index.Should().Be(6);
                options.Step.Should().Be(1);
            }

            {
                var options = new IndexOptions();
                var args    = new[] { "--step", "1", "-s", "0:0", "-e", "42:10" };
                var index   = indexMethod.ExtractStep(args, 0, options);
                index.Should().Be(1);
                options.Step.Should().Be(1);
            }

            {
                var    options = new IndexOptions();
                var    args    = new[] { "--ba", "--step", "gibberish", "-s", "0:0" };
                Action a       = () => indexMethod.ExtractStep(args, 1, options);
                a.Should().Throw <FormatException>();
            }

            {
                var    options = new IndexOptions();
                var    args    = new[] { "--ba", "--step" };
                Action a       = () => indexMethod.ExtractStep(args, 1, options);
                a.Should().Throw <ArgumentException>();
            }
        }
示例#4
0
        public void Extract_Access_Breakpoints_From_Args()
        {
            var indexMethod = new IndexMethod();

            {
                var options = new IndexOptions();
                var args    = new[] { "--ba", "rw8:abc120", "r8:abc420", "-s", "0:0" };
                var index   = indexMethod.ExtractAccessBreakpoints(args, 0, "--ba", options);
                index.Should().Be(2);
                options.AccessBreakpoints.Should().HaveCount(2);
                options.AccessBreakpoints.ElementAt(0).Should().Be(new AccessBreakpoint(0xabc120, 8, true, true));
                options.AccessBreakpoints.ElementAt(1).Should().Be(new AccessBreakpoint(0xabc420, 8, true, false));
            }

            {
                var options = new IndexOptions();
                var args    = new[] { "-s", "0:0", "--ba" };
                var index   = indexMethod.ExtractAccessBreakpoints(args, 2, "--ba", options);
                index.Should().Be(2);
                options.AccessBreakpoints.Should().HaveCount(0);
            }

            {
                var    options = new IndexOptions();
                var    args    = new[] { "--ba", "gibberish", "-s", "0:0" };
                Action a       = () => indexMethod.ExtractAccessBreakpoints(args, 0, "--ba", options);
                a.Should().Throw <FormatException>();
            }
        }
示例#5
0
        public void Create_Frames_For_All_Frames_With_The_Same_Position()
        {
            var indexMethod = new IndexMethod();

            indexMethod.TimeTravelFacade = new TimeTravelFacadeBuilder()
                                           .WithGetCurrentFrame(1, new Frame {
                ThreadId = 1
            })
                                           .WithGetCurrentFrame(2, new Frame {
                ThreadId = 2
            })
                                           .Build();

            var positionsResult = new PositionsResult(new[]
            {
                new PositionsRecord(1, new Position(1, 1), true),
                new PositionsRecord(3, new Position(2, 1), false),
                new PositionsRecord(2, new Position(1, 1), false)
            });

            var frames = indexMethod.CreateFramesForUpsert(positionsResult);

            frames[0].ThreadId.Should().Be(1);
            frames[1].ThreadId.Should().Be(2);
        }
示例#6
0
        public void Extract_The_Desired_Starting_Position_From_Args()
        {
            var indexMethod = new IndexMethod();

            {
                var options = new IndexOptions();
                var args    = new[] { "--ba", "-s", "0:0", "-e", "42:10" };
                var index   = indexMethod.ExtractStartingPosition(args, 1, "-s", options);
                index.Should().Be(2);
                options.Start.Should().Be(new Position(0, 0));
            }

            {
                var options = new IndexOptions();
                var args    = new[] { "--ba", "-e", "1:0", "-s", "0:0" };
                var index   = indexMethod.ExtractStartingPosition(args, 3, "-s", options);
                index.Should().Be(4);
                options.Start.Should().Be(new Position(0, 0));
            }

            {
                var    options = new IndexOptions();
                var    args    = new[] { "--ba", "-e", "1:0", "-s", "gibberish" };
                Action a       = () => indexMethod.ExtractStartingPosition(args, 3, "-s", options);
                a.Should().Throw <FormatException>();
            }

            {
                var    options = new IndexOptions();
                var    args    = new[] { "--ba", "-s" };
                Action a       = () => indexMethod.ExtractStartingPosition(args, 1, "-s", options);
                a.Should().Throw <ArgumentException>();
            }
        }
示例#7
0
        public void Extract_Breakpoint_Masks_From_Args()
        {
            var indexMethod = new IndexMethod();

            {
                var options = new IndexOptions();
                var args    = new[] { "--bm", "kernel32!*", "ntdll!*", "-s", "0:0" };
                var index   = indexMethod.ExtractBreakpointMasks(args, 0, "--bm", options);
                index.Should().Be(2);
                options.BreakpointMasks.Should().HaveCount(2);
                options.BreakpointMasks.ElementAt(0).Should().Be(new BreakpointMask("kernel32", "*"));
                options.BreakpointMasks.ElementAt(1).Should().Be(new BreakpointMask("ntdll", "*"));
            }

            {
                var options = new IndexOptions();
                var args    = new[] { "--bm" };
                var index   = indexMethod.ExtractBreakpointMasks(args, 0, "--bm", options);
                index.Should().Be(0);
                options.BreakpointMasks.Should().HaveCount(0);
            }

            {
                var    options = new IndexOptions();
                var    args    = new[] { "--bm", "gibberish", "-s", "0:0" };
                Action a       = () => indexMethod.ExtractBreakpointMasks(args, 0, "--bm", options);
                a.Should().Throw <FormatException>();
            }
        }
示例#8
0
        public void Extract_Memory_Ranges_()
        {
            var indexMethod = new IndexMethod();

            {
                var options = new IndexOptions();
                var args    = new[] { "-m", "abc120L50", "abc100:abc420", "-s", "0:0" };
                var index   = indexMethod.ExtractMemoryRanges(args, 0, "-m", options);
                index.Should().Be(2);
                options.MemoryRanges.Should().HaveCount(2);
                options.MemoryRanges.ElementAt(0).Should().Be(new MemoryRange(0xabc120, 0xabc170));
                options.MemoryRanges.ElementAt(1).Should().Be(new MemoryRange(0xabc100, 0xabc420));
            }

            {
                var options = new IndexOptions();
                var args    = new[] { "-s", "0:0", "--ba", "-m" };
                var index   = indexMethod.ExtractMemoryRanges(args, 4, "-m", options);
                index.Should().Be(4);
                options.MemoryRanges.Should().HaveCount(0);
            }

            {
                var    options = new IndexOptions();
                var    args    = new[] { "-m", "gibberish", "-s", "0:0" };
                Action a       = () => indexMethod.ExtractMemoryRanges(args, 0, "-m", options);
                a.Should().Throw <FormatException>();
            }
        }
示例#9
0
        public void Properly_Parse_Args_Into_Options()
        {
            // arrange
            var args0 =
                "--start abc:123 --end def:456 --bm kernel32!*create* user32!* --ba rw8:10000 w4:30000 -m abcl100 abc:def"
                .Split(' ');
            var options0 = new IndexOptions
            {
                Start           = new Position(0xabc, 0x123),
                End             = new Position(0xdef, 0x456),
                BreakpointMasks = new[]
                {
                    new BreakpointMask("kernel32", "*create*"),
                    new BreakpointMask("user32", "*")
                },
                AccessBreakpoints = new[]
                {
                    new AccessBreakpoint(0x10000, 8, true, true),
                    new AccessBreakpoint(0x30000, 4, false, true)
                },
                MemoryRanges = new[]
                {
                    new MemoryRange(0xabc, 0xbbc),
                    new MemoryRange(0xabc, 0xdef)
                }
            };
            var index = new IndexMethod();

            // act
            // assert
            index.ExtractIndexOptions(args0).Should().Be(options0);
        }
示例#10
0
        private IEnumerable <MethodInfo> MakeActions()
        {
            var knownMethods = IndexMethod.AsSingle().Concat(Formatters);
            var methods      = PaperType.GetMethods(BindingFlags.Public | BindingFlags.Instance).Except(knownMethods);

            foreach (var method in methods)
            {
                if (method.DeclaringType.Namespace.StartsWith("System"))
                {
                    continue;
                }

                if (typeof(void).IsAssignableFrom(method.ReturnType) ||
                    typeof(Ret).IsAssignableFrom(method.ReturnType)

                    || typeof(string).IsAssignableFrom(method.ReturnType) ||
                    typeof(Href).IsAssignableFrom(method.ReturnType) ||
                    typeof(Uri).IsAssignableFrom(method.ReturnType) ||
                    typeof(UriString).IsAssignableFrom(method.ReturnType)

                    || typeof(Ret <string>).IsAssignableFrom(method.ReturnType) ||
                    typeof(Ret <Href>).IsAssignableFrom(method.ReturnType) ||
                    typeof(Ret <Uri>).IsAssignableFrom(method.ReturnType) ||
                    typeof(Ret <UriString>).IsAssignableFrom(method.ReturnType))
                {
                    yield return(method);
                }
            }
        }
示例#11
0
        public void Set_Breakpoints_Correctly()
        {
            var options = new IndexOptions()
            {
                BreakpointMasks = new []
                {
                    new BreakpointMask("kernel32", "*create*"),
                    new BreakpointMask("kernel32", "*process*"),
                },
                AccessBreakpoints = new []
                {
                    new AccessBreakpoint(0x100, 8, true, false),
                }
            };
            var indexMethod = new IndexMethod();
            BreakpointFacadeBuilder breakpointFacadeBuilder = new BreakpointFacadeBuilder();

            indexMethod.BreakpointFacade = breakpointFacadeBuilder
                                           .WithSetBreakpointByMask()
                                           .WithSetReadAccessBreakpoint()
                                           .Build();
            indexMethod.SetBreakpoints(options);
            breakpointFacadeBuilder.Mock.Verify(facade => facade.SetBreakpointByMask(It.IsAny <string>(), It.IsAny <string>()), Times.Exactly(2));
            breakpointFacadeBuilder.Mock.Verify(facade => facade.SetReadAccessBreakpoint(It.IsAny <int>(), It.IsAny <ulong>()), Times.Once);
        }
示例#12
0
        public IndexedStorage(string indexPrefix, IndexMethod indexingMethod)
        {
            IndexingMethod = indexingMethod;
            IndexPrefix = indexPrefix;

            LoadIndex();
        }
示例#13
0
 private ParameterInfo[] MakePaperParameters()
 {
     return((
                from param in IndexMethod.GetParameters()
                where !typeof(Sort).IsAssignableFrom(param.ParameterType) &&
                !typeof(Page).IsAssignableFrom(param.ParameterType) &&
                !typeof(IFilter).IsAssignableFrom(param.ParameterType)
                select param
                ).ToArray());
 }
示例#14
0
        public void Get_The_Correct_Ending_Position()
        {
            var indexMethod = new IndexMethod();

            indexMethod.TimeTravelFacade = new TimeTravelFacadeBuilder()
                                           .WithLastPosition(new Position(1, 1))
                                           .Build();
            indexMethod.GetEndingPosition(new IndexOptions()).Should().Be(new Position(1, 1));
            indexMethod.GetEndingPosition(new IndexOptions {
                End = new Position(2, 2)
            }).Should().Be(new Position(2, 2));
        }
示例#15
0
        public void sort_order_only_applied_for_btree_index(IndexMethod method, bool shouldUseSort)
        {
            theIndex.Method    = method;
            theIndex.SortOrder = SortOrder.Desc;

            var ddl = theIndex.ToDDL(parent);

            if (shouldUseSort)
            {
                ddl.ShouldEndWith(" DESC);");
            }
            else
            {
                ddl.ShouldNotEndWith(" DESC);");
            }
        }
示例#16
0
        private IEnumerable <MethodInfo> MakeFactories()
        {
            var knownMethods = IndexMethod.AsSingle().Concat(Formatters).Concat(Actions);
            var methods      = PaperType.GetMethods(BindingFlags.Public | BindingFlags.Instance).Except(knownMethods);

            foreach (var method in methods)
            {
                if (typeof(Sort).IsAssignableFrom(method.ReturnType) ||
                    typeof(Page).IsAssignableFrom(method.ReturnType) ||
                    typeof(IFilter).IsAssignableFrom(method.ReturnType))
                {
                    if (!method.GetParameters().Any())
                    {
                        yield return(method);
                    }
                }
            }
        }
        public void sort_order_only_applied_for_btree_index(IndexMethod method, bool shouldUseSort)
        {
            var definition = new IndexDefinition(mapping, "foo");

            definition.Method    = method;
            definition.SortOrder = SortOrder.Desc;

            var ddl = definition.ToDDL();

            if (shouldUseSort)
            {
                ddl.ShouldEndWith(" DESC);");
            }
            else
            {
                ddl.ShouldNotEndWith(" DESC);");
            }
        }
示例#18
0
        public void Upsert_Frames_From_Breaks()
        {
            var dbg = new DebugEngineProxyBuilder();
            var tt  = new TimeTravelFacadeBuilder(dbg);
            var sc  = new ServerClientBuilder();
            var bp  = new BreakpointFacadeBuilder();

            dbg.WithRunUntilBreak();
            var count = 0;

            dbg.SetRunUntilBreakCallback(() =>
            {
                if (count++ > 0)
                {
                    tt.AdvanceToNextPosition();
                }
            });
            var dbgEngProxy      = dbg.Build();
            var timeTravelFacade = tt.Build();
            var serverClient     = sc.Build();
            var bpFacade         = bp.Build();

            dbg.CurrentThreadId = MockFrames.SingleThreaded0.First().ThreadId;
            tt.WithFrames(MockFrames.SingleThreaded0);
            sc.WithUpsertFrames(() => { });

            var indexMethod = new IndexMethod
            {
                DebugEngineProxy = dbgEngProxy,
                TimeTravelFacade = timeTravelFacade,
                ServerClient     = serverClient,
                BreakpointFacade = bpFacade
            };

            indexMethod.ProcessInternal(new Position(0, 0), MockFrames.SingleThreaded0.Max(x => x.Position),
                                        new IndexOptions());
            sc.Mock.Verify(client =>
                           client.UpsertFrames(
                               It.Is <IEnumerable <Frame> >(frames => frames.SequenceEqual(MockFrames.SingleThreaded0))));
        }
示例#19
0
        public void Identify_32_And_64_Bit_Arch()
        {
            // Arrange
            var builder = new DebugEngineProxyBuilder();

            builder.WithExecuteResult("!peb", @"PEB at 00000000003b9000
    InheritedAddressSpace:    No
    ReadImageFileExecOptions: No
    BeingDebugged:            No
    ...
    ImageBaseAddress:         0000000140000000        _NT_SYMBOL_PATH=SRV*c:\symbols*http://msdl.microsoft.com/download/symbols");
            var proxy = builder.Build();

            // Act
            var indexMethod = new IndexMethod();

            indexMethod.DebugEngineProxy = builder.Build();
            var is32 = indexMethod.Is32Bit();

            // Assert
            is32.Should().BeFalse("00000000003b9000 is 16 characters and thus 64bit");
        }
示例#20
0
        public void Set_Breakpoints_If_They_Are_Provided_In_The_Options()
        {
            // arrange
            var indexMethod  = new IndexMethod();
            var indexOptions = new IndexOptions
            {
                AccessBreakpoints = new[]
                {
                    AccessBreakpoint.Parse("r8:100"),
                    AccessBreakpoint.Parse("w8:200"),
                    AccessBreakpoint.Parse("rw4:300")
                },
                BreakpointMasks = new[]
                {
                    BreakpointMask.Parse("kernel32!createprocess*"),
                    BreakpointMask.Parse("user32!*"),
                    BreakpointMask.Parse("mycustommod!myfancyfunction")
                }
            };
            var builder = new BreakpointFacadeBuilder();

            indexMethod.BreakpointFacade = builder.Build();

            // act
            indexMethod.SetBreakpoints(indexOptions);

            // assert
            builder.Mock.Verify(proxy => proxy.SetBreakpointByMask("kernel32", "createprocess*"), Times.Once);
            builder.Mock.Verify(proxy => proxy.SetBreakpointByMask("user32", "*"), Times.Once);
            builder.Mock.Verify(proxy => proxy.SetBreakpointByMask("mycustommod", "myfancyfunction"), Times.Once);

            builder.Mock.Verify(proxy => proxy.SetReadAccessBreakpoint(0x8, 0x100), Times.Once);
            builder.Mock.Verify(proxy => proxy.SetReadAccessBreakpoint(0x4, 0x300), Times.Once);
            builder.Mock.Verify(proxy => proxy.SetWriteAccessBreakpoint(0x8, 0x200), Times.Once);
            builder.Mock.Verify(proxy => proxy.SetWriteAccessBreakpoint(0x4, 0x300), Times.Once);
        }
示例#21
0
        public void Identify_Correct_Starting_Position()
        {
            // Arrange
            var options = new IndexOptions
            {
                Start = new Position(0x35, 0x1)
            };

            var dbg         = new DebugEngineProxyBuilder();
            var indexMethod = new IndexMethod();

            indexMethod.DebugEngineProxy = dbg.Build();
            var builder = new TimeTravelFacadeBuilder(dbg);

            builder.WithGetStartingPosition(new Position(0x35, 0));
            indexMethod.TimeTravelFacade = builder.Build();

            // Act
            var startingPosition = indexMethod.GetStartingPosition(options);

            // Assert
            startingPosition.Should().Be(new Position(0x35, 1),
                                         "35:1 means that the high portion is 35 and the low portion is 1");
        }