(pointer)
return chain
Recursively dereference a pointer for display
Recursively dereference a pointer for display
Recursively dereference a pointer for display
def dereference(pointer):
	"""
	Recursively dereference a pointer for display
	"""
	MAX_DEREF = 8
	t = lldb.debugger.GetSelectedTarget()
	error = lldb.SBError()

	addr = pointer
	chain = []

	# recursively dereference
	for i in range(0, MAX_DEREF):
		ptr = t.process.ReadPointerFromMemory(addr, error)
		if error.Success():
			if ptr in chain:
				chain.append(('circular', 'circular'))
				break
			chain.append(('pointer', addr))
			addr = ptr
		else:
			break

	if len(chain) == 0:
		# errlog(f"0x{pointer:x} is not a valid pointer")
		return

	# get some info for the last pointer
	# first try to resolve a symbol context for the address
	p, addr = chain[-1]
	sbaddr = lldb.SBAddress(addr, t)
	ctx = t.ResolveSymbolContextForAddress(sbaddr, lldb.eSymbolContextEverything)
	if ctx.IsValid() and ctx.GetSymbol().IsValid():
		# found a symbol, store some info and we're done for this pointer
		fstart = ctx.GetSymbol().GetStartAddress().GetLoadAddress(t)
		offset = addr - fstart
		chain.append(('symbol', '{} + 0x{:X}'.format(ctx.GetSymbol().name, offset)))
		# log.debug("symbol context: {}".format(str(chain[-1])))
	else:
		# no symbol context found, see if it looks like a string
		# errlog("no symbol context")
		try:
			s = t.process.ReadCStringFromMemory(addr, 256, error)
			for i in range(0, len(s)):
				if ord(s[i]) >= 128:
					s = s[:i]
					break
			if len(s):
				chain.append(('string', s))
		
		except:
			pass

	return chain
def dereference ( pointer ) : MAX_DEREF = 8 t = lldb . debugger . GetSelectedTarget ( ) error = lldb . SBError ( ) addr = pointer chain = [ ] # recursively dereference for i in range ( 0 , MAX_DEREF ) : ptr = t . process . ReadPointerFromMemory ( addr , error ) if error . Success ( ) : if ptr in chain : chain . append ( ( 'circular' , 'circular' ) ) break chain . append ( ( 'pointer' , addr ) ) addr = ptr else : break if len ( chain ) == 0 : # errlog(f"0x{pointer:x} is not a valid pointer") return # get some info for the last pointer # first try to resolve a symbol context for the address p , addr = chain [ - 1 ] sbaddr = lldb . SBAddress ( addr , t ) ctx = t . ResolveSymbolContextForAddress ( sbaddr , lldb . eSymbolContextEverything ) if ctx . IsValid ( ) and ctx . GetSymbol ( ) . IsValid ( ) : # found a symbol, store some info and we're done for this pointer fstart = ctx . GetSymbol ( ) . GetStartAddress ( ) . GetLoadAddress ( t ) offset = addr - fstart chain . append ( ( 'symbol' , '{} + 0x{:X}' . format ( ctx . GetSymbol ( ) . name , offset ) ) ) # log.debug("symbol context: {}".format(str(chain[-1]))) else : # no symbol context found, see if it looks like a string # errlog("no symbol context") try : s = t . process . ReadCStringFromMemory ( addr , 256 , error ) for i in range ( 0 , len ( s ) ) : if ord ( s [ i ] ) >= 128 : s = s [ : i ] break if len ( s ) : chain . append ( ( 'string' , s ) ) except : pass return chain