/*** libraries ***/ #include #include #include /*** global vars ***/ HWND login_win = 0; int verbose = 0; int process_id = 0; FILE *out = NULL; /*** functions ***/ static BOOL CALLBACK _enum_windows_proc(HWND hwnd, LPARAM lParam) { char title[256]; int h; int style; int match; /* get window title and properties */ title[0] = 0; GetWindowText(hwnd, title, 256); GetWindowThreadProcessId(hwnd, &h); style = GetWindowLong(hwnd, GWL_STYLE); /* check if it's the login window - method 1 */ match = (process_id != 0) && (h == process_id) && (style & WS_VISIBLE) && (style & DS_SETFOREGROUND) && (style & WS_DLGFRAME) && (strlen(title) > 10); if (match) { login_win = hwnd; printf("login window found (method 1): 0x%08X\n", hwnd); } /* check if it's the login window - method 2 */ if (!strncmp(title, "Connect to ", 11)) { login_win = hwnd; printf("login window found (method 2en): 0x%08X\n", hwnd); } if (!strncmp(title, "Connecter à ", 12)) { login_win = hwnd; printf("login window found (method 2fr): 0x%08X\n", hwnd); } /* log debug informations */ if (out) { int i; fprintf(out, "%X, %s, %X, %d\n ", hwnd, title, h, style); for (i=0; i<(int)strlen(title); i++) { fprintf(out, "%02X ", (int)title[i] & 0xFF); } fprintf(out, "\n"); } return TRUE; } void send_char(HWND hwnd, char c) { SendMessage(hwnd, WM_CHAR, c, 0x40001); } void send_str(HWND hwnd, char *s) { int i; for (i=0; i<(int)strlen(s); i++) SendMessage(hwnd, WM_CHAR, s[i], 0x40001); } BOOL login(char *password) { HWND hwnd; /* search Outlook window (not displayed) */ hwnd = FindWindow(NULL, "Microsoft Outlook"); /* get process id */ process_id = 0; if (hwnd != 0) GetWindowThreadProcessId(hwnd, &process_id); if (out != NULL) fprintf(out, "outlook wnd = %X, process id = %X\n", hwnd, process_id); /* search login window */ login_win = 0; EnumWindows(_enum_windows_proc, 0); if (login_win == 0) return 0; //printf("\nchild\n"); //EnumChildWindows(login_win, _enum_windows_proc, 1); //hwnd = GetWindow(login_win, GW_CHILD); hwnd = FindWindowEx(login_win, 0, "SysCredential", NULL); if (hwnd == 0) return 0; hwnd = FindWindowEx(hwnd, 0, "Edit", NULL); if (hwnd == 0) return 0; send_str(hwnd, password); hwnd = FindWindowEx(login_win, 0, "Button", "OK"); if (hwnd == 0) return 0; SendMessage(hwnd, WM_LBUTTONDOWN, 1, 0x00010001); // press down mouse button at location 1,1 SendMessage(hwnd, WM_LBUTTONUP, 0, 0x00010001); // release mouse button at location 1,1 //SendMessage(hwnd, BM_SETSTATE, 1, 0); //SendMessage(hwnd, BM_SETSTATE, 0, 0); return 1; } int main(int argc, char *argv[]) { int i; char *p; char path[1024]; char password[1024]; FILE *f; /* print welcome */ printf("OutlookAutologin V1.0.2 for Outlook 2003\n"); //SetForegroundWindow(ttt); /* check arguments */ if (argc > 1 && strcmp(argv[1], "-v") == 0) verbose = 1; if (verbose) { out = fopen("autologin-log.txt", "w"); if (out == NULL) out = stderr; } /* get config file */ p = getenv("APPDATA"); if (p == NULL) { printf("APPDATA env var not found\n"); Sleep(2000); exit(1); } strcpy(path, p); if (p[strlen(p)-1] != '\\') strcat(path, "\\"); strcat(path, "OutlookAutologin"); mkdir(path); strcat(path, "\\config.dat"); f=fopen(path, "r"); if (f == NULL) { /* create file */ printf("Enter the password of your account on the Exchange server:\n"); password[0] = 0; gets(password); f = fopen(path, "w"); fprintf(f, "%s\n", password); fclose(f); printf("WARNING: the password is stored in the file %s without any encryption!\n", path); printf("Press Enter to continue.\n"); getchar(); } else { /* read file */ password[0] = 0; fgets(password, 1024, f); fclose(f); } while (strlen(password) > 0 && password[strlen(password)-1] < 32) password[strlen(password)-1] = 0; /* start outlook */ i = (int)ShellExecute(0, "open", "outlook", NULL, NULL, SW_SHOWDEFAULT); if (out != NULL) fprintf(out, "shell ret = %d\n", i); /* autologin */ for (i=0; i<60; i++) { Sleep(1000); if (login(password)) break; if (out != NULL) { fclose(out); out = NULL; } } /* end */ if (verbose) { if (out != NULL) fclose(out); printf("press enter to exit\n"); getchar(); } return 0; }