Esempio n. 1
0
SR_PRIV int victor_dmm_receive_data(struct sr_dev_inst *sdi, unsigned char *buf)
{
	GString *dbg;
	int i;
	unsigned char data[DMM_DATA_SIZE];
	unsigned char obfuscation[DMM_DATA_SIZE] = "jodenxunickxia";
	unsigned char shuffle[DMM_DATA_SIZE] = {
		6, 13, 5, 11, 2, 7, 9, 8, 3, 10, 12, 0, 4, 1
	};

	for (i = 0; i < DMM_DATA_SIZE && buf[i] == 0; i++);
	if (i == DMM_DATA_SIZE) {
		/* This DMM outputs all zeroes from time to time, just ignore it. */
		sr_dbg("Received all zeroes.");
		return SR_OK;
	}

	/* Deobfuscate and reorder data. */
	for (i = 0; i < DMM_DATA_SIZE; i++)
		data[shuffle[i]] = (buf[i] - obfuscation[i]) & 0xff;

	if (sr_log_loglevel_get() >= SR_LOG_SPEW) {
		dbg = g_string_sized_new(128);
		g_string_printf(dbg, "Deobfuscated.");
		for (i = 0; i < DMM_DATA_SIZE; i++)
			g_string_append_printf(dbg, " %.2x", data[i]);
		sr_spew("%s", dbg->str);
		g_string_free(dbg, TRUE);
	}

	decode_buf(sdi, data);

	return SR_OK;
}
Esempio n. 2
0
int decode_SNM_comm( snm_comm_name_t *comm_name,
                     const uint8_t *base,
                     size_t *rem,
                     size_t *idx )
{
    int retval = 0;
    memset(comm_name, 0, N2N_COMMUNITY_SIZE);
    retval += decode_uint8(&comm_name->size, base, rem, idx);
    retval += decode_buf(comm_name->name, comm_name->size, base, rem, idx);
    return retval;
}
Esempio n. 3
0
// OLD servlink2=nfs://192.168.88.13:/space&smb.user=nmt&smb.passwd=;1234;
// NEW netfs_link2=nfs://[user=pwdbase64]192.168.88.13:/space
char *get_link_passwd(char *servlink)
{
    char *result=NULL;
    if (is_new_style_link(servlink)) {
        if (strstr(servlink,"[=") ==NULL) {
            result = regextract1(servlink,"=([^]]+)",1,0);
            if (result) {
                char *tmp = decode_buf(result);
                FREE(result);
                result=tmp;
            }
        }
    } else {
        char *amp = strchr(servlink,'&');
        if (amp) {
            //result = regextract(servlink,"smb.passwd=([^&]+)",1,0);
            result = get_link_option(servlink,"smb.passwd");
        }
    }
    return result;

}
Esempio n. 4
0
/******************************************************************************
 *                                                                            *
 ******************************************************************************/
static int extract_values(NML_Entry *entry, char *r)
{
    char *s, *d, term;
    int n, type;
    int comma = FALSE;
    int ires = 0, bd = FALSE;
    double rres = 0.;

    do  {
        s = r;
        if (*r == '"' || *r == '\'' ) { // a string
            term = *r++; s++;
            while (*r && *r != term) {
                if (*r == '\\' ) r++;
                r++;
            }
            if ( *r != term ) { fprintf(stderr, "unmatched '%c'\n", term); exit(1); }

            n = r++ - s;

            d = grab_substring(s, n);

            type = TYPE_STR;

            while (*r && *r != ',' ) r++;
        } else {
            while (*r && *r != ',' ) r++;

            n = r - s;
            if ( *r ) r++;

            d = grab_substring(s, n);

            type = decode_buf(d, &rres, &ires, &bd);
            if ( type == TYPE_INT && entry->type == TYPE_DOUBLE ) {
                type = entry->type;
                // rres = ires;
            } else if ( type == TYPE_DOUBLE && entry->type == TYPE_INT ) {
                // This is a fix if the first item of a list was made an int, but there are reals in the
                // list meaning the whole list should have been reals.
                int i;
                for (i = 0; i < entry->count; i++) {
                    double tr = entry->data[i].i;
                    entry->data[i].r = tr;
                }
                entry->type = TYPE_DOUBLE;
            }

            free(d);
        }
        if ( entry->type == 0 ) entry->type = type;
        entry->data = realloc(entry->data, sizeof(NML_Value)*(entry->count+1));
        switch (type) {
            case TYPE_STR :
                entry->data[entry->count].s = d;
                break;
            case TYPE_INT :
                entry->data[entry->count].i = ires;
                break;
            case TYPE_DOUBLE :
                entry->data[entry->count].r = rres;
                break;
            case TYPE_BOOL :
                entry->data[entry->count].b = bd;
                break;
        }
        entry->count++;

        comma = FALSE;
        while ( *r && ( *r == ' ' || *r == '\t' ) ) r++; // skip blanks
        if ( *r == ',' ) {
            r++;
            while ( *r && ( *r == ' ' || *r == '\t' ) ) r++; // skip blanks
            comma = TRUE;
        }
    }
    while (*r);

    return comma;
}
Esempio n. 5
0
/* 復号 */
static int decode(void)
{
	int osize = 0;
	
	/* バッファサイズの読込 */
	bufsize = xgetc(infp);
	bufsize = (bufsize << 8) | xgetc(infp);
	if (bufsize < BUFMIN || BUFMAX < bufsize)  return(-1);
	//printf("作業領域用メモリバッファ: %dByte\n", bufsize);
	while (TRUE)
	{
		int i, typ;
		int pts, ch, c2;
		int isize, srcsize;
		/* ブロックヘッダ読込 */
		if (ob_count > 0) {
			if (xread(workbuf, 1, bufsize, infp) != (size_t)bufsize)  return(-1);
			xwrite(workbuf, 1, bufsize, outfp);
			srcsize = bufsize;
			ob_count--;
		} else {
			int headcode = xgetc(infp);
			if (headcode == EOF)  break;
			if (headcode == 0x7f) {
				ob_count = xgetc(infp);
				headcode = bufsize;
			} else {
				headcode = (headcode << 8) | xgetc(infp);
			}
			
			typ = headcode >> 15;
			isize = headcode & 0x7fff;
			/* ブロックデータの読込 */
			if (xread(workbuf, 1, isize, infp) != (size_t)isize)  return(-1);

			/* ペア表を初期化 */
			for (i = 0; i < 256; i++) {
				pairtable1[i] = i;
			}
			if (typ) {
				/* ペア表の読込 */
				if ((pts = xgetc(infp)) < 0)  return(-1);
				for (i = 0; i < pts; i++) {
					if ((ch = xgetc(infp)) < 0)  return(-1);
					if ((c2 = xgetc(infp)) < 0)  return(-1);
					pairtable1[ch] = c2;
					if ((c2 = xgetc(infp)) < 0)  return(-1);
					pairtable2[ch] = c2;
				}
			}
			srcsize = decode_buf(bufsize, isize);  /* 復号処理 */
            if(srcsize < 0) return(-1);
			xwrite(srcbuf, 1, srcsize, outfp);
		}
		
		/* 途中経過表示 */
		osize += srcsize;
		//printf("             %d\r", osize);
	}
    return(0);
}