예제 #1
0
        private void MainBoxClick(object sender, EventArgs e)
        {
            int index = mainBox.SelectedIndex;

            // If index is negative, bail out
            if (index == -1)
            {
                asAddress.Text = GlobalFunctions.toHex(cAddress);
                asText.Text    = "";
                return;
            }

            // When user clicks, update the selected address
            UInt32 address = cAddress + (UInt32)index * 4;

            asAddress.Text = GlobalFunctions.toHex(address);
            selAddress     = address;

            // Split the assembly instruction along tabs and put it in the "one-line assembler"
            String assembly = mainBox.Items[index].ToString();

            assembly = assembly.Substring(20, assembly.Length - 20);
            String[] sep = assembly.Split(new char[1] {
                '\t'
            }, StringSplitOptions.RemoveEmptyEntries);
            assembly = "";
            for (int i = 0; i < sep.Length; i++)
            {
                assembly += sep[i] + " ";
            }
            //assembly = assembly.Trim();
            asText.Text = assembly;
        }
예제 #2
0
        public static String addressToString(UInt32[] address)
        {
            if (address.Length == 0)
            {
                return("");
            }
            String output = GlobalFunctions.toHex(address[0]);
            UInt32 cv;
            char   op;

            for (int i = 1; i < address.Length; i++)
            {
                output = "[" + output + "]";
                cv     = address[i];
                if (address[i] > 0x80000000)
                {
                    op = '-';
                    cv = (UInt32)((long)0x100000000 - (long)cv);
                }
                else
                {
                    op = '+';
                }
                output += op + GlobalFunctions.shortHex(cv);
            }
            return(output);
        }
예제 #3
0
        public static string addressToString(uint[] address)
        {
            if (address.Length == 0)
            {
                return(string.Empty);
            }
            string output = GlobalFunctions.toHex(address[0]);
            uint   cv;
            char   op;

            for (int i = 1; i < address.Length; i++)
            {
                output = "[" + output + "]";
                cv     = address[i];
                if (address[i] > 0x80000000)
                {
                    op = '-';
                    cv = (uint)(0x100000000 - (long)cv);
                }
                else
                {
                    op = '+';
                }
                output += op + GlobalFunctions.shortHex(cv);
            }
            return(output);
        }
예제 #4
0
        public override String ToString()
        {
            String result = GroupNumber + ": ";

            if (PRegister >= BPList.longRegNames.Length)
            {
                result += "VoA ";
            }
            else
            {
                result += BPList.longRegNames[PRegister].Trim() + " ";
            }
            switch (PCondition)
            {
            case BreakpointComparison.Equal:
                result += "=="; break;

            case BreakpointComparison.NotEqual:
                result += "!="; break;

            case BreakpointComparison.Greater:
                result += ">"; break;

            case BreakpointComparison.GreaterEqual:
                result += ">="; break;

            case BreakpointComparison.Lower:
                result += "<"; break;

            case BreakpointComparison.LowerEqual:
                result += "<="; break;
            }
            result += " " + GlobalFunctions.toHex(PValue);
            return(result);
        }
예제 #5
0
        private void MainBoxClick(object sender, EventArgs e)
        {
            int index = mainBox.SelectedIndex;

            if (index == -1)
            {
                asAddress.Text = GlobalFunctions.toHex(cAddress);
                asText.Text    = string.Empty;
                return;
            }

            uint address = cAddress + (uint)index * 4;

            asAddress.Text = GlobalFunctions.toHex(address);
            disAddress     = address;

            string assembly = mainBox.Items[index].ToString();

            assembly = assembly.Substring(20, assembly.Length - 20);
            string[] sep = assembly.Split(new char[1] {
                '\t'
            }, StringSplitOptions.RemoveEmptyEntries);
            assembly = string.Empty;
            for (int i = 0; i < sep.Length; i++)
            {
                assembly += sep[i] + " ";
            }
            asText.Text = assembly;
        }
예제 #6
0
        private string ParseValue(uint peekValue, WatchDataSize dataSize, uint add, WatchEntry entry)
        {
            string pOutput = string.Empty;
            uint   val;
            float  floatV;

            switch (dataSize)
            {
            case WatchDataSize.Bit8:
                switch (add)
                {
                case 0:
                    val = ((peekValue & 0xFF000000) >> 24);
                    break;

                case 1:
                    val = ((peekValue & 0x00FF0000) >> 16);
                    break;

                case 2:
                    val = ((peekValue & 0x0000FF00) >> 8);
                    break;

                default:
                    val = ((peekValue & 0x000000FF) >> 0);
                    break;
                }
                entry.lastValue = val;
                pOutput         = GlobalFunctions.toHex(val, 2);
                break;

            case WatchDataSize.Bit16:
                switch (add)
                {
                case 0:
                    val = ((peekValue & 0xFFFF0000) >> 16);
                    break;

                default:
                    val = ((peekValue & 0x0000FFFF) >> 0);
                    break;
                }
                entry.lastValue = val;
                pOutput         = GlobalFunctions.toHex(val, 4);
                break;

            case WatchDataSize.Bit32:
                entry.lastValue = peekValue;
                pOutput         = GlobalFunctions.toHex(peekValue);
                break;

            default:
                entry.lastValue = peekValue;
                floatV          = GlobalFunctions.UIntToSingle(peekValue);
                pOutput         = floatV.ToString("G6");
                break;
            }
            return(pOutput);
        }
