BlockRead() public static method

public static BlockRead ( uint addr, byte buffer, int length ) : int
addr uint
buffer byte
length int
return int
Beispiel #1
0
        private void MemoryButtonClick(object sender, EventArgs e)
        {
            uint addr = 0;

            byte[] block = new byte[180];

            if (String.IsNullOrEmpty(memOffset.Text))
            {
                addr = 0;
            }
            else
            {
                try
                {
                    addr = uint.Parse(memOffset.Text, NumberStyles.HexNumber);
                }
                catch
                {
                    MessageBox.Show(Resources.Invalid_address, Resources.ErrorTitle);
                }
            }

            Memory.BlockRead(addr, block, block.Length);

            memoryChar.Text  = ((char)block[0]).ToString();
            memoryByte.Text  = block[0].ToString("X2");
            memoryWord.Text  = ((ushort)(block[0] | block[1] << 8)).ToString("X4");
            memoryDWord.Text = ((uint)(block[0] | block[1] << 8 | block[2] << 16 | block[3] << 24)).ToString("X8");

            string memBlock = "";
            string charList = "";
            int    offset   = 0;

            memoryList.Items.Clear();
            memoryCharList.Items.Clear();

            for (int i = 0; i < block.Length / 18; i++)
            {
                for (offset = 0; offset < 18; offset++)
                {
                    byte b = block[i * 18 + offset];
                    memBlock += b.ToString("X2") + " ";

                    char c = Convert.ToChar(b);
                    if (Char.IsControl(c))
                    {
                        c = '.';
                    }
                    charList += c + " ";
                }

                memoryList.Items.Add(memBlock);
                memoryCharList.Items.Add(charList);
                memBlock = "";
                charList = "";
            }
        }
Beispiel #2
0
        private void MemoryButtonClick(object sender, EventArgs e)
        {
            uint addr = 0;

            byte[] block = new byte[180];

            if (String.IsNullOrEmpty(memOffset.Text))
            {
                addr = 0;
            }
            else
            {
                // try register names first
                switch (memOffset.Text.ToUpper())
                {
                case "EAX":
                    addr = machine.CPU.EAX;
                    break;

                case "EBX":
                    addr = machine.CPU.EBX;
                    break;

                case "ECX":
                    addr = machine.CPU.ECX;
                    break;

                case "EDX":
                    addr = machine.CPU.EDX;
                    break;

                case "ESI":
                    addr = machine.CPU.ESI;
                    break;

                case "EDI":
                    addr = machine.CPU.EDI;
                    break;

                case "EBP":
                    addr = machine.CPU.EBP;
                    break;

                case "ESP":
                    addr = machine.CPU.ESP;
                    break;

                case "EIP":
                    addr = machine.CPU.EIP;
                    break;

                default:
                    break;
                }

                // try parse value instead
                if (addr == 0)
                {
                    try
                    {
                        addr = uint.Parse(memOffset.Text, NumberStyles.HexNumber);
                    }
                    catch
                    {
                        MessageBox.Show(Resources.Invalid_address, Resources.ErrorTitle);
                    }
                }
            }

            Memory.BlockRead(addr, block, block.Length);

            memoryChar.Text  = ((char)block[0]).ToString();
            memoryByte.Text  = block[0].ToString("X2");
            memoryWord.Text  = ((ushort)(block[0] | block[1] << 8)).ToString("X4");
            memoryDWord.Text = ((uint)(block[0] | block[1] << 8 | block[2] << 16 | block[3] << 24)).ToString("X8");

            string memBlock   = "";
            string charList   = "";
            string disasmList = "";
            int    offset     = 0;

            memoryList.Items.Clear();
            memoryCharList.Items.Clear();
            memoryDisasmList.Items.Clear();

            for (int i = 0; i < block.Length / 18; i++)
            {
                for (offset = 0; offset < 18; offset++)
                {
                    // generate byte lines (TODO: add option for byte, word, dword, float, signed/unsigned int etc)
                    byte b = block[i * 18 + offset];
                    memBlock += b.ToString("X2") + " ";

                    // generate character view
                    char c = Convert.ToChar(b);
                    if (Char.IsControl(c))
                    {
                        c = '.';
                    }
                    charList += c + " ";
                }


                memoryList.Items.Add(memBlock);
                memoryCharList.Items.Add(charList);
                memBlock = "";
                charList = "";
            }

            // fill disasm list
            var disassm = new x86Disasm.Disassembler(new x86Disasm.ReadCallback(DisassemblerRead));

            uint DisassemblerRead(uint offs, int size)
            {
                return(Memory.Read(addr + offs, size));
            }

            uint index = 0;

            while (memoryDisasmList.Items.Count < 12)
            {
                int len = disassm.Disassemble(addr + index);
                // TODO: addr     bytes       opcode (disassmeble)
                disasmList = $"{block[index].ToString("X8").PadRight(9)}: {disassm.InstructionText}";
                memoryDisasmList.Items.Add(disasmList);
                disasmList = "";
                index     += (uint)len;
            }
        }