33import com .beaudoin .jmm .misc .Cacheable ;
44import com .beaudoin .jmm .misc .MemoryBuffer ;
55import com .beaudoin .jmm .misc .Strings ;
6- import com .beaudoin .jmm .natives .windows .Kernel32 ;
7- import com .beaudoin .jmm .process .impl .LinuxProcess ;
8- import com .beaudoin .jmm .process .impl .WindowsProcess ;
6+ import com .beaudoin .jmm .natives .win32 .Kernel32 ;
7+ import com .beaudoin .jmm .process .impl .unix . UnixProcess ;
8+ import com .beaudoin .jmm .process .impl .win32 . Wind32Process ;
99import com .sun .jna .Native ;
1010import com .sun .jna .Platform ;
1111import com .sun .jna .Pointer ;
1212import com .sun .jna .platform .win32 .Tlhelp32 ;
1313
14+ import java .io .IOException ;
15+ import java .util .Scanner ;
16+
1417import static com .beaudoin .jmm .misc .Cacheable .buffer ;
1518
1619/**
@@ -36,8 +39,13 @@ static NativeProcess byName(String name) {
3639 throw new UnsupportedOperationException ("Unknown mac system! (" + System .getProperty ("os.name" ) + ")" );
3740 //MAC
3841 } else if (Platform .isLinux ()) {
39- throw new UnsupportedOperationException ("Unknown linux system! (" + System .getProperty ("os.name" ) + ")" );
40- //Linux
42+ try {
43+ int processid = Integer .parseInt (new Scanner (Runtime .getRuntime ().exec ("ps -C " +name +" -o pid" ).getInputStream ()).useDelimiter ("\\ A" ).next ().replaceAll ("[^0-9]" ,"" ));
44+ return byId (processid );
45+ } catch (Exception e ) {
46+ e .printStackTrace ();
47+ //throw new IllegalStateException("Process " + name + " was not found. Are you sure its running?");
48+ }
4149 } else {
4250 throw new UnsupportedOperationException ("Unknown operating system! (" + System .getProperty ("os.name" ) + ")" );
4351 }
@@ -46,12 +54,12 @@ static NativeProcess byName(String name) {
4654
4755 static NativeProcess byId (int id ) {
4856 if (Platform .isWindows ()) {
49- return new WindowsProcess (id , Kernel32 .OpenProcess (0x438 , true , id ));
57+ return new Wind32Process (id , Kernel32 .OpenProcess (0x438 , true , id ));
5058 } else if (Platform .isMac ()) {
5159 throw new UnsupportedOperationException ("Unknown mac system! (" + System .getProperty ("os.name" ) + ")" );
5260 //MAC
5361 } else if (Platform .isLinux ()) {
54- return new LinuxProcess (id , null );
62+ return new UnixProcess (id , null );
5563 } else {
5664 throw new IllegalStateException ("Process " + id + " was not found. Are you sure its running?" );
5765 }
@@ -61,6 +69,8 @@ static NativeProcess byId(int id) {
6169
6270 Pointer pointer ();
6371
72+ void initModules ();
73+
6474 Module findModule (String moduleName );
6575
6676 MemoryBuffer read (Pointer address , int size );
0 commit comments