Skip to content

Commit

Permalink
Move pince-hex-dump to GDB_Engine.hex_dump
Browse files Browse the repository at this point in the history
  • Loading branch information
korcankaraokcu committed Oct 14, 2021
1 parent bc90274 commit 3bc0b0e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 32 deletions.
21 changes: 18 additions & 3 deletions libpince/GDB_Engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from threading import Lock, Thread, Condition
from time import sleep, time
from collections import OrderedDict, defaultdict
import pexpect, os, ctypes, pickle, json, shelve, re, struct
import pexpect, os, ctypes, pickle, json, shelve, re, struct, io
from . import SysUtils, type_defs, common_regexes

self_pid = os.getpid()
Expand Down Expand Up @@ -1311,8 +1311,23 @@ def hex_dump(address, offset):
Examples:
returned list-->["??","??","??","7f","43","67","40","??","??, ...]
"""
return send_command("pince-hex-dump", send_with_file=True, file_contents_send=(address, offset),
recv_with_file=True)
hex_byte_list = []
with open(mem_file, "rb") as FILE:
try:
FILE.seek(address)
except (OSError, ValueError):
pass
for item in range(offset):
try:
current_item = " ".join(format(n, '02x') for n in FILE.read(1))
except OSError:
current_item = "??"
try:
FILE.seek(1, io.SEEK_CUR) # Necessary since read() failed to execute
except (OSError, ValueError):
pass
hex_byte_list.append(current_item)
return hex_byte_list


#:tag:BreakWatchpoints
Expand Down
30 changes: 1 addition & 29 deletions libpince/gdb_python_scripts/GDBCommandExtensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import gdb, pickle, json, sys, re, struct, io, ctypes, os, shelve, distorm3
import gdb, pickle, json, sys, re, struct, ctypes, os, shelve, distorm3
from collections import OrderedDict

# This is some retarded hack
Expand Down Expand Up @@ -230,33 +230,6 @@ def invoke(self, arg, from_tty):
send_to_pince(frame_info)


class HexDump(gdb.Command):
def __init__(self):
super(HexDump, self).__init__("pince-hex-dump", gdb.COMMAND_USER)

def invoke(self, arg, from_tty):
contents_recv = receive_from_pince()
hex_byte_list = []
address = contents_recv[0]
offset = contents_recv[1]
with open(ScriptUtils.mem_file, "rb") as FILE:
try:
FILE.seek(address)
except (OSError, ValueError):
pass
for item in range(offset):
try:
current_item = " ".join(format(n, '02x') for n in FILE.read(1))
except OSError:
current_item = "??"
try:
FILE.seek(1, io.SEEK_CUR) # Necessary since read() failed to execute
except (OSError, ValueError):
pass
hex_byte_list.append(current_item)
send_to_pince(hex_byte_list)


class GetTrackWatchpointInfo(gdb.Command):
def __init__(self):
super(GetTrackWatchpointInfo, self).__init__("pince-get-track-watchpoint-info", gdb.COMMAND_USER)
Expand Down Expand Up @@ -642,7 +615,6 @@ def invoke(self, arg, from_tty):
GetStackInfo()
GetFrameReturnAddresses()
GetFrameInfo()
HexDump()
GetTrackWatchpointInfo()
GetTrackBreakpointInfo()
PhaseOut()
Expand Down

0 comments on commit 3bc0b0e

Please sign in to comment.