Repository: pwndbg/pwndbg

Issue:
windbg compatibility commands fail for hex 
### Description
There's a weird bug while using command such as `eq`

### Steps to reproduce

```
pwndbg> eq 0x7fffffffdf30 41414141

pwndbg> tele 0x7fffffffdf30 1
00:0000│ rbp rsp  0x7fffffffdf30 ◂— 0x41414141 /* 'AAAA' */

pwndbg> eq 0x7fffffffdf30 0xabcd

pwndbg> tele 0x7fffffffdf30 1
00:0000│ rbp rsp  0x7fffffffdf30 ◂— 0x43981

pwndbg> eq 0x7fffffffdf30 abcd
Exception occured: eq: No symbol "abcd" in current context. (<class 'gdb.error'>)
For more info invoke `set exception-verbose on` and rerun the command
or debug it by yourself with `set exception-debugger on`

pwndbg> eq 0x7fffffffdf30 abcd10
Exception occured: eq: No symbol "abcd10" in current context. (<class 'gdb.error'>)
For more info invoke `set exception-verbose on` and rerun the command
or debug it by yourself with `set exception-debugger on`

pwndbg> eq 0x7fffffffdf30 10abcd10
Exception occured: eq: Invalid number "10abcd10". (<class 'gdb.error'>)
For more info invoke `set exception-verbose on` and rerun the command
or debug it by yourself with `set exception-debugger on`
```
### My setup

```sh
$ git --no-pager log -1 --stat                                    15:15:04  ☁  dev ☂ ⚡
commit 848247ed9c5b832dc0f143cd2df605b90f2f05c5
Author: Levente Polyak <levente@leventepolyak.net>
Date:   Tue Aug 20 01:45:47 2019 +0200

    checksec: try detect different variants and use appropriate args (#671)
    
    Modern maintained checksec >2.0 requires to use "--file=arg" which
    we try to detect. The command call is cached anyway so lets try
    to find out what version is running.
    In case we can't find a verbose variant, we just fall back to the
    common old fessioned "--file arg" variant as if nothing has happened.
    
    Fixes #662

 pwndbg/wrappers/checksec.py | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
```

```
pwndbg> version
Gdb:      7.12.0.20161007-git
Python:   3.5.3 (default, Sep 27 2018, 17:25:39)  [GCC 6.3.0 20170516]
Pwndbg:   1.1.0 build: 848247e
Capstone: 4.0.1024
Unicorn:  1.0.1
```


Discussion:
This is probably a bug that happened when we converted everything to use argparse. I'll try to take a look at this soon.
EDIT:
Yep: Looks like
https://github.com/pwndbg/pwndbg/blob/848247ed9c5b832dc0f143cd2df605b90f2f05c5/pwndbg/commands/windbg.py#L174
Should be type=str and hex=True should be passed to eX. I'll try to test this and other windbg commands at some point with that fix.

Resolving patch:
diff --git a/pwndbg/commands/windbg.py b/pwndbg/commands/windbg.py
--- a/pwndbg/commands/windbg.py
+++ b/pwndbg/commands/windbg.py
@@ -135,7 +135,7 @@ def enhex(size, value):
 
 parser = argparse.ArgumentParser(description="Write hex bytes at the specified address.")
 parser.add_argument("address", type=int, help="The address to write to.")
-parser.add_argument("data", type=int, nargs="*", help="The bytes to write.")
+parser.add_argument("data", type=str, nargs="*", help="The bytes to write.")
 @pwndbg.commands.ArgparsedCommand(parser)
 @pwndbg.commands.OnlyWhenRunning
 def eb(address, data):
@@ -147,7 +147,7 @@ def eb(address, data):
 
 parser = argparse.ArgumentParser(description="Write hex words at the specified address.")
 parser.add_argument("address", type=int, help="The address to write to.")
-parser.add_argument("data", type=int, nargs="*", help="The words to write.")
+parser.add_argument("data", type=str, nargs="*", help="The words to write.")
 @pwndbg.commands.ArgparsedCommand(parser)
 @pwndbg.commands.OnlyWhenRunning
 def ew(address, data):
@@ -159,7 +159,7 @@ def ew(address, data):
 
 parser = argparse.ArgumentParser(description="Write hex dwords at the specified address.")
 parser.add_argument("address", type=int, help="The address to write to.")
-parser.add_argument("data", type=int, nargs="*", help="The dwords to write.")
+parser.add_argument("data", type=str, nargs="*", help="The dwords to write.")
 @pwndbg.commands.ArgparsedCommand(parser)
 @pwndbg.commands.OnlyWhenRunning
 def ed(address, data):
@@ -171,7 +171,7 @@ def ed(address, data):
 
 parser = argparse.ArgumentParser(description="Write hex qwords at the specified address.")
 parser.add_argument("address", type=int, help="The address to write to.")
-parser.add_argument("data", type=int, nargs="*", help="The qwords to write.")
+parser.add_argument("data", type=str, nargs="*", help="The qwords to write.")
 @pwndbg.commands.ArgparsedCommand(parser)
 @pwndbg.commands.OnlyWhenRunning
 def eq(address, data):


Test patch: