Looks like they fixed it.
How do I read a variable value in another process?
Demivec,
Yes I know the watchlist will give me the ability to view a variables value but you have to open it and add the variables each time.
It is much more intuitive as you are debugging a line of code and you see a variable to be able to simply hold your mouse over it and see the value of the variable in a tooltip.
Devildog
Yes I know the watchlist will give me the ability to view a variables value but you have to open it and add the variables each time.
It is much more intuitive as you are debugging a line of code and you see a variable to be able to simply hold your mouse over it and see the value of the variable in a tooltip.
Devildog
When all is said and done, more is said than done.
I found the following code in a different post.
Can anyone tell if this would be helpful to do what I need.
I don't have experience with interprocess programming or low level api programming and I need some help.
I can see it has a function to get a handle on a process and to read an address but I'm not sure how I could use it to do what I need.
Any help is appreciated.
Devildog
Can anyone tell if this would be helpful to do what I need.
I don't have experience with interprocess programming or low level api programming and I need some help.
I can see it has a function to get a handle on a process and to read an address but I'm not sure how I could use it to do what I need.
Any help is appreciated.
Code: Select all
; Trainer Library
; Coded by Daniel Middelhede - thefool
Structure tl_freeze
Address.s
Value.l
phandle.l
Size.l
EndStructure
ProcedureDLL tl_Init()
Global Dim tl_tmrlist.tl_freeze(500)
EndProcedure
Procedure.l tl_hex2long(Hex.s)
Erg.l = 0
For i.l = 1 To Len(Hex)
c.l = Asc(Mid(Hex, i, 1))
If c > 64
c - 55
EndIf
If c > 47
c - 48
EndIf
Erg = Erg << 4 + c
Next
ProcedureReturn Erg
EndProcedure
ProcedureDLL tl_GetPhandle(ProcessId) ;Opens process access and gives Handle.
phandle = OpenProcess_(#PROCESS_ALL_ACCESS, #False, ProcessId)
ProcedureReturn phandle
EndProcedure
ProcedureDLL tl_ReadAddress(phandle, Address.s, Size) ;Returns a value from given address
addressLONG.l = tl_hex2long(Address.s)
If ReadProcessMemory_(phandle, addressLONG, @mybuf.l, Size, NULL)
ProcedureReturn mybuf
Else
ProcedureReturn 0
EndIf
EndProcedure
ProcedureDLL.f tl_ReadAddressFLOAT(phandle, Address.s, Size) ;Returns a value from given address
addressLONG.l = tl_hex2long(Address.s)
If ReadProcessMemory_(phandle, addressLONG, @mybuf.f, Size, NULL)
ProcedureReturn mybuf
Else
ProcedureReturn 0
EndIf
EndProcedure
ProcedureDLL tl_WriteAddress(phandle, Address.s, Value,Size) ;Writes a value to memory..
addressLONG = tl_hex2long(Address.s)
result = WriteProcessMemory_(phandle, addressLONG, @Value, Size, NULL)
ProcedureReturn result
EndProcedure
ProcedureDLL tl_ChangeaddressValue(phandle, Address.s, Value,Size) ;Adds or subtracts a value to the address
originalval = tl_ReadAddress(phandle, Address.s, Size)
newval = originalval + Value
val = tl_WriteAddress(phandle,Address.s, newval, Size)
ProcedureReturn val
EndProcedure
ProcedureDLL tl_CloseProcess(phandle) ;Terminates a process
result = TerminateProcess_(phandle, 0)
ProcedureReturn result
EndProcedure
Procedure tl_KeepFreezed()
Repeat
Delay(1000)
i=0
Repeat
phandle = tl_tmrlist(i)\phandle
If phandle > 0
Size = tl_tmrlist(i)\Size
Address.s = tl_tmrlist(i)\Address
oldval = tl_tmrlist(i)\Value
newval = tl_ReadAddress(phandle, Address, Size)
If newval = oldval
;Do nothing..
Else
tl_WriteAddress(phandle,Address,oldval,Size)
EndIf
EndIf
i + 1
Until i = tl_fcount
ForEver
EndProcedure
ProcedureDLL tl_FreezeAddress(phandle,Address.s,Size) ;Freezes a value in an address
Value = tl_ReadAddress(phandle,Address.s,Size)
tl_tmrlist(tl_Place)\Value = Value
tl_tmrlist(tl_Place)\Address = Address.s
tl_tmrlist(tl_Place)\phandle = phandle
tl_tmrlist(tl_Place)\Size = Size
tl_Place + 1
tl_fcount + 1
tl_madef + 1
If tl_fcount > 1
;nothing
Else
tl_tmrhandle = CreateThread(@tl_KeepFreezed(), 0)
EndIf
ProcedureReturn tl_Place
EndProcedure
ProcedureDLL tl_UnFreezeAddress(FreezeNumber) ;Removes a freeze
FreezeNumber - 1
tl_tmrlist(FreezeNumber)\phandle = 0
tl_tmrlist(FreezeNumber)\Address = ""
tl_tmrlist(FreezeNumber)\Value = 0
tl_tmrlist(FreezeNumber)\Size = 0
tl_madef - 1
If tl_madef = 0
KillThread(tl_tmrhandle)
EndIf
EndProcedureWhen all is said and done, more is said than done.
- Fluid Byte
- Addict

- Posts: 2336
- Joined: Fri Jul 21, 2006 4:41 am
- Location: Berlin, Germany
I won't accomplish what you are after since it's using process handles and memory pointers to modfiy / train another programms memory.
No. He want's to directly read the values of varibales assigned in PureBasic sourcecode.Irene wrote:Are you trying to code a trainer in PureBasic?
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Irene, Fluid Byte,
If you look on the announcements forum you will see a tool called PB Project that I wrote. It's a project manager for PB that will manage all your PB files, graphics, etc.
You can double-click a .pb file in PBProject and it will open it in your editor whether that's jaPBe or the PB editor.
My request for help in figuring out how to read an variable address in another process is so that I could add the feature to PBProject that would allow me to open a .pb program in an editor and then have PBProject be able to show you the values of variables in the editor as you hold your mouse over it.
I don't want to change the values of anything in another process, I want to be able to read the values to improve the debugging process and to make PBProject a better tool.
Devildog
If you look on the announcements forum you will see a tool called PB Project that I wrote. It's a project manager for PB that will manage all your PB files, graphics, etc.
You can double-click a .pb file in PBProject and it will open it in your editor whether that's jaPBe or the PB editor.
My request for help in figuring out how to read an variable address in another process is so that I could add the feature to PBProject that would allow me to open a .pb program in an editor and then have PBProject be able to show you the values of variables in the editor as you hold your mouse over it.
I don't want to change the values of anything in another process, I want to be able to read the values to improve the debugging process and to make PBProject a better tool.
Devildog
When all is said and done, more is said than done.
Hundreds? Perhaps you need a different coding style, one that uses other data structures to hold information, arrays, structures and lists.DevilDog wrote:Because I'm trying to add this as a feature to my project (PB Project) so I can use it when I program.
I would prefer to have the ability to see the value of a variable by holding my mouse over a variable in the debugger window rather than have to open the debugger scroll through over a hundred variables looking for the one I need.
Devildog
(I know that's not helping you but I can't say I've ever had 50 vars show up in the list. I've had arrays opened out and structures etc with many elements but it just gets too unwieldy.)
A screenshot might help us understand though
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
> after reading the first page of this thread I really don't know anymore
> what is left and what is right @_@
Go here to find out: http://www.purebasic.fr/english/viewtopic.php?t=29091
> what is left and what is right @_@
Go here to find out: http://www.purebasic.fr/english/viewtopic.php?t=29091
- Psychophanta
- Always Here

- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
- Psychophanta
- Always Here

- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Mutexes and Critical Sections work to serialise access to memory.
Lets say you have a global list which is used as a queue and two threads that read the first item in the list then delete it while some other thread adds to the end of it. Creating a mutex stops threads bumping into eachother so if two threads both read item 1 then both try to delete it then what *might* (always hard to tell) happen is that they both get the data then the faster thread delete the item and the slower thread deletes the next item that no thread read leading to bugs.
What you do is have a mutex for that list and each thread that wants to use the list locks the mutex, uses the list this unlocks it. If a thread tries to read the list and the mutex is locked then it waits till its unlocked (assuming it's using a mutex too of course).
The waiting is usually only very brief while another thread just accesses that list.
You need to be careful of threads locking up. if one thread locks a mutex and something happens, error or something and it doesn't get unlocked then other threads will wait.
If you have two areas of mutex then you can have two threads waiting for eachther in a deadlock too.
The docs cover all this quite well though and have samples to play with
Lets say you have a global list which is used as a queue and two threads that read the first item in the list then delete it while some other thread adds to the end of it. Creating a mutex stops threads bumping into eachother so if two threads both read item 1 then both try to delete it then what *might* (always hard to tell) happen is that they both get the data then the faster thread delete the item and the slower thread deletes the next item that no thread read leading to bugs.
What you do is have a mutex for that list and each thread that wants to use the list locks the mutex, uses the list this unlocks it. If a thread tries to read the list and the mutex is locked then it waits till its unlocked (assuming it's using a mutex too of course).
The waiting is usually only very brief while another thread just accesses that list.
You need to be careful of threads locking up. if one thread locks a mutex and something happens, error or something and it doesn't get unlocked then other threads will wait.
If you have two areas of mutex then you can have two threads waiting for eachther in a deadlock too.
The docs cover all this quite well though and have samples to play with
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
FYI
I think most of you are familiar with what I'm trying to do from experience with Visual Studio or VB.
Just in case someone does not know what I mean, here's a screen capture where I have held the mouse pointer over a variable while in debug mode in Visual Studio. As you can see, VS displays the value of the variable (0). I did not have to open any additional windows or add variables to any viewers, I just held my mouse over the variable in the debugger and I can see its value. That's what I'm trying to do.

Just in case someone does not know what I mean, here's a screen capture where I have held the mouse pointer over a variable while in debug mode in Visual Studio. As you can see, VS displays the value of the variable (0). I did not have to open any additional windows or add variables to any viewers, I just held my mouse over the variable in the debugger and I can see its value. That's what I'm trying to do.

When all is said and done, more is said than done.
- Psychophanta
- Always Here

- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:

