⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mwactivex.ctl

📁 中国石化IC开发程序
💻 CTL
📖 第 1 页 / 共 5 页
字号:
giRet = cpu_protocol(glIcdev, 9, gbInput(0), gbOutput(0))
If giRet <> 0 Then
    gsErrHint = "读二进制错误."
    Exit Function
End If
giLength = gbOutput(2)
giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
If Not Get_Result(gsHex, giLength) Then
    gsErrHint = "读二进制错误,ERROR NO:" + gsErrorNO
    Exit Function
End If
For i = 0 To giLength - 2 - 1
    pbRead(i) = gbOutput(i + 3)
Next i
Read_Binary = True
End Function

Public Function Sam_Read_Binary(psFileID As String, piBegin As Integer, piByteNumber As Integer, pbRead() As Byte) As Boolean
'psFileID 短文件标识符或当前文件.
'piBegin 读的偏移量.
'piByteNumber  读取的字节数.
'pbRead()  返回的字节.
gsErrHint = ""
gbInput(0) = &H0        'nad
gbInput(1) = &H40       'pcb
gbInput(2) = 5          'length
gbInput(3) = &H0        'cla
gbInput(4) = &HB0       'ins
gbInput(5) = Val("&H" + (psFileID))       'p1
gbInput(6) = CByte(piBegin)      'p2
gbInput(7) = CByte(piByteNumber)
gbInput(8) = &H0
For i = 0 To 7
    gbInput(8) = gbInput(i) Xor gbInput(8)     'bcc calculation
Next i
giRet = sam_protocol(glIcdev, 9, gbInput(0), gbOutput(0))
If giRet <> 0 Then
    gsErrHint = "读二进制错误."
    Exit Function
End If
giLength = gbOutput(2)
giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
If Not Get_Result(gsHex, giLength) Then
    gsErrHint = "读二进制错误,ERROR NO:" + gsErrorNO
    Exit Function
End If
For i = 0 To giLength - 2 - 1
    pbRead(i) = gbOutput(i + 3)
Next i
Sam_Read_Binary = True
End Function

Public Function Update_Binary(puType As geUser_UpdateType, psFileID As String, piBegin As Integer, piByteNumber As Integer, pbUpdate() As Byte) As Boolean
'pbUpdate() 要写入的数据,取前piByteNumber个字节.
gsErrHint = ""
If puType = geU_Data Then
    gbInput(0) = &H0        'nad
    gbInput(1) = &H40       'pcb
    gbInput(2) = 5 + CByte(piByteNumber)       'length
    gbInput(3) = &H0        'cla
    gbInput(4) = &HD6       'ins
    gbInput(5) = Val("&H" + (psFileID))       'p1
    gbInput(6) = CByte(piBegin)      'p2
    gbInput(7) = CByte(piByteNumber)
    For i = 0 To piByteNumber - 1
        gbInput(8 + i) = pbUpdate(i)
    Next i
    gbInput(8 + piByteNumber) = &H0
    For i = 0 To 8 + piByteNumber - 1
        gbInput(8 + piByteNumber) = gbInput(i) Xor gbInput(8 + piByteNumber)     'bcc calculation
    Next i
    giRet = cpu_protocol(glIcdev, 8 + piByteNumber + 1, gbInput(0), gbOutput(0))
    If giRet <> 0 Then
        gsErrHint = "修改二进制错误."
        Exit Function
    End If
    giLength = gbOutput(2)
    giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
    If Not Get_Result(gsHex, giLength) Then
        gsErrHint = "修改二进制错误,ERROR NO:" + gsErrorNO
        Exit Function
    End If
End If
If puType = geU_DataMac Then
    '暂时不做
End If
Update_Binary = True
End Function

