#include <cli-parser.hpp>
#include <theo/theo.hpp>
#include <xtils.hpp>

int __cdecl main( int argc, const char *argv[] )
{
    argparse::argument_parser_t cli_parser( "theodosis.exe", "Theodosis v2.0" );
    cli_parser.add_argument().names( { "-i", "--input" } ).description( ".lib file path..." ).required( "true" );
    cli_parser.enable_help();

    auto err = cli_parser.parse( argc, argv );
    const auto umtils = xtils::um_t::get_instance();

    if ( err )
    {
        std::cout << err << std::endl;
        return -1;
    }

    if ( cli_parser.exists( "help" ) )
    {
        cli_parser.print_help();
        return 0;
    }

    std::vector< std::uint8_t > lib;
    umtils->open_binary_file( cli_parser.get< std::string >( "i" ), lib );
    theo::engine_t theo( lib );

    auto deadstore_pass = std::make_shared< theo::obf_pass_deadstore_t >( []( theo::iff_t::section_t &iff_section ) {
        std::printf( "> section name = %s\n", iff_section.header.name.to_string().data() );
        std::printf( "> number of instructions = %d\n", iff_section.instrs.size() );
    } );

    theo.push( deadstore_pass );
    theo.run();
    std::getchar();
}