-
Notifications
You must be signed in to change notification settings - Fork 9
/
c_mem.php
48 lines (38 loc) · 1.6 KB
/
c_mem.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
class c_mem {
public function read_mem( array $source, int $offset, int $size ) : array {
$result = array( );
for ( $i = $offset; $i < $offset + $size; $i++ )
$result[ ] = $source[ $i ];
return $result;
}
public function mem_copy( array $source, array $dest, int $dest_offset, int $offset, int $size ) : array {
$mem = $this->read_mem( $source, $offset, $size );
for ( $i = $dest_offset; $i < $dest_offset + $size; $i++ )
$dest[ $i ] = $mem[ $i - $dest_offset ];
return $dest;
}
public function set_dword( array $dest, int $offset, int $delta ) : array {
$replacement = unpack( "C*", pack( "L", $delta ) );
for ( $i = $offset; $i < $offset + 4; $i++ )
$dest[ $i ] = $replacement[ $i - $offset + 1 ];
return $dest;
}
public function read_dword( array $source, int $offset ) : int {
$arr = $this->read_mem($source, $offset, 4);
return (($arr[3] & 0xFF) << 24) | (($arr[2] & 0xFF) << 16) | (($arr[1] & 0xFF) << 8) | ($arr[0] & 0xFF);
}
public function read_qword( array $source, int $offset ) : array {
return $this->read_mem($source, $offset, 8);
}
public function read_word( array $source, int $offset ) : int {
$arr = $this->read_mem($source, $offset, 2);
return (($arr[1] & 0xFF) << 8) | ($arr[0] & 0xFF);
}
public function read_string( array $source, int $offset ) : string {
$result = "";
while ( $source[ $offset ] != 0 )
$result .= chr( $source[ $offset++ ] );
return $result;
}
}