@@ -61,16 +61,18 @@ public ulong AllocateMemory(int pid, int length) {
61
61
public ulong Call ( int pid , ulong rpcstub , ulong address , params object [ ] args ) {
62
62
CheckConnected ( ) ; // Check if the connection is active
63
63
64
- // Create a custom format packet
65
- CMDPacket packet = new CMDPacket {
66
- magic = CMD_PACKET_MAGIC ,
67
- cmd = ( uint ) CMDS . CMD_PROC_CALL ,
68
- datalen = ( uint ) CMD_PROC_CALL_PACKET_SIZE
69
- } ;
70
- SendData ( GetBytesFromObject ( packet ) , CMD_PACKET_SIZE ) ; // Send the packet
71
-
72
- MemoryStream rs = new MemoryStream ( ) ; // Create a memory stream to store the arguments
73
- rs . Write ( BitConverter . GetBytes ( pid ) , 0 , sizeof ( int ) ) ; // Write PID to the stream
64
+ // Build a new CMD (Command) Packet that will be sent to the PS4 System
65
+ CMDPacket packet = new CMDPacket ( ) ;
66
+ packet . magic = CMD_PACKET_MAGIC ;
67
+ packet . cmd = ( uint ) CMDS . CMD_PROC_CALL ;
68
+ packet . datalen = ( uint ) CMD_PROC_CALL_PACKET_SIZE ;
69
+
70
+ // Send the packet to the PS4 System
71
+ SendData ( GetBytesFromObject ( packet ) , CMD_PACKET_SIZE ) ;
72
+
73
+ // Create a memory stream to store the arguments
74
+ MemoryStream rs = new MemoryStream ( ) ;
75
+ rs . Write ( BitConverter . GetBytes ( pid ) , 0 , sizeof ( int ) ) ; // Write PID to the stream
74
76
rs . Write ( BitConverter . GetBytes ( rpcstub ) , 0 , sizeof ( ulong ) ) ; // Write RPC stub to the stream
75
77
rs . Write ( BitConverter . GetBytes ( address ) , 0 , sizeof ( ulong ) ) ; // Write address to the stream
76
78
@@ -149,7 +151,12 @@ public ulong Call(int pid, ulong rpcstub, ulong address, params object[] args) {
149
151
}
150
152
151
153
// Check the number of arguments
152
- if ( num > 6 ) throw new Exception ( "libdebug: too many arguments" ) ;
154
+ if ( num > 6 ) {
155
+ // cleanup memory stream
156
+ rs . Dispose ( ) ;
157
+ // throw the exception
158
+ throw new Exception ( $ "libdebug: too many arguments! max 6, current is { num } ") ;
159
+ }
153
160
154
161
// If there are less than 6 arguments, pad the remaining slots with zeros
155
162
if ( num < 6 ) {
@@ -158,16 +165,17 @@ public ulong Call(int pid, ulong rpcstub, ulong address, params object[] args) {
158
165
}
159
166
}
160
167
161
- // Send the data
168
+ // Now send the memory stream to our PS4 System
162
169
SendData ( rs . ToArray ( ) , CMD_PROC_CALL_PACKET_SIZE ) ;
163
- rs . Dispose ( ) ; // Dispose of the memory stream
170
+
171
+ // Perform some cleanup
172
+ rs . Dispose ( ) ;
164
173
165
174
// Check the status
166
175
CheckStatus ( ) ;
167
176
168
177
// Receive and return the result
169
- byte [ ] data = ReceiveData ( PROC_CALL_SIZE ) ;
170
- return BitConverter . ToUInt64 ( data , 4 ) ;
178
+ return BitConverter . ToUInt64 ( ReceiveData ( PROC_CALL_SIZE ) , 4 ) ;
171
179
}
172
180
173
181
/// <summary>
@@ -347,6 +355,7 @@ public T ReadMemory<T>(int pid, ulong address) {
347
355
348
356
while ( true ) {
349
357
byte value = ReadMemory ( pid , address + i , sizeof ( byte ) ) [ 0 ] ;
358
+
350
359
if ( value == 0 ) {
351
360
break ;
352
361
}
0 commit comments