VB6批量修改IC卡全部扇区密钥源码

news2024/12/26 21:48:48

本示例使用设备: Android Linux RFID读写器NFC发卡器WEB可编程NDEF文本/智能海报/-淘宝网 (taobao.com)

 函数声明

Private Declare Function piccreadex Lib "OUR_MIFARE.dll" (ByVal ctrlword As Byte, ByVal serial As Long, ByVal area As Byte, ByVal keyA1B0 As Byte, ByVal picckey As Long, ByVal piccdata0_2 As Long) As Byte

'Close the comport
Private Declare Function piccwriteex Lib "OUR_MIFARE.dll" (ByVal ctrlword As Byte, ByVal serial As Long, ByVal area As Byte, ByVal keyA1B0 As Byte, ByVal picckey As Long, ByVal piccdata0_2 As Long) As Byte

'修改单区函数声明
Private Declare Function piccchangesinglekey Lib "OUR_MIFARE.dll" (ByVal ctrlword As Byte, ByVal serial As Long, ByVal area As Byte, ByVal keyA1B0 As Byte, ByVal piccoldkey As Long, ByVal piccnewkey As Long) As Byte

Private Declare Function piccchangesinglekeyex Lib "OUR_MIFARE.dll" (ByVal ctrlword As Byte, ByVal serial As Long, ByVal area As Byte, ByVal keyA1B0 As Byte, ByVal piccoldkey As Long, ByVal piccnewkey As Long) As Byte

'让设备发出声响函数声明
Private Declare Function pcdbeep Lib "OUR_MIFARE.dll" (ByVal xms As Long) As Byte

'读取设备编号函数声明
Private Declare Function pcdgetdevicenumber Lib "OUR_MIFARE.dll" (ByVal devicenumber As Long) As Byte

'寻卡并返回该卡的序列号
Private Declare Function piccrequest Lib "OUR_MIFARE.dll" (ByVal serial As Long) As Byte

'寻卡并选中指定序列号的IC卡,必须指定序列号
Private Declare Function piccrequestex Lib "OUR_MIFARE.dll" (ByVal serial As Long) As Byte

'将密码写入芯片内部保密性极高的只写区域,此函数写入密码仅仅是为了piccauthkey2函数的使用。
Private Declare Function pcdwritekeytoe2 Lib "OUR_MIFARE.dll" (ByVal area As Byte, ByVal keyA1B0 As Byte, ByVal picckey As Long) As Byte

'密码认证方式1,用外部密码认证,必须指定外部密码。本函数必须在piccrequest或piccrequestex函数执行之后运行,并且要紧接着调用,中途不能调用其他函数。
Private Declare Function piccauthkey1 Lib "OUR_MIFARE.dll" (ByVal serial As Long, ByVal area As Byte, ByVal keyA1B0 As Byte, ByVal picckey As Long) As Byte

'读出一块的数据,也就是16个字节。必须在执行piccrequest或 Piccrequestex函数,接着执行piccauthkey1或 piccauthkey2函数,然后执行piccread才能成功读出一块的数据。
Private Declare Function piccread Lib "OUR_MIFARE.dll" (ByVal block As Byte, ByVal piccdata As Long) As Byte

'写一块的数据,也就是16个字节。必须在执行piccrequest或 Piccrequestex函数,接着执行piccauthkey1或 piccauthkey2函数,然后执行piccread才能成功读出一块的数据。
Private Declare Function piccwrite Lib "OUR_MIFARE.dll" (ByVal block As Byte, ByVal piccdata As Long) As Byte

'读设备存储区1
Private Declare Function pcdgetcustomizedata1 Lib "OUR_MIFARE.dll" (ByVal readerdata As Long) As Byte

'写设备存储区1
Private Declare Function pcdsetcustomizedata1 Lib "OUR_MIFARE.dll" (ByVal readerdata As Long) As Byte


'读设备存储区2
Private Declare Function pcdgetcustomizedata2 Lib "OUR_MIFARE.dll" (ByVal readerdata As Long, ByVal devicenumber As Long) As Byte

'写设备存储区2
Private Declare Function pcdsetcustomizedata2 Lib "OUR_MIFARE.dll" (ByVal readerdata As Long) As Byte

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long


        
'控制字定义,控制字指定,控制字的含义请查看本公司网站提供的动态库说明
Private Const BLOCK0_EN = &H1
Private Const BLOCK1_EN = &H2
Private Const BLOCK2_EN = &H4
Private Const NEEDSERIAL = &H8
Private Const EXTERNKEY = &H10
Private Const NEEDHALT = &H20

Dim counstr As Integer
Dim lastuid As String

 修改全部扇区密码

