Skip to content

Commit be0a561

Browse files
committed
CCAPI support implemented.
1 parent 49f8566 commit be0a561

File tree

1 file changed

+102
-11
lines changed

1 file changed

+102
-11
lines changed

ps3api/ccapi.py

Lines changed: 102 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def __init__(self):
142142
'''
143143
self.CCAPISetMemory = self.CCAPI_DLL.CCAPISetMemory
144144
self.CCAPISetMemory.argtypes = [ c_uint32, c_uint64, c_uint32, POINTER(c_char) ]
145-
self.CCAPISetMemory.restype = CCAPIError
145+
self.CCAPISetMemory.restype = c_ulong
146146

147147
'''
148148
int CCAPIGetMemory(u32 pid, u64 address, u32 size, void* data);
@@ -151,7 +151,7 @@ def __init__(self):
151151
'''
152152
self.CCAPIGetMemory = self.CCAPI_DLL.CCAPIGetMemory
153153
self.CCAPIGetMemory.argtypes = [ c_uint32, c_uint64, c_uint32, POINTER(c_char) ]
154-
self.CCAPIGetMemory.restype = CCAPIError
154+
self.CCAPIGetMemory.restype = c_ulong
155155

156156
'''
157157
int CCAPIGetProcessList(u32* npid, u32* pids);
@@ -160,7 +160,7 @@ def __init__(self):
160160
'''
161161
self.CCAPIGetProcessList = self.CCAPI_DLL.CCAPIGetProcessList
162162
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
164164

165165
'''
166166
int CCAPIGetProcessName(u32 pid, ProcessName* name);
@@ -263,19 +263,110 @@ def __init__(self):
263263

264264
class CCAPI:
265265
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()
267273

268274
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)
270319

271-
def ConnectTarget(self, TargetIndex):
272-
raise Exception("CCAPI Not Implemented!!")
320+
return self.ConnectTargetWithIP(IP)
273321

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
276361

277362
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)
279368

280369
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

Comments
 (0)