#include <sys/ioctl.h>
#include "iface-env-inject.h"
+#include "v3_ctrl.h"
-static void usage (char* bin) {
- fprintf(stderr, "usage: %s /dev/v3-vm<N> env-file inject-point-exe\n", bin);
-}
-
int main (int argc, char **argv) {
char *vm_dev, *env_file, *bin_name;
- int vm_fd, err, bytes_read, num_strings;
+ int err, bytes_read, num_strings;
struct stat t_stat;
struct env_data env;
char * strings[MAX_NUM_STRINGS];
FILE * t_fd;
if (argc < 4) {
- usage(argv[0]);
+ v3_usage("<vm device> <env-file> <inject-point-exe>\n\n"
+ "\tenv-file : file containing a list of new-line separated env vars\n\n"
+ "\tinject-point-exe : if this is an exec-hooked inject, use this executable name\n");
+
return -1;
}
strncpy(env.bin_name, bin_name, MAX_STRING_LEN);
- vm_fd = open(vm_dev, O_RDONLY);
- if (vm_fd == -1) {
- fprintf(stderr, "Error opening VM device: %s\n", vm_dev);
- return -1;
- }
-
printf("Transferring control to Palacios\n");
- err = ioctl(vm_fd, V3_VM_ENV_INJECT, &env);
+ err = v3_vm_ioctl(vm_dev, V3_VM_ENV_INJECT, &env);
if (err < 0) {
fprintf(stderr, "Error providing env var data to palacios\n");
return -1;
}
close(t_fd);
- close(vm_fd);
return 0;
}
#include <string.h>
#include "iface-syscall.h"
+#include "v3_ctrl.h"
#define CMD_MAX 10
#define SYSCALL_MAX 256
-static void usage () {
- fprintf(stderr, "\nusage: v3_syscall <vm device> <syscall_nr> <on|off|status>\n");
- exit(0);
+static void usage (char * argv[]) {
+ v3_usage("<vm device> <syscall_nr> <on|off|status>\n");
}
-
int main (int argc, char * argv[]) {
- int vm_fd, ret, syscall_nr;
+ int ret, syscall_nr;
char * vm_dev = NULL;
struct v3_syscall_cmd syscall_cmd;
if (argc < 4 || argc > 4) {
fprintf(stderr, "Invalid number of arguments.\n");
- usage();
+ usage(argv);
}
vm_dev = argv[1];
syscall_cmd.cmd = SYSCALL_STAT;
} else {
fprintf(stderr, "Invalid command.\n");
- usage();
+ usage(argv);
}
if (syscall_nr < 0 || syscall_nr > SYSCALL_MAX) {
syscall_cmd.syscall_nr = syscall_nr;
- vm_fd = open(vm_dev, O_RDONLY);
-
- if (vm_fd < 0) {
- fprintf(stderr, "Error opening VM device: %s\n", vm_dev);
- return -1;
- }
-
- ret = ioctl(vm_fd, V3_VM_SYSCALL_CTRL, &syscall_cmd);
+ ret = v3_vm_ioctl(vm_dev, V3_VM_SYSCALL_CTRL, &syscall_cmd);
if (ret < 0) {
fprintf(stderr, "Error with syscall control\n");
#include <sys/ioctl.h>
#include "iface-code-inject.h"
+#include "v3_ctrl.h"
#define __ELF_INJECT_CLASS 32
#define _ElfW_1(e,w,t) e##w##t
-static void usage (char* bin) {
- fprintf(stderr, "usage: %s /dev/v3-vm<N> <inject-code> <code-entry-offset> [inject-point-exe]\n", bin);
-}
-
-
/* look for PT_DYNAMIC to see if it's dynamically linked */
static int is_dynamic (ElfW(Ehdr) * ehdr) {
int i;
char *vm_dev = NULL;
char *top_half = NULL;
char *bin_file = NULL;
- int vm_fd, t_fd, err, bytes_read, entry;
+ int t_fd, err, bytes_read, entry;
struct stat t_stat;
struct top_half_data elf;
ElfW(Ehdr) * elf_hdr;
if (argc < 4 || argc > 5) {
- usage(argv[0]);
+ // TODO: add a better explanation here
+ v3_usage("/dev/v3-vm<N> <inject-code> <code-entry-offset> [inject-point-exe]\n\n"
+ "\tinject-code : the binary file to be injected\n\n"
+ "\tcode-entry-offset : offset in the binary to .text\n\n"
+ "\tinject-point-exe : if exec-hooked injection is used, use this exec name\n");
return -1;
}
/* is it a dynamically linked executable? */
elf.is_dyn = is_dynamic(elf_hdr);
- vm_fd = open(vm_dev, O_RDONLY);
- if (vm_fd == -1) {
- fprintf(stderr, "Error opening VM device: %s\n", vm_dev);
- return -1;
- }
printf("Transferring control to Palacios\n");
- err = ioctl(vm_fd, V3_VM_TOPHALF_INJECT, &elf);
+ err = v3_vm_ioctl(vm_dev, V3_VM_TOPHALF_INJECT, &elf);
if (err < 0) {
fprintf(stderr, "Error providing top half to palacios: %s\n", top_half);
return -1;
free(elf.elf_data);
close(t_fd);
- close(vm_fd);
return 0;
}