Private Sub Command2_Click()
Dim divstr, regstr, divreg As String
Dim devno(0 To 3) As Byte '设备编号
status = pcdgetdevicenumber(VarPtr(devno(0)))
If status = 0 Then
    divstr = Format(devno(0), "000") & "-" & Format(devno(1), "000") & "-" & Format(devno(2), "000") & "-" & Format(devno(3), "000")
    divreg = sGetINI(App.Path & "\SysConfig.ini", "DefaultSetup", "RegisterCode", "1234567890abcdef")
    regstr = DecryptStr(divreg)
    If divstr = regstr Then
        lastuid = ""
        If Command2.Caption = "修改选定扇区的卡密码" Then
            Command2.Caption = "停 止"
            For I = 0 To 15
                Text4(I).Text = ""
            Next
            Timer1.Enabled = True
        Else
            Timer1.Enabled = False
            Command2.Caption = "修改选定扇区的卡密码"
        End If
    Else
        Timer1.Enabled = False
        Command2.Caption = "修改选定扇区的卡密码"
        MsgBox ("设备编号:" & divstr & ",非本系统的注册设备,暂不能执行此功能!请将设备编号发给供应商申请注册码开通此功能!"), vbCritical + vbOKOnly, "提示"
    End If
Else
    Timer1.Enabled = False
    Command2.Caption = "修改选定扇区的卡密码"
    MsgBox ("系统未识别到发卡器,暂无法执行此功能!"), vbCritical + vbOKOnly, "提示"
End If
End Sub

Private Sub Timer1_Timer()
Dim I As Integer
Dim status As Byte '存放返回值
Dim myareano As Byte '区号
Dim authmode As Byte '密码类型,用A密码或B密码
Dim mypiccserial(0 To 3) As Byte
Dim mypiccoldkey(0 To 5) As Byte '旧密码
Dim mypiccnewkey(0 To 16) As Byte '新密码
Dim keystr, cardstr As String
    
Timer1.Enabled = False
If piccrequest(VarPtr(mypiccserial(0))) = 0 Then              'M1标签
    For I = 0 To 3
        cardstr = cardstr + Right("0" + Hex(mypiccserial(I)), 2)
    Next I
    
    If cardstr <> lastuid Then
        ListAddItem "寻找到新卡:" & cardstr & ",正在修改扇区密码及控制位,请不要移动卡片..."
        lastuid = cardstr
        
        For I = 0 To 15
            Text4(I).Text = ""
        Next

        For I = 0 To 15
            If Check4(I).Value > 0 Then
                myctrlword = BLOCK0_EN + BLOCK1_EN + BLOCK2_EN + EXTERNKEY
                myareano = I
                authmode = Combo16(I).ListIndex
                
                On Error GoTo err1:
                keystr = Trim(Text17(I).Text)
                mypiccoldkey(0) = "&H" & Mid(keystr, 1, 2)
                mypiccoldkey(1) = "&H" & Mid(keystr, 3, 2)
                mypiccoldkey(2) = "&H" & Mid(keystr, 5, 2)
                mypiccoldkey(3) = "&H" & Mid(keystr, 7, 2)
                mypiccoldkey(4) = "&H" & Mid(keystr, 9, 2)
                mypiccoldkey(5) = "&H" & Mid(keystr, 11, 2)
                
                On Error GoTo err2:
                keystr = Trim(Text1(I).Text)
                mypiccnewkey(0) = "&H" & Mid(keystr, 1, 2)
                mypiccnewkey(1) = "&H" & Mid(keystr, 3, 2)
                mypiccnewkey(2) = "&H" & Mid(keystr, 5, 2)
                mypiccnewkey(3) = "&H" & Mid(keystr, 7, 2)
                mypiccnewkey(4) = "&H" & Mid(keystr, 9, 2)
                mypiccnewkey(5) = "&H" & Mid(keystr, 11, 2)
                
                On Error GoTo err3:
                keystr = Trim(Text2(I).Text)
                mypiccnewkey(6) = "&H" & Mid(keystr, 1, 2)
                mypiccnewkey(7) = "&H" & Mid(keystr, 3, 2)
                mypiccnewkey(8) = "&H" & Mid(keystr, 5, 2)
                mypiccnewkey(9) = "&H" & Mid(keystr, 7, 2)
                
                On Error GoTo err4:
                keystr = Trim(Text3(I).Text)
                mypiccnewkey(10) = "&H" & Mid(keystr, 1, 2)
                mypiccnewkey(11) = "&H" & Mid(keystr, 3, 2)
                mypiccnewkey(12) = "&H" & Mid(keystr, 5, 2)
                mypiccnewkey(13) = "&H" & Mid(keystr, 7, 2)
                mypiccnewkey(14) = "&H" & Mid(keystr, 9, 2)
                mypiccnewkey(15) = "&H" & Mid(keystr, 11, 2)
                
                mypiccnewkey(16) = &H3  '3是表示同时更改A、B、 密码权限访问字,为2表示密码权限访问字不更改,只改A、B密码,为0表示只改A密码
        
                status = piccchangesinglekeyex(myctrlword, VarPtr(mypiccserial(0)), myareano, authmode, VarPtr(mypiccoldkey(0)), VarPtr(mypiccnewkey(0)))
                Select Case status
                    Case 0
                         Text4(I).Text = "扇区密码及控制位修改成功!"
                    Case 12
                         Text4(I).Text = "扇区密码认证失败!"
                    Case Else
                         Text4(I).Text = "操作失败,异常代码:" + Format(status, "0")
                End Select
            End If
        Next
        pcdbeep 50
    Else
        ListAddItem "请在感应区刷新的卡"
    End If
