public void DumpTree() { //address will be alligned to 4 UInt32 paddress = 0x80000038; //Create a memory stream for the actual dump MemoryStream stream = new MemoryStream(); try { //dump data gecko.Dump(paddress, paddress + 8, stream); //go to beginning stream.Seek(0, SeekOrigin.Begin); Byte[] buffer = new Byte[8]; stream.Read(buffer, 0, 8); //Stream can be cleared now stream.Close(); //Read buffer UInt32 fstadd = BitConverter.ToUInt32(buffer, 0); UInt32 fstsize = BitConverter.ToUInt32(buffer, 4); //Swap to machine endianness and return fstadd = ByteSwap.Swap(fstadd); fstsize = ByteSwap.Swap(fstsize); stream = new MemoryStream(); gecko.Dump(fstadd, fstadd + fstsize + 1, stream); stream.Seek(-1, SeekOrigin.End); buffer = new Byte[] { 0xFF }; stream.Write(buffer, 0, 1); stream.Seek(0, SeekOrigin.Begin); buffer = new Byte[0xC]; stream.Read(buffer, 0, 12); Byte flag = buffer[0]; UInt32 truenameoff; buffer[0] = 0; UInt32 nameoff = ByteSwap.Swap(BitConverter.ToUInt32(buffer, 0)); UInt32 offset = ByteSwap.Swap(BitConverter.ToUInt32(buffer, 4)); UInt32 entries = ByteSwap.Swap(BitConverter.ToUInt32(buffer, 8)); long fstpos = stream.Position; UInt32 strpos = entries * 0x0C; UInt32 endpos = strpos; //List<TreeNode> rootArr = new List<TreeNode>(); List <fileStructure> rootArr = new List <fileStructure>(); List <UInt32> dirSize = new List <UInt32>(); dirSize.Add(0); fstTextPositions.Clear(); sourceFile = null; targetFile = null; generatedSwapCode.Text = ""; targetFileName.Text = ""; sourceFileName.Text = ""; setAsSourceButton.Enabled = false; setAsTargetButton.Enabled = false; generateFileSwap.Enabled = false; swapFilesNow.Enabled = false; selectedFile = -1; //TreeNode current = treeView.Nodes.Add("Root"); fileStructure current = new fileStructure("Root", -1); root = current; int tag; int curDir = 0; rootArr.Add(current); String nname; do { stream.Seek(fstpos, SeekOrigin.Begin); stream.Read(buffer, 0, 12); flag = buffer[0]; truenameoff = ByteSwap.Swap(BitConverter.ToUInt32(buffer, 0)); buffer[0] = 0; nameoff = ByteSwap.Swap(BitConverter.ToUInt32(buffer, 0)); offset = ByteSwap.Swap(BitConverter.ToUInt32(buffer, 4)); entries = ByteSwap.Swap(BitConverter.ToUInt32(buffer, 8)); fstTextPositions.Add(new fstEntry((UInt32)fstpos + fstadd, truenameoff, offset, entries, (UInt32)fstpos + strpos + nameoff)); tag = fstTextPositions.Count - 1; fstpos = stream.Position; stream.Seek(strpos + nameoff, SeekOrigin.Begin); //fstTextPositions.Add((UInt32)stream.Position + fstadd); nname = ReadString(stream); do { if (fstpos == dirSize[curDir] * 0x0C + 0x0C && curDir > 0) { dirSize[curDir] = 0; curDir--; } } while (curDir != 0 && fstpos >= dirSize[curDir] * 0x0C + 0x0C); if (flag == 0) { //current = rootArr[curDir].Nodes.Add(nname); rootArr[curDir].addFile(nname, tag); //image crap } else { curDir++; current = rootArr[curDir - 1].addSubFolder(nname, tag); //current = rootArr[curDir-1].Nodes.Add(nname); //image crap if (rootArr.Count > curDir) { rootArr[curDir] = current; dirSize[curDir] = entries; } else { rootArr.Add(current); dirSize.Add(entries); } } } while (fstpos < endpos); stream.Close(); root.Sort(); root.ToTreeView(treeView); } catch (EUSBGeckoException e) { exceptionHandling.HandleException(e); } catch { } }
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 { try { if (gecko.connected) { gecko.Dump(sAddress, sAddress + 0x100, miniDump); } } catch (EUSBGeckoException e) { exceptionHandling.HandleException(e); // MessageBox.Show("USBGecko not connected!\n", "Update error", // MessageBoxButtons.OK, MessageBoxIcon.Warning); miniDump.SetLength(0x100); } //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 (EUSBGeckoException e) { exceptionHandling.HandleException(e); } catch { MessageBox.Show("Unknown error while updating memory view!\n", "Update error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
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()); }