예제 #1
0
int DYLL_MRBC2_ParseHexData(char **rcs, byte **rct, int *rsz)
{
	char *cs;
	byte *ct, *ict, *cte;
	int i, j, k;

	cs=*rcs;

	ict=*rct; cte=ict+(*rsz);
	if(!ict) { ict=malloc(256); cte=ict+256; }
	ct=ict;

	while(*cs)
	{
		if(*cs<=' ')
		{
			while(*cs && *cs<=' ')cs++;
			continue;
		}
		i=hexbyte(cs);
		if(i<0)break;

		if((ct+1)>cte)
		{
			j=(cte-ict); j=j+(j>>1);
			k=ct-ict;
			ict=realloc(ict, j);
			cte=ict+j; ct=ict+k;
		}

		cs+=2; *ct++=i;
	}
예제 #2
0
파일: gdb_be.c 프로젝트: ops-class/sys161
static
unsigned
getthreadid(const char *s)
{
	char *ign;

	return hexbyte(s, &ign) - 10;
}
char *debug_hash_to_str(char *buf, hash_t *hash)
{
	char *bp = buf;
	uint8_t *raw = hash->bytes;
	for (uint32_t i = 0; i < sizeof(hash_t); i++)
	{
		hexbyte(bp, raw[i]&0xff);
		bp+=2;
	}
	*bp = '\0';
	return buf;
}
예제 #4
0
int main()
{
	char hex[] = "A1BDEF6789454CEF";
	unsigned char *byte;
	int len,i;
	printf("%d  ",strlen(hex));
	len = strlen(hex);
	unsigned char a[8]={0,0,0,0,0,0,0,0};
	byte = hexbyte(hex, a);
	for(i=0;i<8;i++)
	{
	//	printf("%d  ", *(byte+i));
	}
	return 0;
}
예제 #5
0
파일: _objects.c 프로젝트: brosner/dulwich
static PyObject *py_hex_to_sha(PyObject *self, PyObject *py_hexsha)
{
	char *hexsha;
	char sha[20];
	int i;

	if (!PyString_CheckExact(py_hexsha)) {
		PyErr_SetString(PyExc_TypeError, "hex sha is not a string");
		return NULL;
	}

	if (PyString_Size(py_hexsha) != 40) {
		PyErr_SetString(PyExc_ValueError, "hex sha is not 40 bytes long");
		return NULL;
	}

	hexsha = PyString_AsString(py_hexsha);

	for (i = 0; i < 20; i++) {
		sha[i] = (hexbyte(hexsha[i*2]) << 4) + hexbyte(hexsha[i*2+1]);
	}

	return PyString_FromStringAndSize(sha, 20);
}
예제 #6
0
파일: gdb_be.c 프로젝트: ops-class/sys161
static
void
debug_write_mem(struct gdbcontext *ctx, const char *spec)
{
	uint32_t vaddr, length, i;
	uint8_t *bytes;
	const char *curptr;

	// AAAAAAA,LLL:DDDD
	// address,len,data
	vaddr = strtoul(spec, (char **) &curptr, 16);
	length = strtoul(curptr + 1, (char **)&curptr, 16);

	// curptr now points to the ':' which 
	// delimits the length from the data
	// so we advance it a little
	curptr++;

	bytes = domalloc(length);
	for (i=0; i<length; i++) {
		bytes[i] = hexbyte(curptr, (char **) &curptr);
	}

	for (i=0; i<length && (vaddr+i)%4 != 0; i++) {
		if (cpudebug_store_byte(debug_cpu, vaddr+i, bytes[i])) {
			debug_send(ctx, "E03");
			return;
		}
	}
	for (; i+4<=length; i+=4) {
		uint32_t word;
		memcpy(&word, bytes+i, sizeof(uint32_t));
		if (cpudebug_store_word(debug_cpu, vaddr+i, ntohl(word))) {
			debug_send(ctx, "E03");
			return;
		}
	}
	for (; i<length; i++) {
		if (cpudebug_store_byte(debug_cpu, vaddr+i, bytes[i])) {
			debug_send(ctx, "E03");
			return;
		}
	}

	free(bytes);
	debug_send(ctx, "OK");
}
예제 #7
0
static VALUE objectid_from_string(VALUE self, VALUE str)
{
    VALUE oid;
    int i;

    if (!legal_objectid_str(str)) {
        rb_raise(InvalidObjectId, "illegal ObjectId format: %s", RSTRING_PTR(str));
    }

    oid = rb_ary_new2(12);

    for(i = 0; i < 12; i++) {
        rb_ary_store(oid, i, INT2FIX( (unsigned)(hexbyte( RSTRING_PTR(str)[2*i] ) << 4 ) | hexbyte( RSTRING_PTR(str)[2*i + 1] )));
    }

    return rb_class_new_instance(1, &oid, ObjectId);
}
예제 #8
0
static VALUE objectid_from_string(VALUE self, VALUE str)
{
    VALUE oid;
    int i;

    if (!legal_objectid_str(str)) {
      if (TYPE(str) == T_STRING) {
        rb_raise(InvalidObjectId, "illegal ObjectId format: %s", RSTRING_PTR(str));
      } else {
        VALUE inspect;
        inspect = rb_funcall(str, rb_intern("to_s"), 0);
        rb_raise(InvalidObjectId, "not a String: %s", (char *)inspect);
      }
    }

    oid = rb_ary_new2(12);

    for(i = 0; i < 12; i++) {
        rb_ary_store(oid, i, INT2FIX( (unsigned)(hexbyte( RSTRING_PTR(str)[2*i] ) << 4 ) | hexbyte( RSTRING_PTR(str)[2*i + 1] )));
    }

    return rb_class_new_instance(1, &oid, ObjectId);
}
예제 #9
0
파일: bson.c 프로젝트: halayudha/kdengine
void bson_oid_from_string( bson_oid_t *oid, const char *str ) {
    int i;
    for ( i=0; i<12; i++ ) {
        oid->bytes[i] = ( hexbyte( str[2*i] ) << 4 ) | hexbyte( str[2*i + 1] );
    }
}
예제 #10
0
파일: fec_tests.c 프로젝트: ASW27B/stratux
static void hex_to_bytes(const char *s, uint8_t *to)
{
    for (; *s; s += 2)
        *to++ = (uint8_t) hexbyte(s);
}