MCPcopy Create free account
hub / github.com/fabioz/PyDev.Debugger / peek_string

Method peek_string

pydevd_attach_to_process/winappdbg/process.py:2323–2377  ·  view source on GitHub ↗

Tries to read an ASCII or Unicode string from the address space of the process. @see: L{read_string} @type lpBaseAddress: int @param lpBaseAddress: Memory address to begin reading. @type fUnicode: bool @param fUnicode: C{True} is the stri

(self, lpBaseAddress, fUnicode=False, dwMaxSize=0x1000)

Source from the content-addressed store, hash-verified

2321 return self.__poke_c_type(lpBaseAddress, "@P", unpackedValue)
2322
2323 def peek_string(self, lpBaseAddress, fUnicode=False, dwMaxSize=0x1000):
2324 """
2325 Tries to read an ASCII or Unicode string
2326 from the address space of the process.
2327
2328 @see: L{read_string}
2329
2330 @type lpBaseAddress: int
2331 @param lpBaseAddress: Memory address to begin reading.
2332
2333 @type fUnicode: bool
2334 @param fUnicode: C{True} is the string is expected to be Unicode,
2335 C{False} if it's expected to be ANSI.
2336
2337 @type dwMaxSize: int
2338 @param dwMaxSize: Maximum allowed string length to read, in bytes.
2339
2340 @rtype: str, compat.unicode
2341 @return: String read from the process memory space.
2342 It B{doesn't} include the terminating null character.
2343 Returns an empty string on failure.
2344 """
2345
2346 # Validate the parameters.
2347 if not lpBaseAddress or dwMaxSize == 0:
2348 if fUnicode:
2349 return ""
2350 return ""
2351 if not dwMaxSize:
2352 dwMaxSize = 0x1000
2353
2354 # Read the string.
2355 szString = self.peek(lpBaseAddress, dwMaxSize)
2356
2357 # If the string is Unicode...
2358 if fUnicode:
2359 # Decode the string.
2360 szString = compat.unicode(szString, "U16", "replace")
2361 ## try:
2362 ## szString = compat.unicode(szString, 'U16')
2363 ## except UnicodeDecodeError:
2364 ## szString = struct.unpack('H' * (len(szString) / 2), szString)
2365 ## szString = [ unichr(c) for c in szString ]
2366 ## szString = u''.join(szString)
2367
2368 # Truncate the string when the first null char is found.
2369 szString = szString[: szString.find("\0")]
2370
2371 # If the string is ANSI...
2372 else:
2373 # Truncate the string when the first null char is found.
2374 szString = szString[: szString.find("\0")]
2375
2376 # Return the decoded string.
2377 return szString
2378
2379 # TODO
2380 # try to avoid reading the same page twice by caching it

Callers 8

get_image_nameMethod · 0.95
get_command_lineMethod · 0.95
do_dsMethod · 0.80
do_duMethod · 0.80
get_filenameMethod · 0.80
get_filenameMethod · 0.80
get_debug_stringMethod · 0.80

Calls 2

peekMethod · 0.95
findMethod · 0.45

Tested by

no test coverage detected