Core Function PTRRead
From Sputnik Wiki
(Difference between revisions)
(→type) |
(→Example) |
||
Line 64: | Line 64: | ||
Free($PTR); | Free($PTR); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | If the type is a NUMBER instead of a STRING this function will READ that many BYTES from the pointer and return it as a binary variable example | ||
+ | |||
+ | <syntaxhighlight lang="sputnik"> | ||
+ | #PTRRead($p, 100, 0); # Read 100 bytes from offset 0 | ||
+ | #PTRRead($p, 100, 50); # Read 100 bytes from offset 50 | ||
+ | #PTRRead($p, 70, 25); # Read 70 bytes from offset 25 | ||
+ | |||
+ | my $GameCap = "Pacman 2.4"; | ||
+ | my $GamePID = WinGetProcess($GameCap); | ||
+ | $Value = GetUTF8Bytes("The Cat"); | ||
+ | WriteMem($GamePID, "", 0x400300, $Value); | ||
+ | |||
+ | // Grabs the raw UTF8 bytes from ram | ||
+ | // and returns them as a binary variable | ||
+ | Function GetUTF8Bytes( &$String ) | ||
+ | { | ||
+ | fixed( $p = $String ) | ||
+ | { | ||
+ | // Read the whole memory of the string | ||
+ | // including all the extra unicode characters | ||
+ | // and even grab its null terminator | ||
+ | return PTRRead($p, StrLen($String) * @CharSize + 1, 0); | ||
+ | } | ||
+ | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Revision as of 15:40, 29 September 2013
PTRRead( <ptr>, <type>, <offset> )
Contents |
Description
Read data from a memory pointer optionally starting from a given index.
Parameters
ptr
The pointer to use.
type
The type of data to read
If the type parameter contains a number instead of a string it will ignore the table below and read that many bytes from the pointer and return it.
[TYPE] [WHAT IT IS] c ASCII char C UNICODE char b unsigned byte B signed byte s signed int16 i signed int32 l signed int64 S unsigned int16 I unsigned int32 L unsigned int64 f float d double t pointer
offset
Offset to add to the pointer.
Return Value
Success: Returns the value requested or -1 if fail.
Failure: Returns null.
Remarks
None.
Example
$PTR = Alloc(300); PTRWrite($PTR, "f", 0, 133.77); PTRWrite($PTR, "l", 4, 777); PTRWrite($PTR, "i", 12, 1221); Println( PTRRead($PTR, "f", 0) ); Println( PTRRead($PTR, "l", 4) ); Println( PTRRead($PTR, "i", 12) ); Free($PTR);
If the type is a NUMBER instead of a STRING this function will READ that many BYTES from the pointer and return it as a binary variable example
#PTRRead($p, 100, 0); # Read 100 bytes from offset 0 #PTRRead($p, 100, 50); # Read 100 bytes from offset 50 #PTRRead($p, 70, 25); # Read 70 bytes from offset 25 my $GameCap = "Pacman 2.4"; my $GamePID = WinGetProcess($GameCap); $Value = GetUTF8Bytes("The Cat"); WriteMem($GamePID, "", 0x400300, $Value); // Grabs the raw UTF8 bytes from ram // and returns them as a binary variable Function GetUTF8Bytes( &$String ) { fixed( $p = $String ) { // Read the whole memory of the string // including all the extra unicode characters // and even grab its null terminator return PTRRead($p, StrLen($String) * @CharSize + 1, 0); } }