Esempio n. 1
0
        public HashVerifySetup()
        {
            // Combine the path to the class .dll with the relative path to the test vectors
            PATH_PREFIX = Path.Combine(
                Path.GetDirectoryName(
                    Uri.UnescapeDataString(
                        new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).AbsolutePath
                        )
                    ),
                RELATIVE_PATH_PREFIX
                );

            Process proc = Process.GetCurrentProcess();

            app = Application.Attach(proc);

            // Workaround required when debugging unit tests in the VS GUI -
            // for some reason the first time this is called the DLL loads but HashVerify doesn't start
            if (Debugger.IsAttached && proc.MainModule.ModuleName.StartsWith("vstest.executionengine."))
            {
                Process.Start(Path.Combine(PATH_PREFIX, "SHA3_256ShortMsg.rsp.sha3-256"));
            }
        }
Esempio n. 2
0
        //
        Window OpenHashPropWindow(string filename)
        {
            // Combine the path to the class .dll with the relative path to the test vectors
            if (PATH_PREFIX == null)
            {
                PATH_PREFIX = Path.Combine(
                    Path.GetDirectoryName(
                        Uri.UnescapeDataString(
                            new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).AbsolutePath
                            )
                        ),
                    RELATIVE_PATH_PREFIX
                    );
            }

            // Open the Checksums tab in the shell file properties sheet
            SHELLEXECUTEINFO sei = new SHELLEXECUTEINFO();

            sei.cbSize       = (uint)System.Runtime.InteropServices.Marshal.SizeOf(sei);
            sei.fMask        = 0x0000010C; // SEE_MASK_INVOKEIDLIST | SEE_MASK_NOASYNC
            sei.lpVerb       = "Properties";
            sei.lpFile       = Path.Combine(PATH_PREFIX, filename);
            sei.lpParameters = "Checksums";
            sei.nShow        = 1;    // SW_SHOWNORMAL
            ShellExecuteExW(ref sei);

            // Find the file properties sheet window
            Window prop_window = null;

            // Prior to Windows 10, the file properties sheet opens in the curent process
            int orig_timeout = CoreAppXmlConfiguration.Instance.FindWindowTimeout;

            if ((int)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentMajorVersionNumber", 0) >= 10)
            {
                CoreAppXmlConfiguration.Instance.FindWindowTimeout = 1500;  // likely to fail on Windows 10+, so use a short timeout (1.5s) in that case
            }
            if (!is_com_surrogate)
            {
                Application app = Application.Attach(Process.GetCurrentProcess());
                try
                {
                    prop_window      = app.GetWindow(filename + " Properties");
                    is_com_surrogate = false;
                }
                catch (AutomationException) { }
            }

            // Starting with Windows 10, the file properties sheet is hosted in a dllhost COM surrogate
            if (prop_window == null)
            {
                foreach (Process proc in Process.GetProcessesByName("dllhost"))
                {
                    Application app = Application.Attach(proc);
                    try
                    {
                        prop_window = app.GetWindow(filename + " Properties");
                        break;
                    }
                    catch (AutomationException) { }
                }
                Assert.NotNull(prop_window);
                is_com_surrogate = true;
            }
            CoreAppXmlConfiguration.Instance.FindWindowTimeout = orig_timeout;

            return(prop_window);
        }