Esempio n. 1
0
//------------------------------------------------------------------------
inline char *pe_loader_t::asciiz(linput_t *li, uint32 rva, char *buf, size_t bufsize, bool *ok)
{
    bool _ok = vseek(li, rva);
    if ( !_ok && ok != NULL )
        *ok = false;
    return qlgetz(li, -1, buf, bufsize);
}
Esempio n. 2
0
void read_exif_header(FILE *fp, unsigned char *buffer, bool *is_valid, bool *is_little_endian)
{
  //  SOI
  vread(buffer, 2, fp, is_valid);
  vcmp(SOI, buffer, 2, is_valid);

  //  APP1 Marker
  vread(buffer, 2, fp, is_valid);
  vcmp(APP1_MARKER, buffer, 2, is_valid);

  //  EXIF Identifier Code
  vseek(fp, 2, SEEK_CUR, is_valid);   //  Skip (APP1 Length)
  vread(buffer, 6, fp, is_valid);
  vcmp(EXIF_IDENT_CODE, buffer, 6, is_valid);

  //  Byte Order
  vread(buffer, 2, fp, is_valid);

  if(*is_valid && memcmp(TIFF_LITTLE_ENDIAN, buffer, 2) == 0)
    *is_little_endian = true;
  else if(*is_valid && memcmp(TIFF_BIG_ENDIAN, buffer, 2) == 0)
    *is_little_endian = false;
  else
    *is_valid = false;

  //  EXIF Fixed Code
  vread(buffer, 2, fp, is_valid);
  vrev(buffer, 2, is_valid, is_little_endian);
  vcmp(EXIF_FIXED_CODE, buffer, 2, is_valid);

  //  0th IFD Offset
  vread(buffer, 4, fp, is_valid);
  vrev(buffer, 4, is_valid, is_little_endian);

  //  0th IFD
  vseek(fp, todecimal(buffer, 4) - 8, SEEK_CUR, is_valid);

  //  0th IFD Entry Count
  vread(buffer, 2, fp, is_valid);
  vrev(buffer, 2, is_valid, is_little_endian);
}
Esempio n. 3
0
//------------------------------------------------------------------------
inline int pe_loader_t::process_delayed_imports(linput_t *li, pe_import_visitor_t &il)
{
    if ( pe.didtab.rva == 0 )
        return 0;

    if ( transvec.empty() )
        process_sections(li);

    int code = 0;
    uint32 ni = 0;
    bool ok = true;
    while ( true )
    {
        uint32 table = pe.didtab.rva + ni*uint32(sizeof(dimpdir_t));
        if ( !vseek(li, table) )
            break;
        dimpdir_t &id = il.did;
        lread(li, &id, sizeof(id));
        if ( !id.dllname )
            break;
        il.withbase = (id.attrs & DIMP_NOBASE) == 0;
        uval_t base = il.withbase ? 0 : uval_t(get_imagebase());
        ea_t atable = id.diat + base;
        ea_t ltable = id.dint;
        char dll[MAXSTR];
        uint32 off = uint32(il.withbase ? id.dllname - (ea_t)pe.imagebase() : id.dllname);
        asciiz(li, off, dll, sizeof(dll), &ok);
        if ( !ok )
            break;
        ansi2idb(dll);
        code = il.visit_module(dll, atable, ltable);
        if ( code != 0 )
            break;
        code = process_import_table(li, pe, atable, ltable, il);
        if ( code != 0 )
            break;
        ni++;
    }
    return ok || code != 0 ? code : -1;
}
Esempio n. 4
0
int Garlick_vf_seek(void *handle, long offset, int origin) { vseek((VFILE*)handle,offset,origin); return 0; }
Esempio n. 5
0
MAP::MAP(char *fname)
{
	VFILE *f = vopen(fname);
	if (!f)
		err("MAP::MAP() - could not load map %s", fname);

	strcpy(mapfname, fname);
	strlwr(mapfname);

	char signature[8];
	vread(signature, 6, f);
	if (strcmp(signature, maptag))
		err("MAP::MAP() - %s is not a valid mapfile!", fname);

	int version;
	vread(&version, 4, f);
	if (version != MAP_VERSION)
		err("MAP::MAP() - %s is not the correct MAP format version!", fname);
	vread(&version, 4, f); // skip vc offset

	vread(mapname, 256, f);
	vread(vspname, 256, f);
	strcpy(savevspname, vspname); // Overkill 2006-05-21
	vread(musicname, 256, f);
	vread(renderstring, 256, f);
	vread(startupscript, 256, f);

	PlayMusic(musicname);

	startx = starty = 0;
	vread(&startx, 2, f);
	vread(&starty, 2, f);

	std::string s = std::string(fname);
	int offs = s.rfind('\\');
	if (offs >= 0)
	{
		s.replace(offs+1,strlen(fname),vspname);
		tileset = new VSP((char *)s.c_str());
	}
	else
	{
		offs = s.rfind('/');
		if (offs >= 0)
		{
			s.replace(offs+1,strlen(fname),vspname);
			tileset = new VSP((char *)s.c_str());
		}
		else
			tileset = new VSP(vspname);
	}

	vread(&numlayers, 4, f);

	//layers = new Layer*[numlayers];
	layers.resize(numlayers);
	int i;
	for (i=0; i<numlayers; i++)
		layers[i] = new Layer(f);

	mapwidth = layers[0]->width;
	mapheight = layers[0]->height;

	obslayer = new byte[mapwidth*mapheight];
	zonelayer = new word[mapwidth*mapheight];
	cvread(obslayer, mapwidth*mapheight, f);
	cvread(zonelayer, mapwidth*mapheight*2, f);

	vread(&numzones, 4, f);
	zones.resize(numzones);
	for (i=0; i<numzones; i++)
	{
		zones[i] = new Zone;
		zones[i]->percent = zones[i]->method = zones[i]->delay = 0;
		vread(zones[i]->name, 256, f);
		vread(zones[i]->script, 256, f);
		vread(&zones[i]->percent, 1, f);
		vread(&zones[i]->delay, 1, f);
		vread(&zones[i]->method, 1, f);
	}

	vread(&mapentities, 4, f);

	for (i=0; i<mapentities; i++)
	{
		int t=0, x1=0, y1=0, x2=0, y2=0;
		char movescript[256], chrname[256], script[256], description[256];

		vread(&x1, 2, f);
		vread(&y1, 2, f);
		int o1 = vtell(f);
		vseek(f, 22, 1);
		vread(movescript, 256, f);
		vread(chrname, 256, f);
		vread(description, 256, f); // this is actually the description which we dont care about
		vread(script, 256, f); // this is the actual script
		vseek(f, o1, 0);

		int i = AllocateEntity(x1*16, y1*16, chrname);

		entity[i]->description = description;
		entity[i]->script = script;
		vread(&t, 1, f);
		if (!t) t = SOUTH;
		entity[i]->setface(t); t=0;
		vread(&t, 1, f);
		entity[i]->obstructable = t ? true : false; t=0;
		vread(&t, 1, f);
		entity[i]->obstruction = t ? true : false; t=0;
		vread(&t, 1, f);
		entity[i]->autoface = (t!=0); t=0;
		vread(&t, 2, f);
		entity[i]->setspeed(t); t=0;
		vread(&t, 1, f);
		// activation mode FIXME
		vread(&t, 1, f);

		vread(&x1, 2, f);
		vread(&y1, 2, f);
		vread(&x2, 2, f);
		vread(&y2, 2, f);
		switch(t)
		{
			case 0: entity[i]->SetMotionless(); break;
			case 1: entity[i]->SetWanderZone(); break;
			case 2: entity[i]->SetWanderBox(x1, y1, x2, y2); break; //FIXME
			case 3: entity[i]->SetMoveScript(movescript); break;
		}
		t=0; vread(&t, 2, f);
		entity[i]->SetWanderDelay(t);
		vread(&t, 4, f);
		vseek(f, 1024, 1);
		/*
		vread(&tlen, 4, f);
		vread(ename, tlen+1, f);
		// chr filename
		vread(&tlen, 4, f);
		vread(chrfn, tlen+1, f);
		// script
		vread(&tlen, 4, f);
		vread(escript, tlen+1, f);
		// movescript
		vread(&tlen, 4, f);
		vread(emovescript, tlen+1, f);

		vread(&tlen, 4, f);
		vread(&tlen, 4, f);
		int eface, speed, tx, ty;
		vread(&eface, 4, f);
		vread(&speed, 4, f);
		vread(&tx, 4, f);
		vread(&ty, 4, f);

		vread(&x1, 4, f);
		vread(&y1, 4, f);
		vread(&x2, 4, f);
		vread(&y2, 4, f);

		int idx = AllocateEntity(tx*16, ty*16, chrfn);
		entity[idx]->setface(eface);
		entity[idx]->setspeed(speed);
		entity[idx]->script = escript;
		entity[idx]->autoface = (eflags & ENT_AUTOFACE) ? true : false;
		entity[idx]->obstructable = (eflags & ENT_OBSTRUCTED) ? true : false;
		entity[idx]->obstruction = (eflags & ENT_OBSTRUCTS) ? true : false;

		if (method == ENT_MOVESCRIPT) entity[idx]->SetMoveScript(emovescript);
		if (method == ENT_WANDERZONE) entity[idx]->SetWanderZone();
		if (method == ENT_WANDERBOX) entity[idx]->SetWanderBox(x1, y1, x2, y2);*/
	}
	current_map = this;
	se->LoadMapScript(f, mapfname);
	vclose(f);
	se->ExecuteFunctionString(startupscript);
}
Esempio n. 6
0
//------------------------------------------------------------------------
// process all exports of a pe file
// returns -2: could not read expdir, -1: other read errors, 0-ok,
// other values can be returned by the visitor
inline int pe_loader_t::process_exports(linput_t *li, pe_export_visitor_t &pev)
{
    if ( pe.expdir.rva == 0 )
        return 0;
    if ( transvec.empty() )
        process_sections(li);
    if ( !vseek(li, pe.expdir.rva) )
        return -2;

    // process export directory
    bool ok = true;
    char buf[MAXSTR];
    peexpdir_t ed;
    lread(li, &ed, sizeof(ed));
    asciiz(li, ed.dllname, buf, sizeof(buf), &ok);
    ansi2idb(buf);
    int code = pev.visit_expdir(ed, buf);
    if ( code != 0 )
        return code;

    // gather name information
    typedef std::map<int, qstring> names_t;
    names_t names;
    for ( uint32 i=0; i < ed.nnames && ok; i++ )
    {
        ushort ord = ushort(vashort(li, ed.ordtab + i*sizeof(ushort), &ok) + ed.ordbase);
        uint32 rva = valong(li, ed.namtab + i*sizeof(uint32), &ok);
        asciiz(li, rva, buf, sizeof(buf), &ok);
        if ( !win_utf2idb(buf) )
            ansi2idb(buf);
        names[ord] = buf;
    }

    // visit all exports
    uint32 expdir_start_rva = pe.expdir.rva;
    uint32 expdir_end_rva   = pe.expdir.rva+pe.expdir.size;
    for ( uint32 i=0; i < ed.naddrs && ok; i++ )
    {
        uint32 rva = valong(li, ed.adrtab + i*sizeof(uint32), &ok);
        if ( rva != 0 && ok )
        {
            uint32 ord = i + ed.ordbase;
            names_t::iterator p = names.find(ord);
            const char *name = p != names.end() ? p->second.c_str() : "";
            const char *forwarder = NULL;
            if ( rva >= expdir_start_rva && rva < expdir_end_rva )
            {
                asciiz(li, rva, buf, sizeof(buf), &ok);
                char* p = strrchr(buf, '.');
                if ( p != NULL ) *p = '\0';
                ansi2idb(buf);
                if ( p != NULL ) {
                    *p++ = '.';
                    if ( !win_utf2idb(p) )
                        ansi2idb(p);
                }
                forwarder = buf;
            }
            int code = pev.visit_export(rva, ord, name, forwarder);
            if ( code != 0 )
                return code;
        }
    }
    return ok ? 0 : -1;
}