├── .gitattributes ├── .gitignore ├── CEServerPS4.sln ├── CEServerPS4 ├── App.config ├── CEServerPS4.csproj ├── CheatEngineConstants.cs ├── CheatEnginePackets │ ├── Architecture.cs │ ├── C2S │ │ ├── CheatEngineCommand.cs │ │ ├── CloseHandleCommand.cs │ │ ├── CommandEnum.cs │ │ ├── ContinueForDebugEventCommand.cs │ │ ├── CreateToolHelp32SnapshotCommand.cs │ │ ├── Exceptions │ │ │ └── CommandNotInitializedException.cs │ │ ├── GetABICommand.cs │ │ ├── GetArchitectureCommand.cs │ │ ├── GetSymbolsFromFileCommand.cs │ │ ├── GetThreadContextCommand.cs │ │ ├── GetVersionCommand.cs │ │ ├── ICheatEngineCommand.cs │ │ ├── Module32FirstCommand.cs │ │ ├── Module32NextCommand.cs │ │ ├── OpenProcessCommand.cs │ │ ├── Process32FirstCommand.cs │ │ ├── Process32NextCommand.cs │ │ ├── ReadProcessMemoryCommand.cs │ │ ├── RemoveBreakPointCommand.cs │ │ ├── ResumeThreadCommand.cs │ │ ├── SetBreakPointCommand.cs │ │ ├── StartDebugCommand.cs │ │ ├── StopDebugCommand.cs │ │ ├── SuspendThreadCommand.cs │ │ ├── VirtualQueryExCommand.cs │ │ ├── VirtualQueryExFullCommand.cs │ │ ├── WaitForDebugEventCommand.cs │ │ └── WriteProcessMemoryCommand.cs │ ├── MissingCommandHandlerException.cs │ ├── PacketManager.cs │ └── S2C │ │ ├── CloseHandleResponse.cs │ │ ├── ContinueForDebugEventResponse.cs │ │ ├── GetABIResponse.cs │ │ ├── GetArchitectureResponse.cs │ │ ├── GetSymbolsFromFileResponse.cs │ │ ├── GetVersionResponse.cs │ │ ├── HandleResponse.cs │ │ ├── ICheatEngineResponse.cs │ │ ├── Module32Response.cs │ │ ├── Process32Response.cs │ │ ├── ReadProcessMemoryResponse.cs │ │ ├── ThreadContextResponse.cs │ │ ├── VirtualQueryExFullResponse.cs │ │ ├── VirtualQueryExResponse.cs │ │ ├── WaitForDebugEventResponse.cs │ │ └── WriteProcessMemoryResponse.cs ├── CheatEngineServer.cs ├── EventHandler │ ├── DebugEventHandler.cs │ ├── Event │ │ ├── ContinueDebugEvent.cs │ │ ├── DebugThreadEvent.cs │ │ ├── ProcessReumeEvent.cs │ │ ├── RemoveBreakPointEvent.cs │ │ ├── RemoveWatchPointEvent.cs │ │ ├── ResumeThreadEvent.cs │ │ ├── SetBreakPointEvent.cs │ │ ├── SetWatchPointEvent.cs │ │ ├── SuspendThreadEvent.cs │ │ └── ThreadContextEvent.cs │ ├── Handler.cs │ └── Request │ │ ├── ContinueDebugEventRequest.cs │ │ ├── RemoveBreakPointRequest.cs │ │ ├── RemoveWatchPointRequest.cs │ │ ├── ResumeThreadRequest.cs │ │ ├── SetBreakPointRequest.cs │ │ ├── SetWatchPointRequest.cs │ │ ├── SuspendThreadRequest.cs │ │ └── ThreadContextRequest.cs ├── PS4API │ ├── DebugAPI.cs │ ├── MemoryAPI.cs │ ├── PS4APIWrapper.cs │ ├── PS4DedugAPIWrapper.cs │ ├── PS4Static.cs │ └── ToolHelp.cs ├── PS4CEServerWindows.Designer.cs ├── PS4CEServerWindows.cs ├── PS4CEServerWindows.resx ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── RJToggleButton.cs ├── lib │ └── libdebug.dll └── packages.config ├── LICENSE ├── README.md └── libdebug.dll /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | bld/ 24 | [Bb]in/ 25 | [Oo]bj/ 26 | [Ll]og/ 27 | 28 | # Visual Studio 2015/2017 cache/options directory 29 | .vs/ 30 | # Uncomment if you have tasks that create the project's static files in wwwroot 31 | #wwwroot/ 32 | 33 | # Visual Studio 2017 auto generated files 34 | Generated\ Files/ 35 | 36 | # MSTest test Results 37 | [Tt]est[Rr]esult*/ 38 | [Bb]uild[Ll]og.* 39 | 40 | # NUNIT 41 | *.VisualState.xml 42 | TestResult.xml 43 | 44 | # Build Results of an ATL Project 45 | [Dd]ebugPS/ 46 | [Rr]eleasePS/ 47 | dlldata.c 48 | 49 | # Benchmark Results 50 | BenchmarkDotNet.Artifacts/ 51 | 52 | # .NET Core 53 | project.lock.json 54 | project.fragment.lock.json 55 | artifacts/ 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_h.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *_wpftmp.csproj 81 | *.log 82 | *.vspscc 83 | *.vssscc 84 | .builds 85 | *.pidb 86 | *.svclog 87 | *.scc 88 | 89 | # Chutzpah Test files 90 | _Chutzpah* 91 | 92 | # Visual C++ cache files 93 | ipch/ 94 | *.aps 95 | *.ncb 96 | *.opendb 97 | *.opensdf 98 | *.sdf 99 | *.cachefile 100 | *.VC.db 101 | *.VC.VC.opendb 102 | 103 | # Visual Studio profiler 104 | *.psess 105 | *.vsp 106 | *.vspx 107 | *.sap 108 | 109 | # Visual Studio Trace Files 110 | *.e2e 111 | 112 | # TFS 2012 Local Workspace 113 | $tf/ 114 | 115 | # Guidance Automation Toolkit 116 | *.gpState 117 | 118 | # ReSharper is a .NET coding add-in 119 | _ReSharper*/ 120 | *.[Rr]e[Ss]harper 121 | *.DotSettings.user 122 | 123 | # JustCode is a .NET coding add-in 124 | .JustCode 125 | 126 | # TeamCity is a build add-in 127 | _TeamCity* 128 | 129 | # DotCover is a Code Coverage Tool 130 | *.dotCover 131 | 132 | # AxoCover is a Code Coverage Tool 133 | .axoCover/* 134 | !.axoCover/settings.json 135 | 136 | # Visual Studio code coverage results 137 | *.coverage 138 | *.coveragexml 139 | 140 | # NCrunch 141 | _NCrunch_* 142 | .*crunch*.local.xml 143 | nCrunchTemp_* 144 | 145 | # MightyMoose 146 | *.mm.* 147 | AutoTest.Net/ 148 | 149 | # Web workbench (sass) 150 | .sass-cache/ 151 | 152 | # Installshield output folder 153 | [Ee]xpress/ 154 | 155 | # DocProject is a documentation generator add-in 156 | DocProject/buildhelp/ 157 | DocProject/Help/*.HxT 158 | DocProject/Help/*.HxC 159 | DocProject/Help/*.hhc 160 | DocProject/Help/*.hhk 161 | DocProject/Help/*.hhp 162 | DocProject/Help/Html2 163 | DocProject/Help/html 164 | 165 | # Click-Once directory 166 | publish/ 167 | 168 | # Publish Web Output 169 | *.[Pp]ublish.xml 170 | *.azurePubxml 171 | # Note: Comment the next line if you want to checkin your web deploy settings, 172 | # but database connection strings (with potential passwords) will be unencrypted 173 | *.pubxml 174 | *.publishproj 175 | 176 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 177 | # checkin your Azure Web App publish settings, but sensitive information contained 178 | # in these scripts will be unencrypted 179 | PublishScripts/ 180 | 181 | # NuGet Packages 182 | *.nupkg 183 | # The packages folder can be ignored because of Package Restore 184 | **/[Pp]ackages/* 185 | # except build/, which is used as an MSBuild target. 186 | !**/[Pp]ackages/build/ 187 | # Uncomment if necessary however generally it will be regenerated when needed 188 | #!**/[Pp]ackages/repositories.config 189 | # NuGet v3's project.json files produces more ignorable files 190 | *.nuget.props 191 | *.nuget.targets 192 | 193 | # Microsoft Azure Build Output 194 | csx/ 195 | *.build.csdef 196 | 197 | # Microsoft Azure Emulator 198 | ecf/ 199 | rcf/ 200 | 201 | # Windows Store app package directories and files 202 | AppPackages/ 203 | BundleArtifacts/ 204 | Package.StoreAssociation.xml 205 | _pkginfo.txt 206 | *.appx 207 | 208 | # Visual Studio cache files 209 | # files ending in .cache can be ignored 210 | *.[Cc]ache 211 | # but keep track of directories ending in .cache 212 | !*.[Cc]ache/ 213 | 214 | # Others 215 | ClientBin/ 216 | ~$* 217 | *~ 218 | *.dbmdl 219 | *.dbproj.schemaview 220 | *.jfm 221 | *.pfx 222 | *.publishsettings 223 | orleans.codegen.cs 224 | 225 | # Including strong name files can present a security risk 226 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 227 | #*.snk 228 | 229 | # Since there are multiple workflows, uncomment next line to ignore bower_components 230 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 231 | #bower_components/ 232 | 233 | # RIA/Silverlight projects 234 | Generated_Code/ 235 | 236 | # Backup & report files from converting an old project file 237 | # to a newer Visual Studio version. Backup files are not needed, 238 | # because we have git ;-) 239 | _UpgradeReport_Files/ 240 | Backup*/ 241 | UpgradeLog*.XML 242 | UpgradeLog*.htm 243 | ServiceFabricBackup/ 244 | *.rptproj.bak 245 | 246 | # SQL Server files 247 | *.mdf 248 | *.ldf 249 | *.ndf 250 | 251 | # Business Intelligence projects 252 | *.rdl.data 253 | *.bim.layout 254 | *.bim_*.settings 255 | *.rptproj.rsuser 256 | 257 | # Microsoft Fakes 258 | FakesAssemblies/ 259 | 260 | # GhostDoc plugin setting file 261 | *.GhostDoc.xml 262 | 263 | # Node.js Tools for Visual Studio 264 | .ntvs_analysis.dat 265 | node_modules/ 266 | 267 | # Visual Studio 6 build log 268 | *.plg 269 | 270 | # Visual Studio 6 workspace options file 271 | *.opt 272 | 273 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 274 | *.vbw 275 | 276 | # Visual Studio LightSwitch build output 277 | **/*.HTMLClient/GeneratedArtifacts 278 | **/*.DesktopClient/GeneratedArtifacts 279 | **/*.DesktopClient/ModelManifest.xml 280 | **/*.Server/GeneratedArtifacts 281 | **/*.Server/ModelManifest.xml 282 | _Pvt_Extensions 283 | 284 | # Paket dependency manager 285 | .paket/paket.exe 286 | paket-files/ 287 | 288 | # FAKE - F# Make 289 | .fake/ 290 | 291 | # JetBrains Rider 292 | .idea/ 293 | *.sln.iml 294 | 295 | # CodeRush personal settings 296 | .cr/personal 297 | 298 | # Python Tools for Visual Studio (PTVS) 299 | __pycache__/ 300 | *.pyc 301 | 302 | # Cake - Uncomment if you are using it 303 | # tools/** 304 | # !tools/packages.config 305 | 306 | # Tabs Studio 307 | *.tss 308 | 309 | # Telerik's JustMock configuration file 310 | *.jmconfig 311 | 312 | # BizTalk build output 313 | *.btp.cs 314 | *.btm.cs 315 | *.odx.cs 316 | *.xsd.cs 317 | 318 | # OpenCover UI analysis results 319 | OpenCover/ 320 | 321 | # Azure Stream Analytics local run output 322 | ASALocalRun/ 323 | 324 | # MSBuild Binary and Structured Log 325 | *.binlog 326 | 327 | # NVidia Nsight GPU debugger configuration file 328 | *.nvuser 329 | 330 | # MFractors (Xamarin productivity tool) working folder 331 | .mfractor/ 332 | 333 | # Local History for Visual Studio 334 | .localhistory/ 335 | -------------------------------------------------------------------------------- /CEServerPS4.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30104.148 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CEServerPS4", "CEServerPS4\CEServerPS4.csproj", "{91218BB6-DF7E-406C-8CC2-EFD5FFF732EC}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {91218BB6-DF7E-406C-8CC2-EFD5FFF732EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {91218BB6-DF7E-406C-8CC2-EFD5FFF732EC}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {91218BB6-DF7E-406C-8CC2-EFD5FFF732EC}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {91218BB6-DF7E-406C-8CC2-EFD5FFF732EC}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {BBA8FFB4-D264-486E-BBC5-80AA6D6D7FB8} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /CEServerPS4/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 58 | -------------------------------------------------------------------------------- /CEServerPS4/CEServerPS4.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | {91218BB6-DF7E-406C-8CC2-EFD5FFF732EC} 9 | WinExe 10 | CEServerPS4 11 | CEServerPS4 12 | v4.7.2 13 | 512 14 | true 15 | true 16 | false 17 | publish\ 18 | true 19 | Disk 20 | false 21 | Foreground 22 | 7 23 | Days 24 | false 25 | false 26 | true 27 | 0 28 | 1.0.0.%2a 29 | false 30 | true 31 | 32 | 33 | 34 | 35 | AnyCPU 36 | true 37 | full 38 | false 39 | bin\Debug\ 40 | TRACE;DEBUG 41 | prompt 42 | 4 43 | 44 | 45 | AnyCPU 46 | pdbonly 47 | true 48 | bin\Release\ 49 | TRACE;DEBUG 50 | prompt 51 | 4 52 | true 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | lib\libdebug.dll 61 | 62 | 63 | 64 | ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll 65 | 66 | 67 | 68 | 69 | 70 | ..\packages\System.Threading.Tasks.Dataflow.6.0.2-mauipre.1.22102.15\lib\net461\System.Threading.Tasks.Dataflow.dll 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | Form 132 | 133 | 134 | PS4CEServerWindows.cs 135 | 136 | 137 | Component 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | False 174 | Microsoft .NET Framework 4.7.2 %28x86 and x64%29 175 | true 176 | 177 | 178 | False 179 | .NET Framework 3.5 SP1 180 | false 181 | 182 | 183 | 184 | 185 | PS4CEServerWindows.cs 186 | 187 | 188 | 189 | 190 | 191 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 192 | 193 | 194 | 195 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEngineConstants.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Net.Sockets; 7 | using System.Text; 8 | using CEServerPS4.CheatEnginePackets.C2S; 9 | using System.IO; 10 | using System.Threading.Tasks; 11 | using System.Threading; 12 | 13 | namespace CEServerPS4 14 | { 15 | public static class CheatEngineConstants 16 | { 17 | public static bool isCustomCheatEngine 18 | { 19 | get; set; 20 | } 21 | 22 | } 23 | 24 | public enum ConnectType 25 | { 26 | INIT, 27 | SUCCESS, 28 | FAILED 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/Architecture.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace CEServerPS4.CheatEnginePackets 7 | { 8 | //https://github.com/cheat-engine/cheat-engine/blob/master/Cheat%20Engine/ceserver/ceserver.c#L137-L153 9 | public enum Architecture 10 | { 11 | i386 = 0, 12 | x86_64 = 1, 13 | arm = 2, 14 | aarch = 3 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/CheatEngineCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using CEServerPS4.CheatEnginePackets.S2C; 6 | 7 | namespace CEServerPS4.CheatEnginePackets.C2S 8 | { 9 | public abstract class CheatEngineCommand : ICheatEngineCommand where T : ICheatEngineResponse 10 | { 11 | public bool initialized { get; internal set; } 12 | 13 | 14 | 15 | /** 16 | * Initializes a command from a binary reader 17 | */ 18 | public abstract void Initialize(System.IO.BinaryReader reader); 19 | public abstract CommandType CommandType { get; } 20 | 21 | 22 | public abstract T Process(); 23 | 24 | 25 | public byte[] ProcessAndGetBytes() 26 | { 27 | T output = this.Process(); 28 | return output.Serialize(); 29 | } 30 | 31 | public void Unintialize() 32 | { 33 | this.initialized = false; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/CloseHandleCommand.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets.S2C; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace CEServerPS4.CheatEnginePackets.C2S 9 | { 10 | public class CloseHandleCommand : CheatEngineCommand 11 | { 12 | public IntPtr Handle; 13 | public override CommandType CommandType => CommandType.CMD_CLOSEHANDLE; 14 | 15 | public CloseHandleCommand() 16 | { 17 | 18 | } 19 | public CloseHandleCommand(IntPtr handle) 20 | { 21 | this.Handle = handle; 22 | this.initialized = true; 23 | } 24 | 25 | public override void Initialize(BinaryReader reader) 26 | { 27 | this.Handle = (IntPtr)reader.ReadUInt32(); 28 | this.initialized = true; 29 | } 30 | 31 | public override CloseHandleResponse Process() 32 | { 33 | return new CloseHandleResponse(PS4API.ToolHelp.CloseHandle(this.Handle)); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/CommandEnum.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace CEServerPS4 8 | { 9 | public enum CommandType : byte 10 | { 11 | CMD_GETVERSION = 0, 12 | CMD_CLOSECONNECTION = 1, 13 | CMD_TERMINATESERVER = 2, 14 | CMD_OPENPROCESS = 3, 15 | CMD_CREATETOOLHELP32SNAPSHOT = 4, 16 | CMD_PROCESS32FIRST = 5, 17 | CMD_PROCESS32NEXT = 6, 18 | CMD_CLOSEHANDLE = 7, 19 | CMD_VIRTUALQUERYEX = 8, 20 | CMD_READPROCESSMEMORY = 9, 21 | CMD_WRITEPROCESSMEMORY = 10, 22 | CMD_STARTDEBUG = 11, 23 | CMD_STOPDEBUG = 12, 24 | CMD_WAITFORDEBUGEVENT = 13, 25 | CMD_CONTINUEFROMDEBUGEVENT = 14, 26 | CMD_SETBREAKPOINT = 15, 27 | CMD_REMOVEBREAKPOINT = 16, 28 | CMD_SUSPENDTHREAD = 17, 29 | CMD_RESUMETHREAD = 18, 30 | CMD_GETTHREADCONTEXT = 19, 31 | CMD_SETTHREADCONTEXT = 20, 32 | CMD_GETARCHITECTURE = 21, 33 | CMD_MODULE32FIRST = 22, 34 | CMD_MODULE32NEXT = 23, 35 | CMD_GETSYMBOLLISTFROMFILE = 24, 36 | CMD_LOADEXTENSION = 25, 37 | CMD_ALLOC = 26, 38 | CMD_FREE = 27, 39 | CMD_CREATETHREAD = 28, 40 | CMD_LOADMODULE = 29, 41 | CMD_SPEEDHACK_SETSPEED = 30, 42 | CMD_VIRTUALQUERYEXFULL = 31, 43 | CMD_GETREGIONINFO = 32, 44 | CMD_COMMANDLIST2 = 255, 45 | CMD_GETABI =33, 46 | CMD_SETWATCHPOINT = 115, 47 | CMD_REMOVEWATCHPOINT = 116 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/ContinueForDebugEventCommand.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets.S2C; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace CEServerPS4.CheatEnginePackets.C2S 9 | { 10 | public class ContinueForDebugEventCommand : CheatEngineCommand 11 | { 12 | public override CommandType CommandType => CommandType.CMD_CONTINUEFROMDEBUGEVENT;// throw new NotImplementedException(); 13 | public IntPtr handle; 14 | public uint tid; 15 | public uint ignore; 16 | public ContinueForDebugEventCommand() 17 | { 18 | 19 | } 20 | 21 | public ContinueForDebugEventCommand(IntPtr handle,uint tid,uint ignore) 22 | { 23 | this.handle = handle; 24 | this.tid = tid; 25 | this.ignore = ignore; 26 | this.initialized = true; 27 | } 28 | 29 | public override void Initialize(BinaryReader reader) 30 | { 31 | this.handle = (IntPtr)reader.ReadInt32(); 32 | this.tid = reader.ReadUInt32(); 33 | this.ignore = reader.ReadUInt32(); 34 | this.initialized = true; 35 | } 36 | 37 | public override ContinueForDebugEventResponse Process() 38 | { 39 | IntPtr hande = PS4API.DebugAPI.ContinueForDebugEvent(handle, tid, ignore); 40 | 41 | return new ContinueForDebugEventResponse(hande); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/CreateToolHelp32SnapshotCommand.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets.S2C; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using CEServerPS4.PS4API; 8 | 9 | namespace CEServerPS4.CheatEnginePackets.C2S 10 | { 11 | public class CreateToolHelp32SnapshotCommand : CheatEngineCommand 12 | { 13 | public PS4API.ToolHelp.SnapshotFlags SnapshotFlags; 14 | public uint ProcessID; 15 | 16 | public sealed override CommandType CommandType => CommandType.CMD_CREATETOOLHELP32SNAPSHOT;// throw new NotImplementedException(); 17 | 18 | public CreateToolHelp32SnapshotCommand() 19 | { 20 | 21 | } 22 | public CreateToolHelp32SnapshotCommand(PS4API.ToolHelp.SnapshotFlags snapshotFlags, uint pid) 23 | { 24 | this.SnapshotFlags = snapshotFlags; 25 | this.ProcessID = pid; 26 | this.initialized = true; 27 | } 28 | 29 | public override HandleResponse Process() 30 | { 31 | if (!this.initialized) 32 | { 33 | throw new Exceptions.CommandNotInitializedException(); 34 | } 35 | IntPtr handle = ToolHelp.CreateToolhelp32Snapshot(this.SnapshotFlags, this.ProcessID); 36 | 37 | return new HandleResponse(handle); 38 | } 39 | 40 | public override void Initialize(BinaryReader reader) 41 | { 42 | this.SnapshotFlags = (PS4API.ToolHelp.SnapshotFlags)reader.ReadUInt32(); 43 | this.ProcessID = reader.ReadUInt32(); 44 | this.initialized = true; 45 | 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/Exceptions/CommandNotInitializedException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace CEServerPS4.CheatEnginePackets.C2S.Exceptions 7 | { 8 | class CommandNotInitializedException : Exception 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/GetABICommand.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets.S2C; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace CEServerPS4.CheatEnginePackets.C2S 9 | { 10 | public class GetABICommand : CheatEngineCommand 11 | { 12 | public override CommandType CommandType => CommandType.CMD_GETABI; 13 | 14 | public GetABICommand() 15 | { 16 | this.initialized = true; 17 | } 18 | public override void Initialize(BinaryReader reader) 19 | { 20 | this.initialized = true; 21 | } 22 | 23 | public override GetABIResponse Process() 24 | { 25 | //https://github.com/cheat-engine/cheat-engine/blob/master/Cheat%20Engine/ceserver/ceserver.c#L137-L153 26 | return new GetABIResponse(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/GetArchitectureCommand.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets.S2C; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace CEServerPS4.CheatEnginePackets.C2S 9 | { 10 | public class GetArchitectureCommand : CheatEngineCommand 11 | { 12 | public override CommandType CommandType => CommandType.CMD_GETARCHITECTURE; 13 | 14 | public GetArchitectureCommand() 15 | { 16 | this.initialized = true; 17 | } 18 | public override void Initialize(BinaryReader reader) 19 | { 20 | this.initialized = true; 21 | } 22 | 23 | public override GetArchitectureResponse Process() 24 | { 25 | //https://github.com/cheat-engine/cheat-engine/blob/master/Cheat%20Engine/ceserver/ceserver.c#L137-L153 26 | return new GetArchitectureResponse(Architecture.x86_64); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/GetSymbolsFromFileCommand.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets.S2C; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace CEServerPS4.CheatEnginePackets.C2S 10 | { 11 | public class GetSymbolsFromFileCommand : CheatEngineCommand 12 | { 13 | 14 | public string SymbolsFile; 15 | public override CommandType CommandType => CommandType.CMD_GETSYMBOLLISTFROMFILE;// throw new NotImplementedException(); 16 | 17 | public GetSymbolsFromFileCommand() { } 18 | 19 | public GetSymbolsFromFileCommand(string path) 20 | { 21 | SymbolsFile = path; 22 | this.initialized = true; 23 | } 24 | 25 | public override void Initialize(BinaryReader reader) 26 | { 27 | int size = reader.ReadInt32(); 28 | this.SymbolsFile = Encoding.UTF8.GetString( reader.ReadBytes(size)); 29 | this.initialized = true; 30 | } 31 | 32 | public override GetSymbolsFromFileResponse Process() 33 | { 34 | return new GetSymbolsFromFileResponse(new byte[0]); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/GetThreadContextCommand.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets.S2C; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace CEServerPS4.CheatEnginePackets.C2S 9 | { 10 | public class GetThreadContextCommand : CheatEngineCommand 11 | { 12 | public IntPtr Handle; 13 | public uint tid; 14 | public int type; 15 | 16 | public override CommandType CommandType => CommandType.CMD_GETTHREADCONTEXT; 17 | 18 | public GetThreadContextCommand() { } 19 | 20 | public GetThreadContextCommand(IntPtr handle, uint tid, int type) 21 | { 22 | this.Handle = handle; 23 | this.tid = tid; 24 | this.type = type; 25 | this.initialized = true; 26 | } 27 | 28 | public override void Initialize(BinaryReader reader) 29 | { 30 | Handle = (IntPtr)reader.ReadInt32(); 31 | tid = reader.ReadUInt32(); 32 | type = reader.ReadInt32(); 33 | this.initialized = true; 34 | } 35 | 36 | public override ThreadContextResponse Process() 37 | { 38 | 39 | IntPtr ptr = PS4API.DebugAPI.GetThreadContext(Handle, tid, out PS4API.DebugAPI.CONTEXT Context, type); 40 | return new ThreadContextResponse(Context.regs, ptr); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/GetVersionCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using CEServerPS4.CheatEnginePackets.S2C; 7 | 8 | namespace CEServerPS4.CheatEnginePackets.C2S 9 | { 10 | public class GetVersionCommand : CheatEngineCommand 11 | { 12 | public sealed override CommandType CommandType => CommandType.CMD_GETVERSION; 13 | 14 | public GetVersionCommand() 15 | { 16 | this.initialized = true; 17 | } 18 | 19 | public sealed override void Initialize(BinaryReader reader) 20 | { 21 | this.initialized = true; 22 | } 23 | 24 | public override GetVersionResponse Process() 25 | { 26 | if(!this.initialized) 27 | { 28 | throw new Exceptions.CommandNotInitializedException(); 29 | } 30 | return new GetVersionResponse(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/ICheatEngineCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace CEServerPS4.CheatEnginePackets.C2S 7 | { 8 | public interface ICheatEngineCommand 9 | { 10 | bool initialized { get; } 11 | 12 | void Initialize(System.IO.BinaryReader reader); 13 | 14 | void Unintialize(); 15 | CommandType CommandType { get; } 16 | byte[] ProcessAndGetBytes(); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/Module32FirstCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | 8 | namespace CEServerPS4.CheatEnginePackets.C2S 9 | { 10 | public class Module32FirstCommand : CheatEngineCommand 11 | { 12 | public override CommandType CommandType => CommandType.CMD_MODULE32FIRST; 13 | 14 | public IntPtr Handle; 15 | public Module32FirstCommand() 16 | { 17 | } 18 | 19 | public Module32FirstCommand(IntPtr handle) 20 | { 21 | this.Handle = handle; 22 | this.initialized = true; 23 | } 24 | 25 | public sealed override void Initialize(BinaryReader reader) 26 | { 27 | this.Handle = (IntPtr)reader.ReadUInt32(); 28 | this.initialized = true; 29 | } 30 | 31 | public override S2C.Module32Response Process() 32 | { 33 | PS4API.ToolHelp.MODULEENTRY32 moduleEntry = new PS4API.ToolHelp.MODULEENTRY32(); 34 | moduleEntry.dwSize = (uint)Marshal.SizeOf(moduleEntry); 35 | 36 | var result = PS4API.ToolHelp.Module32First(this.Handle, ref moduleEntry); 37 | 38 | return new S2C.Module32Response(result, moduleEntry); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/Module32NextCommand.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets.S2C; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | 8 | namespace CEServerPS4.CheatEnginePackets.C2S 9 | { 10 | public class Module32NextCommand : Module32FirstCommand 11 | { 12 | public override CommandType CommandType => CommandType.CMD_MODULE32NEXT; 13 | 14 | public override Module32Response Process() 15 | { 16 | PS4API.ToolHelp.MODULEENTRY32 moduleEntry = new PS4API.ToolHelp.MODULEENTRY32(); 17 | moduleEntry.dwSize = (uint)Marshal.SizeOf(moduleEntry); 18 | 19 | var result = PS4API.ToolHelp.Module32Next(this.Handle, ref moduleEntry); 20 | 21 | return new Module32Response(result, moduleEntry); 22 | } 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/OpenProcessCommand.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets.S2C; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace CEServerPS4.CheatEnginePackets.C2S 9 | { 10 | public class OpenProcessCommand : CheatEngineCommand 11 | { 12 | public override CommandType CommandType => CommandType.CMD_OPENPROCESS;// throw new NotImplementedException(); 13 | public int ProcessID; 14 | public OpenProcessCommand() 15 | { 16 | 17 | } 18 | 19 | public OpenProcessCommand(int pid) 20 | { 21 | this.ProcessID = pid; 22 | this.initialized = true; 23 | } 24 | 25 | public override void Initialize(BinaryReader reader) 26 | { 27 | this.ProcessID = reader.ReadInt32(); 28 | this.initialized = true; 29 | } 30 | 31 | public override HandleResponse Process() 32 | { 33 | IntPtr handle = PS4API.ToolHelp.OpenProcess( 34 | PS4API.ToolHelp.ProcessAccessFlags.VirtualMemoryRead | 35 | PS4API.ToolHelp.ProcessAccessFlags.VirtualMemoryWrite | 36 | PS4API.ToolHelp.ProcessAccessFlags.QueryInformation, 37 | false, this.ProcessID); 38 | 39 | return new HandleResponse(handle); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/Process32FirstCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | using CEServerPS4.CheatEnginePackets.S2C; 8 | 9 | namespace CEServerPS4.CheatEnginePackets.C2S 10 | { 11 | public class Process32FirstCommand : CheatEngineCommand 12 | { 13 | public override CommandType CommandType => CommandType.CMD_PROCESS32FIRST; 14 | 15 | public IntPtr Handle; 16 | public Process32FirstCommand() 17 | { 18 | } 19 | 20 | public Process32FirstCommand(IntPtr handle) 21 | { 22 | this.Handle = handle; 23 | this.initialized = true; 24 | } 25 | 26 | public sealed override void Initialize(BinaryReader reader) 27 | { 28 | this.Handle = (IntPtr)reader.ReadUInt32(); 29 | this.initialized = true; 30 | } 31 | 32 | public override Process32Response Process() 33 | { 34 | PS4API.ToolHelp.PROCESSENTRY32 processEntry = new PS4API.ToolHelp.PROCESSENTRY32(); 35 | processEntry.dwSize = (uint)Marshal.SizeOf(processEntry); 36 | 37 | var result = PS4API.ToolHelp.Process32First(this.Handle, ref processEntry); 38 | 39 | return new Process32Response(result, processEntry); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/Process32NextCommand.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets.S2C; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | 8 | namespace CEServerPS4.CheatEnginePackets.C2S 9 | { 10 | public class Process32NextCommand : Process32FirstCommand 11 | { 12 | public override CommandType CommandType => CommandType.CMD_PROCESS32NEXT; 13 | 14 | public override Process32Response Process() 15 | { 16 | PS4API.ToolHelp.PROCESSENTRY32 processEntry = new PS4API.ToolHelp.PROCESSENTRY32(); 17 | processEntry.dwSize = (uint)Marshal.SizeOf(processEntry); 18 | 19 | var result = PS4API.ToolHelp.Process32Next(this.Handle, ref processEntry); 20 | 21 | return new Process32Response(result, processEntry); 22 | } 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/ReadProcessMemoryCommand.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets.S2C; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace CEServerPS4.CheatEnginePackets.C2S 9 | { 10 | public class ReadProcessMemoryCommand : CheatEngineCommand 11 | { 12 | public IntPtr Handle; 13 | public ulong Address; 14 | public int Size; 15 | public bool Compress; 16 | 17 | public override CommandType CommandType => CommandType.CMD_READPROCESSMEMORY; 18 | 19 | public ReadProcessMemoryCommand() { } 20 | 21 | public ReadProcessMemoryCommand(IntPtr handle, UInt64 address, int size, bool compress) 22 | { 23 | this.Handle = handle; 24 | this.Address = address; 25 | this.Size = size; 26 | this.Compress = compress; 27 | this.initialized = true; 28 | } 29 | 30 | public override void Initialize(BinaryReader reader) 31 | { 32 | Handle = (IntPtr)reader.ReadInt32(); 33 | Address = reader.ReadUInt64(); 34 | Size = reader.ReadInt32(); 35 | Compress = reader.ReadByte() == 0 ? false : true; 36 | this.initialized = true; 37 | } 38 | 39 | public override ReadProcessMemoryResponse Process() 40 | { 41 | var data = new byte[this.Size]; 42 | IntPtr dataRead; 43 | PS4API.MemoryAPI.ReadProcessMemory(this.Handle, this.Address, out data, this.Size, out dataRead); 44 | if((int)dataRead < this.Size) 45 | { 46 | var data2 = new byte[(int)dataRead]; 47 | Array.Copy(data, 0, data2, 0, data2.Length); 48 | data = data2; 49 | } 50 | 51 | return new ReadProcessMemoryResponse(data, this.Compress); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/RemoveBreakPointCommand.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets.S2C; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace CEServerPS4.CheatEnginePackets.C2S 9 | { 10 | public class RemoveBreakPointCommand : CheatEngineCommand 11 | { 12 | public IntPtr Handle; 13 | public int bid; 14 | public IntPtr debugregister; 15 | public ulong Address; 16 | public int wasbp; 17 | 18 | public override CommandType CommandType => CommandType.CMD_REMOVEBREAKPOINT; 19 | 20 | public RemoveBreakPointCommand() { } 21 | 22 | public RemoveBreakPointCommand(IntPtr handle, int bid, IntPtr debugregister, UInt64 address, int wasbp) 23 | { 24 | this.Handle = handle; 25 | this.bid = bid; 26 | this.debugregister = debugregister; 27 | this.Address = address; 28 | this.wasbp = wasbp; 29 | this.initialized = true; 30 | } 31 | 32 | public override void Initialize(BinaryReader reader) 33 | { 34 | Handle = (IntPtr)reader.ReadInt32(); 35 | bid = reader.ReadInt32(); 36 | debugregister = (IntPtr)reader.ReadInt32(); 37 | if (CheatEngineConstants.isCustomCheatEngine) 38 | { 39 | Address = reader.ReadUInt64(); 40 | } 41 | 42 | wasbp = reader.ReadInt32(); 43 | this.initialized = true; 44 | } 45 | 46 | public override HandleResponse Process() 47 | { 48 | 49 | IntPtr o = PS4API.DebugAPI.RemoveBreakpoint(this.Handle, this.bid, this.debugregister,this.Address, this.wasbp); 50 | 51 | 52 | return new HandleResponse(o); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/ResumeThreadCommand.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets.S2C; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace CEServerPS4.CheatEnginePackets.C2S 9 | { 10 | public class ResumeThreadCommand : CheatEngineCommand 11 | { 12 | public override CommandType CommandType => CommandType.CMD_RESUMETHREAD;// throw new NotImplementedException(); 13 | public IntPtr handle; 14 | public uint ThreadId; 15 | public ResumeThreadCommand() 16 | { 17 | 18 | } 19 | 20 | public ResumeThreadCommand(IntPtr handle,uint ThreadId) 21 | { 22 | this.handle = handle; 23 | this.ThreadId = ThreadId; 24 | this.initialized = true; 25 | } 26 | 27 | public override void Initialize(BinaryReader reader) 28 | { 29 | this.handle = (IntPtr)reader.ReadInt32(); 30 | this.ThreadId = reader.ReadUInt32(); 31 | this.initialized = true; 32 | } 33 | 34 | public override HandleResponse Process() 35 | { 36 | IntPtr hande = PS4API.DebugAPI.ResumeThread(handle, ThreadId); 37 | 38 | return new HandleResponse(hande); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/SetBreakPointCommand.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets.S2C; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace CEServerPS4.CheatEnginePackets.C2S 9 | { 10 | public class SetBreakPointCommand : CheatEngineCommand 11 | { 12 | public IntPtr Handle; 13 | public int bid; 14 | public IntPtr debugregister; 15 | public ulong Address; 16 | public int bptype; 17 | public int bpsize; 18 | 19 | public override CommandType CommandType => CommandType.CMD_SETBREAKPOINT; 20 | 21 | public SetBreakPointCommand() { } 22 | 23 | public SetBreakPointCommand(IntPtr handle, int bid, IntPtr debugregister, UInt64 address, int bptype, int bpsize) 24 | { 25 | this.Handle = handle; 26 | this.bid = bid; 27 | this.debugregister = debugregister; 28 | this.Address = address; 29 | this.bptype = bptype; 30 | this.bpsize = bpsize; 31 | this.initialized = true; 32 | } 33 | 34 | public override void Initialize(BinaryReader reader) 35 | { 36 | Handle = (IntPtr)reader.ReadInt32(); 37 | bid = reader.ReadInt32(); 38 | debugregister = (IntPtr)reader.ReadInt32(); 39 | Address = reader.ReadUInt64(); 40 | bptype = reader.ReadInt32(); 41 | bpsize = reader.ReadInt32(); 42 | this.initialized = true; 43 | } 44 | 45 | public override HandleResponse Process() 46 | { 47 | 48 | IntPtr o = PS4API.DebugAPI.SetBreakpoint(this.Handle, this.bid, this.debugregister, this.Address, this.bptype,this.bpsize); 49 | 50 | return new HandleResponse(o); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/StartDebugCommand.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets.S2C; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace CEServerPS4.CheatEnginePackets.C2S 9 | { 10 | public class StartDebugCommand : CheatEngineCommand 11 | { 12 | public override CommandType CommandType => CommandType.CMD_STARTDEBUG;// throw new NotImplementedException(); 13 | public IntPtr handle; 14 | public StartDebugCommand() 15 | { 16 | 17 | } 18 | 19 | public StartDebugCommand(IntPtr handle) 20 | { 21 | this.handle = handle; 22 | this.initialized = true; 23 | } 24 | 25 | public override void Initialize(BinaryReader reader) 26 | { 27 | this.handle = (IntPtr)reader.ReadInt32(); 28 | this.initialized = true; 29 | } 30 | 31 | public override HandleResponse Process() 32 | { 33 | IntPtr hande = PS4API.DebugAPI.StartDebug(handle); 34 | 35 | return new HandleResponse(hande); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/StopDebugCommand.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets.S2C; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace CEServerPS4.CheatEnginePackets.C2S 9 | { 10 | public class StopDebugCommand : CheatEngineCommand 11 | { 12 | public override CommandType CommandType => CommandType.CMD_STOPDEBUG;// throw new NotImplementedException(); 13 | public IntPtr handle; 14 | public StopDebugCommand() 15 | { 16 | 17 | } 18 | 19 | public StopDebugCommand(IntPtr handle) 20 | { 21 | this.handle = handle; 22 | this.initialized = true; 23 | } 24 | 25 | public override void Initialize(BinaryReader reader) 26 | { 27 | this.handle = (IntPtr)reader.ReadInt32(); 28 | this.initialized = true; 29 | } 30 | 31 | public override HandleResponse Process() 32 | { 33 | IntPtr hande = PS4API.DebugAPI.StopDebug(handle); 34 | 35 | return new HandleResponse(hande); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/SuspendThreadCommand.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets.S2C; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace CEServerPS4.CheatEnginePackets.C2S 9 | { 10 | public class SuspendThreadCommand : CheatEngineCommand 11 | { 12 | public override CommandType CommandType => CommandType.CMD_SUSPENDTHREAD;// throw new NotImplementedException(); 13 | public IntPtr handle; 14 | public uint ThreadId; 15 | public SuspendThreadCommand() 16 | { 17 | 18 | } 19 | 20 | public SuspendThreadCommand(IntPtr handle,uint ThreadId) 21 | { 22 | this.handle = handle; 23 | this.ThreadId = ThreadId; 24 | this.initialized = true; 25 | } 26 | 27 | public override void Initialize(BinaryReader reader) 28 | { 29 | this.handle = (IntPtr)reader.ReadInt32(); 30 | this.ThreadId = reader.ReadUInt32(); 31 | this.initialized = true; 32 | } 33 | 34 | public override HandleResponse Process() 35 | { 36 | IntPtr hande = PS4API.DebugAPI.SuspendThread(handle, ThreadId); 37 | 38 | return new HandleResponse(hande); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/VirtualQueryExCommand.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets.S2C; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Runtime.InteropServices; 7 | using System.Text; 8 | 9 | namespace CEServerPS4.CheatEnginePackets.C2S 10 | { 11 | public class VirtualQueryExCommand : CheatEngineCommand 12 | { 13 | 14 | public IntPtr Handle; 15 | public UInt64 Address; 16 | 17 | public override CommandType CommandType => CommandType.CMD_VIRTUALQUERYEX;// throw new NotImplementedException(); 18 | 19 | public VirtualQueryExCommand() { } 20 | 21 | public VirtualQueryExCommand(IntPtr handle, UInt64 address) 22 | { 23 | this.Handle = handle; 24 | this.Address = address; 25 | this.initialized = true; 26 | } 27 | 28 | public override void Initialize(BinaryReader reader) 29 | { 30 | this.Handle = (IntPtr)reader.ReadInt32(); 31 | this.Address = reader.ReadUInt64(); 32 | this.initialized = true; 33 | } 34 | 35 | public override VirtualQueryExResponse Process() 36 | { 37 | PS4API.MemoryAPI.MEMORY_BASIC_INFORMATION mbi = new PS4API.MemoryAPI.MEMORY_BASIC_INFORMATION(); 38 | int ret = PS4API.MemoryAPI.VirtualQueryEx(Handle, Address, out mbi, (uint)Marshal.SizeOf(mbi)); 39 | 40 | return new VirtualQueryExResponse(ret, mbi); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/VirtualQueryExFullCommand.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets.S2C; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Runtime.InteropServices; 7 | using System.Text; 8 | 9 | namespace CEServerPS4.CheatEnginePackets.C2S 10 | { 11 | public class VirtualQueryExFullCommand : CheatEngineCommand 12 | { 13 | 14 | public IntPtr Handle; 15 | 16 | public override CommandType CommandType => CommandType.CMD_VIRTUALQUERYEXFULL;// throw new NotImplementedException(); 17 | 18 | public VirtualQueryExFullCommand() { } 19 | 20 | public VirtualQueryExFullCommand(IntPtr handle) 21 | { 22 | this.Handle = handle; 23 | this.initialized = true; 24 | } 25 | 26 | public override void Initialize(BinaryReader reader) 27 | { 28 | this.Handle = (IntPtr)reader.ReadInt32(); 29 | reader.ReadByte();//Cheat engine/linux specific flags? 30 | this.initialized = true; 31 | } 32 | 33 | public override VirtualQueryExFullResponse Process() 34 | { 35 | var regions = new List(); 36 | ulong currentAddress = 0; 37 | int ret = 0; 38 | while(true) 39 | { 40 | PS4API.MemoryAPI.MEMORY_BASIC_INFORMATION mbi = new PS4API.MemoryAPI.MEMORY_BASIC_INFORMATION(); 41 | try 42 | { 43 | ret = PS4API.MemoryAPI.VirtualQueryEx(Handle, currentAddress, out mbi, (uint)Marshal.SizeOf(mbi)); 44 | if (ret == 0) 45 | break; 46 | }catch(Exception e) 47 | { 48 | Console.WriteLine(currentAddress); 49 | } 50 | 51 | currentAddress = (ulong)mbi.BaseAddress+(ulong)mbi.RegionSize; 52 | regions.Add(mbi); 53 | } 54 | 55 | return new VirtualQueryExFullResponse(regions); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/WaitForDebugEventCommand.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets.S2C; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace CEServerPS4.CheatEnginePackets.C2S 9 | { 10 | public class WaitForDebugEventCommand : CheatEngineCommand 11 | { 12 | public override CommandType CommandType => CommandType.CMD_WAITFORDEBUGEVENT;// throw new NotImplementedException(); 13 | public IntPtr handle; 14 | public int timeout; 15 | public WaitForDebugEventCommand() 16 | { 17 | 18 | } 19 | 20 | public WaitForDebugEventCommand(IntPtr handle,int timeout) 21 | { 22 | this.handle = handle; 23 | this.timeout = timeout; 24 | this.initialized = true; 25 | } 26 | 27 | public override void Initialize(BinaryReader reader) 28 | { 29 | this.handle = (IntPtr)reader.ReadInt32(); 30 | this.timeout = reader.ReadInt32(); 31 | this.initialized = true; 32 | } 33 | 34 | public override WaitForDebugEventResponse Process() 35 | { 36 | IntPtr hande = PS4API.DebugAPI.WaitForDebugEvent(handle, timeout,out object evt); 37 | return new WaitForDebugEventResponse(hande,evt); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/C2S/WriteProcessMemoryCommand.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets.S2C; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace CEServerPS4.CheatEnginePackets.C2S 9 | { 10 | public class WriteProcessMemoryCommand : CheatEngineCommand 11 | { 12 | public IntPtr Handle; 13 | public ulong Address; 14 | public int Size; 15 | public byte[] data; 16 | 17 | public override CommandType CommandType => CommandType.CMD_WRITEPROCESSMEMORY; 18 | 19 | public WriteProcessMemoryCommand() { } 20 | 21 | public WriteProcessMemoryCommand(IntPtr handle, UInt64 address, int size, byte[] data) 22 | { 23 | this.Handle = handle; 24 | this.Address = address; 25 | this.Size = size; 26 | this.data = data; 27 | this.initialized = true; 28 | } 29 | 30 | public override void Initialize(BinaryReader reader) 31 | { 32 | Handle = (IntPtr)reader.ReadInt32(); 33 | Address = reader.ReadUInt64(); 34 | Size = reader.ReadInt32(); 35 | data = reader.ReadBytes(Size); 36 | this.initialized = true; 37 | } 38 | 39 | public override WriteProcessMemoryResponse Process() 40 | { 41 | 42 | IntPtr dataWriten; 43 | PS4API.MemoryAPI.WriteMemory(this.Handle, this.Address, data, this.Size, out dataWriten); 44 | 45 | return new WriteProcessMemoryResponse(this.Size); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/MissingCommandHandlerException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace CEServerPS4.CheatEnginePackets 7 | { 8 | class MissingCommandHandlerException : Exception 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/PacketManager.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets.C2S; 2 | using CEServerPS4.CheatEnginePackets.S2C; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Diagnostics; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Text; 9 | 10 | namespace CEServerPS4.CheatEnginePackets 11 | { 12 | /** 13 | * This classes parses incoming commands 14 | * It's possible to register commands to parse with the RegisterCommand method 15 | * 16 | * The instance passed is utilized to write the data to, no copying is made! 17 | * This is because Cheat Engine always waits for a response to the requested command so parellism/async is handling is not necessary. 18 | * To solve this you could get the type of the passed command and instanciate a new one through reflection but some performance would be lost with this. 19 | * Because of this one server can only server one client at a time, maybe on a future release add this support? 20 | */ 21 | public class PacketManager 22 | { 23 | 24 | private Dictionary commandHandler = new Dictionary(); 25 | 26 | 27 | public void RegisterCommand(ICheatEngineCommand command) 28 | { 29 | if (commandHandler.ContainsKey(command.CommandType)) 30 | commandHandler.Remove(command.CommandType); 31 | commandHandler.Add(command.CommandType, command); 32 | } 33 | 34 | public ICheatEngineCommand ReadNextCommand(BinaryReader reader) 35 | { 36 | CommandType type = (CommandType)reader.ReadByte(); 37 | 38 | ICheatEngineCommand command; 39 | if(!commandHandler.TryGetValue(type, out command)) 40 | { 41 | //Unoptimal solution if multiple commands can be sent at once 42 | //But if that were the case knowledge of all commands would be necessary 43 | //As the protocol doesn't provide a way to know the 'size' of the incoming message 44 | //this.consumeAll(reader); 45 | Trace.WriteLine(type); 46 | throw new MissingCommandHandlerException(); 47 | } 48 | command = (ICheatEngineCommand)Activator.CreateInstance(command.GetType()); 49 | command.Initialize(reader); 50 | 51 | return command; 52 | 53 | } 54 | 55 | public byte[] ProcessAndGetBytes(ICheatEngineCommand command) 56 | { 57 | if(!command.initialized) 58 | { 59 | throw new C2S.Exceptions.CommandNotInitializedException(); 60 | } 61 | var ret = command.ProcessAndGetBytes(); 62 | command.Unintialize(); 63 | return ret; 64 | } 65 | 66 | private byte[] consumeAll(BinaryReader reader) 67 | { 68 | byte[] all; 69 | 70 | byte[] data = new byte[1024]; 71 | using (MemoryStream ms = new MemoryStream()) 72 | { 73 | 74 | int numBytesRead; 75 | while ((numBytesRead = reader.Read(data, 0, data.Length)) > 0) 76 | { 77 | ms.Write(data, 0, numBytesRead); 78 | if (numBytesRead < data.Length) 79 | break; 80 | 81 | } 82 | all = ms.ToArray(); 83 | } 84 | return all; 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/S2C/CloseHandleResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace CEServerPS4.CheatEnginePackets.S2C 8 | { 9 | public class CloseHandleResponse : ICheatEngineResponse 10 | { 11 | 12 | public bool Result; 13 | public CloseHandleResponse(bool result) 14 | { 15 | this.Result = result; 16 | } 17 | 18 | public byte[] Serialize() 19 | { 20 | MemoryStream ms = new MemoryStream(); 21 | BinaryWriter br = new BinaryWriter(ms); 22 | br.Write(Result ? 1 : 0); 23 | 24 | br.Close(); 25 | return ms.ToArray(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/S2C/ContinueForDebugEventResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Runtime.Serialization.Formatters.Binary; 7 | 8 | namespace CEServerPS4.CheatEnginePackets.S2C 9 | { 10 | public class ContinueForDebugEventResponse : ICheatEngineResponse 11 | { 12 | private IntPtr handle; 13 | 14 | 15 | public ContinueForDebugEventResponse(IntPtr handle) 16 | { 17 | this.handle = handle; 18 | } 19 | 20 | public byte[] Serialize() 21 | { 22 | MemoryStream ms = new MemoryStream(); 23 | BinaryWriter br = new BinaryWriter(ms); 24 | 25 | br.Write((int)handle); 26 | br.Close(); 27 | return ms.ToArray(); 28 | } 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/S2C/GetABIResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace CEServerPS4.CheatEnginePackets.S2C 7 | { 8 | public class GetABIResponse : ICheatEngineResponse 9 | { 10 | 11 | public GetABIResponse( ) 12 | { 13 | 14 | } 15 | 16 | public byte[] Serialize() 17 | { 18 | return new byte[] { (byte)1 }; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/S2C/GetArchitectureResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace CEServerPS4.CheatEnginePackets.S2C 7 | { 8 | public class GetArchitectureResponse : ICheatEngineResponse 9 | { 10 | public Architecture Architecture; 11 | 12 | public GetArchitectureResponse(Architecture arch) 13 | { 14 | this.Architecture = arch; 15 | } 16 | 17 | public byte[] Serialize() 18 | { 19 | return new byte[] { (byte)Architecture }; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/S2C/GetSymbolsFromFileResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace CEServerPS4.CheatEnginePackets.S2C 9 | { 10 | public class GetSymbolsFromFileResponse : ICheatEngineResponse 11 | { 12 | public byte[] Data; 13 | 14 | public GetSymbolsFromFileResponse(byte[] data) 15 | { 16 | this.Data = data; 17 | } 18 | public byte[] Serialize() 19 | { 20 | MemoryStream ms = new MemoryStream(); 21 | BinaryWriter br = new BinaryWriter(ms); 22 | br.Write(0L); 23 | 24 | br.Close(); 25 | return ms.ToArray(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/S2C/GetVersionResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace CEServerPS4.CheatEnginePackets.S2C 8 | { 9 | public class GetVersionResponse : ICheatEngineResponse 10 | { 11 | public const string VERSION = "CHEATENGINE Network 2.1"; 12 | public const string VER = "CH"; 13 | public string version; 14 | 15 | public GetVersionResponse() 16 | { 17 | this.version = VERSION; 18 | } 19 | 20 | public GetVersionResponse(string version) 21 | { 22 | this.version = version; 23 | } 24 | 25 | public byte[] Serialize() 26 | { 27 | MemoryStream ms = new MemoryStream(); 28 | BinaryWriter br = new BinaryWriter(ms); 29 | br.Write(version.Length); 30 | br.Write((byte)2); 31 | br.Write(Encoding.UTF8.GetBytes(VER)); 32 | br.Close(); 33 | return ms.ToArray(); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/S2C/HandleResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace CEServerPS4.CheatEnginePackets.S2C 8 | { 9 | public class HandleResponse : ICheatEngineResponse 10 | { 11 | public IntPtr Handle; 12 | 13 | public HandleResponse(IntPtr handle) 14 | { 15 | this.Handle = handle; 16 | } 17 | 18 | public byte[] Serialize() 19 | { 20 | MemoryStream ms = new MemoryStream(); 21 | BinaryWriter br = new BinaryWriter(ms); 22 | 23 | br.Write((int)this.Handle); 24 | br.Close(); 25 | return ms.ToArray(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/S2C/ICheatEngineResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace CEServerPS4.CheatEnginePackets.S2C 7 | { 8 | public interface ICheatEngineResponse 9 | { 10 | byte[] Serialize(); 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/S2C/Module32Response.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace CEServerPS4.CheatEnginePackets.S2C 8 | { 9 | public class Module32Response : ICheatEngineResponse 10 | { 11 | public bool Result; 12 | public PS4API.ToolHelp.MODULEENTRY32 ModuleEntry; 13 | 14 | public Module32Response(bool result, PS4API.ToolHelp.MODULEENTRY32 moduleEntry) 15 | { 16 | this.Result = result; 17 | this.ModuleEntry = moduleEntry; 18 | } 19 | 20 | public byte[] Serialize() 21 | { 22 | MemoryStream ms = new MemoryStream(); 23 | BinaryWriter br = new BinaryWriter(ms); 24 | 25 | br.Write((int)(this.Result ? 1 : 0)); 26 | if (this.Result) 27 | { 28 | br.Write((long)ModuleEntry.modBaseAddr); 29 | br.Write(ModuleEntry.GlblcntUsage); 30 | br.Write(ModuleEntry.modBaseSize); 31 | br.Write(ModuleEntry.szModule.Length); 32 | br.Write(Encoding.UTF8.GetBytes(ModuleEntry.szModule)); 33 | } 34 | else 35 | { 36 | br.Write(0L);//Base Address 37 | br.Write(0);//part 38 | br.Write(0);//Mod Size 39 | br.Write(0);//str Size 40 | } 41 | 42 | br.Close(); 43 | return ms.ToArray(); 44 | } 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/S2C/Process32Response.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace CEServerPS4.CheatEnginePackets.S2C 8 | { 9 | public class Process32Response : ICheatEngineResponse 10 | { 11 | public bool Result; 12 | public PS4API.ToolHelp.PROCESSENTRY32 ProcessEntry; 13 | 14 | public Process32Response(bool result, PS4API.ToolHelp.PROCESSENTRY32 processEntry) 15 | { 16 | this.Result = result; 17 | this.ProcessEntry = processEntry; 18 | } 19 | 20 | public byte[] Serialize() 21 | { 22 | MemoryStream ms = new MemoryStream(); 23 | BinaryWriter br = new BinaryWriter(ms); 24 | 25 | br.Write((int)(this.Result ? 1 : 0)); 26 | if (this.Result) 27 | { 28 | br.Write((int)ProcessEntry.th32ProcessID); 29 | br.Write((int)ProcessEntry.szExeFile.Length); 30 | br.Write(Encoding.UTF8.GetBytes(ProcessEntry.szExeFile)); 31 | } 32 | else 33 | { 34 | br.Write((int)0); 35 | br.Write((int)0); 36 | } 37 | 38 | br.Close(); 39 | return ms.ToArray(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/S2C/ReadProcessMemoryResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace CEServerPS4.CheatEnginePackets.S2C 8 | { 9 | public class ReadProcessMemoryResponse : ICheatEngineResponse 10 | { 11 | public byte[] Data; 12 | public bool Compression; 13 | public ReadProcessMemoryResponse(byte[] data, bool compression) 14 | { 15 | this.Data = data; 16 | this.Compression = compression; 17 | } 18 | 19 | public byte[] Serialize() 20 | { 21 | if(this.Compression) 22 | throw new NotImplementedException("Compression is not implemented"); 23 | 24 | MemoryStream ms = new MemoryStream(); 25 | BinaryWriter br = new BinaryWriter(ms); 26 | br.Write(Data.Length); 27 | br.Write(Data); 28 | br.Close(); 29 | return ms.ToArray(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/S2C/ThreadContextResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Runtime.Serialization.Formatters.Binary; 7 | using System.Runtime.InteropServices; 8 | using System.Diagnostics; 9 | 10 | namespace CEServerPS4.CheatEnginePackets.S2C 11 | { 12 | public class ThreadContextResponse : ICheatEngineResponse 13 | { 14 | public PS4API.DebugAPI.CONTEXT_REGS rgs; 15 | public IntPtr handle; 16 | 17 | public ThreadContextResponse(PS4API.DebugAPI.CONTEXT_REGS regs, IntPtr handle) 18 | { 19 | this.rgs = regs; 20 | this.handle = handle; 21 | } 22 | 23 | public byte[] Serialize() 24 | { 25 | MemoryStream ms = new MemoryStream(); 26 | BinaryWriter br = new BinaryWriter(ms); 27 | if ((int)handle == 0) 28 | { 29 | br.Write(0); 30 | br.Close(); 31 | return ms.ToArray(); 32 | } 33 | 34 | br.Write(1); 35 | br.Write(Marshal.SizeOf(typeof(PS4API.DebugAPI.CONTEXT_REGS))); 36 | writeregs(br); 37 | br.Close(); 38 | return ms.ToArray(); 39 | } 40 | 41 | public void writeregs(BinaryWriter br) 42 | { 43 | br.Write(rgs.r15); 44 | 45 | br.Write(rgs.r14); 46 | 47 | br.Write(rgs.r13); 48 | 49 | br.Write(rgs.r12); 50 | 51 | br.Write(rgs.rbp); 52 | 53 | br.Write(rgs.rbx); 54 | 55 | br.Write(rgs.r11); 56 | 57 | br.Write(rgs.r10); 58 | 59 | br.Write(rgs.r9); 60 | 61 | br.Write(rgs.r8); 62 | 63 | br.Write(rgs.rax); 64 | 65 | br.Write(rgs.rcx); 66 | 67 | br.Write(rgs.rdx); 68 | 69 | br.Write(rgs.rsi); 70 | 71 | br.Write(rgs.rdi); 72 | 73 | br.Write(rgs.orig_rax); 74 | 75 | br.Write(rgs.rip); 76 | 77 | Trace.WriteLine("adress:"+rgs.rip); 78 | 79 | br.Write(rgs.cs); 80 | 81 | br.Write(rgs.eflags); 82 | 83 | br.Write(rgs.rsp); 84 | 85 | br.Write(rgs.ss); 86 | 87 | br.Write(rgs.fs_base); 88 | 89 | br.Write(rgs.gs_base); 90 | 91 | br.Write(rgs.ds); 92 | 93 | br.Write(rgs.es); 94 | 95 | br.Write(rgs.fs); 96 | 97 | br.Write(rgs.gs); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/S2C/VirtualQueryExFullResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace CEServerPS4.CheatEnginePackets.S2C 8 | { 9 | public class VirtualQueryExFullResponse : ICheatEngineResponse 10 | { 11 | 12 | public IList Regions; 13 | public VirtualQueryExFullResponse(IList regions) 14 | { 15 | this.Regions = regions; 16 | } 17 | 18 | public byte[] Serialize() 19 | { 20 | 21 | MemoryStream ms = new MemoryStream(); 22 | BinaryWriter br = new BinaryWriter(ms); 23 | br.Write(Regions.Count); 24 | //The number of bytes return by VirtualQueryEx is the number of bytes written to mbi, if it's 0 it failed 25 | //But in Cheat engise server 1 is success and 0 is failed 26 | foreach (var region in Regions) 27 | {//Yes this is reversed from VirtualQueryEx.... 28 | br.Write(region.BaseAddress); 29 | br.Write(region.RegionSize); 30 | br.Write((int)region.AllocationProtect); // Or Protect 31 | br.Write((int)region.Type); 32 | } 33 | 34 | br.Close(); 35 | return ms.ToArray(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/S2C/VirtualQueryExResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace CEServerPS4.CheatEnginePackets.S2C 8 | { 9 | public class VirtualQueryExResponse : ICheatEngineResponse 10 | { 11 | public int Result; 12 | public PS4API.MemoryAPI.MEMORY_BASIC_INFORMATION MemoryBasicInformation; 13 | 14 | public VirtualQueryExResponse(int result, PS4API.MemoryAPI.MEMORY_BASIC_INFORMATION mbi) 15 | { 16 | this.Result = result; 17 | this.MemoryBasicInformation = mbi; 18 | } 19 | 20 | public byte[] Serialize() 21 | { 22 | 23 | MemoryStream ms = new MemoryStream(); 24 | BinaryWriter br = new BinaryWriter(ms); 25 | //The number of bytes return by VirtualQueryEx is the number of bytes written to mbi, if it's 0 it failed 26 | //But in Cheat engise server 1 is success and 0 is failed 27 | if (Result > 0) 28 | br.Write((byte)1); 29 | else 30 | br.Write((byte)0); 31 | //Yes this is reversed from VirtualQueryExFull.... 32 | br.Write((int)MemoryBasicInformation.AllocationProtect); 33 | br.Write((int)MemoryBasicInformation.Type); 34 | br.Write((Int64)MemoryBasicInformation.BaseAddress); 35 | br.Write((Int64)MemoryBasicInformation.RegionSize); 36 | 37 | br.Close(); 38 | return ms.ToArray(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/S2C/WaitForDebugEventResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Runtime.Serialization.Formatters.Binary; 7 | 8 | namespace CEServerPS4.CheatEnginePackets.S2C 9 | { 10 | public class WaitForDebugEventResponse : ICheatEngineResponse 11 | { 12 | private IntPtr handle; 13 | private object et; 14 | 15 | 16 | public WaitForDebugEventResponse(IntPtr handle,object et) 17 | { 18 | this.et = et; 19 | this.handle = handle; 20 | } 21 | 22 | public byte[] Serialize() 23 | { 24 | MemoryStream ms = new MemoryStream(); 25 | BinaryWriter br = new BinaryWriter(ms); 26 | br.Write((int)handle); 27 | if ((int)handle > 0) 28 | { 29 | set(ref br); 30 | } 31 | br.Close(); 32 | return ms.ToArray(); 33 | } 34 | 35 | private void set(ref BinaryWriter br) 36 | { 37 | 38 | if(et is PS4API.DebugAPI.CreateDebugEvent) 39 | { 40 | PS4API.DebugAPI.CreateDebugEvent bf = (PS4API.DebugAPI.CreateDebugEvent)et; 41 | br.Write(bf.debugevent); 42 | br.Write(bf.threadid); 43 | br.Write((ulong)0); 44 | } 45 | else if(et is PS4API.DebugAPI.ProcessEvent) 46 | { 47 | PS4API.DebugAPI.ProcessEvent pe = (PS4API.DebugAPI.ProcessEvent)et; 48 | br.Write(pe.debugevent); 49 | br.Write(pe.threadid); 50 | br.Write(pe.maxBreakpointCount); 51 | br.Write(pe.maxWatchpointCount); 52 | br.Write(pe.maxSharedBreakpoints); 53 | br.Write((int)0); 54 | br.Write((sbyte)0); 55 | } 56 | else 57 | { 58 | PS4API.DebugAPI.DebugEvent de = (PS4API.DebugAPI.DebugEvent)et; 59 | br.Write(de.debugevent); 60 | br.Write(de.threadid); 61 | br.Write(de.address); 62 | } 63 | 64 | 65 | } 66 | 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEnginePackets/S2C/WriteProcessMemoryResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace CEServerPS4.CheatEnginePackets.S2C 8 | { 9 | public class WriteProcessMemoryResponse : ICheatEngineResponse 10 | { 11 | public Int32 Data; 12 | public WriteProcessMemoryResponse(Int32 data) 13 | { 14 | this.Data = data; 15 | } 16 | 17 | public byte[] Serialize() 18 | { 19 | MemoryStream ms = new MemoryStream(); 20 | BinaryWriter br = new BinaryWriter(ms); 21 | br.Write(Data); 22 | br.Close(); 23 | return ms.ToArray(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /CEServerPS4/CheatEngineServer.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.CheatEnginePackets; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Net.Sockets; 7 | using System.Text; 8 | using CEServerPS4.CheatEnginePackets.C2S; 9 | using System.IO; 10 | using System.Threading.Tasks; 11 | using System.Threading; 12 | using System.Diagnostics; 13 | 14 | namespace CEServerPS4 15 | { 16 | public class CheatEngineServer : IDisposable 17 | { 18 | private TcpListener _tcpListener; 19 | private PacketManager packetManager; 20 | private CancellationTokenSource _tokenSource; 21 | 22 | private bool isDisposed 23 | { 24 | get;set; 25 | } 26 | public static bool islistening 27 | { 28 | get; set; 29 | } 30 | 31 | public static ConnectType isConnected 32 | { 33 | get; set; 34 | } 35 | private CancellationToken _token; 36 | 37 | 38 | public CheatEngineServer(string ip,ushort port = 52736) : this(port, new PacketManager()) 39 | { 40 | PS4API.PS4Static.IP = ip; 41 | PS4API.PS4APIWrapper.Connect(); 42 | this.RegisterDefaultHandlers(); 43 | isConnected = ConnectType.INIT; 44 | } 45 | 46 | public CheatEngineServer(PacketManager pm) : this(52736, pm) 47 | { 48 | 49 | } 50 | 51 | public CheatEngineServer(ushort port, PacketManager pm) 52 | { 53 | _tcpListener = new TcpListener(IPAddress.Any, port); 54 | this.packetManager = pm; 55 | } 56 | 57 | private void HandleReceivedClient(TcpClient client) 58 | { 59 | 60 | var clientStream = client.GetStream(); 61 | var reader = new BinaryReader(clientStream); 62 | var writer = new BinaryWriter(clientStream); 63 | while (true) 64 | { 65 | try 66 | { 67 | 68 | var command = this.packetManager.ReadNextCommand(reader); 69 | var output = this.packetManager.ProcessAndGetBytes(command); 70 | 71 | writer.Write(output); 72 | writer.Flush(); 73 | 74 | } 75 | catch(EndOfStreamException) 76 | { 77 | client.Close(); 78 | break; 79 | } 80 | catch (Exception e) 81 | { 82 | Trace.WriteLine(e + ": "+ e.Message); 83 | Trace.WriteLine(e.StackTrace); 84 | client.Close(); 85 | Dispose(); 86 | break; 87 | } 88 | 89 | } 90 | } 91 | 92 | public async Task StartAsync(CancellationToken? token = null) 93 | { 94 | _tokenSource = CancellationTokenSource.CreateLinkedTokenSource(token ?? new CancellationToken()); 95 | _token = _tokenSource.Token; 96 | try 97 | { 98 | _tcpListener.Start(); 99 | isConnected = ConnectType.SUCCESS; 100 | islistening = true; 101 | isDisposed = false; 102 | while (!_token.IsCancellationRequested) 103 | { 104 | if (islistening) 105 | { 106 | var tcpClientTask = _tcpListener.AcceptTcpClientAsync(); 107 | var result = await tcpClientTask; 108 | _ = Task.Run(() => 109 | { 110 | HandleReceivedClient(result); 111 | }, _token); 112 | } 113 | 114 | } 115 | } 116 | finally 117 | { 118 | if (islistening) 119 | { 120 | _tcpListener.Stop(); 121 | islistening = false; 122 | } 123 | if (!ConnectType.SUCCESS.Equals(isConnected)) 124 | { 125 | isConnected = ConnectType.FAILED; 126 | } 127 | Dispose(); 128 | } 129 | } 130 | 131 | public void Stop() 132 | { 133 | _tokenSource?.Cancel(); 134 | } 135 | 136 | public void Dispose() 137 | { 138 | if (!isDisposed) 139 | { 140 | isDisposed = true; 141 | Stop(); 142 | if (islistening) 143 | { 144 | _tcpListener.Stop(); 145 | islistening = false; 146 | } 147 | PS4API.PS4DedugAPIWrapper.dettachDebugger(); 148 | PS4API.PS4APIWrapper.Disconnect(); 149 | } 150 | 151 | } 152 | 153 | private void RegisterDefaultHandlers() 154 | { 155 | this.RegisterCommandHandler(new CreateToolHelp32SnapshotCommand()); 156 | this.RegisterCommandHandler(new GetVersionCommand()); 157 | this.RegisterCommandHandler(new Module32FirstCommand()); 158 | this.RegisterCommandHandler(new Module32NextCommand()); 159 | this.RegisterCommandHandler(new Process32FirstCommand()); 160 | this.RegisterCommandHandler(new Process32NextCommand()); 161 | this.RegisterCommandHandler(new CloseHandleCommand()); 162 | this.RegisterCommandHandler(new OpenProcessCommand()); 163 | this.RegisterCommandHandler(new GetArchitectureCommand()); 164 | this.RegisterCommandHandler(new VirtualQueryExCommand()); 165 | this.RegisterCommandHandler(new VirtualQueryExFullCommand()); 166 | this.RegisterCommandHandler(new ReadProcessMemoryCommand()); 167 | this.RegisterCommandHandler(new GetSymbolsFromFileCommand()); 168 | this.RegisterCommandHandler(new StartDebugCommand()); 169 | this.RegisterCommandHandler(new ResumeThreadCommand()); 170 | this.RegisterCommandHandler(new SuspendThreadCommand()); 171 | this.RegisterCommandHandler(new SetBreakPointCommand()); 172 | this.RegisterCommandHandler(new RemoveBreakPointCommand()); 173 | this.RegisterCommandHandler(new GetThreadContextCommand()); 174 | this.RegisterCommandHandler(new WaitForDebugEventCommand()); 175 | this.RegisterCommandHandler(new ContinueForDebugEventCommand()); 176 | this.RegisterCommandHandler(new WriteProcessMemoryCommand()); 177 | this.RegisterCommandHandler(new GetABICommand()); 178 | } 179 | 180 | public void RegisterCommandHandler(ICheatEngineCommand command) 181 | { 182 | this.packetManager.RegisterCommand(command); 183 | } 184 | 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /CEServerPS4/EventHandler/DebugEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.Concurrent; 4 | using System.Linq; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | using System.Threading; 8 | using libdebug; 9 | using System.Threading.Tasks.Dataflow; 10 | using System.Threading.Tasks; 11 | using CEServerPS4.EventHandler.Event; 12 | using CEServerPS4.CheatEnginePackets; 13 | using System.Diagnostics; 14 | 15 | namespace CEServerPS4.EventHandler 16 | { 17 | public static class DebugEventHandler 18 | { 19 | 20 | private static BlockingCollection debugEvents = new BlockingCollection(); 21 | private static Dictionary handlers = new Dictionary(); 22 | 23 | 24 | static DebugEventHandler() 25 | { 26 | new Thread(listen).Start(); 27 | RegisterHandlers(); 28 | } 29 | 30 | public static void Produce(Object block,Object data) 31 | { 32 | 33 | ITargetBlock target = (ITargetBlock)block; 34 | target.Post(data); 35 | 36 | target.Complete(); 37 | } 38 | 39 | public static async Task ConsumeAsync(object obj) 40 | { 41 | 42 | ISourceBlock source = (ISourceBlock)obj; 43 | 44 | while (await source.OutputAvailableAsync()) 45 | { 46 | return await source.ReceiveAsync(); 47 | 48 | } 49 | 50 | return null; 51 | } 52 | 53 | public static void AddEvent(Object debugThreadEvent) 54 | { 55 | debugEvents.Add(debugThreadEvent); 56 | } 57 | 58 | public static void listen() 59 | { 60 | while (true) 61 | { 62 | try 63 | { 64 | object obj = debugEvents.Take(); 65 | Handle(obj); 66 | } 67 | catch (Exception e) 68 | { 69 | Trace.WriteLine("Error Executing Event:" + e.Message); 70 | break; 71 | } 72 | } 73 | } 74 | 75 | public static void stoplistening() 76 | { 77 | try 78 | { 79 | debugEvents.CompleteAdding(); 80 | debugEvents.Dispose(); 81 | } 82 | catch (Exception e) 83 | { 84 | Trace.WriteLine(e); 85 | } 86 | 87 | } 88 | 89 | public static void Handle(object DebuggerEvent) 90 | { 91 | 92 | DebugThreadEvent debugThreadEvent = (DebugThreadEvent)DebuggerEvent; 93 | Object response = null; 94 | try 95 | { 96 | if (!handlers.TryGetValue(debugThreadEvent.CommandType, out IHandler handler)) 97 | { 98 | 99 | Trace.WriteLine("handler not found:" + debugThreadEvent.CommandType); 100 | throw new MissingCommandHandlerException(); 101 | } 102 | handler.handle(debugThreadEvent ,out response); 103 | } 104 | catch (Exception e) 105 | { 106 | Trace.WriteLine("Exception ocuccerd in " + debugThreadEvent.CommandType+ " :" + e.Message); 107 | } 108 | finally 109 | { 110 | DebugEventHandler.Produce(debugThreadEvent.BufferBlock, response); 111 | } 112 | 113 | 114 | } 115 | 116 | public static void RegisterHandler(IHandler handler) 117 | { 118 | if (handlers.ContainsKey(handler.CommandType)) 119 | handlers.Remove(handler.CommandType); 120 | handlers.Add(handler.CommandType, handler); 121 | } 122 | 123 | public static void RegisterHandlers() 124 | { 125 | RegisterHandler(new SetWatchPointHandler()); 126 | RegisterHandler(new ResumeThreadHandler()); 127 | RegisterHandler(new SuspendThreadHandler()); 128 | RegisterHandler(new RemoveWatchPointHandler()); 129 | RegisterHandler(new ThreadContextHandler()); 130 | RegisterHandler(new ContinueDebugEventHandler()); 131 | RegisterHandler(new SetBreakPointHandler()); 132 | RegisterHandler(new RemoveBreakPointHandler()); 133 | } 134 | 135 | } 136 | 137 | } -------------------------------------------------------------------------------- /CEServerPS4/EventHandler/Event/ContinueDebugEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Threading.Tasks.Dataflow; 7 | using CEServerPS4.EventHandler.Request; 8 | 9 | namespace CEServerPS4.EventHandler.Event 10 | { 11 | public class ContinueDebugEvent : DebugThreadEvent 12 | { 13 | public override CommandType CommandType => CommandType.CMD_CONTINUEFROMDEBUGEVENT; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /CEServerPS4/EventHandler/Event/DebugThreadEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Threading.Tasks.Dataflow; 7 | 8 | namespace CEServerPS4.EventHandler.Event 9 | { 10 | public abstract class DebugThreadEvent 11 | { 12 | public Object Data { get; set; } 13 | public abstract CommandType CommandType { get; } 14 | public BufferBlock BufferBlock { get; } = new BufferBlock(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /CEServerPS4/EventHandler/Event/ProcessReumeEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Threading.Tasks.Dataflow; 7 | using CEServerPS4.EventHandler.Request; 8 | 9 | namespace CEServerPS4.EventHandler.Event 10 | { 11 | public class ProcessReumeEvent : DebugThreadEvent 12 | { 13 | public override CommandType CommandType => CommandType.CMD_CONTINUEFROMDEBUGEVENT; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /CEServerPS4/EventHandler/Event/RemoveBreakPointEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Threading.Tasks.Dataflow; 7 | using CEServerPS4.EventHandler.Request; 8 | 9 | namespace CEServerPS4.EventHandler.Event 10 | { 11 | public class RemoveBreakPointEvent : DebugThreadEvent 12 | { 13 | public override CommandType CommandType => CommandType.CMD_REMOVEBREAKPOINT; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /CEServerPS4/EventHandler/Event/RemoveWatchPointEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Threading.Tasks.Dataflow; 7 | using CEServerPS4.EventHandler.Request; 8 | 9 | namespace CEServerPS4.EventHandler.Event 10 | { 11 | public class RemoveWatchPointEvent : DebugThreadEvent 12 | { 13 | public override CommandType CommandType => CommandType.CMD_REMOVEWATCHPOINT; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /CEServerPS4/EventHandler/Event/ResumeThreadEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Threading.Tasks.Dataflow; 7 | using CEServerPS4.EventHandler.Request; 8 | 9 | namespace CEServerPS4.EventHandler.Event 10 | { 11 | public class ResumeThreadEvent : DebugThreadEvent 12 | { 13 | public override CommandType CommandType => CommandType.CMD_RESUMETHREAD; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /CEServerPS4/EventHandler/Event/SetBreakPointEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Threading.Tasks.Dataflow; 7 | using CEServerPS4.EventHandler.Request; 8 | 9 | namespace CEServerPS4.EventHandler.Event 10 | { 11 | public class SetBreakPointEvent : DebugThreadEvent 12 | { 13 | public override CommandType CommandType => CommandType.CMD_SETBREAKPOINT; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /CEServerPS4/EventHandler/Event/SetWatchPointEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Threading.Tasks.Dataflow; 7 | using CEServerPS4.EventHandler.Request; 8 | 9 | namespace CEServerPS4.EventHandler.Event 10 | { 11 | public class SetWatchPointEvent : DebugThreadEvent 12 | { 13 | public override CommandType CommandType => CommandType.CMD_SETWATCHPOINT; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /CEServerPS4/EventHandler/Event/SuspendThreadEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Threading.Tasks.Dataflow; 7 | using CEServerPS4.EventHandler.Request; 8 | 9 | namespace CEServerPS4.EventHandler.Event 10 | { 11 | public class SuspendThreadEvent : DebugThreadEvent 12 | { 13 | public override CommandType CommandType => CommandType.CMD_SUSPENDTHREAD; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /CEServerPS4/EventHandler/Event/ThreadContextEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Threading.Tasks.Dataflow; 7 | using CEServerPS4.EventHandler.Request; 8 | using libdebug; 9 | 10 | namespace CEServerPS4.EventHandler.Event 11 | { 12 | public class ThreadContextEvent : DebugThreadEvent 13 | { 14 | public override CommandType CommandType => CommandType.CMD_GETTHREADCONTEXT; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /CEServerPS4/EventHandler/Handler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using CEServerPS4.EventHandler.Event; 7 | using CEServerPS4.EventHandler.Request; 8 | using CEServerPS4.PS4API; 9 | using libdebug; 10 | 11 | namespace CEServerPS4.EventHandler 12 | { 13 | public interface IHandler 14 | { 15 | CommandType CommandType { get; } 16 | void handle(Object obj,out Object response); 17 | } 18 | 19 | public class SetWatchPointHandler : IHandler 20 | { 21 | public CommandType CommandType => CommandType.CMD_SETWATCHPOINT; 22 | 23 | public void handle(Object obj, out Object response) 24 | { 25 | response = 0; 26 | SetWatchPointEvent watchPointEvent = (SetWatchPointEvent)obj; 27 | SetWatchPointRequest r = (SetWatchPointRequest)watchPointEvent.Data; 28 | PS4DedugAPIWrapper.SetWatchpoint(r.Tid, r.Address, r.Bpsize, r.Bptype); 29 | response = 1; 30 | } 31 | } 32 | 33 | 34 | public class RemoveWatchPointHandler : IHandler 35 | { 36 | public CommandType CommandType => CommandType.CMD_REMOVEWATCHPOINT; 37 | 38 | public void handle(Object obj, out Object response) 39 | { 40 | RemoveWatchPointEvent watchPointEvent = (RemoveWatchPointEvent)obj; 41 | RemoveWatchPointRequest r = (RemoveWatchPointRequest)watchPointEvent.Data; 42 | response = 0; 43 | 44 | if (r.Tid == -1) 45 | { 46 | PS4DedugAPIWrapper.ClearWatchPoints(); 47 | response = 1; 48 | } 49 | else 50 | { 51 | PS4DedugAPIWrapper.ClearWatchpoint(r.Tid); 52 | response = 1; 53 | } 54 | } 55 | } 56 | 57 | public class SetBreakPointHandler : IHandler 58 | { 59 | public CommandType CommandType => CommandType.CMD_SETBREAKPOINT; 60 | 61 | public void handle(Object obj, out Object response) 62 | { 63 | response = 0; 64 | SetBreakPointEvent breakPointEvent = (SetBreakPointEvent)obj; 65 | SetBreakPointRequest r = (SetBreakPointRequest)breakPointEvent.Data; 66 | PS4DedugAPIWrapper.SetBreakpoint(r.Tid, r.Address); 67 | response = 1; 68 | } 69 | } 70 | 71 | 72 | public class RemoveBreakPointHandler : IHandler 73 | { 74 | public CommandType CommandType => CommandType.CMD_REMOVEBREAKPOINT; 75 | 76 | public void handle(Object obj, out Object response) 77 | { 78 | RemoveBreakPointEvent breakPointEvent = (RemoveBreakPointEvent)obj; 79 | RemoveBreakPointRequest r = (RemoveBreakPointRequest)breakPointEvent.Data; 80 | response = 0; 81 | 82 | if (r.Tid == -1) 83 | { 84 | PS4DedugAPIWrapper.ClearBreakpoints(); 85 | response = 1; 86 | } 87 | else 88 | { 89 | PS4DedugAPIWrapper.ClearBreakpoint(r.Tid); 90 | response = 1; 91 | } 92 | 93 | 94 | } 95 | } 96 | 97 | public class SuspendThreadHandler : IHandler 98 | { 99 | public CommandType CommandType => CommandType.CMD_SUSPENDTHREAD; 100 | 101 | public void handle(Object obj, out Object response) 102 | { 103 | SuspendThreadEvent watchPointEvent = (SuspendThreadEvent)obj; 104 | SuspendThreadRequest r = (SuspendThreadRequest)watchPointEvent.Data; 105 | response = 0; 106 | 107 | PS4DedugAPIWrapper.StopDebuggerThread(r.Tid); 108 | response=1; 109 | 110 | } 111 | } 112 | 113 | 114 | public class ResumeThreadHandler : IHandler 115 | { 116 | public CommandType CommandType => CommandType.CMD_RESUMETHREAD; 117 | 118 | public void handle(Object obj, out Object response) 119 | { 120 | ResumeThreadEvent watchPointEvent = (ResumeThreadEvent)obj; 121 | ResumeThreadRequest r = (ResumeThreadRequest)watchPointEvent.Data; 122 | response = 0; 123 | 124 | PS4DedugAPIWrapper.resumeDebuggerThread(r.Tid); 125 | response = 1; 126 | 127 | } 128 | } 129 | 130 | public class ThreadContextHandler : IHandler 131 | { 132 | public CommandType CommandType => CommandType.CMD_GETTHREADCONTEXT; 133 | 134 | public void handle(Object obj, out Object response) 135 | { 136 | ThreadContextEvent watchPointEvent = (ThreadContextEvent)obj; 137 | ThreadContextRequest r = (ThreadContextRequest)watchPointEvent.Data; 138 | response = new regs(); 139 | response = PS4DedugAPIWrapper.getRegisters(r.Tid); 140 | 141 | } 142 | } 143 | 144 | 145 | public class ContinueDebugEventHandler : IHandler 146 | { 147 | public CommandType CommandType => CommandType.CMD_CONTINUEFROMDEBUGEVENT; 148 | 149 | public void handle(Object obj, out Object response) 150 | { 151 | ContinueDebugEvent Cevent = (ContinueDebugEvent)obj; 152 | ContinueDebugEventRequest rq = (ContinueDebugEventRequest)Cevent.Data; 153 | response = 0; 154 | PS4DedugAPIWrapper.ContinueBreakpointThread(rq.Tid, rq.singleStep); 155 | response = 1; 156 | 157 | } 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /CEServerPS4/EventHandler/Request/ContinueDebugEventRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace CEServerPS4.EventHandler.Request 8 | { 9 | public class ContinueDebugEventRequest 10 | { 11 | public uint Tid { get; set; } 12 | public bool singleStep { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /CEServerPS4/EventHandler/Request/RemoveBreakPointRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace CEServerPS4.EventHandler.Request 8 | { 9 | public class RemoveBreakPointRequest 10 | { 11 | public int Tid { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /CEServerPS4/EventHandler/Request/RemoveWatchPointRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace CEServerPS4.EventHandler.Request 8 | { 9 | public class RemoveWatchPointRequest 10 | { 11 | public int Tid { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /CEServerPS4/EventHandler/Request/ResumeThreadRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace CEServerPS4.EventHandler.Request 8 | { 9 | public class ResumeThreadRequest 10 | { 11 | public uint Tid { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /CEServerPS4/EventHandler/Request/SetBreakPointRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace CEServerPS4.EventHandler.Request 8 | { 9 | public class SetBreakPointRequest 10 | { 11 | public int Tid { get; set; } 12 | public IntPtr Debugreg { get; set; } 13 | public ulong Address { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /CEServerPS4/EventHandler/Request/SetWatchPointRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace CEServerPS4.EventHandler.Request 8 | { 9 | public class SetWatchPointRequest 10 | { 11 | public int Tid { get; set; } 12 | public IntPtr Debugreg { get; set; } 13 | public ulong Address { get; set; } 14 | public int Bptype { get; set; } 15 | public int Bpsize { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /CEServerPS4/EventHandler/Request/SuspendThreadRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace CEServerPS4.EventHandler.Request 8 | { 9 | public class SuspendThreadRequest 10 | { 11 | public uint Tid { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /CEServerPS4/EventHandler/Request/ThreadContextRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace CEServerPS4.EventHandler.Request 8 | { 9 | public class ThreadContextRequest 10 | { 11 | public uint Tid { get; set; } 12 | 13 | public int Type { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /CEServerPS4/PS4API/DebugAPI.cs: -------------------------------------------------------------------------------- 1 | using CEServerPS4.EventHandler; 2 | using CEServerPS4.EventHandler.Event; 3 | using CEServerPS4.EventHandler.Request; 4 | using libdebug; 5 | using System; 6 | using System.Collections.Concurrent; 7 | using System.Collections.Generic; 8 | using System.Diagnostics; 9 | using System.Runtime.InteropServices; 10 | using System.Threading; 11 | 12 | 13 | namespace CEServerPS4.PS4API 14 | { 15 | public static class DebugAPI 16 | { 17 | 18 | private static uint[] threadIds; 19 | 20 | private static Object currentDebugEvent; 21 | 22 | private static BlockingCollection debugEvents = new BlockingCollection(); 23 | 24 | private static uint debugThread; 25 | 26 | public static uint getThd() 27 | { 28 | return debugThread; 29 | } 30 | 31 | private static HashSet threads = new HashSet(); 32 | 33 | private static HashSet adrresses = new HashSet(); 34 | private static Dictionary breakpointsAddress = new Dictionary(); 35 | 36 | private static Dictionary watchpointAddress = new Dictionary(); 37 | 38 | private static Dictionary watchThreaads = new Dictionary(); 39 | private static Dictionary watchAddress = new Dictionary(); 40 | 41 | private static Dictionary breakThreaads = new Dictionary(); 42 | private static Dictionary breakAddress = new Dictionary(); 43 | 44 | private static Stack watchpoints = new Stack(); 45 | private static Stack breakpoints = new Stack(); 46 | 47 | [StructLayout(LayoutKind.Sequential)] 48 | [Serializable] 49 | public struct CONTEXT_REGS 50 | { 51 | public ulong r15; 52 | public ulong r14; 53 | public ulong r13; 54 | public ulong r12; 55 | public ulong rbp; 56 | public ulong rbx; 57 | public ulong r11; 58 | public ulong r10; 59 | public ulong r9; 60 | public ulong r8; 61 | public ulong rax; 62 | public ulong rcx; 63 | public ulong rdx; 64 | public ulong rsi; 65 | public ulong rdi; 66 | public ulong orig_rax; 67 | public ulong rip; 68 | public ulong cs; 69 | public ulong eflags; 70 | public ulong rsp; 71 | public ulong ss; 72 | public ulong fs_base; 73 | public ulong gs_base; 74 | public ulong ds; 75 | public ulong es; 76 | public ulong fs; 77 | public ulong gs; 78 | }; 79 | 80 | 81 | [StructLayout(LayoutKind.Sequential)] 82 | [Serializable] 83 | public struct CONTEXT 84 | { 85 | public CONTEXT_REGS regs; 86 | } 87 | 88 | [StructLayout(LayoutKind.Sequential)] 89 | [Serializable] 90 | public struct CreateDebugEvent 91 | { 92 | 93 | public int debugevent; 94 | 95 | public ulong threadid; 96 | 97 | } 98 | 99 | [StructLayout(LayoutKind.Sequential)] 100 | [Serializable] 101 | public struct DebugEvent 102 | { 103 | 104 | public int debugevent; 105 | 106 | public ulong threadid; 107 | 108 | public ulong address; 109 | 110 | } 111 | 112 | [StructLayout(LayoutKind.Sequential)] 113 | [Serializable] 114 | public struct ProcessEvent 115 | { 116 | 117 | public int debugevent; 118 | 119 | public ulong threadid; 120 | 121 | public sbyte maxBreakpointCount; 122 | 123 | public sbyte maxWatchpointCount; 124 | 125 | public sbyte maxSharedBreakpoints; 126 | } 127 | 128 | 129 | public static void DebuggerInterruptCallback( 130 | uint lwpid, 131 | uint status, 132 | string tdname, 133 | regs regs, 134 | fpregs fpregs, 135 | dbregs dbregs) 136 | { 137 | 138 | //debugThreadId = lwpid; 139 | Trace.WriteLine("status=:" + status); 140 | DebugEvent evet = new DebugEvent(); 141 | evet.debugevent = 5; 142 | evet.threadid = lwpid; 143 | 144 | debugThread = lwpid; 145 | ulong daddress; 146 | bool isBp; 147 | if((dbregs.dr6 & 1) == 1) 148 | { 149 | daddress = dbregs.dr0; 150 | isBp = false; 151 | if (regs.r_rip == dbregs.dr0 && dbregs.dr7 == 0) 152 | { 153 | isBp = true; 154 | } 155 | }else if(((dbregs.dr6 >>1)& 1) == 1) 156 | { 157 | daddress = dbregs.dr1; 158 | isBp = false; 159 | } 160 | else if (((dbregs.dr6 >> 2) & 1) == 1) 161 | { 162 | daddress = dbregs.dr2; 163 | isBp = false; 164 | } 165 | else if (((dbregs.dr6 >> 3) & 1) == 1) 166 | { 167 | daddress = dbregs.dr3; 168 | isBp = false; 169 | } 170 | else 171 | { 172 | if(!breakThreaads.TryGetValue(lwpid,out daddress)){ 173 | daddress = regs.r_rip; 174 | } 175 | isBp = true; 176 | } 177 | 178 | if (isBp) 179 | { 180 | breakThreaads[lwpid] = daddress; 181 | breakAddress[daddress] = lwpid; 182 | } 183 | else 184 | { 185 | watchThreaads[lwpid] = daddress; 186 | watchAddress[daddress] = lwpid; 187 | } 188 | // dbregs.dr6 = 0; 189 | // PS4DedugAPIWrapper.getps4().SetDebugRegisters(lwpid, dbregs); 190 | evet.address = daddress; 191 | 192 | Thread nThread = new Thread(addDebugEvent) { IsBackground = true }; 193 | nThread.Start(evet); 194 | Trace.WriteLine("address=:" + regs.r_rip); 195 | Trace.WriteLine("thread=:" + lwpid); 196 | Trace.WriteLine("breakaddress=:" + daddress); 197 | } 198 | 199 | private static void addDebugEvent(Object evet) 200 | { 201 | debugEvents.Add(evet); 202 | } 203 | 204 | private static void assignThreadRegisters(regs r, out CONTEXT_REGS regs) 205 | { 206 | regs = new CONTEXT_REGS(); 207 | regs.r15 = r.r_r15; 208 | regs.r14 = r.r_r14; 209 | regs.r13 = r.r_r13; 210 | regs.r12 = r.r_r12; 211 | regs.r11 = r.r_r11; 212 | regs.r10 = r.r_r10; 213 | regs.r9 = r.r_r9; 214 | regs.r8 = r.r_r8; 215 | regs.rax = r.r_rax; 216 | regs.rbx = r.r_rbx; 217 | regs.rcx = r.r_rcx; 218 | regs.rbp = r.r_rbp; 219 | regs.rdi = r.r_rdi; 220 | regs.rdx = r.r_rdx; 221 | regs.rip = r.r_rip; 222 | regs.rsi = r.r_rsi; 223 | regs.rsp = r.r_rsp; 224 | regs.cs = r.r_cs; 225 | regs.ds = r.r_ds; 226 | regs.eflags = r.r_rflags; 227 | regs.es = r.r_es; 228 | regs.fs = r.r_fs; 229 | regs.gs = r.r_gs; 230 | regs.ss = r.r_ss; 231 | 232 | } 233 | 234 | 235 | 236 | public static IntPtr StartDebug(IntPtr hProcess) 237 | { 238 | 239 | IntPtr value = (IntPtr)PS4DedugAPIWrapper.attachDebugger(new PS4DBG.DebuggerInterruptCallback(DebuggerInterruptCallback)); 240 | threadIds = PS4DedugAPIWrapper.GetThreadsList(); 241 | ProcessEvent processEvent = new ProcessEvent(); 242 | processEvent.debugevent = -2; 243 | processEvent.threadid = threadIds[0]; 244 | processEvent.maxBreakpointCount = Convert.ToSByte(PS4DBG.MAX_BREAKPOINTS); 245 | processEvent.maxWatchpointCount = Convert.ToSByte(PS4DBG.MAX_WATCHPOINTS); 246 | 247 | 248 | processEvent.maxSharedBreakpoints = 4; 249 | debugThread = threadIds[0]; 250 | 251 | addDebugEvent(processEvent); 252 | 253 | //CreateDebugEvent deEvent = new CreateDebugEvent(); 254 | //deEvent.debugevent = -1; 255 | //deEvent.threadid = threadIds[0]; 256 | 257 | //addDebugEvent(deEvent); 258 | 259 | //DebugEvent evet = new DebugEvent(); 260 | //evet.debugevent = 5; 261 | //evet.threadid = threadIds[0]; 262 | //evet.address = 12356; 263 | //addDebugEvent(evet); 264 | 265 | threads = new HashSet(threadIds); 266 | 267 | return value; 268 | } 269 | public static IntPtr StopDebug(IntPtr handle) 270 | { 271 | IntPtr value = (IntPtr)PS4DedugAPIWrapper.dettachDebugger(); 272 | 273 | return value; 274 | } 275 | 276 | 277 | public static IntPtr SetBreakpoint(IntPtr handle, int tid, IntPtr debugreg, UInt64 address, int bptype, int bpsize) 278 | { 279 | // return SetWatchpointToPS4(handle, tid, debugreg, address, bptype, bpsize); 280 | // return SetBreakpointToPS4(handle, tid, debugreg, address, bptype, bpsize); 281 | if (isWatchPoint(bptype, bpsize)) 282 | { 283 | return SetWatchpointToPS4(handle, tid, debugreg, address, bptype, bpsize); 284 | } 285 | else 286 | { 287 | return SetBreakpointToPS4(handle, tid, debugreg, address, bptype, bpsize); 288 | } 289 | } 290 | public static IntPtr SetBreakpointToPS4(IntPtr handle, int tid, IntPtr debugreg, UInt64 address, int bptype, int bpsize) 291 | { 292 | 293 | int num = findBreakPointNumber(); 294 | 295 | if(num == -2) 296 | { 297 | return (IntPtr)0; 298 | } 299 | 300 | if (breakpointsAddress.ContainsKey(address)) 301 | { 302 | uint ti; 303 | if(!breakAddress.TryGetValue(address,out ti)){ 304 | Trace.WriteLine("no tid present for the address " + address.ToString("X")); 305 | } 306 | return (IntPtr)1; 307 | } 308 | 309 | if (SetBreakpoint(num, debugreg, address, bptype, bpsize) != 0) 310 | { 311 | breakpointsAddress[address] = num; 312 | breakpoints.Push(num); 313 | return (IntPtr)1; 314 | } 315 | return (IntPtr)0; 316 | } 317 | 318 | public static IntPtr SetWatchpointToPS4(IntPtr handle, int tid, IntPtr debugreg, UInt64 address, int bptype, int bpsize) 319 | { 320 | 321 | int num = findWatchPointNumber(); 322 | 323 | if (num == -2) 324 | { 325 | return (IntPtr)0; 326 | } 327 | 328 | if (watchpointAddress.ContainsKey(address)) 329 | { 330 | uint ti; 331 | if (!watchAddress.TryGetValue(address, out ti)) 332 | { 333 | Trace.WriteLine("no tid present for the address " + address.ToString("X")); 334 | } 335 | return (IntPtr)1; 336 | } 337 | 338 | if (SetWatchpoint(num, debugreg, address, bptype, bpsize) != 0) 339 | { 340 | watchpointAddress[address] = num; 341 | watchpoints.Push(num); 342 | return (IntPtr)1; 343 | } 344 | return (IntPtr)0; 345 | } 346 | 347 | private static int SetBreakpoint(int tid, IntPtr debugreg, UInt64 address, int bptype, int bpsize) 348 | { 349 | try 350 | { 351 | SetBreakPointEvent se = new SetBreakPointEvent(); 352 | SetBreakPointRequest request = new SetBreakPointRequest 353 | { 354 | Address = address, 355 | Tid = tid 356 | }; 357 | se.Data = request; 358 | DebugEventHandler.AddEvent(se); 359 | 360 | return (int)DebugEventHandler.ConsumeAsync(se.BufferBlock).Result; 361 | } 362 | catch (Exception) 363 | { 364 | Trace.WriteLine("cant create break point for" + tid); 365 | return 0; 366 | } 367 | } 368 | 369 | private static int SetWatchpoint(int tid, IntPtr debugreg, UInt64 address, int bptype, int bpsize) 370 | { 371 | try 372 | { 373 | SetWatchPointEvent se = new SetWatchPointEvent(); 374 | SetWatchPointRequest request = new SetWatchPointRequest 375 | { 376 | Address = address, 377 | Bpsize = bpsize, 378 | Bptype = bptype, 379 | Tid = tid 380 | }; 381 | se.Data = request; 382 | DebugEventHandler.AddEvent(se); 383 | 384 | return (int)DebugEventHandler.ConsumeAsync(se.BufferBlock).Result; 385 | } 386 | catch (Exception) 387 | { 388 | Trace.WriteLine("cant create watch point for" + tid); 389 | return 0; 390 | } 391 | } 392 | 393 | 394 | public static IntPtr RemoveBreakpoint(IntPtr handle, int tid, IntPtr debugreg,ulong address, int wasWatchpoint) 395 | { 396 | // return RemoveWatchpointFromPS4(handle, tid, debugreg, address, wasWatchpoint); 397 | // return RemoveBreakpointFromPS4(handle, tid, debugreg, wasWatchpoint); 398 | if (wasWatchpoint == 1) 399 | { 400 | return RemoveWatchpointFromPS4(handle, tid, debugreg, address, wasWatchpoint); 401 | } 402 | else 403 | { 404 | return RemoveBreakpointFromPS4(handle, tid, debugreg, address, wasWatchpoint); 405 | } 406 | } 407 | 408 | public static IntPtr RemoveWatchpointFromPS4(IntPtr handle, int tid, IntPtr debugreg, ulong address, int wasWatchpoint) 409 | { 410 | 411 | if (address > 0) 412 | { 413 | if (watchpoints.Count > 0) 414 | { 415 | watchpoints.Pop(); 416 | } 417 | if (watchpointAddress.Count > 0) 418 | { 419 | 420 | if (watchpointAddress.TryGetValue(address, out int wp)) 421 | { 422 | 423 | if (watchAddress.TryGetValue(address, out uint ti)) 424 | { 425 | breakAddress.Remove(address); 426 | watchThreaads.Remove(ti); 427 | } 428 | watchpointAddress.Remove(address); 429 | return RemoveWatchPointEventFromPS4(wp); 430 | } 431 | 432 | return (IntPtr)1; 433 | } 434 | } 435 | if (tid == -1) 436 | { 437 | watchpointAddress.Clear(); 438 | watchpoints.Clear(); 439 | watchThreaads.Clear(); 440 | watchAddress.Clear(); 441 | return RemoveWatchPointEventFromPS4(tid); 442 | } 443 | else 444 | { 445 | if (watchpoints.Count > 0) 446 | { 447 | watchpoints.Pop(); 448 | } 449 | 450 | if (watchpointAddress.Count > 0) 451 | { 452 | if (watchThreaads.TryGetValue(Convert.ToUInt32(tid), out ulong ad)) 453 | { 454 | if (watchpointAddress.TryGetValue(Convert.ToUInt32(tid), out int wp)) 455 | { 456 | watchThreaads.Remove(Convert.ToUInt32(tid)); 457 | watchAddress.Remove(ad); 458 | watchpointAddress.Remove(ad); 459 | return RemoveWatchPointEventFromPS4(wp); 460 | } 461 | 462 | } 463 | return (IntPtr)1; 464 | } 465 | else 466 | { 467 | return (IntPtr)1; 468 | } 469 | } 470 | 471 | } 472 | 473 | public static IntPtr RemoveWatchPointEventFromPS4(int tid) 474 | { 475 | RemoveWatchPointEvent se = new RemoveWatchPointEvent(); 476 | RemoveWatchPointRequest request = new RemoveWatchPointRequest 477 | { 478 | 479 | Tid = tid 480 | }; 481 | se.Data = request; 482 | DebugEventHandler.AddEvent(se); 483 | 484 | int obj = (int)DebugEventHandler.ConsumeAsync(se.BufferBlock).Result; 485 | return (IntPtr)obj; 486 | } 487 | 488 | 489 | public static IntPtr RemoveBreakpointFromPS4(IntPtr handle, int tid, IntPtr debugreg, ulong address, int wasWatchpoint) 490 | { 491 | if (address > 0) 492 | { 493 | if (breakpoints.Count > 0) 494 | { 495 | breakpoints.Pop(); 496 | } 497 | if (breakpointsAddress.Count > 0) 498 | { 499 | 500 | if (breakpointsAddress.TryGetValue(address, out int bp)) 501 | { 502 | 503 | if (breakAddress.TryGetValue(address, out uint ti)) 504 | { 505 | breakAddress.Remove(address); 506 | breakThreaads.Remove(ti); 507 | } 508 | breakpointsAddress.Remove(address); 509 | return RemoveBreakPointEventFromPS4(bp); 510 | } 511 | 512 | return (IntPtr)1; 513 | } 514 | } 515 | 516 | if (tid == -1) 517 | { 518 | breakpointsAddress.Clear(); 519 | breakpoints.Clear(); 520 | breakAddress.Clear(); 521 | breakThreaads.Clear(); 522 | return RemoveBreakPointEventFromPS4(tid); 523 | } 524 | else 525 | { 526 | if (breakpoints.Count > 0) 527 | { 528 | breakpoints.Pop(); 529 | } 530 | if (breakpointsAddress.Count > 0) 531 | { 532 | if (breakThreaads.TryGetValue(Convert.ToUInt32(tid), out ulong ad)) 533 | { 534 | if (breakpointsAddress.TryGetValue(Convert.ToUInt32(tid), out int bp)) 535 | { 536 | breakThreaads.Remove(Convert.ToUInt32(tid)); 537 | breakAddress.Remove(ad); 538 | breakpointsAddress.Remove(ad); 539 | return RemoveBreakPointEventFromPS4(bp); 540 | } 541 | } 542 | return (IntPtr)1; 543 | } 544 | else 545 | { 546 | return (IntPtr)1; 547 | } 548 | } 549 | 550 | } 551 | 552 | 553 | public static IntPtr RemoveBreakPointEventFromPS4(int tid) 554 | { 555 | RemoveBreakPointEvent se = new RemoveBreakPointEvent(); 556 | RemoveBreakPointRequest request = new RemoveBreakPointRequest 557 | { 558 | 559 | Tid = tid 560 | }; 561 | se.Data = request; 562 | DebugEventHandler.AddEvent(se); 563 | 564 | int obj = (int)DebugEventHandler.ConsumeAsync(se.BufferBlock).Result; 565 | return (IntPtr)obj; 566 | } 567 | 568 | 569 | public static IntPtr SuspendThread(IntPtr handle, uint tid) 570 | { 571 | SuspendThreadEvent se = new SuspendThreadEvent(); 572 | SuspendThreadRequest request = new SuspendThreadRequest 573 | { 574 | 575 | Tid = tid 576 | }; 577 | se.Data = request; 578 | DebugEventHandler.AddEvent(se); 579 | 580 | int obj = (int)DebugEventHandler.ConsumeAsync(se.BufferBlock).Result; 581 | return (IntPtr)obj; 582 | } 583 | public static IntPtr ResumeThread(IntPtr handle, uint tid) 584 | { 585 | ResumeThreadEvent se = new ResumeThreadEvent(); 586 | ResumeThreadRequest request = new ResumeThreadRequest 587 | { 588 | 589 | Tid = tid 590 | }; 591 | se.Data = request; 592 | DebugEventHandler.AddEvent(se); 593 | 594 | int obj = (int)DebugEventHandler.ConsumeAsync(se.BufferBlock).Result; 595 | return (IntPtr)obj; 596 | } 597 | 598 | public static IntPtr GetThreadContext(IntPtr handle, uint tid, out CONTEXT Context, int type) 599 | { 600 | try 601 | { 602 | if (!threads.Contains(tid)) 603 | { 604 | tid = debugThread; 605 | } 606 | ThreadContextEvent se = new ThreadContextEvent(); 607 | ThreadContextRequest request = new ThreadContextRequest 608 | { 609 | 610 | Tid = tid , 611 | Type = type 612 | }; 613 | se.Data = request; 614 | DebugEventHandler.AddEvent(se); 615 | regs r = (regs)DebugEventHandler.ConsumeAsync(se.BufferBlock).Result; 616 | 617 | 618 | assignThreadRegisters(r, out CONTEXT_REGS regs); 619 | Context = new CONTEXT 620 | { 621 | regs = regs 622 | }; 623 | 624 | if (regs.rip == 0) 625 | { 626 | return (IntPtr)0; 627 | } 628 | 629 | return (IntPtr)1; 630 | } 631 | catch (Exception) 632 | { 633 | Context = new CONTEXT(); 634 | return (IntPtr)0; 635 | } 636 | 637 | } 638 | 639 | public static IntPtr setThreadContext(IntPtr handle, uint tid, CONTEXT Context, int type) 640 | { 641 | try 642 | { 643 | if (!threads.Contains(tid)) 644 | { 645 | tid = debugThread; 646 | } 647 | ThreadContextEvent se = new ThreadContextEvent(); 648 | ThreadContextRequest request = new ThreadContextRequest 649 | { 650 | 651 | Tid = tid, 652 | Type = type 653 | }; 654 | se.Data = request; 655 | DebugEventHandler.AddEvent(se); 656 | regs r = (regs)DebugEventHandler.ConsumeAsync(se.BufferBlock).Result; 657 | 658 | 659 | assignThreadRegisters(r, out CONTEXT_REGS regs); 660 | Context = new CONTEXT 661 | { 662 | regs = regs 663 | }; 664 | 665 | if (regs.rip == 0) 666 | { 667 | return (IntPtr)0; 668 | } 669 | 670 | return (IntPtr)1; 671 | } 672 | catch (Exception) 673 | { 674 | Context = new CONTEXT(); 675 | return (IntPtr)0; 676 | } 677 | 678 | } 679 | 680 | public static IntPtr WaitForDebugEvent(IntPtr handle, int timeout, out Object evet) 681 | { 682 | try 683 | { 684 | Object et; 685 | if(debugEvents.TryTake(out et, timeout)) 686 | { 687 | evet = et; 688 | currentDebugEvent = evet; 689 | return (IntPtr)1; 690 | } 691 | evet = new DebugEvent(); 692 | return (IntPtr)0; 693 | } 694 | catch (Exception) 695 | { 696 | evet = new DebugEvent(); 697 | return (IntPtr)0; 698 | } 699 | } 700 | 701 | public static IntPtr ContinueForDebugEvent(IntPtr handle, uint tid, uint continuemethod) 702 | { 703 | try 704 | { 705 | 706 | ContinueDebugEvent se = new ContinueDebugEvent(); 707 | ContinueDebugEventRequest rq = new ContinueDebugEventRequest(); 708 | rq.Tid = tid; 709 | if(continuemethod == 2) 710 | { 711 | rq.singleStep = true; 712 | } 713 | else 714 | { 715 | rq.singleStep = false; 716 | } 717 | se.Data = rq; 718 | DebugEventHandler.AddEvent(se); 719 | 720 | int obj = (int)DebugEventHandler.ConsumeAsync(se.BufferBlock).Result; 721 | return (IntPtr)obj; 722 | 723 | } 724 | catch (Exception) 725 | { 726 | return (IntPtr)0; 727 | } 728 | } 729 | 730 | private static int findWatchPointNumber() 731 | { 732 | if(watchpoints.Count<=0) 733 | { 734 | return 0; 735 | }else if(watchpoints.Count > 0 && watchpoints.Count < PS4DBG.MAX_WATCHPOINTS) 736 | { 737 | return watchpoints.Peek()+1; 738 | } 739 | else 740 | { 741 | return -2; 742 | } 743 | } 744 | 745 | private static int findBreakPointNumber() 746 | { 747 | if (breakpoints.Count <= 0) 748 | { 749 | return 0; 750 | } 751 | else if (breakpoints.Count > 0 && breakpoints.Count < PS4DBG.MAX_BREAKPOINTS) 752 | { 753 | return breakpoints.Peek() + 1; 754 | } 755 | else 756 | { 757 | return -2; 758 | } 759 | } 760 | 761 | private static bool isWatchPoint(int btype,int bsize) 762 | { 763 | if(btype==0 && bsize == 1) 764 | { 765 | return false; 766 | } 767 | else 768 | { 769 | return true; 770 | } 771 | } 772 | } 773 | } 774 | -------------------------------------------------------------------------------- /CEServerPS4/PS4API/MemoryAPI.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using libdebug; 7 | 8 | namespace CEServerPS4.PS4API 9 | { 10 | public static class MemoryAPI 11 | { 12 | 13 | private static ulong regionsize = 512; 14 | 15 | private static ulong pagesize = 512 * 8; 16 | 17 | private static SortedDictionary memoryMap = new SortedDictionary(); 18 | 19 | private static List keys; 20 | 21 | public enum AllocationProtectEnum : uint 22 | { 23 | PAGE_EXECUTE = 0x00000010, 24 | PAGE_EXECUTE_READ = 0x00000020, 25 | PAGE_EXECUTE_READWRITE = 0x00000040, 26 | PAGE_EXECUTE_WRITECOPY = 0x00000080, 27 | PAGE_NOACCESS = 0x00000001, 28 | PAGE_READONLY = 0x00000002, 29 | PAGE_READWRITE = 0x00000004, 30 | PAGE_WRITECOPY = 0x00000008, 31 | PAGE_GUARD = 0x00000100, 32 | PAGE_NOCACHE = 0x00000200, 33 | PAGE_WRITECOMBINE = 0x00000400 34 | } 35 | 36 | public enum StateEnum : uint 37 | { 38 | MEM_COMMIT = 0x1000, 39 | MEM_FREE = 0x10000, 40 | MEM_RESERVE = 0x2000 41 | } 42 | 43 | public enum TypeEnum : uint 44 | { 45 | MEM_IMAGE = 0x1000000, 46 | MEM_MAPPED = 0x40000, 47 | MEM_PRIVATE = 0x20000 48 | } 49 | 50 | [StructLayout(LayoutKind.Sequential)] 51 | public struct MEMORY_BASIC_INFORMATION 52 | { 53 | public ulong BaseAddress; 54 | public ulong AllocationBase; 55 | public AllocationProtectEnum AllocationProtect; 56 | public ulong RegionSize; 57 | public StateEnum State; 58 | public AllocationProtectEnum Protect; 59 | public TypeEnum Type; 60 | } 61 | 62 | [StructLayout(LayoutKind.Sequential)] 63 | public struct CONTEXT_REGS 64 | { 65 | public ulong r15; 66 | public ulong r14; 67 | public ulong r13; 68 | public ulong r12; 69 | public ulong rbp; 70 | public ulong rbx; 71 | public ulong r11; 72 | public ulong r10; 73 | public ulong r9; 74 | public ulong r8; 75 | public ulong rax; 76 | public ulong rcx; 77 | public ulong rdx; 78 | public ulong rsi; 79 | public ulong rdi; 80 | public ulong orig_rax; 81 | public ulong rip; 82 | public ulong cs; 83 | public ulong eflags; 84 | public ulong rsp; 85 | public ulong ss; 86 | public ulong fs_base; 87 | public ulong gs_base; 88 | public ulong ds; 89 | public ulong es; 90 | public ulong fs; 91 | public ulong gs; 92 | }; 93 | 94 | 95 | [StructLayout(LayoutKind.Sequential)] 96 | public struct CONTEXT 97 | { 98 | public CONTEXT_REGS regs; 99 | } 100 | 101 | 102 | public static bool ReadProcessMemory( 103 | IntPtr hProcess, 104 | ulong lpBaseAddress, 105 | out byte[] lpBuffer, 106 | Int32 nSize, 107 | out IntPtr lpNumberOfBytesRead) 108 | { 109 | byte[] readbuffer = new byte[nSize]; 110 | readbuffer = PS4APIWrapper.ReadMemory(lpBaseAddress, nSize); 111 | lpBuffer = readbuffer; 112 | string value = BitConverter.ToString(readbuffer); 113 | lpNumberOfBytesRead = new IntPtr(readbuffer.Length); 114 | return true; 115 | } 116 | 117 | public static bool WriteMemory( 118 | IntPtr hProcess, 119 | ulong lpBaseAddress, 120 | byte[] lpBuffer, 121 | Int32 nSize, 122 | out IntPtr lpNumberOfBytesRead) 123 | { 124 | PS4APIWrapper.WriteMemory(lpBaseAddress, lpBuffer); 125 | lpNumberOfBytesRead = new IntPtr(nSize); 126 | return true; 127 | } 128 | 129 | 130 | public static int VirtualQueryEx(IntPtr hProcess, ulong lpAddress, out MEMORY_BASIC_INFORMATION lpBuffer,uint dwLength) 131 | { 132 | lpBuffer = new MEMORY_BASIC_INFORMATION(); 133 | ulong address = (ulong)lpAddress; 134 | if (keys.Contains(address)) 135 | { 136 | 137 | if (!memoryMap.TryGetValue(address, out lpBuffer)) 138 | { 139 | return 0; 140 | } 141 | return 1; 142 | } 143 | 144 | if (lpAddress == 0) 145 | { 146 | lpBuffer = memoryMap.First().Value; 147 | return 1; 148 | } 149 | else 150 | { 151 | 152 | foreach(ulong adrs in keys) 153 | { 154 | if (address < adrs) 155 | { 156 | 157 | if (!memoryMap.TryGetValue(adrs, out lpBuffer)) 158 | { 159 | return 0; 160 | } 161 | 162 | return 1; 163 | } 164 | } 165 | 166 | return 0; 167 | } 168 | 169 | } 170 | 171 | 172 | 173 | public static void intit( int pid) 174 | { 175 | memoryMap.Clear(); 176 | ProcessMap pm = PS4APIWrapper.GetProcessMaps(pid); 177 | 178 | for (int i = 0; i < pm.entries.Length; i++) 179 | { 180 | MemoryEntry entry = pm.entries[i]; 181 | if ((entry.prot & 0x1) == 0x1) 182 | { 183 | 184 | ulong length = entry.end - entry.start; 185 | ulong start = entry.start; 186 | 187 | ulong buffer_length = regionsize * pagesize; 188 | 189 | //Executable section 190 | if ((entry.prot & 0x5) == 0x5) 191 | { 192 | buffer_length =length; 193 | } 194 | 195 | while (length != 0) 196 | { 197 | ulong cur_length = buffer_length; 198 | 199 | if (cur_length > length) 200 | { 201 | cur_length = length; 202 | length = 0; 203 | } 204 | else 205 | { 206 | length -= cur_length; 207 | } 208 | MEMORY_BASIC_INFORMATION m32Entry = new MEMORY_BASIC_INFORMATION(); 209 | m32Entry.BaseAddress = start; 210 | m32Entry.AllocationBase = start; 211 | m32Entry.AllocationProtect = allocationProtect(entry.prot); 212 | m32Entry.RegionSize = cur_length; 213 | m32Entry.Type = typeEnum(entry.prot); 214 | 215 | memoryMap[start]= m32Entry; 216 | 217 | start += cur_length; 218 | 219 | } 220 | } 221 | } 222 | keys = new List(memoryMap.Keys.AsEnumerable()); 223 | 224 | } 225 | 226 | private static AllocationProtectEnum allocationProtect(uint prot) 227 | { 228 | if ((uint)PS4DBG.VM_PROTECTIONS.VM_PROT_ALL ==prot) 229 | { 230 | return AllocationProtectEnum.PAGE_EXECUTE_READWRITE; 231 | } 232 | else if((uint)PS4DBG.VM_PROTECTIONS.VM_PROT_EXECUTE == prot) 233 | { 234 | return AllocationProtectEnum.PAGE_EXECUTE; 235 | } 236 | else if ((uint)PS4DBG.VM_PROTECTIONS.VM_PROT_READ == prot) 237 | { 238 | return AllocationProtectEnum.PAGE_READONLY; 239 | } 240 | else if ((uint)PS4DBG.VM_PROTECTIONS.VM_PROT_DEFAULT == prot) 241 | { 242 | return AllocationProtectEnum.PAGE_READWRITE; 243 | } 244 | return AllocationProtectEnum.PAGE_WRITECOPY; 245 | } 246 | 247 | 248 | private static TypeEnum typeEnum(uint prot) 249 | { 250 | return TypeEnum.MEM_PRIVATE; 251 | } 252 | 253 | } 254 | } 255 | -------------------------------------------------------------------------------- /CEServerPS4/PS4API/PS4APIWrapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using libdebug; 4 | using System.Runtime.InteropServices; 5 | using System.Diagnostics; 6 | 7 | namespace CEServerPS4.PS4API 8 | { 9 | 10 | public class PS4APIWrapper 11 | { 12 | 13 | public static int num_threads = 6; 14 | public static PS4DBG[] ps4 = new PS4DBG[num_threads]; 15 | private static Mutex[] mutex = new Mutex[num_threads]; 16 | 17 | 18 | 19 | private static int mutexId = 0; 20 | 21 | 22 | static PS4APIWrapper() 23 | { 24 | for (int i = 0; i < num_threads; i++) 25 | mutex[i] = new Mutex(); 26 | } 27 | 28 | private static int MutrexID 29 | { 30 | get 31 | { 32 | mutexId++; 33 | if (mutexId > num_threads - 1) 34 | { 35 | mutexId = 0; 36 | } 37 | return mutexId; 38 | } 39 | } 40 | 41 | 42 | public static int ProcessID 43 | { 44 | get; set; 45 | } 46 | 47 | public static bool Connect() 48 | { 49 | try 50 | { 51 | for (int i = 0; i < num_threads; i++) 52 | { 53 | mutex[i].WaitOne(); 54 | ps4[i] = new PS4DBG(PS4Static.IP); 55 | ps4[i].Connect(); 56 | } 57 | 58 | return true; 59 | } 60 | catch(Exception e) 61 | { 62 | Trace.WriteLine("unable to connect:"+e.Message); 63 | } 64 | finally 65 | { 66 | for (int i = 0; i < num_threads; i++) 67 | mutex[i].ReleaseMutex(); 68 | } 69 | return false; 70 | } 71 | 72 | public static bool Disconnect() 73 | { 74 | 75 | try 76 | { 77 | for (int i = 0; i < num_threads; i++) 78 | { 79 | 80 | if (ps4[i] != null) 81 | { 82 | ps4[i].Disconnect(); 83 | } 84 | } 85 | 86 | return true; 87 | } 88 | catch (Exception e) 89 | { 90 | Trace.WriteLine("unable to disconnect:"+e.Message); 91 | } 92 | return false; 93 | } 94 | 95 | public static byte[] ReadMemory(ulong address, int length) 96 | { 97 | int currentThreadId = MutrexID; 98 | mutex[currentThreadId].WaitOne(); 99 | try 100 | { 101 | return ps4[currentThreadId].ReadMemory(ProcessID, address, length); 102 | } 103 | catch (Exception e) 104 | { 105 | Trace.WriteLine("Error while reading Memory :"+e.Message); 106 | } 107 | finally 108 | { 109 | mutex[currentThreadId].ReleaseMutex(); 110 | } 111 | return new byte[length]; 112 | } 113 | 114 | public static void WriteMemory(ulong address, byte[] data) 115 | { 116 | int currentThreadId = MutrexID; 117 | mutex[currentThreadId].WaitOne(); 118 | try 119 | { 120 | ps4[currentThreadId].WriteMemory(ProcessID, address, data); 121 | } 122 | catch (Exception e) 123 | { 124 | Trace.WriteLine("Error while write Memory :"+e.Message); 125 | } 126 | finally 127 | { 128 | mutex[currentThreadId].ReleaseMutex(); 129 | } 130 | } 131 | 132 | public static ProcessList GetProcessList() 133 | { 134 | int currentThreadId = MutrexID; 135 | mutex[currentThreadId].WaitOne(); 136 | try 137 | { 138 | return ps4[currentThreadId].GetProcessList(); 139 | 140 | } 141 | catch (Exception e) 142 | { 143 | Trace.WriteLine("Error while GetProcessList:"+e.Message); 144 | } 145 | finally 146 | { 147 | mutex[currentThreadId].ReleaseMutex(); 148 | } 149 | return null; 150 | } 151 | 152 | public static ProcessInfo? GetProcessInfo(int processID) 153 | { 154 | int currentThreadId = MutrexID; 155 | mutex[currentThreadId].WaitOne(); 156 | 157 | try 158 | { 159 | ProcessInfo processInfo = ps4[currentThreadId].GetProcessInfo(processID); 160 | return processInfo; 161 | } 162 | catch (Exception e) 163 | { 164 | Trace.WriteLine("Error while GetProcessInfo:"+e.Message); 165 | } 166 | finally 167 | { 168 | mutex[currentThreadId].ReleaseMutex(); 169 | } 170 | return null; 171 | } 172 | 173 | public static ProcessMap GetProcessMaps(int processID) 174 | { 175 | int currentThreadId = MutrexID; 176 | mutex[currentThreadId].WaitOne(); 177 | try 178 | { 179 | ProcessMap processMap = ps4[currentThreadId].GetProcessMaps(processID); 180 | return processMap; 181 | } 182 | catch (Exception e) 183 | { 184 | Trace.WriteLine("Error while GetProcessMaps:"+e.Message); 185 | } 186 | finally 187 | { 188 | mutex[currentThreadId].ReleaseMutex(); 189 | } 190 | return null; 191 | } 192 | 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /CEServerPS4/PS4API/PS4DedugAPIWrapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using libdebug; 4 | using System.Runtime.InteropServices; 5 | using System.Diagnostics; 6 | 7 | namespace CEServerPS4.PS4API 8 | { 9 | 10 | public class PS4DedugAPIWrapper 11 | { 12 | private static PS4DBG ps4Debugger; 13 | 14 | public static PS4DBG getps4() 15 | { 16 | return ps4Debugger; 17 | } 18 | 19 | public static uint[] GetThreadsList() 20 | { 21 | 22 | try 23 | { 24 | return ps4Debugger.GetThreadList(); 25 | } 26 | catch (Exception e) 27 | { 28 | Trace.WriteLine("Error while GetThreadsList :" + e.Message); 29 | } 30 | 31 | return null; 32 | } 33 | 34 | public static int attachDebugger(PS4DBG.DebuggerInterruptCallback callback) 35 | { 36 | try 37 | { 38 | ps4Debugger = new PS4DBG(PS4Static.IP); 39 | ps4Debugger.Connect(); 40 | if (!ps4Debugger.IsDebugging) 41 | { 42 | ps4Debugger.AttachDebugger(PS4APIWrapper.ProcessID, callback); 43 | ps4Debugger.ProcessResume(); 44 | } 45 | 46 | return 1; 47 | } 48 | catch (Exception e) 49 | { 50 | Trace.WriteLine("unable to attach"); 51 | Trace.WriteLine(e); 52 | } 53 | 54 | return 0; 55 | } 56 | 57 | public static int dettachDebugger() 58 | { 59 | try 60 | { 61 | if (ps4Debugger != null) 62 | { 63 | ps4Debugger.DetachDebugger(); 64 | ps4Debugger.Disconnect(); 65 | } 66 | 67 | return 1; 68 | } 69 | catch(Exception e) 70 | { 71 | Trace.WriteLine("unable to detach"); 72 | Trace.WriteLine(e); 73 | return 0; 74 | } 75 | 76 | } 77 | 78 | 79 | public static void ProcessResume() 80 | { 81 | try 82 | { 83 | ps4Debugger.ProcessResume(); 84 | } 85 | catch (Exception e) 86 | { 87 | Trace.WriteLine("unable to resume process:" + e.Message); 88 | Trace.WriteLine(e.Message); 89 | } 90 | 91 | } 92 | 93 | public static void resumeDebuggerThread(uint tid) 94 | { 95 | try 96 | { 97 | ps4Debugger.ResumeThread(tid); 98 | } 99 | catch (Exception e) 100 | { 101 | Trace.WriteLine("unable to resume:" + e.Message); 102 | Trace.WriteLine(e.Message); 103 | throw e; 104 | } 105 | 106 | } 107 | 108 | 109 | public static void ContinueBreakpointThread(uint tid,bool IsSingleStep) 110 | { 111 | try 112 | { 113 | if (IsSingleStep) 114 | { 115 | ps4Debugger.SingleStep(); 116 | } 117 | else 118 | { 119 | ps4Debugger.ProcessResume(); 120 | } 121 | } 122 | catch (Exception e) 123 | { 124 | Trace.WriteLine("unable to continue:"+e.Message); 125 | Trace.WriteLine(e.Message); 126 | throw e; 127 | } 128 | 129 | } 130 | 131 | 132 | public static void StopDebuggerThread(uint tid) 133 | { 134 | try 135 | { 136 | ps4Debugger.StopThread(tid); 137 | } 138 | catch (Exception e) 139 | { 140 | Trace.WriteLine("unable to stop thread:"+e.Message); 141 | Trace.WriteLine(e.Message); 142 | throw e; 143 | } 144 | 145 | } 146 | 147 | 148 | public static void ClearBreakpoints() 149 | { 150 | for (int index = 0; (long)index < (long)PS4DBG.MAX_BREAKPOINTS; ++index) 151 | ps4Debugger.ChangeBreakpoint(index, false, 0UL); 152 | 153 | ps4Debugger.ProcessResume(); 154 | } 155 | 156 | public static void ClearWatchPoints() 157 | { 158 | for (int index = 0; (long)index < (long)PS4DBG.MAX_WATCHPOINTS; ++index) 159 | ps4Debugger.ChangeWatchpoint(index, false, PS4DBG.WATCHPT_LENGTH.DBREG_DR7_LEN_1, 160 | PS4DBG.WATCHPT_BREAKTYPE.DBREG_DR7_EXEC, 0UL); 161 | ps4Debugger.ProcessResume(); 162 | } 163 | 164 | public static void SetWatchpoint(int watchpoint,ulong address,int watchtLength,int type) 165 | { 166 | PS4DBG.WATCHPT_LENGTH watchptLength = PS4DBG.WATCHPT_LENGTH.DBREG_DR7_LEN_1; 167 | 168 | if (!(watchtLength == 1)) 169 | { 170 | if (!(watchtLength == 2)) 171 | { 172 | if (!(watchtLength == 4)) 173 | { 174 | if (watchtLength == 8) 175 | watchptLength = PS4DBG.WATCHPT_LENGTH.DBREG_DR7_LEN_8; 176 | } 177 | else 178 | watchptLength = PS4DBG.WATCHPT_LENGTH.DBREG_DR7_LEN_4; 179 | } 180 | else 181 | watchptLength = PS4DBG.WATCHPT_LENGTH.DBREG_DR7_LEN_2; 182 | } 183 | else 184 | watchptLength = PS4DBG.WATCHPT_LENGTH.DBREG_DR7_LEN_1; 185 | 186 | PS4DBG.WATCHPT_BREAKTYPE watchptBreaktype = PS4DBG.WATCHPT_BREAKTYPE.DBREG_DR7_EXEC; 187 | 188 | if (!(type == (int)PS4DBG.WATCHPT_BREAKTYPE.DBREG_DR7_EXEC)) 189 | { 190 | if (!(type == (int)PS4DBG.WATCHPT_BREAKTYPE.DBREG_DR7_WRONLY)) 191 | { 192 | if (type == (int)PS4DBG.WATCHPT_BREAKTYPE.DBREG_DR7_RDWR) 193 | watchptBreaktype = PS4DBG.WATCHPT_BREAKTYPE.DBREG_DR7_RDWR; 194 | } 195 | else 196 | watchptBreaktype = PS4DBG.WATCHPT_BREAKTYPE.DBREG_DR7_WRONLY; 197 | } 198 | else 199 | watchptBreaktype = PS4DBG.WATCHPT_BREAKTYPE.DBREG_DR7_EXEC; 200 | try 201 | { 202 | ps4Debugger.ChangeWatchpoint(watchpoint, true, watchptLength, watchptBreaktype, 203 | address); 204 | }catch(Exception e) 205 | { 206 | Trace.WriteLine("breakpoint error:"+e.Message); 207 | throw e; 208 | } 209 | 210 | } 211 | 212 | public static void ClearWatchpoint(int watchpoint) 213 | { 214 | ps4Debugger.ChangeWatchpoint(watchpoint, false, 215 | PS4DBG.WATCHPT_LENGTH.DBREG_DR7_LEN_1, PS4DBG.WATCHPT_BREAKTYPE.DBREG_DR7_EXEC, 0UL); 216 | } 217 | 218 | public static void SetBreakpoint(int breakpoint, ulong address) 219 | { 220 | ps4Debugger.ChangeBreakpoint(breakpoint, true, address); 221 | } 222 | 223 | public static void ClearBreakpoint(int breakpoint) 224 | { 225 | ps4Debugger.ChangeBreakpoint(breakpoint, false, 0UL); 226 | } 227 | 228 | public static regs getRegisters(uint tid) 229 | { 230 | return ps4Debugger.GetRegisters(tid); 231 | } 232 | } 233 | } 234 | -------------------------------------------------------------------------------- /CEServerPS4/PS4API/PS4Static.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using libdebug; 4 | using System.Runtime.InteropServices; 5 | 6 | namespace CEServerPS4.PS4API 7 | { 8 | 9 | public static class PS4Static 10 | { 11 | 12 | public static string IP 13 | { 14 | get; set; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /CEServerPS4/PS4API/ToolHelp.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using libdebug; 7 | 8 | namespace CEServerPS4.PS4API 9 | { 10 | public static class ToolHelp 11 | { 12 | 13 | 14 | private static ProcessList processList = null; 15 | 16 | private static ProcessMap processMap = null; 17 | 18 | private static List moduleEntries = new List(); 19 | 20 | private static int processIndex ; 21 | 22 | private static int moduleIndex; 23 | 24 | [Flags] 25 | public enum SnapshotFlags : uint 26 | { 27 | HeapList = 0x00000001, 28 | Process = 0x00000002, 29 | Thread = 0x00000004, 30 | Module = 0x00000008, 31 | Module32 = 0x00000010, 32 | All = (HeapList | Process | Thread | Module), 33 | Inherit = 0x80000000, 34 | NoHeaps = 0x40000000 35 | } 36 | 37 | [Flags] 38 | public enum ProcessAccessFlags : uint 39 | { 40 | All = 0x001F0FFF, 41 | Terminate = 0x00000001, 42 | CreateThread = 0x00000002, 43 | VirtualMemoryOperation = 0x00000008, 44 | VirtualMemoryRead = 0x00000010, 45 | VirtualMemoryWrite = 0x00000020, 46 | DuplicateHandle = 0x00000040, 47 | CreateProcess = 0x000000080, 48 | SetQuota = 0x00000100, 49 | SetInformation = 0x00000200, 50 | QueryInformation = 0x00000400, 51 | QueryLimitedInformation = 0x00001000, 52 | Synchronize = 0x00100000 53 | } 54 | 55 | [StructLayout(LayoutKind.Sequential)] 56 | public struct PROCESSENTRY32 57 | { 58 | public uint dwSize; 59 | public uint cntUsage; 60 | public uint th32ProcessID; 61 | public IntPtr th32DefaultHeapID; 62 | public uint th32ModuleID; 63 | public uint cntThreads; 64 | public uint th32ParentProcessID; 65 | public int pcPriClassBase; 66 | public uint dwFlags; 67 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string szExeFile; 68 | }; 69 | 70 | [StructLayout(LayoutKind.Sequential)] 71 | public struct MODULEENTRY32 72 | { 73 | internal uint dwSize; 74 | internal uint th32ModuleID; 75 | internal uint th32ProcessID; 76 | internal uint GlblcntUsage; 77 | internal uint ProccntUsage; 78 | internal ulong modBaseAddr; 79 | internal uint modBaseSize; 80 | internal ulong hModule; 81 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] 82 | internal string szModule; 83 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] 84 | internal string szExePath; 85 | } 86 | 87 | 88 | 89 | public static IntPtr CreateToolhelp32Snapshot(SnapshotFlags dwFlags, uint th32ProcessID) 90 | { 91 | bool processFlag = ((uint)SnapshotFlags.Process & (uint)dwFlags) != 0; 92 | bool moduleFlag = ((uint)SnapshotFlags.Module & (uint)dwFlags) != 0; 93 | if (processFlag) 94 | { 95 | processIndex = 0; 96 | processList = PS4APIWrapper.GetProcessList(); 97 | return (IntPtr)1; 98 | 99 | }else if (moduleFlag) 100 | { 101 | moduleIndex = 0; 102 | processMap = PS4APIWrapper.GetProcessMaps(Convert.ToInt32(th32ProcessID)); 103 | moduleEntries.Clear(); 104 | InitModuleList(processMap); 105 | return (IntPtr)2; 106 | } 107 | else 108 | { 109 | return (IntPtr)0; 110 | } 111 | } 112 | 113 | 114 | 115 | public static bool Process32First(IntPtr hSnapshot, ref PROCESSENTRY32 lppe) 116 | { 117 | if(processList == null) 118 | { 119 | return false; 120 | } 121 | if(processIndex< processList.processes.Length) 122 | { 123 | Process process = processList.processes[processIndex++]; 124 | processEntry(process, ref lppe); 125 | return true; 126 | } 127 | else 128 | { 129 | processIndex = 0; 130 | } 131 | 132 | return false; 133 | 134 | } 135 | 136 | public static bool Process32Next(IntPtr hSnapshot, ref PROCESSENTRY32 lppe) 137 | { 138 | return Process32First(hSnapshot, ref lppe); 139 | } 140 | 141 | public static bool Module32First(IntPtr hSnapshot, ref MODULEENTRY32 lpme) 142 | { 143 | if (processMap == null) 144 | { 145 | return false; 146 | } 147 | if(moduleIndex < moduleEntries.Count()) 148 | { 149 | MODULEENTRY32 MODULEENTRY32 = moduleEntries[moduleIndex++]; 150 | moduleEntry(MODULEENTRY32, ref lpme); 151 | return true; 152 | } 153 | else 154 | { 155 | moduleIndex = 0; 156 | } 157 | 158 | 159 | return false; 160 | } 161 | 162 | private static void moduleEntry(MODULEENTRY32 m1, ref MODULEENTRY32 result) 163 | { 164 | result.modBaseAddr = m1.modBaseAddr; 165 | result.GlblcntUsage = m1.GlblcntUsage; 166 | result.modBaseSize = m1.modBaseSize; 167 | result.szModule = m1.szModule; 168 | result.th32ProcessID = m1.th32ProcessID; 169 | } 170 | 171 | 172 | 173 | public static bool Module32Next(IntPtr hSnapshot, ref MODULEENTRY32 lpme) 174 | { 175 | return Module32First(hSnapshot, ref lpme); 176 | } 177 | 178 | public static bool CloseHandle(IntPtr handle) 179 | { 180 | return true; 181 | } 182 | 183 | 184 | public static IntPtr OpenProcess( 185 | ProcessAccessFlags processAccess, 186 | bool bInheritHandle, 187 | int processId) 188 | { 189 | if(processList == null) 190 | { 191 | processList = PS4APIWrapper.GetProcessList(); 192 | } 193 | int i = 0; 194 | foreach(Process process in processList.processes) 195 | { 196 | if (process.pid.Equals(processId)) 197 | { 198 | i++; 199 | PS4APIWrapper.ProcessID = processId; 200 | MemoryAPI.intit(processId); 201 | return (IntPtr)i; 202 | } 203 | } 204 | 205 | return (IntPtr)0; 206 | } 207 | 208 | private static void processEntry(Process process,ref PROCESSENTRY32 p32Entry) 209 | { 210 | p32Entry.th32ProcessID = Convert.ToUInt32(process.pid); 211 | p32Entry.szExeFile = process.name; 212 | 213 | } 214 | 215 | 216 | 217 | public static void InitModuleList(ProcessMap pm) 218 | { 219 | moduleEntries.Clear(); 220 | moduleIndex = 0; 221 | 222 | for (int i = 0; i < pm.entries.Length; i++) 223 | { 224 | MemoryEntry entry = pm.entries[i]; 225 | if ((entry.prot & 0x1) == 0x1) 226 | { 227 | 228 | ulong length = entry.end - entry.start; 229 | ulong start = entry.start; 230 | string name = entry.name; 231 | int idx = 0; 232 | uint buffer_length = 1024 * 1024 * 128; 233 | 234 | //Executable section 235 | if ((entry.prot & 0x5) == 0x5) 236 | { 237 | buffer_length = Convert.ToUInt32(length); 238 | } 239 | int part = 0; 240 | while (length != 0) 241 | { 242 | uint cur_length = buffer_length; 243 | 244 | if (cur_length > length) 245 | { 246 | cur_length = Convert.ToUInt32(length); 247 | length = 0; 248 | } 249 | else 250 | { 251 | length -= cur_length; 252 | } 253 | MODULEENTRY32 m32Entry = new PS4API.ToolHelp.MODULEENTRY32(); 254 | m32Entry.modBaseAddr = start; 255 | m32Entry.GlblcntUsage = Convert.ToUInt32(part); 256 | m32Entry.modBaseSize = cur_length; 257 | m32Entry.szModule = names(entry.name,part, start); 258 | m32Entry.th32ProcessID = Convert.ToUInt32(pm.pid); 259 | part++; 260 | 261 | moduleEntries.Add(m32Entry); 262 | 263 | start += cur_length; 264 | ++idx; 265 | } 266 | } 267 | } 268 | 269 | } 270 | 271 | private static string names(string name, int part,ulong bs) 272 | { 273 | if (string.IsNullOrEmpty(name)) 274 | { 275 | return string.Join("-",part ,bs.ToString("X")); 276 | } 277 | return name; 278 | } 279 | } 280 | } 281 | -------------------------------------------------------------------------------- /CEServerPS4/PS4CEServerWindows.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace CEServerPS4 2 | { 3 | partial class PS4CEServerWindows 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | if (cheatEngineServer != null) 22 | { 23 | cheatEngineServer.Dispose(); 24 | } 25 | 26 | } 27 | 28 | #region Windows Form Designer generated code 29 | 30 | /// 31 | /// Required method for Designer support - do not modify 32 | /// the contents of this method with the code editor. 33 | /// 34 | private void InitializeComponent() 35 | { 36 | this.label1 = new System.Windows.Forms.Label(); 37 | this.label2 = new System.Windows.Forms.Label(); 38 | this.label3 = new System.Windows.Forms.Label(); 39 | this.IPTextBox = new System.Windows.Forms.TextBox(); 40 | this.ConnectBtn = new System.Windows.Forms.Button(); 41 | this.CustomCEToggle = new CEServerPS4.RJToggleButton(); 42 | this.SuspendLayout(); 43 | // 44 | // label1 45 | // 46 | this.label1.AutoSize = true; 47 | this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 48 | this.label1.ForeColor = System.Drawing.Color.MidnightBlue; 49 | this.label1.Location = new System.Drawing.Point(91, 63); 50 | this.label1.Name = "label1"; 51 | this.label1.Size = new System.Drawing.Size(153, 20); 52 | this.label1.TabIndex = 2; 53 | this.label1.Text = "CustonCheatEngine"; 54 | // 55 | // label2 56 | // 57 | this.label2.AutoSize = true; 58 | this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 59 | this.label2.ForeColor = System.Drawing.SystemColors.MenuHighlight; 60 | this.label2.ImageAlign = System.Drawing.ContentAlignment.BottomLeft; 61 | this.label2.Location = new System.Drawing.Point(12, 141); 62 | this.label2.Name = "label2"; 63 | this.label2.Size = new System.Drawing.Size(423, 16); 64 | this.label2.TabIndex = 3; 65 | this.label2.Text = "Custome Cheat Engine Means it is build additional support for Ps4 Port"; 66 | // 67 | // label3 68 | // 69 | this.label3.AutoSize = true; 70 | this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 71 | this.label3.ForeColor = System.Drawing.Color.DarkGreen; 72 | this.label3.Location = new System.Drawing.Point(37, 31); 73 | this.label3.Name = "label3"; 74 | this.label3.Size = new System.Drawing.Size(48, 16); 75 | this.label3.TabIndex = 4; 76 | this.label3.Text = "PS4 IP"; 77 | // 78 | // IPTextBox 79 | // 80 | this.IPTextBox.Location = new System.Drawing.Point(95, 30); 81 | this.IPTextBox.Name = "IPTextBox"; 82 | this.IPTextBox.Size = new System.Drawing.Size(157, 20); 83 | this.IPTextBox.TabIndex = 5; 84 | // 85 | // ConnectBtn 86 | // 87 | this.ConnectBtn.ForeColor = System.Drawing.Color.Indigo; 88 | this.ConnectBtn.Location = new System.Drawing.Point(278, 31); 89 | this.ConnectBtn.Name = "ConnectBtn"; 90 | this.ConnectBtn.Size = new System.Drawing.Size(146, 23); 91 | this.ConnectBtn.TabIndex = 6; 92 | this.ConnectBtn.Text = "Connect"; 93 | this.ConnectBtn.UseVisualStyleBackColor = true; 94 | this.ConnectBtn.Click += new System.EventHandler(this.button1_Click); 95 | // 96 | // CustomCEToggle 97 | // 98 | this.CustomCEToggle.AutoSize = true; 99 | this.CustomCEToggle.Location = new System.Drawing.Point(40, 61); 100 | this.CustomCEToggle.MinimumSize = new System.Drawing.Size(45, 22); 101 | this.CustomCEToggle.Name = "CustomCEToggle"; 102 | this.CustomCEToggle.OffBackColor = System.Drawing.Color.Gray; 103 | this.CustomCEToggle.OffToggleColor = System.Drawing.Color.Gainsboro; 104 | this.CustomCEToggle.OnBackColor = System.Drawing.Color.MediumSlateBlue; 105 | this.CustomCEToggle.OnToggleColor = System.Drawing.Color.WhiteSmoke; 106 | this.CustomCEToggle.Size = new System.Drawing.Size(45, 22); 107 | this.CustomCEToggle.TabIndex = 1; 108 | this.CustomCEToggle.UseVisualStyleBackColor = true; 109 | this.CustomCEToggle.CheckedChanged += new System.EventHandler(this.CustomCEToggle_CheckedChanged); 110 | // 111 | // PS4CEServerWindows 112 | // 113 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 114 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 115 | this.ClientSize = new System.Drawing.Size(563, 166); 116 | this.Controls.Add(this.ConnectBtn); 117 | this.Controls.Add(this.IPTextBox); 118 | this.Controls.Add(this.label3); 119 | this.Controls.Add(this.label2); 120 | this.Controls.Add(this.label1); 121 | this.Controls.Add(this.CustomCEToggle); 122 | this.MaximizeBox = false; 123 | this.Name = "PS4CEServerWindows"; 124 | this.Text = "PS4CEServerWindows"; 125 | this.ResumeLayout(false); 126 | this.PerformLayout(); 127 | 128 | } 129 | 130 | #endregion 131 | 132 | private RJToggleButton CustomCEToggle; 133 | private System.Windows.Forms.Label label1; 134 | private System.Windows.Forms.Label label2; 135 | private System.Windows.Forms.Label label3; 136 | private System.Windows.Forms.TextBox IPTextBox; 137 | public System.Windows.Forms.Button ConnectBtn; 138 | } 139 | } -------------------------------------------------------------------------------- /CEServerPS4/PS4CEServerWindows.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Diagnostics; 6 | using System.Drawing; 7 | using System.Linq; 8 | using System.Runtime.InteropServices; 9 | using System.Text; 10 | using System.Threading; 11 | using System.Threading.Tasks; 12 | using System.Windows.Forms; 13 | 14 | namespace CEServerPS4 15 | { 16 | public partial class PS4CEServerWindows : Form 17 | { 18 | ConnectType isConnected; 19 | 20 | CheatEngineServer cheatEngineServer; 21 | 22 | delegate void SetConnectedCallback(); 23 | 24 | [DllImport("kernel32")] 25 | private static extern long WritePrivateProfileString(string section, 26 | string key, string val, string filePath); 27 | [DllImport("kernel32")] 28 | private static extern int GetPrivateProfileString(string section, 29 | string key, string def, StringBuilder retVal, 30 | int size, string filePath); 31 | 32 | string path = "ps4.ini"; 33 | string section = "Connection"; 34 | string ipkey = "PS4IP"; 35 | 36 | public PS4CEServerWindows() 37 | { 38 | InitializeComponent(); 39 | string ip = readip(); 40 | this.IPTextBox.Text = ip; 41 | } 42 | 43 | private void CustomCEToggle_CheckedChanged(object sender, EventArgs e) 44 | { 45 | RJToggleButton but = (RJToggleButton)sender; 46 | if (but.Checked) 47 | { 48 | CheatEngineConstants.isCustomCheatEngine = true; 49 | } 50 | else 51 | { 52 | CheatEngineConstants.isCustomCheatEngine = false; 53 | } 54 | 55 | } 56 | 57 | private void button1_Click(object sender, EventArgs e) 58 | { 59 | 60 | string ip = this.IPTextBox.Text; 61 | writeip(ip); 62 | 63 | if (!ConnectType.SUCCESS.Equals(isConnected)) 64 | { 65 | try 66 | { 67 | isConnected = ConnectType.INIT; 68 | cheatEngineServer = new CheatEngineServer(ip); 69 | Thread nthread = new Thread(Start); 70 | nthread.Start(cheatEngineServer); 71 | Thread isconnectedThread = new Thread(SetConnected); 72 | isconnectedThread.Start(); 73 | 74 | } 75 | catch (Exception) 76 | { 77 | isConnected = ConnectType.FAILED; 78 | MessageBox.Show("Please Check If you are loaded Payload or Ps4 Properly"); 79 | } 80 | } 81 | else 82 | { 83 | MessageBox.Show("PS4 is Connected Already"); 84 | } 85 | } 86 | 87 | private void Start(object cheatEngineServer) 88 | { 89 | try 90 | { 91 | ((CheatEngineServer)cheatEngineServer).StartAsync().Wait(); 92 | } 93 | catch (Exception e) 94 | { 95 | if (!ConnectType.SUCCESS.Equals(isConnected)) 96 | { 97 | Trace.WriteLine("Error While Creating Tcp Client"); 98 | Trace.WriteLine(e); 99 | } 100 | } 101 | 102 | } 103 | 104 | public void SetConnected( ) 105 | { 106 | string text; 107 | while (true) 108 | { 109 | if (ConnectType.SUCCESS.Equals(CheatEngineServer.isConnected)) 110 | { 111 | isConnected = ConnectType.SUCCESS; 112 | text = "Connected"; 113 | break; 114 | } 115 | else if (ConnectType.FAILED.Equals(CheatEngineServer.isConnected)) 116 | { 117 | isConnected = ConnectType.FAILED; 118 | text = "Connect"; 119 | break; 120 | } 121 | } 122 | if (this.ConnectBtn.InvokeRequired) 123 | { 124 | SetConnectedCallback d = new SetConnectedCallback(SetConnected); 125 | this.ConnectBtn.Invoke(d); 126 | } 127 | else 128 | { 129 | this.ConnectBtn.Text = text; 130 | } 131 | } 132 | 133 | string readip() 134 | { 135 | try 136 | { 137 | StringBuilder ip = new StringBuilder(255); 138 | GetPrivateProfileString(section, ipkey, "", ip, 255, this.path); 139 | return ip.ToString(); 140 | 141 | } 142 | catch 143 | { 144 | return ""; 145 | } 146 | 147 | } 148 | 149 | void writeip(string ip) 150 | { 151 | try 152 | { 153 | WritePrivateProfileString(section, ipkey, ip, this.path); 154 | } 155 | catch 156 | { 157 | Trace.WriteLine("failed reading ini file"); 158 | } 159 | 160 | } 161 | 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /CEServerPS4/PS4CEServerWindows.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /CEServerPS4/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | using libdebug; 8 | using CEServerPS4.PS4API; 9 | using System.Windows.Forms; 10 | 11 | namespace CEServerPS4 12 | { 13 | class Program 14 | { 15 | 16 | static int pid; 17 | static Thread t; 18 | static uint tid=0; 19 | 20 | static void Main(string[] args) 21 | { 22 | Application.EnableVisualStyles(); 23 | Application.SetCompatibleTextRenderingDefault(false); 24 | Application.Run(new PS4CEServerWindows()); 25 | //if (!(args.Length > 0)) 26 | //{ 27 | // Console.WriteLine("use CEServerPS4 "); 28 | // Console.WriteLine("Example CEServerPS4 197.168.137.2"); 29 | // return; 30 | //} 31 | 32 | //Start(args[0]); 33 | 34 | } 35 | 36 | 37 | public static void Start(string ip) 38 | { 39 | CheatEngineConstants.isCustomCheatEngine = false; 40 | CheatEngineServer cheatEngine = new CheatEngineServer(ip); 41 | cheatEngine.StartAsync().Wait(); 42 | } 43 | 44 | // public static void Start(string ip) 45 | //{ 46 | // CheatEngineServer cheatEngine = new CheatEngineServer(ip); 47 | // PS4DBG ps4 = new PS4DBG(ip); 48 | // //ps4.Connect(); 49 | 50 | // ProcessList list = PS4APIWrapper.GetProcessList(); 51 | // //cheatEngine.StartAsync().Wait(); 52 | 53 | // //cheatEngine.StartAsync().Wait(); 54 | // foreach (Process p in list.processes) 55 | // { 56 | // if (p.name.Contains("eboot")) 57 | // { 58 | // pid = p.pid; 59 | // PS4APIWrapper.ProcessID = pid; 60 | // break; 61 | // } 62 | // } 63 | 64 | // Thread.Sleep(100); 65 | 66 | // //while (true) 67 | // //{ 68 | // try 69 | // { 70 | // //ps4.AttachDebugger(pid,DebuggerInterruptCallback); 71 | // // ps4.ProcessResume(); 72 | // DebugAPI.StartDebug((IntPtr)0); 73 | // ps4 = PS4DedugAPIWrapper.getps4(); 74 | // //uint tid = PS4APIWrapper.GetThreadsList()[0]; 75 | // //Console.WriteLine(tid); 76 | // //DebugAPI.GetThreadContext((IntPtr)0, tid, out PS4API.DebugAPI.CONTEXT Context, 1); 77 | // //ulong add = Context.regs.rip; 78 | // //Console.WriteLine("Address:" + add); 79 | // // DebugAPI.SetBreakpoint((IntPtr)0, -1, (IntPtr)0, 2150544583, 0, 1);2437280967 80 | // //DebugAPI.SetBreakpoint((IntPtr)0, -1, (IntPtr)0, 2150544583, 0, 1); 81 | // ps4.ChangeBreakpoint(0, true, 2150544583); 82 | // // ps4.ChangeWatchpoint(0, true, PS4DBG.WATCHPT_LENGTH.DBREG_DR7_LEN_1, PS4DBG.WATCHPT_BREAKTYPE.DBREG_DR7_WRONLY, 13018470472); 83 | // // ps4.ChangeWatchpoint(0, true, PS4DBG.WATCHPT_LENGTH.DBREG_DR7_LEN_1, PS4DBG.WATCHPT_BREAKTYPE.DBREG_DR7_WRONLY, 13018470472); 84 | // object ev; 85 | // DebugAPI.WaitForDebugEvent((IntPtr)0, 0, out ev); 86 | // DebugAPI.WaitForDebugEvent((IntPtr)0, 0, out ev); 87 | // //ps4.ChangeBreakpoint(0, true, 4375540935); 88 | // Console.WriteLine("break"); 89 | // tid = DebugAPI.getThd(); 90 | // //while (tid == 0) 91 | // //{ 92 | // // Console.WriteLine("wait"); 93 | // //} 94 | // // tid = DebugAPI.getThd(); 95 | // for (int i = 0; i < 4; i++) 96 | // { 97 | // // DebugAPI.ContinueForDebugEvent((IntPtr)0, tid, 2); 98 | // // PS4DedugAPIWrapper.ContinueBreakpointThread(0, true); 99 | // // PS4DedugAPIWrapper.getps4().SingleStep(); 100 | // ps4.SingleStep(); 101 | // } 102 | // ps4.ProcessResume(); 103 | // // DebugAPI.ContinueForDebugEvent((IntPtr)0, tid, 0); 104 | // // PS4DedugAPIWrapper.ContinueBreakpointThread(0, false); 105 | // // DebugAPI.RemoveBreakpoint((IntPtr)0, -1, (IntPtr)0, 0); 106 | // // ps4.ChangeWatchpoint(0, false, PS4DBG.WATCHPT_LENGTH.DBREG_DR7_LEN_1, PS4DBG.WATCHPT_BREAKTYPE.DBREG_DR7_WRONLY, 13018470472); 107 | // // DebugAPI.ContinueForDebugEvent((IntPtr)0, tid, 0); 108 | // //PS4DedugAPIWrapper.ContinueBreakpointThread(0, false); 109 | // Thread.Sleep(10); 110 | // } 111 | // catch (Exception e) 112 | // { 113 | // Console.WriteLine("error:" + e.Message); 114 | // //break; 115 | // } 116 | // finally 117 | // { 118 | // PS4DedugAPIWrapper.dettachDebugger(); 119 | // //ps4.DetachDebugger(); 120 | // //ps4.Disconnect(); 121 | // } 122 | // //} 123 | //} 124 | 125 | 126 | //public static void rbuffer(object address) 127 | //{ 128 | 129 | // while (true) 130 | // { 131 | // try 132 | // { 133 | // byte[] bs = PS4APIWrapper.ReadMemory((ulong)address, 20); 134 | // Console.WriteLine("String" + Encoding.UTF8.GetString(bs)); 135 | // }catch(Exception e) 136 | // { 137 | // Console.WriteLine("error:" + e.Message); 138 | // break; 139 | // } 140 | 141 | // } 142 | 143 | //} 144 | 145 | //public static void DebuggerInterruptCallback( 146 | // uint lwpid, 147 | // uint status, 148 | // string tdname, 149 | // regs regs, 150 | // fpregs fpregs, 151 | // dbregs dbregs) 152 | //{ 153 | 154 | // tid = lwpid; 155 | // Console.WriteLine("address=:" + regs.r_rip); 156 | // Console.WriteLine("thread=:" + lwpid); 157 | // Console.WriteLine("breakaddress=:" + dbregs.dr0); 158 | 159 | //} 160 | 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /CEServerPS4/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("CEServerPS4")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("CEServerPS4")] 13 | [assembly: AssemblyCopyright("Copyright © 2022")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("91218bb6-df7e-406c-8cc2-efd5fff732ec")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /CEServerPS4/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace CEServerPS4.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CEServerPS4.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /CEServerPS4/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | text/microsoft-resx 91 | 92 | 93 | 1.3 94 | 95 | 96 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 97 | 98 | 99 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 100 | 101 | -------------------------------------------------------------------------------- /CEServerPS4/RJToggleButton.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | using System.Windows.Forms; 8 | using System.Drawing; 9 | using System.Drawing.Drawing2D; 10 | using System.ComponentModel; 11 | 12 | namespace CEServerPS4 13 | { 14 | public class RJToggleButton : CheckBox 15 | { 16 | //Fields 17 | private Color onBackColor = Color.MediumSlateBlue; 18 | private Color onToggleColor = Color.WhiteSmoke; 19 | private Color offBackColor = Color.Gray; 20 | private Color offToggleColor = Color.Gainsboro; 21 | private bool solidStyle = true; 22 | 23 | //Properties 24 | [Category("RJ Code Advance")] 25 | public Color OnBackColor 26 | { 27 | get 28 | { 29 | return onBackColor; 30 | } 31 | 32 | set 33 | { 34 | onBackColor = value; 35 | this.Invalidate(); 36 | } 37 | } 38 | 39 | [Category("RJ Code Advance")] 40 | public Color OnToggleColor 41 | { 42 | get 43 | { 44 | return onToggleColor; 45 | } 46 | 47 | set 48 | { 49 | onToggleColor = value; 50 | this.Invalidate(); 51 | } 52 | } 53 | 54 | [Category("RJ Code Advance")] 55 | public Color OffBackColor 56 | { 57 | get 58 | { 59 | return offBackColor; 60 | } 61 | 62 | set 63 | { 64 | offBackColor = value; 65 | this.Invalidate(); 66 | } 67 | } 68 | 69 | [Category("RJ Code Advance")] 70 | public Color OffToggleColor 71 | { 72 | get 73 | { 74 | return offToggleColor; 75 | } 76 | 77 | set 78 | { 79 | offToggleColor = value; 80 | this.Invalidate(); 81 | } 82 | } 83 | 84 | [Browsable(false)] 85 | public override string Text 86 | { 87 | get 88 | { 89 | return base.Text; 90 | } 91 | 92 | set 93 | { 94 | 95 | } 96 | } 97 | 98 | [Category("RJ Code Advance")] 99 | [DefaultValue(true)] 100 | public bool SolidStyle 101 | { 102 | get 103 | { 104 | return solidStyle; 105 | } 106 | 107 | set 108 | { 109 | solidStyle = value; 110 | this.Invalidate(); 111 | } 112 | } 113 | 114 | //Constructor 115 | public RJToggleButton() 116 | { 117 | this.MinimumSize = new Size(45, 22); 118 | } 119 | 120 | //Methods 121 | private GraphicsPath GetFigurePath() 122 | { 123 | int arcSize = this.Height - 1; 124 | Rectangle leftArc = new Rectangle(0, 0, arcSize, arcSize); 125 | Rectangle rightArc = new Rectangle(this.Width - arcSize - 2, 0, arcSize, arcSize); 126 | 127 | GraphicsPath path = new GraphicsPath(); 128 | path.StartFigure(); 129 | path.AddArc(leftArc, 90, 180); 130 | path.AddArc(rightArc, 270, 180); 131 | path.CloseFigure(); 132 | 133 | return path; 134 | } 135 | 136 | protected override void OnPaint(PaintEventArgs pevent) 137 | { 138 | int toggleSize = this.Height - 5; 139 | pevent.Graphics.SmoothingMode = SmoothingMode.AntiAlias; 140 | pevent.Graphics.Clear(this.Parent.BackColor); 141 | 142 | if (this.Checked) //ON 143 | { 144 | //Draw the control surface 145 | if (solidStyle) 146 | pevent.Graphics.FillPath(new SolidBrush(onBackColor), GetFigurePath()); 147 | else pevent.Graphics.DrawPath(new Pen(onBackColor, 2), GetFigurePath()); 148 | //Draw the toggle 149 | pevent.Graphics.FillEllipse(new SolidBrush(onToggleColor), 150 | new Rectangle(this.Width - this.Height + 1, 2, toggleSize, toggleSize)); 151 | } 152 | else //OFF 153 | { 154 | //Draw the control surface 155 | if (solidStyle) 156 | pevent.Graphics.FillPath(new SolidBrush(offBackColor), GetFigurePath()); 157 | else pevent.Graphics.DrawPath(new Pen(offBackColor, 2), GetFigurePath()); 158 | //Draw the toggle 159 | pevent.Graphics.FillEllipse(new SolidBrush(offToggleColor), 160 | new Rectangle(2, 2, toggleSize, toggleSize)); 161 | } 162 | } 163 | } 164 | } -------------------------------------------------------------------------------- /CEServerPS4/lib/libdebug.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hemanthl7/cheat-engine-ps4-server/9ea0c03e29f46cd1422abe694178d9c3cbce1bc8/CEServerPS4/lib/libdebug.dll -------------------------------------------------------------------------------- /CEServerPS4/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Cheat engine windows server 3 | First of All, 4 | A Big Thanks to CTN for Sharing Libdebug source code and ps4debug payload without it would not be possible. 5 | 6 | I am Grateful to these Cheat Engine team, Developers and Testers: 7 | - [@CTN](https://github.com/ctn123) 8 | - [@Shiningami](https://ko-fi.com/shiningami) 9 | - [@Rizla](https://github.com/Dankzy) 10 | - [@GrimDoe](https://twitter.com/GrimDoe) 11 | - [@Dark Byte](https://cheatengine.org/) 12 | - jogolden and Ps4 supporters 13 | 14 | A port of the linux/android cheat engine server to Windows utilizing C# ported from the [official Cheat Engine repositotry](https://github.com/cheat-engine/cheat-engine/tree/a2d035583c35c0cb2455bd9aef771efbba1570c3/Cheat%20Engine/ceserver). 15 | The initial reason this project was created was to 'bypass' some applications that block Cheat Engine when running in the same machine or just refuse to run when Cheat Engine is running as well. With this you can run Cheat Engine in a separate environment and connect to the target machine. 16 | 17 | # Example usage 18 | If you just want to run the server as is there is a console project named **CEServerApplicaiton** that takes advantage of the generated library which is an assembly with the following code: 19 | ```csharp 20 | CheatEngineServer server = new CheatEngineServer(); 21 | server.StartAsync().Wait(); 22 | ``` 23 | If you just want to run the server as is there is a console application named CEServerPS4.exe: 24 | ```cmd 25 | CEServerPS4.exe 192.168.137.2 26 | ``` 27 | 28 | If you wish to handle a specific command from cheat engine differently or register a new one you can do this by either extending one of the defined Commands in **CEServerWindows.CheatEnginePackets.S2C** or by implementing the **ICheatEngineResponse** interface although it is recommended to extend the base class **CheatEngineCommand** 29 | 30 | For example you could override the **Process** method of **ReadProcessorMemoryCommand** to utilize a different way of reading the memory of the target process such as communication with a kernel module/driver. 31 | 32 | # What doesn't work 33 | Even though the official cheat engine server 'ports' a few of Windows API calls some code is specific to linux and are not easily brought back to windows 34 | * **Compression**: The current implementation of the command **ReadProcessMemory** does not implement compression, this is disabled by default in Cheat Engine (Network >> Compression) 35 | * **Debug symbols**: Symbols are not loaded as we believe that cheat engine expects debug symbols for elf binaries 36 | * **Speed hack**: Not implemented 37 | * **Alloc/Free**: Not implemented 38 | * **Aob injection**:Not Implemented 39 | -------------------------------------------------------------------------------- /libdebug.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hemanthl7/cheat-engine-ps4-server/9ea0c03e29f46cd1422abe694178d9c3cbce1bc8/libdebug.dll --------------------------------------------------------------------------------