Public Function Sam_Update_Binary(puType As geUser_UpdateType, psFileID As String, piBegin As Integer, piByteNumber As Integer, pbUpdate() As Byte) As Boolean
'pbUpdate() 要写入的数据,取前piByteNumber个字节.
gsErrHint = ""
If puType = geU_Data Then
    gbInput(0) = &H0        'nad
    gbInput(1) = &H40       'pcb
    gbInput(2) = 5 + CByte(piByteNumber)       'length
    gbInput(3) = &H0        'cla
    gbInput(4) = &HD6       'ins
    gbInput(5) = Val("&H" + (psFileID))       'p1
    gbInput(6) = CByte(piBegin)      'p2
    gbInput(7) = CByte(piByteNumber)
    For i = 0 To piByteNumber - 1
        gbInput(8 + i) = pbUpdate(i)
    Next i
    gbInput(8 + piByteNumber) = &H0
    For i = 0 To 8 + piByteNumber - 1
        gbInput(8 + piByteNumber) = gbInput(i) Xor gbInput(8 + piByteNumber)     'bcc calculation
    Next i
    giRet = sam_protocol(glIcdev, 8 + piByteNumber + 1, gbInput(0), gbOutput(0))
    If giRet <> 0 Then
        gsErrHint = "修改二进制错误."
        Exit Function
    End If
    giLength = gbOutput(2)
    giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
    If Not Get_Result(gsHex, giLength) Then
        gsErrHint = "修改二进制错误,ERROR NO:" + gsErrorNO
        Exit Function
    End If
End If
If puType = geU_DataMac Then
    '暂时不做
End If
Sam_Update_Binary = True
End Function

Public Function Application_Block(puLockType As geUser_ApplicationType, psKey As String) As Boolean
Dim psMac As String * 8
gsErrHint = ""
Select Case puLockType
     Case geU_TempKey8
         psMac = MAC(0, psKey, 16, "841E00" + "00" + "04", 10)
     Case geU_TempKey16
         psMac = MAC(0, psKey, 32, "841E00" + "00" + "04", 10)
     Case geU_ForeverKey8
         psMac = MAC(0, psKey, 16, "841E00" + "01" + "04", 10)
     Case geU_ForeverKey16
         psMac = MAC(0, psKey, 32, "841E00" + "01" + "04", 10)
End Select
gbInput(0) = &H0        'nad
gbInput(1) = &H40       'pcb
gbInput(2) = 9          'length
gbInput(3) = &H84       'cla
gbInput(4) = &H1E       'ins
gbInput(5) = &H0        'p1
Select Case puLockType  'p2
     Case geU_TempKey8
         gbInput(6) = &H0
     Case geU_TempKey16
         gbInput(6) = &H0
     Case geU_ForeverKey8
         gbInput(6) = &H1
     Case geU_ForeverKey16
         gbInput(6) = &H1
End Select
gbInput(7) = &H4
giRet = asc_hex(psMac, gbInput(8), 4)
gbInput(12) = &H0
For i = 0 To 11
    gbInput(12) = gbInput(i) Xor gbInput(12)     'bcc calculation
Next i
giRet = cpu_protocol(glIcdev, 13, gbInput(0), gbOutput(0))
If giRet <> 0 Then
    gsErrHint = "应用锁定错误."
    Exit Function
End If
giLength = gbOutput(2)
giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
If Not Get_Result(gsHex, giLength) Then
    gsErrHint = "应用锁定错误,ERROR NO:" + gsErrorNO
    Exit Function
End If
Application_Block = True
End Function

Public Function Sam_Application_Block(puLockType As geUser_ApplicationType, psKey As String) As Boolean
Dim psMac As String * 8
gsErrHint = ""
Select Case puLockType
     Case geU_TempKey8
         psMac = Sam_MAC(0, psKey, 16, "841E00" + "00" + "04", 10)
     Case geU_TempKey16
         psMac = Sam_MAC(0, psKey, 32, "841E00" + "00" + "04", 10)
     Case geU_ForeverKey8
         psMac = Sam_MAC(0, psKey, 16, "841E00" + "01" + "04", 10)
     Case geU_ForeverKey16
         psMac = Sam_MAC(0, psKey, 32, "841E00" + "01" + "04", 10)
