Exemple #1
0
static void runtest_keys_valid(const char *json_base_fn)
{
	char *json_fn = test_filename(json_base_fn);
	cJSON *tests = read_json(json_fn);
	assert((tests->type & 0xFF) == cJSON_Array);

	unsigned int idx;

	for (idx = 0; idx < cJSON_GetArraySize(tests); idx++) {

	    cJSON *test = cJSON_GetArrayItem(tests, idx);
	    assert((test->type & 0xFF) == cJSON_Array);
	    assert(cJSON_GetArraySize(test) == 3);

		cJSON *j_base58 = cJSON_GetArrayItem(test, 0);
		cJSON *j_payload = cJSON_GetArrayItem(test, 1);
		assert((j_base58->type & 0xFF) == cJSON_String);
		assert((j_payload->type & 0xFF) == cJSON_String);

		cJSON *j_meta = cJSON_GetArrayItem(test, 2);
		assert((j_meta->type & 0xFF) == cJSON_Object);

		cJSON *j_addrtype = cJSON_GetObjectItem(j_meta, "addrType");
		assert(!j_addrtype || ((j_addrtype->type & 0xFF) == cJSON_String));

		cJSON *j_compress = cJSON_GetObjectItem(j_meta, "isCompressed");
		assert(!j_compress || ((j_compress->type & 0xFF) == cJSON_True) ||
		       ((j_compress->type & 0xFF) == cJSON_False));

		bool is_privkey = ((cJSON_GetObjectItem(j_meta, "isPrivkey")->type & 0xFF) == cJSON_True);
		bool is_testnet = ((cJSON_GetObjectItem(j_meta, "isTestnet")->type & 0xFF) == cJSON_True);

		if (is_privkey) {
			test_privkey_valid_enc(
			    j_base58->valuestring,
				hex2str(j_payload->valuestring),
				((j_compress->type & 0xFF) == cJSON_True),
				is_testnet);
			test_privkey_valid_dec(
				j_base58->valuestring,
				hex2str(j_payload->valuestring),
				((j_compress->type & 0xFF) == cJSON_True),
				is_testnet);
		} else {
			test_pubkey_valid_enc(
				j_base58->valuestring,
				hex2str(j_payload->valuestring),
				j_addrtype->valuestring,
				is_testnet);
			test_pubkey_valid_dec(
				j_base58->valuestring,
				hex2str(j_payload->valuestring),
				j_addrtype->valuestring,
				is_testnet);
		}
	}

	free(json_fn);
	cJSON_Delete(tests);
}
void zrtp_log_print_sessioninfo(zrtp_session_info_t* info)
{
	char buffer[256];
	
	ZRTP_LOG(3,("zrtp"," ZRTP Session sID=%u is ready=%s\n", info->id, info->sas_is_ready?"YES":"NO"));
	ZRTP_LOG(3,("zrtp","    peer client: <%s> V=<%s>\n", info->peer_clientid.buffer, info->peer_version.buffer));
	hex2str(info->zid.buffer, info->zid.length, buffer, sizeof(buffer));
	ZRTP_LOG(3,("zrtp","            zid: %s\n", buffer));
	hex2str(info->peer_zid.buffer, info->peer_zid.length, buffer, sizeof(buffer));
	ZRTP_LOG(3,("zrtp","       peer zid: %s\n", buffer));
	hex2str(info->zid.buffer, info->zid.length, buffer, sizeof(buffer));
	
	ZRTP_LOG(3,("zrtp","     is base256: %s\n", info->sas_is_base256?"YES":"NO"));
	ZRTP_LOG(3,("zrtp","           SAS1: %s\n", info->sas1.buffer));
	ZRTP_LOG(3,("zrtp","           SAS2: %s\n", info->sas2.buffer));
	hex2str(info->sasbin.buffer, info->sasbin.length, buffer, sizeof(buffer));
	ZRTP_LOG(3,("zrtp","        bin SAS: %s\n", buffer));
	ZRTP_LOG(3,("zrtp","            TTL: %u\n", info->secrets_ttl));
	
	ZRTP_LOG(3,("zrtp","           hash: %s\n", info->hash_name.buffer));
	ZRTP_LOG(3,("zrtp","         cipher: %s\n", info->cipher_name.buffer));
	ZRTP_LOG(3,("zrtp","           auth: %s\n", info->auth_name.buffer));
	ZRTP_LOG(3,("zrtp","            sas: %s\n", info->sas_name.buffer));
	ZRTP_LOG(3,("zrtp","            pks: %s\n", info->pk_name.buffer));
}
Exemple #3
0
zrtp_status_t zrtp_signaling_hash_set( zrtp_stream_t* ctx,
									   const char *hash_buff,
									   uint32_t hash_buff_length)
{
	if (!ctx) {
		return zrtp_status_bad_param;
	}

	if (ZRTP_MESSAGE_HASH_SIZE*2 < hash_buff_length) {
		return zrtp_status_buffer_size;
	}

	if (ctx->state != ZRTP_STATE_ACTIVE) {
		return zrtp_status_wrong_state;
	}
	
	str2hex( hash_buff,
		     hash_buff_length,
			 ctx->messages.signaling_hash.buffer,
			 ctx->messages.signaling_hash.max_length);
	ctx->messages.signaling_hash.length = ZRTP_MESSAGE_HASH_SIZE;
	
	{
	char buff[64];
	ZRTP_LOG(3, (_ZTU_,"SIGNALLING HAS was ADDED for the comparision. ID=%u\n", ctx->id));
	ZRTP_LOG(3, (_ZTU_,"Hash=%s.\n", hex2str(hash_buff, hash_buff_length, buff, sizeof(buff))));
	}

	return zrtp_status_ok;
}
Exemple #4
0
void print_hex(u32 val)
{
	char str[9];

	hex2str(str,val);
	print_str(str);
}
Exemple #5
0
void drawHex(u32 val, int x, int y)
{
	char str[9];

	hex2str(str,val);
	renderString(str,x,y);
}
Exemple #6
0
/*---------------------------------------------------------------------------*/
zrtp_status_t zrtp_signaling_hash_get( zrtp_stream_t* stream,
									   char *hash_buff,
									   uint32_t hash_buff_length)
{	
	zrtp_string32_t hash_str = ZSTR_INIT_EMPTY(hash_str);
	zrtp_hash_t *hash = NULL;

	if (!stream || !hash_buff) {
		return zrtp_status_bad_param;
	}

	if (ZRTP_SIGN_ZRTP_HASH_LENGTH > hash_buff_length) {
		return zrtp_status_buffer_size;
	}

	if (stream->state < ZRTP_STATE_ACTIVE) {
		return zrtp_status_wrong_state;
	}

	hash = zrtp_comp_find(ZRTP_CC_HASH, ZRTP_HASH_SHA256, stream->zrtp);
	hash->hash_c( hash,
		 	     (const char*)&stream->messages.hello.hdr,
				  zrtp_ntoh16(stream->messages.hello.hdr.length) * 4,
				  ZSTR_GV(hash_str) );

	hex2str(hash_str.buffer, ZRTP_MESSAGE_HASH_SIZE, hash_buff, hash_buff_length);
	
	return zrtp_status_ok;	
}
Exemple #7
0
/*----------------------------------------------------------------------------*/
static zrtp_status_t _attach_secret( zrtp_session_t *session,
									 zrtp_proto_secret_t* psec,
									 zrtp_shared_secret_t* sec,
									 uint8_t is_initiator)
{
	zrtp_uchar32_t buff;
	static const zrtp_string16_t initiator	= ZSTR_INIT_WITH_CONST_CSTRING(ZRTP_ROLE_INITIATOR);
	static const zrtp_string16_t responder	= ZSTR_INIT_WITH_CONST_CSTRING(ZRTP_ROLE_RESPONDER);

	const zrtp_string16_t* role				= is_initiator ? &initiator : &responder;
	const zrtp_string16_t* his_role			= is_initiator ? &responder : &initiator;

	ZSTR_SET_EMPTY(psec->id);
	ZSTR_SET_EMPTY(psec->peer_id);
	psec->secret = sec;

	/*
	 * If secret's value is available (from the cache or from SIP) - use hmac;
	 * use zero-strings in other case.
	 */
	if (psec->secret) {
		session->hash->hmac_truncated( session->hash,
									   ZSTR_GV(sec->value),
									   ZSTR_GVP(role),
									   ZRTP_RSID_SIZE,
									   ZSTR_GV(psec->id));

		session->hash->hmac_truncated( session->hash,
									   ZSTR_GV(sec->value),
									   ZSTR_GVP(his_role),
									   ZRTP_RSID_SIZE,
									   ZSTR_GV(psec->peer_id));
	} else {
		psec->id.length = ZRTP_RSID_SIZE;
		zrtp_memset(psec->id.buffer, 0, psec->id.length);

		psec->peer_id.length = ZRTP_RSID_SIZE;
		zrtp_memset(psec->peer_id.buffer, 0, psec->peer_id.length);
	}

	ZRTP_LOG(3,(_ZTU_,"\tAttach RS id=%s.\n",
				hex2str((const char*)psec->id.buffer, psec->id.length, (char*)buff, sizeof(buff))));
	ZRTP_LOG(3,(_ZTU_,"\tAttach RS peer_id=%s.\n",
				hex2str((const char*)psec->peer_id.buffer, psec->peer_id.length, (char*)buff, sizeof(buff))));

	return zrtp_status_ok;
}
Exemple #8
0
hash_stat hash_plugin_parse_hash(char *hashline, char *filename)
{
    char username[HASHFILE_MAX_LINE_LENGTH];
    char hash[HASHFILE_MAX_LINE_LENGTH];
    char salt[HASHFILE_MAX_LINE_LENGTH];
    char line[HASHFILE_MAX_LINE_LENGTH];
    char line2[HASHFILE_MAX_LINE_LENGTH];
    char *temp_str;
    
    if (!hashline) return hash_err;
    
    if (strlen(hashline)<2) return hash_err;
    
    snprintf(line, HASHFILE_MAX_LINE_LENGTH-1, "%s", hashline);
    strcpy(username, strtok(line, ":"));
    temp_str=strtok(NULL,":");
    if (temp_str) 
    {
	strcpy(hash, temp_str);
    }

    /* Hash is not 32 characters long => not a md5 hash */
    if ((strlen(hash)!=32)&&(strlen(username)!=32))
    {
	return hash_err;
    }
    
    /* No hash provided at all */
    if (strcmp(username,hashline)==0)
    {
	return hash_err;
    }

    /* salt */
    temp_str=strtok(NULL,":");
    if (temp_str) 
    {
	if (strlen(salt)>32) return hash_err;
	strcpy(salt, temp_str);
    }
    else
    {
	strcpy(salt,hash);
	strcpy(hash,username);
	strcpy(username,"N/A");
    }

    strlow(hash);
    hex2str(line2, hash, 32);
    (void)hash_add_username(username);
    (void)hash_add_hash(line2, 16);
    (void)hash_add_salt(salt);
    (void)hash_add_salt2("");

    return hash_ok;
}
Exemple #9
0
void Immediate::repr(int indentlevel){
	std::string indenter(indentlevel, '\t');
	clog << indenter << "<Immediate>" << endl;
	if (m_data.size() == 0)
		clog << indenter << "\t<value>uninitialized</value>"<<endl;	
	else
		clog << indenter << "\t<value>" << hex2str(&m_data[0], m_data.size()) << "</value>"<< endl;
//		clog << indenter << "\t<accessmode>" << accessmodeLUT[(uint8_t)Operand::getAccessMode() >> 2] << "</accessmode>" <<  endl;
	clog << indenter << "</Immediate>" << endl;
}
Exemple #10
0
hash_stat hash_plugin_parse_hash(char *hashline, char *filename)
{
    char username[256];
    char *hash = alloca(256);
    //char line[HASHFILE_MAX_LINE_LENGTH];
    char line[256];
    char *line2 = alloca(256);
    char *temp_str;
    int len;
    
    if (!hashline) return hash_err;
    if (strlen(hashline)>256) return hash_err;
    if (strlen(hashline)<2) return hash_err;
    
    snprintf(line, HASHFILE_MAX_LINE_LENGTH-1, "%s", hashline);
    strcpy(username, strtok(line, ":"));
    temp_str = strtok(NULL,":");
    if (!temp_str)
    {
	temp_str = alloca(256);
	strcpy(temp_str,username);
	strcpy(username,"N/A");
    }
    
    len = strlen(temp_str);

    /* Bad constant header */
    if (!strstr(temp_str,"0x0200"))
    {
	return hash_err;
    }

    /* Bad hash */
    if (strlen(temp_str)!=142)
    {
	return hash_err;
    }

    (void)hash_add_username(username);
    strcpy(line2,strlow(temp_str));

    /* Skip header, add salt, skip case-sensitive hash, get uppercase one */
    strcpy(line, line2+14);
    line[128] = 0;
    hex2str(hash, line, 128);
    (void)hash_add_hash((char *)hash, 64);

    strncpy(line, line2+6, 8);
    line[8]=0;
    (void)hash_add_salt(line);
    (void)hash_add_salt2("");

    return hash_ok;
}
Exemple #11
0
static const char *hex2utf8( const char *src, char *dest )
{
	char sz[256] = {0} ;
	int nsrc = hex2str( src, sz ) ;

	int len = 1024 ;
	if( g2u( (char *)sz , nsrc , dest , len ) == -1 ){
		OUT_ERROR( NULL, 0, NULL , "locale2utf8 query %s failed" , sz ) ;
		return NULL ;
	}
	dest[len] = 0 ;
	return dest ;
}
Exemple #12
0
static int LUA_C_hex2str(lua_State* ls)
  {
  const int argc = lua_gettop(ls);
  if(argc < 1)  return 0;

  size_t l = 0;
  auto s = luaL_checklstring(ls, 1, &l);

  const bool isup = lua_toboolean(ls, 2);

  lua_pushstring(ls, hex2str(string(s, l), isup).c_str());
  return 1;
  }
