Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Light messenger - Connessione al Server

Light messenger

Sommario | Admin | Forum | Bugs | Todo | Files

Avatar
Roberto VB (Member)
Expert


Messaggi: 419
Iscritto: 29/01/2007

Segnala al moderatore
Postato alle 22:02
Lunedì, 26/11/2007
Vi posto il codice del form login di un progetto trovato su internet:
Codice sorgente - presumibilmente VB.NET

  1. Attribute VB_Name = "Frm_Login"
  2. Attribute VB_GlobalNameSpace = False
  3. Attribute VB_Creatable = False
  4. Attribute VB_PredeclaredId = True
  5. Attribute VB_Exposed = False
  6. Dim foo As WinHttp.WinHttpRequest
  7. Dim mSSLIncomingWhenOnProtocol As String
  8. Const HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0
  9. Const HTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1
  10.  
  11. 'Trasparenza Form
  12.  
  13. Dim g_nTransparency As Integer
  14.     Dim color As Long
  15.     Dim flag As Byte
  16. Private Sub Form_Load()
  17.     progb.Value = 0.0001
  18.     Set foo = New WinHttp.WinHttpRequest
  19.  foo.Option(WinHttpRequestOption_EnableRedirects) = False
  20.     color = RGB(255, 0, 255)
  21.     flag = LWA_COLORKEY
  22.     g_nTransparency = 255
  23.     SetTranslucent Me.hwnd, color, g_nTransparency, flag
  24.  
  25.     Dim Xini1 As New CINIFile
  26.     Xini1.LoadFile App.Path & "\Settings.ini"
  27.     txt_User.Text = Xini1.GetValue("Dati", "Username")
  28.     txt_Passwd.Text = Xini1.GetValue("Dati", "Password")
  29.     Xini1.Release
  30.     Set Xini1 = Nothing
  31. End Sub
  32.  
  33. Private Sub Form_Unload(Cancel As Integer)
  34.     Set foo = Nothing
  35. End Sub
  36.  
  37. Private Sub wskSock_Connect()
  38.     senddata "VER 1 MSNP9" & vbCrLf
  39. End Sub
  40.  
  41. Public Sub senddata(ByVal sdata As String)
  42.     wskSock.senddata sdata
  43. End Sub
  44.  
  45. Private Sub wskSock_DataArrival(ByVal bytesTotal As Long)
  46.     Dim x As String
  47.     Dim sdata As String
  48.     wskSock.GetData sdat
  49.     If Mid(sdata, 1, 3) = "VER" Then
  50.         senddata "CVR 2 0x0409 win 4.10 i386 MSNMSGR 5.0.0544 MSMSGS " & user & vbCrLf
  51.     ElseIf Mid(sdata, 1, 3) = "CVR" Then
  52.         senddata "USR 1 TWN I " & user & vbCrLf
  53.         progb.Value = 25
  54.     ElseIf Mid(sdata, 1, 3) = "XFR" Then
  55.         If Split(sdata, " ")(2) = "NS" Then
  56.             x = Split(sdata, " ")(3)
  57.             wskSock.Close
  58.             NewIP = Split(x, ":")(0)
  59.             NewPort = Split(x, ":")(1)
  60.             wskSock.Connect NewIP, NewPort
  61.         End If
  62.  
  63.     ElseIf Mid(sdata, 1, 3) = "USR" Then
  64.         If Split(sdata, " ")(2) = "TWN" Then
  65.             mSSLIncomingWhenOnProtocol = Split(sdata, " ")(4)
  66.             ticket = Passport
  67.             senddata "USR 4 TWN S " & ticket & vbCrLf
  68.            progb.Value = 35
  69.  
  70.            
  71.  
  72.         ElseIf Split(sdata, " ")(2) = "OK" Then
  73.  
  74.             senddata "CHG 1 NLN" & vbCrLf
  75.  
  76.             progb.Value = 50
  77.  
  78.         End If
  79.  
  80.     ElseIf Mid(sdata, 1, 3) = "CHG" Then
  81.  
  82.         Unload Frm_Login
  83.  
  84.         Load FrmPrincipal
  85.  
  86.     End If
  87.  
  88.  
  89.  
  90. End Sub
  91.  
  92.  
  93.  
  94. Public Function Passport() As String
  95.  
  96.  
  97.  
  98.     Dim sFirstResponse As String
  99.  
  100.     Dim sSecondResponse As String
  101.  
  102.     Dim sThirdResponse As String
  103.  
  104.    
  105.  
  106.     Dim iDaLoginStart As Integer
  107.  
  108.     Dim iDaLoginEnd As Integer
  109.  
  110.     Dim sDaLogin As String
  111.  
  112.    
  113.  
  114.    
  115.  
  116.     Dim iDaLocaStart As Integer
  117.  
  118.     Dim iDaLocaEnd As Integer
  119.  
  120.     Dim sDaLoca As String
  121.  
  122.    
  123.  
  124.     Dim iDaKeyStart As Integer
  125.  
  126.     Dim iDaKeyEnd As Integer
  127.  
  128.     Dim sDaKey As String
  129.  
  130.    
  131.  
  132.     'connect to the main server and get the next url
  133.  
  134.     foo.Open "GET", "https://nexus.passport.com/rdr/pprdr.asp"
  135.  
  136.     foo.Send
  137.  
  138.     sFirstResponse = foo.GetAllResponseHeaders
  139.  
  140.     iDaLoginStart = InStr(1, sFirstResponse, "DALogin=") + 8
  141.  
  142.     iDaLoginEnd = InStr(iDaLoginStart, sFirstResponse, ",")
  143.  
  144.     sDaLogin = Mid(sFirstResponse, iDaLoginStart, iDaLoginEnd - iDaLoginStart)
  145.  
  146.    
  147.  
  148.     'connect to another server and attempt auth but get redirected
  149.  
  150.     foo.Open "GET", "https://" & sDaLogin
  151.  
  152.     foo.SetRequestHeader "Authorization", "Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in=" & user & ",pwd=" & passwd & "," & mSSLIncomingWhenOnProtocol
  153.  
  154.     foo.Send
  155.  
  156.     sSecondResponse = foo.GetAllResponseHeaders
  157.  
  158.     If InStr(1, sSecondResponse, "Location:") > 0 Then
  159.  
  160.         iDaLocaStart = InStr(1, sSecondResponse, "Location: ") + 10
  161.  
  162.         iDaLocaEnd = InStr(iDaLocaStart, sSecondResponse, vbCrLf)
  163.  
  164.         sDaLoca = Mid(sSecondResponse, iDaLocaStart, iDaLocaEnd - iDaLocaStart)
  165.  
  166.        
  167.  
  168.         'connect to 3rd and final server and get my key
  169.  
  170.         foo.Open "GET", sDaLoca
  171.  
  172.         foo.SetRequestHeader "Authorization", "Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in=" & user & ",pwd=" & passwd & "," & mSSLIncomingWhenOnProtocol
  173.  
  174.         foo.Send
  175.  
  176.         sThirdResponse = foo.GetAllResponseHeaders
  177.  
  178.         iDaKeyStart = InStr(1, sThirdResponse, "from-PP=") + 9
  179.  
  180.         iDaKeyEnd = InStr(iDaKeyStart, sThirdResponse, "'")
  181.  
  182.         sDaKey = Mid(sThirdResponse, iDaKeyStart, iDaKeyEnd - iDaKeyStart)
  183.  
  184.         Passport = sDaKey
  185.  
  186.     Else
  187.  
  188.         iDaKeyStart = InStr(1, sSecondResponse, "from-PP=") + 9
  189.  
  190.         iDaKeyEnd = InStr(iDaKeyStart, sSecondResponse, "'")
  191.  
  192.         sDaKey = Mid(sSecondResponse, iDaKeyStart, iDaKeyEnd - iDaKeyStart)
  193.  
  194.         Passport = sDaKey
  195.  
  196.     End If
  197.  
  198. End Function
  199.  
  200.  
  201.  
  202. Private Sub xpcmdbutton1_Click()
  203.  
  204.    
  205.  
  206.    
  207.  
  208.     user = txt_User
  209.  
  210.     passwd = txt_Passwd
  211.  
  212.    
  213.  
  214.     Dim Xini1 As New CINIFile
  215.  
  216.     Xini1.LoadFile App.Path & "\Settings.ini"
  217.  
  218.     Xini1.SetValue "Dati", "Username", user
  219.  
  220.     Xini1.SetValue "Dati", "Password", passwd
  221.  
  222.     Xini1.Save
  223.  
  224.     Xini1.Release
  225.  
  226.     Set Xini1 = Nothing
  227.  
  228.     wskSock.Connect "messenger.hotmail.com", 1863
  229.  
  230.     progb.Value = 10
  231.  
  232.  
  233.  
  234. End Sub
  235.  
  236.  
  237.  
  238. Private Sub xpcmdbutton2_Click()
  239.  
  240.     wskSock.Close
  241.  
  242.     Unload Me
  243.  
  244. End Sub



Dunque analizziamo il frmLogin di questo progetto. Nel form load abbiamo:
Codice sorgente - presumibilmente VB.NET

  1. progb.Value = 0.0001
  2.  
  3.     Set foo = New WinHttp.WinHttpRequest
  4.  
  5.     foo.Option(WinHttpRequestOption_EnableRedirects) = False
  6.  
  7.    
  8.  
  9.        
  10.  
  11.     color = RGB(255, 0, 255)
  12.  
  13.     flag = LWA_COLORKEY
  14.  
  15.     g_nTransparency = 255
  16.  
  17.     SetTranslucent Me.hwnd, color, g_nTransparency, flag
  18.  
  19.    
  20.  
  21.     Dim Xini1 As New CINIFile
  22.  
  23.     Xini1.LoadFile App.Path & "\Settings.ini"
  24.  
  25.     txt_User.Text = Xini1.GetValue("Dati", "Username")
  26.  
  27.     txt_Passwd.Text = Xini1.GetValue("Dati", "Password")
  28.  
  29.     Xini1.Release
  30.  
  31.     Set Xini1 = Nothing



Le prime 3 righe di codice non ho capito a che cosa servono
le 4 che seguono invece hanno a che fare con la grafica, quindi per il momento non ci interessa
Il resto, secondo me, salva/carica i dati immessi dall'utente (Nick e password)

Dunque credo che il procedimento che si segue in questo form è il seguente:
Quando premiamo il tasto Login, il programma si connette al server di hotmail :
Codice sorgente - presumibilmente VB.NET

  1. Private Sub xpcmdbutton1_Click()
  2.  
  3.    
  4.  
  5.    
  6.  
  7.     user = txt_User
  8.  
  9.     passwd = txt_Passwd
  10.  
  11.    
  12.  
  13.     Dim Xini1 As New CINIFile
  14.  
  15.     Xini1.LoadFile App.Path & "\Settings.ini"
  16.  
  17.     Xini1.SetValue "Dati", "Username", user
  18.  
  19.     Xini1.SetValue "Dati", "Password", passwd
  20.  
  21.     Xini1.Save
  22.  
  23.     Xini1.Release
  24.  
  25.     Set Xini1 = Nothing
  26.  
  27.     wskSock.Connect "messenger.hotmail.com", 1863 'Server e porta
  28.  
  29.     progb.Value = 10
  30.  
  31.  
  32.  
  33. End Sub


Nelle prime due righe dice che la variabile user è uguale a quello che viene inserito nella textbox txt_User, e che la variabile passwd è uguale a quello che viene inserito nella textbox txt_Passwd.
Tutto ciò che ha a che fare con Xini1 serve per caricare i dati immessi dall'utente.
Poi si connette. Rimane misterioso quel progb

Dopodiche:
Codice sorgente - presumibilmente VB.NET

  1. Private Sub wskSock_Connect()
  2.  
  3.  
  4.  
  5.     senddata "VER 1 MSNP9" & vbCrLf
  6.  
  7.  
  8.  
  9. End Sub
  10.  
  11.  
  12.  
  13.  
  14.  
  15. Private Sub wskSock_DataArrival(ByVal bytesTotal As Long)
  16.  
  17.    
  18.  
  19.     Dim x As String
  20.  
  21.    
  22.  
  23.     Dim sdata As String
  24.  
  25.     wskSock.GetData sdata
  26.  
  27.    
  28.  
  29.     If Mid(sdata, 1, 3) = "VER" Then
  30.  
  31.         senddata "CVR 2 0x0409 win 4.10 i386 MSNMSGR 5.0.0544 MSMSGS " & user & vbCrLf
  32.  
  33.     ElseIf Mid(sdata, 1, 3) = "CVR" Then
  34.  
  35.         senddata "USR 1 TWN I " & user & vbCrLf
  36.  
  37.         progb.Value = 25
  38.  
  39.     ElseIf Mid(sdata, 1, 3) = "XFR" Then
  40.  
  41.         If Split(sdata, " ")(2) = "NS" Then
  42.  
  43.             x = Split(sdata, " ")(3)
  44.  
  45.             wskSock.Close
  46.  
  47.             NewIP = Split(x, ":")(0)
  48.  
  49.             NewPort = Split(x, ":")(1)
  50.  
  51.             wskSock.Connect NewIP, NewPort
  52.  
  53.         End If
  54.  
  55.     ElseIf Mid(sdata, 1, 3) = "USR" Then
  56.  
  57.         If Split(sdata, " ")(2) = "TWN" Then
  58.  
  59.             mSSLIncomingWhenOnProtocol = Split(sdata, " ")(4)
  60.  
  61.             ticket = Passport
  62.  
  63.             senddata "USR 4 TWN S " & ticket & vbCrLf
  64.  
  65.             progb.Value = 35
  66.  
  67.            
  68.  
  69.         ElseIf Split(sdata, " ")(2) = "OK" Then
  70.  
  71.             senddata "CHG 1 NLN" & vbCrLf
  72.  
  73.             progb.Value = 50
  74.  
  75.         End If
  76.  
  77.     ElseIf Mid(sdata, 1, 3) = "CHG" Then
  78.  
  79.         Unload Frm_Login
  80.  
  81.         Load FrmPrincipal
  82.  
  83.     End If
  84.  
  85.  
  86.  
  87. End Sub


