Results 1 to 10 of 10

Thread: AIM Log in .NET

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2003
    Posts
    7

    AIM Log in .NET

    I've been searching all over for a successful way to find the chat window of AIM and get it's text. I've found plenty on using the API (FindWindow, FindWindowEx, etc). What I have so far is:

    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
    Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer

    Public Function FindIM() As Long
    Dim hWnd As Integer
    Dim AteClass As Integer
    FindIM = FindWindow("AIM_IMessage", vbNullString)
    Dim AteClass2 As Integer
    Dim WndAteClass As Integer
    WndAteClass = FindWindowEx(FindIM, 0, "WndAteClass", vbNullString)
    AteClass = FindWindowEx(WndAteClass, 0, "Ate32Class", vbNullString)

    End Function

    which seems to get the window handles fine, but all attempts to retrieve the text have failed (empty string returned). Most of the code in the forums search is VB6 which needs some tweaking, and i'm probably tweaking something the wrong way. If anyone has any suggestions, or an alternative, easier, or more effective way to do this in .NET, I would really appreciate it

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Try changing long variables in FindWindowExA to integer .

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2003
    Posts
    7
    Doesn't seem to solve the problem I can get the caption of the IM window fine, and the handle of the im text window, but the string is always null when getting text from the im text window. Here's more of my code:

    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
    Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer
    Public Declare Ansi Function GetWindowText Lib "User32.dll" Alias "GetWindowTextA" ( _
    ByVal hwnd As Integer, _
    ByVal lpString As String, _
    ByVal nMaxCount As Integer) As Integer
    Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Integer) As Integer


    Public Function FindIM() As Long
    Dim hWnd As Integer
    Dim AteClass As Integer
    FindIM = FindWindow("AIM_IMessage", vbNullString)
    Dim AteClass2 As Integer
    Dim WndAteClass As Integer
    WndAteClass = FindWindowEx(FindIM, 0, "WndAte32Class", vbNullString)
    AteClass = FindWindowEx(WndAteClass, 0, "Ate32Class", vbNullString)
    FindIM = API_GetText(AteClass)
    End Function


    Public Function API_GetText(ByVal hWnd As Integer)

    Dim Ret As Integer
    Dim s As String
    Ret = GetWindowTextLength(hWnd)
    Call GetWindowText(hWnd, s, Ret + 1)
    API_GetText = s

    End Function

  4. #4
    Fanatic Member
    Join Date
    Jun 2001
    Posts
    521
    Try using WM_GETTEXT and WM_GETTEXTLENGTH with SendMessage. Keep in mind that you can only retrieve a certain amount -- IIRC, ~80k characters. I forget how you deal with images in IM's... (I've done this before, and made away messages that are sent only to certain people). An alternative is to hack into AIM's memory with ReadProcessMemory (you can hack into games too ).

    You're in luck, I have some VB6 code that gets the text from a window using SendMessage. Remeber to change longs to integers and I think the "as Any" will work "as Integer" (you can't use "as Any" in .NET).
    VB Code:
    1. Public Declare Function SendMessage _
    2.     Lib "user32" Alias "SendMessageA" _
    3.    (ByVal hWnd As Long, _
    4.     ByVal wMsg As Long, _
    5.     ByVal wParam As Long, _
    6.     lParam As Any) As Long
    7.  
    8. Public Const WM_SETTEXT = &HC
    9. Public Const WM_GETTEXTLENGTH = &HE
    10.  
    11. Public Function TrimNull(s As String) As String
    12.     Dim n As Integer
    13.    
    14.     n = InStr(s, vbNullChar)
    15.    
    16.     If n >= Len(s) Then
    17.         TrimNull = Left$(s, InStr(s, vbNullChar) - 1)
    18.     Else
    19.         TrimNull = ""
    20.     End If
    21. End Function
    22.  
    23. Public Function GetText(hWnd As Long) As String
    24.     Dim nSize As Integer
    25.     Dim sRet As String
    26.    
    27.     nSize = SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0)
    28.     nSize = nSize + 1
    29.     sRet = Space$(nSize)
    30.     SendMessage hWnd, WM_GETTEXT, nSize, ByVal sRet
    31.     GetText = TrimNull(sRet)
    32. End Function

  5. #5
    Fanatic Member
    Join Date
    Jun 2001
    Posts
    521
    From MSDN: Rich Edit: If the text to be copied exceeds 64K, use either the EM_STREAMOUT or EM_GETSELTEXT message.

    I tried EM_STREAMOUT and failed (crashing the IDE and everything). I'm not sure if the limit is 64k or not...

  6. #6

    Thread Starter
    New Member
    Join Date
    Jun 2003
    Posts
    7
    Looks like it's finally working. It finally gets the text! I'm testing the limitations, so far i've been able to get ~94.5k characters (haven't testeted any higher yet) from the IM window. This seems to exceed the supposed limit, so does that limit not apply in .NET? Just curious. I guess I have a couple other questions now that this is working:

    Can I detect when a window flashes and then get the handle of that window, or is there a simpler way to detect when you've been IMed and get the window handle to get the text?
    You seem to have done some pretty fun stuff with AIM . I've just started to fiddle with it (for my own use). Do you have any source code you could email me? It could really help in learning how to deal with aim.

  7. #7
    Fanatic Member
    Join Date
    Jun 2001
    Posts
    521
    I found that the easiest way to check if I've gotten a new IM is to always keep a record of the text length of each IM using WM_GETTEXTLENGTH. I know I've gotten IM by checking to see if a new window has appeared, or the text length changed for one of the existing windows.

    When I looked at my AIM project, it looked a little on the convoluted side, and I never got around to commenting it (I have the bad habit of writing code like crazy and then going back and commenting it while I still remember what it does). Therefore, I don't think I'll post the code, but I will answer as my questions regarding AIM as I can.

  8. #8
    Junior Member
    Join Date
    Nov 2003
    Posts
    30
    I know its an old thread,.. sorry.


    Mistame, You said you got EM_STREAMOUT working on a roch text box outside your process space (ie AIM)? would you care to share how?

    did you use any type of hooking?

  9. #9
    New Member
    Join Date
    Nov 2003
    Location
    Illinois
    Posts
    11
    Hey, IM me, my screen name is Cubs Anonymous, maybe i can help you out, i know a few places that have this source
    \/\The Conscience of a Hacker/\/

    by

    +++The Mentor+++

    Written on January 8, 1986
    =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    <cut by admin -- too long>

  10. #10
    New Member
    Join Date
    Nov 2003
    Location
    Illinois
    Posts
    11
    also, i got an idea if anybody wants to code a 2 person project with me... anybody wanna enhance the IMs? like give them new looks and an auto away program where it switchers your IM? It could also include stuff like an IM logger, and maybe use winsock to play games with persons on AIM?
    \/\The Conscience of a Hacker/\/

    by

    +++The Mentor+++

    Written on January 8, 1986
    =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    <cut by admin -- too long>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width