📄 frmsat.frm
字号:
VERSION 5.00
Begin VB.Form frmSAT
Caption = "S@TML compiler"
ClientHeight = 9735
ClientLeft = 60
ClientTop = 630
ClientWidth = 10395
LinkTopic = "Form1"
ScaleHeight = 10710
ScaleWidth = 15240
StartUpPosition = 2 'CenterScreen
WindowState = 2 'Maximized
Begin VB.CommandButton cmdDownload
Caption = "Download"
Height = 615
Left = 12960
TabIndex = 5
Top = 9240
Width = 1935
End
Begin VB.CommandButton cmdCompile
Caption = "Compile"
Height = 615
Left = 6600
TabIndex = 2
Top = 9240
Width = 1935
End
Begin VB.TextBox txtByteCode
Height = 8535
Left = 8760
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 1
Top = 480
Width = 6135
End
Begin VB.TextBox txtScript
Height = 8535
Left = 120
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 0
Top = 480
Width = 8415
End
Begin VB.Label Label2
Caption = "Bytecode"
Height = 255
Left = 8760
TabIndex = 4
Top = 240
Width = 855
End
Begin VB.Label Label1
Caption = "Script"
Height = 255
Left = 120
TabIndex = 3
Top = 240
Width = 615
End
Begin VB.Menu mnuSettings
Caption = "&Settings"
Index = 0
Begin VB.Menu mnuUSB1
Caption = "USB1"
Checked = -1 'True
End
Begin VB.Menu mnuUSB2
Caption = "USB2"
End
Begin VB.Menu mnuCOM1
Caption = "COM1"
End
Begin VB.Menu mnuCOM2
Caption = "COM2"
End
End
End
Attribute VB_Name = "frmSAT"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim startdeck As String
Dim enddeck As String
Dim totalcardlength As Integer
Dim totaldecklength As Integer
Dim startcard As String
Dim endcard As String
Dim startparagraph As String
Dim startinput As String
Dim startsetvar As String
Dim startgo As String
Dim startgoback As String
Dim startexit As String
Dim startextract As String
Dim startconstant As String
Dim startsetupcall As String
Dim startenv As String
Dim startswitch As String
Dim startinitvarsel As String
Dim startexecute As String
Dim startconcat As String
Dim startMCMI As String
Dim startsms As String
Private Sub cmdCompile_Click()
txtByteCode.Text = ""
Erase output 'delete output array contents
Erase thisSATEnv.DeckInfo
Erase APDU
Dim script(1000) As String 'max 200 lines of WML or S@TML script
Dim nolinecount As Long
Dim scriptlinecount As Long
scriptlinecount = NoOfLines(txtScript) 'count no.of lines in script
Dim templine As String
Dim CurrentLineCount As Long
Dim TotalLineScript As Integer
CurrentLineCount = 0
TotalLineScript = 0
While scriptlinecount <> CurrentLineCount
CurrentLineCount = CurrentLineCount + 1
templine = GetLineText(txtScript, CurrentLineCount)
If templine <> "" Then
'script(UBound(script)) = templine 'insert templine into scriptarray
'ReDim Preserve script(UBound(script) + 1)
templine = Trim(templine)
'MsgBox templine
script(CurrentLineCount) = templine
TotalLineScript = TotalLineScript + 1
End If
Wend
'script array is ready for interpretation
Dim j As Integer
Dim i As Integer
Dim hexvalue As String
Dim CurrentDeckNo As Integer
Dim CurrentCardNo As Integer
CurrentDeckNo = -1
CurrentCardNo = -1
startdeck = "<satml"
enddeck = "</satml>"
startcard = "<card"
endcard = "</card>"
startparagraph = "<p"
startinput = "<input"
startsetvar = "<setvar"
startgoback = "<goback"
startgo = "<goselected"
startexit = "<satexit"
startextract = "<extract"
startconstant = "<setconst"
startsetupcall = "<setupcall"
startenv = "<getenv"
startswitch = "<switch"
startinitvarsel = "<initvarsel"
startexecute = "<execute"
startconcat = "<concatenate"
startMCMI = "<mcmi"
startsms = "<sms"
Dim cardpropertyindex As Integer
Dim deckpropertyindex As Integer
Dim CurrentScriptIndex As Integer
TotalLineScript = TotalLineScript - 1 'TotalLineScript -= 1 is = number of lines of script
totalcardlength = 0
totaldecklength = 0
For CurrentScriptIndex = 1 To TotalLineScript
If InStr(1, script(CurrentScriptIndex), startdeck, vbTextCompare) Then
CurrentDeckNo = CurrentDeckNo + 1
Call InitSATEnvironment(CurrentDeckNo)
deckpropertyindex = CurrentScriptIndex
totalcardlength = 0
totaldecklength = 0
'loop this until end of deck => </satml>
While InStr(1, script(CurrentScriptIndex), enddeck, vbTextCompare) = 0
CurrentScriptIndex = CurrentScriptIndex + 1
'check if <template>
If InStr(1, script(CurrentScriptIndex), "<template>", vbTextCompare) Then
While InStr(1, script(CurrentScriptIndex), "</template>", vbTextCompare) = 0
CurrentScriptIndex = CurrentScriptIndex + 1
If InStr(1, script(CurrentScriptIndex), startsetvar, vbTextCompare) Then
Call ProcessTemplateSetVar(CurrentDeckNo, CurrentScriptIndex, script)
ElseIf InStr(1, script(CurrentScriptIndex), startextract, vbTextCompare) Then
Call ProcessTemplateExtract(CurrentDeckNo, CurrentScriptIndex, script)
ElseIf InStr(1, script(CurrentScriptIndex), startenv, vbTextCompare) Then
Call ProcessTemplateGetEnv(CurrentDeckNo, CurrentScriptIndex, script)
ElseIf InStr(1, script(CurrentScriptIndex), startconcat, vbTextCompare) Then
Call ProcessTemplateConcatenate(CurrentDeckNo, CurrentScriptIndex, script)
ElseIf InStr(1, script(CurrentScriptIndex), startMCMI, vbTextCompare) Then
Call ProcessTemplateMCMI(CurrentDeckNo, CurrentScriptIndex, script)
End If
Wend
End If
'check if <card
If InStr(1, script(CurrentScriptIndex), startcard, vbTextCompare) Then
CurrentCardNo = CurrentCardNo + 1
Call InitCard(CurrentDeckNo, CurrentCardNo)
'save the index where it contain card properties to do processing when card children is finished
cardpropertyindex = CurrentScriptIndex
'loop this until end of card => </card>
While InStr(1, script(CurrentScriptIndex), endcard, vbTextCompare) = 0
CurrentScriptIndex = CurrentScriptIndex + 1
'if this line contains <p
If InStr(1, script(CurrentScriptIndex), startparagraph, vbTextCompare) Then
Call ProcessParagraph(CurrentDeckNo, CurrentCardNo, CurrentScriptIndex, script)
ElseIf InStr(1, script(CurrentScriptIndex), startinput, vbTextCompare) Then
Call ProcessInput(CurrentDeckNo, CurrentCardNo, CurrentScriptIndex, script)
ElseIf InStr(1, script(CurrentScriptIndex), startsetvar, vbTextCompare) Then
Call ProcessSetVar(CurrentDeckNo, CurrentCardNo, CurrentScriptIndex, script)
ElseIf InStr(1, script(CurrentScriptIndex), startgo, vbTextCompare) Then
Call ProcessGo(CurrentDeckNo, CurrentCardNo, CurrentScriptIndex, script, deckpropertyindex, cardpropertyindex)
ElseIf InStr(1, script(CurrentScriptIndex), startgoback, vbTextCompare) Then
Call ProcessGoBack(CurrentDeckNo, CurrentCardNo, CurrentScriptIndex, script)
ElseIf InStr(1, script(CurrentScriptIndex), startexit, vbTextCompare) Then
Call ProcessExit(CurrentDeckNo, CurrentCardNo, CurrentScriptIndex, script)
ElseIf InStr(1, script(CurrentScriptIndex), startextract, vbTextCompare) Then
Call ProcessExtract(CurrentDeckNo, CurrentCardNo, CurrentScriptIndex, script)
ElseIf InStr(1, script(CurrentScriptIndex), startconstant, vbTextCompare) Then
Call ProcessSetConstant(CurrentDeckNo, CurrentCardNo, CurrentScriptIndex, script)
ElseIf InStr(1, script(CurrentScriptIndex), startsetupcall, vbTextCompare) Then
Call ProcessSetupCall(CurrentDeckNo, CurrentCardNo, CurrentScriptIndex, script)
ElseIf InStr(1, script(CurrentScriptIndex), startenv, vbTextCompare) Then
Call ProcessGetEnv(CurrentDeckNo, CurrentCardNo, CurrentScriptIndex, script)
ElseIf InStr(1, script(CurrentScriptIndex), startswitch, vbTextCompare) Then
Call ProcessSwitch(CurrentDeckNo, CurrentCardNo, CurrentScriptIndex, script)
ElseIf InStr(1, script(CurrentScriptIndex), startinitvarsel, vbTextCompare) Then
Call ProcessInitVarSel(CurrentDeckNo, CurrentCardNo, CurrentScriptIndex, script)
ElseIf InStr(1, script(CurrentScriptIndex), startexecute, vbTextCompare) Then
Call ProcessExecute(CurrentDeckNo, CurrentCardNo, CurrentScriptIndex, script)
ElseIf InStr(1, script(CurrentScriptIndex), startconcat, vbTextCompare) Then
Call ProcessConcatenate(CurrentDeckNo, CurrentCardNo, CurrentScriptIndex, script)
ElseIf InStr(1, script(CurrentScriptIndex), startMCMI, vbTextCompare) Then
Call ProcessMCMI(CurrentDeckNo, CurrentCardNo, CurrentScriptIndex, script)
ElseIf InStr(1, script(CurrentScriptIndex), startsms, vbTextCompare) Then
Call ProcessSMS(CurrentDeckNo, CurrentCardNo, CurrentScriptIndex, script)
End If
Wend
'if goes here => have reached endcard "</card>"
totalcardlength = totalcardlength + ProcessCard(CurrentDeckNo, CurrentCardNo, cardpropertyindex, script)
End If
Wend
totaldecklength = totaldecklength + ProcessDeck(CurrentDeckNo, CurrentCardNo, deckpropertyindex, script, totalcardlength)
CurrentCardNo = -1
End If
Next CurrentScriptIndex
hexvalue = ProcessAllDecks(hexvalue)
hexvalue = vbCrLf & "Bytecode To Be Downloaded --> " & hexvalue
ReDim Preserve output(UBound(output) + 1)
output(UBound(output)) = hexvalue
ReDim Preserve output(UBound(output) + 1)
output(UBound(output)) = "========================================================================"
'output to textbox
For i = 0 To UBound(output)
txtByteCode.Text = txtByteCode.Text & output(i) & vbCrLf
Next i
'change to APDU format
Call ByteCodeToAPDU(hexvalue)
'For i = 0 To UBound(APDU)
' txtByteCode.Text = txtByteCode.Text & APDU(i) & vbCrLf
'Next i
End Sub
Private Sub cmdDownload_Click()
Dim ret As Long
Dim i As Integer
Dim SELECT_2700 As String
Dim SELECT_6F73 As String
SELECT_2700 = "A0A40000022700"
SELECT_6F73 = "A0A40000026F73"
ReaderRate = "9600"
If mnuUSB1.Checked = True Then
ComCrw = "USB1"
ElseIf mnuUSB2.Checked = True Then
ComCrw = "USB2"
ElseIf mnuCOM1.Checked = True Then
ComCrw = "COM1"
ElseIf mnuCOM2.Checked = True Then
ComCrw = "COM2"
End If
If Q_IsOpened(ComCrw) Then
MsgBox "Another application is using the reader..."
Exit Sub
End If
fd = OpenPort(ComCrw, ReaderRate)
If fd <= 0 Then
MsgBox "Open" & ComCrw & "failed..."
Exit Sub
End If
ret = VerifyCHV("64722288", "0B")
If Hex(ret) <> 9000 Then
MsgBox "Verify ADM key failed..."
Exit Sub
End If
txtByteCode.Text = txtByteCode.Text & "Downloading to 2700->6F73..." & vbCrLf
ret = SendCmd(ComCrw, fd, Len(SELECT_2700) / 2, SELECT_2700, lenr, Resp)
ret = SendCmd(ComCrw, fd, Len(SELECT_6F73) / 2, SELECT_6F73, lenr, Resp)
For i = 0 To UBound(APDU)
ret = SendCmd(ComCrw, fd, Len(APDU(i)) / 2, APDU(i), lenr, Resp)
txtByteCode.Text = txtByteCode.Text & APDU(i) & vbCrLf
txtByteCode.Text = txtByteCode.Text & "SW1SW2: " & Hex(ret) & vbCrLf
Next i
ClosePort ComCrw, fd
End Sub
Private Sub Form_Load()
output = Split(vbNullString)
txtScript.Text = ""
txtByteCode.Text = ""
'Dim j As Integer
'
'InitSATEnvironment (0)
'If Not ((Not thisSATEnv.DeckInfo(0).VarRefListLength) = True) _
' Then j = UBound(thisSATEnv.DeckInfo(0).VarRefListLength) + 1
' ReDim Preserve thisSATEnv.DeckInfo(0).VarRefListLength(j)
'Call StoreLength(1, thisSATEnv.DeckInfo(0).VarRefListLength)
'Dim a As String
'a = "12345"
'a = NibbleSwap(a)
'Dim i As Integer
'i = convert.toint32("c1", 16)
End Sub
Private Sub mnuCOM1_Click()
mnuUSB1.Checked = False
mnuUSB2.Checked = False
mnuCOM1.Checked = True
mnuCOM2.Checked = False
End Sub
Private Sub mnuCOM2_Click()
mnuUSB1.Checked = False
mnuUSB2.Checked = False
mnuCOM1.Checked = False
mnuCOM2.Checked = True
End Sub
Private Sub mnuUSB1_Click()
mnuUSB1.Checked = True
mnuUSB2.Checked = False
mnuCOM1.Checked = False
mnuCOM2.Checked = False
End Sub
Private Sub mnuUSB2_Click()
mnuUSB1.Checked = False
mnuUSB2.Checked = True
mnuCOM1.Checked = False
mnuCOM2.Checked = False
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -