Ejemplo n.º 1
0
        private string WriteMemory(GDBPacket packet)
        {
            var parameters = packet.GetCommandParameters();

            if (parameters.Length < 3)
            {
                return(GetErrorAnswer(Errno.ENOENT));
            }
            var arg1 = Convert.ToUInt32(parameters[0], 16);
            var arg2 = Convert.ToUInt32(parameters[1], 16);

            if (arg1 > ushort.MaxValue || arg2 > ushort.MaxValue)
            {
                return(GetErrorAnswer(Errno.ENOENT));
            }
            var addr   = (ushort)arg1;
            var length = (ushort)arg2;

            for (var i = 0; i < length; i++)
            {
                var hex   = parameters[2].Substring(i * 2, 2);
                var value = Convert.ToByte(hex, 16);
                _target.CPU.WRMEM((ushort)(addr + i), value);
            }
            return(StandartAnswers.OK);
        }
Ejemplo n.º 2
0
        private string GeneralQueryResponse(GDBPacket packet)
        {
            string command = packet.GetCommandParameters()[0];

            if (command.StartsWith("Supported"))
            {
                return("PacketSize=4000");
            }
            if (command.StartsWith("C"))
            {
                return(StandartAnswers.Empty);
            }
            if (command.StartsWith("Attached"))
            {
                return("1");
            }
            if (command.StartsWith("TStatus"))
            {
                return(StandartAnswers.Empty);
            }
            if (command.StartsWith("Offset"))
            {
                return(StandartAnswers.Error);
            }
            return(StandartAnswers.OK);
        }
Ejemplo n.º 3
0
        private string ReadMemory(GDBPacket packet)
        {
            var parameters = packet.GetCommandParameters();

            if (parameters.Length < 2)
            {
                return(GetErrorAnswer(Errno.EPERM));
            }
            var arg1 = Convert.ToUInt32(parameters[0], 16);
            var arg2 = Convert.ToUInt32(parameters[1], 16);

            if (arg1 > ushort.MaxValue || arg2 > ushort.MaxValue)
            {
                return(GetErrorAnswer(Errno.EPERM));
            }
            var addr   = (ushort)arg1;
            var length = (ushort)arg2;
            var result = string.Empty;

            for (var i = 0; i < length; i++)
            {
                var hex = _target.CPU.RDMEM((ushort)(addr + i))
                          .ToLowEndianHexString();
                result += hex;
            }
            return(result);
        }
Ejemplo n.º 4
0
        private string RemoveBreakpoint(GDBPacket packet)
        {
            string[] parameters            = packet.GetCommandParameters();
            Breakpoint.BreakpointType type = Breakpoint.GetBreakpointType(int.Parse(parameters[0]));
            ushort addr = Convert.ToUInt16(parameters[1], 16);

            _target.RemoveBreakpoint(type, addr);

            return(StandartAnswers.OK);
        }
Ejemplo n.º 5
0
        private string WriteRegisters(GDBPacket packet)
        {
            var regsData = packet.GetCommandParameters()[0];

            for (int i = 0, pos = 0; i < RegistersCount; i++)
            {
                int currentRegisterLength = GetRegisterSize(i) == RegisterSize.Word ? 4 : 2;
                SetRegister(i, regsData.Substring(pos, currentRegisterLength));
                pos += currentRegisterLength;
            }
            return(StandartAnswers.OK);
        }
Ejemplo n.º 6
0
        private string ExecutionRequest(GDBPacket packet)
        {
            string command = packet.GetCommandParameters()[0];

            if (command.StartsWith("Cont?"))
            {
                return("");
            }
            if (command.StartsWith("Cont"))
            {
            }
            return(StandartAnswers.Empty);
        }
Ejemplo n.º 7
0
        private string SetRegister(GDBPacket packet)
        {
            var parameters = packet.GetCommandParameters()[0].Split(new char[] { '=' });

            if (SetRegister(Convert.ToInt32(parameters[0], 16), parameters[1]))
            {
                return(StandartAnswers.OK);
            }
            else
            {
                return(StandartAnswers.Error);
            }
        }
Ejemplo n.º 8
0
        private string ReadMemory(GDBPacket packet)
        {
            var parameters = packet.GetCommandParameters();

            if (parameters.Length < 2)
            {
                return(GetErrorAnswer(Errno.EPERM));
            }
            var arg1 = Convert.ToUInt32(parameters[0], 16);
            var arg2 = Convert.ToUInt32(parameters[1], 16);

            if (arg1 > uint.MaxValue || arg2 > uint.MaxValue)
            {
                return(GetErrorAnswer(Errno.EPERM));
            }
            var addr   = (uint)arg1;
            var length = (uint)arg2;
            var result = string.Empty;

            for (uint i = 0; i < length;)
            {
                uint remain = length - i;
                if (remain > 64)
                {
                    remain = 64;
                }

                byte[] get = _target.RDMEM((uint)(addr + i), (uint)remain);

                for (int j = 0; j < get.Length; j++)
                {
                    var hex = get[j].ToLowEndianHexString().ToLower();
                    result += hex;
                }


                if ((get.Length == 0) && (i == 0))
                {
                    return(GetErrorAnswer(Errno.EFAULT));
                }
                else if (get.Length != remain)
                {
                    return(result);
                }



                i += remain;
            }
            return(result);
        }
Ejemplo n.º 9
0
        private string WriteMemory(GDBPacket packet)
        {
            var parameters = packet.GetCommandParameters();

            if (parameters.Length < 3)
            {
                return(GetErrorAnswer(Errno.ENOENT));
            }
            var arg1 = Convert.ToUInt32(parameters[0], 16);
            var arg2 = Convert.ToUInt32(parameters[1], 16);

            if (arg1 > uint.MaxValue || arg2 > uint.MaxValue)
            {
                return(GetErrorAnswer(Errno.ENOENT));
            }
            uint addr   = (uint)arg1;
            uint length = (uint)arg2;

            byte[] data = new byte[length];
            for (uint i = 0; i < length; i++)
            {
                var hex   = parameters[2].Substring((int)i * 2, 2);
                var value = Convert.ToByte(hex, 16);
                data[i] = value;
            }

            for (uint i = 0; i < length;)
            {
                uint remain = length - i;
                if (remain > 64)
                {
                    remain = 64;
                }

                byte[] toSend = new byte[remain];
                for (int j = 0; j < remain; j++)
                {
                    toSend[j] = data[i + j];
                }
                _target.WRMEM((uint)(addr + i), toSend);
                i += remain;
            }


            return(StandartAnswers.OK);
        }
Ejemplo n.º 10
0
 private string GetRegister(GDBPacket packet)
 {
     return(GetRegisterAsHex(Convert.ToInt32(packet.GetCommandParameters()[0], 16)));
 }