Browse Source

Add commands help

Yann Weber 2 weeks ago
parent
commit
a4954e43dc
3 changed files with 140 additions and 18 deletions
  1. 0
    3
      README.md
  2. 30
    1
      src/shell_cmds.c
  3. 110
    14
      src/shell_cmds.h

+ 0
- 3
README.md View File

@@ -14,9 +14,6 @@ from
14 14
 [GNU Binutils](https://www.gnu.org/software/binutils/), consequently
15 15
  instructions syntax follows GAS syntax.
16 16
  
17
-For the moment the shell can only be used in
18
-[AT&T syntax](https://sourceware.org/binutils/docs-2.40/as/i386_002dVariations.html).
19
-
20 17
 #### Assembly syntax
21 18
 
22 19
 Informations on x86 syntax can be found in

+ 30
- 1
src/shell_cmds.c View File

@@ -471,7 +471,36 @@ int asmsh_cmd_flags(asmsh_t *sh, asmsh_cmd_args_t *args)
471 471
 int asmsh_cmd_help_(asmsh_t *sh, asmsh_cmd_args_t *args)
472 472
 {
473 473
 	char buf[4096], abuf[64];
474
-	int ret;
474
+	int ret = 0;
475
+
476
+	if(*args->args)
477
+	{
478
+		for(size_t i=0; args->args[i]; i++)
479
+		{
480
+			const asmsh_cmd_t *cmd = asmsh_cmd_match(args->args[i],
481
+					strlen(args->args[i]));
482
+			if(!cmd)
483
+			{
484
+				dprintf(2, "Command '%s' not found\n", args->args[i]);
485
+				ret = 1;
486
+				continue;
487
+			}
488
+			dprintf(2, "Usage %s %s\n", cmd->str, cmd->usage);
489
+			dprintf(2, "%s\n\n", cmd->desc);
490
+			if(strlen(cmd->help))
491
+			{
492
+				dprintf(2, "%s\n", cmd->help);
493
+			}
494
+			if(!strcmp(cmd->str, ".help"))
495
+			{
496
+				ret=1;
497
+			}
498
+		}
499
+		if(!ret)
500
+		{
501
+			return 0;
502
+		}
503
+	}
475 504
 
476 505
 	ret = snprintf(buf, 4096, "Available commands :\n");
477 506
 	for(const asmsh_cmd_t *cmd = asmsh_CMDS; cmd->str; cmd++)

+ 110
- 14
src/shell_cmds.h View File

@@ -60,6 +60,8 @@ struct asmsh_cmd_s
60 60
 	const char *usage;
61 61
 	/** Command description */
62 62
 	const char *desc;
63
+	/** Command help */
64
+	const char *help;
63 65
 };
64 66
 
65 67
 /** A command arguments with command name & NULL terminated array of args */
@@ -125,49 +127,143 @@ int asmsh_cmd_flags(asmsh_t *sh, asmsh_cmd_args_t *args);
125 127
 int asmsh_cmd_help_(asmsh_t *sh, asmsh_cmd_args_t *args);
126 128
 
127 129
 
130
+static const char asmsh_cmd_help_help[] = "\
131
+asmsh details:\n\
132
+=============\n\
133
+\n\
134
+This shell allows to execute assembly instructions in a real Linux process.\n\
135
+This process will be named \"child process\".\n\
136
+\n\
137
+The shell uses the GNU assembler as from binutils. Consequently, instructions\n\
138
+syntax follows GAS syntax.\n\
139
+\n\
140
+child process details:\n\
141
+----------------------\n\
142
+In order to execute assembly instructions we have to be able to write them.\n\
143
+The bytecode will be written in a dedicated memory map (mmap). This memory\n\
144
+map is created by the child process when spawned, the the child jump in\n\
145
+the memory map and pauses.\n\
146
+At this moment the shell can prompt the user for a new instruction to\n\
147
+execute. The instructions is compiled using GNU as. The resulting bytecode\n\
148
+is written at the %rip (next instruction pointer register on x86_64), in\n\
149
+the memory map we just jumped into. Once written an implicit .step is called\n\
150
+and the instruction is executed.\n\
151
+";
152
+
153
+static const char asmsh_cmd_breakpoint_help[] = "\
154
+Breakpoint management commands.\n\
155
+    add (default) : add a breakpoint at given address (. by default)\n\
156
+    del           : remove a breakpoint at given address (. by default)\n\
157
+    list          : list breakpoints set\
158
+";
159
+
160
+static const char asmsh_cmd_bcode_help[] = "\
161
+Print the bytecode of the instruction given in argument or, by default\n\
162
+the last instruction bytecode.\n\
163
+\n\
164
+Exemple :\n\
165
+---------\n\
166
+\n\
167
+.bytecode xor %rax, %rax\n\
168
+";
169
+
170
+static const char asmsh_cmd_label_help[] = "\
171
+Set a label at given address (. by default)\n\
172
+\n\
173
+Note :\n\
174
+------\n\
175
+Label names must be uniq (?)\n\
176
+\n\
177
+Example :\n\
178
+---------\n\
179
+.label some_name ; name current address \"some_name\"\n\
180
+.label foobar 0x123456 ; name address 0x123456 \"foobar\"\n\
181
+";
182
+
183
+static const char asmsh_cmd_syntax_help[] = "\
184
+Allows to change between AT&T (att argument) or Intel (intel argument)\n\
185
+syntaxes.\n\
186
+\n\
187
+More informations can be found in GNU as documentation :\n\
188
+ https://ftp.gnu.org/old-gnu/Manuals/gas/html_chapter/as_16.html#SEC198\n\
189
+\n\
190
+Example:\n\
191
+--------\n\
192
+.syntax intel\n\
193
+.syn att\n\
194
+";
195
+
196
+static const char asmsh_cmd_reset_help[] = "\
197
+Kill underlying child process and start a new one.\n\
198
+\n\
199
+see .help .help for more informations\n\
200
+";
201
+
202
+static const char asmsh_cmd_step_help[] = "";
203
+static const char asmsh_cmd_run_help[] = "";
204
+
205
+static const char asmsh_cmd_syscalls_help[] = "";
206
+static const char asmsh_cmd_maps_help[] = "";
207
+static const char asmsh_cmd_print_regs_help[] = "";
208
+static const char asmsh_cmd_flags_help[] = "";
209
+static const char asmsh_cmd_quit_help[] = "";
210
+
128 211
 /* 
129 212
  * The list of shell commands
130 213
  */
131 214
 static const asmsh_cmd_t asmsh_CMDS[] = {
132 215
 	{".breakpoint", asmsh_cmd_breakpoint, 3,
133 216
 	 ".br(eakpoint)", "[add|del|list] [addr]",
134
-	 "Set a breakpoint"},
217
+	 "manage breakpoints",
218
+	 asmsh_cmd_breakpoint_help},
135 219
 	{".bytecode", asmsh_cmd_bcode, 2,
136
-	 ".b(ytecode)", "",
137
-	 "display last instruction bytecode"},
220
+	 ".b(ytecode)", "[instruction]",
221
+	 "display instruction bytecode",
222
+	 asmsh_cmd_bcode_help},
138 223
 	{".flags", asmsh_cmd_flags, 2,
139 224
 	 ".f(lags)", "",
140
-	 "display CPU flags"},
225
+	 "display CPU flags",
226
+	 asmsh_cmd_flags_help},
141 227
 	{".help", asmsh_cmd_help_, 2,
142 228
 	 ".h(elp)","[cmd]",
143
-	 "display this help or the help of specified command"},
229
+	 "display this help or the help of specified command",
230
+	 asmsh_cmd_help_help},
144 231
 	{".label", asmsh_cmd_label, 2,
145 232
 	 ".l(abel)", "label_name [addr]",
146
-	 "Set a label at given address (or . if none given)"},
233
+	 "set a label",
234
+	 asmsh_cmd_label_help},
147 235
 	{".maps", asmsh_cmd_maps, 2,
148 236
 	 ".m(aps)", "",
149
-	 "display memory maps"},
237
+	 "display memory maps",
238
+	 asmsh_cmd_maps_help},
150 239
 	{".quit", asmsh_cmd_quit, 2,
151 240
 	 ".q(uit)","",
152
-	 "quit asmsh"},
241
+	 "quit asmsh",
242
+	 asmsh_cmd_quit_help},
153 243
 	{".regs", asmsh_cmd_print_regs, 1,
154 244
 	".(regs)", "",
155
-	"display registers value"},
245
+	"display registers value",
246
+	asmsh_cmd_print_regs_help},
156 247
 	{".run", asmsh_cmd_run, 3,
157 248
 	 ".ru(n)", "",
158
-	 "Run until a breakpoint is reached"},
249
+	 "Run until a breakpoint is reached",
250
+	 asmsh_cmd_run_help},
159 251
 	{".step", asmsh_cmd_step, 2,
160 252
 	 ".s(tep)", "",
161
-	 "Run the instruction pointed by RIP"},
253
+	 "Run the instruction pointed by RIP",
254
+	 asmsh_cmd_step_help},
162 255
 	{".syntax", asmsh_cmd_syntax, 4,
163 256
 	 ".syn(tax)", "(att)|(intel)",
164
-	 "Change syntax AT&T (att) or Intel (intel)"},
257
+	 "Change syntax AT&T (att) or Intel (intel)",
258
+	 asmsh_cmd_syntax_help},
165 259
 	{".syscalls", asmsh_cmd_syscalls, 4,
166 260
 	 ".sys(calls)", "",
167
-	 "print syscalls name & numbers"},
261
+	 "print syscalls name & numbers",
262
+	 asmsh_cmd_syscalls_help},
168 263
 	{".reset", asmsh_cmd_reset, 0,
169 264
 	 ".reset", "",
170
-	 "reset the shell"},
265
+	 "reset the shell",
266
+	 asmsh_cmd_reset_help},
171 267
 	{NULL, NULL, 0},
172 268
 };
173 269
 

Loading…
Cancel
Save