Una volta che si è connesso al server invia la seguente stringa "VER 1 MSNP9"(il suo significato è scritto nella guida), quindi quando il server ci risponde si segue questo procedimento:
Se la stringa ricevuta è CVR 2 0x0409 win 4.10 i386 MSNMSGR 5.0.0544 MSMSGS allora... se la stringa è ricevuta è USR 1 TWN I allora...
Voglio far notare che la prima volta risulterà vera la prima condizione, la secondo volta risulterà vera la seconda condizione, e così via fino a quando non raggiungiamo il punto in cui carica il frmPrincipal e qui non sono più riuscito a comprendere bene il codice.
Non sono riuscito a capire a cosa serve progb e quella riga dove c'è scritto ticket = Passport (forse ha a che fare con la password)
Notate inoltre che arrivato ad un certo punto si collega all'altro server ( NewIP = Split(x, ":")(0) NewPort = Split(x, ":")(1) wskSock.Connect NewIP, NewPort...)
Ora mi chiedo, noi con tutto sto casino abbiamo inviato l'email, e la password??????
A voi la parola :D

Ultima modifica effettuata da Roberto VB il 26/11/2007 alle 22:05
PM Quote
Avatar
antometal (Member)
Guru


Messaggi: 691
Iscritto: 12/09/2007

Segnala al moderatore
Postato alle 22:15
Lunedì, 26/11/2007
progb----> progress bar

PM Quote
Avatar
antometal (Member)
Guru


Messaggi: 691
Iscritto: 12/09/2007

Segnala al moderatore
Postato alle 22:18
Lunedì, 26/11/2007

PM Quote
Avatar
albertking82 (Member)
Pro


Messaggi: 112
Iscritto: 14/08/2006

Segnala al moderatore
Postato alle 14:24
Martedì, 27/11/2007
Molto bene!!! Bravi ragazzi.Scusate se nn mi faccio tanto sentire.Sono molto impegnato tra nuovo lavoro e scuola guida.

PM Quote
Avatar
Roberto VB (Member)
Expert


Messaggi: 419
Iscritto: 29/01/2007

Segnala al moderatore
Postato alle 14:48
Martedì, 27/11/2007
Codice sorgente - presumibilmente Plain Text

  1. ticket = Passport


Questa riga di codice serve per la password, La funzione Passport praticamente si connette al server per verificare se è giusta

PM Quote
Avatar
Whivel (Ex-Member)
Newbie


Messaggi: 1
Iscritto: 17/08/2006

Segnala al moderatore
Postato alle 21:14
Venerdì, 12/12/2008
Testo quotato

Postato originariamente da Roberto VB:
Dunque analizziamo il frmLogin di questo progetto. Nel form load abbiamo:
Codice sorgente

             progb.Value = 0.0001     Set foo = New WinHttp.WinHttpRequest     foo.Option(WinHttpRequestOption_EnableRedirects) = False     



Le prime 3 righe di codice non ho capito a che cosa servono
le 4 che seguono invece hanno a che fare con la grafica, quindi per il momento non ci interessa
Il resto, secondo me, salva/carica i dati immessi dall'utente (Nick e password)




le prime 3 righe servono:
1) setta ad un valore piccolo la propietà di un oggetto (forse una progressbar)

2 e 3) crea un oggetto che serve per inviare richieste http e gli dice di non cambiare automaticamente pagina quando il server gli risponde dicendogli che la pagina ha cambiato indirizzo (non ricordo il codice)


PM Quote
Avatar
Roberto VB (Member)
Expert


Messaggi: 419
Iscritto: 29/01/2007

Segnala al moderatore
Postato alle 16:37
Sabato, 13/12/2008
ti ringrazio

PM Quote