public TextBuffer(MemoryLocation memory) { this.memory = memory; MaxLength = memory.Bytes.Span[0] - 1; Text = ""; Tokens = new Dictionary <int, string>(); }
public void CanTokensize() { using var file = File.OpenRead(@"Data\ZORK1.DAT"); var logger = NullLoggerFactory.GetLogger(); var machine = new Machine(logger, new SolveZorkInputStream()); machine.Load(file); var textBytes = new byte[37]; textBytes[0] = (byte)textBytes.Length; var textMemory = new MemoryLocation(1, textBytes.AsMemory()); var textBuffer = new TextBuffer(textMemory); textBuffer.Write("fred,go fishing"); var dictionary = new ParseDictionary(machine); textBuffer.Tokenize(dictionary); Assert.Equal(4, textBuffer.Tokens.Count); Assert.Equal("fred", textBuffer.Tokens[1]); Assert.Equal(",", textBuffer.Tokens[5]); Assert.Equal("go", textBuffer.Tokens[6]); Assert.Equal("fishing", textBuffer.Tokens[9]); }
public OpLoad( MemoryLocation From, MemoryLocation To) { m_From = From; m_To = To; }
private void CalculatePointers() { var bytesToFind = new byte[] { 0x4c, 0x8b, 0x35, 0x90, 0x90, 0x90, 0x90,// = 0x55, 0xfa, 0x0c, 0x00 WILDCARDS 0x4c, 0x69, 0xf8, 0x90, 0x90, 0x90, 0x90, 0x4c, 0x89, 0xf0, 0x4c, 0x01, 0xf8 }; var results = MemoryUtil.FindMemoryWithWildcards(GetGameHandle(), GetEntryPoint(), (uint)this.GameProcess.MainModule.ModuleMemorySize, bytesToFind); if (results.Count != 1) { throw new AmbiguousMatchException($"{results.Count} memory locations matched, which is not 1!"); } var result = results.First(); var resultAddress = result.Key; var resultBytes = result.Value; var chessboardPointerLocation = IntPtr.Add(resultAddress, BitConverter.ToInt32(resultBytes, 3) + 7); this.MemLocChessArrayPointer = new MemoryLocation <IntPtr>(GetGameHandle(), chessboardPointerLocation); this.MemLocChessArraySize = new MemoryLocation <int>(GetGameHandle(), chessboardPointerLocation, -8); this.MemLocChessBoardSizeWidth = new MemoryLocation <int>(GetGameHandle(), chessboardPointerLocation, 0xA8 + 0x4); this.MemLocChessBoardSizeHeight = new MemoryLocation <int>(GetGameHandle(), chessboardPointerLocation, 0xA8); this.MemLocCurrentPlayersTurn = new MemoryLocation <int>(GetGameHandle(), chessboardPointerLocation, 0x110); this.MemLocGameEndedWinner = new MemoryLocation <int>(GetGameHandle(), chessboardPointerLocation, 0xCC); this.MemLocGameState = new MemoryLocation <int>(GetGameHandle(), chessboardPointerLocation, 0xD0); }
private void comm_MessageReceived(object sender, MessageReceivedEventArgs e) { var obj = e.IndicationObject; if (obj is MemoryLocation) { MemoryLocation loc = obj as MemoryLocation; try { var msg = comm.ReadMessage(loc.Index, loc.Storage); comm.DeleteMessage(msg.Index, PhoneStorageType.Sim); var d = (SmsDeliverPdu)msg.Data; if (d.OriginatingAddress != null) { this.Invoke((Action)(() => { lock (listDo) { listDo.Add((SmsDeliverPdu)msg.Data); }; })); this.Invoke((Action)(() => { MessageReceived(msg); })); } } catch (Exception ex) { this.Invoke(new Action(() => ShowException(ex))); } } }
private void comm_MessageReceived(object sender, MessageReceivedEventArgs e) { try { IMessageIndicationObject obj = e.IndicationObject; if (obj is MemoryLocation) { MemoryLocation loc = (MemoryLocation)obj; Output(string.Format("New message received in storage \"{0}\", index {1}.", loc.Storage, loc.Index)); Output(""); return; } if (obj is ShortMessage) { ShortMessage msg = (ShortMessage)obj; SmsPdu pdu = comm.DecodeReceivedMessage(msg); Output("New message received."); Output(""); ShowMessage(pdu); return; } Output("Error: Unknown notification object!"); } catch (Exception ex) { Output(ex.ToString()); } }
private void comm_MessageReceived(object sender, MessageReceivedEventArgs e) { try { IMessageIndicationObject obj = e.IndicationObject; if (obj is MemoryLocation) { MemoryLocation loc = (MemoryLocation)obj; string logmsg = string.Format("New message received in storage \"{0}\", index {1}.", loc.Storage, loc.Index); logger(logmsg); DecodedShortMessage msg = comm.ReadMessage(loc.Index, loc.Storage); ShowMessage(msg.Data); return; } if (obj is ShortMessage) { ShortMessage msg = (ShortMessage)obj; SmsPdu pdu = comm.DecodeReceivedMessage(msg); logger("New message received:"); ShowMessage(pdu); return; } logger("Error: Unknown notification object!"); } catch (Exception ex) { ShowException(ex); } }
public void OperatorEqualsSameInstance() { var t_Location = new MemoryLocation(new MemoryAddress(0), m_Bank); (t_Location == t_Location) .Should() .BeTrue(); }
public void EqualsNull() { var t_Location = new MemoryLocation(new MemoryAddress(0), m_Bank); t_Location.Equals(null) .Should() .BeFalse(); }
public AssignmentStatement ParseAssignmentStatement(MemoryLocation destination) { AssignmentStatement result = new AssignmentStatement(destination); Scanner.ConsumeOperatorToken(Token.Types.ASSIGN); result.Expression = ParseExpression(); return result; }
private static bool LocationsAdjacent(MemoryLocation locationOne, MemoryLocation locationTwo) { var horizontallyAdjacent = Math.Abs(locationOne.X - locationTwo.X) == 1; var verticallyAdjacent = Math.Abs(locationOne.Y - locationTwo.Y) == 1; var sameHorizontal = Math.Abs(locationOne.X - locationTwo.X) == 0; var sameVertical = Math.Abs(locationOne.Y - locationTwo.Y) == 0; return(horizontallyAdjacent && sameVertical || verticallyAdjacent && sameHorizontal); }
public void EqualsIncorrectType() { var t_Location = new MemoryLocation(new MemoryAddress(0), m_Bank); t_Location .Equals(new MemoryAddress(0)) .Should() .BeFalse(); }
public void OperatorBothInstancesEqualsNull() { MemoryLocation t_FirstLocation = null; MemoryLocation t_SecondLocation = null; (t_FirstLocation == t_SecondLocation) .Should() .BeTrue(); }
public void HashCode() { var t_Location = new MemoryLocation(new MemoryAddress(0), m_Bank); var t_AnotherLocation = new MemoryLocation(new MemoryAddress(0), m_Bank); (t_Location.GetHashCode() == t_AnotherLocation.GetHashCode()) .Should() .BeTrue(); }
public void EqualsSameInstance() { var t_Location = new MemoryLocation(new MemoryAddress(0), m_Bank); t_Location .Equals(t_Location) .Should() .BeTrue(); }
public void CompareToSameLocation() { var t_Location = new MemoryLocation(new MemoryAddress(0), m_Bank); t_Location .CompareTo(t_Location) .Should() .Be(0); }
public WindowsDumpFileMemoryReader(string dumpFilePath) : base(dumpFilePath) { bool dispose = true; try { IntPtr streamPointer = IntPtr.Zero; uint streamSize = 0; MINIDUMP_DIRECTORY directory = new MINIDUMP_DIRECTORY(); if (!MiniDumpReadDumpStream((IntPtr)basePointer, MINIDUMP_STREAM_TYPE.Memory64ListStream, ref directory, ref streamPointer, ref streamSize)) { throw new Exception("Unable to read mini dump stream"); } var data = (MINIDUMP_MEMORY64_LIST)Marshal.PtrToStructure(streamPointer, typeof(MINIDUMP_MEMORY64_LIST)); ulong lastEnd = data.BaseRva; MemoryLocation[] ranges = new MemoryLocation[data.NumberOfMemoryRanges]; for (int i = 0; i < ranges.Length; i++) { var descriptor = (MINIDUMP_MEMORY_DESCRIPTOR64)Marshal.PtrToStructure(streamPointer + sizeof(MINIDUMP_MEMORY64_LIST) + i * sizeof(MINIDUMP_MEMORY_DESCRIPTOR64), typeof(MINIDUMP_MEMORY_DESCRIPTOR64)); ranges[i] = new MemoryLocation() { MemoryStart = descriptor.StartOfMemoryRange, MemoryEnd = descriptor.StartOfMemoryRange + descriptor.DataSize, FilePosition = lastEnd, }; lastEnd += descriptor.DataSize; } Initialize(ranges); dispose = false; } finally { if (dispose) { stream.SafeMemoryMappedViewHandle.ReleasePointer(); if (stream != null) { stream.Dispose(); } if (memoryMappedFile != null) { memoryMappedFile.Dispose(); } if (fileStream != null) { fileStream.Dispose(); } } } }
public ParseBuffer(MemoryLocation memory) { this.memory = memory; MaxLength = memory.Bytes.Span[0] - 1; if (MaxLength <= 6) { throw new InvalidOperationException("Parse buffer size indicates a bug"); } }
public void CompareToSameBankHigherAddress() { var t_Lower = new MemoryLocation(new MemoryAddress(0), m_Bank); var t_Higher = new MemoryLocation(new MemoryAddress(10), m_Bank); t_Lower .CompareTo(t_Higher) .Should() .Be(-1); }
public void CompareToOutsideBank() { var t_OtherBank = new MemoryLocation(new MemoryAddress(0), null); var t_DefaultBank = new MemoryLocation(new MemoryAddress(10), m_Bank); t_OtherBank .CompareTo(t_DefaultBank) .Should() .Be(-1); }
public void EqualsObject() { var t_Location = new MemoryLocation(new MemoryAddress(0), m_Bank); object t_AnotherLocation = new MemoryLocation(new MemoryAddress(1), m_Bank); t_Location .Equals(t_AnotherLocation) .Should() .BeFalse(); }
public void ExecuteLoadIfZeroOperation() { var t_Destination = new MemoryLocation(new MemoryAddress(4), m_Bank); new OpLoadConstIfZero <int>(5, t_Destination, new MemoryLocation(new MemoryAddress(8), m_Bank)) .Execute(); t_Destination.Load <int>() .Should().Be(5); }
private static bool LocationsAdjacentIncludingDiagonal(MemoryLocation locationOne, MemoryLocation locationTwo) { if (locationOne.X == locationTwo.X && locationOne.Y == locationTwo.Y) { return(false); } var horizontallyAdjacent = Math.Abs(locationOne.X - locationTwo.X) <= 1; var verticallyAdjacent = Math.Abs(locationOne.Y - locationTwo.Y) <= 1; return(horizontallyAdjacent && verticallyAdjacent); }
private Node GenerateStackVariableLocation(Function.Function function, MemoryLocation loc) { if (loc.Function == function) { return(new ArithmeticBinaryOperation( AST.ArithmeticOperationType.Addition, new RegisterRead(HardwareRegister.RBP), new IntegerImmediateValue(loc.Offset))); } throw new ArgumentException($"Attempt to access non-local stack variable of {function}"); }
public static int FindNextValue(int input) { List <MemoryLocation> locations = new List <MemoryLocation>(); var currentHorizontalMovement = 1; var currentVerticalMovement = 0; var horizontalLimit = 1; var verticalLimit = 0; var currentHorizontalPosition = 0; var currentVerticalPosition = 0; var nextValue = 1; while (nextValue <= input) { var newLocation = new MemoryLocation { Value = nextValue, Y = currentVerticalPosition, X = currentHorizontalPosition }; nextValue = locations.Where(x => LocationsAdjacentIncludingDiagonal(x, newLocation)).Sum(x => x.Value); newLocation.Value = Math.Max(1, nextValue); locations.Add(newLocation); if (currentHorizontalMovement != 0 && Math.Abs(currentHorizontalPosition) == horizontalLimit) { if (currentHorizontalMovement > 0) { verticalLimit++; } currentVerticalMovement = currentHorizontalMovement > 0 ? -1 : 1; currentHorizontalMovement = 0; } else if (currentVerticalMovement != 0 && Math.Abs(currentVerticalPosition) == verticalLimit) { if (currentVerticalMovement > 0) { horizontalLimit++; } currentHorizontalMovement = currentVerticalMovement > 0 ? 1 : -1; currentVerticalMovement = 0; } currentHorizontalPosition += currentHorizontalMovement; currentVerticalPosition += currentVerticalMovement; } return(nextValue); }
private void comm_MessageReceived(object sender, MessageReceivedEventArgs e) { IMessageIndicationObject obj = e.IndicationObject; MemoryLocation loc = (MemoryLocation)obj; DecodedShortMessage[] messages; messages = comm.ReadMessages(PhoneMessageStatus.ReceivedUnread, loc.Storage); foreach (DecodedShortMessage message in messages) { SmsDeliverPdu data = new SmsDeliverPdu(); SmsPdu smsrec = message.Data; ShowMessage(smsrec, message.Index); } }
public bool PlayerHasTarget() { Memory oMemory = new Memory(); MemoryLocation nmLocation = new MemoryLocation(); if (oMemory.OpenProcess("aion.bin")) { if (oMemory.ReadInt(_Address_Base + nmLocation._Address_LocalPlayer_HasTarget) == 1) { return(true); } } oMemory = null; nmLocation = null; return(false); }
public bool IsTargetDead() { Memory oMemory = new Memory(); MemoryLocation nmLocation = new MemoryLocation(); if (oMemory.OpenProcess("aion.bin")) { if (oMemory.ReadInt(_Address_Base + nmLocation._Address_Target_Health, nmLocation.offset_Target_Health) == 0) { return(true); } } oMemory = null; nmLocation = null; return(false); }
/// <summary> /// Initializes a new instance of the <see cref="CoreDumpReader" /> class. /// </summary> /// <param name="dumpFilePath">The dump file path.</param> /// <param name="segments">The segments.</param> public CoreDumpReader(string dumpFilePath, IEnumerable <Segment <ulong> > segments) : base(dumpFilePath) { Segment <ulong>[] segmentsArray = segments.OrderBy(s => s.Address).ToArray(); MemoryLocation[] ranges = new MemoryLocation[segmentsArray.Length]; for (int i = 0; i < ranges.Length; i++) { ranges[i] = new MemoryLocation() { MemoryStart = segmentsArray[i].Address, MemoryEnd = segmentsArray[i].Address + (ulong)segmentsArray[i].FileSize, FilePosition = (ulong)segmentsArray[i].Offset, }; } Initialize(ranges); }
public void CanWriteToTextBuffer() { var buffer = new byte[37]; buffer[0] = (byte)buffer.Length; var memory = new MemoryLocation(1, buffer.AsMemory()); var textBuffer = new TextBuffer(memory); textBuffer.Write("This is a long string with extra words."); Assert.Equal(buffer.Length, buffer[0]); Assert.Equal(36, textBuffer.MaxLength); Assert.Equal((byte)'t', buffer[1]); Assert.Equal((byte)'o', buffer[35]); Assert.Equal(0, buffer[36]); }
private IMessageIndicationObject HandleStatusReportMemoryIndication(ref string input) { Regex regex = new Regex("\\+CDSI: \"(\\w+)\",(\\d+)"); Match match = regex.Match(input); if (match.Success) { string value = match.Groups[1].Value; int num = int.Parse(match.Groups[2].Value); MemoryLocation memoryLocation = new MemoryLocation(value, num); input = input.Remove(match.Index, match.Length); return(memoryLocation); } else { throw new ArgumentException("Input string does not contain an SMS-STATUS-REPORT memory location indication."); } }
public MemoryLocation ParseMemoryLocation(Token idToken) { MemoryLocation result = new MemoryLocation(idToken.CodeLineNumber, idToken.CodeColumnNumber, idToken.CodeCharacterIndex); result.VariableName = idToken.Text; if (NextTokenType == Token.Types.OPEN_BRACKET) // Array index specified { Scanner.ConsumeOperatorToken(Token.Types.OPEN_BRACKET); result.ArrayIndexExpression = ParseExpression(); // Array index expression Scanner.ConsumeOperatorToken(Token.Types.CLOSE_BRACKET); } return result; }
public DumpFileMemoryReader(string dumpFilePath) { bool dispose = true; FileStream fileStream = null; MemoryMappedFile memoryMappedFile = null; MemoryMappedViewStream stream = null; try { fileStream = new FileStream(dumpFilePath, FileMode.Open, FileAccess.Read); memoryMappedFile = MemoryMappedFile.CreateFromFile(fileStream, Guid.NewGuid().ToString(), fileStream.Length, MemoryMappedFileAccess.Read, new MemoryMappedFileSecurity(), HandleInheritability.Inheritable, false); stream = memoryMappedFile.CreateViewStream(0, fileStream.Length, MemoryMappedFileAccess.Read); stream.SafeMemoryMappedViewHandle.AcquirePointer(ref basePointer); IntPtr streamPointer = IntPtr.Zero; uint streamSize = 0; MINIDUMP_DIRECTORY directory = new MINIDUMP_DIRECTORY(); if (!MiniDumpReadDumpStream((IntPtr)basePointer, MINIDUMP_STREAM_TYPE.Memory64ListStream, ref directory, ref streamPointer, ref streamSize)) throw new Exception("Unable to read mini dump stream"); var data = (MINIDUMP_MEMORY64_LIST)Marshal.PtrToStructure(streamPointer, typeof(MINIDUMP_MEMORY64_LIST)); ulong lastEnd = data.BaseRva; ranges = new MemoryLocation[data.NumberOfMemoryRanges]; for (int i = 0; i < ranges.Length; i++) { var descriptor = (MINIDUMP_MEMORY_DESCRIPTOR64)Marshal.PtrToStructure(streamPointer + sizeof(MINIDUMP_MEMORY64_LIST) + i * sizeof(MINIDUMP_MEMORY_DESCRIPTOR64), typeof(MINIDUMP_MEMORY_DESCRIPTOR64)); ranges[i] = new MemoryLocation() { MemoryStart = descriptor.StartOfMemoryRange, MemoryEnd = descriptor.StartOfMemoryRange + descriptor.DataSize, FilePosition = lastEnd, }; lastEnd += descriptor.DataSize; } int newEnd = 0; for (int i = 1; i < ranges.Length; i++) if (ranges[i].MemoryStart == ranges[newEnd].MemoryEnd) ranges[newEnd].MemoryEnd = ranges[i].MemoryEnd; else ranges[++newEnd] = ranges[i]; newEnd++; Array.Resize(ref ranges, newEnd); finder = new MemoryRegionFinder(ranges.Select(r => new MemoryRegion { BaseAddress = r.MemoryStart, MemoryEnd = r.MemoryEnd }).ToArray()); dispose = false; } finally { if (dispose) { stream.SafeMemoryMappedViewHandle.ReleasePointer(); if (stream != null) { stream.Dispose(); } if (memoryMappedFile != null) { memoryMappedFile.Dispose(); } if (fileStream != null) { fileStream.Dispose(); } } else { this.fileStream = fileStream; this.stream = stream; this.memoryMappedFile = memoryMappedFile; } } }