Page 1 of 1
Peek hex string?
Posted: Mon Feb 02, 2004 7:52 pm
by Justin
what would be the best way to return the contents of a memory area as an hex string?, the fact that pb works always with unsigneds messes me a bit
peekHEX(address,len)
Posted: Mon Feb 02, 2004 8:07 pm
by Proteus
Try these procedures:
Code: Select all
Procedure.s PeekHEXByte(*Address)
ProcedureReturn RSet(Hex(PeekB(*Address)), 2, "0")
EndProcedure
Procedure PeekHEXWord(*Address)
ProcedureReturn RSet(Hex(PeekW(*Address)), 4, "0")
EndProcedure
Procedure PeekHEXLong(*Address)
ProcedureReturn RSet(Hex(PeekL(*Address)), 8, "0")
EndProcedure
Procedure.s PeekHEX(*Address, len)
Out.s = ""
For a = 0 To len-1
Out + PeekHEXByte(*Address+a)
Next
ProcedureReturn Out
EndProcedure
Posted: Mon Feb 02, 2004 8:23 pm
by Justin
It does not work, at least is not what you would see in an hex editor, you have to convert to unsigned, this worked
Code: Select all
procedure.s peekHEX(mem,bytes)
st$=""
for x=0 to bytes-1
vs.b=peekb(mem+x)
vu.w = vs & $FF
h$=hex(vu)
if len(h$)=1 : h$="0" + h$ : endif
st$=st$ + h$
next
procedurereturn st$
endprocedure