示例#1
0
        public static List <LogInfo> RegHiveLoad(EngineState s, CodeCommand cmd)
        {
            List <LogInfo> logs = new List <LogInfo>();

            CodeInfo_RegHiveLoad info = cmd.Info.Cast <CodeInfo_RegHiveLoad>();

            string keyPath  = StringEscaper.Preprocess(s, info.KeyPath);
            string hiveFile = StringEscaper.Preprocess(s, info.HiveFile);

            if (!File.Exists(hiveFile))
            {
                logs.Add(new LogInfo(LogState.Info, $"Hive file [{hiveFile}] does not exist and will be created."));
            }

            if (!_privilegesEnabled)
            {
                RegistryHelper.GetAdminPrivileges();
                _privilegesEnabled = true;
            }

            int result = RegistryHelper.RegLoadKey(Registry.LocalMachine.Handle, keyPath, hiveFile);

            if (result == (int)BetterWin32Errors.Win32Error.ERROR_SUCCESS)
            {
                logs.Add(new LogInfo(LogState.Success, $"Loaded [{hiveFile}] into [HKLM\\{keyPath}]"));
            }
            else
            {
                string errorMessage = new Win32Exception(result).Message;
                logs.Add(new LogInfo(LogState.Error, $"Could not load [{hiveFile}] into [HKLM\\{keyPath}], error code = [{result} - {errorMessage}]"));
            }
            return(logs);
        }
示例#2
0
        public static List <LogInfo> RegHiveLoad(EngineState s, CodeCommand cmd)
        {
            List <LogInfo> logs = new List <LogInfo>();

            Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_RegHiveLoad));
            CodeInfo_RegHiveLoad info = cmd.Info as CodeInfo_RegHiveLoad;

            string keyPath  = StringEscaper.Preprocess(s, info.KeyPath);
            string hiveFile = StringEscaper.Preprocess(s, info.HiveFile);

            if (!File.Exists(hiveFile))
            {
                throw new ExecuteException($"Hive file [{hiveFile}] does not exist");
            }

            if (!privilegesEnabled)
            {
                RegistryHelper.GetAdminPrivileges();
                privilegesEnabled = true;
            }

            int result = RegistryHelper.RegLoadKey(Registry.LocalMachine.Handle, keyPath, hiveFile);

            if (result == (int)BetterWin32Errors.Win32Error.ERROR_SUCCESS)
            {
                logs.Add(new LogInfo(LogState.Success, $"Loaded [{hiveFile}] into [HKLM\\{keyPath}]"));
            }
            else
            {
                logs.Add(new LogInfo(LogState.Success, $"Could not load [{hiveFile}] into [HKLM\\{keyPath}], error code = [{result}]"));
            }

            return(logs);
        }