Esempio n. 1
0
// Try to determine if a Unicode codepoint (presumed to be from an untrusted source)
// is "safe" to print to a terminal.
// We try to ban control characters, formatting characters, private-use characters,
// and noncharacters.
// It would be be good to also ban incorrectly-used "combining" and other context-
// sensitive characters, but that's too difficult.
static int is_printable_uchar(de_int32 ch)
{
	struct pr_range { de_int32 n1, n2; };
	static const struct pr_range ranges[] = {
		{ 0x0020, 0x007e },
		{ 0x00a0, 0x200d },
		{ 0x2010, 0x2027 },
		{ 0x202f, 0x2065 },
		{ 0x2070, 0xd7ff },
		{ 0xf900, 0xfdcf },
		{ 0xfdf0, 0xfdff },
		{ 0xfe10, 0xfefe },
		{ 0xff00, 0xffef },
		{ 0xfffd, 0xfffd },
		{ 0x10000, 0x101ff },
		{ 0x1f000, 0x1f9ff }
		// TODO: Whitelist more codepoints
	};
	size_t i;
	const size_t num_ranges = DE_ITEMS_IN_ARRAY(ranges);

	for(i=0; i<num_ranges; i++) {
		if(ch>=ranges[i].n1 && ch<=ranges[i].n2) return 1;
	}
	return 0;
}
Esempio n. 2
0
static const struct ele_id_info *find_ele_id_info(i64 ele_id)
{
	size_t k;
	for(k=0; k<DE_ITEMS_IN_ARRAY(ele_id_info_arr); k++) {
		if(ele_id_info_arr[k].ele_id == ele_id) {
			return &ele_id_info_arr[k];
		}
	}
	return NULL;
}
Esempio n. 3
0
File: png.c Progetto: jsummers/deark
static const struct chunk_type_info_struct *get_chunk_type_info(u32 id)
{
	size_t i;

	for(i=0; i<DE_ITEMS_IN_ARRAY(chunk_type_info_arr); i++) {
		if(id == chunk_type_info_arr[i].id) {
			return &chunk_type_info_arr[i];
		}
	}
	return NULL;
}
Esempio n. 4
0
File: png.c Progetto: jsummers/deark
static void handler_PLTE(deark *c, lctx *d, struct handler_params *hp)
{
	// pal is a dummy variable, since we don't need to keep the palette.
	// TODO: Maybe de_read_palette_rgb shouldn't require the palette to be returned.
	u32 pal[256];
	i64 nentries;

	nentries = hp->dlen/3;
	de_dbg(c, "num palette entries: %d", (int)nentries);
	de_read_palette_rgb(c->infile, hp->dpos, nentries, 3, pal, DE_ITEMS_IN_ARRAY(pal), 0);
}
Esempio n. 5
0
// Caller supplies dsi. This function will set its fields.
static int lookup_ds_info(de_byte recnum, de_byte dsnum, struct ds_info *dsi)
{
	size_t i;

	de_memset(dsi, 0, sizeof(struct ds_info));

	for(i=0; i<DE_ITEMS_IN_ARRAY(ds_info_arr); i++) {
		if(ds_info_arr[i].recnum==recnum && ds_info_arr[i].dsnum==dsnum) {
			*dsi = ds_info_arr[i]; // struct copy
			return 1;
		}
	}

	// Not found
	dsi->recnum = recnum;
	dsi->dsnum = dsnum;
	dsi->dsname = "?";
	return 0;
}
Esempio n. 6
0
File: ogg.c Progetto: jsummers/deark
static void do_identify_bitstream(deark *c, lctx *d, struct stream_info *si, i64 pos, i64 len)
{
	u8 idbuf[16];
	size_t bytes_to_scan;
	size_t k;

	bytes_to_scan = (size_t)len;
	if(bytes_to_scan > sizeof(idbuf)) {
		bytes_to_scan = sizeof(idbuf);
	}

	de_read(idbuf, pos, bytes_to_scan);

	for(k=0; k<DE_ITEMS_IN_ARRAY(stream_type_info_arr); k++) {
		if(!de_memcmp(idbuf, stream_type_info_arr[k].magic,
			stream_type_info_arr[k].magic_len))
		{
			si->sti = &stream_type_info_arr[k];
			si->stream_type = si->sti->stream_type;
			break;
		}
	}

	if(si->stream_type==STREAMTYPE_VORBIS) {
		d->found_vorbis = 1;
	}
	else if(si->stream_type==STREAMTYPE_THEORA) {
		d->found_theora = 1;
	}
	else if(si->stream_type==STREAMTYPE_SKELETON) {
		d->found_skeleton = 1;
	}
	else if(si->sti && (si->sti->flags&0x1)) {
		d->found_ogm = 1;
	}

	if(si->stream_type!=STREAMTYPE_VORBIS && si->stream_type!=STREAMTYPE_THEORA) {
		d->has_non_vorbis_non_theora_stream = 1;
	}

	de_dbg(c, "bitstream type: %s", si->sti?si->sti->name:"unknown");
}
Esempio n. 7
0
void de_register_modules(deark *c)
{
	de_module_getinfo_fn infofunc_list[] = {
#define DE_MODULE(x)      x,
#define DE_MODULE_LAST(x) x
#include "deark-modules.h"
#undef DE_MODULE
#undef DE_MODULE_LAST
	};
	size_t num_modules;
	size_t i;

	num_modules = DE_ITEMS_IN_ARRAY(infofunc_list);

	if(!c->module_info) {
		c->module_info = de_malloc(c, num_modules*sizeof(struct deark_module_info));
	}

	for(i=0; i<num_modules; i++) {
		register_a_module(c, infofunc_list[i]);
	}
}