-
Notifications
You must be signed in to change notification settings - Fork 4
/
nc-aegir.c
3251 lines (2785 loc) · 86.7 KB
/
nc-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
/*
nc-aegir - interactive debugging GUI for fenris
-----------------------------------------------
Copyright (C) 2002 Andrzej Szombierski <[email protected]>
Based on Aegir by Michal Zalewski <[email protected]>
[ I added some bugs later -- Michal ]
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.
*/
#include <dirent.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/fcntl.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <string.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <dlfcn.h>
#include <sys/socket.h>
#include <termios.h>
#include <linux/un.h>
#include <sys/ptrace.h>
#include <sys/user.h>
#include <errno.h>
#include <ncurses.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#define ENVPIPE "NCAEGIR_PIPE"
#define ENVSOCK "NCAEGIR_SOCK"
#define ENVCMD "NCAEGIR_CMD"
#define regs_color (COLOR_PAIR(1) | A_BOLD)
#define running_color (COLOR_PAIR(2) | A_BOLD | A_BLINK)
#define data_color (COLOR_PAIR(3) | A_BOLD)
#define fenris_color (COLOR_PAIR(4) | A_BOLD)
#define prompt_color (def | A_BOLD)
#define fatal_color (def | A_BOLD)
#define cyan_color (COLOR_PAIR(5) | A_BOLD)
#define cblink_color (COLOR_PAIR(5) | A_BOLD | A_BLINK)
#define code_color (COLOR_PAIR(6))
#define def 0
// hardcoded window heights
#define WD 4
#define WC 6
#define WF 6
#define WA (LINES-(WC+WD+WF+3))
int doingstop;
int syscnum;
void do_prompt(int n);
void refresh_all(int t);
WINDOW *Waegir, *Wregs, *Wdata, *Winput, *Wstatus, *Wcode, *Wfenris;
#include "config.h"
#include "fdebug.h"
#include "libdisasm/opcodes2/opdis.h"
int stopped;
int please_disass;
/******************************************************************************/
void clean_exit(int n);
char *reg_mem_code_update();
void my_wprintw(WINDOW * w, char *fmt, ...);
void my_waddstr(WINDOW * w, char *str);
unsigned int wdata_addr;
unsigned int Wcode_addr;
#include "rstree.h"
#define MSG(x...) my_wprintw(Waegir,x)
#define FATALMSG(x) do { wattrset(Waegir,fatal_color); MSG("FATAL: %s\n",x); clean_exit(1); } while (0);
/******************************************************************************/
// 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
};
/******************************************************************************/
struct aegir_cmd {
char *cmd;
void (*handler) (char *param);
char *help;
};
extern struct aegir_cmd cmd[];
struct Wcode_info {
RSTree tree; /* stores disassembled addresses
* key-> opcode addr
* val-> opcode size
*/
RSNode top_node; /* Wcode topmost opcode (tree node)
*/
unsigned int cur_addr; /* highlighted opcode addr */
} Wcode_info;
/******************************************************************************/
// For sscanf hack. Blame libc authors.
unsigned long long int l1, l2;
// FIXME:NIX this is obsolete, no reason to limit to 32 bits
/*
* #define LC(x) { \
* if (x > 0xffffffff) { MSG("Value out of range.\n"); \
* return; } \
* }
*/
/******************************************************************************/
void *send_message(int mtype, void *data, void *store);
int sd;
void connect_to_fenris(char *where)
{
struct sockaddr_un sun;
MSG("[+] Connecting to Fenris at %s...\n", where);
if ((sd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0) {
MSG("FATAL: cannot create a socket (%s)\n", strerror(errno));
clean_exit(1);
}
sun.sun_family = AF_LOCAL;
strncpy(sun.sun_path, where, UNIX_PATH_MAX);
if (connect(sd, (struct sockaddr *)&sun, sizeof(sun))) {
MSG("FATAL: cannot connect to Fenris socket (%s)\n", strerror(errno));
clean_exit(1);
}
MSG("[+] Trying to send \"hello\" message...\n");
send_message(DMSG_FOO, 0, 0);
MSG("[*] Response ok, connection established.\n\n");
}
/******************************************************************************/
char str_buf[MAXFENT];
char *get_string_sock(int sock)
{
unsigned int len = 0;
while (1) {
if (read(sock, str_buf + len, 1) != 1)
FATALMSG("short read in get_string_sock from Fenris");
if (!str_buf[len])
break;
if (++len >= sizeof(str_buf) - 2)
FATALMSG("string from Fenris is of excessive length");
}
return str_buf;
}
int get_dword_sock(int sock)
{
int ret = 0;
if (read(sock, &ret, 4) != 4)
FATALMSG("short read in get_dword_sock in Fenris");
return ret;
}
char msg_data[MAXFENT];
void *send_message(int mtype, void *data, void *store)
{
struct dmsg_header x;
int dlen = 0;
if (!store)
store = msg_data;
switch (mtype) {
case DMSG_NOMESSAGE:
break; /* don't send, just read */
case DMSG_RWATCH:
case DMSG_WWATCH:
case DMSG_SETMEM:
case DMSG_GETMEM:
dlen = 8;
break;
case DMSG_ABREAK:
case DMSG_SBREAK:
case DMSG_STEP:
case DMSG_TORET:
case DMSG_FPRINT:
case DMSG_DEL:
case DMSG_IBREAK:
case DMSG_DESCADDR:
case DMSG_DESCFD:
case DMSG_GETNAME:
dlen = 4;
break;
case DMSG_GETADDR:
dlen = strlen(data) + 1;
break;
case DMSG_SETREGS:
dlen = sizeof(struct signed_user_regs_struct);
break;
case DMSG_GETREGS:
case DMSG_GETMAP:
case DMSG_FDMAP:
case DMSG_FNLIST:
case DMSG_SIGNALS:
case DMSG_TOLIBCALL:
case DMSG_TOSYSCALL:
case DMSG_TOLOCALCALL:
case DMSG_TOLOWERNEST:
case DMSG_GETBACK:
case DMSG_RUN:
case DMSG_TONEXT:
case DMSG_STOP:
case DMSG_HALT:
case DMSG_LISTBREAK:
case DMSG_KILL:
case DMSG_DYNAMIC:
case DMSG_FOO:
dlen = 0;
break;
default:
FATALMSG("unknown message type in send_message");
}
if (mtype != DMSG_NOMESSAGE) {
if (dlen && !data)
FATALMSG("message needs data but data is NULL");
x.magic1 = DMSG_MAGIC1;
x.magic2 = DMSG_MAGIC2;
x.type = mtype;
errno = 0;
if (write(sd, &x, sizeof(x)) <= 0)
FATALMSG("connection to Fenris dropped (tried to send message header)");
if (dlen)
if (write(sd, data, dlen) <= 0)
FATALMSG("connection to Fenris dropped (tried to send message data)");
}
while (1) {
int a, b;
int prevstopped = 0;
errno = 0;
bzero(&x, sizeof(x));
if (read(sd, &x, sizeof(x)) != sizeof(x))
FATALMSG("disconnected from Fenris");
if (x.magic1 != DMSG_MAGIC1)
FATALMSG("incorrect magic1 from Fenris");
if (x.magic2 != DMSG_MAGIC2)
FATALMSG("incorrect magic2 from Fenris");
stopped = !(x.code_running);
syscnum = x.code_running;
wmove(Wstatus, 0, 1);
wattrset(Wstatus, stopped ? def : running_color);
waddch(Wstatus, stopped ? 's' : 'R');
if (stopped && !prevstopped)
please_disass = 1;
prevstopped = stopped;
if (x.type == DMSG_ASYNC) {
MSG("%s", get_string_sock(sd));
if (mtype == DMSG_NOMESSAGE)
break;
continue;
}
if (x.type != DMSG_REPLY)
FATALMSG("invalid message type from Fenris");
switch (mtype) {
// If we didn't send any message, we don't want replies.
case DMSG_NOMESSAGE:
FATALMSG("no sync response expected for DMSG_NOMESSAGE");
break;
// GETMEM returns dword:length and raw data
case DMSG_GETMEM:
a = get_dword_sock(sd);
if (a < 0 || a >= MAXFENT - 4)
FATALMSG("excessive data length in DMSG_GETMEM");
memcpy(store, &a, 4);
b = 0;
while (b < a) {
int inc;
inc = read(sd, &((char *)store)[4 + b], a - b);
if (inc <= 0)
FATALMSG("short read on DMSG_GETMEM");
b += inc;
}
break;
// Most requests return strings
case DMSG_GETBACK:
case DMSG_STEP:
case DMSG_TORET:
case DMSG_TOLIBCALL:
case DMSG_TOSYSCALL:
case DMSG_TOLOCALCALL:
case DMSG_GETNAME:
case DMSG_RWATCH:
case DMSG_WWATCH:
case DMSG_TOLOWERNEST:
case DMSG_DESCADDR:
case DMSG_DESCFD:
case DMSG_STOP:
case DMSG_HALT:
case DMSG_FPRINT:
case DMSG_SETMEM:
case DMSG_LISTBREAK:
case DMSG_DEL:
case DMSG_DYNAMIC:
case DMSG_SETREGS:
case DMSG_ABREAK:
case DMSG_GETMAP:
case DMSG_FDMAP:
case DMSG_FNLIST:
case DMSG_RUN:
case DMSG_SIGNALS:
case DMSG_KILL:
case DMSG_SBREAK:
case DMSG_TONEXT:
case DMSG_IBREAK:
strcpy(store, get_string_sock(sd));
break;
// GETADDR returns dword
case DMSG_GETADDR:
a = get_dword_sock(sd);
memcpy(store, &a, 4);
break;
// GETREGS returns signed_user_regs_struct
case DMSG_GETREGS:
if (read(sd, store, sizeof(struct signed_user_regs_struct)) != sizeof(struct signed_user_regs_struct))
FATALMSG("short read on DMSG_RETREGS");
break;
// Empty.
case DMSG_FOO:
break;
// Catch whatever I missed...
default:
FATALMSG("implementation error in send_message");
}
break;
}
return store;
}
/******************************************************************************/
// "load" handler
void load_module(char *what)
{
void *x;
void (*modinit) (void);
if (!what) {
MSG("You have to provide module name.\n");
return;
}
x = dlopen(what, RTLD_LAZY | RTLD_GLOBAL);
if (!x) {
MSG("Cannot open module %s: %s\n", what, dlerror());
return;
}
modinit = dlsym(x, "aegir_module_init");
if (!modinit) {
MSG("Error: this module does not have 'aegir_module_init' export.\n");
dlclose(x);
return;
}
modinit();
MSG("Module %s loaded.\n", what);
}
// "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, ':'))
FATALMSG("Are you insane?");
*strchr(command, ':') = 0;
start = strchr(cmd[q].help, ':') + 1;
while (*start && isspace(*start))
start++;
}
MSG("%-15s - %s\n", command, start);
q++;
}
MSG("\nFor additional help, please refer to debugger's documentation.\n");
}
// "quit" handler
void handle_quit(char *param)
{
if (!param) {
MSG("Use 'quit yes' or 'q y' if you really mean it.\n");
return;
}
clean_exit(0);
}
// "exec" handler
void exec_cmd(char *param)
{
if (!param) {
MSG("You have to provide a command to be executed.\n");
return;
}
endwin();
system(param);
refresh_all(1);
}
// custom fprintf routine, called indirectly from opdis.c
int nc_fprintf(FILE * stream, char *format, ...)
{
va_list args;
va_start(args, format);
vw_printw((WINDOW *) 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) {
MSG("Numeric parameters required.\n");
return;
}
st = l1;
len = l2;
// LC(l1); LC(l2);
if (len < 0) {
MSG("Empty range provided.\n");
return;
}
} else {
if (sscanf(param, "%lld", &l1) != 1) {
MSG("The parameter needs to be an address.\n");
return;
}
st = l1;
len = 0;
// LC(l1);
Wcode_addr = l1;
reg_mem_code_update();
}
}
if (len > MAXFENT - 30) {
MSG("You exceeded the maximum memory size per single request.\n");
len = MAXFENT - 30;
}
par[0] = st;
par[1] = st + len + 16;
mem = send_message(DMSG_GETMEM, (char *)&par, 0);
retlen = *((unsigned int *)mem);
if (retlen <= 0) {
MSG("Unable to access memory at 0x%x.\n", st);
return;
}
{
MSG("\n");
opdis_disass((FILE *) Waegir, &mem[4], st, len > retlen ? retlen : len);
}
if (retlen < len)
MSG("Truncated - unable to access memory past 0x%x.\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);
}
char *wmemdump(WINDOW * w, unsigned int st, unsigned int len, char verb)
{
char *mem;
unsigned int retlen;
unsigned int caddr;
unsigned int par[2] = { st, st + len };
mem = send_message(DMSG_GETMEM, (char *)&par, 0);
retlen = *((unsigned int *)mem);
mem += 4;
if (retlen <= 0) {
if (!verb)
return 0;
my_wprintw(Waegir, "Unable to access memory at 0x%x.\n", st);
return 0;
}
if (!verb)
werase(Wdata);
if (retlen > len)
retlen = len;
caddr = 0;
while (caddr < retlen) {
int i;
int rem;
rem = retlen - caddr;
if (rem > 16)
rem = 16;
my_wprintw(w, "%08x: ", st + caddr);
for (i = 0; i < 16; i++) {
if (i && !(i % 4))
my_wprintw(w, " ");
if (i < rem)
my_wprintw(w, "%02x ", (unsigned char)mem[caddr + i]);
else
my_waddstr(w, " ");
}
my_waddstr(w, "| ");
for (i = 0; i < rem; i++)
waddch(w, isprint(mem[caddr + i]) ? mem[caddr + i] : '.');
my_waddstr(w, "\n");
caddr += 16;
}
if (retlen < len) {
my_wprintw( /*Waegir */ w, "Truncated - unable to access memory past 0x%x.\n", st + retlen);
}
return mem;
}
// "x" handler
void do_memdump(char *param)
{
long long int st, len;
if (!param) {
MSG("One or two parameters required.\n");
return;
} else {
if (strchr(param, ' ')) {
if (sscanf(param, "%lld %lld", &l1, &l2) != 2) {
MSG("Numeric parameters required.\n");
return;
}
st = l1;
len = l2;
// LC(l1); LC(l2);
if (len < 0) {
MSG("Empty range provided.\n");
return;
}
} else {
if (sscanf(param, "%lld", &l1) != 1) {
MSG("Numeric parameter required.\n");
return;
}
// st=l1;
// LC(l1);
st = wdata_addr;
wdata_addr = l1;
len = 16 * 4;
if (!reg_mem_code_update()) {
wdata_addr = st;
reg_mem_code_update();
}
return;
}
}
if (len > MAXFENT - 20) {
MSG("You exceeded the maximum memory size per single request.\n");
len = MAXFENT - 20;
}
if (st > st + len) {
MSG("Illegal combination of start address and length.\n");
return;
}
wmemdump(Waegir, st, len, 1);
}
void do_rwatch(char *param)
{
char *mem;
unsigned int par[2];
if (!param) {
MSG("Two parameters required.\n");
return;
} else {
if (sscanf(param, "%lld %lld", &l1, &l2) != 2) {
MSG("Two numeric parameters required.\n");
return;
}
par[0] = l1;
par[1] = l2;
// LC(l1); LC(l2);
if (par[0] > par[1]) {
MSG("Empty range provided.\n");
return;
}
}
mem = send_message(DMSG_RWATCH, (char *)&par, 0);
MSG("%s", mem);
}
FILE *extralog;
void do_log(char *param)
{
FILE *tmp;
if (!param && extralog) {
MSG("Logging stopped.\n");
fclose(extralog);
extralog = 0;
return;
}
if (!param && !extralog) {
MSG("Log never started.\n");
return;
}
if (param && extralog) {
MSG("Closing old log...\n");
fclose(extralog);
extralog = 0;
}
tmp = fopen(param, "w");
if (!tmp) {
MSG("Cannot create log file '%s'.\n", param);
return;
}
extralog = tmp;
MSG("New log '%s' initiated.\n", param);
}
void do_logappend(char *data)
{
if (!extralog)
return;
fwrite(data, strlen(data), 1, extralog);
}
void do_wwatch(char *param)
{
char *mem;
unsigned int par[2];
if (!param) {
MSG("Two parameters required.\n");
return;
} else {
if (sscanf(param, "%lld %lld", &l1, &l2) != 2) {
MSG("Two numeric parameters required.\n");
return;
}
par[0] = l1;
par[1] = l2;
// LC(l1); LC(l2);
if (par[0] > par[1]) {
MSG("Empty range provided.\n");
return;
}
}
mem = send_message(DMSG_WWATCH, (char *)&par, 0);
MSG("%s", mem);
}
// "x" handler
void do_setmem(char *param)
{
char *res;
unsigned int par[2];
if (!param) {
MSG("Two parameters required.\n");
return;
} else {
if (sscanf(param, "%lld %lld", &l1, &l2) != 2) {
MSG("Numeric parameters required.\n");
return;
}
par[0] = l1;
par[1] = l2;
// LC(l1); LC(l2);
}
res = send_message(DMSG_SETMEM, (char *)&par, 0);
MSG("%s", res);
}
// "y" handler
void do_strdump(char *param)
{
unsigned int st;
char *mem;
unsigned int par[2];
int retlen;
int i;
if (!param) {
MSG("Parameter required.\n");
return;
} else {
if (sscanf(param, "%lld", &l1) != 1) {
MSG("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) {
MSG("Unable to access memory at 0x%x.\n", st);
return;
}
MSG("%08x: \"", st);
for (i = 0; i < retlen; i++) {
if (!mem[4 + i])
break;
if (isprint(mem[4 + i]) && mem[4 + i] != '"')
MSG("%c", mem[4 + i]);
else
MSG("\\x%02x", (unsigned char)mem[4 + i]);
}
if (i == retlen) {
if (retlen < MAXYSTR)
MSG("\"... <read past accessible memory>\n");
else
MSG("\"...\n");
} else
MSG("\"\n");
}
void do_regs(char *param __attribute__ ((unused)))
{
struct signed_user_regs_struct *x;
x = (void *)send_message(DMSG_GETREGS, 0, 0);
MSG("eax \t0x%08x\t %d\n", x->rax, x->rax);
MSG("ebx \t0x%08x\t %d\n", x->rbx, x->rbx);
MSG("ecx \t0x%08x\t %d\n", x->rcx, x->rcx);
MSG("edx \t0x%08x\t %d\n", x->rdx, x->rdx);
MSG("esi \t0x%08x\t %d\n", x->rsi, x->rsi);
MSG("edi \t0x%08x\t %d\n", x->rdi, x->rdi);
MSG("ebp \t0x%08x\t %d\n", x->rbp, x->rbp);
MSG("esp \t0x%08x\t %d\n", x->rsp, x->rsp);
MSG("eip \t0x%08x\t %d\n", x->rip, x->rip);
MSG("eflags \t0x%08x\t 0%o\n", x->eflags, x->eflags);
MSG("ds \t0x%x\n", x->ds);
MSG("es \t0x%x\n", x->es);
MSG("fs \t0x%x\n", x->fs);
MSG("gs \t0x%x\n", x->gs);
MSG("cs \t0x%x\n", x->es);
MSG("ss \t0x%x\n", x->ss);
}
void do_setreg(char *param)
{
char *ww;
struct signed_user_regs_struct x;
char regname[128];
int val;
if (!param) {
MSG("Parameters required.\n");
return;
}
if (sscanf(param, "%s %lld", regname, &l1) != 2) {
MSG("Two parameters, register name and numeric value, required.\n");
return;
}
// LC(l1);
val = l1;
send_message(DMSG_GETREGS, 0, &x);
if (!strcasecmp("eax", regname)) {
MSG("Changing %s from 0x%x to 0x%x...\n", regname, x.rax, val);
x.rax = val;
} else
if (!strcasecmp("ebx", regname)) {
MSG("Changing %s from 0x%x to 0x%x...\n", regname, x.rbx, val);
x.rbx = val;
} else
if (!strcasecmp("ecx", regname)) {
MSG("Changing %s from 0x%x to 0x%x...\n", regname, x.rcx, val);
x.rcx = val;
} else
if (!strcasecmp("edx", regname)) {
MSG("Changing %s from 0x%x to 0x%x...\n", regname, x.rdx, val);
x.rdx = val;
} else
if (!strcasecmp("esi", regname)) {
MSG("Changing %s from 0x%x to 0x%x...\n", regname, x.rsi, val);
x.rsi = val;
} else
if (!strcasecmp("edi", regname)) {
MSG("Changing %s from 0x%x to 0x%x...\n", regname, x.rdi, val);
x.rdi = val;
} else
if (!strcasecmp("esp", regname)) {
MSG("Changing %s from 0x%x to 0x%x...\n", regname, x.rsp, val);
x.rsp = val;
} else
if (!strcasecmp("eip", regname)) {
MSG("Changing %s from 0x%x to 0x%x...\n", regname, x.rip, val);
MSG("Note: modifying eip is the best way to trash Fenris. Act wisely.\n");
x.rip = val;
} else
if (!strcasecmp("ebp", regname)) {
MSG("Changing %s from 0x%x to 0x%x...\n", regname, x.rbp, val);
x.rbp = val;
} else
if (!strcasecmp("eflags", regname)) {
MSG("Changing %s from 0x%x to 0x%x...\n", regname, x.eflags, val);
x.eflags = val;
} else
if (!strcasecmp("ds", regname)) {
MSG("Changing %s from 0x%x to 0x%x...\n", regname, x.ds, val);
x.ds = val;
} else
if (!strcasecmp("es", regname)) {
MSG("Changing %s from 0x%x to 0x%x...\n", regname, x.es, val);
x.es = val;
} else
if (!strcasecmp("fs", regname)) {
MSG("Changing %s from 0x%x to 0x%x...\n", regname, x.fs, val);
x.fs = val;
} else
if (!strcasecmp("gs", regname)) {
MSG("Changing %s from 0x%x to 0x%x...\n", regname, x.gs, val);
x.gs = val;
} else
if (!strcasecmp("cs", regname)) {
MSG("Changing %s from 0x%x to 0x%x...\n", regname, x.cs, val);
x.cs = val;
} else
if (!strcasecmp("ss", regname)) {
MSG("Changing %s from 0x%x to 0x%x...\n", regname, x.ss, val);
x.ss = val;
} else {
MSG("Unknown register '%s'.\n", regname);
return;
}
ww = send_message(DMSG_SETREGS, &x, 0);
MSG("%s", ww);
}
void do_back(char *param __attribute__ ((unused)))
{
char *x;
x = (void *)send_message(DMSG_GETBACK, 0, 0);
MSG("%s", x);
}
void do_addr(char *param)
{
int *x;
int fifi;
int st;
if (!param) {
MSG("Parameter required.\n");
return;
}
if (sscanf(param, "%lld", &l1) != 1) {
x = (void *)send_message(DMSG_GETADDR, param, 0);
if (!*x)