Esempio n. 1
0
static void load_json_key(json_t *wallet, struct bp_key *key)
{
	json_t *keys_a = json_object_get(wallet, "keys");
	assert(json_is_array(keys_a));

	json_t *key_o = json_array_get(keys_a, 0);
	assert(json_is_object(key_o));

	const char *address_str = json_string_value(json_object_get(key_o, "address"));
	assert(address_str != NULL);

	const char *privkey_address_str = json_string_value(json_object_get(key_o, "privkey_address"));
	assert(privkey_address_str);

	const char *pubkey_str = json_string_value(json_object_get(key_o, "pubkey"));
	assert(pubkey_str != NULL);

	const char *privkey_str = json_string_value(json_object_get(key_o, "privkey"));
	assert(privkey_str != NULL);

	char rawbuf[strlen(privkey_str)];
	size_t buf_len = 0;

	/* decode privkey */
	assert(decode_hex(rawbuf, sizeof(rawbuf), privkey_str, &buf_len) == true);

	assert(bp_privkey_set(key, rawbuf, buf_len) == true);

	/* decode pubkey */
	assert(decode_hex(rawbuf, sizeof(rawbuf), pubkey_str, &buf_len) == true);

	void *pk = NULL;
	size_t pk_len = 0;

	/* verify pubkey matches expected */
	assert(bp_pubkey_get(key, &pk, &pk_len) == true);
	assert(pk_len == buf_len);
	assert(memcmp(rawbuf, pk, pk_len) == 0);

	free(pk);

	/* verify pubkey hash (bitcoin address) matches expected */
	cstring *btc_addr = bp_pubkey_get_address(key, PUBKEY_ADDRESS_TEST);
	assert(strlen(address_str) == btc_addr->len);
	assert(memcmp(address_str, btc_addr->str, btc_addr->len) == 0);

	/* verify the private key address (WIF) */
	cstring *privkey_addr = bp_privkey_get_address(key, PRIVKEY_ADDRESS_TEST);
	assert(strlen(privkey_address_str) == privkey_addr->len);
	assert(memcmp(privkey_address_str, privkey_addr->str, privkey_addr->len) == 0);

	cstr_free(privkey_addr, true);
	cstr_free(btc_addr, true);
}
Esempio n. 2
0
char *telepod_func(char *sender,int32_t valid,cJSON **objs,int32_t numobjs,char *origargstr)
{
    uint64_t satoshis;
    struct coin_info *cp;
    uint32_t crc,ind,height,vout,totalcrc,sharei,M,N;
    char NXTACCTSECRET[1024],coinstr[512],coinaddr[512],otherpubaddr[512],txid[512],pubkey[512],privkey[2048],privkeyhex[2048],*retstr = 0;
    copy_cJSON(NXTACCTSECRET,objs[1]);
    if ( NXTACCTSECRET[0] == 0 && (cp= get_coin_info("BTCD")) != 0 )
        safecopy(NXTACCTSECRET,cp->NXTACCTSECRET,sizeof(NXTACCTSECRET));
    crc = get_API_uint(objs[2],0);
    ind = get_API_uint(objs[3],0);
    height = get_API_uint(objs[4],0);
    copy_cJSON(coinstr,objs[5]);
    satoshis = SATOSHIDEN * get_API_float(objs[6]);
    copy_cJSON(coinaddr,objs[7]);
    copy_cJSON(txid,objs[8]);
    vout = get_API_uint(objs[9],0);
    copy_cJSON(pubkey,objs[10]);
    copy_cJSON(privkeyhex,objs[11]);
    decode_hex((unsigned char *)privkey,(int32_t)strlen(privkeyhex)/2,privkeyhex);
    privkey[strlen(privkeyhex)/2] = 0;
    totalcrc = get_API_uint(objs[12],0);
    sharei = get_API_uint(objs[13],0);
    M = get_API_uint(objs[14],1);
    N = get_API_uint(objs[15],1);
    copy_cJSON(otherpubaddr,objs[16]);
    if ( coinstr[0] != 0 && sender[0] != 0 && valid != 0 )
        retstr = telepod_received(sender,NXTACCTSECRET,coinstr,crc,ind,height,satoshis,coinaddr,txid,vout,pubkey,privkey,totalcrc,sharei,M,N,otherpubaddr);
    else retstr = clonestr("{\"error\":\"invalid telepod received\"}");
    return(retstr);
}
Esempio n. 3
0
char *SuperNET_parsemainargs(struct supernet_info *myinfo,bits256 *wallethashp,bits256 *wallet2privp,char *argjsonstr)
{
    cJSON *exchanges=0,*json = 0;
    char *wallet2fname,*coinargs=0,*secret,*filestr;
    long allocsize;
    bits256 wallethash,wallet2priv;
    int32_t n,len;
    uint8_t secretbuf[8192];
    wallethash = wallet2priv = GENESIS_PRIVKEY;
    if ( argjsonstr != 0 )
    {
        if ( (filestr= OS_filestr(&allocsize,argjsonstr)) != 0 )
        {
            json = cJSON_Parse(filestr);
            free(filestr);
        }
        if ( json != 0 || (json= cJSON_Parse(argjsonstr)) != 0 )
        {
            printf("ARGSTR.(%s)\n",argjsonstr);
            if ( jobj(json,"numhelpers") != 0 )
                IGUANA_NUMHELPERS = juint(json,"numhelpers");
            if ( (secret= jstr(json,"passphrase")) != 0 )
            {
                len = (int32_t)strlen(secret);
                if ( is_hexstr(secret,0) != 0 && len == 128 )
                {
                    len >>= 1;
                    decode_hex(secretbuf,len,secret);
                } else vcalc_sha256(0,secretbuf,(void *)secret,len), len = sizeof(bits256);
Esempio n. 4
0
static void get_heart_data(p16_tcp_heart_data* ptcp_heart_data)
{
	ptcp_heart_data->identify_code = 0x01;		
	get_order_array_by_int(p16pos.cfgverno, ptcp_heart_data->cfgverno, 4);
	decode_hex(p16pos.devphyid, 8, ptcp_heart_data->machine_no);
	//get_order_array_by_int(5,ptcp_heart_data->machine_no,4);//就是devphyid
}
Esempio n. 5
0
static void test_decode(const char *hexstr, const char *base58_str)
{
	size_t hs_len = strlen(hexstr) / 2;
	unsigned char *raw = calloc(1, hs_len);
	size_t out_len;

	bool rc = decode_hex(raw, hs_len, hexstr, &out_len);
	if (!rc) {
		fprintf(stderr, "raw %p, sizeof(raw) %lu, hexstr %p %s\n",
			raw, hs_len, hexstr, hexstr);
		assert(rc);
	}

	cstring *s = base58_decode(base58_str);
	if (memcmp(s->str, raw, out_len < s->len ? out_len : s->len)) {
		dumphex("decode have", s->str, s->len);
		dumphex("decode want", raw, out_len);
		assert(memcmp(s->str, raw, out_len) == 0);
	}
	if (s->len != out_len) {
		fprintf(stderr, "decode len: have %u, want %u\n",
			(unsigned int) s->len,
			(unsigned int) out_len);
		dumphex("decode have", s->str, s->len);
		dumphex("decode want", raw, out_len);
		assert(s->len == out_len);
	}

	free(raw);
	cstr_free(s, true);
}
Esempio n. 6
0
static void test_application_entry_decode(void)
{
	unsigned char *ef_dir;
	long len;
	GSList *entries;
	struct sim_app_record *app[2];

	ef_dir = decode_hex(at_cuad_response, -1, &len, 0);
	entries = sim_parse_app_template_entries(ef_dir, len);

	g_assert(g_slist_length(entries) == 2);

	app[0] = entries->next->data;
	app[1] = entries->data;

	g_assert(app[0]->aid_len == 0x10);
	g_assert(!memcmp(app[0]->aid, &ef_dir[4], 0x10));
	g_assert(app[0]->label == NULL);

	g_assert(app[1]->aid_len == 0x0c);
	g_assert(!memcmp(app[1]->aid, &ef_dir[37], 0x0c));
	g_assert(app[1]->label != NULL);
	g_assert(!strcmp(app[1]->label, "MIDPfiles"));

	g_free(ef_dir);
}
Esempio n. 7
0
int32_t SuperNET_str2hex(uint8_t *hex,char *str)
{
    int32_t len;
    len = (int32_t)strlen(str)+1;
    decode_hex(hex,len,str);
    return(len);
}
Esempio n. 8
0
uint64_t bitcoin_parseunspent(struct iguana_info *coin,struct bitcoin_unspent *unspent,double minconfirms,char *account,cJSON *item)
{
    char *hexstr,coinaddr[64];
    memset(unspent,0,sizeof(*unspent));
    if ( jstr(item,"address") != 0 )
    {
        safecopy(coinaddr,jstr(item,"address"),sizeof(coinaddr));
        bitcoin_addr2rmd160(&unspent->addrtype,unspent->rmd160,coinaddr);
        /*sprintf(args,"[\"%s\"]",coinaddr);
        wifstr = bitcoind_RPC(0,coin->symbol,coin->chain->serverport,coin->chain->userpass,"dumpprivkey",args);
        if ( wifstr != 0 )
        {
            bitcoin_wif2priv(&addrtype,&unspent->privkeys[0],wifstr);
            //printf("wifstr.(%s) -> %s\n",wifstr,bits256_str(str,unspent->privkeys[0]));
            free(wifstr);
        } else fprintf(stderr,"error (%s) cant find privkey\n",coinaddr);*/
    }
    if ( (account == 0 || jstr(item,"account") == 0 || strcmp(account,jstr(item,"account")) == 0) && (minconfirms <= 0 || juint(item,"confirmations") >= minconfirms-SMALLVAL) )
    {
        if ( (hexstr= jstr(item,"scriptPubKey")) != 0 )
        {
            unspent->spendlen = (int32_t)strlen(hexstr) >> 1;
            if ( unspent->spendlen < sizeof(unspent->spendscript) )
                decode_hex(unspent->spendscript,unspent->spendlen,hexstr);
        }
        unspent->txid = jbits256(item,"txid");
        unspent->value = SATOSHIDEN * jdouble(item,"amount");
        unspent->vout = jint(item,"vout");
        //char str[65]; printf("(%s) -> %s %.8f scriptlen.%d\n",jprint(item,0),bits256_str(str,unspent->txid),dstr(unspent->value),unspent->scriptlen);
    } else printf("skip.(%s) minconfirms.%f\n",jprint(item,0),minconfirms);
Esempio n. 9
0
char *single_xor_decode(char *chex) {
    int chexlen = strlen(chex);

    byte *cbytes = decode_hex(chex, chexlen);

    /* Way bigger than any possible score from freq analysis */
    double best = 1000;
    char *best_text = malloc(sizeof(char));
    for (int key = 0; key < 256; key++) {
        byte *dec_bytes = single_xor(cbytes, (char) key, chexlen / 2);
        char *dec_text = as_string(dec_bytes, chexlen / 2);
        double score = fa_score(dec_text);

        if (score < best && (int) strlen(dec_text) == chexlen / 2) {
            free(best_text);
            best = score;
            best_text = dec_text;
        }
        else {
            free(dec_text);
        }

        free(dec_bytes);
    }

    free(cbytes);
    return best_text;
}
Esempio n. 10
0
static int get_rt_transdtl_data(p16_tcp_transdtl* ptcp_rt_transdtl)
{
	int ret = 0;
	p16_transdtl_t transdtl;
	memset(&transdtl,0,sizeof transdtl);
	ret = trans_get_last_record(&transdtl);
	if(ret == 0)
	{
		//LOG((LOG_DEBUG,"无可取的消费流水"));
		return -1;
	}
	//将该条记录设为已读取
	transdtl.confirm = 1;
	ret = trans_update_record(&transdtl);
	if(ret)
	{
		//LOG((LOG_ERROR,"更新交易流水失败"));
		return -2;
	}
	ptcp_rt_transdtl->devseqno= transdtl.devseqno;//表里的devseqno
	get_order_array_by_int(transdtl.cardbefbal, ptcp_rt_transdtl->cardbefbal, 4);
	get_order_array_by_int(transdtl.paycnt, ptcp_rt_transdtl->paycnt, 2);
	get_order_array_by_int(transdtl.cardno, ptcp_rt_transdtl->cardno, 4);
	if(transdtl.transflag == TRANS_WRITE_CARD_OK)
	{
		ptcp_rt_transdtl->transflag = 0x81;//10000001
	}
	else if(transdtl.transflag == TRANS_WRITE_CARD_FAILED)
	{
		ptcp_rt_transdtl->transflag = 0x83;//10000011
	}
	get_order_array_by_int(0, ptcp_rt_transdtl->additional, 3);//附加金额暂时为0
	get_order_array_by_int(transdtl.amount, ptcp_rt_transdtl->transamt, 4);
	decode_hex(transdtl.termno, 12, ptcp_rt_transdtl->termno);
	get_order_array_by_int(0, ptcp_rt_transdtl->machine_no, 4);//机器号暂时填0
	char transdatetime[15] = {0};
	SAFE_GET_DATETIME("%y%m%d%H%M%S", transdatetime);
	get_std_trans_datetime(transdatetime, ptcp_rt_transdtl->transdatetime, 6);
	//decode_hex(transdatetime, 12, ptcp_rt_transdtl->transdatetime);//日期时间
	
		//打印日期时间
	decode_hex(transdtl.tac, 8, ptcp_rt_transdtl->tac);
	int buffer_len = sizeof(p16_tcp_transdtl)-2;
	LOG((LOG_DEBUG,"参与crc的buffer_len=%d",buffer_len));
	pb_protocol_crc((const uint8 *)ptcp_rt_transdtl, buffer_len, ptcp_rt_transdtl->crc);
	return 0;
}
Esempio n. 11
0
int32_t serdes777_convstr(int32_t encoding,void *dest,void *src,int32_t len)
{
    if ( encoding == 16 )
    {
        len >>= 1;
        decode_hex(dest,len,src);
        return(8 * len);
    }
Esempio n. 12
0
//}}}
/////////////////////////////组包函数////////////////////////////////////////
static void get_blacklist_data(p16_tcp_blacklist_data* ptcp_blacklist_data)
{
	//get_order_array_by_int(0,ptcp_blacklist_data->machine_no,4);
	//memset(ptcp_blacklist_data->pos_blacklist_version,0,6);

	decode_hex(p16pos.devphyid, 8, ptcp_blacklist_data->machine_no);
	memcpy(ptcp_blacklist_data->pos_blacklist_version,p16pos.pos_blacklist_version, 6);
}
Esempio n. 13
0
// }}}
// {{{ load_sys_config
static int load_sys_config()
{
    if (SAFE_GET_CONFIG("dev.devphyid", p16pos.devphyid))
        return -1;
	//读取黑名单版本号
	char pos_blacklist_version[13] = {0};
	if(SAFE_GET_CONFIG("dev.pos_blacklist_version",pos_blacklist_version))
		return -1;
	decode_hex(pos_blacklist_version, 12,p16pos.pos_blacklist_version);
    //LOG((LOG_DEBUG,"devphyid: %s",p16pos.devphyid));
    if (SAFE_GET_CONFIG("sys.appid", p16pos.appid))
        return -1;
    if (SAFE_GET_CONFIG("sys.appsecret", p16pos.appsecret))
        return -1;
	//获取前置的ip和端口号
    if (SAFE_GET_CONFIG("svc.remotename", p16pos.remote[REMOTE_WIRE].u.host.host_name))
    {
        return -1;
    }
    if (get_config_int("svc.remoteport", &(p16pos.remote[REMOTE_WIRE].u.host.host_port)))
    {
        return -1;
    }
    if (SAFE_GET_CONFIG("svc.remoteurl", p16pos.service_path))
    {
        return -1;
    }
    int pages;
    if (get_config_int("sys.printerpages", &pages))
    {
        return -1;
    }
    int cfgverno;
    if (get_config_int("sys.cfgverno", &cfgverno))
    {
        p16pos.cfgverno = 0;
		LOG((LOG_DEBUG,"获取sys.cfgverno失败"));
    }
    else
    {
        p16pos.cfgverno = cfgverno;
    }
    p16pos.printer_pages = (uint8)pages;

    if (get_config_int("sys.workmode", &(p16pos.work_mode)))
    {
        p16pos.work_mode = 0;
    }

    if (get_config_int("sys.heartbeatminutes", &(p16pos.heartbeat_minutes)))
    {
        p16pos.heartbeat_minutes = 0;
    }
    //memset( p16pos.termno, 0, sizeof p16pos.termno );
    //memcpy(p16pos.termno,"\x00\x00\x00\x05\x00\x04",6);
    setup_svc_url();
    return 0;
}
Esempio n. 14
0
static void ril_sms_notify(GRilIoChannel *io, guint ril_event,
				const void *data, guint len, void *user_data)
{
	struct ril_sms *sd = user_data;
	GRilIoParser rilp;
	char *ril_pdu;
	int ril_pdu_len;
	unsigned int smsc_len;
	long ril_buf_len;
	guchar *ril_data;

	ril_pdu = NULL;
	ril_data = NULL;

	DBG("event: %d; data_len: %d", ril_event, len);

	grilio_parser_init(&rilp, data, len);
	ril_pdu = grilio_parser_get_utf8(&rilp);
	if (ril_pdu == NULL)
		goto error;

	ril_pdu_len = strlen(ril_pdu);

	DBG("ril_pdu_len is %d", ril_pdu_len);
	ril_data = decode_hex(ril_pdu, ril_pdu_len, &ril_buf_len, -1);
	if (ril_data == NULL)
		goto error;

	/* The first octect in the pdu contains the SMSC address length
	 * which is the X following octects it reads. We add 1 octet to
	 * the read length to take into account this read octet in order
	 * to calculate the proper tpdu length.
	 */
	smsc_len = ril_data[0] + 1;
	ofono_info("sms received, smsc_len is %d", smsc_len);
	DBG("(%s)", ril_pdu);

	if (ril_event == RIL_UNSOL_RESPONSE_NEW_SMS) {
		/* Last parameter is 'tpdu_len' ( substract SMSC length ) */
		ofono_sms_deliver_notify(sd->sms, ril_data, ril_buf_len,
						ril_buf_len - smsc_len);
	} else {
		GASSERT(ril_event == RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT);
		ofono_sms_status_notify(sd->sms, ril_data, ril_buf_len,
						ril_buf_len - smsc_len);
	}

	g_free(ril_pdu);
	g_free(ril_data);
	ril_ack_delivery(sd, TRUE);
	return;

error:
	g_free(ril_pdu);
	g_free(ril_data);
	ril_ack_delivery(sd, FALSE);
	ofono_error("Unable to parse NEW_SMS notification");
}
Esempio n. 15
0
static void test_hex(void)
{
  int       i;
  char      raw_data[32];
  size_t    raw_length;
  uint8_t  *encoded_data;
  uint64_t  encoded_length;
  uint8_t  *decoded_data;
  uint64_t  decoded_length;
  uint8_t   expected_data[32];
  uint64_t  expected_length;

  for(i = 0; i < 256; i++)
  {
    raw_length = sprintf(raw_data, "%c%c%c", i, i, i);
    encoded_data = encode_hex((uint8_t*)raw_data, raw_length, &encoded_length);
    expected_length = sprintf((char*)expected_data, "%02x%02x%02x", i, i, i);
    test_check_memory("encode_hex", expected_data, expected_length, encoded_data, encoded_length);
    free(encoded_data);
  }

  for(i = 0; i < 256; i++)
  {
    raw_length = sprintf(raw_data, "%02x%02x%02x", (uint8_t)(i - 1), (uint8_t)(i), (uint8_t)(i + 1));
    decoded_data = decode_hex((uint8_t*)raw_data, raw_length, &decoded_length);
    expected_length = sprintf((char*)expected_data, "%c%c%c", i - 1, i, i + 1);
    test_check_memory("decode_hex", expected_data, expected_length, decoded_data, decoded_length);
    free(decoded_data);
  }

  /* Side-case: odd numbers of hex digits. */
  decoded_data = decode_hex((uint8_t*)"41424", 5, &decoded_length);
  test_check_memory("decode_hex ('41424')", (uint8_t*)"AB", 2, decoded_data, decoded_length);
  free(decoded_data);

  /* Side-case: non-hex characters in the string. */
  decoded_data = decode_hex((uint8_t*)"414z4", 5, &decoded_length);
  test_check_memory("decode_hex ('414z4')", (uint8_t*)"A", 1, decoded_data, decoded_length);
  free(decoded_data);

  decoded_data = decode_hex((uint8_t*)"4141z4141", 9, &decoded_length);
  test_check_memory("decode_hex ('4141z4141')", (uint8_t*)"AAAA", 4, decoded_data, decoded_length);
  free(decoded_data);
}
Esempio n. 16
0
char *SuperNET_gotpacket(char *msg,int32_t duration,char *ip_port)
{
    static int flood,duplicates;
    cJSON *json;
    uint16_t p2pport;
    struct pserver_info *pserver;
    uint64_t txid;
    struct sockaddr prevaddr;
    int32_t len,createdflag,valid;
    unsigned char packet[2*MAX_JSON_FIELD];
    char ipaddr[64],txidstr[64],retjsonstr[2*MAX_JSON_FIELD],verifiedNXTaddr[64],*cmdstr,*retstr;
    if ( SUPERNET_PORT != _SUPERNET_PORT )
        return(clonestr("{\"error\":private SuperNET}"));
    strcpy(retjsonstr,"{\"result\":null}");
    if ( Debuglevel > 2 )
        printf("gotpacket.(%s) duration.%d from (%s)\n",msg,duration,ip_port);
    if ( Finished_loading == 0 )
    {
        if ( is_hexstr(msg) == 0 )
        {
            //printf("QUEUE.(%s)\n",msg);
            return(block_on_SuperNET(0,msg));
        }
        return(clonestr(retjsonstr));
    }
    p2pport = parse_ipaddr(ipaddr,ip_port);
    uv_ip4_addr(ipaddr,0,(struct sockaddr_in *)&prevaddr);
    pserver = get_pserver(0,ipaddr,0,p2pport);
    len = (int32_t)strlen(msg);
    if ( is_hexstr(msg) != 0 )
    {
        len >>= 1;
        len = decode_hex(packet,len,msg);
        txid = calc_txid(packet,len);//hash,sizeof(hash));
        sprintf(txidstr,"%llu",(long long)txid);
        MTadd_hashtable(&createdflag,&Global_pNXT->msg_txids,txidstr);
        if ( createdflag == 0 )
        {
            duplicates++;
            return(clonestr("{\"error\":\"duplicate msg\"}"));
        }
        if ( (len<<1) == 30 ) // hack against flood
            flood++;
        if ( Debuglevel > 0 )
            printf("gotpacket %d | Finished_loading.%d | flood.%d duplicates.%d\n",duration,Finished_loading,flood,duplicates);
        if ( is_encrypted_packet(packet,len) != 0 )
            process_packet(0,retjsonstr,packet,len,0,&prevaddr,ipaddr,0);
        /*else if ( (obookid= is_orderbook_tx(packet,len)) != 0 )
        {
            if ( update_orderbook_tx(1,obookid,(struct orderbook_tx *)packet,txid) == 0 )
            {
                ((struct orderbook_tx *)packet)->txid = txid;
                sprintf(retjsonstr,"{\"result\":\"SuperNET_gotpacket got obbokid.%llu packet txid.%llu\"}",(long long)obookid,(long long)txid);
            } else sprintf(retjsonstr,"{\"result\":\"SuperNET_gotpacket error updating obookid.%llu\"}",(long long)obookid);
        }*/ else sprintf(retjsonstr,"{\"error\":\"SuperNET_gotpacket cant find obookid\"}");
    }
Esempio n. 17
0
char *dpow_passthru(struct iguana_info *coin,char *function,char *hex)
{
    char params[32768]; int32_t len = 0;
    if ( hex != 0 && hex[0] != 0 )
    {
        len = (int32_t)strlen(hex) >> 1;
        if ( len < sizeof(params)-1 )
            decode_hex((uint8_t *)params,(int32_t)strlen(hex),hex);
        else len = 0;
    }
Esempio n. 18
0
struct tstring *
tstring_hex(const char *hex)
{
  struct tstring *s;
  unsigned length = decode_hex_length(hex);

  s = tstring_alloc(length);

  decode_hex(s->data, hex);
  return s;
}
Esempio n. 19
0
bits256 get_API_bits256(cJSON *obj)
{
    bits256 hash; char *str;
    memset(hash.bytes,0,sizeof(hash));
    if ( obj != 0 )
    {
        if ( is_cJSON_String(obj) != 0 && (str= obj->valuestring) != 0 && strlen(str) == 64 )
            decode_hex(hash.bytes,sizeof(hash),str);
    }
    return(hash);
}
Esempio n. 20
0
struct reply_sim_io *g_ril_reply_parse_sim_io(GRil *gril,
						const struct ril_msg *message)
{
	struct parcel rilp;
	char *response = NULL;
	struct reply_sim_io *reply;

	/*
	 * Minimum length of SIM_IO_Response is 12:
	 * sw1 (int32)
	 * sw2 (int32)
	 * simResponse (string)
	 */
	if (message->buf_len < 12) {
		ofono_error("Invalid SIM IO reply: size too small (< 12): %d ",
			    (int) message->buf_len);
		return NULL;
	}

	reply =	g_new0(struct reply_sim_io, 1);

	g_ril_init_parcel(message, &rilp);
	reply->sw1 = parcel_r_int32(&rilp);
	reply->sw2 = parcel_r_int32(&rilp);

	response = parcel_r_string(&rilp);

	g_ril_append_print_buf(gril,
				"(sw1=0x%.2X,sw2=0x%.2X,%s)",
				reply->sw1,
				reply->sw2,
				response);
	g_ril_print_response(gril, message);

	if (rilp.malformed)
		goto error;

	if (response != NULL) {
		reply->hex_response =
			decode_hex(response, strlen(response),
					(long *) &reply->hex_len, -1);
		g_free(response);

		if (reply->hex_response == NULL)
			goto error;
	}

	return reply;

error:
	g_free(reply);

	return NULL;
}
Esempio n. 21
0
void dpow_addresses()
{
    int32_t i; char coinaddr[64]; uint8_t pubkey[33];
    for (i=0; i<sizeof(Notaries)/sizeof(*Notaries); i++)
    {
        decode_hex(pubkey,33,Notaries[i][1]);
        bitcoin_address(coinaddr,60,pubkey,33);
        printf("%s ",coinaddr);
    }
    printf("Numnotaries.%d\n",i);
}
int32_t shuffle_encrypt(uint64_t nxt64bits,uint8_t *dest,uint8_t *src,int32_t len)
{
    cJSON *item; char *str; int32_t n = 0;
    if ( (item= privatemessage_encrypt(nxt64bits,src,len)) != 0 )
    {
        if ( (str= cJSON_str(item)) != 0 )
        {
            n = (int32_t)strlen(str) >> 1;
            decode_hex(dest,n,str);
        }
        free_json(item);
    }
Esempio n. 23
0
int32_t iguana_getdata(struct iguana_info *coin,uint8_t *serialized,int32_t type,char *hashstr)
{
    uint32_t len,i,n=1; bits256 hash2;
    decode_hex(hash2.bytes,sizeof(hash2),hashstr);
    len = iguana_rwvarint32(1,&serialized[sizeof(struct iguana_msghdr)],(uint32_t *)&n);
    for (i=0; i<n; i++)
    {
        len += iguana_rwnum(1,&serialized[sizeof(struct iguana_msghdr) + len],sizeof(uint32_t),&type);
        len += iguana_rwbignum(1,&serialized[sizeof(struct iguana_msghdr) + len],sizeof(bits256),hash2.bytes);
    }
    return(iguana_sethdr((void *)serialized,coin->chain->netmagic,"getdata",&serialized[sizeof(struct iguana_msghdr)],len));
}
Esempio n. 24
0
int32_t iguana_gethdrs(struct iguana_info *coin,uint8_t *serialized,char *cmd,char *hashstr)
{
    uint32_t len,n; bits256 hash2;
    decode_hex(hash2.bytes,sizeof(hash2),hashstr);
    n = 0;
    len = iguana_rwnum(1,&serialized[sizeof(struct iguana_msghdr)],sizeof(uint32_t),&n);
    n++;
    len += iguana_rwvarint32(1,&serialized[sizeof(struct iguana_msghdr) + len],(uint32_t *)&n);
    len += iguana_rwbignum(1,&serialized[sizeof(struct iguana_msghdr) + len],sizeof(bits256),hash2.bytes);
    len += iguana_rwbignum(1,&serialized[sizeof(struct iguana_msghdr) + len],sizeof(bits256),(uint8_t *)bits256_zero.bytes);
    return(iguana_sethdr((void *)serialized,coin->chain->netmagic,cmd,&serialized[sizeof(struct iguana_msghdr)],len));
}
Esempio n. 25
0
uint8_t *get_dataptr(int32_t hdroffset,uint8_t **ptrp,int32_t *datalenp,uint8_t *space,int32_t spacesize,char *hexstr)
{
    *ptrp = 0; uint8_t *data = 0;
    if ( hexstr != 0 && (*datalenp= is_hexstr(hexstr,0)) > 0 )
    {
        *datalenp >>= 1;
        if ( (*datalenp+hdroffset) <= spacesize )
        {
            memset(space,0,hdroffset);
            data = &space[hdroffset];
        } else *ptrp = data = calloc(1,*datalenp + hdroffset);
        decode_hex(&data[hdroffset],*datalenp,hexstr);
    }
Esempio n. 26
0
int32_t iguana_pollQs(struct iguana_info *coin,struct iguana_peer *addr)
{
    uint8_t serialized[sizeof(struct iguana_msghdr) + sizeof(uint32_t)*32 + sizeof(bits256)];
    char *hashstr=0,hexstr[65]; bits256 hash2; int32_t height=-1,datalen,flag = 0;
    struct iguana_blockreq *req=0;
    if ( iguana_needhdrs(coin) != 0 && addr->pendhdrs == 0 && (hashstr= queue_dequeue(&coin->hdrsQ,1)) != 0 )
    {
        if ( (datalen= iguana_gethdrs(coin,serialized,coin->chain->gethdrsmsg,hashstr)) > 0 )
        {
            decode_hex(hash2.bytes,sizeof(hash2),hashstr);
            //printf("%s request hdr.(%s) %d pend.%d\n",addr->ipaddr,hashstr,iguana_itemheight(coin,hash2),addr->pendhdrs);
            iguana_send(coin,addr,serialized,datalen);
            addr->pendhdrs++;
            flag++;
        } else printf("datalen.%d from gethdrs\n",datalen);
        free_queueitem(hashstr);
        hashstr = 0;
    }
    if ( ((req= queue_dequeue(&coin->priorityQ,0)) != 0 || (req= queue_dequeue(&coin->blocksQ,0)) != 0) )
    {
        hash2 = req->hash2;
        height = iguana_hash2height(coin,hash2);
        if ( req->height >= 0 && height != req->height )
        {
            printf("blocksQ ht.%d vs %d dequeued.(%s) for %s\n",req->height,height,bits256_str(hash2),addr->ipaddr);
            myfree(req,sizeof(*req));
            return(0);
        }
        if ( height >= 0 && (height < coin->blocks.recvblocks || iguana_blockptr(coin,height) != 0) )
        {
            printf("skip.%d vs recvblocks.%d %p\n",height,coin->blocks.recvblocks,iguana_blockptr(coin,height));
            myfree(req,sizeof(*req));
        }
        else
        {
            init_hexbytes_noT(hexstr,hash2.bytes,sizeof(hash2));
            if ( (datalen= iguana_getdata(coin,serialized,MSG_BLOCK,hexstr)) > 0 )
            {
                //printf("%s %s REQ BLOCK.%d\n",addr->ipaddr,hexstr,iguana_blockheight(coin,hash2));
                iguana_send(coin,addr,serialized,datalen);
                //if ( height >= 0 )
                //    iguana_setwaitstart(coin,height);
                addr->pendblocks++;
                addr->pendtime = (uint32_t)time(NULL);
                flag++;
                myfree(req,sizeof(*req));
            } else printf("error constructing request %s.%d\n",hexstr,height);
        }
    }
    return(flag);
}
Esempio n. 27
0
static void test_3g_status_data(void)
{
	unsigned char *response;
	long len;
	int flen, rlen, str;
	unsigned char access[3];
	unsigned short efid;

	response = decode_hex(binary_ef, -1, &len, 0);

	sim_parse_3g_get_response(response, len, &flen, &rlen, &str,
					access, &efid);

	g_assert(flen == 10);
	g_assert(rlen == 0);
	g_assert(str == 0);
	g_assert(access[0] == 0x01);
	g_assert(access[1] == 0xff);
	g_assert(access[2] == 0x44);
	g_assert(efid == 0x2F05);

	g_free(response);

	response = decode_hex(record_ef, -1, &len, 0);

	sim_parse_3g_get_response(response, len, &flen, &rlen, &str,
					access, &efid);

	g_assert(flen == 0x80);
	g_assert(rlen == 0x20);
	g_assert(str == 1);
	g_assert(access[0] == 0x11);
	g_assert(access[1] == 0xff);
	g_assert(access[2] == 0x44);
	g_assert(efid == 0x6F40);

	g_free(response);
}
Esempio n. 28
0
int32_t peggy_emit(void *_PEGS,uint8_t opreturndata[MAX_OPRETURNSIZE],struct opreturn_payment *payments,int32_t max,uint32_t currentblocknum,uint32_t blocknum,uint32_t blocktimestamp)
{
    char *opreturnstr; int32_t nonz,len = 0; struct peggy_info *PEGS = _PEGS;
    if ( payments != 0 && max > 1 && PEGS->accts != 0 && peggy_payments(&PEGS->accts->PaymentsQ,payments,max,currentblocknum,blocknum,blocktimestamp) < 0 )
        return(-1);
    if ( opreturndata != 0 && (opreturnstr= peggy_emitprices(&nonz,PEGS,blocktimestamp,0)) != 0 )
    {
        memset(opreturndata,0,MAX_OPRETURNSIZE);
        len = (int32_t)strlen(opreturnstr) / 2;
        decode_hex(opreturndata,len,opreturnstr);
        free(opreturnstr);
    }
    return(len);
}
Esempio n. 29
0
int32_t basilisk_message_returned(uint8_t *data,int32_t maxlen,cJSON *item)
{
    char *hexstr=0; cJSON *msgobj; int32_t datalen=0,retval = -1;
    if ( (msgobj= jobj(item,"message")) != 0 )
    {
        if ( (hexstr= jstr(msgobj,"data")) != 0 && (datalen= is_hexstr(hexstr,0)) > 0 )
        {
            datalen >>= 1;
            if ( datalen < maxlen )
            {
                decode_hex(data,datalen,hexstr);
                printf("decoded hexstr.[%d]\n",datalen);
                retval = datalen;
            } else printf("datalen.%d < maxlen.%d\n",datalen,maxlen);
        } else printf("no hexstr.%p or datalen.%d\n",hexstr,datalen);
Esempio n. 30
0
BOOL WINAPI
GetPrivateProfileStruct(LPCTSTR lpszSection,
	LPCTSTR lpszKey,
	LPVOID lpStruct,
	UINT uSizeStruct,
	LPCTSTR szFile)
{
	char valuebuf[BUFSIZ];
	char *src, *dst;

	APISTR((LF_APICALL,
	   "GetPrivateProfileStruct(LPCTSTR=%s,LPCTSTR=%s,LPVOID=%s,UINT=%x,LPCTSTR=%s)\n",
		lpszSection?lpszSection : "NULL",
		lpszKey?lpszKey : "NULL",
		lpStruct?lpStruct  : "NULL",
		uSizeStruct,
		szFile?szFile : "NULL"));

	if (!GetPrivateProfileString(lpszSection, lpszKey, "", valuebuf,
		sizeof(valuebuf), szFile)) {
     		APISTR((LF_APIRET,"GetPrivateProfileStruct: returning BOOL FALSE\n"));
		return (FALSE);
	}

	/* convert hex string to struct bytes */
	if (strlen(valuebuf) / 2 > uSizeStruct)
		return (FALSE);
	src = valuebuf;
	dst = (char *) lpStruct;
	for ( ; *src != '\0'; src += 2, dst++)
		*dst = decode_hex(src[0]) << 4 | decode_hex(src[1]);

     	APISTR((LF_APIRET,"GetPrivateProfileStruct: returning BOOL TRUE\n"));
	return (TRUE);

}