@@ -142,7 +142,7 @@ def __init__(self):
142
142
'''
143
143
self .CCAPISetMemory = self .CCAPI_DLL .CCAPISetMemory
144
144
self .CCAPISetMemory .argtypes = [ c_uint32 , c_uint64 , c_uint32 , POINTER (c_char ) ]
145
- self .CCAPISetMemory .restype = CCAPIError
145
+ self .CCAPISetMemory .restype = c_ulong
146
146
147
147
'''
148
148
int CCAPIGetMemory(u32 pid, u64 address, u32 size, void* data);
@@ -151,7 +151,7 @@ def __init__(self):
151
151
'''
152
152
self .CCAPIGetMemory = self .CCAPI_DLL .CCAPIGetMemory
153
153
self .CCAPIGetMemory .argtypes = [ c_uint32 , c_uint64 , c_uint32 , POINTER (c_char ) ]
154
- self .CCAPIGetMemory .restype = CCAPIError
154
+ self .CCAPIGetMemory .restype = c_ulong
155
155
156
156
'''
157
157
int CCAPIGetProcessList(u32* npid, u32* pids);
@@ -160,7 +160,7 @@ def __init__(self):
160
160
'''
161
161
self .CCAPIGetProcessList = self .CCAPI_DLL .CCAPIGetProcessList
162
162
self .CCAPIGetProcessList .argtypes = [ POINTER (c_uint32 ), POINTER (c_uint32 ) ]
163
- self .CCAPIGetProcessList .restype = c_ulong # seems to return something else 0x80001000
163
+ self .CCAPIGetProcessList .restype = c_ulong
164
164
165
165
'''
166
166
int CCAPIGetProcessName(u32 pid, ProcessName* name);
@@ -263,19 +263,110 @@ def __init__(self):
263
263
264
264
class CCAPI :
265
265
def __init__ (self ):
266
- raise Exception ("CCAPI Not Implemented!!" )
266
+ self .NativeAPI = CCAPIExports ()
267
+ self .PS3TargetIndex = - 1
268
+ self .IsConnected = False
269
+ self .ProcessID = 0
270
+
271
+ def GetNumberOfTargets (self ):
272
+ return self .NativeAPI .CCAPIGetNumberOfConsoles ()
267
273
268
274
def GetDefaultTarget (self ):
269
- raise Exception ("CCAPI Not Implemented!!" )
275
+ NumConsoles = self .GetNumberOfTargets ()
276
+
277
+ if NumConsoles == 0 :
278
+ return None
279
+
280
+ return 0
281
+
282
+ def GetConsoleInfo (self , TargetIndex ):
283
+ NamePtr = pointer (CCAPIConsoleName ())
284
+ IPPtr = pointer (CCAPIConsoleIp ())
285
+
286
+ self .NativeAPI .CCAPIGetConsoleInfo (TargetIndex , NamePtr , IPPtr )
287
+
288
+ Name = NamePtr .contents .value
289
+ IP = IPPtr .contents .value
290
+
291
+ if Name == b"" or IP == b"" :
292
+ return (None , None )
293
+
294
+ return (Name .decode ("ascii" ), IP .decode ("ascii" ))
295
+
296
+ def ConnectTargetWithIP (self , TargetIP ):
297
+ if self .NativeAPI .CCAPIConnectConsole (bytes (TargetIP , "ascii" )) == CCAPIError .CCAPI_OK :
298
+ return True
299
+
300
+ return False
301
+
302
+ def ConnectTarget (self , TargetIndex = - 1 ):
303
+ NumConsoles = self .GetNumberOfTargets ()
304
+
305
+ if NumConsoles == 0 :
306
+ raise Exception ("No Consoles Added In CCAPI" )
307
+
308
+ TargetIndex = self .GetDefaultTarget () if TargetIndex == - 1 else TargetIndex
309
+
310
+ if TargetIndex == None :
311
+ raise Exception ("Could not find default console" )
312
+
313
+ ConsoleName , IP = self .GetConsoleInfo (TargetIndex )
314
+
315
+ if IP == None :
316
+ raise Exception ("Failed to find console info" )
317
+
318
+ print (IP )
270
319
271
- def ConnectTarget (self , TargetIndex ):
272
- raise Exception ("CCAPI Not Implemented!!" )
320
+ return self .ConnectTargetWithIP (IP )
273
321
274
- def AttachProcess (self ):
275
- raise Exception ("CCAPI Not Implemented!!" )
322
+ def GetProcessList (self ):
323
+ NumProcessPtr = pointer (c_uint32 (0 ))
324
+
325
+ if self .NativeAPI .CCAPIGetProcessList (NumProcessPtr , None ) == CCAPIError .CCAPI_ERROR :
326
+ raise Exception ("CCAPIGetProcessList() Failed" )
327
+
328
+ print (NumProcessPtr .contents .value )
329
+
330
+ ProccessIDList = (c_uint32 * NumProcessPtr .contents .value )()
331
+
332
+ if self .NativeAPI .CCAPIGetProcessList (NumProcessPtr , ProccessIDList ) == CCAPIError .CCAPI_ERROR :
333
+ raise Exception ("CCAPIGetProcessList() Failed" )
334
+
335
+ return list (ProccessIDList )
336
+
337
+ def GetProcessName (self , ProcessID ):
338
+ ProcessNamePtr = pointer (CCAPIProcessName ())
339
+
340
+ if self .NativeAPI .CCAPIGetProcessName (ProcessID , ProcessNamePtr ) == CCAPIError .CCAPI_OK :
341
+ ProcessName = ProcessNamePtr .contents .value
342
+ return ProcessName .decode ("ascii" )
343
+
344
+ return None
345
+
346
+ def AttachProcess (self , ProcessID = - 1 ):
347
+ if ProcessID == - 1 :
348
+ ProcessList = self .GetProcessList ()
349
+
350
+ for Process in ProcessList :
351
+ ProcessName = self .GetProcessName (Process )
352
+
353
+ if "dev_flash" not in ProcessName :
354
+ ProcessID = Process
355
+ break
356
+
357
+ if ProcessID == - 1 :
358
+ raise Exception ("Failed to find game process ID" )
359
+
360
+ self .ProcessID = ProcessID
276
361
277
362
def ReadMemory (self , Address , Size ):
278
- raise Exception ("CCAPI Not Implemented!!" )
363
+ MemoryBuffer = (c_char * Size )()
364
+
365
+ Error = self .NativeAPI .CCAPIGetMemory (self .ProcessID , Address , Size , MemoryBuffer )
366
+
367
+ return bytes (MemoryBuffer )
279
368
280
369
def WriteMemory (self , Address , Bytes ):
281
- raise Exception ("CCAPI Not Implemented!!" )
370
+ WriteBuffer = (c_char * len (Bytes )).from_buffer (bytearray (Bytes ))
371
+
372
+ Error = self .NativeAPI .CCAPISetMemory (self .ProcessID , Address , len (Bytes ), WriteBuffer )
0 commit comments