Exemple #13
0
/* Same as hex2str but this function allocated a new string.  Returns
   NULL on error.  If R_COUNT is not NULL, the number of scanned bytes
   will be stored there.  ERRNO is set on error. */
char *
hex2str_alloc (const char *hexstring, size_t *r_count)
{
  const char *tail;
  size_t nbytes;
  char *result;

  tail = hex2str (hexstring, NULL, 0, &nbytes);
  if (!tail)
    {
      if (r_count)
        *r_count = 0;
      return NULL;
    }
  if (r_count)
    *r_count = tail - hexstring;
  result = xtrymalloc (nbytes+1);
  if (!result)
    return NULL;
  if (!hex2str (hexstring, result, nbytes+1, NULL))
    BUG ();
  return result;
}
Exemple #14
0
void decrypt()
{
	int n, x;
	char *plain, *cypher;

	for ( x = 0 ; x < nAccounts ; x++ )
	{
		cypher = hex2str(pAccounts[x]->cyphertext);
		plain  = pAccounts[x]->plaintext;

		for ( n = 0 ; n < (strlen(cypher)-1) ; n++ )
		{
			plain[n] = cypher[n] ^ key[n];
		}
	}
}
Exemple #15
0
hash_stat hash_plugin_parse_hash(char *hashline, char *filename)
{
    char username[HASHFILE_MAX_LINE_LENGTH];
    char hash[HASHFILE_MAX_LINE_LENGTH];
    char line[HASHFILE_MAX_LINE_LENGTH];
    char *temp_str;
    char line2[HASHFILE_MAX_LINE_LENGTH];
    
    
    if (!hashline) return hash_err;
    
    if (strlen(hashline)<2) return hash_err;
    
    snprintf(line, HASHFILE_MAX_LINE_LENGTH-1, "%s", hashline);
    bzero(username,20);
    strcpy(username, strtok(line, ":"));
    temp_str=strtok(NULL,":");
    if (temp_str) 
    {
	if (temp_str[0]=='$') strcpy(hash, temp_str+1); // Strip $
	else strcpy(hash, temp_str);
    }

    /* Hash is not 40 characters long => not a smf hash */
    if (strlen(hash)!=40)
    {
	return hash_err;
    }
    
    /* No hash provided at all */
    if (strcmp(username,hashline)==0)
    {
	return hash_err;
    }
    
    strlow(hash);
    hex2str(line2, hash, 40);
    
    (void)hash_add_username(username);
    (void)hash_add_hash(line2, 20);
    (void)hash_add_salt("   ");
    (void)hash_add_salt2("");

    return hash_ok;
}
Exemple #16
0
int main(int argc, char **argv)
{
    if (argc != 2) {
        printf("Usage : %s <shellcode>\n", argv[0]);
        printf("\nDifferent shellcode formats are allowed :\n");
        printf("\t%s \"31 c0 50 68 2f 2f 73 68 68 2f 62 69 6e 89 e3 89 c1 89 c2 b0 0b cd 80 31 c0 40 cd 80\"\n", argv[0]);
        printf("\t%s \"0x31 0xc0 0x50 0x68 0x2f 0x2f 0x73 0x68 0x68 0x2f 0x62 0x69 0x6e 0x89 0xe3 0x89 0xc1 0x89 0xc2 0xb0 0x0b 0xcd 0x80 0x31 0xc0 0x40 0xcd 0x80\"\n", argv[0]);
        printf("\t%s \"\\x31 \\xc0 \\x50 \\x68 \\x2f \\x2f \\x73 \\x68 \\x68 \\x2f \\x62 \\x69 \\x6e \\x89 \\xe3 \\x89 \\xc1 \\x89 \\xc2 \\xb0 \\x0b \\xcd \\x80 \\x31 \\xc0 \\x40 \\xcd \\x80\"\n", argv[0]);
        printf("\t%s \"\\x31\\xc0\\x50\\x68\\x2f\\x2f\\x73\\x68\\x68\\x2f\\x62\\x69\\x6e\\x89\\xe3\\x89\\xc1\\x89\\xc2\\xb0\\x0b\\xcd\\x80\\x31\\xc0\\x40\\xcd\\x80\"\n", argv[0]);
        return 1;
    }
    char *shellcode = hex2str(argv[1]);
    printf("Shellcode Length: %zd\n", strlen(shellcode));
    int (*ret)() = (int(*)())shellcode;
    ret();
    free(shellcode);
    return 0;
}
Exemple #17
0
int Cregact::generate_active_code(uint32_t user_id, char *active_code)   //test !
{
	STRU_ACTIVE_KEY ak;
	char tepCode[sizeof (STRU_ACTIVE_KEY)];

	ak.user_id=user_id;
	ak.pri_key1=FILLKEY1;
	ak.pri_key2=FILLKEY2;
	ak.pri_key3=FILLKEY3;
	ak.now=time(NULL);
	ak.now_next=ak.now+TIME_NEXT_SEP;

	//DES_n(ACT_KEY, (char*)&ak, tepCode, 3); //24 bytes
	des_encrypt_n(ACT_KEY, (char*)&ak, tepCode, 3); //24 bytes
	hex2str(tepCode, sizeof(STRU_ACTIVE_KEY), active_code);

	return (0);
}
Exemple #18
0
hash_stat hash_plugin_parse_hash(char *hashline, char *filename)
{
    char username[255];
    char hash[255];
    char line[255];
    char line2[255];
    char *temp_str=NULL;
    
    if (!hashline) return hash_err;
    
    if (strlen(hashline)<2) return hash_err;
    snprintf(line, 254, "%s", hashline);
    if (strstr(line,":"))
    {
	strcpy(username, strtok(line, ":"));
	temp_str=strtok(NULL,":");
    }
    if (temp_str) 
    {
	strcpy(hash, temp_str);
    }
    else
    {
	strcpy(hash,line);
	strcpy(username,"N/A");
    }

    /* Hash is not 96 characters long => not a sha384 hash*/
    if (strlen(hash)!=96)
    {
	return hash_err;
    }


    (void)hash_add_username(username);
    hex2str(line2, hash, 96);
   
    (void)hash_add_hash(line2, 48);
    (void)hash_add_salt("");
    (void)hash_add_salt2("");

    return hash_ok;
}
Exemple #19
0
int Cregact::gen_mole_emissary_code (uint32_t user_id, char *act)
{
	uint8_t	buf1[16], buf2[16];
	uint32_t tm, rand;

	tm = time(NULL);
	rand = MOLE_EMISSARY_RAND;

	memcpy(buf1, (uint8_t *)&user_id, 4);
	memcpy(buf1+4, (uint8_t *)&rand, 4);
	memcpy(buf1+8, (uint8_t *)&tm, 4);
	memcpy(buf1+12, (uint8_t *)&rand, 4);

	//DES_n (MOLE_EMISSARY_KEY, (char *)buf1, (char *)buf2, 2);
	des_encrypt_n(MOLE_EMISSARY_KEY, (char *)buf1, (char *)buf2, 2);
	hex2str ((char *)buf2, 16, (char *)act);
	//cpDecodeBase64 (buf3, (uint8_t *)act, 32); //32 ---> 24

	return 0;
}
Exemple #20
0
int Cregact::gen_reg_act_code (uint32_t user_id, uint32_t time, uint32_t cnt, uint32_t rand, char *key, char *act)
{
	uint8_t buf1[16], buf2[16], buf3[33];

	memcpy (buf1, (uint8_t *)&rand+2, 2);
	memcpy (buf1+2, (uint8_t *)&cnt, 2);
	memcpy (buf1+4, (uint8_t *)&time+2, 2);
	memcpy (buf1+6, (uint8_t *)&rand, 2);
	memcpy (buf1+8, (uint8_t *)&user_id+2, 2);
	memcpy (buf1+10, (uint8_t *)&time, 2);
	memcpy (buf1+12, (uint8_t *)&user_id, 2);
	memcpy (buf1+14, (uint8_t *)&cnt+2, 2);

	//DES_n (key, (char *)buf1, (char *)buf2, 2);
	des_encrypt_n(key, (char *)buf1, (char *)buf2, 2);
	hex2str ((char *)buf2, 16, (char *)buf3);
	cpDecodeBase64 (buf3, (uint8_t *)act, 32); //32 ---> 24

	return (0);
}
Exemple #21
0
static void read_data(void)
{
	if (!opt_hexdata) {
		fprintf(stderr, "no input data\n");
		exit(1);
	}

	cstring *txbuf = hex2str(opt_hexdata);
	if (!txbuf) {
		fprintf(stderr, "invalid input data\n");
		exit(1);
	}
	struct const_buffer cbuf = { txbuf->str, txbuf->len };

	if (!deser_bp_tx(&tx, &cbuf)) {
		fprintf(stderr, "TX decode failed\n");
		exit(1);
	}

	cstr_free(txbuf, true);
}
Exemple #22
0
hash_stat hash_plugin_parse_hash(char *hashline, char *filename)
{
    char line[1024];
    char myhash[32];
    char myhash2[16];
    char mysalt[512];
    char myuser[512];
    int a;

    bzero(mysalt,512);
    
    if (!hashline) return hash_err;
    if (!strstr(hashline,"lastpass")) return hash_err;
    if (!strstr(hashline,"|")) return hash_err;
    if (strlen(hashline)<2) return hash_err;
    
    snprintf(line, 511, "%s", hashline);
    line[511]=0;

    strncpy(mysalt,strtok(line,"|"),511);
    strncpy(myhash,strtok(NULL,"|"),32);

    memset(myuser,0,512);
    a=9;
    while ((mysalt[a]!=':')&&(a<512))
    {
	myuser[a-9]=mysalt[a];
	a++;
    }

    myuser[31]=0;
    hex2str(myhash2, myhash, 32);

    (void)hash_add_username(myuser);
    (void)hash_add_hash(myhash2, 16);
    (void)hash_add_salt(mysalt);
    (void)hash_add_salt2("");
    return hash_ok;
}
Exemple #23
0
GString *parse_script_str(const char *enc)
{
	char **tokens = g_strsplit_set(enc, " \t\n", 0);
	assert (tokens != NULL);

	GString *script = g_string_sized_new(64);

	unsigned int idx;
	for (idx = 0; tokens[idx] != NULL; idx++) {
		char *token = tokens[idx];

		if (is_digitstr(token)) {
			int64_t v = strtoll(token, NULL, 10);
			bsp_push_int64(script, v);
		}

		else if (is_hexstr(token, true)) {
			GString *raw = hex2str(token);
			g_string_append_len(script, raw->str, raw->len);
			g_string_free(raw, TRUE);
		}

		else if ((strlen(token) >= 2) &&
			 (token[0] == '\'') &&
			 (token[strlen(token) - 1] == '\''))
			bsp_push_data(script, &token[1], strlen(token) - 2);

		else if (GetOpType(token) != OP_INVALIDOPCODE)
			bsp_push_op(script, GetOpType(token));

		else
			assert(!"parse error");
	}

	g_strfreev(tokens);

	return script;
}
Exemple #24
0
// color =  a*255^3 + b*255^2 + g*255 + r
QString getColorStr(unsigned int color)
{
    int high,low;
    QString out;
	int r = color % 256;
	int g = (color / 256) % 256;
	int b = (color / 256/ 256) % 256;
    high=r/16;
    low=r%16;
    out+=QObject::tr("%1%2").arg(hex2str(high)).arg(hex2str(low));
    high=g/16;
    low=g%16;
    out+=QObject::tr("%1%2").arg(hex2str(high)).arg(hex2str(low));
    high=b/16;
    low=b%16;
    out+=QObject::tr("%1%2").arg(hex2str(high)).arg(hex2str(low));
    return out;
}
Exemple #25
0
hash_stat hash_plugin_parse_hash(char *hashline, char *filename)
{
    char username[HASHFILE_MAX_LINE_LENGTH];
    char hash[HASHFILE_MAX_LINE_LENGTH];
    char line[HASHFILE_MAX_LINE_LENGTH];
    char line2[HASHFILE_MAX_LINE_LENGTH];
    char *temp_str;
    
    if (!hashline) return hash_err;
    if (strlen(hashline)<2) return hash_err;
    
    snprintf(line, HASHFILE_MAX_LINE_LENGTH-1, "%s", hashline);
    strcpy(username, strtok(line, ":"));
    temp_str=strtok(NULL,":");
    if (temp_str) 
    {
        strcpy(hash, temp_str);
    }
    else return hash_err;
    /* Hash is not 32 characters long => not a mscash2 hash */
    if ((strlen(hash)!=32))
    {
        return hash_err;
    }


    strlow(hash);
    hex2str(line2, hash, 32);

    (void)hash_add_username(username);
    (void)hash_add_hash(line2, 16);
    (void)hash_add_salt(" ");
    (void)hash_add_salt2("");

    return hash_ok;
}
Exemple #26
0
static void runtest(bool is_valid, const char *basefn)
{
	char *fn = test_filename(basefn);
	json_t *tests = read_json(fn);
	assert(json_is_array(tests));

	struct bp_hashtab *input_map = bp_hashtab_new_ext(
		input_hash, input_equal,
		free, input_value_free);

	comments = parr_new(8, free);

	unsigned int idx;
	for (idx = 0; idx < json_array_size(tests); idx++) {
		json_t *test = json_array_get(tests, idx);

		if (!json_is_array(json_array_get(test, 0))) {
			const char *cmt =
				json_string_value(json_array_get(test, 0));
			if (cmt)
				parr_add(comments, strdup(cmt));
			continue;			/* comments */
		}

		assert(json_is_array(test));
		assert(json_array_size(test) == 3);
		assert(json_is_string(json_array_get(test, 1)));
		assert(json_is_boolean(json_array_get(test, 2)));

		json_t *inputs = json_array_get(test, 0);
		assert(json_is_array(inputs));

		bp_hashtab_clear(input_map);

		unsigned int i;
		for (i = 0; i < json_array_size(inputs); i++) {
			json_t *input = json_array_get(inputs, i);
			assert(json_is_array(input));

			const char *prev_hashstr =
				json_string_value(json_array_get(input, 0));
			int prev_n =
				json_integer_value(json_array_get(input, 1));
			const char *prev_pubkey_enc =
				json_string_value(json_array_get(input, 2));

			assert(prev_hashstr != NULL);
			assert(json_is_integer(json_array_get(input, 1)));
			assert(prev_pubkey_enc != NULL);

			struct bp_outpt *outpt;
			outpt = malloc(sizeof(*outpt));
			hex_bu256(&outpt->hash, prev_hashstr);
			outpt->n = prev_n;

			cstring *script = parse_script_str(prev_pubkey_enc);
			assert(script != NULL);

			bp_hashtab_put(input_map, outpt, script);
		}

		const char *tx_hexser =
			json_string_value(json_array_get(test, 1));
		assert(tx_hexser != NULL);

		bool enforce_p2sh = json_is_true(json_array_get(test, 2));

		cstring *tx_ser = hex2str(tx_hexser);
		assert(tx_ser != NULL);

		test_tx_valid(is_valid, input_map, tx_ser, enforce_p2sh);

		cstr_free(tx_ser, true);

		if (comments->len > 0) {
			parr_free(comments, true);
			comments = parr_new(8, free);
		}
	}

	parr_free(comments, true);
	comments = NULL;

	bp_hashtab_unref(input_map);
	json_decref(tests);
	free(fn);
}
Exemple #27
0
int wmmp_sendAppData(int flowID, char *buf, int len)
{
	char cmdbuf[128];
	char ctrlz[1]={0x1A};
	int tmplen;
	int transID1,transID2;
	int rc;
	int wlen;
	int readlen;

	char sendbuf[APP_SEND_PACKET_MAXLEN*2+1]="";

	char *rp;

	rp = buf;

	int i = 0;

	do
	{
		tmplen = len > APP_SEND_PACKET_MAXLEN ? APP_SEND_PACKET_MAXLEN : len;
//		check status
//		DEBUG_PRINTF(("WMMP get status \n"));
//		rc = wmmp_checkStatus();
//		if( rc != 0 )
//		{
//			DEBUG_PRINTF(("WMMP ready for operation \n"));
//			goto ExitProcessing;
//		}

		//flush input buffer
		modem_flushInputBuffer();
		//send cmd
		DEBUG_PRINTF(("WMMP send cmd \n"));
		sprintf( cmdbuf, "AT$M2MAPPSEND=%d", flowID);
		modem_sendCmd( cmdbuf );
		
// 		printf("**i = %d tmplen = %d", i++, tmplen);
// 		printf("**send cmdbuf = %s", cmdbuf);
		

		DEBUG_PRINTF(("WMMP wait for prompt \n"));
//		rc = modem_waitFor(">",10);
//		if(rc != 0)
//		{
//			DEBUG_PRINTF(("WMMP get prompt error: %x\n",rc));
//			goto ExitProcessing;
//		}
		rc = wmmp_waitResponse(NULL,20);
		if (rc != 0)
		{
			DEBUG_PRINTF("error: rc = %x\n",rc);
			goto ExitProcessing;
		}
		

		if(wmmp_rx_buf.enumResponseType != RESPONSE_PROMPT)
		{
			DEBUG_PRINTF("unexpected response: %d\n",wmmp_rx_buf.enumResponseType);
			rc = MODEM_ERROR_NUM(MODEM_ERROR_WMMP,ERROR_WMMP_BAD_RESPONSE);
			goto ExitProcessing;
		}
#if 0
		//RAW data mode
		//write data
		DEBUG_PRINTF("WMMP send data,len =%d\n",tmplen);
		modem_write( rp, tmplen );
		//terminate
		modem_write( ctrlz, 1 );
#else
		//HEX encoded data mode
		//HEX encode the output data
		wlen = hex2str(rp,tmplen,sendbuf,(APP_SEND_PACKET_MAXLEN*2+1));

		//write data
		DEBUG_PRINTF("WMMP send data,len =%d\n",wlen);

		modem_write( sendbuf, wlen );
		//terminate
		modem_write( ctrlz, 1 );
#endif
		//wait response
		DEBUG_PRINTF("WMMP wait response \n");
		rc = wmmp_waitResponse("$M2MAPPSEND",20);

		if (rc != 0)
		{
			DEBUG_PRINTF("error: rc = %x\n",rc);
			goto ExitProcessing;
		}
//		printf("rev1 = %s\n", wmmp_rx_buf.line[0]);
		if(wmmp_rx_buf.enumResponseType != RESPONSE_WMMP_CMD_OK)
		{
			DEBUG_PRINTF("unexpected response: %d\n",wmmp_rx_buf.enumResponseType);
			rc = MODEM_ERROR_NUM(MODEM_ERROR_WMMP,ERROR_WMMP_BAD_RESPONSE);
			goto ExitProcessing;
		}

		if(sscanf(wmmp_rx_buf.line[0],"$M2MAPPSEND: %d",&transID1) != 1)
		{
			DEBUG_PRINTF("transID not found\n");
			rc = MODEM_ERROR_NUM(MODEM_ERROR_WMMP,ERROR_WMMP_BAD_RESPONSE);
			goto ExitProcessing;
		}

		DEBUG_PRINTF("transID1 = %d\n",transID1);
#if 1
		//wait async acks
		DEBUG_PRINTF("WMMP wait response \n");
		rc = wmmp_waitResponse(NULL,20);

		if (rc != 0)
		{
			DEBUG_PRINTF("error: rc = %x\n",rc);
			goto ExitProcessing;
		}
//		printf("rev2 = %s\n", wmmp_rx_buf.line[0]);
		if(wmmp_rx_buf.enumResponseType != RESPONSE_WMMP_ACK)
		{
			DEBUG_PRINTF("unexpected response: %d\n",wmmp_rx_buf.enumResponseType);
			rc = MODEM_ERROR_NUM(MODEM_ERROR_WMMP,ERROR_WMMP_BAD_RESPONSE);
			goto ExitProcessing;
		}

		if(sscanf(wmmp_rx_buf.line[0],"$M2MACK: %d",&transID2) != 1)
		{
			DEBUG_PRINTF("transID not found\n");
			rc = MODEM_ERROR_NUM(MODEM_ERROR_WMMP,ERROR_WMMP_BAD_RESPONSE);
			goto ExitProcessing;
		}

		DEBUG_PRINTF("transID2 = %d\n",transID2);
		if(transID1 != transID2)
		{
			DEBUG_PRINTF("transID1 != transID2. transID1=%d, transID2=%d\n",transID1,transID2);
			rc = MODEM_ERROR_NUM(MODEM_ERROR_WMMP,ERROR_WMMP_BAD_RESPONSE);
			goto ExitProcessing;
		}
#endif
/*
#if 1	//add by yy 20110818
		//wait async $MSG
		DEBUG_PRINTF("WMMP wait response \n");
		printf("**WMMP wait response $MSG \n"); //for debug
		rc = wmmp_waitResponse(NULL,20);

		if (rc != 0)
		{
			DEBUG_PRINTF("**error: rc = %x\n",rc);
			goto ExitProcessing;
		}
		printf("rev3 = %s", wmmp_rx_buf.line[0]);
		
		if(wmmp_rx_buf.enumResponseType != RESPONSE_WMMP_SEND_MSG)
		{
			DEBUG_PRINTF("**unexpected response: %d\n",wmmp_rx_buf.enumResponseType);
			rc = MODEM_ERROR_NUM(MODEM_ERROR_WMMP,ERROR_WMMP_BAD_RESPONSE);
			goto ExitProcessing;
		}

		DEBUG_PRINTF("here\n");
	//	if(sscanf(wmmp_rx_buf.line[0],"$M2M$MSG: %d, %",&transID2) != 1)
		if(sscanf(wmmp_rx_buf.line[0],"$M2M$MSG: 7,%d,%d",&transID2,&readlen) != 2)
		{
			DEBUG_PRINTF("**transID not found\n");
			rc = MODEM_ERROR_NUM(MODEM_ERROR_WMMP,ERROR_WMMP_BAD_RESPONSE);
			goto ExitProcessing;
		}

		DEBUG_PRINTF("transID2 = %d\n",transID2);
		printf("transID2 = %d\n",transID2); //for debug
		if(transID1 != transID2)
		{
			DEBUG_PRINTF("**transID2 = %d\n",transID2);
			rc = MODEM_ERROR_NUM(MODEM_ERROR_WMMP,ERROR_WMMP_BAD_RESPONSE);
			goto ExitProcessing;
		}
		DEBUG_PRINTF("readlen = %d\n",readlen);
		printf("readlen = %d\n",readlen); //for debug
		//比长度
		if(readlen != tmplen)
		{
			DEBUG_PRINTF("**readlen = %d, tmplen = %d\n",readlen, tmplen);
			rc = MODEM_ERROR_NUM(MODEM_ERROR_WMMP,ERROR_WMMP_BAD_RESPONSE);
			goto ExitProcessing;
		}
		
#endif*/

		//update len and buf pointer
		len -= tmplen;
		rp = buf +tmplen;

	}while( len > 0 );
ExitProcessing:
	return rc;

}
static void __vprintk(const char *fmt, va_list ap)
{
	char buf[128];
	char *p, *p0;
	char c, fill;
	unsigned long long v;
	unsigned int width;
	bool longmode;

	p = buf;

	while (1) {
		c = *fmt++;
		if (c == 0)
			break;
		else if (c == '%') {
			*p = 0;
			console_write(buf);
			p = buf;

			c = *fmt++;

			width = 0;
			p0 = p;
			fill = (c == '0') ? '0' : ' ';
			while (c >= '0' && c <= '9') {
				width = width * 10 + c - '0';
				c = *fmt++;
				if (width >= sizeof(buf) - 1)
					width = 0;
			}

			longmode = false;
			if (c == 'l') {
				longmode = true;
				c = *fmt++;
			}

			switch (c) {
			case 'd':
				if (longmode)
					v = va_arg(ap, long);
				else
					v = va_arg(ap, int);
				p = int2str(v, p);
				p = align(p, p0, width, fill);
				break;
			case 'p':
				*p++ = '0';
				*p++ = 'x';
				v = va_arg(ap, unsigned long);
				p = hex2str(v, p, (unsigned long)-1);
				break;
			case 's':
				console_write(va_arg(ap, const char *));
				break;
			case 'u':
				if (longmode)
					v = va_arg(ap, unsigned long);
				else
					v = va_arg(ap, unsigned int);
				p = uint2str(v, p);
				p = align(p, p0, width, fill);
				break;
			case 'x':
				if (longmode)
					v = va_arg(ap, unsigned long);
				else
				console_write(va_arg(ap, const char *));
				break;
			case 'u':
				if (longmode)
					v = va_arg(ap, unsigned long);
				else
					v = va_arg(ap, unsigned int);
				p = uint2str(v, p);
				p = align(p, p0, width, fill);
				break;
			case 'x':
				if (longmode)
					v = va_arg(ap, unsigned long);
				else
					v = va_arg(ap, unsigned int);
				p = hex2str(v, p, 0);
				p = align(p, p0, width, fill);
				break;
			default:
				*p++ = '%';
				*p++ = c;
				break;
			}
		} else if (c == '\n') {
			*p++ = c;
			*p = 0;
			console_write(buf);
			p = buf;
			*p++ = '\r';
		} else
			*p++ = c;
Exemple #30
0
static void
test_hex2str (void)
{
  static struct {
    const char *hex;
    const char *str;
    int len; /* Length of STR.  This may included embedded nuls.  */
    int off;
    int no_alloc_test;
  } tests[] = {
    /* Simple tests.  */
    { "112233445566778899aabbccddeeff1122",
      "\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff\x11\x22",
      17, 34 },
    { "112233445566778899aabbccddeeff1122 blah",
      "\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff\x11\x22",
      17, 34 },
    { "112233445566778899aabbccddeeff1122\tblah",
      "\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff\x11\x22",
      17, 34 },
    { "112233445566778899aabbccddeeff1122\nblah",
      "\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff\x11\x22",
      17, 34 },
    /* Valid tests yielding an empty string.  */
    { "00",
      "",
      1, 2 },
    { "00 x",
      "",
      1, 2 },
    { "",
      "",
      0, 0 },
    { " ",
      "",
      0, 0 },
    /* Test trailing Nul feature.  */
    { "112233445566778899aabbccddeeff1100",
      "\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff\x11\x00",
      17, 34 },
    { "112233445566778899aabbccddeeff1100 ",
      "\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff\x11\x00",
      17, 34 },
    /* Test buffer size. (buffer is of length 20)  */
    { "6162636465666768696A6b6c6D6e6f70717273",
      "abcdefghijklmnopqrs",
      19, 38 },
    { "6162636465666768696A6b6c6D6e6f7071727300",
      "abcdefghijklmnopqrs",
      20, 40 },
    { "6162636465666768696A6b6c6D6e6f7071727374",
      NULL,
      0, 0, 1 },
    { "6162636465666768696A6b6c6D6e6f707172737400",
      NULL,
      0, 0, 1 },
    { "6162636465666768696A6b6c6D6e6f707172737475",
      NULL,
      0, 0, 1 },

    /* Invalid tests. */
    { "112233445566778899aabbccddeeff1122334",      NULL, 0, 0 },
    { "112233445566778899AABBCCDDEEFF1122334",      NULL, 0, 0 },
    { "112233445566778899AABBCCDDEEFG11223344",     NULL, 0, 0 },
    { "0:0112233445566778899aabbccddeeff11223344",  NULL, 0, 0 },
    { "112233445566778899aabbccddeeff11223344:",    NULL, 0, 0 },
    { "112233445566778899aabbccddeeff112233445",    NULL, 0, 0 },
    { "112233445566778899aabbccddeeff1122334455",   NULL, 0, 0, 1 },
    { "112233445566778899aabbccddeeff11223344blah", NULL, 0, 0 },
    { "0",    NULL, 0, 0 },
    { "00:",  NULL, 0, 0 },
    { "00x",  NULL, 0, 0 },

    { NULL, NULL, 0, 0 }
  };

  int idx;
  char buffer[20];
  const char *tail;
  size_t count;
  char *result;

  for (idx=0; tests[idx].hex; idx++)
    {
      tail = hex2str (tests[idx].hex, buffer, sizeof buffer, &count);
      if (tests[idx].str)
        {
          /* Good case test.  */
          if (!tail)
            fail (idx);
          else if (strcmp (tests[idx].str, buffer))
            fail (idx);
          else if (tail - tests[idx].hex != tests[idx].off)
            fail (idx);
          else if (tests[idx].len != count)
            fail (idx);
        }
      else
        {
          /* Bad case test.  */
          if (tail)
            fail (idx);
        }
    }

  /* Same tests again using in-place conversion.  */
  for (idx=0; tests[idx].hex; idx++)
    {
      char tmpbuf[100];

      assert (strlen (tests[idx].hex)+1 < sizeof tmpbuf);
      strcpy (tmpbuf, tests[idx].hex);

      /* Note: we still need to use 20 as buffer length because our
         tests assume that. */
      tail = hex2str (tmpbuf, tmpbuf, 20, &count);
      if (tests[idx].str)
        {
          /* Good case test.  */
          if (!tail)
            fail (idx);
          else if (strcmp (tests[idx].str, tmpbuf))
            fail (idx);
          else if (tail - tmpbuf != tests[idx].off)
            fail (idx);
          else if (tests[idx].len != count)
            fail (idx);
        }
      else
        {
          /* Bad case test.  */
          if (tail)
            fail (idx);
          if (strcmp (tmpbuf, tests[idx].hex))
            fail (idx); /* Buffer was modified.  */
        }
    }

  /* Test the allocation variant.  */
  for (idx=0; tests[idx].hex; idx++)
    {
      if (tests[idx].no_alloc_test)
        continue;

      result = hex2str_alloc (tests[idx].hex, &count);
      if (tests[idx].str)
        {
          /* Good case test.  */
          if (!result)
            fail (idx);
          else if (strcmp (tests[idx].str, result))
            fail (idx);
          else if (count != tests[idx].off)
            fail (idx);
        }
      else
        {
          /* Bad case test.  */
          if (result)
            fail (idx);
        }
      xfree (result);
    }
}