-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaegir.c
1632 lines (1394 loc) · 42.3 KB
/
aegir.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
fenris - program execution path analysis tool
---------------------------------------------
Copyright (C) 2001, 2002 by Bindview Corporation Portions copyright (C)
2001, 2002 by their respective contributors Developed and maintained by
Michal Zalewski <lcamtuf@coredump.cx>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 675 Mass
Ave, Cambridge, MA 02139, USA.
Well - readline support mindlessly ripped from Argante r1. Original code in
Argante r1 came from Artur Skura. What is still terribly wrong is that async
output from Fenris can pop up at any time and will make the screen look
ugly. Hey, any libreadline wizards?
For testing, use test/fakedebug.c.
"dobry feature to feature w wygodnym toolu" Slawomir Krawczyk, Dziela
zebrane tom XLVII
*/
#include <unistd.h>
#include <stdio.h>
#include <sys/fcntl.h>
#include <sys/time.h>
#include <string.h>
#include <signal.h>
#include <dlfcn.h>
#include <sys/socket.h>
#include <linux/un.h>
#include <sys/ptrace.h>
#include <sys/user.h>
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
#include <ctype.h>
#ifdef HAVE_READLINE
#include <readline/readline.h>
#include <readline/history.h>
#include <sched.h>
#endif /* HAVE_READLINE */
#include "config.h"
#include "fdebug.h"
#include "libdisasm/opcodes2/opdis.h"
void do_addr(char *param);
void do_back(char *param);
void do_break(char *param);
void do_call(char *param);
void do_cur(char *param);
void do_del(char *param);
void do_disass(char *param);
void do_down(char *param);
void do_dynamic(char *param);
void do_fd(char *param);
void do_fdmap(char *param);
void do_fnmap(char *param);
void do_fprint(char *param);
void do_halt(char *param);
void do_ibreak(char *param);
void do_libc(char *param);
void do_list(char *param);
void do_memdump(char *param);
void do_memmap(char *param);
void do_next(char *param);
void do_regs(char *param);
void do_ret(char *param);
void do_run(char *param);
void do_rwatch(char *param);
void do_sbreak(char *param);
void do_setmem(char *param);
void do_setreg(char *param);
void do_signals(char *param);
void do_step(char *param);
void do_stop(char *param);
void do_strdump(char *param);
void do_sys(char *param);
void do_wwatch(char *param);
void load_module(char *param);
void exec_cmd(char *param);
void display_help(char *param);
void display_help(char *param);
void handle_quit(char *param);
void handle_quit(char *param);
void *send_message(int mtype, void *data, void *store);
// FIXME:NIX hardcoded?!? more than 300+ for i386
const char *scnames[256] = {
0,
#include "syscallnames.h"
0
};
const char *my_siglist[] = {
"none", "sighup", "sigint", "sigquit", "sigill", "sigtrap", "sigabrt",
"sigbus", "sigfpe", "sigkill", "sigusr1", "sigsegv", "sigusr2", "sigpipe",
"sigalrm", "sigterm", "sigchld", "sigcont", "sigstop", "sigtstp",
"sigttin", "sigttou", "sigurg", "sigxcpu", "sigxfsz", "sigvtalrm",
"sigprof", "sigwinch", "sigio", "sigpwr", "sigsys", 0
};
int stupid_pid;
char T_besync = 1;
struct aegir_cmd {
char *cmd;
void (*handler) (char *param);
char *help;
};
unsigned char stopped;
char use_readline, prompted;
char input_buffer[1024];
char restart_last;
// For sscanf hack. Blame libc authors.
unsigned long long int l1, l2;
// FIXME:NIX This should be obsolete, no reason to limit to 32 bits
/*
* #define LC(x) { \
* if (x > 0xffffffff) { STDERRMSG("Value out of range.\n"); \
* return; } \
* }
*/
// Predefined commands.
struct aegir_cmd cmd[MAXCMD + 1] = {
{"disass", do_disass, "disass [ x len ]: disassemble current eip [ or memory region ]"},
{"regs", do_regs, "display registers"},
{"back", do_back, "display call backtrace"},
{"cur", do_cur, "display last line from Fenris"},
{"info", do_addr, "info x: get info about name or address x"},
{"fdinfo", do_fd, "fdinfo x: display info about file descriptor x"},
{"break", do_break, "break x: set a breakpoint at address x"},
{"sbreak", do_sbreak, "break x: set a breakpoint on syscall x"},
{"ibreak", do_ibreak, "break x: set a breakpoint on signal x"},
{"rwatch", do_rwatch, "rwatch x y: watch memory region for reads"},
{"wwatch", do_wwatch, "wwatch x y: watch memory region for writes"},
{"step", do_step, "step [ x ]: do a single step [ or x steps ]"},
{"ret", do_ret, "ret [ x ]: continue until [ x-th ] ret"},
{"libc", do_libc, "continue to next libcall"},
{"sys", do_sys, "continue to next syscall"},
{"call", do_call, "continue to next local call"},
{"down", do_down, "continue to ret from current function"},
{"next", do_next, "continue to next line from Fenris"},
{"run", do_run, "continue to next breakpoint or watchpoint"},
{"dynamic", do_dynamic, "continue to the main code (skip libc prolog)"},
{"stop", do_stop, "stop program as soon as possible"},
{"halt", do_halt, "stop program NOW"},
{"fprint", do_fprint, "fprint x: fingerprint code at address x"},
{"x", do_memdump, "x x y: display memory region as bytes"},
{"y", do_strdump, "y x: display a string under address x"},
{"setreg", do_setreg, "setreg x y: set register x to value y"},
{"setmem", do_setmem, "setmem x y: set byte at address x to value y"},
{"list", do_list, "list watchpoints and breakpoints"},
{"del", do_del, "del x: delete a watchpoint or breakpoint"},
{"memmap", do_memmap, "display process memory map"},
{"fdmap", do_fdmap, "display process file descriptor map"},
{"fnmap", do_fnmap, "list known local functions"},
{"signals", do_signals, "display signal actions"},
{"load", load_module, "load x: load custom debugging module x"},
{"exec", exec_cmd, "exec x: execute shell command x"},
{"help", display_help, "display help"},
{"?", display_help, 0},
{"quit", handle_quit, "quit, exit: terminate the session"},
{"exit", handle_quit, 0}
};
#ifdef HAVE_READLINE
// There is an ugly hack there (and later, with clone()). Basically,
// libreadline is not too good with async reading and such (it is
// theoretically possible, but not always working as we want it). So
// we have to create a new thread and read in sync mode there.
char *read_stack, *read_tmp;
int read_the_line(void *arg)
{
char *prev = 0;
signal(SIGINT, SIG_IGN);
usleep(200000);
while (1) {
// It never hurts to wait.
while (read_tmp)
usleep(20000);
if (prev)
free(prev);
if (!(read_tmp = readline(PROMPT))) {
STDERRMSG("Use 'quit yes' (or 'q y') to quit.\n");
} else if (strlen(read_tmp))
add_history(read_tmp);
prev = read_tmp;
kill(getppid(), SIGUSR1);
}
return 0;
}
#endif
int hardstopping;
void ctrlc(int x __attribute__ ((unused)))
{
if (stopped) {
STDERRMSG("Use 'quit yes' (or 'q y') to quit.\n");
} else
hardstopping = 1;
}
// "load" handler
void load_module(char *what)
{
void *x;
void (*modinit) (void);
if (!what) {
STDERRMSG("You have to provide module name.\n");
return;
}
x = dlopen(what, RTLD_LAZY | RTLD_GLOBAL);
if (!x) {
STDERRMSG("Cannot open module %s: %s\n", what, dlerror());
return;
}
modinit = dlsym(x, "aegir_module_init");
if (!modinit) {
STDERRMSG("Error: this module does not have 'aegir_module_init' export.\n");
dlclose(x);
return;
}
modinit();
STDERRMSG("Module %s loaded.\n", what);
}
void register_command(char *commd, void *handler, char *help)
{
int q = 0;
if (!commd)
FATALEXIT("You cannot register command with null name");
while (cmd[q].cmd)
q++;
if (q >= MAXCMD)
FATALEXIT("MAXCMD exceeded");
cmd[q].cmd = strdup(commd);
cmd[q].handler = handler;
cmd[q].help = strdup(help);
}
char last_buf[MAXFENT];
void do_cur(char *param __attribute__ ((unused)))
{
STDERRMSG("%s", last_buf);
}
// "help" handler
void display_help(char *param __attribute__ ((unused)))
{
int q = 0;
while (cmd[q].cmd) {
char command[512];
char *start;
if (!cmd[q].help) {
q++;
continue;
}
command[sizeof(command) - 1] = 0;
if (!strchr(cmd[q].help, ':')) {
strcpy(command, cmd[q].cmd);
start = cmd[q].help;
} else {
strncpy(command, cmd[q].help, sizeof(command) - 1);
if (!strchr(command, ':'))
FATALEXIT("Are you insane?");
*strchr(command, ':') = 0;
start = strchr(cmd[q].help, ':') + 1;
while (*start && isspace(*start))
start++;
}
STDERRMSG("%-15s - %s\n", command, start);
q++;
}
STDERRMSG("\nFor additional help, please refer to debugger's documentation.\n");
}
// "quit" handler
void handle_quit(char *param)
{
if (!param) {
STDERRMSG("Use 'quit yes' or 'q y' if you really mean it.\n");
return;
}
STDERRMSG("So long, and thanks for all the fish.\n");
#ifdef HAVE_READLINE
kill(stupid_pid, 15);
#endif
usleep(200000);
exit(0);
}
// "exec" handler
void exec_cmd(char *param)
{
if (!param) {
STDERRMSG("You have to provide a command to be executed.\n");
return;
}
system(param);
}
// custom fprintf routine, called indirectly from opdis.c
int aegir_fprintf(FILE * stream, char *format, ...)
{
va_list args;
va_start(args, format);
vfprintf(stream, format, args);
va_end(args);
return 0;
}
// "disass" handler
void do_disass(char *param)
{
long long int st, len;
char *mem;
unsigned int par[2];
int retlen;
if (!param) {
struct signed_user_regs_struct *x;
x = (void *)send_message(DMSG_GETREGS, 0, 0);
st = x->rip;
len = 0;
} else {
if (strchr(param, ' ')) {
if (sscanf(param, "%lld %lld", &l1, &l2) != 2) {
STDERRMSG("Two numeric parameters required.\n");
return;
}
// LC(l1); LC(l2);
st = l1;
len = l2;
if (len < 0) {
STDERRMSG("Empty range provided.\n");
return;
}
} else {
if (sscanf(param, "%lld", &l1) != 1) {
STDERRMSG("The parameter needs to be an address.\n");
return;
}
// LC(l1);
st = l1;
len = 0;
}
}
if (len > MAXFENT - 30) {
STDERRMSG("You exceeded the maximum memory size per single request.\n");
len = MAXFENT - 30;
}
par[0] = st;
par[1] = st + len + 16;
if (par[0] > par[1]) {
STDERRMSG("Illegal combination of start address and length.\n");
return;
}
mem = send_message(DMSG_GETMEM, (char *)&par, 0);
retlen = *((unsigned int *)mem);
if (retlen <= 0) {
STDERRMSG("Unable to access memory at 0x%llx.\n", st);
return;
}
opdis_disass(stderr, &mem[4], st, len > retlen ? retlen : len);
fflush(0);
if (retlen < len)
STDERRMSG("Truncated - unable to access memory past 0x%llx.\n", st + retlen);
}
// Describe addresses in disassembly. Called from opdis.c.
char descbuf[MAXFENT];
char *describe_address(unsigned int addr)
{
return send_message(DMSG_GETNAME, (char *)&addr, descbuf);
}
// "x" handler
void do_memdump(char *param)
{
int st, len;
char *mem;
unsigned int par[2];
int retlen;
int caddr;
if (!param) {
STDERRMSG("One or two parameters required.\n");
return;
} else {
if (strchr(param, ' ')) {
if (sscanf(param, "%lld %lld", &l1, &l2) != 2) {
STDERRMSG("Numeric parameters required.\n");
return;
}
st = l1;
len = l2;
// LC(l1); LC(l2);
if (len < 0) {
STDERRMSG("Empty range provided.\n");
return;
}
} else {
if (sscanf(param, "%lld", &l1) != 1) {
STDERRMSG("Numeric parameter required.\n");
return;
}
st = l1;
// LC(l1);
len = 16;
}
}
if (len > MAXFENT - 20) {
STDERRMSG("You exceeded the maximum memory size per single request.\n");
len = MAXFENT - 20;
}
par[0] = st;
par[1] = st + len;
if (par[0] > par[1]) {
STDERRMSG("Illegal combination of start address and length.\n");
return;
}
mem = send_message(DMSG_GETMEM, (char *)&par, 0);
retlen = *((unsigned int *)mem);
mem += 4;
if (retlen <= 0) {
STDERRMSG("Unable to access memory at 0x%x.\n", st);
return;
}
if (retlen > len)
retlen = len;
caddr = 0;
while (caddr < retlen) {
int i;
int rem;
rem = retlen - caddr;
if (rem > 16)
rem = 16;
STDERRMSG("%08x: ", st + caddr);
for (i = 0; i < rem; i++)
STDERRMSG("%02x ", (unsigned char)mem[caddr + i]);
if (rem < 16)
for (i = 0; i < 16 - rem; i++)
STDERRMSG(" ");
STDERRMSG(" | ");
for (i = 0; i < rem; i++)
STDERRMSG("%c", isprint(mem[caddr + i]) ? mem[caddr + i] : '.');
STDERRMSG("\n");
caddr += 16;
}
if (retlen < len)
STDERRMSG("Truncated - unable to access memory past 0x%x.\n", st + retlen);
}
void do_rwatch(char *param)
{
char *mem;
unsigned int par[2];
if (!param) {
STDERRMSG("Two parameters required.\n");
return;
} else {
if (sscanf(param, "%lld %lld", &l1, &l2) != 2) {
STDERRMSG("Two numeric parameters required.\n");
return;
}
par[0] = l1;
par[1] = l2;
// LC(l1); LC(l2);
if (par[0] > par[1]) {
STDERRMSG("Empty range provided.\n");
return;
}
}
mem = send_message(DMSG_RWATCH, (char *)&par, 0);
STDERRMSG("%s", mem);
}
void do_wwatch(char *param)
{
char *mem;
unsigned int par[2];
if (!param) {
STDERRMSG("Two parameters required.\n");
return;
} else {
if (sscanf(param, "%lld %lld", &l1, &l2) != 2) {
STDERRMSG("Two numeric parameters required.\n");
return;
}
par[0] = l1;
par[1] = l2;
// LC(l1); LC(l2);
if (par[0] > par[1]) {
STDERRMSG("Empty range provided.\n");
return;
}
}
mem = send_message(DMSG_WWATCH, (char *)&par, 0);
STDERRMSG("%s", mem);
}
// "x" handler
void do_setmem(char *param)
{
char *res;
unsigned int par[2];
if (!param) {
STDERRMSG("Two parameters required.\n");
return;
} else {
if (sscanf(param, "%lld %lld", &l1, &l2) != 2) {
STDERRMSG("Numeric parameters required.\n");
return;
}
par[0] = l1;
par[1] = l2;
// LC(l1); LC(l2);
}
res = send_message(DMSG_SETMEM, (char *)&par, 0);
STDERRMSG("%s", res);
}
// "y" handler
void do_strdump(char *param)
{
unsigned int st;
char *mem;
unsigned int par[2];
int retlen;
int i;
if (!param) {
STDERRMSG("Parameter required.\n");
return;
} else {
if (sscanf(param, "%lld", &l1) != 1) {
STDERRMSG("Numeric parameter required.\n");
return;
}
st = l1;
// LC(l1);
}
par[0] = st;
par[1] = st + MAXYSTR;
mem = send_message(DMSG_GETMEM, (char *)&par, 0);
retlen = *((unsigned int *)mem);
if (retlen <= 0) {
STDERRMSG("Unable to access memory at 0x%x.\n", st);
return;
}
STDERRMSG("%08x: \"", st);
for (i = 0; i < retlen; i++) {
if (!mem[4 + i])
break;
if (isprint(mem[4 + i]) && mem[4 + i] != '"')
STDERRMSG("%c", mem[4 + i]);
else
STDERRMSG("\\x%02x", (unsigned char)mem[4 + i]);
}
if (i == retlen) {
if (retlen < MAXYSTR)
STDERRMSG("\"... <read past accessible memory>\n");
else
STDERRMSG("\"...\n");
} else
STDERRMSG("\"\n");
}
void do_regs(char *param __attribute__ ((unused)))
{
struct signed_user_regs_struct *x;
x = (void *)send_message(DMSG_GETREGS, 0, 0);
STDERRMSG("eax \t0x%08x\t %d\n", (int)x->rax, (int)x->rax);
STDERRMSG("ebx \t0x%08x\t %d\n", (int)x->rbx, (int)x->rbx);
STDERRMSG("ecx \t0x%08x\t %d\n", (int)x->rcx, (int)x->rcx);
STDERRMSG("edx \t0x%08x\t %d\n", (int)x->rdx, (int)x->rdx);
STDERRMSG("esi \t0x%08x\t %d\n", (int)x->rsi, (int)x->rsi);
STDERRMSG("edi \t0x%08x\t %d\n", (int)x->rdi, (int)x->rdi);
STDERRMSG("ebp \t0x%08x\t %d\n", (int)x->rbp, (int)x->rbp);
STDERRMSG("esp \t0x%08x\t %d\n", (int)x->rsp, (int)x->rsp);
STDERRMSG("eip \t0x%08x\t %d\n", (int)x->rip, (int)x->rip);
STDERRMSG("eflags \t0x%08x\t 0%o\n", (int)x->eflags, (int)x->eflags);
STDERRMSG("ds \t0x%x\n", (int)x->ds);
STDERRMSG("es \t0x%x\n", (int)x->es);
STDERRMSG("fs \t0x%x\n", (int)x->fs);
STDERRMSG("gs \t0x%x\n", (int)x->gs);
STDERRMSG("cs \t0x%x\n", (int)x->es);
STDERRMSG("ss \t0x%x\n", (int)x->ss);
}
void do_setreg(char *param)
{
char *ww;
struct signed_user_regs_struct x;
char regname[128];
int val;
if (!param) {
STDERRMSG("Parameters required.\n");
return;
}
if (sscanf(param, "%s %lld", regname, &l1) != 2) {
STDERRMSG("Two parameters, register name and numeric value, required.\n");
return;
}
// LC(l1);
val = l1;
send_message(DMSG_GETREGS, 0, &x);
if (!strcasecmp("eax", regname)) {
STDERRMSG("Changing %s from 0x%x to 0x%x...\n", regname, (int)x.rax, val);
x.rax = val;
} else
if (!strcasecmp("ebx", regname)) {
STDERRMSG("Changing %s from 0x%x to 0x%x...\n", regname, (int)x.rbx, val);
x.rbx = val;
} else
if (!strcasecmp("ecx", regname)) {
STDERRMSG("Changing %s from 0x%x to 0x%x...\n", regname, (int)x.rcx, val);
x.rcx = val;
} else
if (!strcasecmp("edx", regname)) {
STDERRMSG("Changing %s from 0x%x to 0x%x...\n", regname, (int)x.rdx, val);
x.rdx = val;
} else
if (!strcasecmp("esi", regname)) {
STDERRMSG("Changing %s from 0x%x to 0x%x...\n", regname, (int)x.rsi, val);
x.rsi = val;
} else
if (!strcasecmp("edi", regname)) {
STDERRMSG("Changing %s from 0x%x to 0x%x...\n", regname, (int)x.rdi, val);
x.rdi = val;
} else
if (!strcasecmp("esp", regname)) {
STDERRMSG("Changing %s from 0x%x to 0x%x...\n", regname, (int)x.rsp, val);
x.rsp = val;
} else
if (!strcasecmp("eip", regname)) {
STDERRMSG("Changing %s from 0x%x to 0x%x...\n", regname, (int)x.rip, val);
STDERRMSG("Note: modifying eip is the best way to trash Fenris. Act wisely.\n");
x.rip = val;
} else
if (!strcasecmp("ebp", regname)) {
STDERRMSG("Changing %s from 0x%x to 0x%x...\n", regname, (int)x.rbp, val);
x.rbp = val;
} else
if (!strcasecmp("eflags", regname)) {
STDERRMSG("Changing %s from 0x%x to 0x%x...\n", regname, (int)x.eflags, val);
x.eflags = val;
} else
if (!strcasecmp("ds", regname)) {
STDERRMSG("Changing %s from 0x%x to 0x%x...\n", regname, (int)x.ds, val);
x.ds = val;
} else
if (!strcasecmp("es", regname)) {
STDERRMSG("Changing %s from 0x%x to 0x%x...\n", regname, (int)x.es, val);
x.es = val;
} else
if (!strcasecmp("fs", regname)) {
STDERRMSG("Changing %s from 0x%x to 0x%x...\n", regname, (int)x.fs, val);
x.fs = val;
} else
if (!strcasecmp("gs", regname)) {
STDERRMSG("Changing %s from 0x%x to 0x%x...\n", regname, (int)x.gs, val);
x.gs = val;
} else
if (!strcasecmp("cs", regname)) {
STDERRMSG("Changing %s from 0x%x to 0x%x...\n", regname, (int)x.cs, val);
x.cs = val;
} else
if (!strcasecmp("ss", regname)) {
STDERRMSG("Changing %s from 0x%x to 0x%x...\n", regname, (int)x.ss, val);
x.ss = val;
} else {
STDERRMSG("Unknown register '%s'.\n", regname);
return;
}
ww = send_message(DMSG_SETREGS, &x, 0);
STDERRMSG("%s", ww);
}
void do_back(char *param __attribute__ ((unused)))
{
char *x;
x = (void *)send_message(DMSG_GETBACK, 0, 0);
STDERRMSG("%s", x);
}
void do_addr(char *param)
{
int *x;
int fifi;
int st;
if (!param) {
STDERRMSG("Parameter required.\n");
return;
}
if (sscanf(param, "%lld", &l1) != 1) {
x = (void *)send_message(DMSG_GETADDR, param, 0);
if (!*x)
STDERRMSG("Name '%s' not found.\n", param);
else {
STDERRMSG("Name '%s' has address 0x%08x.\n", param, *x);
fifi = *x;
x = (void *)send_message(DMSG_DESCADDR, &fifi, 0);
STDERRMSG("%s", (char *)x);
}
} else {
st = l1;
// LC(l1);
x = (void *)send_message(DMSG_DESCADDR, &st, 0);
STDERRMSG("%s", (char *)x);
}
}
void do_fd(char *param)
{
char *x;
int st;
if (!param) {
STDERRMSG("Parameter required.\n");
return;
} else {
if (sscanf(param, "%lld", &l1) != 1) {
STDERRMSG("Numeric parameter required.\n");
return;
}
st = l1;
// LC(l1);
}
x = (void *)send_message(DMSG_DESCFD, &st, 0);
STDERRMSG("%s", x);
}
void do_break(char *param)
{
char *x;
int st;
if (!param) {
STDERRMSG("Parameter required.\n");
return;
} else {
if (sscanf(param, "%lld", &l1) != 1) {
STDERRMSG("Numeric parameter required.\n");
return;
}
st = l1;
// LC(l1);
}
x = (void *)send_message(DMSG_ABREAK, &st, 0);
STDERRMSG("%s", x);
}
void do_fprint(char *param)
{
char *x;
int st;
if (!param) {
STDERRMSG("Parameter required.\n");
return;
} else {
if (sscanf(param, "%lld", &l1) != 1) {
STDERRMSG("Numeric parameter required.\n");
return;
}
st = l1;
// LC(l1);
}
x = (void *)send_message(DMSG_FPRINT, &st, 0);
STDERRMSG("%s", x);
}
void do_sbreak(char *param)
{
char *x;
int st;
if (!param) {
STDERRMSG("Parameter required.\n");
return;
} else {
if (sscanf(param, "%lld", &l1) != 1) {
// FIXME:NIX hardcoded?!? there are 300+ for i386!
for (st = 0; st < 256; st++)
if (scnames[st])
if (!strcasecmp(scnames[st], param))
break;
if (st == 256) {
STDERRMSG("Invalid syscall name.\n");
return;
}
} else {
// LC(l1);
st = l1;
}
}
x = (void *)send_message(DMSG_SBREAK, &st, 0);
STDERRMSG("%s", x);
}
void do_ibreak(char *param)
{
char *x;
int st;
if (!param) {
STDERRMSG("Parameter required.\n");
return;
} else {
if (sscanf(param, "%lld", &l1) != 1) {
for (st = 0; st < MAXMYSIG; st++)
if (my_siglist[st])
if (!strcasecmp(param, my_siglist[st]))
break;
if (st == MAXMYSIG) {
STDERRMSG("Invalid signal name.\n");
return;
}
} else {
st = l1;
// LC(l1);
}
}
x = (void *)send_message(DMSG_IBREAK, &st, 0);
STDERRMSG("%s", x);
}
void do_ret(char *param)
{
char *x;
int st;
if (!param) {
st = 1;
} else {
if (sscanf(param, "%lld", &l1) != 1) {
STDERRMSG("Numeric parameter required.\n");
return;
}
st = l1;
// LC(l1);
}
x = (void *)send_message(DMSG_TORET, &st, 0);
STDERRMSG("%s", x);
}
void do_step(char *param)
{
char *x;
int st;
if (!param) {
st = 1;
} else {
if (sscanf(param, "%lld", &l1) != 1) {
STDERRMSG("Numeric parameter required.\n");
return;
}
st = l1;
// LC(l1);
}
if (st < 0) {
STDERRMSG("Nonsense parameter.\n");
return;
}
x = (void *)send_message(DMSG_STEP, &st, 0);
STDERRMSG("%s", x);
}
void do_dynamic(char *param __attribute__ ((unused)))
{
char *x;
x = (void *)send_message(DMSG_DYNAMIC, 0, 0);
STDERRMSG("%s", x);
}
void do_del(char *param)
{
char *x;
int st;
if (!param) {
st = 1;
} else {
if (sscanf(param, "%lld", &l1) != 1) {
STDERRMSG("Numeric parameter required.\n");
return;
}
st = l1;
// LC(l1);
}
x = (void *)send_message(DMSG_DEL, &st, 0);
STDERRMSG("%s", x);
}
void do_libc(char *param __attribute__ ((unused)))
{
char *x;
x = (void *)send_message(DMSG_TOLIBCALL, 0, 0);
STDERRMSG("%s", x);
}
void do_sys(char *param __attribute__ ((unused)))
{
char *x;
x = (void *)send_message(DMSG_TOSYSCALL, 0, 0);
STDERRMSG("%s", x);
}