main.c 1.06 KB
/*==============================================================================
   main.c : cord main program
==============================================================================*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

#include "proc.h"

main(int argc, char **argv){

    parse_command_line(argc, argv);

    read_orig_binary(); /* read binary */

    if(option.debug)
        dump_procs();

    /*------------------
      open reorder file
    ------------------*/
    read_reorder_files();

    /*------------------
      open new binary
    ------------------*/
    bin.fd_out = open(option.out_file, O_WRONLY|O_CREAT|O_TRUNC, 0755);
    if(bin.fd_out <= 0){
        sysfatal("cannot open %s", option.out_file);
    }

    /*------------------
      copy the entire binary first
    ------------------*/
    bin_copy(bin.fd_in, bin.fd_out);

    reorder_it();

    write_it();

    elf_end(bin.elf);
    elf_end(bin.new_elf);

    post_process_rpt(bin.fd_in, bin.fd_out);
    post_process_line(bin.fd_in, bin.fd_out);
}