End Select
gbInput(0) = &H0        'nad
gbInput(1) = &H40       'pcb
gbInput(2) = 9          'length
gbInput(3) = &H84       'cla
gbInput(4) = &H1E       'ins
gbInput(5) = &H0        'p1
Select Case puLockType  'p2
     Case geU_TempKey8
         gbInput(6) = &H0
     Case geU_TempKey16
         gbInput(6) = &H0
     Case geU_ForeverKey8
         gbInput(6) = &H1
     Case geU_ForeverKey16
         gbInput(6) = &H1
End Select
gbInput(7) = &H4
giRet = asc_hex(psMac, gbInput(8), 4)
gbInput(12) = &H0
For i = 0 To 11
    gbInput(12) = gbInput(i) Xor gbInput(12)     'bcc calculation
Next i
giRet = sam_protocol(glIcdev, 13, gbInput(0), gbOutput(0))
If giRet <> 0 Then
    gsErrHint = "应用锁定错误."
    Exit Function
End If
giLength = gbOutput(2)
giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
If Not Get_Result(gsHex, giLength) Then
    gsErrHint = "应用锁定错误,ERROR NO:" + gsErrorNO
    Exit Function
End If
Sam_Application_Block = True
End Function

Public Function Application_Unblock(psKey As String) As Boolean
Dim psMac As String
gsErrHint = ""
psMac = MAC(0, psKey, 32, "8418000004", 10)
gbInput(0) = &H0        'nad
gbInput(1) = &H40       'pcb
gbInput(2) = 9          'length
gbInput(3) = &H84       'cla
gbInput(4) = &H18       'ins
gbInput(5) = &H0        'p1
gbInput(6) = &H0        'p2
gbInput(7) = &H4
giRet = asc_hex(psMac, gbInput(8), 4)
gbInput(12) = &H0
For i = 0 To 11
    gbInput(12) = gbInput(i) Xor gbInput(12)     'bcc calculation
Next i
giRet = cpu_protocol(glIcdev, 13, gbInput(0), gbOutput(0))
If giRet <> 0 Then
    gsErrHint = "应用解锁错误."
    Exit Function
End If
giLength = gbOutput(2)
giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
If Not Get_Result(gsHex, giLength) Then
    gsErrHint = "应用解锁错误,ERROR NO:" + gsErrorNO
    Exit Function
End If
Application_Unblock = True
End Function

Public Function Sam_Application_Unblock(psKey As String) As Boolean
Dim psMac As String
gsErrHint = ""
psMac = Sam_MAC(0, psKey, 32, "8418000004", 10)
gbInput(0) = &H0        'nad
gbInput(1) = &H40       'pcb
gbInput(2) = 9          'length
gbInput(3) = &H84       'cla
gbInput(4) = &H18       'ins
gbInput(5) = &H0        'p1
gbInput(6) = &H0        'p2
gbInput(7) = &H4
giRet = asc_hex(psMac, gbInput(8), 4)
gbInput(12) = &H0
For i = 0 To 11
    gbInput(12) = gbInput(i) Xor gbInput(12)     'bcc calculation
Next i
giRet = sam_protocol(glIcdev, 13, gbInput(0), gbOutput(0))
If giRet <> 0 Then
    gsErrHint = "应用解锁错误."
    Exit Function
End If
giLength = gbOutput(2)
giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
If Not Get_Result(gsHex, giLength) Then
    gsErrHint = "应用解锁错误,ERROR NO:" + gsErrorNO
    Exit Function
End If
Sam_Application_Unblock = True
End Function

