public InternalVariableDesc(ref FsuipcVariable variable) { var vc = new VariableConverter(); Variable = variable; Buffer = new byte[vc.ConvertSize(variable.GetVariableSize())]; }
public void CustomConverter_CanDeserializeWithVariables() { var variables = new Dictionary <string, object>() { { "$x", 1 }, { "$radius", 2.0 }, { "$color", "test" }, { "$smooth", true } }; var converter = new VariableConverter(variables); var json = @"{ ""Position"": { ""X"": ""$x"", ""Y"": 0 }, ""Color"": ""$color"", ""Radius"": ""$radius"" }"; var obj = JsonConvert.DeserializeObject <CircleShape>(json, converter); Assert.AreEqual(1, obj.Position.X); Assert.AreEqual("test", obj.Color); Assert.AreEqual(2, obj.Radius); }
public void ListParsingTest(string json, int varCount) { var js = new VariableConverter(new FileArgsBase(), Mock.Of <ILogger>()); var vars = js.Convert(json); vars.Count.Should().Be(varCount); }
protected internal override XmlFormulaTree ToXmlObject2() { var xmlVariableConverter = new VariableConverter <GlobalVariable>(); var xmlVariable = xmlVariableConverter.Convert(Variable, null); return(XmlFormulaTreeFactory.CreateGlobalVariableNode(xmlVariable)); }
public UploadLibraryCommand(LibraryTargetArgs args, ISecretsMananger secretsMananger, ILibraryManager libraryMananger, VariableConverter variableConverter, ILogger logger, IFileSystem fileSystem) { _args = args ?? throw new ArgumentNullException(nameof(args)); _secretsMananger = secretsMananger ?? throw new ArgumentNullException(nameof(secretsMananger)); _libraryManager = libraryMananger ?? throw new ArgumentNullException(nameof(libraryMananger)); _varConverter = variableConverter ?? throw new ArgumentNullException(nameof(variableConverter)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem)); }
public ValidateTenantCommand(ValidateTenantArgs args, ISecretsMananger secretsMananger, ITenantManager tenantManager, VariableConverter jsonValidator, IFileSystem fileSystem, ILogger logger) { _args = args ?? throw new ArgumentNullException(nameof(args)); _secretsMananger = secretsMananger ?? throw new ArgumentNullException(nameof(secretsMananger)); _tenantManager = tenantManager ?? throw new ArgumentNullException(nameof(tenantManager)); _jsonValidator = jsonValidator ?? throw new ArgumentNullException(nameof(jsonValidator)); _fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public void BasicJsonTest() { var js = new VariableConverter(new JsonReplacementArgs() { MergeArrays = false, VariableType = VariableType.JsonConversion }, Mock.Of <ILogger>()); var vars = js.Convert("{\"a\":\"b\"}"); vars.Single().Name.Should().Be("a"); }
public bool AddVariableToRead(FsuipcVariable variable) { var varConverter = new VariableConverter(); var convertedVariableSize = varConverter.ConvertSize(variable.GetVariableSize()); _fsuipcVariablesForRead[variable.Id] = new InternalVariableDesc(ref variable); return(_fsuipc.FSUIPC_Read(variable.Offset, convertedVariableSize, ref _fsuipcVariablesForRead[variable.Id].Token, ref _dwResult)); // что делать с dwResult. Куда-то возвращать? }
public void InvalidJsonThrowsSerialException(string json) { var js = new VariableConverter(new FileArgsBase() { MergeArrays = true }, Mock.Of <ILogger>()); Action flattenAct = () => js.Convert(json); flattenAct.Should().Throw <Newtonsoft.Json.JsonSerializationException>(); }
public void FlattenArraysTest(string json, int varCount) { var js = new VariableConverter(new FileArgsBase() { MergeArrays = true }, Mock.Of <ILogger>()); var vars = js.Convert(json); vars.Count.Should().Be(varCount); }
public void ColonSeparatorTest(string json, string expectedName, string expectedValue) { var js = new VariableConverter(new JsonReplacementArgs() { MergeArrays = false, VariableType = VariableType.JsonConversion }, Mock.Of <ILogger>()); var vars = js.Convert(json); vars.Single().Name.Should().Be(expectedName); vars.Single().Value.Should().Be(expectedValue); }
public UploadTenantCommand(UploadTenantArgs args, ISecretsMananger secretsMananger, IProjectManager projectManager, ITenantManager tenantManager, VariableConverter variableConverter, IFileSystem fileSystem, ILogger logger) { _args = args ?? throw new ArgumentNullException(nameof(args)); _secretsMananger = secretsMananger ?? throw new ArgumentNullException(nameof(secretsMananger)); _varConverter = variableConverter ?? throw new ArgumentNullException(nameof(variableConverter)); _projectManager = projectManager ?? throw new ArgumentNullException(nameof(projectManager)); _tenantManager = tenantManager ?? throw new ArgumentNullException(nameof(tenantManager)); _fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public void ArrayFlattenTest(string json, string prefix, string expectedName) { var args = new FileArgsBase() { Prefix = prefix, MergeArrays = true }; var js = new VariableConverter(args, Mock.Of <ILogger>()); var vars = js.Convert(json); vars.Single().Name.Should().Be(expectedName); }
public void PrefixUnderscoreSeparatorTest(string json, string prefix, string expectedName) { var args = new FileArgsBase() { Prefix = prefix, MergeArrays = false, VariableType = VariableType.Environment }; var js = new VariableConverter(args, Mock.Of <ILogger>()); var vars = js.Convert(json); vars.Single().Name.Should().Be(expectedName); }
public void BasicEnviroTest() { var args = new FileArgsBase() { Prefix = "", MergeArrays = false, VariableType = VariableType.Environment }; var js = new VariableConverter(args, Mock.Of <ILogger>()); var vars = js.Convert("{\"a\":\"b\"}"); vars.Single().Name.Should().Be("a"); }
/// <summary> /// Получить значение переменной в памяти /// </summary> /// <param name="moduleName">Имя модуля, где находится переменная</param> /// <param name="moduleOffset">Относительное смещение от начала модуля</param> /// <param name="variableSize">Размер переменной</param> /// <returns>Результат получения значения переменной</returns> public ManageMemoryVariableResult GetVariableValue(string moduleName, uint moduleOffset, MemoryVariableSize variableSize) { lock (_modules) { if (!_modules.ContainsKey(moduleName)) { return(new ManageMemoryVariableResult { Code = MemoryPatchVariableErrorCode.ModuleNotFound, ErrorMessage = moduleName }); } if ((int)_modules[moduleName].BaseAddress + _modules[moduleName].Size < moduleOffset) { return(new ManageMemoryVariableResult { Code = MemoryPatchVariableErrorCode.OffsetIsOutOfModule }); } try { var baseOffset = (IntPtr)((int)_modules[moduleName].BaseAddress + moduleOffset); var varConverter = new VariableConverter(); var buffer = new byte[varConverter.ConvertSize(variableSize)]; uint bytesRead = 0; var readResult = ReadProcessMemory(_processHandle, baseOffset, buffer, (uint)buffer.Length, ref bytesRead); if (!readResult) { return(new ManageMemoryVariableResult { Code = MemoryPatchVariableErrorCode.ReadError, Value = 0 }); } var result = varConverter.ArrayToValue(buffer, variableSize); return(new ManageMemoryVariableResult { Code = MemoryPatchVariableErrorCode.Ok, Value = result }); } catch (Exception ex) { return(new ManageMemoryVariableResult { Code = MemoryPatchVariableErrorCode.Unknown, ErrorMessage = ex.Message }); } } }
public bool AddVariableToWrite(FsuipcVariable variable) { var varConverter = new VariableConverter(); var convertedVariableSize = varConverter.ConvertSize(variable.GetVariableSize()); _fsuipcVariablesForWrite[variable.Id] = new InternalVariableDesc(ref variable); _fsuipcVariablesForWrite[variable.Id].Buffer = varConverter.ValueToArray((double)variable.GetValueToSet(), variable.GetVariableSize()); var result = _fsuipc.FSUIPC_Write(variable.Offset, convertedVariableSize, ref _fsuipcVariablesForWrite[variable.Id].Buffer, ref _fsuipcVariablesForWrite[variable.Id].Token, ref _dwResult); return(result); // что делать с dwResult. Куда-то возвращать? }
public void GlobShouldBeSecret(string json, IFixture fixture) { var args = fixture.Build <FileArgsBase>() .With(a => a.Prefix, "") .With(a => a.MergeArrays, false) .With(a => a.VariableType, VariableType.EnvironmentGlob) .Create(); var js = new VariableConverter(args, Mock.Of <ILogger>()); var vars = js.Convert(json); vars.Single().IsSecret.Should().BeTrue(); }
public void GlobValuesShouldConcat(string json, string expectedValue, IFixture fixture) { var args = fixture.Build <FileArgsBase>() .With(a => a.Prefix, "") .With(a => a.MergeArrays, false) .With(a => a.VariableType, VariableType.EnvironmentGlob) .Create(); var js = new VariableConverter(args, Mock.Of <ILogger>()); var vars = js.Convert(json); vars.Single().Value.Should().Be(expectedValue); }
public void Process() { var res = _fsuipc.FSUIPC_Process(ref _dwResult); foreach (var variable in _fsuipcVariablesForRead) { var varConverter = new VariableConverter(); var convertedVariableSize = varConverter.ConvertSize(variable.Value.Variable.GetVariableSize()); _fsuipc.FSUIPC_Get(ref variable.Value.Token, convertedVariableSize, ref variable.Value.Buffer); variable.Value.Variable.SetValueInMemory(varConverter.ArrayToValue(variable.Value.Buffer, variable.Value.Variable.GetVariableSize())); } }
public void FlattenArrayPrefixTest(string prefix, string json) { var js = new VariableConverter(new FileArgsBase() { Prefix = prefix, MergeArrays = true }, Mock.Of <ILogger>()); var vars = js.Convert(json); foreach (var expected in vars) { expected.Name.StartsWith(prefix).Should().Be(true, $"Expected variable name to start with {prefix} but was {expected.Name}"); } }
/// <summary> /// Установить значение переменной в памяти /// </summary> /// <param name="moduleName">Имя модуля, где находится переменная</param> /// <param name="moduleOffset">Относительное смещение от начала модуля</param> /// <param name="variableSize">Размер переменной</param> /// <param name="valueToSet">Значение, которое требуется установить</param> /// <returns>Результат установки значения переменной</returns> public ManageMemoryVariableResult SetVariableValue(string moduleName, uint moduleOffset, MemoryVariableSize variableSize, double valueToSet) { lock (_modules) { if (!_modules.ContainsKey(moduleName)) { return new ManageMemoryVariableResult { Code = MemoryPatchVariableErrorCode.ModuleNotFound, ErrorMessage = moduleName } } ; if ((int)_modules[moduleName].BaseAddress + _modules[moduleName].Size < moduleOffset) { return new ManageMemoryVariableResult { Code = MemoryPatchVariableErrorCode.OffsetIsOutOfModule } } ; try { var baseOffset = (IntPtr)((int)_modules[moduleName].BaseAddress + moduleOffset); var varConverter = new VariableConverter(); var buffer = varConverter.ValueToArray(valueToSet, variableSize); uint bytesWrite = 0; var res = WriteProcessMemory(_processHandle, baseOffset, buffer, (uint)buffer.Length, ref bytesWrite); return(new ManageMemoryVariableResult { Code = res ? MemoryPatchVariableErrorCode.Ok : MemoryPatchVariableErrorCode.WriteError, Value = valueToSet }); } catch (Exception ex) { return(new ManageMemoryVariableResult { Code = MemoryPatchVariableErrorCode.Unknown, ErrorMessage = ex.Message }); } } }
protected internal override XmlFormulaTree ToXmlObject2() { var xmlVariableConverter = new VariableConverter<GlobalVariable>(); var xmlVariable = xmlVariableConverter.Convert(Variable, null); return XmlFormulaTreeFactory.CreateGlobalVariableNode(xmlVariable); }