News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

hyperlink and logging in

Started by Klod, June 10, 2007, 10:35:51 PM

Previous topic - Next topic

Klod

Several times a day, I have to log on to a corporate server via the internet. I would like to know if and how I could automate this process using asm?
I have played around with an example from KetilO that uses hyperlink to get to the site, but how do I go about to navigate to the login box or any other control?
After the login I have to navigate through several menues to get to my page.
Does any body have suggestions?
Your input is gratly appreciated, THX

u

Cookies and the POST method make it too hard to do it the TCP/IP way.
So, make an app, that starts FireFox with the URL as a parameter, waits for the browser+page to load,
and then start sending mouse-messages to Firefox's window. (for click a specified places).
You can also add image-recognition (it's simple bitmap-memory compare) if the mouse-coordinates won't be always true due to layout reordering, caused by news-text above it.
Or you can find a way to inject cookies in Firefox, and do everything the TCP/IP way in your app.
Please use a smaller graphic in your signature.

Klod

Thanks for your reply Ultrano
Quote
Cookies and the POST method make it too hard to do it the TCP/IP way.
So, make an app, that starts FireFox with the URL as a parameter, waits for the browser+page to load,
and then start sending mouse-messages to Firefox's window. (for click a specified places).
You can also add image-recognition (it's simple bitmap-memory compare) if the mouse-coordinates won't be always true due to layout reordering, caused by news-text above it.
Or you can find a way to inject cookies in Firefox, and do everything the TCP/IP way in your app.
Quote

I would like to avoid TCP/IP as I'm still to newbish
I'm not familiar with the Image recogintion technique, would you now of any examples or web links that deal with this technique?
thx

u

Just try implementing the mouse-clicks for now;
Image-matching is very easy, though needs a bit of knowledge in graphics, GDI and custom drawing. And for now it's unnecessary.
Please use a smaller graphic in your signature.

Klod

I don't have Firefox installed on my system. Supposedly the server only supports explorer.
This is all I have come up so far. I'm not sure if I fully understand the process of
Quote
So, make an app, that starts FireFox with the URL as a parameter, waits for the browser+page to load,
and then start sending mouse-messages to Firefox's window. (for click a specified places).
Quote

so far, this is all I could think. When the web page is loaded, the focus and the cursor is in the user name edit box. I thought I could just this example to auto type my username and tab to the next field and auto type password. but this does not work.

; Autotype demo by Vortex, modified

.386
.model flat,stdcall
option casemap:none

include     \GeneSys\include\windows.inc
include     \GeneSys\include\user32.inc
include     \GeneSys\include\kernel32.inc

includelib  \GeneSys\lib\user32.lib
includelib  \GeneSys\lib\kernel32.lib

.data

username     db  'Username',9, 0
password      db 'password',13,0
app         db  'C:\Program Files\Internet Explorer\IEXPLORE.EXE www.google.com', 0
wndclass    db  'IExplore', 0
childclass  db  'Edit', 0

.data?

handle      dd  ?

.code

start:
    invoke  WinExec, ADDR app, SW_SHOW
    invoke  FindWindow, ADDR wndclass, 0
    invoke  FindWindowEx, eax, 0, ADDR childclass, 0
    mov     handle, eax
    invoke  Sleep, 20000                             ;wait for page to load
    mov     edx, OFFSET username
@@:
    movzx   eax,BYTE PTR [edx]
    test    eax,eax
    jz      @f
    push    edx
    invoke  SendMessage, handle, WM_CHAR, eax, 0
     invoke  Sleep, 20
    pop     edx
    inc     edx
    jmp     @b
@@:
    invoke  ExitProcess, 0

    END     start



I  think this doesen't work because I do not have a handle to the edit box?? :red

u

There are no Windows-controlled editboxes in browsers. Instead, send the WM_ messages to the IExplore window. You'll have to experiment a lot, to find what messages work and when.
Please use a smaller graphic in your signature.

Klod

How do I determine I have sent the right one?

evlncrn8

trial and error from the looks of things...

ragdog

hi

i hope this can help you!

.data
szVerbOpen      db "open",0
szFindInGoogle   db 'http://www.google.com/search?q=',0
szString            db "masm32",0

.data?
hInstance     dd ?
szTempBuf       db MAX_PATH  dup(?)

.code

start:
        invoke GetModuleHandle,NULL
      mov hInstance,eax
      
        invoke lstrcpy,addr szTempBuf,addr szFindInGoogle
   invoke lstrcat,addr szTempBuf,addr szString
   invoke ShellExecute,0,addr szVerbOpen,addr szTempBuf,0,0,SW_NORMAL
            
   invoke ExitProcess,0
end start


greets ragdog

Klod

Thank you  ragdog  for your example. In the case for a google search, this example works great. I used the google search in my example because I did not want to use the corporate server address. I asumed if I can put a string into the google search box, I could put one anywhere. Obviously wrong.
However, the szFindInGoogle   db 'http://www.google.com/search?q=',0 looks like some scripting to me. Is this correct? If yes, then all that would be needed is to find the correct script for USERID: and PASSWORD: Or Iam I wrong again?

For Ultranos approach, I tried this,:
      .486                      ; create 32 bit code
      .model flat, stdcall      ; 32 bit memory model
      option casemap :none      ; case sensitive

      include \masm32\include\dialogs.inc
      include simple2.inc

      dlgproc PROTO :DWORD,:DWORD,:DWORD,:DWORD

.data
username     db  'Username', 0
app         db  'C:\Program Files\Internet Explorer\IEXPLORE.EXE www.google.com', 0
wndclass    db  'IExplore', 0
childclass  db  'Edit', 0
message     db  'in wm_create',0
cap      db   'wm-Create',0

.data?

handle      dd  ?
hwndname   dd  ?
    .code

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

start:

      mov hInstance, FUNC(GetModuleHandle,NULL)
      mov hIcon, FUNC(LoadIcon,hInstance,500)
      invoke  WinExec, ADDR app, SW_SHOW
    invoke  FindWindow, ADDR wndclass, 0
    invoke  FindWindowEx, eax, 0, ADDR childclass, 0
    mov     handle, eax

      call main

      invoke ExitProcess,eax

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

main proc

    LOCAL lpArgs:DWORD

    invoke GlobalAlloc,GMEM_FIXED or GMEM_ZEROINIT, 32
    mov lpArgs, eax

    push hIcon
    pop [eax]

    Dialog "Dialog With Icon","MS Sans Serif",10, \         ; caption,font,pointsize
            WS_OVERLAPPED or WS_SYSMENU or DS_CENTER, \     ; style
            3, \                                            ; control count
            50,50,150,80, \                                 ; x y co-ordinates
            1024                                            ; memory buffer size

    DlgButton "OK",WS_TABSTOP,112,5,30,10,IDCANCEL
    DlgStatic "MASM32 Pure And Simple Dialogs",SS_CENTER,3,35,140,9,100
    DlgIcon   500,10,10,101

    CallModalDialog hInstance,0,dlgproc,ADDR lpArgs

    invoke GlobalFree, lpArgs

    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

dlgproc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

    .if uMsg == WM_INITDIALOG
      mov eax, lParam
      mov eax, [eax]
      invoke SendMessage,hWin,WM_SETICON,1,[eax]
      invoke GetForegroundWindow
      mov hwndname, eax
      invoke  SendMessage, hwndname, WM_SETFOCUS, offset username , 0
      invoke SetForegroundWindow, hwndname
   invoke SetCapture,hwndname

    .elseif uMsg == WM_COMMAND
      .if wParam == IDCANCEL
        jmp quit_dialog
      .endif
   .elseif (eax==WM_LBUTTONDOWN)
          mov     edx, OFFSET username
@@:
    movzx   eax,BYTE PTR [edx]
    test    eax,eax
    jz      @f
    push    edx
    invoke  SendMessage, handle, WM_CHAR, eax, 0
     invoke  Sleep, 20
    pop     edx
    inc     edx
    jmp     @b
@@:

    .elseif uMsg == WM_CLOSE
      quit_dialog:
      invoke EndDialog,hWin,0

    .endif

    xor eax, eax
    ret

dlgproc endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start

I tried several different ways to send WM_MESSAGES to explorer. The webpage takes some time to load and I suspect that my first example terminated before the page was loaded.
With the obove example I'm no further since I have no idea wether or not it got there and I have no clue what explorer does with the received messages.

drizz

Klod have you tried using wininet?
InternetOpen,InternetOpenUrl,InternetCloseHandle
its easy.
The truth cannot be learned ... it can only be recognized.

ragdog

to klod

which you look for a login script in masm32 ??


greets
ragdog

Klod

Thak you all for your replies
What I try to acomplish is to logi with username and password to a server on the internet from my proggie written in asm.
ragdogs szFindInGoogle   db 'http://www.google.com/search?q=',0 made me assume /search?q= may be some sort of script since I cannot find this in the docs. :dazzled: This string will start explorer and put the search string into the text box and execute the search.
I have tried the same thing with my login, assuming it would work the same way, but it does not.

To back up, all I try to accomplish is to load the servers web page, input my username and my password from within my proggie.
I tried to send WM_MESSAGES as suggested, tried to obtain a handle or processId for explorer (previous code example) but find that all these methods do not work.



u

Of course it won't login. For sign-in, sites use POST. And if the corporate server is well-setup, they'll be using https instead of http :) (but I guess it isn't).
Please use a smaller graphic in your signature.

ragdog

to klod

try this

.data
szVerbOpen       db "open",0
szMasm32Login      db 'http://www.masm32.com/board/index.php?"',0
szString                db 'action=login2"&user="XXX"&passwrd="XXX',0

.data?
hInstance         dd ?
szTempBuf        db MAX_PATH  dup(?)

.code

start:

        invoke GetModuleHandle,NULL
       mov hInstance,eax
      
        invoke lstrcpy,addr szTempBuf,addr szMasm32Login
        invoke lstrcat,addr szTempBuf,addr szString
   invoke ShellExecute,0,addr szVerbOpen,addr szTempBuf,0,0,SW_NORMAL
            
       invoke ExitProcess,0
end start

greets
ragdog