Exemplo n.º 1
0
void readcfg(char *filename) {
	FILE *input;
	struct contents *p;
	//p = malloc(sizeof(struct contents));
	if((input = fopen(filename, "r")) == NULL){
		fprintf(stderr, "ERROR: fopen()\n");
		exit(-1);
	}
	if ( (err = load_address(input, vip, vhw, vpt, &vad, &vha,1)) < 0 ){
		load_error(err,"Original Victim");
	}
	if ( (err = load_address(input, aip, ahw, apt, &aad, &aha,1)) < 0 ){
		load_error(err,"Original Attacker");
	}
	if ( (err = load_address(input, rvip, rvmc, vpt, &revi_ip, &revi_mac,0)) < 0 ){
		load_error(err,"Replay Victim");
	}
	if ( (err = load_address(input, ratip, ratmac, apt, &reat_ip, &reat_mac,0)) < 0 ){
		load_error(err,"Replay Attacker");
	}
	if ( fgets(iface, sizeof(iface), input) == NULL ) {
		fprintf(stderr, "Interface too large\n");
		exit(-1);
	}
	rmnl(iface);
	if ( fgets(timing, sizeof(timing), input) == NULL ) {
		fprintf(stderr, "Timing in correct\n");
		exit(-1);
	}
	fclose(input);
	return;
}
Exemplo n.º 2
0
ContentPtr ContentFactory::createContent(const QString& uri)
{
    auto content = _makeContent(uri);
    if (!content->readMetadata())
        throw load_error("Could not read content metadata.");
    return content;
}
Exemplo n.º 3
0
void
main (int argc, char *argv[])
{
    FILE	*fp;
    struct stat	statbuf;

    if (argc != 2) load_error (0);
    fp = fopen (argv[1], "rb");
    if (fp == NULL) load_error (1, argv[1]);
    if (stat (argv[1], &statbuf)) load_error (2, argv[1]);
    if (statbuf.st_size < 24) load_error (5);
    load_elf_exe (fp);

    /* THE ROAD OF NO RETURN!!! */
    run_executable();
}
Exemplo n.º 4
0
FaceDetector::FaceDetector()
{
    if (FLAGS_detector_file.length() > 0) {
        if (!m_classifier.load(FLAGS_detector_file)) {
            throw load_error()
                << boost::errinfo_file_name(FLAGS_detector_file);
        }
    }
}
Exemplo n.º 5
0
ElfDynVal load_getDyn(sElfDyn *dyn,ElfDynTag tag) {
	if(dyn == NULL)
		load_error("No dynamic entries");
	while(dyn->d_tag != DT_NULL) {
		if(dyn->d_tag == tag)
			return dyn->d_un.d_val;
		dyn++;
	}
	return 0;
}
Exemplo n.º 6
0
bool load_hasDyn(sElfDyn *dyn,ElfDynTag tag) {
	if(dyn == NULL)
		load_error("No dynamic entries");
	while(dyn->d_tag != DT_NULL) {
		if(dyn->d_tag == tag)
			return true;
		dyn++;
	}
	return false;
}
Exemplo n.º 7
0
void readcfg1(char *filename) {
	FILE *input;
	
	if((input = fopen(filename, "r")) == NULL){
		fprintf(stderr, "ERROR: fopen()\n");
		exit(-1);
	}

	// Get victim ip, mac, port
	if ( (err = load_address(input, vip, vhw, vpt, &vad, &vha,1)) < 0 )
		load_error(err,"Original Victim");

	// Get attacker ip, mac, port
	if ( (err = load_address(input, aip, ahw, apt, &aad, &aha,1)) < 0 )
		load_error(err,"Original Attacker");

	// Get replay victim, ip, mac and then add original victim port
	if ( (err = load_address(input, rvip, rvmc, vpt, &revi_ip, &revi_mac,0)) < 0 )
		load_error(err,"Replay Victim");

	// Get replay attacker, ip, mac and then add original attacker port
	if ( (err = load_address(input, ratip, ratmac, apt, &reat_ip, &reat_mac,0)) < 0 )
		load_error(err,"Replay Attacker");

	// Get the interface
	if ( fgets(iface, sizeof(iface), input) == NULL ) {
		fprintf(stderr, "Interface too large\n");
		exit(-1);
	}
	rmnl(iface);

	// Get the timing
	if ( fgets(timing, sizeof(timing), input) == NULL ) {
		fprintf(stderr, "Timing in correct\n");
		exit(-1);
	}
	rmnl(timing);
	fclose(input);
}
Exemplo n.º 8
0
/*!
 * \brief Check for a unloaded data on the stream.
 *
 * If there is still data left on the stream (excluding any initial comments),
 * throws an exception with details on the stream position where this occurred.
 * All data left from this position onwards is also returned.
 */
