public void Send_WhenReceiveNAK_2ndTime_ShouldTryAgain() { using (var stream = new RWStream()) using (var sut = new StreamRawPinPad(stream)) { var payload = Encoding.ASCII.GetBytes("OPN000"); var expectedBytes = new ByteArrayBuilder() .Add(Bytes.SYN).Add(payload).Add(Bytes.ETB).Add(0x77, 0x5e) .Add(Bytes.SYN).Add(payload).Add(Bytes.ETB).Add(0x77, 0x5e) .Add(Bytes.SYN).Add(payload).Add(Bytes.ETB).Add(0x77, 0x5e) .Add(Bytes.CAN) .ToArray(); Should.CompleteIn(async() => { var taskSend = sut.SendRawMessageAsync(new RawRequestMessage(payload)); await Task.Delay(100); stream.PushByteToRead(Bytes.NAK); await Task.Delay(100); stream.PushByteToRead(Bytes.NAK); await taskSend; }, TimeSpan.FromMilliseconds(100 + 100 + TimeoutMilliseconds + ToleranceMilliseconds)); stream.GetBytesWritten().ShouldBe(expectedBytes); } }
public static string ReadStringFromFile(ref RWStream file) { if (file.Length - file.Position < 4) { return(""); } int strLength = file.ReadInt32(); return(strLength == -1 || strLength == 0 ? "" : file.ReadString(StringType.Ascii, strLength).TrimEnd(new[] { '\0' })); }
public void deSerialize(RWStream file) { int size = file.ReadInt32(); var bData = file.ReadBytes(size); RWStream data = new RWStream(bData); IDeserializable Iself = this; while (data.Position < data.Length) { Utilities.ReadProperty(ref data, Iself); } }
/// <summary>Peek into the Memory</summary> /// <param name="startDumpAddress">The Hex offset to start dump Example:0xC0000000 </param> /// <param name="dumpLength">The Length or size of dump Example:0xFFFFFF </param> /// <param name="memoryAddress">The memory address to peek Example:0xC5352525 </param> /// <param name="peekSize">The byte size to peek Example: "0x4" or "4"</param> /// <returns>Return the hex string of the value</returns> private string Peek(uint startDumpAddress, uint dumpLength, uint memoryAddress, int peekSize) { var total = (memoryAddress - startDumpAddress); if (memoryAddress > (startDumpAddress + dumpLength) || memoryAddress < startDumpAddress) { throw new Exception("Memory Address Out of Bounds"); } if (!Connect()) { return(null); //Call function - If not connected return } if (!GetMeMex(startDumpAddress, dumpLength)) { return(null); //call function - If not connected or if somethign wrong return } var readWriter = new RWStream(); try { var data = new byte[1026]; //byte chuncks //Writing each byte chuncks======== for (var i = 0; i < dumpLength / 1024; i++) { _tcp.Client.Receive(data); readWriter.WriteBytes(data, 2, 1024); } //Write whatever is left var extra = (int)(dumpLength % 1024); if (extra > 0) { _tcp.Client.Receive(data); readWriter.WriteBytes(data, 2, extra); } readWriter.Flush(); readWriter.Position = total; var value = readWriter.ReadBytes(peekSize); return(Functions.Functions.ToHexString(value)); } catch (Exception ex) { throw new Exception(ex.Message); } finally { readWriter.Close(true); _tcp.Close(); //close connection _connected = false; _memexValidConnection = false; } }
public void Load(byte[] raw) { RWStream str = new RWStream(raw); Width = str.ReadInt32(); Height = str.ReadInt32(); Map = new int[Width * Height]; for (int i = 0; i < Width * Height; i++) { Map[i] = str.ReadInt32();//read hex value of pixle } }
public void deSerialize(RWStream file) { var size = file.ReadInt32(); var bData = new byte[size]; file.Position += 4; Utilities.ReadStringFromFile(ref file); file.Position += 4; bData = file.ReadBytes(size);; var data = new RWStream(bData); IDeserializable Iself = this; while (data.Position < data.Length) { Utilities.ReadProperty(ref data, Iself); } }
public void Dump(string filename, uint startDumpAddress, uint dumpLength) { if (!Connect()) { return; //Call function - If not connected return } if (!GetMeMex(startDumpAddress, dumpLength)) { return; //call function - If not connected or if something wrong return } var readWriter = new RWStream(filename); try { var data = new byte[1026]; //byte chuncks //Writing each byte chuncks======== for (var i = 0; i < dumpLength / 1024; i++) { _tcp.Client.Receive(data); readWriter.WriteBytes(data, 2, 1024); ReportProgress(0, (int)(dumpLength / 1024), (i + 1), "Dumping Memory..."); } //Write whatever is left var extra = (int)(dumpLength % 1024); if (extra > 0) { _tcp.Client.Receive(data); readWriter.WriteBytes(data, 2, extra); } readWriter.Flush(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { readWriter.Close(false); _tcp.Close(); //close connection _connected = false; _memexValidConnection = false; } }
public void Send_WhenDoesNotReceiveReplyAndTimeout_ShouldAddCANandAbort() { using (var stream = new RWStream()) using (var sut = new StreamRawPinPad(stream)) { var payload = Encoding.ASCII.GetBytes("OPN000"); var expectedBytes = new ByteArrayBuilder() .Add(Bytes.SYN).Add(payload).Add(Bytes.ETB).Add(0x77, 0x5e) .Add(Bytes.CAN) .ToArray(); Should.CompleteIn(async() => { await sut.SendRawMessageAsync(new RawRequestMessage(payload)); }, TimeSpan.FromMilliseconds(TimeoutMilliseconds + ToleranceMilliseconds)); stream.GetBytesWritten().ShouldBe(expectedBytes); } }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { Enumerator.Dispose(); if (RWStream != null) { try { RWStream.Dispose(); } catch (Exception) {} } } disposedValue = true; } }
private void button1_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); if (dlg.ShowDialog() == DialogResult.OK) { Bitmap bmp = (Bitmap)Image.FromFile(dlg.FileName); RWStream str = new RWStream(); str.WriteInt32(bmp.Width); str.WriteInt32(bmp.Height); for (int y = 0; y < bmp.Height; y++) { for (int x = 0; x < bmp.Width; x++) { var px = bmp.GetPixel(x, y); str.WriteInt32(((px.R << 16) | (px.G << 8) | px.B)); } } File.WriteAllBytes("img.cif", str._buffer.ToArray()); } }
public BindingList<Types.SearchResults> FindHexOffset(string pointer) { if (pointer == null) throw new Exception("Empty Search string!"); if (!Functions.Functions.IsHex(pointer)) throw new Exception(string.Format("{0} is not a valid Hex string.", pointer)); if (!Connect()) return null; //Call function - If not connected return if (!GetMeMex()) return null; //call function - If not connected or if something wrong return try { //LENGTH or Size = Length of the dump var size = _startDumpLength; _readWriter = new RWStream(); _readWriter.ReportProgress += new UpdateProgressBarHandler(ReportProgress); var data = new byte[1026]; //byte chuncks //Writing each byte chuncks======== //No need to mess with it :D for (var i = 0; i < size / 1024; i++) { if (_stopSearch) return null; _tcp.Client.Receive(data); _readWriter.WriteBytes(data, 2, 1024); ReportProgress(0, (int)(size / 1024), (i + 1), "Dumping Memory..."); } //Write whatever is left var extra = (int)(size % 1024); if (extra > 0) { if (_stopSearch) return null; _tcp.Client.Receive(data); _readWriter.WriteBytes(data, 2, extra); } _readWriter.Flush(); //=================================== //=================================== if (_stopSearch) return null; _readWriter.Position = 0; var values = _readWriter.SearchHexString(Functions.Functions.StringToByteArray(pointer), _startDumpOffset); return values; } catch (Exception ex) { throw new Exception(ex.Message); } finally { _readWriter.Close(true); _tcp.Close(); //close connection _connected = false; _memexValidConnection = false; ReportProgress(0, 100, 0,"Idle"); } }
/// <summary>Peek into the Memory</summary> /// <param name="startDumpAddress">The Hex offset to start dump Example:0xC0000000 </param> /// <param name="dumpLength">The Length or size of dump Example:0xFFFFFF </param> /// <param name="memoryAddress">The memory address to peek Example:0xC5352525 </param> /// <param name="peekSize">The byte size to peek Example: "0x4" or "4"</param> /// <returns>Return the hex string of the value</returns> private string Peek(uint startDumpAddress, uint dumpLength, uint memoryAddress, int peekSize) { var total = (memoryAddress - startDumpAddress); if (memoryAddress > (startDumpAddress + dumpLength) || memoryAddress < startDumpAddress) throw new Exception("Memory Address Out of Bounds"); if (!Connect()) return null; //Call function - If not connected return if (!GetMeMex(startDumpAddress, dumpLength)) return null; //call function - If not connected or if somethign wrong return var readWriter = new RWStream(); try { var data = new byte[1026]; //byte chuncks //Writing each byte chuncks======== for (var i = 0; i < dumpLength / 1024; i++) { _tcp.Client.Receive(data); readWriter.WriteBytes(data, 2, 1024); } //Write whatever is left var extra = (int)(dumpLength % 1024); if (extra > 0) { _tcp.Client.Receive(data); readWriter.WriteBytes(data, 2, extra); } readWriter.Flush(); readWriter.Position = total; var value = readWriter.ReadBytes(peekSize); return Functions.Functions.ToHexString(value); } catch (Exception ex) { throw new Exception(ex.Message); } finally { readWriter.Close(true); _tcp.Close(); //close connection _connected = false; _memexValidConnection = false; } }
public static bool readBoolFromFile(ref RWStream file) { return(Convert.ToBoolean(file.ReadInt8())); }
public void Dump(string filename, uint startDumpAddress, uint dumpLength) { if (!Connect()) return; //Call function - If not connected return if (!GetMeMex(startDumpAddress, dumpLength)) return; //call function - If not connected or if something wrong return var readWriter = new RWStream(filename); try { var data = new byte[1026]; //byte chuncks //Writing each byte chuncks======== for (var i = 0; i < dumpLength / 1024; i++) { _tcp.Client.Receive(data); readWriter.WriteBytes(data, 2, 1024); ReportProgress(0, (int)(dumpLength / 1024), (i + 1), "Dumping Memory..."); } //Write whatever is left var extra = (int)(dumpLength % 1024); if (extra > 0) { _tcp.Client.Receive(data); readWriter.WriteBytes(data, 2, extra); } readWriter.Flush(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { readWriter.Close(false); _tcp.Close(); //close connection _connected = false; _memexValidConnection = false; } }
public Font(byte[] File) { RawFile = new RWStream(File); DeserlizeFile(); }
public static float readSingleFloatFromFile(ref RWStream file) { return(file.ReadSingle()); }
public static double readDoubleFloatFromFile(ref RWStream file) { return(file.ReadDouble()); }
public static void ReadProperty(ref RWStream file, IDeserializable obj) { string propName = ReadStringFromFile(ref file); file.Position += 4; string propType = ReadStringFromFile(ref file); file.Position += 4; FieldInfo prop = obj.GetType().GetField(propName, BindingFlags.Public | BindingFlags.Instance); if (prop == null) { return; } switch (propType) { case "StructProperty": object instanceObj = Activator.CreateInstance(prop.GetValue(obj).GetType()); MethodInfo parse = instanceObj.GetType().GetMethod("deSerialize"); parse.Invoke(instanceObj, new object[] { file }); prop.SetValue(obj, instanceObj); break; case "ArrayProperty": object instanceArray = Activator.CreateInstance(prop.GetValue(obj).GetType()); MethodInfo arrayparse = instanceArray.GetType().GetMethod("deSerialize"); arrayparse.Invoke(instanceArray, new object[] { file }); prop.SetValue(obj, instanceArray); break; case "BoolProperty": file.Position += 8; //Skip two unkown int32s bool value = readBoolFromFile(ref file); prop.SetValue(obj, value); break; case "ByteProperty": file.Position += 8; ReadStringFromFile(ref file); file.Position += 4; string name = ReadStringFromFile(ref file); int eIndex = file.ReadInt32(); object enumValue = Enum.Parse(prop.GetValue(obj).GetType(), name); prop.SetValue(obj, enumValue); break; case "FloatProperty": int floatSize = file.ReadInt32(); file.Position += 4; switch (floatSize) { case 4: float single = readSingleFloatFromFile(ref file); prop.SetValue(obj, single); break; case 8: double dbl = readDoubleFloatFromFile(ref file); prop.SetValue(obj, dbl); break; default: throw new Exception("WTF that's not a floater"); } break; case "IntProperty": file.Position += 4; int index = file.ReadInt32(); int intvalue = file.ReadInt32(); if (prop.GetValue(obj).GetType().IsArray) { var arrayVal = (int[])prop.GetValue(obj); arrayVal[index] = intvalue; prop.SetValue(obj, arrayVal); } else { prop.SetValue(obj, intvalue); } break; case "StrProperty": file.Position += 8; string strValue = ReadStringFromFile(ref file); prop.SetValue(obj, strValue); break; case "": file.Position += 4; break; } }
public BindingList <Types.SearchResults> FindHexOffset(string pointer) { if (pointer == null) { throw new Exception("Empty Search string!"); } if (!Functions.Functions.IsHex(pointer)) { throw new Exception(string.Format("{0} is not a valid Hex string.", pointer)); } if (!Connect()) { return(null); //Call function - If not connected return } if (!GetMeMex()) { return(null); //call function - If not connected or if something wrong return } try { //LENGTH or Size = Length of the dump var size = _startDumpLength; _readWriter = new RWStream(); _readWriter.ReportProgress += new UpdateProgressBarHandler(ReportProgress); var data = new byte[1026]; //byte chuncks //Writing each byte chuncks======== //No need to mess with it :D for (var i = 0; i < size / 1024; i++) { if (_stopSearch) { return(null); } _tcp.Client.Receive(data); _readWriter.WriteBytes(data, 2, 1024); ReportProgress(0, (int)(size / 1024), (i + 1), "Dumping Memory..."); } //Write whatever is left var extra = (int)(size % 1024); if (extra > 0) { if (_stopSearch) { return(null); } _tcp.Client.Receive(data); _readWriter.WriteBytes(data, 2, extra); } _readWriter.Flush(); //=================================== //=================================== if (_stopSearch) { return(null); } _readWriter.Position = 0; var values = _readWriter.SearchHexString(Functions.Functions.StringToByteArray(pointer), _startDumpOffset); return(values); } catch (Exception ex) { throw new Exception(ex.Message); } finally { _readWriter.Close(true); _tcp.Close(); //close connection _connected = false; _memexValidConnection = false; ReportProgress(0, 100, 0, "Idle"); } }
public void deSerialize(RWStream file) { int size = file.ReadInt32(); file.Position += 4 + size; }
public void deSerialize(RWStream file) { int size = file.ReadInt32(); file.Position += 4; Utilities.ReadStringFromFile(ref file); file.Position += 4 + size; }