📄 lha_handler.cls
字号:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "LHA_Handler"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
'AwardMod BIOS Manipulation Tool
'Copyright (C) 2001 Josef Hill
'
'This program is free software; you can redistribute it and/or
'modify it under the terms of the GNU General Public License
'as published by the Free Software Foundation; either version 2
'of the License, or any later version.
'
'This program is distributed in the hope that it will be useful,
'but WITHOUT ANY WARRANTY; without even the implied warranty of
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'GNU General Public License for more details.
'
'You should have received a copy of the GNU General Public License
'along with this program; if not, write to the Free Software
'Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
'Structure of archive block (low order byte first):
'-----preheader
' 1 basic header size
' = 25 + strlen(filename) (= 0 if end of archive)
' 1 basic header algebraic sum (mod 256)
'-----basic header
' 5 method ("-lh0-" = stored, "-lh5-" = compressed)
' 4 compressed size (including extended headers)
' 4 original Size
' 4 not used
' 1 0x20
' 1 0x01
' 1 FileName length(x)
' x FileName
' 2 original file 's CRC
' 1 0x20
' 2 first extended header size (0 if none)
'-----first extended header, etc.
'-----compressed file
Public Enum eRefs
LHA_eRefs = 5
Header_eRefs = 6
Encoded_eRefs = 7
Data_eRefs = 10
HeaderSize_eRefs = 20
Checksum_eRefs = 21
Method_eRefs = 25
CompSize_eRefs = 26
OrigSize_eRefs = 27
LoadOffset_eRefs = 28
LoadBase_eRefs = 29
Marker1_eRefs = 30
FileNameLength_eRefs = 31
FileName_eRefs = 32
OrigCRC_eRefs = 33
Marker2_eRefs = 34
End Enum
Private mS(1 To 34) As String
Public Sub SetItem(iItem As eRefs, iValue As String)
mS(iItem) = iValue
pBreakDown iItem
End Sub
Public Function GetItem(iItem As eRefs) As String
GetItem = mS(iItem)
End Function
Private Sub pBreakDown(iItem As eRefs)
'This is where we deal with things that change the data
Select Case iItem
Case Is = eRefs.LHA_eRefs
'We Caught an LHA File, Decode it
pLHADecode
Case Is = eRefs.Data_eRefs
'We Caught an Uncompressed file, Encode it
pLHAEncode
Case Is = eRefs.LoadBase_eRefs
'The Base has been set. recalculate the header sum
mS(eRefs.LoadBase_eRefs) = W2S(CLng(mS(eRefs.LoadBase_eRefs)))
pBuildHeader
Case Is = eRefs.LoadOffset_eRefs
'The Offset has been set, recalculate the header sum
mS(eRefs.LoadOffset_eRefs) = W2S(CLng(mS(eRefs.LoadOffset_eRefs)))
pBuildHeader
Case Is = eRefs.FileName_eRefs
'The Filename has been set, adjust the filename length
mS(eRefs.FileNameLength_eRefs) = B2S(Len(mS(eRefs.FileName_eRefs)))
'then recalc the header sum
'then recalc the header length
pBuildHeader
End Select
mS(eRefs.LHA_eRefs) = mS(eRefs.HeaderSize_eRefs) & mS(eRefs.Checksum_eRefs) & mS(eRefs.Header_eRefs) & mS(eRefs.Encoded_eRefs)
End Sub
Private Sub pBuildHeader()
Dim lS As String
lS = lS & mS(eRefs.Method_eRefs)
lS = lS & mS(eRefs.CompSize_eRefs)
lS = lS & mS(eRefs.OrigSize_eRefs)
lS = lS & mS(eRefs.LoadOffset_eRefs)
lS = lS & mS(eRefs.LoadBase_eRefs)
lS = lS & mS(eRefs.Marker1_eRefs)
lS = lS & mS(eRefs.FileNameLength_eRefs)
lS = lS & mS(eRefs.FileName_eRefs)
lS = lS & mS(eRefs.OrigCRC_eRefs)
lS = lS & mS(eRefs.Marker2_eRefs)
mS(eRefs.Header_eRefs) = lS
pGenChkSum
pSetHeaderLen
End Sub
Private Sub pLHAEncode()
Dim lEnc As IWork
'set the original size
mS(eRefs.OrigSize_eRefs) = DW2S(Len(mS(eRefs.Data_eRefs)))
'generate the original crc
Set lEnc = New CRC16Gen
lEnc.SetInput mS(eRefs.Data_eRefs)
lEnc.Work
mS(eRefs.OrigCRC_eRefs) = W2S(lEnc.GetOutput)
'compress and set the encoded data
Set lEnc = New LHAEncode
lEnc.SetInput mS(eRefs.Data_eRefs)
lEnc.Work
If Len(lEnc.GetOutput) >= Len(mS(eRefs.Data_eRefs)) Then
mS(eRefs.Encoded_eRefs) = mS(eRefs.Data_eRefs)
mS(eRefs.CompSize_eRefs) = mS(eRefs.OrigSize_eRefs)
mS(eRefs.Method_eRefs) = "-lh0-"
Else
mS(eRefs.Encoded_eRefs) = lEnc.GetOutput
mS(eRefs.CompSize_eRefs) = DW2S(Len(mS(eRefs.Encoded_eRefs)))
mS(eRefs.Method_eRefs) = "-lh5-"
End If
Set lEnc = Nothing
pBuildHeader
End Sub
Private Sub pLHADecode()
Dim lDec As IWork
pSplitLHA
If mS(eRefs.Method_eRefs) = "-lh5-" Then
Set lDec = New LHADecode
lDec.SetInput mS(eRefs.Encoded_eRefs)
lDec.Work
mS(eRefs.Data_eRefs) = lDec.GetOutput
Else
mS(eRefs.Data_eRefs) = mS(eRefs.Encoded_eRefs)
End If
Set lDec = New CRC16Gen
lDec.SetInput mS(eRefs.Data_eRefs)
Debug.Print Len(mS(eRefs.Data_eRefs))
lDec.Work
ts = W2S(lDec.GetOutput)
Debug.Print S2W(CStr(ts))
Debug.Print S2W(mS(eRefs.OrigCRC_eRefs))
Debug.Print Len(mS(eRefs.Data_eRefs))
If lDec.GetOutput <> S2W((mS(eRefs.OrigCRC_eRefs))) Then Stop
mS(eRefs.FileName_eRefs) = Trim2File(mS(eRefs.FileName_eRefs))
pBreakDown (FileName_eRefs)
Set lDec = Nothing
End Sub
Private Sub pSplitLHA()
'Splits the LHA file into Header and Encoded
mS(eRefs.HeaderSize_eRefs) = Left(mS(eRefs.LHA_eRefs), 1)
mS(eRefs.Checksum_eRefs) = Mid(mS(eRefs.LHA_eRefs), 2, 1)
mS(eRefs.Header_eRefs) = Mid(mS(eRefs.LHA_eRefs), 3, Asc(mS(eRefs.HeaderSize_eRefs)))
pSplitHeader
mS(eRefs.Encoded_eRefs) = Mid(mS(eRefs.LHA_eRefs), 3 + Asc(mS(eRefs.HeaderSize_eRefs)), S2DW(mS(eRefs.CompSize_eRefs)))
End Sub
Private Sub pSplitHeader()
mS(eRefs.Method_eRefs) = Mid(mS(eRefs.Header_eRefs), 1, 5)
mS(eRefs.CompSize_eRefs) = Mid(mS(eRefs.Header_eRefs), 6, 4)
mS(eRefs.OrigSize_eRefs) = Mid(mS(eRefs.Header_eRefs), 10, 4)
mS(eRefs.LoadOffset_eRefs) = Mid(mS(eRefs.Header_eRefs), 14, 2)
mS(eRefs.LoadBase_eRefs) = Mid(mS(eRefs.Header_eRefs), 16, 2)
mS(eRefs.FileNameLength_eRefs) = Mid(mS(eRefs.Header_eRefs), 20, 1)
mS(eRefs.FileName_eRefs) = Mid(mS(eRefs.Header_eRefs), 21, Asc(mS(eRefs.FileNameLength_eRefs)))
mS(eRefs.OrigCRC_eRefs) = Mid(mS(eRefs.Header_eRefs), 21 + Asc(mS(eRefs.FileNameLength_eRefs)), 2)
End Sub
Private Sub pDefHeader()
mS(eRefs.Method_eRefs) = String(5, Chr(0))
mS(eRefs.CompSize_eRefs) = String(4, Chr(0))
mS(eRefs.OrigSize_eRefs) = String(4, Chr(0))
mS(eRefs.LoadOffset_eRefs) = String(2, Chr(0))
mS(eRefs.LoadBase_eRefs) = String(2, Chr(0))
mS(eRefs.Marker1_eRefs) = Chr(32) & Chr(1)
mS(eRefs.FileNameLength_eRefs) = String(1, Chr(0))
mS(eRefs.FileName_eRefs) = ""
mS(eRefs.OrigCRC_eRefs) = String(2, Chr(0))
mS(eRefs.Marker2_eRefs) = Chr(32) & String(2, Chr(0))
End Sub
Private Sub pGenChkSum()
mS(eRefs.Checksum_eRefs) = Chr(Sum8(mS(eRefs.Header_eRefs)))
End Sub
Private Sub pSetHeaderLen()
mS(eRefs.HeaderSize_eRefs) = B2S(Len(mS(eRefs.Header_eRefs)))
End Sub
Private Function S2B(iStr As String) As Byte
Dim lI As Byte
For lI = 1 To 1
S2B = Asc(Mid(iStr, lI, 1))
Next lI
End Function
Private Function S2W(iStr As String) As Long
Dim lI As Long
Dim lL As Long
For lI = 1 To 2
S2W = S2W + (2 ^ (((lI - 1) * 8)) * Asc(Mid(iStr, lI, 1)))
Next lI
End Function
Private Function S2DW(iStr As String) As Double
Dim lI As Integer
For lI = 1 To 4
S2DW = S2DW + (2 ^ (((lI - 1) * 8)) * Asc(Mid(iStr, lI, 1)))
Next lI
End Function
Private Function B2S(iByte As Byte) As String
Dim lI As Integer
For lI = 1 To 1
B2S = B2S & Chr(Fix(iByte / (2 ^ (((lI - 1) * 8)))) And 255)
Next lI
'iByte = S2B(B2S)
End Function
Private Function W2S(iLng As Long) As String
Dim lI As Integer
For lI = 1 To 2
W2S = W2S & Chr(Fix(iLng / (2 ^ (((lI - 1) * 8)))) And 255)
'Debug.Print Asc(W2S)
Next lI
iLng = S2W(W2S)
End Function
Private Function DW2S(iDbl As Double) As String
Dim lI As Integer
For lI = 1 To 4
DW2S = DW2S & Chr(Fix(iDbl / (2 ^ (((lI - 1) * 8)))) And 255)
Next lI
'iDbl = S2DW(DW2S)
End Function
Private Function pCS(iStr As String) As String
pCS = Right(iStr, 1) & Left(iStr, 1)
End Function
Private Sub Class_Initialize()
pDefHeader
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -