博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MIFARE系列8《D8M1.exe》
阅读量:6191 次
发布时间:2019-06-21

本文共 4365 字,大约阅读时间需要 14 分钟。

软件名:D8M1.exe
更新时间:2014.06.28
操作系统:windowAll
外部设备:D8读卡器

D8M1能够对MIFARE块读写操作。支持1K,4K。

检验KEY后返回SAK,QTAQ,UID。基于D8读卡器提供的dcrf32.dll开发。

D8型IC卡读写器是开发IC卡相关产品及系统集成必备的前端处理设备。可读写双界面射频智能卡或单独的非接触式射频卡,通过RS232串行接口或USB口实现同PC机及相关设备的连接,USB採用无驱技术。可方便用户的安装使用,它对多卡的支持可用于安全发卡及那些安全要求较高的领域须要。

核心代码例如以下:

void CD8M1Dlg::Show(CString str){	time = CTime::GetCurrentTime();	CString strTime = time.Format("%H:%M:%S");	int len = editShow.GetWindowTextLength();	editShow.SetSel(len, len);	editShow.ReplaceSel(strTime + " ----> " + str + _T("\r\n"));}void CD8M1Dlg::Beer(){	UCHAR SONG_TONE[] = { 212, 212, 190, 212, 159, 169, 212, 212, 190, 212, 142, 159, 212, 212, 106, 126, 159, 169, 190, 119, 119, 126, 159, 142, 159, 0 }; //生日快乐歌的音符频率表,不同频率由不同的延时来决定 	UCHAR SONG_LONG[] = { 9, 3, 12, 12, 12, 24, 9, 3, 12, 12, 12, 24, 9, 3, 12, 12, 12, 12, 12, 9, 3, 12, 12, 12, 24, 0 }; //生日快乐歌节拍表。节拍决定每一个音符的演奏长短 	int len = 6;	for (int i = 0; i < len; i++){		dc_beep(icdev, SONG_LONG[i]/3);		Sleep(SONG_TONE[i]);	}}void CD8M1Dlg::OnBnClickedInitcom(){	//初始化串口1,       	icdev = dc_init(100, 9600);	if ((int)icdev <= 0){		Show("Init Com Error!");	}	else{		Show("Init Com OK!");	}	dc_beep(icdev, 1);//蜂鸣时间,单位是10毫秒	Sleep(30);	dc_beep(icdev, 1);	Sleep(60); 	dc_beep(icdev, 1);//	Beer();}void CD8M1Dlg::OnBnClickedLoadKey(){	//下载password	CString keys;	GetDlgItemText(IDC_EDIT_KEY, keys);	int pos = keys.Find("\r\n");	UCHAR uKey[6];	while (pos != -1){		CString key = keys.Left(pos).Trim();		keys = keys.Mid(pos+2);		unsigned char _SecNr = StrToIntA(key.Left(2));		CString keyN = key.Mid(3);		if (_SecNr > 40){			Show("扇区号有误,大于40扇区...");		}		memset(uKey, 0, 6);		Alg::HexToAsc(keyN, uKey);		int st = dc_load_key(icdev, GetKeyMode(), _SecNr, uKey);		if (st != 0){			Show(IntToStr(_SecNr) + ": 扇区密钥写入失败...");			return;		}		pos = keys.Find("\r\n");	}	Show("加载KEY成功...\r\n");}void CD8M1Dlg::OnBnClickedVerifyCard(){	//寻卡函数,      // 	int st = dc_card(icdev, 0, &cardsnr);	CString linstr;	unsigned short tagType;	int st = dc_request(icdev, 0, &tagType);	if (st != 0)	{		Show("Find Card Error!");		return;	}	else	{		Show("Find Card Ok!");		linstr.Format("%04d", tagType);		Show("ATQA:" + linstr);	}	st = dc_anticoll(icdev, 0, &cardsnr);	if (st != 0)	{		Show("Find Card Error!");		return;	}	else	{		linstr.Format("%X", cardsnr);		Show("UID:" + linstr);	}	UCHAR size;	st = dc_select(icdev, cardsnr, &size);	if (st != 0)	{		Show("select Card Error!");		return;	}	else	{		linstr.Format("%X", size);		Show("SAK:" + linstr);	}	//核对password	int sec = GetSecNr();	int keyMode = GetKeyMode();	for (int i = 0; i < sec; i++){		st = dc_authentication(icdev, keyMode, i);		if (st != 0){			Show(IntToStr(i) + ": Auth Card Error...");			return;		}		}	Show("核对password完毕...\r\n");}void CD8M1Dlg::OnBnClickedRead(){	EditBlock.SetWindowTextA("");	ClearShow();	int adrs = GetBlockNr();	CString sData;	UCHAR pData[32];	unsigned long _NSnr;	for (int i = 0; i < adrs; i++){		//int st = dc_read(icdev, i, data);		if (IsCheckW()){//only read block 3			if ((i < 128) && ((i+1) % 4 != 0)){				continue;			}						if ((i > 128) && ((i+1) % 16 != 0)){				continue;			}			}		memset(pData, 0, 32);		int st = dc_HL_read(icdev, 0, i, cardsnr, pData, &_NSnr);		Alg::AscToHex(pData, 16, sData);				if (st != 0){			Show(IntToStr(i) + ": 读取失败...");			continue;		}		else{			Show(IntToStr(i) + ": 读取成功," + sData);		}		int len = EditBlock.GetWindowTextLength();		EditBlock.SetSel(len, len);		EditBlock.ReplaceSel(IntToStr(i) + ":" + sData + _T("\r\n"));	}		Show("读取块完毕...\r\n");}void CD8M1Dlg::OnBnClickedWrite(){	ClearShow();	CString blocks;	int adrs = GetBlockNr();	GetDlgItemText(IDC_EDIT_BLOCK, blocks);	int pos = blocks.Find("\r\n");	UCHAR uData[16];	while (pos != -1){		CString block = blocks.Left(pos).Trim();		blocks = blocks.Mid(pos + 2);		int posn = block.Find(':');		if (posn == -1){			Show("块地址值有误," + block);			return;		}		unsigned char adr = StrToIntA(block.Left(posn));		CString data = block.Mid(posn + 1);		if (data.GetLength() != 32){			Show("块值长度有误," + block);		}		if (adr > adrs){			Show("块地址越界:" + IntToStr(adr));			return;		}		Alg::HexToAsc(data, uData);				int st = dc_HL_write(icdev, 0, adr, &cardsnr, uData);		if (st != 0){			Show(IntToStr(adr) + ": 写入失败...");		}		else{			Show(IntToStr(adr) + ": 写入成功,写入值 " + data);		}		pos = blocks.Find("\r\n");	}	Show("写入块完毕...\r\n");}void CD8M1Dlg::OnClose(){	dc_exit(icdev);	CDialogEx::OnClose();}
软件下载地址:

你可能感兴趣的文章
ERROR 2002 (HY000): Cant connect to local MySQL server through socket的解决方法
查看>>
SAP IoT Simulator: Testing Out the Internet of Things
查看>>
Oracle如何删除表中重复记录
查看>>
js检测是否手机浏览的函数
查看>>
Javascript闭包简单理解
查看>>
【技巧篇】解决悬浮的<header>、<footer>遮挡内容的处理技巧
查看>>
eclipse CDT的安装
查看>>
HDOJ 2089 不要62(打表)
查看>>
【百度地图API】多家地图API文件大小对比
查看>>
Redmine1.x上 ezFAQ插件导出PDF错误
查看>>
知其所以然(以算法学习为例)
查看>>
[20170309]关于在线日志与归档2.txt
查看>>
ArcGIS Engine开发之旅05---空间数据库
查看>>
CMake使用之一
查看>>
TCL与DuerOS达成战略合作,一口气发三大系列「人工智能」电视
查看>>
centos关机与重启命令
查看>>
CENTOS6 安装docker
查看>>
微信公众号中 JavaScript 获取用户周边的标志性建筑列表
查看>>
tomcat生产部署关键参数设置
查看>>
思必驰DUI 平台正式开放注册 语音交互系统还有很长的路要走
查看>>