Ejemplo n.º 1
0
R_API RBuffer *r_buf_mmap (const char *file, int rw) {
	RBuffer *b = r_buf_new ();
	b->mmap = r_file_mmap (file, rw);
	if (b->mmap && b->mmap->len>0) {
		b->buf = b->mmap->buf;
		b->length = b->mmap->len;
	} else {
		r_buf_free (b);
		return NULL; /* we just freed b, don't return it */
	}
	return b;
}
Ejemplo n.º 2
0
R_API RBuffer *r_buf_mmap (const char *file, int flags) {
	int rw = flags&R_IO_WRITE ? R_TRUE : R_FALSE;
	RBuffer *b = r_buf_new ();
	if (!b) return NULL;
	b->mmap = r_file_mmap (file, rw, 0);
	if (b->mmap) {
		b->buf = b->mmap->buf;
		b->length = b->mmap->len;
		if (b->length == 0) b->empty = 1;
		return b;
	}
	r_buf_free (b);
	return NULL; /* we just freed b, don't return it */
}
Ejemplo n.º 3
0
static int check(RBin *bin) {
	ut8 *h, buf[4];
	int off, ret = false;
	RMmap *m = r_file_mmap (bin->file, false, 0);
	if (!m || !m->buf) {
		r_file_mmap_free (m);
		return false;
	}
	h = m->buf;
	if (m->len >= 0x300 && !memcmp (h, "\xca\xfe\xba\xbe", 4)) {
		// XXX assuming BE
		off = r_read_at_be32 (h, 4 * sizeof (int));
		if (off > 0 && off < m->len) {
			memcpy (buf, h + off, 4);
			if (!memcmp (buf, "\xce\xfa\xed\xfe", 4) ||
				!memcmp (buf, "\xfe\xed\xfa\xce", 4) ||
				!memcmp (buf, "\xfe\xed\xfa\xcf", 4) ||
				!memcmp (buf, "\xcf\xfa\xed\xfe", 4))
				ret = true;
		}
	}
	r_file_mmap_free (m);
	return ret;
}
Ejemplo n.º 4
0
static int check(RBin *bin) {
	ut8 *h, buf[4];
	int off, ret = R_FALSE;
	RMmap *m = r_file_mmap (bin->file, R_FALSE, 0);
	if (!m || !m->buf) {
		r_file_mmap_free (m);
		return R_FALSE;
	}
	h = m->buf;
	if (m->len>=0x300 && !memcmp (h, "\xca\xfe\xba\xbe", 4)) {
		memcpy (&off, h+4*sizeof (int), sizeof (int));
		r_mem_copyendian ((ut8*)&off, (ut8*)&off, sizeof(int), !LIL_ENDIAN);
		if (off > 0 && off < m->len) {
			memcpy (buf, h+off, 4);
			if (!memcmp (buf, "\xce\xfa\xed\xfe", 4) ||
				!memcmp (buf, "\xfe\xed\xfa\xce", 4) ||
				!memcmp (buf, "\xfe\xed\xfa\xcf", 4) ||
				!memcmp (buf, "\xcf\xfa\xed\xfe", 4))
				ret = R_TRUE;
		}
	}
	r_file_mmap_free (m);
	return ret;
}