예제 #7
0
        private bool extractTargetAddress(UInt32 address, ref String command)
        {
            if (command.ToLower().Contains("lr") || command.Contains("ctr"))
            {
                return(true);
            }
            String[] parts = command.ToLower().Split(new char[1] {
                ' '
            });
            String[] orgparts = command.Split(new char[1] {
                ' '
            });
            String numeric = parts[parts.Length - 1];
            String number;
            bool   hex;

            if (numeric.Substring(0, 2) == "0x")
            {
                number = numeric.Substring(2, numeric.Length - 2);
                hex    = true;
            }
            else
            {
                number = numeric;
                hex    = false;
            }

            UInt32 tAddress;
            bool   result;

            if (hex)
            {
                result = GlobalFunctions.tryToHex(number, out tAddress);
            }
            else
            {
                result = UInt32.TryParse(number, out tAddress);
            }

            if (result)
            {
                Int32 offset = (Int32)((long)tAddress - (long)address);
                orgparts[orgparts.Length - 1] = "0x" + GlobalFunctions.toHex(offset);
                command = "";
                for (int i = 0; i < orgparts.Length; i++)
                {
                    command += orgparts[i] + " ";
                }
                command = command.Trim();
            }

            return(result);
        }
예제 #8
0
        public bool ShowDialog(UInt32 address, ref UInt32 value, int maxLength)
        {
            this.InstLab.Text     = "Poking address " + GlobalFunctions.toHex(address) + ":";
            this.PValue.Text      = GlobalFunctions.toHex(value, maxLength);
            this.PValue.MaxLength = maxLength;
            bool result = (this.ShowDialog() == DialogResult.OK);

            if (result)
            {
                value = inputValue;
            }
            return(result);
        }
예제 #9
0
        private void GenSwapButtonClick(object sender, EventArgs e)
        {
            if (sourceFile == null || targetFile == null)
            {
                return;
            }
            UInt32 code = sourceFile.dataAddress - 0x79FFFFFC;

            generatedSwapCode.Text =
                GlobalFunctions.toHex(code) + " 00000008\r\n" +
                GlobalFunctions.toHex(targetFile.offset) + " " +
                GlobalFunctions.toHex(targetFile.entries);
        }
예제 #10
0
        public bool SetRegister(string name, ref uint value)
        {
            InstLab.Text = "You are about to change the value stored in the register " + name +
                           ". Please type in the new value and click OK to set it or Cancel to abort.";
            RegVal.Text = "Value of register " + name + ":";
            RValue.Text = GlobalFunctions.toHex(value);
            setValue    = value;

            if (this.ShowDialog() == DialogResult.OK)
            {
                value = setValue;
                return(true);
            }

            return(false);
        }
예제 #11
0
        private void CellSelectionChange(object sender, EventArgs e)
        {
            UInt32 sAddress = cAddress & 0xFFFFFFF0;

            if (gView.SelectedCells.Count > 0)
            {
                int col = gView.SelectedCells[0].ColumnIndex;
                int row = gView.SelectedCells[0].RowIndex;
                if (col == 0)
                {
                    gView.Rows[oldRow].Cells[oldCol].Selected = true;
                }
                else
                {
                    oldCol = col;
                    oldRow = row;
                    UInt32 addr = (UInt32)(sAddress + row * 16 + (col - 1) * 4);

                    // Nothing to update if the address didn't change
                    if (selAddress == addr)
                    {
                        return;
                    }

                    selAddress       = addr;
                    pokeAddress.Text = GlobalFunctions.toHex(addr);
                    try
                    {
                        UInt32 locValue = 0;
                        if (gecko.connected)
                        {
                            locValue = gecko.peek(addr);
                        }
                        pokeValue.Text = GlobalFunctions.toHex(locValue);
                        fpValue.Text   = GlobalFunctions.UIntToSingle(locValue).ToString("G6");
                    }
                    catch (EUSBGeckoException exc)
                    {
                        exceptionHandling.HandleException(exc);
                    }
                }
            }
        }
예제 #12
0
        public String[] DissToBox(UInt32 address)
        {
            cAddress = address & 0xFFFFFFFC;
            String[] assembly = Disassemble(address, 60);

            mainBox.Items.Clear();
            for (int i = 0; i < assembly.Length; i++)
            {
                mainBox.Items.Add(assembly[i]);
            }

            adressInput.Text = GlobalFunctions.toHex(cAddress);

            if (mainBox.Items.Count > 0)
            {
                mainBox.SelectedIndex = 0;
            }

            return(assembly);
        }
예제 #13
0
        private void CellSelectionChange(object sender, EventArgs e)
        {
            uint sAddress = cAddress & 0xFFFFFFF0;

            if (gView.SelectedCells.Count > 0)
            {
                int col = gView.SelectedCells[0].ColumnIndex;
                int row = gView.SelectedCells[0].RowIndex;
                if (col == 0)
                {
                    gView.Rows[oldRow].Cells[oldCol].Selected = true;
                }
                else
                {
                    oldCol = col;
                    oldRow = row;
                    uint addr = (uint)(sAddress + row * 16 + (col - 1) * 4);

                    if (selectedAddress == addr)
                    {
                        return;
                    }

                    selectedAddress  = addr;
                    pokeAddress.Text = GlobalFunctions.toHex(addr);
                    try
                    {
                        uint locValue = gecko.peek(addr);
                        pokeValue.Text = GlobalFunctions.toHex(locValue);
                        fpValue.Text   = GlobalFunctions.UIntToSingle(locValue).ToString("G6");
                    }
                    catch (ETCPGeckoException exc)
                    {
                        exceptionHandling.HandleException(exc);
                    }
                }
            }
        }
예제 #14
0
        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;
        }
예제 #15
0
        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);
            }
        }
예제 #16
0
        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);
        }
예제 #17
0
        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());
        }
예제 #18
0
        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);
            }
        }
예제 #19
0
        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);
            }
        }
예제 #20
0
        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());
        }
예제 #21
0
        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
            {
            }
        }
예제 #22
0
        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);
        }
예제 #23
0
        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);
            }
        }