public static List <LogInfo> RegWrite(EngineState s, CodeCommand cmd) { // RegWrite,<HKey>,<ValueType>,<KeyPath>,<ValueName>,<ValueData>,[OptionalData] List <LogInfo> logs = new List <LogInfo>(); CodeInfo_RegWrite info = cmd.Info.Cast <CodeInfo_RegWrite>(); string keyPath = StringEscaper.Preprocess(s, info.KeyPath); string valueName = null; if (info.ValueName != null) { valueName = StringEscaper.Preprocess(s, info.ValueName); } if (info.HKey == null) { throw new InternalException("Internal Logic Error"); } string hKeyStr = RegistryHelper.RegKeyToString(info.HKey); string fullKeyPath = $"{hKeyStr}\\{keyPath}"; string fullValuePath = $"{hKeyStr}\\{keyPath}\\{valueName}"; (byte[] BinData, string ValueData) ParseByteArrayFromString() { if (info.ValueData == null) { // Use info.ValueDataList string[] binStrs = StringEscaper.Preprocess(s, info.ValueDataList).ToArray(); string valueData = StringEscaper.PackRegBinary(binStrs); if (!StringEscaper.UnpackRegBinary(binStrs, out byte[] binData))
public void UnpackRegBinary_1() { string src = "43,00,3A,00,5C,00"; Assert.IsTrue(StringEscaper.UnpackRegBinary(src, out byte[] dest)); byte[] comp = new byte[] { 0x43, 0x00, 0x3A, 0x00, 0x5C, 0x00 }; for (int i = 0; i < dest.Length; i++) { Assert.IsTrue(dest[i] == comp[i]); } }
public static List <LogInfo> RegWrite(EngineState s, CodeCommand cmd) { // RegWrite,<HKey>,<ValueType>,<KeyPath>,<ValueName>,<ValueData>,[OptionalData] List <LogInfo> logs = new List <LogInfo>(); CodeInfo_RegWrite info = cmd.Info.Cast <CodeInfo_RegWrite>(); string keyPath = StringEscaper.Preprocess(s, info.KeyPath); string valueName = null; if (info.ValueName != null) { valueName = StringEscaper.Preprocess(s, info.ValueName); } if (info.HKey == null) { throw new InternalException("Internal Logic Error"); } string hKeyStr = RegistryHelper.RegKeyToString(info.HKey); string fullKeyPath = $"{hKeyStr}\\{keyPath}"; string fullValuePath = $"{hKeyStr}\\{keyPath}\\{valueName}"; using (RegistryKey subKey = info.HKey.CreateSubKey(keyPath, true)) { if (valueName == null) { logs.Add(new LogInfo(LogState.Success, $"Registry subkey [{fullKeyPath}] created")); return(logs); } object checkData = subKey.GetValue(valueName); if (checkData != null) { logs.Add(new LogInfo(info.NoWarn ? LogState.Ignore : LogState.Overwrite, $"Registry value [{fullValuePath}] already exists")); } switch (info.ValueType) { case RegistryValueKind.None: { subKey.SetValue(valueName, new byte[0], RegistryValueKind.None); logs.Add(new LogInfo(LogState.Success, $"Registry value [{fullValuePath}] set to REG_NONE")); } break; case RegistryValueKind.String: { string valueData = StringEscaper.Preprocess(s, info.ValueData); subKey.SetValue(valueName, valueData, RegistryValueKind.String); logs.Add(new LogInfo(LogState.Success, $"Registry value [{fullValuePath}] set to REG_SZ [{valueData}]")); } break; case RegistryValueKind.ExpandString: { string valueData = StringEscaper.Preprocess(s, info.ValueData); subKey.SetValue(valueName, valueData, RegistryValueKind.ExpandString); logs.Add(new LogInfo(LogState.Success, $"Registry value [{fullValuePath}] set to REG_EXPAND_SZ [{valueData}]")); } break; case RegistryValueKind.MultiString: { string[] multiStrs = StringEscaper.Preprocess(s, info.ValueDatas).ToArray(); subKey.SetValue(valueName, multiStrs, RegistryValueKind.MultiString); string valueData = StringEscaper.PackRegMultiBinary(multiStrs); logs.Add(new LogInfo(LogState.Success, $"Registry value [{fullValuePath}] set to REG_MULTI_SZ [{valueData}]")); } break; case RegistryValueKind.Binary: { if (info.ValueData == null) { // Use info.ValueDatas string[] binStrs = StringEscaper.Preprocess(s, info.ValueDatas).ToArray(); string valueData = StringEscaper.PackRegBinary(binStrs); if (!StringEscaper.UnpackRegBinary(binStrs, out byte[] binData))