Procházet zdrojové kódy

Implements a .run function that runs until breakpoint

Yann Weber před 1 rokem
rodič
revize
c778c8bd2b
5 změnil soubory, kde provedl 61 přidání a 3 odebrání
  1. 24
    0
      asm_env.c
  2. 10
    1
      asm_env.h
  3. 3
    2
      asmsh.h
  4. 19
    0
      shell_cmds.c
  5. 5
    0
      shell_cmds.h

+ 24
- 0
asm_env.c Zobrazit soubor

@@ -230,6 +230,30 @@ err:
230 230
 }
231 231
 
232 232
 
233
+int asmsh_env_run(asmsh_env_t *env, int *status)
234
+{
235
+	while(1)
236
+	{
237
+		int ret;
238
+		if((ret = asmsh_env_update_regs(env)) < 0)
239
+		{
240
+			return ret;
241
+		}
242
+		const unsigned long rip = env->regs.rip;
243
+		if(asmsh_brk_isset(&(env->brks), rip))
244
+		{
245
+			asmsh_log_info("Breakpoint %016lx reached", rip);
246
+			*status = 0;
247
+			return 0;
248
+		}
249
+		if((ret = asmsh_env_step(env, status)) != 0)
250
+		{
251
+			return ret;
252
+		}
253
+	}
254
+}
255
+
256
+
233 257
 int asmsh_env_update(asmsh_env_t *asmenv)
234 258
 {
235 259
 	if(asmsh_env_update_regs(asmenv) < 0)

+ 10
- 1
asm_env.h Zobrazit soubor

@@ -101,13 +101,22 @@ int asmsh_env_write_code(asmsh_env_t *env, asmsh_bytecode_t *bcode);
101 101
 
102 102
 /** Run the next instruction
103 103
  * @param asmsh_env_t* The run environment
104
- * @param int* If not null will be set to the status of the child PID (error
104
+ * @param int* Will be set to the status of the child PID (error
105 105
  * cases)
106 106
  * @return 0 if no error else -1, if the child is not trapped as expected, 1 is
107 107
  * returned and wstatus is set to the child status (see man 2 waitpid)
108 108
  */
109 109
 int asmsh_env_step(asmsh_env_t *env, int *status);
110 110
 
111
+/** Run until next breakpoint
112
+ * @param asmsh_env_t* The run environment
113
+ * @param int* Will be set to the status of the child PID (error
114
+ * cases)
115
+ * @return 0 if no error else -1, if the child is not trapped as expected, 1 is
116
+ * returned and wstatus is set to the child status (see man 2 waitpid)
117
+ */
118
+int asmsh_env_run(asmsh_env_t *env, int *status);
119
+
111 120
 /** Update both registers and memory maps */
112 121
 int asmsh_env_update(asmsh_env_t *asmenv);
113 122
 /** Update env registers from child */

+ 3
- 2
asmsh.h Zobrazit soubor

@@ -111,14 +111,15 @@ asmsh@0x7f6e312e5022 >
111 111
 
112 112
 @section TODO TODOLIST
113 113
 
114
-@todo Implement breakpoints
115 114
 @todo Implement command for memory read/dump
116 115
 @todo Implement symbols for jumps
117 116
 @todo Add support for label declarations & references
118 117
 @todo Implement write without exec
119 118
 @todo Implement function declaration
120 119
 @todo Add switch between intel's & AT&T's syntaxes.
121
-@todo Rationalise commands argument parsing
120
+@todo Implement a command to run until syscall only (and another for run until
121
+		breakpoint or syscall ?)
122
+@todo Rationalise commands argument parsing (at the moment .breakpoints allready uses special stuff :/)
122 123
 
123 124
 @section AUTHOR
124 125
 Written by Yann Weber &lt;yann.weber@members.fsf.org&gt;

+ 19
- 0
shell_cmds.c Zobrazit soubor

@@ -320,6 +320,25 @@ int asmsh_cmd_syscalls(asmsh_t *sh, asmsh_cmd_args_t *args)
320 320
 	return 0;
321 321
 }
322 322
 
323
+
324
+int asmsh_cmd_run(asmsh_t *sh, asmsh_cmd_args_t *args)
325
+{
326
+	int ret, status;
327
+	ret = asmsh_env_run(sh->env, &status);
328
+	if(ret < 0)
329
+	{
330
+		perror("Unable to run as expected");
331
+		asmsh_log_fatal("Error while child runs...");
332
+		return -1;
333
+	}
334
+	else if(ret > 0)
335
+	{
336
+		return 1+WEXITSTATUS(status);
337
+	}
338
+	return 0;
339
+}
340
+
341
+
323 342
 int asmsh_cmd_reset(asmsh_t *sh, asmsh_cmd_args_t *args)
324 343
 {
325 344
 	char *childpath = sh->child_path?strdup(sh->child_path):NULL;

+ 5
- 0
shell_cmds.h Zobrazit soubor

@@ -106,6 +106,8 @@ int asmsh_cmd_step(asmsh_t *sh, asmsh_cmd_args_t *args);
106 106
 
107 107
 int asmsh_cmd_syscalls(asmsh_t *sh, asmsh_cmd_args_t *args);
108 108
 
109
+int asmsh_cmd_run(asmsh_t *sh, asmsh_cmd_args_t *args);
110
+
109 111
 // Reset the shell (restart the child etc)a
110 112
 int asmsh_cmd_reset(asmsh_t *sh, asmsh_cmd_args_t *args);
111 113
 
@@ -140,6 +142,9 @@ static const asmsh_cmd_t asmsh_CMDS[] = {
140 142
 	{".regs", asmsh_cmd_print_regs, 1,
141 143
 	".(regs)", "",
142 144
 	"display registers value"},
145
+	{".run", asmsh_cmd_run, 3,
146
+	 ".ru(n)", "",
147
+	 "Run until a breakpoint is reached"},
143 148
 	{".step", asmsh_cmd_step, 2,
144 149
 	 ".s(tep)", "",
145 150
 	 "Run the instruction pointed by RIP"},

Loading…
Zrušit
Uložit