Beispiel #1
0
static void test06(char const* infile,
		   char const* password,
		   char const* outfile,
		   char const* outfile2)
{
    char* buf = NULL;
    unsigned long size = 0;
    read_file_into_memory(infile, &buf, &size);
    qpdf_read_memory(qpdf, infile, buf, size, password);
    qpdf_init_write(qpdf, outfile);
    qpdf_set_static_ID(qpdf, QPDF_TRUE);
    qpdf_set_object_stream_mode(qpdf, qpdf_o_generate);
    qpdf_write(qpdf);
    report_errors();
}
Beispiel #2
0
// ----------------------------------------------------------------
void* file_ingestor_stdio_vopen(void* pvstate, char* prepipe, char* filename) {
	char* file_contents_buffer = NULL;
	size_t file_size = 0;

	if (prepipe == NULL) {
		if (streq(filename, "-")) {
			file_contents_buffer = read_fp_into_memory(stdin, &file_size);
			if (file_contents_buffer == NULL) {
				fprintf(stderr, "%s: Couldn't open standard input for read.\n", MLR_GLOBALS.bargv0);
				exit(1);
			}
		} else {
			file_contents_buffer = read_file_into_memory(filename, &file_size);
			if (file_contents_buffer == NULL) {
				fprintf(stderr, "%s: Couldn't open \"%s\" for read.\n", MLR_GLOBALS.bargv0, filename);
				exit(1);
			}
		}

	} else {
		char* escaped_filename = alloc_file_name_escaped_for_popen(filename);
		char* command = mlr_malloc_or_die(strlen(prepipe) + 3 + strlen(escaped_filename) + 1);
		if (streq(filename, "-"))
			sprintf(command, "%s", prepipe);
		else
			sprintf(command, "%s < %s", prepipe, escaped_filename);
		FILE* input_stream = popen(command, "r");
		if (input_stream == NULL) {
			fprintf(stderr, "%s: Couldn't popen \"%s\" for read.\n", MLR_GLOBALS.bargv0, command);
			perror(command);
			exit(1);
		}
		file_contents_buffer = read_fp_into_memory(input_stream, &file_size);
		if (file_contents_buffer == NULL) {
			fprintf(stderr, "%s: Couldn't open popen output for read: \"%s\".\n", MLR_GLOBALS.bargv0, command);
			exit(1);
		}
		pclose(input_stream);
		free(escaped_filename);
		free(command);
	}
	file_ingestor_stdio_state_t* pstate = mlr_malloc_or_die(sizeof(file_ingestor_stdio_state_t));
	pstate->sof = file_contents_buffer;
	pstate->eof = &file_contents_buffer[file_size];
	return pstate;
}
Beispiel #3
0
void
umain(int argc, char **argv)
{
	int i, r, x, want,fd;
        char * file;
        unsigned char elf_buf[512];
        struct Elf *elf;
        void * fileaddr;


	cprintf("process_module started\n");

        if ((r = open("testmodule.o", O_RDONLY)) < 0)
                return ;
        fd = r;


        // Read elf header
        elf = (struct Elf*) elf_buf;
        if (read(fd, elf_buf, sizeof(elf_buf)) != sizeof(elf_buf)
            || elf->e_magic != ELF_MAGIC ) {
                close(fd);
                cprintf("elf magic %08x want %08x\n", elf->e_magic, ELF_MAGIC);
                return ;
        }


        close(fd);

       //open the file testmodule.o and load it into buffer for processing
       r = read_file_into_memory("testmodule.o");
       if( r < 0) 
       {
          cprintf("Could not open file testmodule.o\n");
          return ;
       }

      //Now that file is read @ given address r . 
      file = ( void * ) r ;

       sys_load_kernel_module(UTEMP,PGSIZE);
      read_and_print_section_headers(file);
}
Beispiel #4
0
int main(int argc, char ** argv) {
  FILE * in;
  if (argc > 1) {
    in = fopen(argv[1], "r");
    if (in == NULL) {
      perror("fopen");
      exit(1);
    }
  }
  else {
    in = stdin;
  }
  
  runner * run = init_runner();
  if (read_file_into_memory(run, in) == -1) {
    exit(1);
  }

  int ret = execute(run);
  printf("\n\n>> ret is %d\n", ret);
}