コード例 #1
0
        public void Validate()
        {
            if (InjectionDelay == 0)
            {
                logger.Warn("No delay specified before attempting to inject. The process could crash");
            }

            if (InjectLoopDelay == 0)
            {
                logger.Warn("No delay between injecting multiple DLLs. The process could crash");
            }

            if (ProcessId != null && (ProcessName != null || StartProcess != null))
            {
                Program.HandleError("--pid and --process/--start cannot be combined");
            }

            if (Quiet && Verbose)
            {
                Program.HandleError("--quiet and --verbose cannot be combined");
            }

            if (Interactive && NoPauseOnError)
            {
                Program.HandleError("--interactive and --no-pause-on-error cannot be combined");
            }

            if ((Dlls?.Count() ?? 0) == 0)
            {
                Program.HandleError("No DLLs to inject");
            }

            foreach (var dll in Dlls)
            {
                var dllInfo = GetDllInfo(dll);
                if (!File.Exists(dllInfo.FullName))
                {
                    Program.HandleError($"DLL not found: {dllInfo.FullName}");
                }
            }

            var existingWaitDlls = new List <string>();

            foreach (var dll in WaitDlls)
            {
                var dllInfo = GetDllInfo(dll);
                if (File.Exists(dllInfo.FullName))
                {
                    existingWaitDlls.Add(dll);
                }
                else
                {
                    logger.Warn($"Wait DLL not found: {dllInfo.FullName}");
                }
            }

            WaitDlls = existingWaitDlls;
        }
コード例 #2
0
        private long GetPowerInformationInt64Value(PowerInformationLevel level)
        {
            var outputBuffer = AllocateCoTaskBuffer <long>(out var outputBufferSize);

            try
            {
                // Result returned in count of 100 nanoseconds
                var returnCode = Dlls.CallNtPowerInformation(
                    15,
                    IntPtr.Zero,
                    0,
                    outputBuffer,
                    24);
                EnsureWin32CallSucceeded(returnCode);

                return(Marshal.ReadInt64(outputBuffer, 0));
            }
            finally
            {
                Marshal.FreeCoTaskMem(outputBuffer);
            }
        }