You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

158 lines
5.4 KiB

Module Services
Private sRunTimeDir As String = getRunTimeDir() & "\LVNC-RS"
Private oConfigFile As New IniFile
Public sSupportID As String = String.Empty
Public sSupportPasswd As String = String.Empty
Public byProxyStatus As Byte = 0
Public sProxyHost As String = String.Empty
Public sProxyPort As String = String.Empty
Private aExecResources(,) As String = {
{"lvnc_rs_ini", "\lvnc_rs.ini"},
{"ultravnc_ini", "\UltraVNC\ultravnc.ini"},
{"setpasswd_exe", "\UltraVNC\setpasswd.exe"},
{"winvnc_exe", "\UltraVNC\winvnc.exe"},
{"authadmin_dll", "\UltraVNC\authadmin.dll"},
{"ddengine_dll", "\UltraVNC\ddengine.dll"},
{"SCHook_dll", "\UltraVNC\SCHook.dll"},
{"vnchooks_dll", "\UltraVNC\vnchooks.dll"},
{"SecureVNCPlugin_dsm", "\UltraVNC\SecureVNCPlugin.dsm"}
}
Private Function getRunTimeDir() As String
Dim sRegShellPath As String = "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
Dim sAllUsersDir As String
Dim regKey As Global.Microsoft.Win32.RegistryKey
Dim sCommonDesktop As String
Try
regKey = Global.Microsoft.Win32.Registry.LocalMachine.OpenSubKey(sRegShellPath, False)
sCommonDesktop = regKey.GetValue("Common Desktop")
Catch ex As Exception
sCommonDesktop = ""
End Try
If sCommonDesktop.Length > 0 Then
Dim a() = sCommonDesktop.Split("\")
Dim l As Integer = a.Length - 2
ReDim Preserve a(l)
sAllUsersDir = String.Join("\", a)
Else
sAllUsersDir = ""
End If
Return sAllUsersDir
End Function
Public Sub checkRunTimeComponents()
Dim resItem As Object
Dim resContent As Byte()
With My.Computer.FileSystem
If Not .DirectoryExists(sRunTimeDir) Then
.CreateDirectory(sRunTimeDir)
End If
If Not .DirectoryExists(sRunTimeDir & "\UltraVNC") Then
.CreateDirectory(sRunTimeDir & "\UltraVNC")
End If
For i As Integer = 0 To UBound(aExecResources)
resItem = My.Resources.ResourceManager.GetObject(aExecResources(i, 0))
If TypeOf (resItem) Is String Then
resContent = System.Text.Encoding.Default.GetBytes(resItem.ToString)
Else
resContent = resItem
End If
Using file As New IO.FileStream(sRunTimeDir & aExecResources(i, 1), IO.FileMode.Create)
file.Write(resContent, 0, resContent.Length)
End Using
Next
End With
oConfigFile.Load(sRunTimeDir & "\lvnc_rs.ini")
sProxyHost = oConfigFile.GetKeyValue("repeater", "host")
sProxyPort = oConfigFile.GetKeyValue("repeater", "serverport")
End Sub
Public Sub getSupportID()
Dim aNics() As Net.NetworkInformation.NetworkInterface = Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
Dim sMAC As String = String.Empty
Dim iID As Integer = 0
For Each nic As Net.NetworkInformation.NetworkInterface In aNics
If (nic.NetworkInterfaceType = Net.NetworkInformation.NetworkInterfaceType.Ethernet Or
nic.NetworkInterfaceType = Net.NetworkInformation.NetworkInterfaceType.Wireless80211) And
nic.OperationalStatus = Net.NetworkInformation.OperationalStatus.Up Then
sMAC = nic.GetPhysicalAddress.ToString
Exit For
End If
Next
Dim strBuilder As New Text.StringBuilder(sMAC)
Dim startIndex As Integer = strBuilder.Length - (strBuilder.Length Mod 2) - 2
For i As Integer = startIndex To 2 Step -2
strBuilder.Insert(i, ":"c)
Next i
Dim aMAC() = strBuilder.ToString.Split(":")
Dim n As Integer = 0
For i As Integer = 0 To UBound(aMAC)
n = Convert.ToInt32(aMAC(i), 16)
Debug.Print(n)
iID = ((iID * 16) + n) Mod 99999999
If iID < 99999999 Then
iID = iID + 10000000
End If
Next
sSupportID = iID.ToString
End Sub
Public Sub getSupportPasswd()
Dim rndGen As New System.Random
sSupportPasswd = rndGen.Next(1000, 10000).ToString
End Sub
Public Sub checkProxy(ByRef sHost As String, ByRef sPort As String)
Dim hostEntry As Net.IPHostEntry
Dim ipAddress As Net.IPAddress
Dim epHost As Net.IPEndPoint
Dim socket As Net.Sockets.Socket
Try
hostEntry = Net.Dns.GetHostEntry(sHost)
Catch ex As Exception
byProxyStatus = 2
Exit Sub
End Try
If hostEntry.AddressList.Count > 0 Then
ipAddress = hostEntry.AddressList.FirstOrDefault
epHost = New Net.IPEndPoint(ipAddress, Convert.ToInt32(sPort))
socket = New Net.Sockets.Socket(Net.Sockets.AddressFamily.InterNetwork, Net.Sockets.SocketType.Stream, Net.Sockets.ProtocolType.Tcp)
Try
socket.Connect(epHost)
Catch ex As Exception
End Try
End If
If socket.Connected Then
byProxyStatus = 1
Else
byProxyStatus = 2
End If
socket.Disconnect(False)
End Sub
End Module