Пример #1
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);
        }
Пример #2
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);
                    }
                }
            }
        }
Пример #3
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);
                    }
                }
            }
        }
Пример #4
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);
            }
        }
Пример #5
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);
            }
        }
Пример #6
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);
            }
        }
Пример #7
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);
            }
        }
Пример #8
0
        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);
                }
            }
        }
Пример #9
0
        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++;
            }
        }