From 67bfeba1035dedf98d67cb00ea89e550de673aa4 Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Mon, 25 Jan 2021 23:23:42 +0100 Subject: Adds runner and 32-bit-runner to start implementing software interrupts. --- run/run.cpp | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 run/run.cpp (limited to 'run/run.cpp') diff --git a/run/run.cpp b/run/run.cpp new file mode 100644 index 0000000..2f02a7b --- /dev/null +++ b/run/run.cpp @@ -0,0 +1,111 @@ +#include + +#include +#include +#include + +#include +#include + +#include "le_file.hpp" +#include "le_parse_util.hpp" + +#include "common.hpp" + +static boost::asio::io_context io_context; +static le::File file; +static boost::asio::local::stream_protocol::socket connection_socket(io_context); + +static uint32_t message_size; + +void action_handler(boost::system::error_code const& error, size_t) +{ + if(!error) + { + } + + io_context.post([](){ + connection_socket.async_receive(boost::asio::buffer(&message_size, sizeof message_size), 0, action_handler); + }); +} + +void accept_handler(boost::system::error_code const& error) +{ + if(!error) + { + std::vector binary = load_binary(file); + uint32_t base_address = file.object_table.entries.at(file.le_header.EIP_object).reloc_base_address; + uint32_t binary_size = binary.size(); + BinaryLoadMessage message { + .binary_size = binary_size, + .base_address = base_address, + .eip = file.le_header.EIP + base_address + }; + + connection_socket.send(boost::asio::buffer(&message, sizeof message)); + connection_socket.send(boost::asio::buffer(binary, binary.size())); + + io_context.post([](){ + connection_socket.async_receive(boost::asio::buffer(&message_size, sizeof message_size), 0, action_handler); + }); + } +} + +int main(int argc, char* argv[]) +{ + boost::program_options::options_description description; + description.add_options() + ("help,h", "produces this help message") + ("exe,e", boost::program_options::value(), "The LE executable to parse the header for.") + ; + + boost::program_options::variables_map vm; + boost::program_options::store(boost::program_options::parse_command_line(argc, argv, description), vm); + boost::program_options::notify(vm); + + if(vm.count("help")) { + std::cout << description << std::endl; + return 0; + } + + boost::filesystem::path file_path; + if(vm.count("exe")) { + std::string exe_file = vm["exe"].as(); + + if(boost::filesystem::exists(exe_file)) { + if(!boost::filesystem::is_directory(exe_file)) { + file_path = exe_file; + } else { + std::cerr << exe_file << " is a folder" << std::endl; + std::cerr << std::endl; + std::cerr << description << std::endl; + return -1; + } + } else { + std::cerr << "file: " << exe_file << " does not exist" << std::endl; + std::cerr << std::endl; + std::cerr << description << std::endl; + return -1; + } + } else { + std::cerr << "Option \"exe_file\" is required"; + std::cerr << std::endl; + std::cerr << description << std::endl; + return -1; + } + + std::ifstream file_stream(file_path, std::ios::binary); + file_stream.unsetf(std::ios::skipws); + file = le::parse_file(file_stream); + + boost::filesystem::remove(socket_name); + + boost::asio::local::stream_protocol::endpoint ep(socket_name); + boost::asio::local::stream_protocol::acceptor acceptor(io_context, ep); + acceptor.async_accept(connection_socket, accept_handler); + + io_context.run(); + + boost::filesystem::remove(socket_name); + return 0; +} -- cgit v1.2.3-70-g09d2