Page 2 of 3

Posted: Wed Oct 10, 2007 7:43 pm
by DevilDog
:lol:

Looks like they fixed it.

Posted: Wed Oct 10, 2007 7:44 pm
by Demivec
DevilDog wrote: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.
Use the Watchlist in the Debugger.

Posted: Wed Oct 10, 2007 8:11 pm
by DevilDog
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

Posted: Thu Oct 11, 2007 4:50 pm
by DevilDog
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.

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
EndProcedure
Devildog

Posted: Thu Oct 11, 2007 4:54 pm
by Irene
Are you trying to code a trainer in PureBasic? That is, to read a specific variable of another program, like the high score of a game and manipulate it with your own input?? Because after reading the first page of this thread I really don't know anymore what is left and what is right @_@

Posted: Thu Oct 11, 2007 4:58 pm
by Fluid Byte
I won't accomplish what you are after since it's using process handles and memory pointers to modfiy / train another programms memory.
Irene wrote:Are you trying to code a trainer in PureBasic?
No. He want's to directly read the values of varibales assigned in PureBasic sourcecode.

Posted: Thu Oct 11, 2007 5:05 pm
by DevilDog
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

Posted: Fri Oct 12, 2007 12:26 am
by pdwyer
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
Hundreds? Perhaps you need a different coding style, one that uses other data structures to hold information, arrays, structures and lists.

(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

Posted: Fri Oct 12, 2007 11:09 am
by PB
> 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 ;)

Posted: Fri Oct 12, 2007 11:11 am
by Psychophanta
@Devildog, perhaps the PB Mutex feature can help you for this task :)

Posted: Fri Oct 12, 2007 3:49 pm
by DevilDog
Psychophanta,
How could I use the mutex ability to do what I'm hoping to do?

I haven't done any threading programming and I'm not clear on how that would work.

Thanks
Devildog

Posted: Fri Oct 12, 2007 3:53 pm
by Psychophanta
I have not dealed with Mutex stuff, so sorry i can not help you with that. :oops: But it seems that it could help you, so you can play a little bit with PB and its manual and search forum for some Mutex stuff there. :?

Posted: Fri Oct 12, 2007 4:12 pm
by pdwyer
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

FYI

Posted: Fri Oct 12, 2007 4:28 pm
by DevilDog
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.

Image

Posted: Fri Oct 12, 2007 4:34 pm
by Psychophanta
I see now.
I guess that feature is not included in PB Debugger. Please go to "feature requests" in this forum and ask for it. :)
It would be good to have it. 8)