Public Function Card_Block(psKey As String) As Boolean
Dim pbMac(30) As Byte
Dim pbKey(30) As Byte
Dim pbRandom(30) As Byte
Dim pbData(50) As Byte
gsErrHint = ""
giRet = Get_Challenge(geU_Random4, pbRandom())
pbRandom(4) = 0
pbRandom(5) = 0
pbRandom(6) = 0
pbRandom(7) = 0
giRet = asc_hex(psKey, pbKey(0), 16)
giRet = asc_hex("841600" + "00" + "04", pbData(0), 5)
giRet = Mac_encrypt(pbKey(), pbRandom(), pbData(), 5, pbMac())
gbInput(0) = &H0        'nad
gbInput(1) = &H40       'pcb
gbInput(2) = 5 + 4      'length
gbInput(3) = &H84       'cla
gbInput(4) = &H16       'ins
gbInput(5) = &H0        'p1
gbInput(6) = &H0        'p2
gbInput(7) = &H4
gbInput(8) = pbMac(0)
gbInput(9) = pbMac(1)
gbInput(10) = pbMac(2)
gbInput(11) = pbMac(3)
gbInput(12) = &H0
For i = 0 To 11
    gbInput(12) = gbInput(i) Xor gbInput(12)     'bcc calculation
Next i
giRet = cpu_protocol(glIcdev, 13, gbInput(0), gbOutput(0))
If giRet <> 0 Then
    gsErrHint = "卡片锁定错误."
    Exit Function
End If
giLength = gbOutput(2)
giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
If Not Get_Result(gsHex, giLength) Then
    gsErrHint = "卡片锁定错误,ERROR NO:" + gsErrorNO
    Exit Function
End If
Card_Block = True
End Function

Public Function Sam_Card_Block(psKey As String) As Boolean
Dim pbMac(30) As Byte
Dim pbKey(30) As Byte
Dim pbRandom(30) As Byte
Dim pbData(50) As Byte
gsErrHint = ""
giRet = Sam_Get_Challenge(geU_Random4, pbRandom())
pbRandom(4) = 0
pbRandom(5) = 0
pbRandom(6) = 0
pbRandom(7) = 0
giRet = asc_hex(psKey, pbKey(0), 16)
giRet = asc_hex("841600" + "00" + "04", pbData(0), 5)
giRet = Mac_encrypt(pbKey(), pbRandom(), pbData(), 5, pbMac())
gbInput(0) = &H0        'nad
gbInput(1) = &H40       'pcb
gbInput(2) = 5 + 4      'length
gbInput(3) = &H84       'cla
gbInput(4) = &H16       'ins
gbInput(5) = &H0        'p1
gbInput(6) = &H0        'p2
gbInput(7) = &H4
gbInput(8) = pbMac(0)
gbInput(9) = pbMac(1)
gbInput(10) = pbMac(2)
gbInput(11) = pbMac(3)
gbInput(12) = &H0
For i = 0 To 11
    gbInput(12) = gbInput(i) Xor gbInput(12)     'bcc calculation
Next i
giRet = sam_protocol(glIcdev, 13, gbInput(0), gbOutput(0))
If giRet <> 0 Then
    gsErrHint = "卡片锁定错误."
    Exit Function
End If
giLength = gbOutput(2)
giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
If Not Get_Result(gsHex, giLength) Then
    gsErrHint = "卡片锁定错误,ERROR NO:" + gsErrorNO
    Exit Function
End If
Sam_Card_Block = True
End Function

Public Function PIN_Unblock(psPin As String, psSpin As String) As Boolean
'psPin 此处解锁密码为16个字节.为8个字节时的程序没做.
Dim pbMac(4) As Byte
Dim pbSpin(16) As Byte
Dim psTemp As String
Dim pbTemp(100) As Byte
Dim pbExdest(100) As Byte
Dim piI As Integer
Dim pbKeyA(8) As Byte
Dim pbKeyB(8) As Byte
Dim pbRandom(8) As Byte
gsErrHint = ""
psTemp = "0" + CStr(Len(psPin) / 2) + psPin
piI = Len(psPin) / 2 + 1                                 '如果不到8个字节,开始补"80"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -