2727
2828import com .beaudoin .jmm .misc .Cacheable ;
2929import com .beaudoin .jmm .misc .MemoryBuffer ;
30- import com .beaudoin .jmm .natives .win32 .Kernel32 ;
31- import com .beaudoin .jmm .process .impl .win32 .Win32Process ;
32- import com .sun .jna .Native ;
3330import com .sun .jna .Pointer ;
34- import com .sun .jna .platform .win32 .Win32Exception ;
3531
36- public final class Module implements ReadableRegion {
32+ public final class Module implements DataSource {
3733
38- private final NativeProcess process ;
34+ private final Process process ;
3935 private final String name ;
4036 private final long address ;
4137 private final int size ;
4238 private final Pointer pointer ;
4339 private MemoryBuffer data ;
4440
45- public Module (NativeProcess process , String name , Pointer pointer , long size ) {
41+ public Module (Process process , String name , Pointer pointer , long size ) {
4642 this .process = process ;
4743 this .name = name ;
4844 this .address = Pointer .nativeValue (pointer );
4945 this .size = (int ) size ;
5046 this .pointer = pointer ;
5147 }
5248
53- public NativeProcess process () {
49+ public Process process () {
5450 return process ;
5551 }
5652
@@ -75,32 +71,22 @@ public MemoryBuffer data() {
7571 }
7672
7773 public MemoryBuffer data (boolean forceNew ) {
78- if (forceNew || data == null ) {
79- data = process ().read (pointer (), size ());
80- }
81- return data ;
74+ return data == null || forceNew ? data = process ().read (pointer (), size ()) : data ;
8275 }
8376
8477 @ Override
8578 public MemoryBuffer read (Pointer offset , int size ) {
86- MemoryBuffer buffer = Cacheable .buffer (size );
87- if (Kernel32 .ReadProcessMemory (((Win32Process ) process ()).pointer (), Cacheable .pointer (address () + Pointer .nativeValue (offset )), buffer , size , 0 ) == 0 ) {
88- throw new Win32Exception (Native .getLastError ());
89- }
90- return buffer ;
79+ return process ().read (Cacheable .pointer (address () + Pointer .nativeValue (offset )), size );
9180 }
9281
9382 @ Override
94- public NativeProcess write (Pointer offset , MemoryBuffer buffer ) {
95- if (Kernel32 .WriteProcessMemory (((Win32Process ) process ()).pointer (), Cacheable .pointer (address () + Pointer .nativeValue (offset )), buffer , buffer .size (), 0 ) == 0 ) {
96- throw new Win32Exception (Native .getLastError ());
97- }
98- return process ();
83+ public Process write (Pointer offset , MemoryBuffer buffer ) {
84+ return process ().write (Cacheable .pointer (address () + Pointer .nativeValue (offset )), buffer );
9985 }
10086
10187 @ Override
10288 public boolean canRead (Pointer offset , int size ) {
103- return Kernel32 . ReadProcessMemory ((( Win32Process ) process ()). pointer (), Cacheable .pointer (address () + Pointer .nativeValue (offset )), Cacheable . buffer ( size ), size , 0 ) != 0 ;
89+ return process (). canRead ( Cacheable .pointer (address () + Pointer .nativeValue (offset )), size );
10490 }
10591
10692 @ Override
0 commit comments