public DeviceParameter(String name, int parameterIndex, VariableKind representationKind, StorageFlags paramStorageFlags, int parameterSize, bool hasMinMax, VariableValue minValue, VariableValue maxValue, VariableValue defaultValue) { ParamName = name; ParamIndex = parameterIndex; ParamVarKind = representationKind; ParamStorageFlags = paramStorageFlags; ParamSize = parameterSize; IsDynamic = false; IsReadOnly = false; IsEEProm = false; DefaultValue = defaultValue; RamValue = null; EEPromValue = null; RequiresRefresh = true; HasChanged = true; HasRamValue = false; HasEEPromValue = false; HasDefaultValue = false; UpdateMinAndMax(hasMinMax, minValue, maxValue); }
public override byte[] Encode(G2Protocol protocol) { lock (protocol.WriteSection) { G2Frame folder = protocol.WritePacket(null, StoragePacket.Folder, null); protocol.WritePacket(folder, Packet_UID, BitConverter.GetBytes(UID)); protocol.WritePacket(folder, Packet_ParentUID, BitConverter.GetBytes(ParentUID)); protocol.WritePacket(folder, Packet_Name, UTF8Encoding.UTF8.GetBytes(Name)); protocol.WritePacket(folder, Packet_Date, BitConverter.GetBytes(Date.ToBinary())); StorageFlags netFlags = Flags & ~(StorageFlags.Modified | StorageFlags.Unlocked); protocol.WritePacket(folder, Packet_Flags, BitConverter.GetBytes((ushort)netFlags)); if (Note != null) { protocol.WritePacket(folder, Packet_Note, UTF8Encoding.UTF8.GetBytes(Note)); } protocol.WritePacket(folder, Packet_Revs, BitConverter.GetBytes(Revs)); protocol.WritePacket(folder, Packet_Integrated, BitConverter.GetBytes(IntegratedID)); byte[] scopefield = new byte[10]; foreach (ulong id in Scope.Keys) { BitConverter.GetBytes(id).CopyTo(scopefield, 0); BitConverter.GetBytes(Scope[id]).CopyTo(scopefield, 8); protocol.WritePacket(folder, Packet_Scope, scopefield); } return(protocol.WriteFinish()); } }
public Dictionary <StorageFlags, string> Parse(string[] args) { var flags = new Dictionary <StorageFlags, string>(); for (int argIndex = 0; argIndex < args.Length; argIndex++) { StorageFlags flag = GetFlag(args[argIndex]); if (flags.ContainsKey(flag)) { throw new ApplicationException($"Flag {flag} repeats."); } //checking that the next argument is a flag value, because not all flags need it var flagValue = string.Empty; if (((argIndex + 1) < args.Length) && (IsFlagValue(args[argIndex + 1]))) { flagValue = args[argIndex + 1]; argIndex++; } flags.Add(flag, flagValue); } return(flags); }
/// <summary> /// Constructor /// </summary> /// <param name="reader">PE file reader pointing to the start of this section</param> /// <param name="runtime">Runtime reader kind</param> /// <param name="verify">Verify section</param> /// <exception cref="BadImageFormatException">Thrown if verification fails</exception> public MetadataHeader(ref DataReader reader, CLRRuntimeReaderKind runtime, bool verify) { SetStartOffset(ref reader); signature = reader.ReadUInt32(); if (verify && signature != 0x424A5342) { throw new BadImageFormatException("Invalid metadata header signature"); } majorVersion = reader.ReadUInt16(); minorVersion = reader.ReadUInt16(); reserved1 = reader.ReadUInt32(); stringLength = reader.ReadUInt32(); versionString = ReadString(ref reader, stringLength, runtime); offset2ndPart = (FileOffset)reader.CurrentOffset; flags = (StorageFlags)reader.ReadByte(); reserved2 = reader.ReadByte(); streams = reader.ReadUInt16(); streamHeaders = new StreamHeader[streams]; for (int i = 0; i < streamHeaders.Count; i++) { // Mono doesn't verify all of these so we can't either var sh = new StreamHeader(ref reader, throwOnError: false, verify, runtime, out bool failedVerification); if (failedVerification || (ulong)sh.Offset + sh.StreamSize > reader.EndOffset) { sh = new StreamHeader(0, 0, "<invalid>"); } streamHeaders[i] = sh; } SetEndoffset(ref reader); }
private bool PutEx(StorageContext context, byte[] key, byte[] value, StorageFlags flags) { if (Trigger != TriggerType.Application && Trigger != TriggerType.ApplicationR) { return(false); } if (key.Length > 1024) { return(false); } if (context.IsReadOnly) { return(false); } if (!CheckStorageContext(context)) { return(false); } StorageKey skey = new StorageKey { ScriptHash = context.ScriptHash, Key = key }; StorageItem item = Snapshot.Storages.GetAndChange(skey, () => new StorageItem()); if (item.IsConstant) { return(false); } item.Value = value; item.IsConstant = flags.HasFlag(StorageFlags.Constant); return(true); }
/// <summary> /// Constructor /// </summary> /// <param name="reader">PE file reader pointing to the start of this section</param> /// <param name="verify">Verify section</param> /// <exception cref="BadImageFormatException">Thrown if verification fails</exception> public MetaDataHeader(IImageStream reader, bool verify) { SetStartOffset(reader); //Interaction.MsgBox(reader.Position); this.signature = reader.ReadUInt32(); if (verify && this.signature != 0x424A5342) { throw new BadImageFormatException("Invalid MetaData header signature"); } this.majorVersion = reader.ReadUInt16(); this.minorVersion = reader.ReadUInt16(); if (verify && !((majorVersion == 1 && minorVersion == 1) || (majorVersion == 0 && minorVersion >= 19))) { throw new BadImageFormatException(string.Format("Unknown MetaData header version: {0}.{1}", majorVersion, minorVersion)); } this.reserved1 = reader.ReadUInt32(); this.stringLength = reader.ReadUInt32(); this.versionString = ReadString(reader, stringLength); this.offset2ndPart = reader.FileOffset + reader.Position; this.flags = (StorageFlags)reader.ReadByte(); this.reserved2 = reader.ReadByte(); this.streams = reader.ReadUInt16(); this.streamHeaders = new StreamHeader[streams]; for (int i = 0; i < streamHeaders.Count; i++) { streamHeaders[i] = new StreamHeader(reader, verify); } SetEndoffset(reader); }
/// <summary> /// Initializes a new instance of the <see cref="FileStorage"/> class and prepares the /// file storage for reading or writing data. /// </summary> /// <param name="fileName">Name of the file associated with the storage.</param> /// <param name="storage"> /// Memory storage used for temporary data and for storing dynamic structures, such as /// <see cref="Seq"/> or <see cref="Graph"/>. If it is <b>null</b>, a temporary memory /// storage is created and used. /// </param> /// <param name="flags">Specifies operation flags associated with the new file storage.</param> /// <param name="encoding"> /// Encoding of the file. Note that UTF-16 XML encoding is not supported currently and you /// should use 8-bit encoding instead. /// </param> public FileStorage(string fileName, MemStorage storage, StorageFlags flags, string encoding = null) : base(true) { var pStorage = NativeMethods.cvOpenFileStorage(fileName, storage ?? MemStorage.Null, flags, encoding); SetHandle(pStorage); owner = storage; }
protected bool Storage_PutEx(ExecutionEngine engine) { if (!(engine.CurrentContext.EvaluationStack.Pop() is InteropInterface _interface)) { return(false); } StorageContext context = _interface.GetInterface <StorageContext>(); byte[] key = engine.CurrentContext.EvaluationStack.Pop().GetByteArray(); byte[] value = engine.CurrentContext.EvaluationStack.Pop().GetByteArray(); StorageFlags flags = (StorageFlags)(byte)engine.CurrentContext.EvaluationStack.Pop().GetBigInteger(); return(PutEx(context, key, value, flags)); }
private static IStorage CreateIStorageOnHGlobal() { var bytes = NativeMethods.CreateILockBytesOnHGlobal(IntPtr.Zero, true); try { const StorageFlags CreateRWExclusive = StorageFlags.Create | StorageFlags.ReadWrite | StorageFlags.ShareExclusive; return(NativeMethods.StgCreateDocfileOnILockBytes(bytes, CreateRWExclusive, 0)); } finally { Marshal.ReleaseComObject(bytes); } }
private void PutExInternal(StorageContext context, byte[] key, byte[] value, StorageFlags flags) { if (key.Length > MaxStorageKeySize || value.Length > MaxStorageValueSize || context.IsReadOnly) { throw new ArgumentException(); } int newDataSize; StorageKey skey = new StorageKey { Id = context.Id, Key = key }; StorageItem item = Snapshot.Storages.GetAndChange(skey); if (item is null) { newDataSize = key.Length + value.Length; Snapshot.Storages.Add(skey, item = new StorageItem()); } else { if (item.IsConstant) { throw new InvalidOperationException(); } if (value.Length == 0) { newDataSize = 1; } else if (value.Length <= item.Value.Length) { newDataSize = (value.Length - 1) / 4 + 1; } else { newDataSize = (item.Value.Length - 1) / 4 + 1 + value.Length - item.Value.Length; } } AddGas(newDataSize * StoragePrice); item.Value = value; item.IsConstant = flags.HasFlag(StorageFlags.Constant); }
private bool PutEx(TestStorageContext context, byte[] key, byte[] value, StorageFlags flags) { if (key.Length > MaxStorageKeySize) { return(false); } if (value.Length > MaxStorageValueSize) { return(false); } if (context.IsReadOnly) { return(false); } StorageKey skey = new StorageKey { ScriptHash = context.ScriptHash, Key = key }; if (Storages.TryGetValue(skey, out var item) && item.IsConstant == true) { return(false); } if (value.Length == 0 && !flags.HasFlag(StorageFlags.Constant)) { // If put 'value' is empty (and non-const), we remove it (implicit `Storage.Delete`) Storages.Remove(skey); } else { item = Storages[skey] = new StorageItem(); item.Value = value; item.IsConstant = flags.HasFlag(StorageFlags.Constant); } return(true); }
public override byte[] Encode(G2Protocol protocol) { lock (protocol.WriteSection) { G2Frame file = protocol.WritePacket(null, StoragePacket.File, null); protocol.WritePacket(file, Packet_UID, BitConverter.GetBytes(UID)); protocol.WritePacket(file, Packet_Name, UTF8Encoding.UTF8.GetBytes(Name)); protocol.WritePacket(file, Packet_Date, BitConverter.GetBytes(Date.ToBinary())); StorageFlags netFlags = Flags & ~(StorageFlags.Unlocked); // allow modified for working protocol.WritePacket(file, Packet_Flags, BitConverter.GetBytes((ushort)netFlags)); protocol.WritePacket(file, Packet_Revs, BitConverter.GetBytes(Revs)); protocol.WritePacket(file, Packet_Integrated, BitConverter.GetBytes(IntegratedID)); protocol.WritePacket(file, Packet_Size, CompactNum.GetBytes(Size)); protocol.WritePacket(file, Packet_Hash, Hash); protocol.WritePacket(file, Packet_FileKey, FileKey); protocol.WritePacket(file, Packet_InternalSize, CompactNum.GetBytes(InternalSize)); protocol.WritePacket(file, Packet_InternalHash, InternalHash); byte[] scopefield = new byte[10]; foreach (ulong id in Scope.Keys) { BitConverter.GetBytes(id).CopyTo(scopefield, 0); BitConverter.GetBytes(Scope[id]).CopyTo(scopefield, 8); protocol.WritePacket(file, Packet_Scope, scopefield); } if (Note != null) { protocol.WritePacket(file, Packet_Note, UTF8Encoding.UTF8.GetBytes(Note)); } return(protocol.WriteFinish()); } }
public void RemoveFlag(StorageFlags remove) { Flags = Flags & ~remove; }
private static bool PutEx(ApplicationEngine engine, StorageContext context, byte[] key, byte[] value, StorageFlags flags) { if (engine.Trigger != TriggerType.Application) { return(false); } if (key.Length > MaxStorageKeySize) { return(false); } if (value.Length > MaxStorageValueSize) { return(false); } if (context.IsReadOnly) { return(false); } if (!CheckStorageContext(engine, context)) { return(false); } StorageKey skey = new StorageKey { ScriptHash = context.ScriptHash, Key = key }; StorageItem item = engine.Snapshot.Storages.GetAndChange(skey, () => new StorageItem()); if (item.IsConstant) { return(false); } item.Value = value; item.IsConstant = flags.HasFlag(StorageFlags.Constant); return(true); }
// Update a field in a table entry. Create new entry if necessary. // Returns null on success, otherwise error message. public string PutField(string parameterNameOrIndex, string fieldNameOrId, object value) { string result = null; if (!String.IsNullOrWhiteSpace(parameterNameOrIndex) && value != null) { DeviceParameter d = Find(parameterNameOrIndex); bool isNew = (d == null); if (isNew) { d = new DeviceParameter(parameterNameOrIndex); } switch (DeviceParameter.GetFieldId(fieldNameOrId)) { case DeviceParameter.FieldId.IndexField: try { int v = (int)value; if (v >= 0) { if (!isNew && d.ParamIndex >= 0) { IndexTable.Remove(d.ParamIndex); } d.ParamIndex = v; isNew = true; } else { result = "Error: negative index."; } } catch (Exception) { result = "Error: invalid index type."; } break; case DeviceParameter.FieldId.CategoryField: try { int v = (int)value; if (v >= 0) { d.ParamCategory = v; } else { result = "Error: negative category."; } } catch (Exception) { result = "Error: invalid category type."; } break; case DeviceParameter.FieldId.VariableKindField: try { VariableKind v = VariableValue.StringToVK(value.ToString()); d.ParamVarKind = v; if (v == VariableKind.VK_None) { result = "Error: bad representation kind."; } } catch (Exception) { result = "Error: invalid representation kind type."; } break; case DeviceParameter.FieldId.SizeField: try { int v = (int)value; if (v >= 0) { d.ParamSize = v; } else { d.ParamSize = VariableValue.DataSize(d.ParamVarKind); } } catch (Exception) { result = "Error: invalid size value."; } break; case DeviceParameter.FieldId.StorageFlagsField: try { StorageFlags v = VariableValue.StringToSF(value.ToString()); d.ParamStorageFlags = v; if (v == StorageFlags.SF_None) { result = "Error: bad storage flags."; } } catch (Exception) { result = "Error: invalid storage flags type."; } break; case DeviceParameter.FieldId.MinValueField: try { d.MinValue = new VariableValue(d.ParamVarKind, value.ToString()); } catch (Exception) { result = "Error: invalid min value type."; } break; case DeviceParameter.FieldId.MaxValueField: try { d.MaxValue = new VariableValue(d.ParamVarKind, value.ToString()); } catch (Exception) { result = "Error: invalid max value type."; } break; case DeviceParameter.FieldId.DefaultValueField: try { d.DefaultValue = new VariableValue(d.ParamVarKind, value.ToString()); } catch (Exception) { result = "Error: invalid default value type."; } break; case DeviceParameter.FieldId.RamValueField: try { d.RamValue = new VariableValue(d.ParamVarKind, value.ToString()); } catch (Exception) { result = "Error: invalid ram value type."; } break; case DeviceParameter.FieldId.EepromValueField: try { d.EEPromValue = new VariableValue(d.ParamVarKind, value.ToString()); } catch (Exception) { result = "Error: invalid Eeprom value type."; } break; case DeviceParameter.FieldId.NameField: try { string s = value.ToString().Trim().ToLower(); if (!isNew && !String.IsNullOrWhiteSpace(d.ParamName)) { NameTable.Remove(d.ParamName); } d.ParamName = s; isNew = true; } catch (Exception) { result = "Error: invalid index type."; } break; default: result = "Error: invalid field name or Id."; break; } if (isNew && result == null) { Add(d); } } return(result); }
internal static extern IStorage StgCreateDocfileOnILockBytes( [In] ILockBytes plkbyt, [In] StorageFlags grfMode, [In] UInt32 reserved);
public static extern void PutEx(string key, string value, StorageFlags flags);
public bool IsFlagged(StorageFlags test) { return ((Flags & test) != 0); }
protected internal void PutEx(StorageContext context, byte[] key, byte[] value, StorageFlags flags) { PutExInternal(context, key, value, flags); }
private static bool PutEx(ApplicationEngine engine, StorageContext context, byte[] key, byte[] value, StorageFlags flags) { if (engine.Trigger != TriggerType.Application) { return(false); } if (key.Length > MaxStorageKeySize) { return(false); } if (value.Length > MaxStorageValueSize) { return(false); } if (context.IsReadOnly) { return(false); } if (!CheckStorageContext(engine, context)) { return(false); } StorageKey skey = new StorageKey { ScriptHash = context.ScriptHash, Key = key }; if (engine.Snapshot.Storages.TryGet(skey)?.IsConstant == true) { return(false); } if (value.Length == 0 && !flags.HasFlag(StorageFlags.Constant)) { // If put 'value' is empty (and non-const), we remove it (implicit `Storage.Delete`) engine.Snapshot.Storages.Delete(skey); } else { StorageItem item = engine.Snapshot.Storages.GetAndChange(skey, () => new StorageItem()); item.Value = value; item.IsConstant = flags.HasFlag(StorageFlags.Constant); } return(true); }
public static extern void PutEx(byte[] key, byte[] value, StorageFlags flags);
public static extern void PutEx(byte[] key, BigInteger value, StorageFlags flags);
internal static extern IntPtr cvOpenFileStorage(string filename, MemStorage memstorage, StorageFlags flags, string encoding);
/// <summary> /// Constructor /// </summary> /// <param name="reader">PE file reader pointing to the start of this section</param> /// <param name="verify">Verify section</param> /// <exception cref="BadImageFormatException">Thrown if verification fails</exception> public MetaDataHeader(IImageStream reader, bool verify) { SetStartOffset(reader); this.signature = reader.ReadUInt32(); if (verify && this.signature != 0x424A5342) throw new BadImageFormatException("Invalid MetaData header signature"); this.majorVersion = reader.ReadUInt16(); this.minorVersion = reader.ReadUInt16(); if (verify && !((majorVersion == 1 && minorVersion == 1) || (majorVersion == 0 && minorVersion >= 19))) throw new BadImageFormatException(string.Format("Unknown MetaData header version: {0}.{1}", majorVersion, minorVersion)); this.reserved1 = reader.ReadUInt32(); this.stringLength = reader.ReadUInt32(); this.versionString = ReadString(reader, stringLength); this.offset2ndPart = (uint)(reader.Position - startOffset); this.flags = (StorageFlags)reader.ReadByte(); if (verify && this.flags != 0) throw new BadImageFormatException(string.Format("Storage flags != 0 ({0})", this.flags)); this.reserved2 = reader.ReadByte(); this.streams = reader.ReadUInt16(); this.streamHeaders = new StreamHeader[streams]; for (int i = 0; i < streamHeaders.Count; i++) streamHeaders[i] = new StreamHeader(reader, verify); SetEndoffset(reader); }
public bool IsFlagged(StorageFlags test) { return((Flags & test) != 0); }
public void SetFlag(StorageFlags set) { Flags = Flags | set; }
public static extern void PutEx(string key, BigInteger value, StorageFlags flags);