예제 #1
0
int indala224decode(uint8_t *dest, size_t *size, uint8_t *invert) {
	//large 224 bit indala formats (different preamble too...)
	uint8_t   preamble224[] = {1,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 1};
	uint8_t preamble224_i[] = {0,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 0};
	size_t idx = 0;
	size_t found_size = *size;
	if (!preambleSearch(dest, preamble224, sizeof(preamble224), &found_size, &idx) ) {
		// if didn't find preamble try again inverting
		if (!preambleSearch(dest, preamble224_i, sizeof(preamble224_i), &found_size, &idx)) return -1;
		*invert ^= 1;
	}
	if (found_size != 224) return -2;
	
	if (*invert==1 && idx > 0)
		for (size_t i = idx-1; i < found_size + idx + 2; i++) 
			dest[i] ^= 1;

	// 224 formats are typically PSK2 (afaik 2017 Marshmellow)
	// note loses 1 bit at beginning of transformation...
	// don't need to verify array is big enough as to get here there has to be a full preamble after all of our data
	psk1TOpsk2(dest + (idx-1), found_size+2);
	idx++;

	*size = found_size;
	return (int) idx;
}
예제 #2
0
// by marshmellow
// find PAC preamble in already demoded data
int PacFind(uint8_t *dest, size_t *size) {
	if (*size < 128) return -1; //make sure buffer has data
	size_t startIdx = 0;
	uint8_t preamble[] = {1,1,1,1,1,1,1,1,0,0,1,0,0,0,0,0,0,1,0};
	if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
		return -2; //preamble not found
	if (*size != 128) return -3; //wrong demoded size
	//return start position
	return (int)startIdx;
}
예제 #3
0
// find nedap preamble in already demoded data
int detectNedap(uint8_t *dest, size_t *size) {
	//make sure buffer has data
	if (*size < 128) return -3;

	size_t startIdx = 0;
	//uint8_t preamble[] = {1,1,1,1,1,1,1,1,1,0,0,0,1};
	uint8_t preamble[] = {1,1,1,1,1,1,1,1,1,0};
	if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
		return -4; //preamble not found
	return (int) startIdx;
}
예제 #4
0
// redesigned by marshmellow adjusted from existing decode functions
// indala id decoding
int indala64decode(uint8_t *dest, size_t *size, uint8_t *invert) {
	//standard 64 bit indala formats including 26 bit 40134 format
	uint8_t   preamble64[] = {1,0,1,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 1};
	uint8_t preamble64_i[] = {0,1,0,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 0};
	size_t idx = 0;
	size_t found_size = *size;
	if (!preambleSearch(dest, preamble64, sizeof(preamble64), &found_size, &idx) ) {
		// if didn't find preamble try again inverting
		if (!preambleSearch(dest, preamble64_i, sizeof(preamble64_i), &found_size, &idx)) return -1;
		*invert ^= 1;
	}
	if (found_size != 64) return -2;

	if (*invert == 1)
		for (size_t i = idx; i < found_size + idx; i++) 
			dest[i] ^= 1;

	// note: don't change *size until we are sure we got it... 
	*size = found_size;
	return (int) idx;
}
예제 #5
0
int CmdPSKNexWatch(const char *Cmd)
{
	if (!PSKDemod("", false)) return 0;
	uint8_t preamble[28] = {0,0,0,0,0,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	size_t startIdx = 0, size = DemodBufferLen; 
	bool invert = false;
	if (!preambleSearch(DemodBuffer, preamble, sizeof(preamble), &size, &startIdx)){
		// if didn't find preamble try again inverting
		if (!PSKDemod("1", false)) return 0; 
		size = DemodBufferLen;
		if (!preambleSearch(DemodBuffer, preamble, sizeof(preamble), &size, &startIdx)) return 0;
		invert = true;
	}
	if (size != 128) return 0;
	setDemodBuf(DemodBuffer, size, startIdx+4);
	startIdx = 8+32; //4 = extra i added, 8 = preamble, 32 = reserved bits (always 0)
	//get ID
	uint32_t ID = 0;
	for (uint8_t wordIdx=0; wordIdx<4; wordIdx++){
		for (uint8_t idx=0; idx<8; idx++){
			ID = (ID << 1) | DemodBuffer[startIdx+wordIdx+(idx*4)];
		}	
	}
	//parity check (TBD)

	//checksum check (TBD)

	//output
	PrintAndLog("NexWatch ID: %d", ID);
	if (invert){
		PrintAndLog("Had to Invert - probably NexKey");
		for (uint8_t idx=0; idx<size; idx++)
			DemodBuffer[idx] ^= 1;
	} 

	CmdPrintDemodBuff("x");
	return 1;
}