memory access under Win 2ooo (sample)

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by teachco.

Code: Select all

;*****************************************
;*                                       *
;* File:   memory_access.pb              *
;*                                       *
;* Author: teachco                       *
;*                                       *
;* Used: WinIO from Yariv Kaplan         *
;*       [url]http://www.internals.com[/url]        *
;*       and wrapper-lib (Danilo)        *
;*                                       *
;* Successful tested under Windows 2ooo  *
;*                                       *
;*****************************************   

OpenConsole()

; Initialize WinIO to have access to the memory
If InitializeWinIo() 

  ; ****** Writing to the memory ******
  ; Load $40 into the variable PAdr1
  PAdr1 = $40
  ; With *PAdr1 we interprete $40 as a physical address in the memory
  ; 9867 is the value (DWORD in decimal), we write to the memory address $40  
  SetPhysLong(*PAdr1,9867)


  ; ****** Reading from the memory ******
  ; Same address in another variable (but doesn't matter)
  PAdr2 = $40
  ; In the second parameter we need a physical memory location
  ; for the value we want to read. Therefore we use the address oprerator @.
  GetPhysLong(*PAdr2,@DWValue)

  ; Now it's simple. We read the value from the variable, 
  ; we addressed one step above
  PrintN(Str(DWValue))

Else
  PrintN("WinIO initialization failed (**** happens !)")
EndIf

; To keep the console window open, ... 
Input()
[/code)