Пример #1
0
/* 
 * Adapter function to PQunescapeBytea()
 * This function should properly unescape the charactor representation
 * of the binary data returned from PostgreSQL and return raw binary data.
 */
SEXP
RS_PostgreSQL_unescape_bytea(SEXP escapedstring)
{
    SEXP output;
    size_t raw_length;
    const char* strbuffer;
    unsigned char* rawbuffer;
    strbuffer = CHAR(STRING_ELT(escapedstring, 0));
    if(!strbuffer) RS_DBI_errorMessage("strbuffer is NULL!", RS_DBI_ERROR);
    if (strbuffer[0] == '\\' && strbuffer[1] == 'x'){
      /* the new hex fomat */
        int i;
        size_t enc_length = LENGTH(STRING_ELT(escapedstring, 0));
        raw_length = enc_length / 2 - 1;
        output = allocVector(RAWSXP, raw_length);
        rawbuffer = RAW(output);
        for(i = 0; i < raw_length; i++){
          rawbuffer[i] = (hex2n(strbuffer[2+ i*2]) << 4) + hex2n(strbuffer[2+i*2+1]);
        }
        return output;
    }else{ /* the old escape format */
        rawbuffer = PQunescapeBytea((const unsigned char*) strbuffer,  &raw_length);
        /* explicit cast to suppress warning on signedness by clang */
        if(!rawbuffer) RS_DBI_errorMessage("PQunescapeByea Failed", RS_DBI_ERROR);
        output = allocVector(RAWSXP, raw_length);
        memcpy(RAW(output), rawbuffer, raw_length);
        free(rawbuffer);
        return output;
    }
}
Пример #2
0
int
parse_des_key (const char *key_string, krb5_key_data *key_data,
	       const char **error)
{
    const char *p = key_string;
    unsigned char bits[8];
    int i;

    if (strlen (key_string) != 16) {
	*error = "bad length, should be 16 for DES key";
	return 1;
    }
    for (i = 0; i < 8; ++i) {
	int d1, d2;

	d1 = hex2n(p[2 * i]);
	d2 = hex2n(p[2 * i + 1]);
	if (d1 < 0 || d2 < 0) {
	    *error = "non-hex character";
	    return 1;
	}
	bits[i] = (d1 << 4) | d2;
    }
    for (i = 0; i < 3; ++i) {
	key_data[i].key_data_ver  = 2;
	key_data[i].key_data_kvno = 0;
	/* key */
	key_data[i].key_data_type[0]     = ETYPE_DES_CBC_CRC;
	key_data[i].key_data_length[0]   = 8;
	key_data[i].key_data_contents[0] = malloc(8);
	if (key_data[i].key_data_contents[0] == NULL) {
	    *error = "malloc";
	    return ENOMEM;
	}
	memcpy (key_data[i].key_data_contents[0], bits, 8);
	/* salt */
	key_data[i].key_data_type[1]     = KRB5_PW_SALT;
	key_data[i].key_data_length[1]   = 0;
	key_data[i].key_data_contents[1] = NULL;
    }
    key_data[0].key_data_type[0] = ETYPE_DES_CBC_MD5;
    key_data[1].key_data_type[0] = ETYPE_DES_CBC_MD4;
    return 0;
}
Пример #3
0
int cheat_load(FILE *file)
{
	cheat_dat tmp_dat;
	char buf[256];
	int i;
	char first=true;

	cheat_decreate_cheat_map();
	cheat_clear();

	while(!feof(file)){
		if (fgets(buf,256,file) && buf[0]!='\n' && buf[0]!='\r'){
			if (first){
				for (i=0;i<256;i++){
					if (buf[i]=='\n' || buf[i]=='\r'){
						buf[i]='\0';
						break;
					}
				}
				strcpy(tmp_dat.name,buf);
				first=false;
			}
			else{
				for (i=0;i<256;i++){
					if (buf[i]=='\n' || buf[i]=='\r'){
						buf[i]='\0';
						break;
					}
				}
				if (i!=8){
					cheat_clear();
					return 0;
				}
				tmp_dat.code = hex2n(buf[0])<< 4 | hex2n(buf[1]);
				tmp_dat.dat  = hex2n(buf[2])<< 4 | hex2n(buf[3]);
				tmp_dat.adr  = hex2n(buf[6])<<12 | hex2n(buf[7])<<8 | hex2n(buf[4])<<4 | hex2n(buf[5]);
				tmp_dat.enable = true;
				cheats[nCheats++] = tmp_dat;

				first = true;
			}
		}
		if (nCheats >= MAX_CHEATS)
			break;
	}

	cheat_create_cheat_map();

	return 1;
}