Skip to content

Commit 37d5e90

Browse files
committed
Add use_memoryview param to NdrStream() for speed. Default=False as it currently require special handling in response.
1 parent 87eace2 commit 37d5e90

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

windows/rpc/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ def _get_response_effective_data(self, response):
225225
viewattr = response.view_attribute
226226
assert viewattr.ViewSize >= rpcdatasize
227227
data = windows.current_process.read_memory(viewattr.ViewBase, rpcdatasize)
228+
# We have copied the data from the view: free it
229+
# It looks like:
230+
# windows.winproxy.NtAlpcDeleteSectionView(self.alpc_client.handle, 0, viewattr.ViewBase)
231+
# Will ne be enough, as it will wait for the message to be reused to unmap the section..
232+
# And the current architecture encourage creating new message every time
228233
if response_header.request_id == self.REQUEST_IDENTIFIER_ORPC:
229234
# Parse & remove ORPC headers (orpcthat + LocalThat)
230235
data = self._pass_orpc_response_structures(data)

windows/rpc/ndr.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ def unpack(cls, stream):
173173
assert size1 == size2
174174
assert zero == 0
175175
s = stream.read(size1 * 2)
176+
if stream.use_memoryview:
177+
return bytearray(s).decode("utf-16-le")
176178
return s.decode("utf-16-le")
177179

178180
@classmethod
@@ -551,10 +553,14 @@ class NdrGuidConformantArray(NdrConformantArray):
551553

552554
class NdrStream(object):
553555
"""A stream of bytes used for NDR unpacking"""
554-
def __init__(self, data):
556+
def __init__(self, data, use_memoryview=False):
557+
""""""
555558
self.fulldata = data
556-
self.data = data
557-
# self.data = memoryview(data) # FAST but need some code rewrite at some places
559+
self.use_memoryview = use_memoryview
560+
if use_memoryview:
561+
self.data = memoryview(data) # FAST but need some code rewrite at some places
562+
else:
563+
self.data = data
558564

559565
def partial_unpack(self, format):
560566
size = struct.calcsize(format)

0 commit comments

Comments
 (0)