Exemplo n.º 1
0
    private static BasicSymbolStorage Generate(TextWriter writer)
    {
        NativeCodeAnalyzer analyzer = NativeCodeAnalyzerFactory.Create(OsVersion.WindowsVista);

        analyzer.IncludePathList.AddRange(NativeCodeAnalyzerFactory.GetCommonSdkPaths());

        // Run the preprocessor
        analyzer.Trace = true;
        string        winPath = Path.Combine(PInvoke.Parser.NativeCodeAnalyzerFactory.GetPlatformSdkIncludePath(), "windows.h");
        TextReaderBag tr      = analyzer.RunPreProcessor(winPath);

        File.WriteAllText("d:\\temp\\windows.out.h", tr.TextReader.ReadToEnd());
        analyzer.Trace = false;

        NativeCodeAnalyzerResult result = analyzer.Analyze(winPath);
        ErrorProvider            ep     = result.ErrorProvider;

        if (ep.Errors.Count > 0)
        {
            Debug.Fail("Encountered an error during the parse");
        }
        NativeSymbolBag bag = NativeSymbolBag.CreateFrom(result, CreateInitialBasicSymbolStorage(), ep);

        // Resolve with the full dll list
        using (ProcedureFinder finder = new ProcedureFinder(FullDllList))
        {
            bag.TryResolveSymbolsAndValues(finder, ep);
        }

        foreach (string msg in ep.AllMessages)
        {
            writer.WriteLine("' " + msg);
        }

        // GenerateCode(writer, bag)

        // Now write out the file
        var ns = new BasicSymbolStorage();

        bag.SaveToNativeStorage(ns);
        VerifyGeneratedStorage(ns);

        // TODO: need to write to file again otherwise it's just in memory.

        // Copy the file to the various applications
        File.Copy("windows.xml", "..\\..\\..\\ConsoleTool\\bin\\Debug\\windows.xml", true);
        File.Copy("windows.xml", "..\\..\\Data\\windows.xml", true);

        string fullInstallTarget = Path.Combine(Environment.GetEnvironmentVariable("ProgramFiles"), Path.Combine(PInvoke.Constants.ProductName, "Data\\windows.xml"));

        if (File.Exists(fullInstallTarget))
        {
            File.Copy("windows.xml", fullInstallTarget, true);
        }

        return(ns);
    }
Exemplo n.º 2
0
        public void Find2()
        {
            using (ProcedureFinder finder = new ProcedureFinder())
            {
                string name = null;

                Assert.False(finder.TryFindDllNameExact("DoesNotExistFunc", out name));
            }
        }
Exemplo n.º 3
0
        public void Find1()
        {
            using (ProcedureFinder finder = new ProcedureFinder())
            {
                string name = null;

                Assert.True(finder.TryFindDllNameExact("GetProcAddress", out name));
                Assert.Equal("kernel32.dll", name, true);
                Assert.True(finder.TryFindDllNameExact("SendMessageW", out name));
                Assert.Equal("user32.dll", name, true);
            }
        }
Exemplo n.º 4
0
        public void Find3()
        {
            using (ProcedureFinder finder = new ProcedureFinder())
            {
                string name = null;

                Assert.False(finder.TryFindDllNameExact("SendMessage", out name));
                Assert.True(finder.TryFindDllNameExact("SendMessageW", out name));
                Assert.Equal("user32.dll", name, true);
                Assert.True(finder.TryFindDllName("SendMessage", out name));
                Assert.Equal("user32.dll", name, true);
            }
        }