Skip to content

Commit 235c3c8

Browse files
author
oopo
committed
Support for arguments with execee and execiop.
1 parent c0523b9 commit 235c3c8

File tree

5 files changed

+43
-24
lines changed

5 files changed

+43
-24
lines changed

doc/ps2link-protocol.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161

6262
command.number = htonl(0xBABE0202);
6363
command.length = htons(sizeof(command));
64-
command.argc = htonl(1);
65-
if (pathname) { strncpy(command.argv, argv, 256); }
64+
command.argc = htonl(argc);
65+
if (argv) { memcpy(command.argv, argv, 256); }
6666

6767
-----------------------------
6868
0xBABE0203 (execee command)
@@ -78,8 +78,8 @@
7878

7979
command.number = htonl(0xBABE0203);
8080
command.length = htons(sizeof(command));
81-
command.argc = htonl(1);
82-
if (pathname) { strncpy(command.argv, pathname, 256); }
81+
command.argc = htonl(argc);
82+
if (argv) { memcpy(command.argv, argv, 256); }
8383

8484
-------------------------------
8585
0xBABE0204 (poweroff command)
@@ -113,7 +113,7 @@
113113
command.length = htons(sizeof(command));
114114
command.offset = htonl(offset);
115115
command.size = htonl(size);
116-
if (argv) { strncpy(command.pathname, pathname, 256); }
116+
if (pathname) { strncpy(command.pathname, pathname, 256); }
117117

118118
------------------------------
119119
0xBABE0208 (startvu command)

doc/readme.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
Commands for ps2link:
6060

6161
reset
62-
execiop <filename>
63-
execee <filename>
62+
execiop <filename> [arguments]
63+
execee <filename> [arguments]
6464
poweroff
6565
dumpmem <filename> <offset> <size>
6666
startvu <vu>

src/ps2client.c

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "ps2netfs.h"
88
#include "ps2client.h"
99

10-
char hostname[256], command[256];
10+
char hostname[256], command[256], argvalues[256]; int argcount = 0;
1111

1212
char arg0[256], arg1[256], arg2[256], arg3[256];
1313

@@ -17,7 +17,10 @@
1717
// PS2CLIENT MAIN FUNCTIONS //
1818
//////////////////////////////
1919

