Пример #1
0
tws::geoarray::spatial_extent_t
tws::geoarray::read_spatial_extent(const rapidjson::Value& jspatial_extent)
{
  if(!jspatial_extent.IsObject() || jspatial_extent.IsNull())
    throw tws::parse_error() << tws::error_description("error parsing spatial extent in metadata.");

  spatial_extent_t sp_extent;

  const rapidjson::Value& jextent = jspatial_extent["extent"];

  sp_extent.extent = read_extent(jextent);

  const rapidjson::Value& jres = jspatial_extent["resolution"];

  sp_extent.resolution = read_spatial_resolution(jres);

  //const rapidjson::Value& jcrs = jspatial_extent["crs"];

  //if(!jcrs.IsString() || jcrs.IsNull())
    //throw tws::parse_error() << tws::error_description("error in CRS in metadata.");

  //std::string crs = jcrs.GetString();

  //std::pair<std::string,unsigned int> crs_id = te::srs::SpatialReferenceSystemManager::getInstance().getIdFromP4Txt(crs);

  const rapidjson::Value& jsrid = jspatial_extent["srid"];

  if(!jsrid.IsInt() || jsrid.IsNull())
    throw tws::parse_error() << tws::error_description("error reading geoarray srid.");

  sp_extent.crs_code = jsrid.GetUint();

  return sp_extent;
}
Пример #2
0
char *
read_stringtable(FILE *fin, struct exec *exhdr, int *strtbl_sz)
{
	unsigned long length;
	char *p = NULL;

	assert(NULL != fin);

	if (NULL == exhdr) {
		fprintf(stderr, "Trying to read string table, but got no a.out header\n");
		return NULL;
	}

	if (fseek(fin, N_STROFF(*exhdr), SEEK_SET) < 0) {
		fprintf(stderr, "Problem seeking to string table: %s\n",
			strerror(errno));
		return NULL;
	}

	if (fread(&length, sizeof(length), 1, fin) != 1) {
		fprintf(stderr, "Problem reading length of string table: %s\n",
			strerror(errno));
		return NULL;
	}

	if (length >= 4) {
		p = read_extent(fin, length, N_STROFF(*exhdr), __LINE__);
		*strtbl_sz = length;
		printf("\nstring table size %d\n", *strtbl_sz);
	} else  {
		fprintf(stderr, "Problem, length of string table read as %d,"
			" can't be right\n, ", length);
		*strtbl_sz = 0;
	}

	return p;
}
Пример #3
0
int main(int ac, char **av)
{
	FILE *fin = NULL;
	struct exec *exhdr = NULL;
	char *fname = NULL;
	char *stringtable;
	int   strtbl_sz;
	struct relocation_info *data_reloc = NULL, *text_reloc = NULL;
	struct nlist *symbol_table = NULL;
	int show_header       = 0;
	int show_data_reloc   = 0;
	int show_text_reloc   = 0;
	int show_symbol_table = 0;
	int print_symnames    = 1;
	int correspondence    = 0;
	int hdr_info          = 0;
	int opt;

	while (-1 != (opt = getopt(ac, av, "hdtsacxn"))) {
		switch (opt) {
		case 'h': show_header = 1; break;
		case 'x': show_header = hdr_info = 1; break;  /* show_header implied */
		case 'd': show_data_reloc = 1; break;
		case 't': show_text_reloc = 1; break;
		case 's': show_symbol_table = 1; break;
		case 'c': correspondence = 1; break;
		case 'n': print_symnames = 0; break;
		case 'a':
			show_header = show_data_reloc = show_text_reloc = show_symbol_table = correspondence = hdr_info = 1;
			break;
		default: errout:
			fprintf(stderr, "%s: show exec header, relocation and symbol table data\n", av[0]);
			fprintf(stderr, "usage: %s [-h] [-d] [-t] [-s] [-c] [-x] [-a] <filename>\n", av[0]);
			fprintf(stderr, " -h: show exec header\n"
				" -x: show info derivable from exec header \n"
				" -d: show data segment relocations\n"
				" -t: show text segment relocations\n"
				" -c: show symbols that correspond to relocations\n"
				" -s: show symbol table\n"
				" -n: when showing symbol table, don't print symbol names\n"
				" -a: show it all\n");
			return 1;
			break;
		}
	}

	if (0 == show_header && 0 == show_data_reloc && 0 == show_text_reloc &&
		0 == show_symbol_table)
			show_header = show_data_reloc = show_text_reloc = show_symbol_table = correspondence = 1;

	if (optind < ac)
		fname = av[optind];

	if (NULL == fname) {
		fprintf(stderr, "Need a file to examine\n");
		goto errout;
	}

	if (NULL == (fin = fopen(fname, "r"))) {
		fprintf(stderr, "Couldn't open \"%s\" for reading: %s\n",
			fname, strerror(errno));
		return 1;
	}

	if (stat(fname, &attributes) < 0) {
		fprintf(stderr, "Problem on stat(2) of \"%s\": %s\n",
			fname, strerror(errno));
		fclose(fin);
		return 1;
	}

	exhdr = (struct exec *)read_extent(fin, sizeof(*exhdr), 0, __LINE__);

	if (NULL == exhdr) {
		cleanup(fin, 1, exhdr);
		return 2;
	}

	if (show_header) {
		puts("a.out header:");
		run_header(exhdr, hdr_info);
	}

	if (N_BADMAG(*exhdr)) {
		fprintf(stderr, "%s isn't a recognized NetBSD a.out file\n", fname);
		cleanup(fin, 1, exhdr);
		return 3;
	}

	stringtable  = read_stringtable(fin, exhdr, &strtbl_sz);
	data_reloc   = (struct relocation_info *)read_extent(fin, exhdr->a_drsize, N_DRELOFF(*exhdr), __LINE__);
	text_reloc   = (struct relocation_info *)read_extent(fin, exhdr->a_trsize, N_TRELOFF(*exhdr), __LINE__);
	symbol_table = (struct nlist *)          read_extent(fin, exhdr->a_syms,   N_SYMOFF(*exhdr), __LINE__);

	if (show_data_reloc) {
		puts("\nData relocations:");
		run_reloc(exhdr, exhdr->a_drsize, data_reloc, symbol_table, stringtable, strtbl_sz, correspondence);
	}

	if (show_text_reloc) {
		puts("\nText relocations:");
		run_reloc(exhdr, exhdr->a_trsize, text_reloc, symbol_table, stringtable, strtbl_sz, correspondence);
	}

	if (show_symbol_table) {
		puts("\nSymbol table:");
		run_symtable(exhdr, symbol_table, stringtable, strtbl_sz, print_symnames);
	}

	cleanup(fin, 5, exhdr, stringtable, data_reloc, text_reloc, symbol_table);

	return 0;
}
Пример #4
0
/*
 * find_ext()
 *
 * Given a pointer to a (struct hfs_file) and an allocation block
 * number in the file, find the extent record containing that block.
 * Returns a pointer to the extent record on success or NULL on failure.
 * The 'cache' field of 'fil' also points to the extent so it has a
 * reference count of at least 2.
 *
 * Callers must check that fil != NULL
 */