Else
    ListAddItem "请在感应区刷新的卡"
End If

Timer1.Enabled = True
Exit Sub

err1:
    Command2.Caption = "修改选定扇区的卡密码"
    MsgBox (Format(I, "00") & " 区旧认证密码输入错误!"), vbCritical + vbOKOnly, "提示"
    Exit Sub
    
err2:
    Command2.Caption = "修改选定扇区的卡密码"
    MsgBox (Format(I, "00") & " 区新A密码输入错误!"), vbCritical + vbOKOnly, "提示"
    Exit Sub
    
err3:
    Command2.Caption = "修改选定扇区的卡密码"
    MsgBox (Format(I, "00") & " 区新控制位输入错误!"), vbCritical + vbOKOnly, "提示"
    Exit Sub
    
err4:
    Command2.Caption = "修改选定扇区的卡密码"
    MsgBox (Format(I, "00") & " 区新B密码输入错误!"), vbCritical + vbOKOnly, "提示"
    Exit Sub
           
End Sub

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1233010.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Vscode GDB 查看内存的值

在VSCode的GDB图形界面中&#xff0c;你可以使用"调试控制台(Debug Console)"来查看malloc返回的地址里的值。以下是具体的步骤&#xff1a; 首先&#xff0c;你需要在你的代码中设置一个断点&#xff0c;这个断点应该在malloc函数调用之后&#xff0c;这样你可以获…

传统考勤太复杂怎么办?这个小技巧,我必须吹爆!

随着科技的不断进步&#xff0c;人脸识别技术在各个领域得到了广泛的应用。在企业管理和安全领域&#xff0c;三维人脸考勤系统成为了一种高效、准确的管理工具。 客户案例 银行 天津某银行是一家金融机构&#xff0c;对于安全性要求极高。传统的考勤系统无法满足他们对于员工…

日期格式转化成星期几部署到linux显示英文

异常收集 原因&#xff1a;解决办法仰天大笑出门去&#xff0c;我辈岂是蓬蒿人 传入一个时间获取这个时间对应的是星期几&#xff0c;在开发环境&#xff08;window系统&#xff09;中显示为星期几&#xff0c;部署到服务器&#xff08;linux系统&#xff09;中会显示英文的时间…

2023年中国老年人护理用品市场规模及前景,呈现快速发展趋势[图]

老年护理有着特定含义&#xff0c;它是指对老年人疾病的治疗护理、某些内科慢性疾病或一些外科病患的医学和心理学康复护理&#xff0c;对生活半自理或完全不能自理的老年人的生活护理&#xff0c;以及对病危老年人的心理护理和临终关怀等。老年人护理用品包括老年人护理床垫、…

ATA-304功率放大器的电子实验案例(案例合集)

ATA-304功率放大器凭借其优异的指标参数受到不少电子工程师的喜欢&#xff0c;其在电子实验中的应用也非常频繁&#xff0c;下面为大家整理出ATA-304功率放大器的应用案例合集&#xff0c;希望能对领域内各位工程师、研究人员有所帮助。 案例一&#xff1a;ATA-304功率放大器在…

关于爬虫!看这一篇就够了!

作为一个互联网的技术开发&#xff0c;爬虫不管是自己写的还是所负责的网站被爬&#xff0c;都是挺常见的。 但是一个很常见的东西&#xff0c;却一直没有系统梳理过&#xff0c;今天我们从发展历史&#xff0c;价值&#xff0c;问题和应对恶意爬虫的策略来聊一聊爬虫。 1 爬…

【机器学习】033_反向传播

一、计算图、反向传播原理 1. 回顾前向传播 例&#xff1a;假设现在有一个神经网络&#xff0c;其仅有一个输出层和一个神经单元 定义 定义 &#xff0c;即激活函数对激活值不再做具体处理 定义平方损失函数 &#xff0c;计算a的值与真实值的差距 此时&#xff0c;通过计算…

Ansys Lumerical|菲涅尔透镜设计

