diff --git a/elkscmd/debug/dis.c b/elkscmd/debug/dis.c index 2f10f0714..1eef5c18e 100644 --- a/elkscmd/debug/dis.c +++ b/elkscmd/debug/dis.c @@ -25,6 +25,7 @@ char f_ksyms; char f_syms; +char f_fdinput; unsigned short textseg, ftextseg, dataseg; char * noinstrument getsymbol(int seg, int offset) @@ -134,9 +135,26 @@ int disasm_file(char *filename) return 0; } +int disasm_fd(int fd) +{ + int ip = 0; + int nextip; + + infp = fdopen(fd, "r"); + if (!infp) + return 1; + + while (!feof(infp)) { + if (!f_asmout) printf("%04hx ", ip); + nextip = disasm(textseg, ip, nextbyte_file, dataseg); + ip = nextip; + } + return 0; +} + void usage(void) { - printf("Usage: disasm [-k] [-a] [-s symfile] [[seg:off[#size] | filename]\n"); + printf("Usage: disasm [-k][-a][-s symfile] [[seg:off[#size] | filename | -]\n"); exit(1); } @@ -166,7 +184,9 @@ int main(int ac, char **av) } ac -= optind; av += optind; - if (ac < 1) + if (ac == 1 && **av == '-') + f_fdinput = 1; + else if (ac < 1) usage(); if (symfile && !sym_read_symbols(symfile)) { @@ -188,6 +208,8 @@ int main(int ac, char **av) } #endif + if (f_fdinput) + return disasm_fd(0); if (strchr(*av, ':')) { sscanf(*av, "%lx:%lx#%ld", &seg, &off, &count);