Attribute VB_Name = "Mod1"
Option Explicit

Public 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

Public Declare Sub SSInit Lib "sasme" (SSEncrTable As SSTable)
Public Declare Function SSDecrypt Lib "sasme" (SSEncrTable As SSTable, StrToDecr As String, ByVal StartPos As Integer) As Long

Public Declare Sub CopyMemoryX Lib "kernel32" Alias "RtlMoveMemory" (Dest As Any, Src As Any, ByVal cb&)

'SocketType property values
Public Const SOCK_TCP = 1  'PF_INET, SOCK_TCP, IPPROTO_TCP)
Public Const SOCK_UDP = 2  'PF_INET, SOCK_UDP, IPPROTO_UDP)
Public Const SOCK_IP = 3   'PF_INET, SOCK_UDP, IPPROTO_IP)

Public Type SSTable
    SSKey               As Long
    SSBuf(1 To 520)     As Byte
End Type

Public FirstKey         As Long
Public SSTable          As SSTable

Public Function Decrypt(EncryptedPacket As String) As String
    Dim UnEncryptedPacket As String
    If FirstKey <> SSTable.SSKey Then
        UnEncryptedPacket = EncryptedPacket
        If Left(EncryptedPacket, 1) = Chr(0) Then
            SSDecrypt SSTable, UnEncryptedPacket, 3
        Else
            SSDecrypt SSTable, UnEncryptedPacket, 2
        End If
        Decrypt = UnEncryptedPacket
    Else
        Decrypt = EncryptedPacket
    End If
End Function

Public Function FillZero(RawText As String, DesiredLength As Long) As String
    If DesiredLength <= Len(RawText) Then
        FillZero = Left(RawText, DesiredLength)
    Else
        FillZero = RawText & String(DesiredLength - Len(RawText), Chr(0))
    End If
End Function

Public Function FillX(RawText As String, DesiredLength As Long, CharX As String) As String
    If DesiredLength <= Len(RawText) Then
        FillX = Left(RawText, DesiredLength)
    Else
        FillX = RawText & String(DesiredLength - Len(RawText), CharX)
    End If
End Function

Public Function TrimZero(ByVal RawText As String) As String
    Dim L As Long
    L = InStr(RawText, Chr(0))
    If L > 0 Then
        TrimZero = Left(RawText, L - 1)
    Else
        TrimZero = RawText
    End If
End Function

Public Function StringToInt(RawText As String) As Integer
    Dim I As Integer
    Call CopyMemoryX(I, ByVal RawText, 2)
    StringToInt = I
End Function

Public Function StringToLong(RawText As String) As Long
    Dim L As Long
    Call CopyMemoryX(L, ByVal RawText, 4)
    StringToLong = L
End Function

Public Function LongToString(L As Long) As String
    Dim S4 As String
    S4 = Space(4)
    Call CopyMemoryX(ByVal S4, L, 4)
    LongToString = S4
End Function

Public Function IntToString(I As Integer) As String
    Dim S2 As String
    S2 = Space(2)
    Call CopyMemoryX(ByVal S2, I, 2)
    IntToString = S2
End Function

Public Function GetProfileString(Section As String, Key As String) As String
    Dim S As String * 255
    Dim L As Long
    L = GetPrivateProfileString(Section, Key, "", S, 255, App.Path + "\SSClientFilter.ini")
    GetProfileString = Left(S, L)
End Function

