Setting and getting the Data Pointer...
Posted: Wed Jan 23, 2008 4:42 pm
This routine allows you to save/restore the data pointer. A useful function of it is that you can set the data pointer to an area of allocated memory and use the read commands rather than the peek commands (no need to increment a pointer). This is really useful if reading in a file that has a header with data in it. Another advantage when using this over the traditional "Restore" command is that you can use an expression to set the address.
If you use the commands to read from an area of allocated memory you need to disable and then enable the debugger as it has a slight conflict.
The syntax is:
OriginalPointer=RestorePointer([new address])
If you use the commands to read from an area of allocated memory you need to disable and then enable the debugger as it has a slight conflict.
The syntax is:
OriginalPointer=RestorePointer([new address])
Code: Select all
Procedure RestorePointer(position=0)
!MOV eax,dword [PB_DataPointer]
!MOV edx,dword [p.v_position]
!CMP edx,0
!JE @f
!MOV dword [PB_DataPointer],edx
!@@:
ProcedureReturn
EndProcedure
Debug("Uninitialised restore pointer: "+Hex(RestorePointer()))
Restore MyData
Debug("MyData address: "+Hex(?MyData))
Debug("Current restore pointer: "+Hex(RestorePointer()))
Read var
Debug("Restore pointer after read: "+Hex(RestorePointer(?MyData)))
Debug("Restore pointer after optional setting: "+Hex(RestorePointer()))
Read var2
Debug("Result from 2nd read: "+Str(var2))
memtest=AllocateMemory(100)
PokeL(memtest,456)
l1=PokeS(memtest+4,"blah blah blah")+1
l2=PokeS(memtest+4+l1,"second string")+1
PokeL(memtest+4+l1+l2,789)
RestorePointer(memtest)
DisableDebugger
Read var3
Read string$
Read string2$
Read var4
EnableDebugger
Debug("Result from read from memory: "+Str(var3)+" "+string$+" "+string2$+" "+Str(var4))
DataSection
MyData:
Data.l 123
EndDataSection