Skip to content

Commit

Permalink
Merge pull request #37 from mrexodia/inrange-fixes
Browse files Browse the repository at this point in the history
YOLO
  • Loading branch information
skelsec authored Dec 10, 2023
2 parents fcd585b + 37454bc commit c2d72f6
Show file tree
Hide file tree
Showing 31 changed files with 361 additions and 369 deletions.
8 changes: 4 additions & 4 deletions minidump/__amain__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def run():
parser.add_argument('--all', action='store_true', help='Show all info')
parser.add_argument('-r', '--read-addr', type=lambda x: int(x,0), help='Dump a memory region from the process\'s addres space')
parser.add_argument('-s', '--read-size', type=lambda x: int(x,0), default = 0x20, help='Dump a memory region from the process\'s addres space')

args = parser.parse_args()
if args.verbose == 0:
logging.basicConfig(level=logging.INFO)
Expand All @@ -38,11 +38,11 @@ async def run():
logging.basicConfig(level=1)

print(__banner__)


mf = await AMinidumpFile.parse(args.minidumpfile)
reader = mf.get_reader()

if args.all or args.threads:
if mf.threads is not None:
print(str(mf.threads))
Expand Down Expand Up @@ -81,7 +81,7 @@ async def run():
print(str(mf.misc_info))
if args.all or args.header:
print(str(mf.header))

if args.read_addr:
buff_reader = reader.get_buffered_reader()
await buff_reader.move(args.read_addr)
Expand Down
10 changes: 5 additions & 5 deletions minidump/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def run():
parser.add_argument('--all', action='store_true', help='Show all info')
parser.add_argument('-r', '--read-addr', type=lambda x: int(x,0), help='Dump a memory region from the process\'s addres space')
parser.add_argument('-s', '--read-size', type=lambda x: int(x,0), default = 0x20, help='Dump a memory region from the process\'s addres space')

args = parser.parse_args()
if args.verbose == 0:
logging.basicConfig(level=logging.INFO)
Expand All @@ -40,17 +40,17 @@ def run():
logging.basicConfig(level=1)

print(__banner__)

if args.interactive:
shell = MinidumpShell()
shell.do_open(args.minidumpfile)
shell.cmdloop()

else:

mf = MinidumpFile.parse(args.minidumpfile)
reader = mf.get_reader()

if args.all or args.threads:
if mf.threads is not None:
print(str(mf.threads))
Expand Down Expand Up @@ -89,7 +89,7 @@ def run():
print(str(mf.misc_info))
if args.all or args.header:
print(str(mf.header))

if args.read_addr:
buff_reader = reader.get_buffered_reader()
buff_reader.move(args.read_addr)
Expand Down
2 changes: 1 addition & 1 deletion minidump/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
__version__ = "0.0.22"
__banner__ = \
"""
# minidump %s
# minidump %s
# Author: Tamas Jos @skelsec ([email protected])
""" % __version__
14 changes: 7 additions & 7 deletions minidump/aminidumpreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, start, end, start_file_address):
self.start_file_address = start_file_address

self.data = None

def inrange(self, start, end):
return self.start <= start and end<= self.end

Expand Down Expand Up @@ -45,11 +45,11 @@ async def read(self, file_handle, start, end):
if end is None:
await file_handle.seek(self.start_file_address + start)
return await file_handle.read(self.end_address - (self.start_file_address + start))

for chunk in self.chunks:
if chunk.inrange(start, end):
return chunk.data[start - chunk.start: end - chunk.start]

if self.total_size <= 2*self.chunksize:
chunksize = self.total_size
vs = VirtualSegment(0, chunksize, self.start_file_address)
Expand All @@ -61,12 +61,12 @@ async def read(self, file_handle, start, end):
chunksize = max((end-start), self.chunksize)
if start + chunksize > self.end_address:
chunksize = self.end_address - start

vs = VirtualSegment(start, start+chunksize, self.start_file_address + start)
await file_handle.seek(vs.start_file_address)
vs.data = await file_handle.read(chunksize)
self.chunks.append(vs)

return vs.data[start - vs.start: end - vs.start]

class AMinidumpBufferedReader:
Expand Down Expand Up @@ -157,7 +157,7 @@ async def peek(self, length):
Returns up to length bytes from the current memory segment
"""
t = self.current_position + length
if not self.current_segment.inrange(t):
if not self.current_segment.inrange(t - 1):
raise Exception('Would read over segment boundaries!')
return await self.current_segment.read(self.reader.file_handle, self.current_position - self.current_segment.start_address , t - self.current_segment.start_address)

Expand All @@ -177,7 +177,7 @@ async def read(self, size = -1):
return await self.current_segment.read(self.reader.file_handle, old_new_pos - self.current_segment.start_address, None)

t = self.current_position + size
if not self.current_segment.inrange(t):
if not self.current_segment.inrange(t - 1):
raise Exception('Would read over segment boundaries!')

old_new_pos = self.current_position
Expand Down
Loading

0 comments on commit c2d72f6

Please sign in to comment.