/* Copyright Yann Weber This file is part of asmsh. asmsh 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 3 of the License, or any later version. asmsh 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 asmsh. If not, see . */ #include "config.h" #include #include #include #define CHILD_EXEC_PATH "./child" #include "logger.h" #include "shell.h" #include "completion.h" int main(int argc, char *argv[], char *envp[]) { asmsh_logger_t *logger; asmsh_t sh; int ret; char *cmd; char prompt[64]; bzero(prompt, sizeof(prompt)); logger = asmsh_logger_new(ASMSH_INFO); asmsh_logger_setup(logger); if(asmsh_init(&sh, CHILD_EXEC_PATH)) { perror("Unable to init shell"); asmsh_logger_dprint(2, logger); return 1; } rl_special_prefixes=""; rl_basic_word_break_characters=" \t\n"; rl_attempted_completion_function = asmsh_rl_completion; while(1) { snprintf(prompt, sizeof(prompt)-1, "asmsh@%p > ", sh.env->regs.rip); cmd = readline(prompt); if(!cmd) { break; } ret = asmsh_exec(&sh, cmd); asmsh_logger_dprint_fmt(2, logger, asmsh_log_lvl_fmt); if(ret > 0) { //unrecoverable error or exit (if ret == 1) ret--; // exit status if(ret) { dprintf(2, "Exit with status %d\n", ret); } break; } //else if (ret < 0) {} //recoverable errors add_history(cmd); } asmsh_cleanup(&sh); return ret; err: asmsh_cleanup(&sh); return 1; }