附件下载 联系工作人员获取附件 在这个例子中&#xff0c;我们研究一个球面菲涅尔透镜。透镜的曲率半径为100cm&#xff0c;直径为4.8cm。由于该结构的尺寸较大&#xff0c;我们必须使用该结构的二维近似。透镜的焦点可以用FDTD远场投影函数来研究。 镜头设计和设置 我们将考…

HarmonyOS第一课-对比Kotlin,快速入门TypeScript

编程语言简介 基础类型 1. 布尔值 TypeScript 和 Kotlin: 两者都有 boolean 类型&#xff0c;用于表示 true 或 false。 ts示例&#xff1a; let isDone:boolean falsekotlin示例&#xff1a; val isDone: Boolean false2. 数字 TypeScript: 有 number 类型&#xff0c…

二进制位(计算机存储数据最小单位)

二进制数据中的一个位(bit)简写为b&#xff0c;音译为比特&#xff0c;是计算机存储数据的最小单位。一个二进制位只能表示0或1两种状态&#xff0c;要表示更多的信息&#xff0c;就要把多个位组合成一个整体&#xff0c;一般以8位二进制组成一个基本单位。计算机内部数据以二进…

Camtasia2024喀秋莎软件注册机

真的要被录屏软件给搞疯了&#xff0c;本来公司说要给新人做个培训视频&#xff0c;想着把视频录屏一下&#xff0c;然后简单的剪辑一下就可以了。可谁知道录屏软件坑这么多&#xff0c;弄来弄去头都秃了&#xff0c;不过在头秃了几天之后&#xff0c;终于让我发现了一个值得“…

品尝葡萄酒要注意的重点事项有哪些?

给自己倒一杯葡萄酒&#xff0c;抿一口&#xff0c;这很容易就知道这是不是你喜欢的了。通过一些练习和微调可以加深你对葡萄酒特性的理解&#xff0c;并在品尝时挖掘出葡萄酒中所有的味道。任何品酒师在分析新酒时都会遵循一系列步骤和规则&#xff0c;从外观到香气、味道和特…

DAY59 503.下一个更大元素II + 42. 接雨水

503.下一个更大元素II 题目要求&#xff1a; 给定一个循环数组&#xff08;最后一个元素的下一个元素是数组的第一个元素&#xff09;&#xff0c;输出每个元素的下一个更大元素。数字 x 的下一个更大的元素是按数组遍历顺序&#xff0c;这个数字之后的第一个比它更大的数&am…

django ModelSerializer自定义显示字段

文章目录 前言一、问题二、解决 前言 最近在复习django的时候&#xff0c;发现了一个有趣的问题&#xff0c;解决了之后特意记录下来&#xff0c;以供以后参考。 一、问题 相信大家使用django的时候&#xff0c;被其DRF的强大功能所折服&#xff0c;因为它能通过简单的代码就…

生产环境_移动目标轨迹压缩应用和算法处理-Douglas-Peucker轨迹压缩算法

场景&#xff1a; 我目前设计到的场景是&#xff1a;即在地图应用中&#xff0c;对GPS轨迹数据进行压缩&#xff0c;减少数据传输和存储开销&#xff0c;因为轨迹点太频繁了&#xff0c;占用空间太大&#xff0c;运行节点太慢了&#xff0c;经过小组讨论需要上这个算法&#x…

Nosql的redis概述及基本操作

关系数据库与非关系型数据库概述 关系型数据库 关系型数据库是一个结构化的数据库&#xff0c;创建在关系模型&#xff08;二维表格模型&#xff09;基础上&#xff0c;一般面向于记录。SQL语句(标准数据查询语言)就是一种基于关系型数据库的语言&#xff0c;用于执行对关系型…

【Linux专题】退出bash后再运行jobs命令为什么不会显示后台任务

【Linux专题】firewalld 过滤出接口流量-CSDN博客文章浏览阅读214次。风和日丽&#xff0c;小微给你送福利~如果你是小微的老粉&#xff0c;这里有一份粉丝福利待领取...如果你是新粉关注到了小微&#xff0c;那恭喜你&#xff0c;你赚到了&#xff01;[欢迎关注微信公众号&…

技巧大揭秘!如何优雅地应对Redis读写超时问题

大家好&#xff0c;我是小米&#xff01;今天我们要聊的话题是在Java中如何优雅地处理Redis读写超时问题。这可是个让人头疼的问题&#xff0c;但别担心&#xff0c;我会在这里和大家一起揭开它的神秘面纱&#xff0c;分享一些超实用的技巧和优雅的处理方法。 问题背景 在我们…

陶瓷行业废污水处理使用MES系统的作用

陶瓷行业属于高能耗、高污染行业&#xff0c;生产过程中消耗大量矿产资源和能源&#xff0c;产生的废气、废水、废渣、粉尘等对环境造成严重污染。在近年来&#xff0c;全社会环保意识增强&#xff0c;政府出台了一系列政策、措施加大节能、减排力度&#xff0c;整治行业污染。…