├── COPYRIGHT ├── src ├── .DS_Store └── main │ ├── .DS_Store │ └── java │ ├── .DS_Store │ └── iflores │ └── ceserver │ └── pcileech │ ├── RunningServerListener.java │ ├── WinApiException.java │ ├── TOKEN_ELEVATION.java │ ├── Win32Utils.java │ ├── PciLeechException.java │ ├── ProcessInfo.java │ ├── Win32Constants.java │ ├── DocumentChangeListener.java │ ├── GridBagConstraintsBuilder.java │ ├── VMMDLL_MAP_VAD.java │ ├── ToolHelp32Snapshot_Processes.java │ ├── ToolHelp32Snapshot_Modules.java │ ├── MemoryRegion.java │ ├── JnaPciLeech.java │ ├── VMMDLL_MAP_VADENTRY.java │ ├── VmmDllFlags.java │ ├── CommandConstants.java │ ├── SelectedProcess.java │ ├── MemoryMap.java │ ├── RunningServer.java │ ├── Settings.java │ ├── Main.java │ ├── VadInfo.java │ ├── ServerMain.java │ ├── PciLeech.java │ ├── MainFrame.java │ └── ClientHandler.java ├── NOTICE ├── README.md ├── pom.xml └── LICENSE /COPYRIGHT: -------------------------------------------------------------------------------- 1 | Copyright 2021 Isabella Flores 2 | 1c3f5bd10d1722b1d224354349df9669de5700ae -------------------------------------------------------------------------------- /src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbrking/ceserver-pcileech/HEAD/src/.DS_Store -------------------------------------------------------------------------------- /src/main/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbrking/ceserver-pcileech/HEAD/src/main/.DS_Store -------------------------------------------------------------------------------- /src/main/java/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbrking/ceserver-pcileech/HEAD/src/main/java/.DS_Store -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/RunningServerListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | public interface RunningServerListener { 14 | 15 | void charsRead(String chars); 16 | 17 | void closed(Integer exitCode); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | ceserver-pcileech 2 | Copyright 2021 Isabella Flores 3 | Licensed under the AGPL, version 3.0 4 | 1c3f5bd10d1722b1d224354349df9669de5700ae 5 | https://github.com/iflores/ceserver-pcileech 6 | 7 | Java Native Access 8 | Java Native Access (JNA) is licensed under the LGPL, version 2.1 9 | or later, or (from version 4.0 onward) the Apache License, 10 | version 2.0. 11 | https://github.com/java-native-access/jna 12 | 13 | JetBrains Java Annotations 14 | JetBrains Java Annotations is licensed under the Apache License, version 2.0 15 | https://github.com/JetBrains/java-annotations -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/WinApiException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | public class WinApiException extends RuntimeException { 14 | 15 | public WinApiException(String message, int errno) { 16 | super(message + " (errno=" + errno + ")"); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/TOKEN_ELEVATION.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | import com.sun.jna.Structure; 14 | import com.sun.jna.platform.win32.WinDef; 15 | 16 | @Structure.FieldOrder("TokenIsElevated") 17 | public class TOKEN_ELEVATION extends Structure { 18 | public WinDef.DWORD TokenIsElevated = new WinDef.DWORD(0); 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/Win32Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | import com.sun.jna.platform.win32.Kernel32; 14 | import com.sun.jna.platform.win32.Win32Exception; 15 | 16 | public class Win32Utils { 17 | 18 | public static void throwLastWin32Exception() { 19 | throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/PciLeechException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | public class PciLeechException extends RuntimeException { 14 | 15 | public PciLeechException() { 16 | } 17 | 18 | public PciLeechException(String message) { 19 | super(message); 20 | } 21 | 22 | public PciLeechException(String message, Throwable cause) { 23 | super(message, cause); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/ProcessInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | public class ProcessInfo { 14 | 15 | private final String _name; 16 | private final int _pid; 17 | 18 | public ProcessInfo(String name, int pid) { 19 | _name = name; 20 | _pid = pid; 21 | } 22 | 23 | public int getPid() { 24 | return _pid; 25 | } 26 | 27 | public String getName() { 28 | return _name; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/Win32Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | interface Win32Constants { 14 | 15 | int TH32CS_SNAPPROCESS = 0x02; 16 | int TH32CS_SNAPTHREAD = 0x04; 17 | int TH32CS_SNAPMODULE = 0x08; 18 | int TYPE_MEM_MAPPED = 0x40000; 19 | int TYPE_MEM_ = 0x20000; 20 | int TYPE_MEM_COMMIT = 0x1000; 21 | int TYPE_MEM_FREE = 0x10000; 22 | 23 | int PAGE_READONLY = 2; 24 | int PAGE_READWRITE = 4; 25 | int PAGE_WRITECOPY = 8; 26 | int PAGE_EXECUTE = 16; 27 | int PAGE_EXECUTE_READ = 32; 28 | int PAGE_EXECUTE_READWRITE = 64; 29 | int PAGE_EXECUTE_WRITECOPY = 128; 30 | int PAGE_GUARD = 256; 31 | int PAGE_NOACCESS = 1; 32 | int PAGE_NOCACHE = 512; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/DocumentChangeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | import javax.swing.event.DocumentEvent; 14 | import javax.swing.event.DocumentListener; 15 | 16 | public final class DocumentChangeListener implements DocumentListener { 17 | 18 | private final Runnable _runnable; 19 | 20 | public DocumentChangeListener(Runnable runnable) { 21 | _runnable = runnable; 22 | } 23 | 24 | @Override 25 | public void insertUpdate(DocumentEvent e) { 26 | documentChanged(); 27 | } 28 | 29 | @Override 30 | public void removeUpdate(DocumentEvent e) { 31 | documentChanged(); 32 | } 33 | 34 | @Override 35 | public void changedUpdate(DocumentEvent e) { 36 | documentChanged(); 37 | } 38 | 39 | private void documentChanged() { 40 | _runnable.run(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/GridBagConstraintsBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | import java.awt.*; 14 | 15 | public class GridBagConstraintsBuilder extends GridBagConstraints { 16 | 17 | public GridBagConstraintsBuilder gridx(int gridx) { 18 | this.gridx = gridx; 19 | return this; 20 | } 21 | 22 | public GridBagConstraintsBuilder anchor(int anchor) { 23 | this.anchor = anchor; 24 | return this; 25 | } 26 | 27 | public GridBagConstraintsBuilder insets(Insets insets) { 28 | this.insets = insets; 29 | return this; 30 | } 31 | 32 | public GridBagConstraintsBuilder weightx(double weightx) { 33 | this.weightx = weightx; 34 | return this; 35 | } 36 | 37 | public GridBagConstraintsBuilder fill(int fill) { 38 | this.fill = fill; 39 | return this; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/VMMDLL_MAP_VAD.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | import com.sun.jna.Pointer; 14 | import com.sun.jna.Structure; 15 | import com.sun.jna.WString; 16 | 17 | @Structure.FieldOrder({ 18 | "dwVersion", 19 | "_Reserved1_0", 20 | "_Reserved1_1", 21 | "_Reserved1_2", 22 | "_Reserved1_3", 23 | "cPage", 24 | "wszMultiText", 25 | "cbMultiText", 26 | "cMap", 27 | "pMapArray" 28 | }) 29 | public class VMMDLL_MAP_VAD extends Structure { 30 | public int dwVersion; 31 | public int _Reserved1_0; 32 | public int _Reserved1_1; 33 | public int _Reserved1_2; 34 | public int _Reserved1_3; 35 | public int cPage; 36 | public WString wszMultiText; 37 | public int cbMultiText; 38 | public int cMap; 39 | public VMMDLL_MAP_VADENTRY pMapArray; 40 | 41 | public VMMDLL_MAP_VAD(Pointer p) { 42 | super(p); 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/ToolHelp32Snapshot_Processes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | import java.util.ArrayList; 14 | import java.util.Iterator; 15 | import java.util.List; 16 | 17 | public class ToolHelp32Snapshot_Processes { 18 | 19 | private final List _results = new ArrayList<>(); 20 | private Iterator _processInfoIterator; 21 | 22 | public ToolHelp32Snapshot_Processes() { 23 | List pids = PciLeech.getPids(); 24 | for (Integer pid : pids) { 25 | _results.add(new ProcessInfo(PciLeech.getProcessExecutableName(pid), pid)); 26 | } 27 | } 28 | 29 | public void restartProcessInfo() { 30 | _processInfoIterator = _results.iterator(); 31 | } 32 | 33 | public boolean hasNextProcessInfo() { 34 | return _processInfoIterator.hasNext(); 35 | } 36 | 37 | public ProcessInfo nextProcessInfo() { 38 | return _processInfoIterator.next(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/ToolHelp32Snapshot_Modules.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | import java.util.Iterator; 14 | 15 | public class ToolHelp32Snapshot_Modules { 16 | 17 | private static final long MAX_UNSIGNED_INT = 0xffffffffL; 18 | private final SelectedProcess _selectedProcess; 19 | private Iterator> _moduleInfoIterator; 20 | 21 | public ToolHelp32Snapshot_Modules(SelectedProcess selectedProcess) { 22 | _selectedProcess = selectedProcess; 23 | } 24 | 25 | public boolean hasNextModuleInfo() { 26 | return _moduleInfoIterator.hasNext(); 27 | } 28 | 29 | public MemoryRegion nextModuleInfo() { 30 | return _moduleInfoIterator.next(); 31 | } 32 | 33 | public void restartModuleInfo() { 34 | _moduleInfoIterator = 35 | _selectedProcess 36 | .getMemoryMap() 37 | .stream() 38 | .filter(x -> x.getRegionSize() <= MAX_UNSIGNED_INT) 39 | .iterator(); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/MemoryRegion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | import org.jetbrains.annotations.NotNull; 14 | 15 | public class MemoryRegion implements Comparable> { 16 | 17 | private final T _userObject; 18 | private final long _regionStart; 19 | private final long _size; 20 | 21 | public MemoryRegion(T userObject, long regionStart, long size) { 22 | _userObject = userObject; 23 | _regionStart = regionStart; 24 | _size = size; 25 | } 26 | 27 | public T getUserObject() { 28 | return _userObject; 29 | } 30 | 31 | public long getRegionStart() { 32 | return _regionStart; 33 | } 34 | 35 | @Override 36 | public int compareTo(@NotNull MemoryRegion o) { 37 | return Long.compare(_regionStart, o._regionStart); 38 | } 39 | 40 | public long getRegionEnd() { 41 | return _regionStart + _size - 1; 42 | } 43 | 44 | public long getRegionSize() { 45 | return _size; 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return "[start=" + Long.toHexString(_regionStart) + ", size=" + _size + "]"; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/JnaPciLeech.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | import com.sun.jna.Library; 14 | import com.sun.jna.Pointer; 15 | import com.sun.jna.WString; 16 | 17 | @SuppressWarnings("BooleanMethodIsAlwaysInverted") 18 | public interface JnaPciLeech extends Library { 19 | 20 | boolean VMMDLL_Initialize(int argc, String[] argv); 21 | 22 | boolean VMMDLL_MemReadEx( 23 | int dwPID, 24 | long qwVA, 25 | Pointer pb, 26 | int cb, 27 | Pointer pcbReadOpt, 28 | long flags 29 | ); 30 | 31 | boolean VMMDLL_MemWrite( 32 | int dwPID, 33 | long qwVA, 34 | Pointer pb, 35 | int cb 36 | ); 37 | 38 | boolean VMMDLL_PidList( 39 | Pointer pPIDs, 40 | Pointer pcPIDs 41 | ); 42 | 43 | boolean VMMDLL_Map_GetVadW( 44 | int dwPID, 45 | VMMDLL_MAP_VAD pVadMap, 46 | Pointer pcbVadMap, 47 | boolean fIdentifyModules 48 | ); 49 | 50 | String VMMDLL_ProcessGetInformationString( 51 | int dwPID, 52 | int fOptionString 53 | ); 54 | 55 | long VMMDLL_ProcessGetModuleBaseW( 56 | int dwPID, 57 | WString wszModuleName 58 | ); 59 | 60 | } -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/VMMDLL_MAP_VADENTRY.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | import com.sun.jna.Structure; 14 | import com.sun.jna.WString; 15 | 16 | import java.util.Arrays; 17 | import java.util.List; 18 | 19 | @Structure.FieldOrder({ 20 | "vaStart", 21 | "vaEnd", 22 | "vaVad", 23 | "_dword0", 24 | "_dword1", 25 | "u2", 26 | "cbPrototypePte", 27 | "vaPrototypePte", 28 | "vaSubsection", 29 | "wszText", 30 | "cwszText", 31 | "_Reserved1", 32 | "vaFileObject", 33 | "cVadExPages", 34 | "cVadExPagesBase", 35 | "_Reserved2" 36 | }) 37 | public class VMMDLL_MAP_VADENTRY extends Structure { 38 | public long vaStart; 39 | public long vaEnd; 40 | public long vaVad; 41 | public int _dword0; // see header file for bit breakdown 42 | public int _dword1; // see header file for bit breakdown 43 | public int u2; 44 | public int cbPrototypePte; 45 | public long vaPrototypePte; 46 | public long vaSubsection; 47 | public WString wszText; 48 | public int cwszText; 49 | public int _Reserved1; 50 | public long vaFileObject; 51 | public int cVadExPages; 52 | public int cVadExPagesBase; 53 | public long _Reserved2; 54 | 55 | } 56 | 57 | -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/VmmDllFlags.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | public enum VmmDllFlags { 14 | 15 | // do not use the data cache (force reading from memory acquisition device) 16 | NOCACHE(0x0001), 17 | // zero pad failed physical memory reads and report success if read within range of physical memory. 18 | ZEROPAD_ON_FAIL(0x0002), 19 | // force use of cache - fail non-cached pages - only valid for reads, invalid with NOCACHE/ZEROPAD_ON_FAIL. 20 | FORCECACHE_READ(0x0008), 21 | // do not try to retrieve memory from paged out memory from pagefile/compressed (even if possible) 22 | NOPAGING(0x0010), 23 | // do not try to retrieve memory from paged out memory if read would incur additional I/O (even if possible). 24 | NOPAGING_IO(0x0020), 25 | // do not write back to the data cache upon successful read from memory acquisition device. 26 | NOCACHEPUT(0x0100), 27 | // only fetch from the most recent active cache region when reading. 28 | CACHE_RECENT_ONLY(0x0200), 29 | // do not perform additional predictive page reads (default on smaller requests). 30 | NO_PREDICTIVE_READ(0x0400); 31 | 32 | private final long _value; 33 | 34 | VmmDllFlags(long value) { 35 | _value = value; 36 | } 37 | 38 | public long getValue() { 39 | return _value; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/CommandConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | public interface CommandConstants { 14 | 15 | // byte CMD_GETVERSION = 0; 16 | // byte CMD_CLOSECONNECTION = 1; 17 | // byte CMD_TERMINATESERVER = 2; 18 | byte CMD_OPENPROCESS = 3; 19 | byte CMD_CREATETOOLHELP32SNAPSHOT = 4; 20 | byte CMD_PROCESS32FIRST = 5; 21 | byte CMD_PROCESS32NEXT = 6; 22 | byte CMD_CLOSEHANDLE = 7; 23 | byte CMD_VIRTUALQUERYEX = 8; 24 | byte CMD_READPROCESSMEMORY = 9; 25 | byte CMD_WRITEPROCESSMEMORY = 10; 26 | // byte CMD_STARTDEBUG = 11; 27 | // byte CMD_STOPDEBUG = 12; 28 | // byte CMD_WAITFORDEBUGEVENT = 13; 29 | // byte CMD_CONTINUEFROMDEBUGEVENT = 14; 30 | // byte CMD_SETBREAKPOINT = 15; 31 | // byte CMD_REMOVEBREAKPOINT = 16; 32 | // byte CMD_SUSPENDTHREAD = 17; 33 | // byte CMD_RESUMETHREAD = 18; 34 | // byte CMD_GETTHREADCONTEXT = 19; 35 | // byte CMD_SETTHREADCONTEXT = 20; 36 | byte CMD_GETARCHITECTURE = 21; 37 | byte CMD_MODULE32FIRST = 22; 38 | byte CMD_MODULE32NEXT = 23; 39 | 40 | byte CMD_GETSYMBOLLISTFROMFILE = 24; 41 | // byte CMD_LOADEXTENSION = 25; 42 | 43 | // byte CMD_ALLOC = 26; 44 | // byte CMD_FREE = 27; 45 | // byte CMD_CREATETHREAD = 28; 46 | // byte CMD_LOADMODULE = 29; 47 | // byte CMD_SPEEDHACK_SETSPEED = 30; 48 | 49 | byte CMD_VIRTUALQUERYEXFULL = 31; 50 | byte CMD_GETREGIONINFO = 32; 51 | 52 | // byte CMD_AOBSCAN = (byte) 200; 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/SelectedProcess.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | import java.util.List; 14 | 15 | public class SelectedProcess { 16 | 17 | private final String _executableName; 18 | private final int _pid; 19 | private MemoryMap _memoryMap; 20 | 21 | public SelectedProcess(int pid) { 22 | _pid = pid; 23 | _executableName = PciLeech.getProcessExecutableName(pid); 24 | } 25 | 26 | public byte[] readMemory(long address, int size) { 27 | return PciLeech.readMemory( 28 | _pid, 29 | address, 30 | size, 31 | VmmDllFlags.NOCACHE, 32 | VmmDllFlags.NOCACHEPUT, 33 | VmmDllFlags.NO_PREDICTIVE_READ, 34 | VmmDllFlags.NOPAGING, 35 | VmmDllFlags.NOPAGING_IO 36 | ); 37 | } 38 | 39 | public void writeMemory(long address, byte[] bytes) { 40 | PciLeech.writeMemory( 41 | _pid, 42 | address, 43 | bytes 44 | ); 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return _executableName; 50 | } 51 | 52 | public MemoryMap getMemoryMap() { 53 | if (_memoryMap == null) { 54 | MemoryMap memoryMap = new MemoryMap<>(); 55 | List vadInfos = PciLeech.getVad(_pid, true); 56 | for (VadInfo vadInfo : vadInfos) { 57 | long regionSize = vadInfo.getEnd() - vadInfo.getStart() + 1; 58 | if (regionSize < Integer.MAX_VALUE) { 59 | memoryMap.add( 60 | new MemoryRegion<>( 61 | vadInfo, 62 | vadInfo.getStart(), 63 | regionSize 64 | ) 65 | ); 66 | } 67 | } 68 | _memoryMap = memoryMap; 69 | } 70 | return _memoryMap; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/MemoryMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | import org.jetbrains.annotations.NotNull; 14 | 15 | import java.util.Iterator; 16 | import java.util.TreeSet; 17 | import java.util.stream.Stream; 18 | 19 | public class MemoryMap implements Iterable> { 20 | 21 | private final TreeSet> _treeSet = new TreeSet<>(); 22 | 23 | public void add(MemoryRegion newEntry) { 24 | MemoryRegion previousEntry = _treeSet.floor(newEntry); 25 | MemoryRegion nextEntry = _treeSet.ceiling(newEntry); 26 | if (regionOverlaps(newEntry, previousEntry)) { 27 | throw new RuntimeException("Overlapping entries: " + newEntry + "/" + previousEntry); 28 | } 29 | if (regionOverlaps(newEntry, nextEntry)) { 30 | throw new RuntimeException("Overlapping entries: " + nextEntry + "/" + newEntry); 31 | } 32 | if (!_treeSet.add(newEntry)) { 33 | throw new RuntimeException("Duplicate memory range: " + newEntry); 34 | } 35 | } 36 | 37 | private boolean regionOverlaps(MemoryRegion entry1, MemoryRegion entry2) { 38 | return entry1 != null 39 | && entry2 != null 40 | && entry1.getRegionStart() <= entry2.getRegionEnd() 41 | && entry2.getRegionStart() <= entry1.getRegionEnd(); 42 | } 43 | 44 | public MemoryRegion getMemoryRegionContaining(long address) { 45 | MemoryRegion floorEntry = floor(address); 46 | if (floorEntry != null) { 47 | if (floorEntry.getRegionEnd() >= address) { 48 | return floorEntry; 49 | } 50 | MemoryRegion ceilEntry = ceil(address); 51 | if (ceilEntry != null) { 52 | return new MemoryRegion<>(null, floorEntry.getRegionEnd() + 1, ceilEntry.getRegionStart() - floorEntry.getRegionEnd() - 1); 53 | } 54 | return null; // past end 55 | } 56 | MemoryRegion ceilEntry = ceil(address); 57 | if (ceilEntry != null) { 58 | return new MemoryRegion<>(null, 0L, ceilEntry.getRegionStart()); 59 | } 60 | return null; 61 | } 62 | 63 | private MemoryRegion floor(long address) { 64 | return _treeSet.stream().filter(x -> x.getRegionStart() <= address).reduce((first, second) -> second).orElse(null); 65 | } 66 | 67 | private MemoryRegion ceil(long address) { 68 | return _treeSet.stream().filter(x -> x.getRegionStart() >= address).findFirst().orElse(null); 69 | } 70 | 71 | @NotNull 72 | @Override 73 | public Iterator> iterator() { 74 | return _treeSet.iterator(); 75 | } 76 | 77 | @NotNull 78 | public Stream> stream() { 79 | return _treeSet.stream(); 80 | } 81 | 82 | public int getRegionCount() { 83 | return _treeSet.size(); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/RunningServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | import javax.swing.*; 14 | import java.io.IOException; 15 | import java.io.InputStreamReader; 16 | import java.io.OutputStream; 17 | import java.io.Reader; 18 | import java.util.HashSet; 19 | import java.util.Set; 20 | 21 | public class RunningServer extends Thread { 22 | 23 | private final Process _process; 24 | private final Set _listeners = new HashSet<>(); 25 | private boolean _closed; 26 | 27 | public RunningServer(Process process) { 28 | _process = process; 29 | } 30 | 31 | @Override 32 | public void run() { 33 | try { 34 | Reader in = new InputStreamReader(_process.getInputStream()); 35 | char[] buf = new char[16384]; 36 | while (true) { 37 | int count = in.read(buf); 38 | if (count < 0) { 39 | break; 40 | } 41 | if (count > 0) { 42 | fireCharsRead(buf, 0, count); 43 | } 44 | } 45 | System.out.flush(); 46 | fireClose(_process.waitFor()); 47 | } catch (IOException | InterruptedException ex) { 48 | ex.printStackTrace(); 49 | } finally { 50 | fireClose(null); 51 | } 52 | } 53 | 54 | public void addListener(RunningServerListener l) { 55 | _listeners.add(l); 56 | } 57 | 58 | private void fireCharsRead(char[] chars, @SuppressWarnings("SameParameterValue") int offset, int length) { 59 | String s = new String(chars, offset, length); // make safe copy 60 | SwingUtilities.invokeLater( 61 | () -> { 62 | for (RunningServerListener listener : _listeners) { 63 | listener.charsRead(s); 64 | } 65 | } 66 | ); 67 | } 68 | 69 | private void fireClose(Integer exitCode) { 70 | SwingUtilities.invokeLater( 71 | () -> { 72 | if (_closed) { 73 | return; 74 | } 75 | _closed = true; 76 | for (RunningServerListener listener : _listeners) { 77 | listener.closed(exitCode); 78 | } 79 | } 80 | ); 81 | } 82 | 83 | public void shutdownNow() { 84 | try { 85 | OutputStream pout = _process.getOutputStream(); 86 | pout.write('\n'); 87 | pout.flush(); 88 | } catch (Throwable t) { 89 | _process.destroyForcibly(); 90 | t.printStackTrace(); 91 | } 92 | } 93 | 94 | public void shutdownNowAndWait() throws InterruptedException { 95 | _process.destroyForcibly(); 96 | _process.waitFor(); 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/Settings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | import java.io.ByteArrayInputStream; 14 | import java.io.ByteArrayOutputStream; 15 | import java.io.DataInputStream; 16 | import java.io.DataOutputStream; 17 | import java.util.prefs.BackingStoreException; 18 | import java.util.prefs.Preferences; 19 | 20 | public class Settings { 21 | 22 | private static final String ROOT_KEY = "iflores.ceserver.pcileech"; 23 | 24 | private String _memprocfsExePath; 25 | private String _pciLeechArguments; 26 | 27 | private Settings(String memprocfsExePath, String pciLeechArguments) { 28 | _memprocfsExePath = memprocfsExePath; 29 | _pciLeechArguments = pciLeechArguments; 30 | } 31 | 32 | public static Settings load() { 33 | try { 34 | byte[] settingsBytes = Preferences.userRoot().getByteArray(ROOT_KEY, null); 35 | String memprocfsExePath; 36 | String pcileechArguments; 37 | if (settingsBytes == null) { 38 | memprocfsExePath = ""; 39 | pcileechArguments = "-printf -v -device fpga"; 40 | } else { 41 | DataInputStream in = new DataInputStream(new ByteArrayInputStream(settingsBytes)); 42 | int version = in.readInt(); 43 | if (version > 0) { 44 | throw new IllegalArgumentException("I don't know how to handle settings version " + version); 45 | } 46 | memprocfsExePath = in.readUTF(); 47 | pcileechArguments = in.readUTF(); 48 | } 49 | return new Settings( 50 | memprocfsExePath, 51 | pcileechArguments 52 | ); 53 | } catch (Throwable t) { 54 | throw new RuntimeException("Unable to read settings", t); 55 | } 56 | } 57 | 58 | public void save() { 59 | try { 60 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 61 | DataOutputStream out = new DataOutputStream(baos); 62 | out.writeInt(0); // version 0 63 | out.writeUTF(_memprocfsExePath); 64 | out.writeUTF(_pciLeechArguments); 65 | Preferences prefRoot = Preferences.userRoot(); 66 | prefRoot.putByteArray(ROOT_KEY, baos.toByteArray()); 67 | try { 68 | prefRoot.sync(); 69 | } catch (BackingStoreException e) { 70 | e.printStackTrace(); 71 | } 72 | } catch (Throwable t) { 73 | throw new RuntimeException("Unable to write settings", t); 74 | } 75 | } 76 | 77 | public String getMemProcFsExePath() { 78 | return _memprocfsExePath; 79 | } 80 | 81 | public void setMemProcFsExePath(String memprocfsExePath) { 82 | _memprocfsExePath = memprocfsExePath; 83 | } 84 | 85 | public String getPciLeechArguments() { 86 | return _pciLeechArguments; 87 | } 88 | 89 | public void setPciLeechArguments(String pciLeechArguments) { 90 | _pciLeechArguments = pciLeechArguments; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ceserver-pcileech 2 | 3 | Ceserver-pcileech allows using Cheat Engine against a remote machine, without the need to install ANY software on that 4 | remote machine. It was developed independently from the Cheat Engine software by DarkByte and PCILeech by Ulf Frisk, and 5 | is not affiliated with either. 6 | 7 | All Cheat Engine functions may not be available. Currently implemented is the ability to: 8 | 9 | * Connect to a Process 10 | * Read Memory 11 | * Write Memory 12 | * Search Memory 13 | * Browse Memory 14 | * View Module Listing 15 | 16 | Other functions may or may not work (likely the latter). 17 | 18 | # Terminology 19 | 20 | * "Source": The machine running Cheat Engine and PCILeech. 21 | * "Target": The machine running the process to be inspected/altered. 22 | 23 | # Prerequisites 24 | 25 | * Two machines running Windows 26 | * [MemProcFS](https://github.com/ufrisk/MemProcFS) running on the source machine (part of the PCILeech ecosystem by Ulf Frisk) 27 | * Additional requirements, including possibly the purchase of a hardware FPGA card if you choose to go that route. See 28 | the [PCILeech documentation](https://github.com/ufrisk/pcileech/blob/master/readme.md) for your particular use case. 29 | 30 | # Installation Option #1 - Downloading the Binary 31 | 32 | It is *recommended* that you build ceserver-pcileech yourself from its source code: 33 | 34 | 1. Download and install [Temurin 17](https://adoptium.net/?variant=openjdk17) (Any other Java 17+ is fine too) 35 | 2. Download [the latest ceserver-pcileech.jar](https://github.com/isabellaflores/ceserver-pcileech/releases) from Github 36 | 3. Copy the downloaded ceserver-pcileech.jar file to your Desktop 37 | 4. Continue with "Running the Server" section below 38 | 39 | # Installation Option #2 - Building from Source 40 | 41 | It is *recommended* that you build ceserver-pcileech yourself from its source code: 42 | 43 | 1. Download and install [Temurin 17](https://adoptium.net/?variant=openjdk17) (Any other Java 17+ is fine too) 44 | 2. Download and install [Apache Maven](https://www.youtube.com/watch?v=--Iv5vBIHjI) 45 | 3. Download [the latest source code](https://github.com/isabellaflores/ceserver-pcileech/releases) from Github 46 | 4. Unzip the source code to any desired location 47 | 5. Build it using Maven by typing "mvn package" in the source code directory 48 | 6. Copy the ceserver-pcileech.jar file from the 'target' directory to your Desktop 49 | 7. Continue with "Running the Server" section below 50 | 51 | # Running the Server 52 | 53 | 1. Open a command prompt (Win+R then type "cmd") 54 | 2. Type "cd Desktop" 55 | 3. Type "java -jar ceserver-pcileech.jar" 56 | 4. Configure the server in the window that appears 57 | 5. Press the "Start Server" button 58 | 6. The server will now be listening on the default port, 52736. 59 | 60 | # Connecting to the server 61 | 62 | 1. Open Cheat Engine 63 | 2. File -> Open Process 64 | 3. Click 'Network' 65 | 4. Type 'localhost' in the 'Host' field 66 | 5. Click 'Connect' and select a process to open 67 | 68 | # Contributing to ceserver-pcileech 69 | 70 | Thank you for your interest in contributing to ceserver-pcileech! 71 | 72 | To submit your changes to me, please [create a pull request](https://github.com/isabellaflores/ceserver-pcileech/pulls), 73 | and I will personally review your submission. If it is accepted, you will receive credit for your submission. If you'd 74 | like your submission to be anonymous or pseudonymous, please let me know. -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/Main.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | import com.sun.jna.platform.win32.*; 14 | import com.sun.jna.ptr.IntByReference; 15 | 16 | import javax.swing.*; 17 | import java.text.SimpleDateFormat; 18 | 19 | import static com.sun.jna.platform.win32.Shell32.SEE_MASK_NOCLOSEPROCESS; 20 | import static com.sun.jna.platform.win32.WinUser.SW_SHOWDEFAULT; 21 | 22 | public class Main { 23 | 24 | private static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); 25 | 26 | public static void main(String[] args) { 27 | maybeRerunAsAdministrator(args); 28 | Settings settings = Settings.load(); 29 | SwingUtilities.invokeLater( 30 | () -> { 31 | MainFrame f = new MainFrame(settings); 32 | f.setVisible(true); 33 | } 34 | ); 35 | } 36 | 37 | private static void maybeRerunAsAdministrator(String[] args) { 38 | WinNT.HANDLEByReference phToken = new WinNT.HANDLEByReference(); 39 | WinNT.HANDLE processHandle = Kernel32.INSTANCE.GetCurrentProcess(); 40 | if (!Advapi32.INSTANCE.OpenProcessToken(processHandle, WinNT.TOKEN_QUERY, phToken)) { 41 | Win32Utils.throwLastWin32Exception(); 42 | } 43 | TOKEN_ELEVATION tokenInformation = new TOKEN_ELEVATION(); 44 | IntByReference cbNeeded = new IntByReference(0); 45 | 46 | if (!Advapi32.INSTANCE.GetTokenInformation( 47 | phToken.getValue(), 48 | WinNT.TOKEN_INFORMATION_CLASS.TokenElevation, 49 | tokenInformation, 50 | tokenInformation.size(), 51 | cbNeeded 52 | )) { 53 | Win32Utils.throwLastWin32Exception(); 54 | } 55 | 56 | if (tokenInformation.TokenIsElevated.intValue() == 0) { 57 | ShellAPI.SHELLEXECUTEINFO execInfo = new ShellAPI.SHELLEXECUTEINFO(); 58 | execInfo.lpFile = System.getProperty("java.home") + "/bin/javaw.exe"; 59 | StringBuilder params = new StringBuilder(); 60 | params.append("-classpath "); 61 | params.append(System.getProperty("java.class.path")); 62 | params.append(' '); 63 | params.append(Main.class.getName()); 64 | for (String arg : args) { 65 | params.append(' '); 66 | params.append(arg); 67 | } 68 | execInfo.lpParameters = params.toString(); 69 | execInfo.nShow = SW_SHOWDEFAULT; 70 | execInfo.fMask = SEE_MASK_NOCLOSEPROCESS; 71 | execInfo.lpVerb = "runas"; 72 | boolean result = Shell32.INSTANCE.ShellExecuteEx(execInfo); 73 | if (!result) { 74 | Win32Utils.throwLastWin32Exception(); 75 | } 76 | System.exit(0); 77 | } 78 | } 79 | 80 | public static void log(ClientHandler clientHandler, String message) { 81 | synchronized (System.out) { 82 | System.out.println( 83 | "[" 84 | + SIMPLE_DATE_FORMAT.format(System.currentTimeMillis()) 85 | + " " 86 | + (clientHandler == null ? "---SYSTEM---" : clientHandler) 87 | + "] " 88 | + message 89 | ); 90 | } 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/VadInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | import java.io.Serializable; 14 | 15 | public class VadInfo implements Serializable { 16 | 17 | private final String _name; 18 | private final long _start; 19 | private final long _end; 20 | private final int _type; 21 | private final int _protection; 22 | private final int _fImage; 23 | private final int _fFile; 24 | private final int _fPageFile; 25 | private final int _fPrivateMemory; 26 | private final int _fTeb; 27 | private final int _fStack; 28 | private final int _fSpare; 29 | private final int _HeapNum; 30 | private final int _fHeap; 31 | private final int _cwszDescription; 32 | private final int _commitCharge; 33 | private final int _memCommit; 34 | 35 | public VadInfo(String name, long start, long end, int dword0, int dword1) { 36 | _name = name; 37 | _start = start; 38 | _end = end; 39 | 40 | _type = getValue(dword0, 0, 3); 41 | _protection = getValue(dword0, 3, 5); 42 | _fImage = getValue(dword0, 8, 1); 43 | _fFile = getValue(dword0, 9, 1); 44 | _fPageFile = getValue(dword0, 10, 1); 45 | _fPrivateMemory = getValue(dword0, 11, 1); 46 | _fTeb = getValue(dword0, 12, 1); 47 | _fStack = getValue(dword0, 13, 1); 48 | _fSpare = getValue(dword0, 14, 2); 49 | _HeapNum = getValue(dword0, 16, 7); 50 | _fHeap = getValue(dword0, 23, 1); 51 | _cwszDescription = getValue(dword0, 24, 8); 52 | _commitCharge = getValue(dword1, 0, 31); 53 | _memCommit = getValue(dword1, 31, 1); 54 | } 55 | 56 | public String getName() { 57 | return _name; 58 | } 59 | 60 | public long getStart() { 61 | return _start; 62 | } 63 | 64 | public long getEnd() { 65 | return _end; 66 | } 67 | 68 | @Override 69 | public String toString() { 70 | return _name + " (" + Long.toHexString(_start) + "-" + Long.toHexString(_end) + ")"; 71 | } 72 | 73 | private int getValue(int mask, int start, int length) { 74 | return (mask << (32 - start - length)) >>> (32 - length); 75 | } 76 | 77 | 78 | public int getProtection() { 79 | return _protection; 80 | } 81 | 82 | public int getfImage() { 83 | return _fImage; 84 | } 85 | 86 | public int getfFile() { 87 | return _fFile; 88 | } 89 | 90 | public int getfPageFile() { 91 | return _fPageFile; 92 | } 93 | 94 | public int getfPrivateMemory() { 95 | return _fPrivateMemory; 96 | } 97 | 98 | public int getfTeb() { 99 | return _fTeb; 100 | } 101 | 102 | public int getfStack() { 103 | return _fStack; 104 | } 105 | 106 | public int getfSpare() { 107 | return _fSpare; 108 | } 109 | 110 | public int getHeapNum() { 111 | return _HeapNum; 112 | } 113 | 114 | public int getfHeap() { 115 | return _fHeap; 116 | } 117 | 118 | public int getCwszDescription() { 119 | return _cwszDescription; 120 | } 121 | 122 | public int getCommitCharge() { 123 | return _commitCharge; 124 | } 125 | 126 | public int getMemCommit() { 127 | return _memCommit; 128 | } 129 | 130 | public int getType() { 131 | return _type; 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/ServerMain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | import java.io.File; 14 | import java.io.FileNotFoundException; 15 | import java.io.IOException; 16 | import java.net.BindException; 17 | import java.net.InetSocketAddress; 18 | import java.nio.channels.ServerSocketChannel; 19 | import java.nio.channels.SocketChannel; 20 | import java.util.ArrayList; 21 | import java.util.Arrays; 22 | import java.util.List; 23 | 24 | public class ServerMain { 25 | 26 | public static final int DEFAULT_PORT_NUMBER = 52736; 27 | 28 | public static void main(String[] args) { 29 | try { 30 | if (args.length != 2) { 31 | System.err.println("ERROR: Expected 2 command line arguments"); 32 | System.exit(-1); 33 | } 34 | // start thread that ends the process on any input from parent process 35 | new Thread(() -> { 36 | try { 37 | //noinspection ResultOfMethodCallIgnored 38 | System.in.read(); // wait for any data 39 | } catch (Throwable t) { 40 | t.printStackTrace(); 41 | } finally { 42 | System.exit(0); 43 | } 44 | }).start(); 45 | File jnaLibraryPath = new File(args[0]); 46 | if (!jnaLibraryPath.exists()) { 47 | throw new FileNotFoundException("JNA Library Path does not exist: '" + args[0] + "'"); 48 | } 49 | try { 50 | List pciLeechArgs = new ArrayList<>(); 51 | pciLeechArgs.add(""); 52 | pciLeechArgs.addAll(Arrays.asList(args[1].split(" +"))); 53 | System.setProperty("jna.library.path", jnaLibraryPath.getParent()); 54 | int numTries = 0; 55 | while (true) { 56 | System.out.println("Initializing PCILeech..."); 57 | boolean result = PciLeech.initialize(pciLeechArgs.toArray(String[]::new)); 58 | if (result) { 59 | break; 60 | } 61 | if (++numTries >= 10) { 62 | throw new PciLeechException("Unable to initialize PCILeech -- Giving up."); 63 | } else { 64 | System.out.println("Failed to initialize PCILeech -- Trying again..."); 65 | } 66 | } 67 | System.out.println("PCILeech Initialization Complete."); 68 | runServer(); 69 | } catch (UnsatisfiedLinkError ex) { 70 | throw new PciLeechException("Unable to load PCILeech's VMM DLL.\nCheck MemProcFS location.", ex); 71 | } 72 | } catch (Throwable t) { 73 | t.printStackTrace(); 74 | } finally { 75 | System.exit(-1); 76 | } 77 | } 78 | 79 | private static void runServer() throws IOException { 80 | ServerSocketChannel ss = ServerSocketChannel.open(); 81 | int port = DEFAULT_PORT_NUMBER; 82 | try { 83 | ss.bind(new InetSocketAddress(port)); 84 | } catch (BindException ex) { 85 | throw new IOException("Unable to listen on port " + port, ex); 86 | } 87 | System.err.println("Server running on port " + port + "..."); 88 | //noinspection InfiniteLoopStatement 89 | while (true) { 90 | SocketChannel socketChannel = ss.accept(); 91 | ClientHandler clientHandler = new ClientHandler(socketChannel); 92 | clientHandler.start(); 93 | } 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 4.0.0 14 | 15 | iflores 16 | ceserver-pcileech 17 | 1.1-SNAPSHOT 18 | 19 | 20 | https://github.com/isabellaflores/ceserver-pcileech 21 | scm:git:git://github.com/isabellaflores/ceserver-pcileech.git 22 | scm:git:git@github.com:isabellaflores/ceserver-pcileech.git 23 | HEAD 24 | 25 | 26 | 27 | do_not_use 28 | 29 | 30 | org.apache.maven.plugins 31 | maven-compiler-plugin 32 | 3.8.1 33 | 34 | 17 35 | 17 36 | 37 | 38 | 39 | org.apache.maven.plugins 40 | maven-jar-plugin 41 | 3.2.0 42 | 43 | 44 | 45 | true 46 | 47 | 48 | 49 | 50 | 51 | org.apache.maven.plugins 52 | maven-shade-plugin 53 | 3.2.4 54 | 55 | 56 | package 57 | 58 | shade 59 | 60 | 61 | 62 | 63 | iflores.ceserver.pcileech.Main 64 | 65 | 66 | target/ceserver-pcileech.jar 67 | 68 | 69 | *:* 70 | 71 | META-INF/* 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | maven-deploy-plugin 84 | 2.7 85 | 86 | true 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | org.jetbrains 95 | annotations 96 | 23.0.0 97 | 98 | 99 | net.java.dev.jna 100 | jna 101 | 5.9.0 102 | 103 | 104 | net.java.dev.jna 105 | jna-platform 106 | 5.9.0 107 | 108 | 109 | 110 | 111 | 17 112 | 17 113 | UTF-8 114 | 115 | 116 | -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/PciLeech.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | import com.sun.jna.Native; 14 | import com.sun.jna.Pointer; 15 | import org.jetbrains.annotations.NotNull; 16 | 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | 20 | public class PciLeech { 21 | 22 | private static final JnaPciLeech _jnaPciLeech = Native.load("vmm", JnaPciLeech.class); 23 | 24 | private PciLeech() { 25 | } 26 | 27 | @NotNull 28 | public static List getPids() { 29 | long pcPIDs_malloc = Native.malloc(4); 30 | try { 31 | Pointer pcPIDs = new Pointer(pcPIDs_malloc); 32 | pcPIDs.clear(4); 33 | if ( 34 | !_jnaPciLeech.VMMDLL_PidList( 35 | Pointer.NULL, 36 | pcPIDs 37 | ) 38 | ) { 39 | throw new PciLeechException(); 40 | } 41 | int bufferSize = pcPIDs.getInt(0) * 4; 42 | long pdwPIDs_malloc = Native.malloc(bufferSize); 43 | try { 44 | Pointer pdwPIDs = new Pointer(pdwPIDs_malloc); 45 | pdwPIDs.clear(bufferSize); 46 | if ( 47 | !_jnaPciLeech.VMMDLL_PidList( 48 | pdwPIDs, 49 | pcPIDs 50 | ) 51 | ) { 52 | throw new PciLeechException(); 53 | } 54 | List results = new ArrayList<>(); 55 | int numResults = pcPIDs.getInt(0); 56 | for (int i = 0; i < numResults; i++) { 57 | results.add(pdwPIDs.getInt(i * 4L)); 58 | } 59 | return results; 60 | } finally { 61 | Native.free(pdwPIDs_malloc); 62 | } 63 | } finally { 64 | Native.free(pcPIDs_malloc); 65 | } 66 | } 67 | 68 | public static List getVad(int pid, boolean identifyModules) { 69 | long pcbVadMap_malloc = Native.malloc(4); 70 | try { 71 | Pointer pcbVadMap = new Pointer(pcbVadMap_malloc); 72 | pcbVadMap.clear(4); 73 | if ( 74 | !_jnaPciLeech.VMMDLL_Map_GetVadW( 75 | pid, 76 | null, 77 | pcbVadMap, 78 | identifyModules 79 | ) 80 | ) { 81 | throw new PciLeechException(); 82 | } 83 | int bufferSize = pcbVadMap.getInt(0); 84 | long pVadMap_malloc = Native.malloc(bufferSize); 85 | try { 86 | Pointer pVadMap = new Pointer(pVadMap_malloc); 87 | pVadMap.clear(bufferSize); 88 | VMMDLL_MAP_VAD map = new VMMDLL_MAP_VAD(pVadMap); 89 | if ( 90 | !_jnaPciLeech.VMMDLL_Map_GetVadW( 91 | pid, 92 | map, 93 | pcbVadMap, 94 | identifyModules 95 | ) 96 | ) { 97 | throw new PciLeechException(); 98 | } 99 | List vadInfos = new ArrayList<>(); 100 | VMMDLL_MAP_VADENTRY[] entries = (VMMDLL_MAP_VADENTRY[]) map.pMapArray.toArray(map.cMap); 101 | for (VMMDLL_MAP_VADENTRY entry : entries) { 102 | VadInfo vadInfo = new VadInfo( 103 | entry.wszText.toString(), 104 | entry.vaStart, 105 | entry.vaEnd, 106 | entry._dword0, 107 | entry._dword1 108 | ); 109 | vadInfos.add(vadInfo); 110 | } 111 | return vadInfos; 112 | } finally { 113 | Native.free(pVadMap_malloc); 114 | } 115 | } finally { 116 | Native.free(pcbVadMap_malloc); 117 | } 118 | } 119 | 120 | public static String getProcessExecutableName(int pid) { 121 | return _jnaPciLeech.VMMDLL_ProcessGetInformationString( 122 | pid, 123 | 2 124 | ); 125 | } 126 | 127 | public static byte[] readMemory(int pid, long address, int size, VmmDllFlags... flags) { 128 | if (address < 0) { 129 | throw new IllegalArgumentException(); 130 | } 131 | if (size < 0) { 132 | return new byte[0]; 133 | } 134 | if (size > 1024 * 1024 * 1024) { 135 | throw new IllegalArgumentException(); 136 | } 137 | if (size == 0) { 138 | return new byte[0]; 139 | } 140 | long flagsLong = 0; 141 | for (VmmDllFlags flag : flags) { 142 | flagsLong |= flag.getValue(); 143 | } 144 | 145 | long buffer_malloc = Native.malloc(size); 146 | try { 147 | Pointer pb = new Pointer(buffer_malloc); 148 | long pcbReadOpt_malloc = Native.malloc(4); 149 | try { 150 | Pointer pcbReadOpt = new Pointer(pcbReadOpt_malloc); 151 | int bytesRemaining = size; 152 | Pointer readPointer = pb; 153 | while (true) { 154 | boolean result = _jnaPciLeech.VMMDLL_MemReadEx( 155 | pid, 156 | address, 157 | readPointer, 158 | bytesRemaining, 159 | pcbReadOpt, 160 | flagsLong 161 | ); 162 | int count = pcbReadOpt.getInt(0); 163 | if (!result) { 164 | throw new PciLeechException(); 165 | } 166 | if (count <= 0) { 167 | break; 168 | } 169 | address += count; 170 | bytesRemaining -= count; 171 | if (bytesRemaining <= 0) { 172 | if (bytesRemaining < 0) { 173 | throw new IllegalStateException(); 174 | } 175 | break; 176 | } 177 | readPointer = readPointer.share(count); 178 | } 179 | int totalRead = size - bytesRemaining; 180 | byte[] buf = new byte[totalRead]; 181 | pb.read(0L, buf, 0, totalRead); 182 | return buf; 183 | } finally { 184 | Native.free(pcbReadOpt_malloc); 185 | } 186 | } finally { 187 | Native.free(buffer_malloc); 188 | } 189 | } 190 | 191 | public static void writeMemory(int pid, long address, byte[] bytes) { 192 | if (address < 0) { 193 | throw new IllegalArgumentException(); 194 | } 195 | long buffer_malloc = Native.malloc(bytes.length); 196 | try { 197 | Pointer pb = new Pointer(buffer_malloc); 198 | pb.write(0L, bytes, 0, bytes.length); 199 | int bytesRemaining = bytes.length; 200 | boolean result = _jnaPciLeech.VMMDLL_MemWrite( 201 | pid, 202 | address, 203 | pb, 204 | bytesRemaining 205 | ); 206 | if (!result) { 207 | throw new PciLeechException(); 208 | } 209 | } finally { 210 | Native.free(buffer_malloc); 211 | } 212 | } 213 | 214 | public static boolean initialize(String[] args) { 215 | return _jnaPciLeech.VMMDLL_Initialize(args.length, args); 216 | } 217 | } 218 | -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/MainFrame.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | import javax.swing.*; 14 | import javax.swing.border.EmptyBorder; 15 | import javax.swing.filechooser.FileFilter; 16 | import java.awt.*; 17 | import java.io.File; 18 | import java.io.IOException; 19 | import java.util.concurrent.atomic.AtomicReference; 20 | 21 | public class MainFrame extends JFrame implements RunningServerListener { 22 | 23 | private static final AtomicReference _server = new AtomicReference<>(); 24 | private final JPanel _settingsPanel; 25 | private final JButton _startStopButton; 26 | private final JTextArea _outputArea; 27 | 28 | public MainFrame(Settings settings) { 29 | Runtime.getRuntime().addShutdownHook( 30 | new Thread(() -> { 31 | RunningServer server = _server.get(); 32 | if (server != null) { 33 | try { 34 | server.shutdownNowAndWait(); 35 | } catch (Throwable t) { 36 | t.printStackTrace(); 37 | } 38 | } 39 | }) 40 | ); 41 | 42 | setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 43 | 44 | setLayout(new BorderLayout()); 45 | _settingsPanel = new JPanel(new GridBagLayout()); 46 | _settingsPanel.setBorder(new EmptyBorder(10, 10, 10, 10)); 47 | add(_settingsPanel, BorderLayout.NORTH); 48 | JPanel buttonPanel = new JPanel(); 49 | add(buttonPanel, BorderLayout.SOUTH); 50 | _settingsPanel.add( 51 | new JLabel("MemProcFS.exe Location:"), 52 | new GridBagConstraintsBuilder() 53 | .gridx(0) 54 | .anchor(GridBagConstraints.EAST) 55 | ); 56 | JTextField memprocFsPathTextField = new JTextField(30); 57 | memprocFsPathTextField.setText(settings.getMemProcFsExePath()); 58 | memprocFsPathTextField.setEditable(false); 59 | _settingsPanel.add( 60 | memprocFsPathTextField, 61 | new GridBagConstraintsBuilder() 62 | .gridx(1) 63 | .insets(new Insets(0, 5, 0, 5)) 64 | .weightx(1.0) 65 | .fill(GridBagConstraints.HORIZONTAL) 66 | ); 67 | JButton browseButton = new JButton("Browse..."); 68 | _settingsPanel.add(browseButton, new GridBagConstraintsBuilder().gridx(2)); 69 | _settingsPanel.add( 70 | new JLabel("Arguments to PCILeech:"), 71 | new GridBagConstraintsBuilder().gridx(0).anchor(GridBagConstraints.EAST) 72 | ); 73 | JTextField argsTextField = new JTextField(30); 74 | argsTextField.setText(settings.getPciLeechArguments()); 75 | _settingsPanel.add( 76 | argsTextField, 77 | new GridBagConstraintsBuilder() 78 | .gridx(1) 79 | .insets(new Insets(0, 5, 0, 5)) 80 | .weightx(1.0) 81 | .fill(GridBagConstraints.HORIZONTAL) 82 | ); 83 | _startStopButton = new JButton(); 84 | buttonPanel.add(_startStopButton); 85 | 86 | _outputArea = new JTextArea(10, 30); 87 | _outputArea.setEditable(false); 88 | _outputArea.setAutoscrolls(true); 89 | add(new JScrollPane(_outputArea), BorderLayout.CENTER); 90 | 91 | browseButton.addActionListener(e -> { 92 | File result = openFileDialog_MemProcFsExe(); 93 | if (result != null) { 94 | settings.setMemProcFsExePath(result.getAbsolutePath()); 95 | memprocFsPathTextField.setText(settings.getMemProcFsExePath()); 96 | settings.save(); 97 | } 98 | }); 99 | 100 | _startStopButton.addActionListener( 101 | e -> { 102 | RunningServer server = _server.get(); 103 | if (server == null) { 104 | _outputArea.setText(""); 105 | _startStopButton.setText("Stop Server"); 106 | ProcessBuilder pb = new ProcessBuilder( 107 | System.getProperty("java.home") + "\\bin\\java.exe", 108 | "-classpath", 109 | System.getProperty("java.class.path"), 110 | ServerMain.class.getName(), 111 | settings.getMemProcFsExePath(), 112 | settings.getPciLeechArguments().trim() 113 | ); 114 | pb.redirectInput(ProcessBuilder.Redirect.PIPE); 115 | pb.redirectOutput(ProcessBuilder.Redirect.PIPE); 116 | pb.redirectErrorStream(true); 117 | try { 118 | Process p = pb.start(); 119 | server = new RunningServer(p); 120 | _server.set(server); 121 | server.addListener(this); 122 | server.start(); 123 | updateServerState(); 124 | } catch (IOException ex) { 125 | ex.printStackTrace(); 126 | } 127 | } else { 128 | server.shutdownNow(); 129 | _startStopButton.setEnabled(false); 130 | } 131 | } 132 | ); 133 | 134 | argsTextField.getDocument().addDocumentListener(new DocumentChangeListener(() -> { 135 | settings.setPciLeechArguments(argsTextField.getText()); 136 | settings.save(); 137 | })); 138 | 139 | updateServerState(); 140 | pack(); 141 | setLocationRelativeTo(null); 142 | } 143 | 144 | private static void enableContainer(Container container, boolean enabled) { 145 | for (Component component : container.getComponents()) { 146 | if (component instanceof Container) { 147 | enableContainer((Container) component, enabled); 148 | } 149 | component.setEnabled(enabled); 150 | } 151 | } 152 | 153 | private void updateServerState() { 154 | if (_server.get() == null) { 155 | enableContainer(_settingsPanel, true); 156 | _startStopButton.setText("Start Server"); 157 | } else { 158 | enableContainer(_settingsPanel, false); 159 | _startStopButton.setText("Stop Server"); 160 | } 161 | } 162 | 163 | private File openFileDialog_MemProcFsExe() { 164 | JFileChooser fileChooser = new JFileChooser(); 165 | fileChooser.setFileFilter( 166 | new FileFilter() { 167 | @Override 168 | public boolean accept(File f) { 169 | return f.isDirectory() || f.getName().equalsIgnoreCase("MemProcFS.exe"); 170 | } 171 | 172 | @Override 173 | public String getDescription() { 174 | return "MemProcFS.exe"; 175 | } 176 | } 177 | ); 178 | int option = fileChooser.showOpenDialog(this); 179 | if (option == JFileChooser.APPROVE_OPTION) { 180 | return fileChooser.getSelectedFile(); 181 | } else { 182 | return null; 183 | } 184 | } 185 | 186 | @Override 187 | public void charsRead(String chars) { 188 | _outputArea.append(chars); 189 | } 190 | 191 | @Override 192 | public void closed(Integer exitCode) { 193 | _server.set(null); 194 | if (!_outputArea.getText().isEmpty() && !_outputArea.getText().endsWith("\n")) { 195 | _outputArea.append("\n"); 196 | } 197 | if (exitCode == null) { 198 | _outputArea.append("*** Server died unexpectedly\n"); 199 | } else if (exitCode == 0) { 200 | _outputArea.append("*** Server shut down normally\n"); 201 | } else { 202 | _outputArea.append("*** Server died with exit code " + exitCode + "\n"); 203 | } 204 | updateServerState(); 205 | _startStopButton.setEnabled(true); 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /src/main/java/iflores/ceserver/pcileech/ClientHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ceserver-pcileech by Isabella Flores 3 | * 4 | * Copyright © 2021 Isabella Flores 5 | * 6 | * It is licensed to you under the terms of the 7 | * GNU Affero General Public License, Version 3.0. 8 | * Please see the file LICENSE for more information. 9 | */ 10 | 11 | package iflores.ceserver.pcileech; 12 | 13 | import com.sun.jna.platform.win32.Kernel32; 14 | import com.sun.jna.platform.win32.WinBase; 15 | import org.jetbrains.annotations.NotNull; 16 | 17 | import java.io.EOFException; 18 | import java.io.IOException; 19 | import java.net.InetSocketAddress; 20 | import java.nio.ByteBuffer; 21 | import java.nio.ByteOrder; 22 | import java.nio.channels.SocketChannel; 23 | import java.nio.charset.StandardCharsets; 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | import java.util.concurrent.locks.ReentrantLock; 27 | 28 | import static iflores.ceserver.pcileech.CommandConstants.*; 29 | import static iflores.ceserver.pcileech.Win32Constants.TH32CS_SNAPMODULE; 30 | import static iflores.ceserver.pcileech.Win32Constants.TH32CS_SNAPPROCESS; 31 | 32 | public class ClientHandler extends Thread { 33 | 34 | private static final Map _openProcesses = new HashMap<>(); 35 | private static final Map _handlesById = new HashMap<>(); 36 | private static final ReentrantLock _handleLock = new ReentrantLock(); 37 | private static final Map _clients = new HashMap<>(); 38 | private static int _nextHandleId = 1; 39 | private static int _nextClientId = 1; 40 | private final SocketChannel _socketChannel; 41 | private final int _clientId; 42 | private final String _clientIdString; 43 | 44 | public ClientHandler(SocketChannel socketChannel) throws IOException { 45 | _clientId = generateClientId(); 46 | _clientIdString = "Client-" + String.format("%05d", _clientId); 47 | _socketChannel = socketChannel; 48 | String remoteAddress = ((InetSocketAddress) socketChannel.getRemoteAddress()).getAddress().getHostAddress(); 49 | setName(this + " [" + remoteAddress + "]"); 50 | log("Connection from " + remoteAddress); 51 | } 52 | 53 | private int generateClientId() { 54 | int clientId; 55 | while (true) { 56 | clientId = _nextClientId++; 57 | if (clientId > 99999) { 58 | clientId = 1; 59 | } 60 | synchronized (_clients) { 61 | if (_clients.putIfAbsent(clientId, this) == null) { 62 | return clientId; 63 | } 64 | } 65 | } 66 | } 67 | 68 | private void log(String message) { 69 | Main.log(this, message); 70 | } 71 | 72 | @Override 73 | @NotNull 74 | public String toString() { 75 | return _clientIdString; 76 | } 77 | 78 | @Override 79 | public void run() { 80 | try { 81 | //noinspection InfiniteLoopStatement 82 | while (true) { 83 | ByteBuffer commandbuf = ByteBuffer.allocate(1); 84 | readFully(commandbuf); 85 | byte command = commandbuf.get(0); 86 | handleCommand(command); 87 | } 88 | } catch (EOFException ex) { 89 | // closed connection 90 | } catch (IOException ex) { 91 | ex.printStackTrace(); 92 | } finally { 93 | synchronized (_clients) { 94 | _clients.remove(_clientId); 95 | } 96 | try { 97 | _socketChannel.close(); 98 | } catch (Throwable t) { 99 | t.printStackTrace(); 100 | } 101 | log("Connection closed."); 102 | } 103 | } 104 | 105 | private void handleCommand(byte command) throws IOException { 106 | switch (command) { 107 | case CMD_CREATETOOLHELP32SNAPSHOT -> { 108 | int dwFlags = readInt(); 109 | int th32ProcessID = readInt(); 110 | int handleId; 111 | if ((dwFlags & TH32CS_SNAPPROCESS) != 0) { 112 | ToolHelp32Snapshot_Processes snapshot = new ToolHelp32Snapshot_Processes(); 113 | handleId = generateHandleId(snapshot); 114 | } else if ((dwFlags & TH32CS_SNAPMODULE) != 0) { 115 | SelectedProcess selectedProcess = new SelectedProcess(th32ProcessID); 116 | ToolHelp32Snapshot_Modules snapshot = new ToolHelp32Snapshot_Modules(selectedProcess); 117 | handleId = generateHandleId(snapshot); 118 | } else { 119 | System.out.println("WARNING: Unhandled argument to CMD_CREATETOOLHELP32SNAPSHOT: " + dwFlags); 120 | handleId = 0; 121 | } 122 | ByteBuffer result = ByteBuffer.allocate(4); 123 | result.order(ByteOrder.LITTLE_ENDIAN); 124 | result.putInt(0, handleId); 125 | writeFully(result); 126 | } 127 | case CMD_PROCESS32FIRST, CMD_PROCESS32NEXT -> { 128 | int handleId = readInt(); 129 | ToolHelp32Snapshot_Processes snapshot = (ToolHelp32Snapshot_Processes) getHandle(handleId); 130 | if (snapshot != null) { 131 | if (command == CMD_PROCESS32FIRST) { 132 | snapshot.restartProcessInfo(); 133 | } 134 | if (snapshot.hasNextProcessInfo()) { 135 | ProcessInfo processInfo = snapshot.nextProcessInfo(); 136 | writeCeProcessEntry(true, processInfo.getPid(), processInfo.getName()); 137 | return; 138 | } 139 | } 140 | writeCeProcessEntry(false, 0, ""); 141 | } 142 | case CMD_CLOSEHANDLE -> { 143 | _handleLock.lock(); 144 | try { 145 | int handleId = readInt(); 146 | _handlesById.remove(handleId); 147 | _openProcesses.remove(handleId); 148 | } finally { 149 | _handleLock.unlock(); 150 | } 151 | ByteBuffer buf = ByteBuffer.allocate(4); 152 | buf.order(ByteOrder.LITTLE_ENDIAN); 153 | buf.putInt(0, 1); 154 | writeFully(buf); 155 | } 156 | case CMD_OPENPROCESS -> { 157 | int pid = readInt(); 158 | int handleId = 0; 159 | try { 160 | SelectedProcess selectedProcess = new SelectedProcess(pid); 161 | _handleLock.lock(); 162 | try { 163 | handleId = generateHandleId(selectedProcess); 164 | _openProcesses.put(handleId, selectedProcess); 165 | } finally { 166 | _handleLock.unlock(); 167 | } 168 | } catch (WinApiException ex) { 169 | ex.printStackTrace(); 170 | } 171 | ByteBuffer buf = ByteBuffer.allocate(4); 172 | buf.order(ByteOrder.LITTLE_ENDIAN); 173 | buf.putInt(0, handleId); 174 | writeFully(buf); 175 | } 176 | case CMD_READPROCESSMEMORY -> { 177 | ByteBuffer buf = ByteBuffer.allocate(17); 178 | buf.order(ByteOrder.LITTLE_ENDIAN); 179 | readFully(buf); 180 | final int handleId = buf.getInt(); 181 | final long address = buf.getLong(); 182 | final int size = buf.getInt(); 183 | final byte compress = buf.get(); 184 | SelectedProcess selectedProcess = getOpenProcess(handleId); 185 | if (compress != 0) { 186 | throw new IllegalArgumentException("Compression not yet supported"); 187 | } 188 | if (selectedProcess != null && address >= 0L) { 189 | byte[] bytes = selectedProcess.readMemory(address, size); 190 | ByteBuffer memoryBuf = ByteBuffer.allocate(bytes.length + 4); 191 | memoryBuf.order(ByteOrder.LITTLE_ENDIAN); 192 | memoryBuf.putInt(bytes.length); 193 | memoryBuf.put(bytes); 194 | memoryBuf.flip(); 195 | writeFully(memoryBuf); 196 | } else { 197 | ByteBuffer memoryBuf = ByteBuffer.allocate(4); 198 | memoryBuf.order(ByteOrder.LITTLE_ENDIAN); 199 | memoryBuf.putInt(0); 200 | memoryBuf.flip(); 201 | writeFully(memoryBuf); 202 | } 203 | } 204 | case CMD_WRITEPROCESSMEMORY -> { 205 | ByteBuffer buf = ByteBuffer.allocate(16); 206 | buf.order(ByteOrder.LITTLE_ENDIAN); 207 | readFully(buf); 208 | int handleId = buf.getInt(); 209 | long address = buf.getLong(); 210 | int size = buf.getInt(); 211 | ByteBuffer memoryBuf = ByteBuffer.allocate(size); 212 | memoryBuf.order(ByteOrder.LITTLE_ENDIAN); 213 | readFully(memoryBuf); 214 | SelectedProcess selectedProcess = getOpenProcess(handleId); 215 | if (selectedProcess != null) { 216 | selectedProcess.writeMemory(address, memoryBuf.array()); 217 | } 218 | ByteBuffer responseBuffer = ByteBuffer.allocate(4); 219 | responseBuffer.order(ByteOrder.LITTLE_ENDIAN); 220 | responseBuffer.putInt(0, 0); 221 | writeFully(responseBuffer); 222 | } 223 | case CMD_GETARCHITECTURE -> { 224 | WinBase.SYSTEM_INFO si = new WinBase.SYSTEM_INFO(); 225 | Kernel32.INSTANCE.GetSystemInfo(si); 226 | int architecture = si.processorArchitecture.pi.wProcessorArchitecture.intValue(); 227 | byte result = (byte) switch (architecture) { 228 | case 0 -> 0; // x86 229 | case 9 -> 1; // x64 (AMD or Intel) 230 | case 5 -> 2; // ARM 231 | case 12 -> 3; // ARM64 232 | default -> throw new RuntimeException("Unsupported architecture: #" + architecture); 233 | }; 234 | ByteBuffer buf = ByteBuffer.allocate(1); 235 | buf.order(ByteOrder.LITTLE_ENDIAN); 236 | buf.put(0, result); 237 | writeFully(buf); 238 | } 239 | case CMD_MODULE32FIRST, CMD_MODULE32NEXT -> { 240 | int handleId = readInt(); 241 | ToolHelp32Snapshot_Modules toolHelp32SnapshotModules = (ToolHelp32Snapshot_Modules) getHandle(handleId); 242 | if (toolHelp32SnapshotModules != null) { 243 | if (command == CMD_MODULE32FIRST) { 244 | toolHelp32SnapshotModules.restartModuleInfo(); 245 | } 246 | while (toolHelp32SnapshotModules.hasNextModuleInfo()) { 247 | MemoryRegion memoryRegion = toolHelp32SnapshotModules.nextModuleInfo(); 248 | if (memoryRegion.getUserObject().getfFile() == 0) { 249 | continue; 250 | } 251 | writeCeModuleEntry( 252 | true, 253 | memoryRegion.getRegionStart(), 254 | memoryRegion.getRegionSize(), 255 | memoryRegion.getUserObject().getName() 256 | ); 257 | return; 258 | } 259 | } 260 | System.out.println("End of modules"); 261 | writeCeModuleEntry(false, 0L, 0L, ""); 262 | } 263 | case CMD_GETSYMBOLLISTFROMFILE -> { 264 | int symbolPathSize = readInt(); 265 | ByteBuffer buf = ByteBuffer.allocate(symbolPathSize); 266 | readFully(buf); 267 | ByteBuffer response = ByteBuffer.allocate(4); 268 | response.order(ByteOrder.LITTLE_ENDIAN); 269 | writeFully(response); 270 | } 271 | case CMD_VIRTUALQUERYEX, CMD_GETREGIONINFO -> { 272 | int handleId = readInt(); 273 | long address = readLong(); 274 | SelectedProcess selectedProcess = (SelectedProcess) getHandle(handleId); 275 | String name = null; 276 | ByteBuffer response = ByteBuffer.allocate(25); 277 | response.order(ByteOrder.LITTLE_ENDIAN); 278 | if (selectedProcess == null) { 279 | System.out.println("WARNING: Handle not found: " + handleId); 280 | } else { 281 | MemoryRegion memoryRange = selectedProcess.getMemoryMap().getMemoryRegionContaining(address); 282 | if (memoryRange != null) { 283 | long rangeStart = memoryRange.getRegionStart(); 284 | long rangeEnd = memoryRange.getRegionEnd(); 285 | VadInfo vadInfo = memoryRange.getUserObject(); 286 | name = vadInfo == null ? "" : vadInfo.getName(); 287 | response.put((byte) 1); // result 288 | response.putInt(vadInfo == null ? 1 : vadInfo.getProtection()); // protection 289 | response.putInt(vadInfo == null ? 0 : vadInfo.getType()); // type 290 | response.putLong(rangeStart); // base address 291 | response.putLong(rangeEnd - rangeStart + 1); // size 292 | response.flip(); 293 | } 294 | } 295 | writeFully(response); 296 | if (command == CMD_GETREGIONINFO) { 297 | if (name == null) { 298 | name = ""; 299 | } 300 | byte[] nameBytes = name.getBytes(StandardCharsets.ISO_8859_1); 301 | int numBytes = Math.min(name.length(), 127); 302 | ByteBuffer buf = ByteBuffer.allocate(1 + numBytes); 303 | buf.order(ByteOrder.LITTLE_ENDIAN); 304 | buf.put((byte) numBytes); 305 | buf.put(nameBytes, 0, numBytes); 306 | buf.flip(); 307 | writeFully(buf); 308 | } 309 | } 310 | case CMD_VIRTUALQUERYEXFULL -> { 311 | int handleId = readInt(); 312 | byte flags = readByte(); 313 | SelectedProcess selectedProcess = (SelectedProcess) getHandle(handleId); 314 | MemoryMap memoryMap = selectedProcess.getMemoryMap(); 315 | ByteBuffer response = ByteBuffer.allocate(4 + (memoryMap.getRegionCount() * 24)); 316 | response.order(ByteOrder.LITTLE_ENDIAN); 317 | response.putInt(memoryMap.getRegionCount()); 318 | for (MemoryRegion memoryRegion : memoryMap) { 319 | response.putLong(memoryRegion.getRegionStart()); 320 | response.putLong(memoryRegion.getRegionSize()); 321 | response.putInt(memoryRegion.getUserObject().getProtection()); // protection 322 | response.putInt(memoryRegion.getUserObject().getType()); // type 323 | } 324 | if (response.hasRemaining()) { 325 | throw new IllegalStateException(); 326 | } 327 | response.flip(); 328 | writeFully(response); 329 | } 330 | default -> throw new RuntimeException("Got unknown command: " + command); 331 | } 332 | } 333 | 334 | private SelectedProcess getOpenProcess(int handleId) { 335 | SelectedProcess selectedProcess; 336 | _handleLock.lock(); 337 | try { 338 | selectedProcess = _openProcesses.get(handleId); 339 | } finally { 340 | _handleLock.unlock(); 341 | } 342 | return selectedProcess; 343 | } 344 | 345 | private Object getHandle(int handleId) { 346 | _handleLock.lock(); 347 | try { 348 | return _handlesById.get(handleId); 349 | } finally { 350 | _handleLock.unlock(); 351 | } 352 | } 353 | 354 | private int generateHandleId(Object handle) { 355 | _handleLock.lock(); 356 | try { 357 | int handleId; 358 | do { 359 | handleId = _nextHandleId++; 360 | } 361 | while (handleId == 0 || _handlesById.putIfAbsent(handleId, handle) != null); 362 | return handleId; 363 | } finally { 364 | _handleLock.unlock(); 365 | } 366 | } 367 | 368 | private byte readByte() throws IOException { 369 | ByteBuffer buf = ByteBuffer.allocate(1); 370 | buf.order(ByteOrder.LITTLE_ENDIAN); 371 | readFully(buf); 372 | return buf.get(0); 373 | } 374 | 375 | private int readInt() throws IOException { 376 | ByteBuffer buf = ByteBuffer.allocate(4); 377 | buf.order(ByteOrder.LITTLE_ENDIAN); 378 | readFully(buf); 379 | return buf.getInt(0); 380 | } 381 | 382 | private long readLong() throws IOException { 383 | ByteBuffer buf = ByteBuffer.allocate(8); 384 | buf.order(ByteOrder.LITTLE_ENDIAN); 385 | readFully(buf); 386 | return buf.getLong(0); 387 | } 388 | 389 | private void writeCeProcessEntry(boolean hasNext, int pid, String processName) throws IOException { 390 | if (processName == null) { 391 | processName = ""; 392 | } 393 | byte[] processNameBytes = processName.getBytes(StandardCharsets.UTF_8); 394 | ByteBuffer buf = ByteBuffer.allocate(12 + processNameBytes.length); 395 | buf.order(ByteOrder.LITTLE_ENDIAN); 396 | buf.putInt(hasNext ? 1 : 0); 397 | buf.putInt(pid); 398 | buf.putInt(processNameBytes.length); 399 | buf.put(processNameBytes); 400 | buf.flip(); 401 | writeFully(buf); 402 | } 403 | 404 | private void writeCeModuleEntry(boolean hasNext, long moduleBase, long moduleSize, String moduleName) throws IOException { 405 | if (moduleName == null) { 406 | moduleName = ""; 407 | } 408 | int idx = moduleName.lastIndexOf('\\'); 409 | if (idx >= 0) { 410 | moduleName = moduleName.substring(idx + 1); 411 | } 412 | if (moduleSize > 0xffffffffL) { 413 | throw new IllegalArgumentException(); 414 | } 415 | byte[] moduleNameBytes = moduleName.getBytes(StandardCharsets.UTF_8); 416 | ByteBuffer buf = ByteBuffer.allocate(20 + moduleNameBytes.length); 417 | buf.order(ByteOrder.LITTLE_ENDIAN); 418 | buf.putInt(hasNext ? 1 : 0); 419 | buf.putLong(moduleBase); 420 | buf.putInt((int) moduleSize); 421 | buf.putInt(moduleNameBytes.length); 422 | buf.put(moduleNameBytes); 423 | buf.flip(); 424 | writeFully(buf); 425 | } 426 | 427 | private void writeFully(ByteBuffer result) throws IOException { 428 | if (result.order() != ByteOrder.LITTLE_ENDIAN) { 429 | throw new IllegalStateException(); 430 | } 431 | while (result.hasRemaining()) { 432 | _socketChannel.write(result); 433 | } 434 | } 435 | 436 | private void readFully(ByteBuffer buf) throws IOException { 437 | while (buf.hasRemaining()) { 438 | int count = _socketChannel.read(buf); 439 | if (count < 0) { 440 | throw new EOFException(); 441 | } 442 | } 443 | buf.flip(); 444 | } 445 | 446 | } 447 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . --------------------------------------------------------------------------------