void check_incompleteload(std::istream &is)
   {
   libbase::eatcomments(is);
   if (!is.eof())
      {
      std::ostringstream sout;
      sout << "Incomplete loading, stopped at position " << is.tellg()
            << ", next line:" << std::endl;
      std::string s;
      getline(is, s);
      sout << s;
      throw load_error(sout.str());
      }
   }
Exemplo n.º 9
0
/*!
 * \brief Check for a failure during the last stream input.
 *
 * If the last stream input did not succeed, throws an exception with
 * details on the stream position where this occurred.
 */
void check_failedload(std::istream &is)
   {
   if (is.fail())
      {
      std::ios::iostate state = is.rdstate();
      is.clear();
      std::ostringstream sout;
      sout << "Failure loading object at position " << is.tellg()
            << ", next line:" << std::endl;
      std::string s;
      getline(is, s);
      sout << s;
      is.clear(state);
      throw load_error(sout.str());
      }
   }
Exemplo n.º 10
0
uintptr_t load_setupProg(int binFd,A_UNUSED uintptr_t a,A_UNUSED uintptr_t b,A_UNUSED size_t c,
	int argc,char **argv) {
#else
uintptr_t load_setupProg(int binFd,int argc,char **argv) {
#endif
	sSharedLib *prog;
	uintptr_t entryPoint;

	/* create entry for program */
	prog = (sSharedLib*)malloc(sizeof(sSharedLib));
	if(!prog)
		load_error("Not enough mem!");
	prog->isDSO = false;
	prog->relocated = false;
	prog->initialized = false;
	prog->dynstrtbl = NULL;
	prog->dyn = NULL;
	prog->name = "-Main-";
	prog->deps = NULL;
	appendto(&libs,prog);

	/* load program including shared libraries into linked list */
	load_doLoad(binFd,prog);

	/* load segments into memory */
	entryPoint = load_addSegments();

#if PRINT_LOADADDR
	for(sSharedLib *l = libs; l != NULL; l = l->next) {
		uintptr_t addr;
		lookup_byName(NULL,"_start",&addr);
		debugf("[%d] Loaded %s @ %p .. %p (text @ %p) with deps: ",
				getpid(),l->name,l->loadAddr,l->loadAddr + l->textSize,addr);
		for(sDep *dl = l->deps; dl != NULL; dl = dl->next)
			debugf("%s ",dl->lib->name);
		debugf("\n");
	}
#endif

	/* relocate everything we need so that the program can start */
	load_reloc();

	/* call global constructors */
	load_init(argc,argv);

	return entryPoint;
}
Exemplo n.º 11
0
static void load_relocLib(sSharedLib *l) {
	ElfAddr *got;
	sElfRel *rel;

	/* already relocated? */
	if(l->relocated)
		return;

	/* first go through the dependencies; this may be required for the R_386_COPY-relocation */
	for(sDep *dl = l->deps; dl != NULL; dl = dl->next)
		load_relocLib(dl->lib);

	if(load_hasDyn(l->dyn,DT_TEXTREL))
		load_error("Unable to reloc library %s: requires a writable text segment\n",l->name);

	DBGDL("Relocating %s (loaded @ %p)\n",l->name,l->loadAddr ? l->loadAddr : l->textAddr);

	rel = (sElfRel*)load_getDyn(l->dyn,DT_REL);
	if(rel)
		load_relocDyn(l,rel,load_getDyn(l->dyn,DT_RELSZ),DT_REL);
	rel = (sElfRel*)load_getDyn(l->dyn,DT_RELA);
	if(rel)
		load_relocDyn(l,rel,load_getDyn(l->dyn,DT_RELASZ),DT_RELA);

	/* adjust addresses in PLT-jumps */
	if(l->jmprel) {
		load_relocDyn(l,(void*)((uintptr_t)l->jmprel - l->loadAddr),
			load_getDyn(l->dyn,DT_PLTRELSZ),l->jmprelType);
	}

	/* store pointer to library and lookup-function into GOT */
	got = (ElfAddr*)load_getDyn(l->dyn,DT_PLTGOT);
	DBGDL("GOT-Address of %s: %p\n",l->name,got);
	if(got) {
		got = (ElfAddr*)((uintptr_t)got + l->loadAddr);
		got[1] = (ElfAddr)l;
		got[2] = (ElfAddr)&lookup_resolveStart;
	}

	l->relocated = true;
	/* no longer needed */
	close(l->fd);
}
Exemplo n.º 12
0
static void load_relocDyn(sSharedLib *l,void *entries,size_t size,uint type) {
	sElfRel *rel = (sElfRel*)((uintptr_t)entries + l->loadAddr);
	sElfRela *rela = (sElfRela*)((uintptr_t)entries + l->loadAddr);
	size_t count = type == DT_REL ? size / sizeof(sElfRel) : size / sizeof(sElfRela);
	for(size_t x = 0; x < count; x++) {
		ulong info,offset,addend;
		if(type == DT_REL) {
			info = rel[x].r_info;
			offset = rel[x].r_offset;
			addend = 0;
		}
		else {
			info = rela[x].r_info;
			offset = rela[x].r_offset;
			addend = rela[x].r_addend;
		}

		int rtype = ELF_R_TYPE(info);
		if(rtype == R_NONE)
			continue;

		size_t symIndex = ELF_R_SYM(info);
		sElfSym *sym = l->dynsyms + symIndex;
		const char *symname = l->dynstrtbl + sym->st_name;
		uintptr_t value = sym->st_value;
		uintptr_t *ptr = (uintptr_t*)(offset + l->loadAddr);

		if(rtype == R_JUMP_SLOT) {
			value = *ptr;
			if(*ptr == 0 || LD_BIND_NOW) {
				if(!lookup_byName(l,symname,&value)) {
					if(!lookup_byName(NULL,symname,&value))
						load_error("Unable to find symbol '%s'\n",symname);
				}
				value -= l->loadAddr;
			}
		}
		/* if the symbol-value is 0, it seems that we have to lookup the symbol now and
		 * store that value instead. TODO I'm not sure if thats correct */
		else if(rtype != R_RELATIVE && (rtype == R_COPY || value == 0)) {
			if(!lookup_byName(l,symname,&value))
				load_error("Unable to find symbol '%s'\n",symname);
			// we'll add that again
			value -= l->loadAddr;
		}

		switch(rtype) {
			case R_COPY:
				memcpy((void*)offset,(void*)(value + l->loadAddr),sym->st_size);
				/* set the GOT-Entry in the library of the symbol to the address we've copied
				 * the value to. TODO I'm not sure if that's the intended way... */
				load_adjustCopyGotEntry(symname,offset);
				break;

			default:
				if(!perform_reloc(l,rtype,offset,ptr,value,addend)) {
					load_error("In library %s: Unknown relocation: off=%p info=%p type=%d addend=%x\n",
						l->name,offset,info,ELF_R_TYPE(info),addend);
				}
				break;
		}

		DBGDL("Rel (%s) off=%p reloc=%p value=%p symbol=%s\n",
		 	load_getRelName(rtype),offset,*ptr,value,symname);
	}
}