static struct hfs_extent * find_ext(struct hfs_fork *fork, int alloc_block)
{
    struct hfs_cat_entry *entry = fork->entry;
    struct hfs_btree *tr= entry->mdb->ext_tree;
    struct hfs_ext_key target, *key;
    struct hfs_brec brec;
    struct hfs_extent *ext, *ptr;
    int tmp;

    if (alloc_block < 0) {
        ext = &fork->first;
        goto found;
    }

    ext = fork->cache;
    if (!ext || (alloc_block < ext->start)) {
        ext = &fork->first;
    }
    while (ext->next && (alloc_block > ext->end)) {
        ext = ext->next;
    }
    if ((alloc_block <= ext->end) && (alloc_block >= ext->start)) {
        goto found;
    }

    /* time to read more extents */
    if (!HFS_NEW(ext)) {
        goto bail3;
    }

    build_key(&target, fork, alloc_block);

    tmp = hfs_bfind(&brec, tr, HFS_BKEY(&target), HFS_BFIND_READ_LE);
    if (tmp < 0) {
        goto bail2;
    }

    key = (struct hfs_ext_key *)brec.key;
    if ((hfs_get_nl(key->FNum) != hfs_get_nl(target.FNum)) ||
            (key->FkType != fork->fork)) {
        goto bail1;
    }

    read_extent(ext, brec.data, hfs_get_hs(key->FABN));
    hfs_brec_relse(&brec, NULL);

    if ((alloc_block > ext->end) && (alloc_block < ext->start)) {
        /* something strange happened */
        goto bail2;
    }

    ptr = fork->cache;
    if (!ptr || (alloc_block < ptr->start)) {
        ptr = &fork->first;
    }
    while (ptr->next && (alloc_block > ptr->end)) {
        ptr = ptr->next;
    }
    if (ext->start == ptr->start) {
        /* somebody beat us to it. */
        HFS_DELETE(ext);
        ext = ptr;
    } else if (ext->start < ptr->start) {
        /* insert just before ptr */
        ptr->prev->next = ext;
        ext->prev = ptr->prev;
        ext->next = ptr;
        ptr->prev = ext;
    } else {
        /* insert at end */
        ptr->next = ext;
        ext->prev = ptr;
    }
found:
    ++ext->count; /* for return value */
    set_cache(fork, ext);
    return ext;

bail1:
    hfs_brec_relse(&brec, NULL);
bail2:
    HFS_DELETE(ext);
bail3:
    return NULL;
}