20-
int main(int argc, char *argv[], char *env[]) { int loop0, count = 1; setbuf(stdout, NULL);
20+
int main(int argc, char *argv[], char *env[]) { int loop0, count = 1; char *temp = argvalues;
21+
22+
// Turn off stdout buffering.
23+
setbuf(stdout, NULL);
2124

2225
// First, we parse the optional arguments.
2326
for(loop0=0;loop0<argc;loop0++) {
@@ -41,8 +44,24 @@
4144

4245
}
4346

44-
// Next, the command and its arguments.
47+
// Next, determine the command.
4548
if (argc > count) { strncpy(command, argv[count++], sizeof(command)); } else { sprintf(command, "NULL"); }
49+
50+
// Get the arguments for execee/execiop.
51+
if (argc > count) {
52+
53+
// Clear the argvalues for use.
54+
memset(argvalues, 0, sizeof(argvalues));
55+
56+
// Copy over each argument.
57+
for(loop0=count;loop0<argc;loop0++) { strcpy(temp, argv[loop0]); temp += strlen(argv[loop0]) + 1; }
58+
59+
// Set the argcount.
60+
argcount = argc - count;
61+
62+
}
63+
64+
// Get the arguments for the other commands.
4665
if (argc > count) { strncpy(arg0, argv[count++], sizeof(arg0)); } else { sprintf(arg0, "NULL"); }
4766
if (argc > count) { strncpy(arg1, argv[count++], sizeof(arg1)); } else { sprintf(arg1, "NULL"); }
4867
if (argc > count) { strncpy(arg2, argv[count++], sizeof(arg2)); } else { sprintf(arg2, "NULL"); }
@@ -58,8 +77,8 @@
5877

5978
// Peform any ps2link commands.
6079
if (strcmp(command, "reset") == 0) { return ps2link_command_reset (hostname); }
61-
if (strcmp(command, "execiop") == 0) { return ps2link_command_execiop (hostname, timeout, arg0); }
62-
if (strcmp(command, "execee") == 0) { return ps2link_command_execee (hostname, timeout, arg0); }
80+
if (strcmp(command, "execiop") == 0) { return ps2link_command_execiop (hostname, timeout, argcount, argvalues); }
81+
if (strcmp(command, "execee") == 0) { return ps2link_command_execee (hostname, timeout, argcount, argvalues); }
6382
if (strcmp(command, "poweroff") == 0) { return ps2link_command_poweroff (hostname); }
6483
if (strcmp(command, "dumpmem") == 0) { return ps2link_command_dumpmem (hostname, timeout, arg0, atoi(arg1), atoi(arg2)); }
6584
if (strcmp(command, "startvu") == 0) { return ps2link_command_startvu (hostname, atoi(arg0)); }
@@ -106,8 +125,8 @@
106125
// Output the ps2link commands.
107126
printf(" Commands for ps2link:\n\n");
108127
printf(" reset\n");
109-
printf(" execiop <filename>\n");
110-
printf(" execee <filename>\n");
128+
printf(" execiop <filename> [arguments]\n");
129+
printf(" execee <filename> [arguments]\n");
111130
printf(" poweroff\n");
112131
printf(" dumpmem <filename> <offset> <size>\n");
113132
printf(" startvu <vu>\n");

src/ps2link.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,21 @@
163163

164164
}
165165

166-
int ps2link_command_execiop(char *hostname, int timeout, char *pathname) {
166+
int ps2link_command_execiop(char *hostname, int timeout, int argc, char *argv) {
167167
struct { int number; short length; int argc; char argv[256]; } __attribute__((packed)) command;
168168

169169
#ifndef __QUIET__
170170

171171
// Tell the user what we're doing.
172-
printf("[***] Sending execiop(\"%s\") command...\n", pathname);
172+
printf("[***] Sending execiop(%d, \"%s\") command...\n", argc, argv);
173173

174174
#endif
175175

176176
// Build the command packet.
177177
command.number = htonl(0xBABE0202);
178178
command.length = htons(sizeof(command));
179-
command.argc = htonl(1);
180-
if (pathname) { strncpy(command.argv, pathname, 256); }
179+
command.argc = htonl(argc);
180+
if (argv) { memcpy(command.argv, argv, 256); }
181181

182182
// Connect to the host.
183183
ps2link_connect(hostname);
@@ -196,21 +196,21 @@
196196

197197
}
198198

199-
int ps2link_command_execee(char *hostname, int timeout, char *pathname) {
199+
int ps2link_command_execee(char *hostname, int timeout, int argc, char *argv) {
200200
struct { int number; short length; int argc; char argv[256]; } __attribute__((packed)) command;
201201

202202
#ifndef __QUIET__
203203

204204
// Tell the user what we're doing.
205-
printf("[***] Sending execee(\"%s\") command...\n", pathname);
205+
printf("[***] Sending execee(%d, \"%s\") command...\n", argc, argv);
206206

207207
#endif
208208

209209
// Build the command packet.
210210
command.number = htonl(0xBABE0203);
211211
command.length = htons(sizeof(command));
212-
command.argc = htonl(1);
213-
if (pathname) { strncpy(command.argv, pathname, 256); }
212+
command.argc = htonl(argc);
213+
if (argv) { memcpy(command.argv, argv, 256); }
214214

215215
// Connect to the host.
216216
ps2link_connect(hostname);

src/ps2link.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727

2828
int ps2link_command_reset(char *hostname);
2929

30-
int ps2link_command_execiop(char *hostname, int timeout, char *pathname);
30+
int ps2link_command_execiop(char *hostname, int timeout, int argc, char *argv);
3131

32-
int ps2link_command_execee(char *hostname, int timeout, char *pathname);
32+
int ps2link_command_execee(char *hostname, int timeout, int argc, char *argv);
3333

3434
int ps2link_command_poweroff(char *hostname);
3535

0 commit comments

Comments
 (0)