private void TreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { int tag = -1; if (e.Node != null && e.Node.Tag != null && int.TryParse(e.Node.Tag.ToString(), out tag) && tag != -1) { UInt32 code = fstTextPositions[tag].dataAddress - 0x79FFFFFC; fileSwapCode.Text = GlobalFunctions.toHex(code) + " 00000008\r\n" + GlobalFunctions.toHex(fstTextPositions[tag].offset) + " " + GlobalFunctions.toHex(fstTextPositions[tag].entries); setAsTargetButton.Enabled = true; setAsSourceButton.Enabled = true; selFile = e.Node.Text; } else { fileSwapCode.Text = ""; setAsTargetButton.Enabled = false; setAsSourceButton.Enabled = false; } selectedFile = tag; }
private void MainBoxDoubleClick(object sender, EventArgs e) { int index = mainBox.SelectedIndex; // If index is negative, bail out if (index == -1) { return; } // Grab the instruction that they selected String assembly = mainBox.Items[index].ToString(); assembly = assembly.Substring(20, assembly.Length - 20); String[] sep = assembly.Split(new char[1] { '\t' }, StringSplitOptions.RemoveEmptyEntries); // Is it some sort of branch? Does it have an address parameter? sep[0] = sep[0].ToLower(); if (sep[0].StartsWith("b") && sep.Length > 1) { // Most of the time, this won't matter // However, some branches specify the cr (e.g. bge- cr6,0x802e583c) // So parse out anything before the 0x sep[1] = sep[1].Substring(sep[1].IndexOf("0x")); // Does it have a valid address after it? UInt32 bAddress; if (GlobalFunctions.tryToHex(sep[1], out bAddress) && ValidMemory.validAddress(bAddress)) { // tell the disassembly window to jump there DissToBox(bAddress); } } }
public void SearchString(byte[] searchBytes, bool caseSensitive, bool unicode, bool hex) //public void SearchString(String sString, bool caseSensitive, bool unicode) { byte[] stringBytes = searchBytes; UInt32 startAddr = selAddress + 4; UInt32 endAddress = 0; int dumpLength = (unicode ? 2:1); bool found = false; for (int i = 0; i < ValidMemory.ValidAreas.Length; i++) { if (startAddr >= ValidMemory.ValidAreas[i].low && startAddr < ValidMemory.ValidAreas[i].high) { found = true; endAddress = ValidMemory.ValidAreas[i].high; break; } } if (!found) { throw new Exception("Memory area could not be acquired!"); } bool valueFound = false; int inpos = 0; UInt32 beginAddress = startAddr; MemoryStream ms = new MemoryStream(); long streamPos = 0; UInt32 cVal; char cChar; UInt32 SearchBufferSize = 0x400 * 256; // 400 is the packet size in TCPGecko.cs UInt32 dumpHigh = Math.Min(startAddr + SearchBufferSize, endAddress); try { int index; do { ms.Seek(0, SeekOrigin.End); int startIndex = (int)ms.Position; gecko.Dump(startAddr, dumpHigh, ms); byte[] streamArray = ms.GetBuffer(); index = GlobalFunctions.IndexOfByteArray(streamArray, stringBytes, startIndex, caseSensitive); if (index != -1) { valueFound = true; break; } startAddr = dumpHigh; dumpHigh = Math.Min(startAddr + SearchBufferSize, endAddress); Application.DoEvents(); // check for cancel search } while (dumpHigh != endAddress && !valueFound && searching); if (valueFound) { UInt32 address = (UInt32)(beginAddress + index); cAddress = address; } else { // hack to fix the jumping disassembly window cAddress = beginAddress - 4; if (dumpHigh == endAddress) { MessageBox.Show("Could not find search query"); } } } catch (ETCPGeckoException exc) { exceptionHandling.HandleException(exc); } }
public void Update(bool fast) { MemoryStream miniDump = new MemoryStream(); int oldColumnIndex, oldRowIndex; if (gView.SelectedCells.Count > 0) { oldColumnIndex = gView.SelectedCells[0].ColumnIndex; oldRowIndex = gView.SelectedCells[0].RowIndex; } else { oldColumnIndex = 1; oldRowIndex = 1; } UInt32 sAddress = cAddress & 0xFFFFFFF0; UInt32 offset = cAddress - sAddress; try { gecko.Dump(sAddress, sAddress + 0x100, miniDump); //gView.Rows.Add(16); // Only clear and re-load gView.Rows when it's != 16 // This was one thing slowing us down... if (gView.Rows.Count != 16) { gView.Rows.Clear(); gView.Rows.Add(16); } miniDump.Seek(0, SeekOrigin.Begin); UInt32 value, bValue; Byte[] buffer = new Byte[4]; UInt16 hwInput; UInt32 pValue = 0; for (int i = 0; i < 16; i++) { gView.Rows[i].Cells[0].Value = GlobalFunctions.toHex(sAddress + i * 16); for (int j = 1; j < 5; j++) { miniDump.Read(buffer, 0, 4); bValue = BitConverter.ToUInt32(buffer, 0); value = ByteSwap.Swap(bValue); if (sAddress + i * 0x10 + (j - 1) * 4 == selAddress) { pValue = value; } DataGridViewCell cell = gView.Rows[i].Cells[j]; if (PViewMode == MemoryViewMode.Hex) { cell.Value = GlobalFunctions.toHex(value); } else if (PViewMode == MemoryViewMode.ASCII) { cell.Value = DecodeASCII(buffer); } else if (PViewMode == MemoryViewMode.ANSI) { cell.Value = DecodeANSI(buffer); } else if (PViewMode == MemoryViewMode.Unicode) { cell.Value = DecodeUnicode(buffer); } else if (PViewMode == MemoryViewMode.Single) { cell.Value = PrettyFloat(GlobalFunctions.UIntToSingle(value)); } else if (PViewMode == MemoryViewMode.AutoZero || PViewMode == MemoryViewMode.AutoDot) { // if it might be a pointer, cast it as hex if (ValidMemory.validAddress(value)) { cell.Value = GlobalFunctions.toHex(value); } else { // If it's a float, and it's not too big or small, cast it as a Single Single singleCast = GlobalFunctions.UIntToSingle(value); if (!Single.IsNaN(singleCast) && Math.Abs(singleCast) > 1e-7 && Math.Abs(singleCast) < 1e10) { cell.Value = PrettyFloat(GlobalFunctions.UIntToSingle(value)); } else { if (IsASCII(buffer)) { if (PViewMode == MemoryViewMode.AutoZero && value == 0) { // Cast 0 as hex in auto zero mode cell.Value = GlobalFunctions.toHex(value); } else { // If all characters are valid printable ASCII, cast it as char cell.Value = DecodeASCII(buffer); } } else { // When all else fails, cast as hex cell.Value = GlobalFunctions.toHex(value); } } } } } } oldRow = (int)offset / 0x10; oldCol = (int)(offset & 0xC) / 4 + 1; if (!fast) { gView.Rows[oldRowIndex].Cells[oldColumnIndex].Selected = true; // Don't update the poke value during auto-updates // This way the user can still poke things // TODO: Ignore this if the poke operation isn't write? //pokeValue.Text = GlobalFunctions.toHex(pValue); } pokeAddress.Text = GlobalFunctions.toHex(selAddress); fpValue.Text = GlobalFunctions.UIntToSingle(pValue).ToString("G6"); } catch (ETCPGeckoException e) { exceptionHandling.HandleException(e); } }
public void Assemble(UInt32 address, String command) { if (!File.Exists(GAs)) { MessageBox.Show(GAs + " not found! Cannot assemble!"); return; } if (!File.Exists(GLd)) { MessageBox.Show(GLd + " not found! Cannot assemble!"); return; } if (!File.Exists(GOc)) { MessageBox.Show(GOc + " not found! Cannot assemble!"); return; } command = command.Trim(); if (isBranch(command)) { if (!extractTargetAddress(address, ref command)) { MessageBox.Show("Command parsing error!"); return; } } StreamWriter sw = new StreamWriter("ass.txt"); sw.WriteLine(command); sw.Close(); Process proc = new Process(); proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; proc.StartInfo.UseShellExecute = false; proc.StartInfo.FileName = GAs; proc.StartInfo.Arguments = "-mgekko -mregnames -o ass.o ass.txt"; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.RedirectStandardError = true; proc.Start(); String output = String.Empty; while (!proc.StandardError.EndOfStream) { output += proc.StandardError.ReadLine() + "\n"; } proc.WaitForExit(/*2000*/); int exitCode = proc.ExitCode; proc.Close(); File.Delete("ass.txt"); if (exitCode != 0 || !File.Exists("ass.o")) { if (File.Exists("ass.o")) { File.Delete("ass.o"); } MessageBox.Show(output); return; } proc = new Process(); proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; proc.StartInfo.UseShellExecute = false; proc.StartInfo.FileName = GLd; proc.StartInfo.Arguments = " -Ttext 0x80000000 -o ass2.o ass.o"; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.RedirectStandardError = true; proc.Start(); output = String.Empty; while (!proc.StandardError.EndOfStream) { output += proc.StandardError.ReadLine() + "\n"; } proc.WaitForExit(); exitCode = proc.ExitCode; proc.Close(); File.Delete("ass.o"); if (exitCode != 0 || !File.Exists("ass2.o")) { if (File.Exists("ass2.o")) { File.Delete("ass2.o"); } MessageBox.Show(output); return; } proc = new Process(); proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; proc.StartInfo.UseShellExecute = false; proc.StartInfo.FileName = GOc; proc.StartInfo.Arguments = " -O binary ass2.o ass.bin"; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.RedirectStandardError = true; proc.Start(); output = String.Empty; while (!proc.StandardError.EndOfStream) { output += proc.StandardError.ReadLine() + "\n"; } proc.WaitForExit(); exitCode = proc.ExitCode; proc.Close(); File.Delete("ass2.o"); if (exitCode != 0) { if (File.Exists("ass.bin")) { File.Delete("ass.bin"); } MessageBox.Show(output); return; } UInt32 machineCode; FileStream sr = new FileStream("ass.bin", FileMode.Open); machineCode = GlobalFunctions.ReadStream(sr); sr.Close(); File.Delete("ass.bin"); try { gecko.poke(address, machineCode); System.Threading.Thread.Sleep(100); DissToBox(address); } catch (EUSBGeckoException e) { exceptionHandling.HandleException(e); } }
public String[] Disassemble(UInt32 address, int commands) { List <String> result = new List <String>(); address = address & 0xFFFFFFFC; UInt32 eAddress = address + (UInt32)commands * 4; if (!File.Exists(vdappPath)) { #if MONO return(new String[] { "vdappc not found!" }); #else return(new String[] { "vdappc.exe not found!" }); #endif } // TODO: who is leaving this file open? FileStream values; string filename = System.IO.Path.GetTempFileName(); try { values = new FileStream(filename, FileMode.Create); } catch (Exception e) { return(new String[] { "Couldn't open diss.bin!" }); } try { gecko.Dump(address, eAddress, values); } catch (EUSBGeckoException e) { exceptionHandling.HandleException(e); return(result.ToArray()); } finally { // This will always close the FileStream, even if the exception is handled values.Close(); } Process proc = new Process(); proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.FileName = vdappPath; proc.StartInfo.Arguments = "\"" + filename + "\" 0x" + GlobalFunctions.toHex(address); proc.StartInfo.CreateNoWindow = true; //proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal; //proc.StartInfo.CreateNoWindow = false; proc.Start(); // Must read from the standard output before waiting on the process to close! // Otherwise, the standard output buffer will be full and vdappc will lock up // and we would never read from the buffer while (!proc.StandardOutput.EndOfStream) { result.Add(proc.StandardOutput.ReadLine()); } proc.WaitForExit(/*2000*/); //int exitCode = proc.ExitCode; //if (exitCode == 0) //{ // while (!proc.StandardOutput.EndOfStream) // result.Add(proc.StandardOutput.ReadLine()); //} proc.Close(); File.Delete(filename); return(result.ToArray()); }
public void Update(bool fast) { MemoryStream miniDump = new MemoryStream(); int oldColumnIndex, oldRowIndex; if (gView.SelectedCells.Count > 0) { oldColumnIndex = gView.SelectedCells[0].ColumnIndex; oldRowIndex = gView.SelectedCells[0].RowIndex; } else { oldColumnIndex = 1; oldRowIndex = 1; } uint sAddress = cAddress & 0xFFFFFFF0; uint offset = cAddress - sAddress; try { gecko.Dump(sAddress, sAddress + 0x100, miniDump); if (gView.Rows.Count != 16) { gView.Rows.Clear(); gView.Rows.Add(16); } miniDump.Seek(0, SeekOrigin.Begin); uint value, bValue; byte[] buffer = new byte[4]; uint pValue = 0; for (int i = 0; i < 16; i++) { gView.Rows[i].Cells[0].Value = GlobalFunctions.toHex(sAddress + i * 16); for (int j = 1; j < 5; j++) { miniDump.Read(buffer, 0, 4); bValue = BitConverter.ToUInt32(buffer, 0); value = ByteSwap.Swap(bValue); if (sAddress + i * 0x10 + (j - 1) * 4 == selectedAddress) { pValue = value; } DataGridViewCell cell = gView.Rows[i].Cells[j]; if (viewMode == MemoryViewMode.Hex) { cell.Value = GlobalFunctions.toHex(value); } else if (viewMode == MemoryViewMode.ASCII) { cell.Value = DecodeASCII(buffer); } else if (viewMode == MemoryViewMode.ANSI) { cell.Value = DecodeANSI(buffer); } else if (viewMode == MemoryViewMode.Unicode) { cell.Value = DecodeUnicode(buffer); } else if (viewMode == MemoryViewMode.Single) { cell.Value = PrettyFloat(GlobalFunctions.UIntToSingle(value)); } else if (viewMode == MemoryViewMode.AutoZero || viewMode == MemoryViewMode.AutoDot) { if (ValidMemory.validAddress(value)) { cell.Value = GlobalFunctions.toHex(value); } else { float singleCast = GlobalFunctions.UIntToSingle(value); if (!float.IsNaN(singleCast) && Math.Abs(singleCast) > 1e-7 && Math.Abs(singleCast) < 1e10) { cell.Value = PrettyFloat(GlobalFunctions.UIntToSingle(value)); } else { if (IsASCII(buffer)) { if (viewMode == MemoryViewMode.AutoZero && value == 0) { cell.Value = GlobalFunctions.toHex(value); } else { cell.Value = DecodeASCII(buffer); } } else { cell.Value = GlobalFunctions.toHex(value); } } } } } } oldRow = (int)offset / 0x10; oldCol = (int)(offset & 0xC) / 4 + 1; if (!fast) { gView.Rows[oldRowIndex].Cells[oldColumnIndex].Selected = true; } pokeAddress.Text = GlobalFunctions.toHex(selectedAddress); fpValue.Text = GlobalFunctions.UIntToSingle(pValue).ToString("G6"); } catch (ETCPGeckoException e) { exceptionHandling.HandleException(e); } }
private void UpdateList() { try { int i, j; UInt32[] address; UInt32 peekAddress, actAddress, peekValue; WatchDataSize dataSize; UInt32 dumpAnd; String aOutput, vOutput; UInt32 add; bool pointer, vPointer, vAddress; int maxCount = Math.Min(addressWatchList.Count, watchOut.RowCount); DoubleString[] oUp = new DoubleString[maxCount]; for (i = 0; i < maxCount; i++) { // Skip over any rows that aren't displayed if (!isRowDisplayed(watchOut, i)) { continue; } address = addressWatchList[i].address; pointer = address.Length > 1; dataSize = addressWatchList[i].dataSize; switch (dataSize) { case WatchDataSize.Bit8: dumpAnd = 0xFFFFFFFF; break; case WatchDataSize.Bit16: dumpAnd = 0xFFFFFFFE; break; default: dumpAnd = 0xFFFFFFFC; break; } vPointer = true; peekAddress = address[0]; for (j = 1; j < address.Length; j++) { if (ValidMemory.validAddress(peekAddress, enableDebug)) { peekAddress &= 0xFFFFFFFC; peekAddress = gecko.peek(peekAddress); peekAddress += address[j]; } else { vPointer = false; break; } } vAddress = vPointer && ValidMemory.validAddress(peekAddress, enableDebug); if (pointer) { aOutput = "P->"; if (vPointer) { aOutput += GlobalFunctions.toHex(peekAddress); } else { aOutput += "????????"; } } else { aOutput = GlobalFunctions.toHex(peekAddress); } if (vAddress) { actAddress = peekAddress; peekAddress &= 0xFFFFFFFC; add = actAddress - peekAddress; add &= dumpAnd; peekValue = gecko.peek(peekAddress); vOutput = ParseValue(peekValue, dataSize, add, addressWatchList[i]); addressWatchList[i].addressAvail = true; addressWatchList[i].updatedAddress = peekAddress + add; } else { vOutput = "????????"; addressWatchList[i].addressAvail = false; } oUp[i].address = aOutput; oUp[i].value = vOutput; watchOut.Invoke((MethodInvoker) delegate { watchOut.Rows[i].Cells[1].Value = oUp[i].address; watchOut.Rows[i].Cells[3].Value = oUp[i].value; }); } //watchOut.Invoke((MethodInvoker)delegate // { // for (i = 0; i < maxCount; i++) // { // watchOut.Rows[i].Cells[1].Value = oUp[i].address; // watchOut.Rows[i].Cells[3].Value = oUp[i].value; // } // }); } catch (EUSBGeckoException e) { listEnabled = false; exceptionHandling.HandleException(e); } catch { } }
public void SearchString(byte[] searchBytes, bool caseSensitive, bool unicode, bool hex) { byte[] stringBytes = searchBytes; uint startAddr = selectedAddress + 4; uint endAddress = 0; int dumpLength = (unicode ? 2 : 1); bool found = false; for (int i = 0; i < ValidMemory.ValidAreas.Length; i++) { if (startAddr >= ValidMemory.ValidAreas[i].low && startAddr < ValidMemory.ValidAreas[i].high) { found = true; endAddress = ValidMemory.ValidAreas[i].high; break; } } if (!found) { throw new Exception("Memory area could not be acquired!"); } bool valueFound = false; uint beginAddress = startAddr; MemoryStream ms = new MemoryStream(); uint SearchBufferSize = 0x400 * 256; uint dumpHigh = Math.Min(startAddr + SearchBufferSize, endAddress); try { int index; do { ms.Seek(0, SeekOrigin.End); int startIndex = (int)ms.Position; gecko.Dump(startAddr, dumpHigh, ms); byte[] streamArray = ms.GetBuffer(); index = GlobalFunctions.IndexOfByteArray(streamArray, stringBytes, startIndex, caseSensitive); if (index != -1) { valueFound = true; break; } startAddr = dumpHigh; dumpHigh = Math.Min(startAddr + SearchBufferSize, endAddress); Application.DoEvents(); } while (dumpHigh != endAddress && !valueFound && Searching); if (valueFound) { uint address = (uint)(beginAddress + index); cAddress = address; } else { cAddress = beginAddress - 4; if (dumpHigh == endAddress) { MessageBox.Show("Could not find search query"); } } } catch (ETCPGeckoException exc) { exceptionHandling.HandleException(exc); } }
public String GetStepLog() { String DetailedInstruction = currentInstructionAndAddress; String regDetails; MatchCollection getRegDetails; if (currentInstructionAndAddress == null) { return(String.Empty); } String[] Padding = DetailedInstruction.Split('\t'); // this will help align things if (Padding.Length < 3) { DetailedInstruction += " "; } else if (Padding[2].Length < 8) { for (int i = 8 - Padding[2].Length; i > 0; i--) { DetailedInstruction += " "; } } // Get all the places where there's an LR getRegDetails = Regex.Matches(DetailedInstruction, "lr"); for (int i = 0; i < getRegDetails.Count; i++) { regDetails = "LR = " + GlobalFunctions.toHex(GetRegisterValue(39)); //DetailedInstruction = DetailedInstruction.Insert(getRegDetails[i].Index + getRegDetails[i].Length, regDetails); DetailedInstruction += "\t" + regDetails; } // Get all the places where there's an f0-f31 // TODO: not 0-9 or a-f! // TODO: over matching? switch to trying to find the 0x to determine when not a float reg? //getRegDetails = Regex.Matches(DetailedInstruction, "([^0-9]f[0-9][^0-9])|" + // "([^0-9]f1[0-9][^0-9])|" + // "([^0-9]f2[0-9][^0-9])|" + // "([^0-9]f3[01][^0-9])"); if (!Regex.Match(DetailedInstruction, "0x").Success) { getRegDetails = Regex.Matches(DetailedInstruction, "f[0-9]+"); for (int i = 0; i < getRegDetails.Count; i++) { string floatReg = getRegDetails[i].Value; int index = Int32.Parse(floatReg.Substring(1)) + 40; Single floatVal = GetFloatRegisterValue(index); regDetails = floatReg + " = " + floatVal.ToString("G6"); //DetailedInstruction = DetailedInstruction.Insert(getRegDetails[i].Index + getRegDetails[i].Length, regDetails); DetailedInstruction += "\t" + regDetails; } } // Get all the places where there's an r0-r31 getRegDetails = Regex.Matches(DetailedInstruction, "r[0-9]+"); for (int i = 0; i < getRegDetails.Count; i++) { regDetails = getRegDetails[i].Value + " = " + GlobalFunctions.toHex(GetRegisterValue(Int32.Parse(getRegDetails[i].Value.Substring(1)) + 7)); //DetailedInstruction = DetailedInstruction.Insert(getRegDetails[i].Index + getRegDetails[i].Length, regDetails); DetailedInstruction += "\t" + regDetails; } getRegDetails = Regex.Matches(DetailedInstruction, "\\(r[0-9]+\\)"); for (int i = 0; i < getRegDetails.Count; i++) { if (ValidMemory.validAddress(MemoryAddress)) { regDetails = "[" + GlobalFunctions.toHex(MemoryAddress) + "] = " + GlobalFunctions.toHex(gecko.peek(MemoryAddress)); //DetailedInstruction = DetailedInstruction.Insert(getRegDetails[i].Index + getRegDetails[i].Length, regDetails); if (Regex.Match(DetailedInstruction, "lfd|stfd").Success) { regDetails += GlobalFunctions.toHex(gecko.peek(MemoryAddress + 4)); } DetailedInstruction += "\t" + regDetails; } } //if (IsTakenBranch()) if ((isConditionalBranch(currentInstruction) && BranchTaken(currentInstruction)) || currentInstruction[0] == "b") { DetailedInstruction += "\r\n"; for (int i = 0; i < logIndent; i++) { DetailedInstruction += "| "; } DetailedInstruction += "\t...\t...\t...\t..."; } if (logIndent > 0) { for (int i = 0; i < logIndent; i++) { DetailedInstruction = DetailedInstruction.Insert(0, "| "); } } if (IsBL()) { logIndent++; } if (logIndent > 0 && IsBLR()) { logIndent--; } return(DetailedInstruction); }
private void GetRegisters(Stream regStream) { regStream.Seek(0, SeekOrigin.Begin); String regValue; UInt32 rStream; UInt32[] allReg = new UInt32[72]; for (int i = 0; i < 72; i++) { rStream = GlobalFunctions.ReadStream(regStream); if (i < 40) { changableRegs[i] = rStream; } allReg[i] = rStream; if (i < 40 || ShowFloatsInHex) { regValue = GlobalFunctions.toHex(rStream); } else { regValue = GlobalFunctions.UIntToSingle(rStream).ToString("G8"); } bpOutput.longRegTextBox[i].Text = regValue; // TODO: invoke required? } listSet = true; regStream.Close(); String output = ""; for (int i = 0; i < 72; i++) { output += BPList.longRegNames[bpOutput.longRegIDs[i]] + ":" + GlobalFunctions.toHex(allReg[bpOutput.longRegIDs[i]]); if (i % 4 == 3 && i != 71) { output += "\r\n"; } else if (i % 4 != 3) { output += " "; } if (i == 39) { output += "\r\n"; } } InvokeClassicTextBoxUpdate(output); // Make sure that (SRR0?) contains a valid address // Otherwise we might not be pointing at any valid memory to pass to disassemble if (ValidMemory.validAddress(changableRegs[5])) { UInt32 assAdd = changableRegs[5]; PHitAddress = assAdd; // cache this for later // Fill an array of strings with instructions // TODO: subtract back some so we can see what comes BEFORE the assembly address... String[] assembly = disassembler.DissToBox(assAdd); // Grab the first (i.e. current) instruction if (assembly.Length > 0) { String fCommand = assembly[0]; currentInstructionAndAddress = fCommand; fCommand = fCommand.Substring(20, fCommand.Length - 20); // Split it along tabs so we can extract the operation String[] sep = fCommand.Split(new char[1] { '\t' }, StringSplitOptions.RemoveEmptyEntries); currentInstruction = sep; fCommand = sep[0].ToLower(); // If we're doing a branch-and-link, make a note that we can step over it stepOverPossible = (fCommand == "bl" || fCommand == "bctrl"); GetMemoryAddress(sep); UpdateBranchState(sep); } InvokeDissBoxUpdate(assembly); } }
private void GetRegisters(Stream regStream) { regStream.Seek(0, SeekOrigin.Begin); string regValue; uint rStream; uint[] allReg = new uint[72]; for (int i = 0; i < 72; i++) { rStream = GlobalFunctions.ReadStream(regStream); if (i < 40) { changableRegs[i] = rStream; } allReg[i] = rStream; if (i < 40 || ShowFloatsInHex) { regValue = GlobalFunctions.toHex(rStream); } else { regValue = GlobalFunctions.UIntToSingle(rStream).ToString("G8"); } if (i > 40) { GlobalFunctions.ReadStream(regStream); } bpOutput.longRegTextBox[i].Text = regValue; } listSet = true; regStream.Close(); string output = string.Empty; for (int i = 0; i < 72; i++) { output += BPList.longRegNames[bpOutput.longRegIDs[i]] + ":" + GlobalFunctions.toHex(allReg[bpOutput.longRegIDs[i]]); if (i % 4 == 3 && i != 71) { output += "\r\n"; } else if (i % 4 != 3) { output += " "; } if (i == 39) { output += "\r\n"; } } InvokeClassicTextBoxUpdate(output); if (ValidMemory.validAddress(changableRegs[5])) { uint assAdd = changableRegs[5]; hitAddress = assAdd; string[] assembly = disassembler.DissToBox(assAdd); if (assembly.Length > 0) { string fCommand = assembly[0]; currentInstructionAndAddress = fCommand; fCommand = fCommand.Substring(20, fCommand.Length - 20); string[] sep = fCommand.Split(new char[1] { '\t' }, StringSplitOptions.RemoveEmptyEntries); currentInstruction = sep; fCommand = sep[0].ToLower(); stepOver = (fCommand == "bl" || fCommand == "bctrl"); GetMemoryAddress(sep); UpdateBranchState(sep); } InvokeDissBoxUpdate(assembly); } }
public string GetStepLog() { string DetailedInstruction = currentInstructionAndAddress; string regDetails; MatchCollection getRegDetails; if (currentInstructionAndAddress == null) { return(string.Empty); } string[] Padding = DetailedInstruction.Split('\t'); if (Padding.Length < 3) { DetailedInstruction += " "; } else if (Padding[2].Length < 8) { for (int i = 8 - Padding[2].Length; i > 0; i--) { DetailedInstruction += " "; } } getRegDetails = Regex.Matches(DetailedInstruction, "lr"); for (int i = 0; i < getRegDetails.Count; i++) { regDetails = "LR = " + GlobalFunctions.toHex(GetRegisterValue(39)); DetailedInstruction += "\t" + regDetails; } if (!Regex.Match(DetailedInstruction, "0x").Success) { getRegDetails = Regex.Matches(DetailedInstruction, "f[0-9]+"); for (int i = 0; i < getRegDetails.Count; i++) { string floatReg = getRegDetails[i].Value; int index = int.Parse(floatReg.Substring(1)) + 40; float floatVal = GetFloatRegisterValue(index); regDetails = floatReg + " = " + floatVal.ToString("G6"); DetailedInstruction += "\t" + regDetails; } } getRegDetails = Regex.Matches(DetailedInstruction, "r[0-9]+"); for (int i = 0; i < getRegDetails.Count; i++) { regDetails = getRegDetails[i].Value + " = " + GlobalFunctions.toHex(GetRegisterValue(int.Parse(getRegDetails[i].Value.Substring(1)) + 7)); DetailedInstruction += "\t" + regDetails; } getRegDetails = Regex.Matches(DetailedInstruction, "\\(r[0-9]+\\)"); for (int i = 0; i < getRegDetails.Count; i++) { if (ValidMemory.validAddress(MemoryAddress)) { regDetails = "[" + GlobalFunctions.toHex(MemoryAddress) + "] = " + GlobalFunctions.toHex(gecko.peek(MemoryAddress)); if (Regex.Match(DetailedInstruction, "lfd|stfd").Success) { regDetails += GlobalFunctions.toHex(gecko.peek(MemoryAddress + 4)); } DetailedInstruction += "\t" + regDetails; } } if ((isConditionalBranch(currentInstruction) && BranchTaken(currentInstruction)) || currentInstruction[0] == "b") { DetailedInstruction += "\r\n"; for (int i = 0; i < logIndent; i++) { DetailedInstruction += "| "; } DetailedInstruction += "\t...\t...\t...\t..."; } if (logIndent > 0) { for (int i = 0; i < logIndent; i++) { DetailedInstruction = DetailedInstruction.Insert(0, "| "); } } if (IsBL()) { logIndent++; } if (logIndent > 0 && IsBLR()) { logIndent--; } return(DetailedInstruction); }
public string[] Disassemble(uint address, int commands) { List <string> result = new List <string>(); address = address & 0xFFFFFFFC; uint eAddress = address + (uint)commands * 4; if (!File.Exists(vdappPath)) { #if MONO return(new String[] { "vdappc not found!" }); #else return(new string[] { "vdappc.exe not found!" }); #endif } FileStream values; string filename = System.IO.Path.GetTempFileName(); try { values = new FileStream(filename, FileMode.Create); } catch (Exception) { return(new string[] { "Couldn't open diss.bin!" }); } try { gecko.Dump(address, eAddress, values); } catch (ETCPGeckoException e) { exceptionHandling.HandleException(e); return(result.ToArray()); } finally { values.Close(); } Process proc = new Process(); proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.FileName = vdappPath; proc.StartInfo.Arguments = "\"" + filename + "\" 0x" + GlobalFunctions.toHex(address); proc.StartInfo.CreateNoWindow = true; proc.Start(); while (!proc.StandardOutput.EndOfStream) { result.Add(proc.StandardOutput.ReadLine()); } proc.WaitForExit(); proc.Close(); File.Delete(filename); return(result.ToArray()); }
private bool CompareRefactored(uint given, uint loExpected, ComparisonType cType, uint diffBy, bool floatCompare) { if (floatCompare) { float givenSingle = GlobalFunctions.UIntToSingle(given), loExpectedSingle = GlobalFunctions.UIntToSingle(loExpected), diffBySingle = GlobalFunctions.UIntToSingle(diffBy); if (float.IsNaN(givenSingle) || float.IsNaN(loExpectedSingle) || float.IsNaN(diffBySingle)) { return(false); } switch (cType) { case ComparisonType.Equal: return(givenSingle == loExpectedSingle); case ComparisonType.NotEqual: return(givenSingle != loExpectedSingle); case ComparisonType.Greater: return(givenSingle > loExpectedSingle); case ComparisonType.GreaterEqual: return(givenSingle >= loExpectedSingle); case ComparisonType.Lower: return(givenSingle < loExpectedSingle); case ComparisonType.LowerEqual: return(givenSingle <= loExpectedSingle); case ComparisonType.DifferentBy: return(loExpectedSingle - diffBySingle == givenSingle || loExpectedSingle + diffBySingle == givenSingle); case ComparisonType.DifferentByLess: return(loExpectedSingle - diffBySingle < givenSingle && givenSingle < loExpectedSingle + diffBySingle); case ComparisonType.DifferentByMore: return(givenSingle < loExpectedSingle - diffBySingle || givenSingle > loExpectedSingle + diffBySingle); default: return(givenSingle == loExpectedSingle); } } else { switch (cType) { case ComparisonType.Equal: return(given == loExpected); case ComparisonType.NotEqual: return(given != loExpected); case ComparisonType.Greater: return(given > loExpected); case ComparisonType.GreaterEqual: return(given >= loExpected); case ComparisonType.Lower: return(given < loExpected); case ComparisonType.LowerEqual: return(given <= loExpected); case ComparisonType.DifferentBy: return(loExpected - diffBy == given || loExpected + diffBy == given); case ComparisonType.DifferentByLess: return(loExpected - diffBy < given && given < loExpected + diffBy); case ComparisonType.DifferentByMore: return(given < loExpected - diffBy || given > loExpected + diffBy); default: return(given == loExpected); } } }
private void PrintPageAlt() { if (cPage <= 0) { cPage = 0; prvButton.Enabled = false; } else { prvButton.Enabled = true; } if (cPage >= cPages - 1) { cPage = cPages - 1; if (cPage < 0) { cPage = 0; } nxButton.Enabled = false; } else { nxButton.Enabled = (cPages > 1); } resLab.Text = resultAddressList.Count.ToString() + " results (" + cPages.ToString() + " pages)"; int i = 0; string addr, value, oldv, diff; int strLength; switch (sSize) { case SearchSize.Bit8: strLength = 2; break; case SearchSize.Bit16: strLength = 4; break; default: strLength = 8; break; } int searchBytes = strLength / 2; int start = cPage * pageSize; int end = Math.Min(cPage * pageSize + pageSize, resultAddressList.Count); int count = end - start; if (count < gView.Rows.Count) { gView.Rows.Clear(); } int addCount = count - gView.Rows.Count; if (addCount > 0) { gView.Rows.Add(addCount); } for (int j = start; j < end; j++) { SearchResult result; if (oldDump == null) { result = new SearchResult(resultAddressList[j], newDump.ReadAddress(resultAddressList[j], searchBytes), 0); } else { result = new SearchResult(resultAddressList[j], newDump.ReadAddress(resultAddressList[j], searchBytes), oldDump.ReadAddress(resultAddressList[j], searchBytes)); } addr = fixString(Convert.ToString(result.address, 16).ToUpper(), 8); if (DisplayType == "Hex") { value = fixString(Convert.ToString(result.value, 16).ToUpper(), strLength); oldv = fixString(Convert.ToString(result.oldValue, 16).ToUpper(), strLength); diff = fixString(Convert.ToString(result.value - result.oldValue, 16).ToUpper(), strLength); } else if (DisplayType == "Dec") { value = ((int)result.value).ToString(); oldv = ((int)result.oldValue).ToString(); diff = ((int)(result.value - result.oldValue)).ToString(); } else { float floatVal = GlobalFunctions.UIntToSingle(result.value); float floatOldVal = GlobalFunctions.UIntToSingle(result.oldValue); value = floatVal.ToString("g5"); oldv = floatOldVal.ToString("g5"); diff = (floatVal - floatOldVal).ToString("g5"); } gView.Rows[i].Cells[0].Value = addr; if (InitialSearch) { gView.Rows[i].Cells[1].Value = string.Empty; gView.Rows[i].Cells[3].Value = string.Empty; } else if (resultAddressList[i] < oldDump.StartAddress || resultAddressList[i] > oldDump.EndAddress - searchBytes) { gView.Rows[i].Cells[1].Value = "N/A"; gView.Rows[i].Cells[3].Value = "N/A"; } else { gView.Rows[i].Cells[1].Value = oldv; gView.Rows[i].Cells[3].Value = diff; } gView.Rows[i].Cells[2].Value = value; i++; } }