Author Topic: [XDrx-Hook]WINDOWS hook (HOOK) function (2) - Password input processing  (Read 960 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Swamp Rat
  • Posts: 514
For related content, see:
http://www.theswamp.org/index.php?topic=58729.0
http://www.theswamp.org/index.php?topic=58730.0

Regarding the message loop of the WINDOWS system, you can search online and refer to the literature.

All software in the WINDOWS system interacts with the system through the message loop. When we press the keyboard or move the mouse, the WINDOWS system will send the message to AUTOCAD, and AUTOCAD will accept the message processing and return the information to the system.

The system keyboard message received by AUTOCAD can be intercepted through the hook related functions of ARX. After the application process, the message can continue to be passed to AUTOCAD for subsequent operations, or it can be intercepted so that AUTOCAD does not know that this "message" has come, and AUTOCAD can also You cannot continue to respond to messages and operate.

The general hook function is defined as follows:

Code - C++: [Select]
  1. BOOL HOOK(MSG *pMsg)
  2. {
  3.         switch(pMsg->message){
  4.         case WM_KEYDOWN:
  5.         case WM_SYSKEYDOWN:
  6.                 if(...)
  7.                 {
  8.                         return TRUE; // TRUE intercepts the message and does not allow AUTOCAD to continue processing.
  9.                 }
  10.                 break;
  11.         }
  12.         return FALSE; // Return FALSE, AUTOCAD can continue to accept the message
  13. }


Can A/VLISP also intercept message processing? No, LISP does not provide such a function.

The above operations are completed through the custom functions provided by the XDRX API to LISP.

The "hook" related functions provided by the API are:

Code - Auto/Visual Lisp: [Select]
  1. xdrx-hook-register
  2. xdrx-hook-enable
  3. xdrx-hook-status
  4. xdrx-hook-remove
  5. xdrx-hook-tracemouse
  6. xdrx-hook-block-messageloop
  7. xdrx-system-keystate
  8. xdrx-system-ctrl-down
  9. xdrx-system-ctrl-shift-down
  10. xdrx-system-ctrl-alt-shift-down
  11. xd::hook:register
  12. xd::hook:enable
  13. xd::hook:remove
  14.  

The function of the xdrx-hook-block-messageloop function is equivalent to the return TRUE mentioned above, and the termination message is continued to AUTOCAD.

The typical hook callback function structure of LISP is as follows:

Code - Auto/Visual Lisp: [Select]
  1. (defun hook (hwnd msg wparam lparam time pos)
  2. ;|
  3. hwnd -- window handle
  4. msg --- message
  5. wparam -- main parameter
  6. lparam ---- second parameter
  7. time ------- time of occurrence
  8. pos ------- mouse screen coordinates
  9. |;
  10.   (cond ((= msg WM_KEYUP) ; key up
  11.         )
  12.         ((= msg WM_KEYDOWN) ;Key pressed
  13.          (setq txt (chr wparam))
  14.         )
  15.         ((= msg WM_SYSKEYDOWN)) ;System key pressed
  16.         ((= msg WM_CHAR)
  17.         )
  18.         ((= msg WM_MOUSEWHEEL) ; Turn the wheel
  19.         )
  20.         ((= msg WM_LBUTTONUP) ;The left mouse button pops up
  21.         )
  22.         ((= msg WM_LBUTTONDOWN) ;Left mouse button pressed
  23.         )
  24.         ((= msg WM_LBUTTONDBLCLK) ;Double left mouse button click
  25.         )
  26.         ((= msg WM_RBUTTONUP) ; Right mouse button pops up
  27.         )
  28.         ((= msg WM_RBUTTONDOWN) ;Right mouse button pressed
  29.         )
  30.         ((= msg WM_RBUTTONDBLCLK) ;right mouse button double click
  31.         )
  32.         ((= msg WM_MBUTTONUP) ;Middle mouse button pops up
  33.         )
  34.         ((= msg WM_MBUTTONDOWN) ;Middle mouse button pressed
  35.         )
  36.         ((= msg WM_MBUTTONDBLCLK) ;Middle mouse button double click
  37.         )
  38.         ((= msg WM_MOUSEMOVE) ;mouse movement
  39.         )
  40.         ((= msg WM_PAINT) ;Screen drawing
  41.         )
  42.         ((= msg WM_HOTKEY) ;Hotkey
  43.         )
  44.         ((= msg WM_INPUT) ;Input
  45.         )
  46.         ((= msg WM_VSCROLL) ;Screen scrolling
  47.         )
  48.   )
  49. )

The password input box should display *****, which cannot be realized in ordinary LISP. The XDRX API provides a powerful HOOK injection function. It uses the HOOK technology of the API to intercept keyboard messages, monitor the WINDOWS system WM_CHAR messages, truncate the message processing, and The entered characters become *, and the actual input is saved in a variable for subsequent processing by our program.


The animation below demonstrates that the entered password is displayed in the text box below.
OPENDCL dialog box is used.

The text box below displays the characters being entered, and the dialog box above displays them encrypted with *.



Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.    (setq odcl-data
  3.           '("YWt6A0QTAABH5cGQBuK7KCcxLS9u4OwsMN5uW2TVd3d4Inzo23bIQtYP9cxdZGFKX+oz2y7cdrtp"
  4.             "Ak7vunlhMvL3gH5hIm3pulnpurblQb5hHlwWAk1QquetrAWRqZvIUqzlBQXBRZmysudNjbOnbiPy"
  5.             "xJS3OXPK6WTX92a1k6JqEOCADqhvD26v2XzcPIBpPxtdcdCZ331KNgB07OkPkvXpK4aHBWPBe4ZH"
  6.             "uunpD301fYKQqViUBiDuURNWVGSJz8L3Gz2Cy+C5BQc6QYGJF/PzgkO+EQBgTbYMUQGJFxP/hoZA"
  7.             "wHuZ7SXCG9svXHFXeZsvgrkYjPEv5lCvVjEvYdcKN2xh3DDs7TJBSz3w24lR0i6jWSliRLoNi2mO"
  8.             "Wp4sHYDSloVyjFd1oKgxs2qfC4qsRtGZTCEtpKN/1N4wZN1tAiHed8CFVrqx1WJ1i7TO3wMAf4Zb"
  9.             "npn+Af0xb75Q+WuBTxxa9KpzVDZ6Jhwq70iekQYN8vfaahbgzbJSNGN3y6WOwfChokzZOr1kohMp"
  10.             "ZTFwDO484lK0c3W1eY0xPoB2jh2+cX+djDz3PruOdp6vujxijWzGTrZRfMB3iGhsFfOfOx3CoOYR"
  11.             "TgFAzy9PIneNwWWAFgf0hLZdy4pX10ji95u5muP4wjnOtcxLBzxVlFeqpU220zy+HWhjkAioIrCJ"
  12.             "B8O7XwBBvLEfLNFzpXWc5ddwQ9zZZAKjErZxdpBMjnG/o3gAVYbVu3EsRXIH57ZFckJcxmsU0HMO"
  13.             "RZ5ovg0eEWm6uyJtatH3HHNNqzoUcCKYYJHa2kMIoMBLpgMDzAhW16rOapOMfjVtNW81azUNxwf6"
  14.             "W/Zb9FvyW/Bq/gf36u894BTHVzFD8GpqH7SlxUyg8FzuLE6x71ySVrsqaVMa0/WDigGVnGShEPfw"
  15.             "RRBglDzjnLPxDg1DuvNYXIN87ajQYeomDieEGKC162kVljlnNz1BstepuQbmA2YmhTBsygbES2Ux"
  16.             "JafNF1D1TrW4NrMkShK3IL0XYN+wPpp4fx1koX0CUKUd7R/D+dMx7mI4hJd08SaNkEcaj6/t8/Fs"
  17.             "ZUe2MLbPsPjnFV+tlX7l5oVpTsno5ebFNQ7Q4wZdTq0MRc1hkuRmziKOY84lc5VOT5xGJ2eP855D"
  18.             "vmYgvisegUMebf0UuKNw8i0dtgGwGkBnlodjnpE0Z05+gCRnz0YDtBuctHlqmbRcc5PGrIBiz/Sn"
  19.             "JFBm16dQBQ3eGCEYFMhFB9Io49KLt32VUL03Ojmi0HANFnbAmvjuPT2M2xA2piwotHWm/M47Kz9C"
  20.             "7knOG1/xmq68Apck5mNp050XkUYnx5Bem6hsA9cknEQP27HoVZuJcVpWEJ8="
  21.            )
  22.    )
  23.    (defun c:xd_password#OnInitialize (/)
  24.      (dcl-Control-SetFocus xd_password_1)
  25.    )
  26.    (defun c:xd_password_1#OnSetFocus (/)
  27.      (dcl-Control-SetFocus xd_password_1)
  28.    )
  29.    (defun c:xd_password_1#OnKeyUp (Character RepeatCount Flags /)
  30.      (dcl-Control-SetText xd_password_2 (xdrx_string_left result resultlen))
  31.    )
  32.    (defun _hook (hwnd msg wparam lparam ti pos)
  33.      (cond ((= msg WM_CHAR) ;Capture key characters
  34.             (setq code wparam)
  35. ;|
  36. VK_BACK=8,
  37. VK_RETURN=13,
  38. VK_ESCAPE=27,
  39. VK_SPACE=32
  40. ...
  41. |;
  42.             (if (and (/= code 8)
  43.                      (/= code 13)
  44.                      (/= code 27)
  45.                      (or (/= code 32) t)
  46.                 )
  47.               (progn (setq result (strcat result (chr code))
  48.                            resultlen (1+ resultlen)
  49.                      )
  50.                      (xdrx_hook_put_param 42 589825)
  51.               )
  52.             )
  53.             (if (and (= code 8) (> resultlen 0))
  54.               (setq resultlen (1- resultlen) result (xdrx_string_left result resultlen))
  55.             )
  56.            )
  57.      )
  58.    )
  59.    (xdrx_begin)
  60.    (setq result "")
  61.    (setq resultlen 0)
  62.    (xd::hook:register "_hook" t "password hook");Register the hook function named "password hook"
  63.    (dcl-project-import odcl-data "123456")
  64.    (dcl-form-show xd_password)
  65.    (xd::hook:remove "_hook")
  66.    (xdrx_end)
  67.    (princ)
  68. )
  69.  

=============

The above LISP code uses the XDRX-API, which can be downloaded from https://github.com/xdcad/XDrx-API and is updated at any time.

The XDRX API encapsulates AcDb, AcEd, AcGe, AcBr... C++ library, using C++ methods to develop LISP programs.Thousands of Lisp functions are available.
Modify message
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
https://github.com/xdcad
https://sourceforge.net/projects/xdrx-api-zip/
http://bbs.xdcad.net

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8825
  • AKA Daniel
Re: [XDrx-Hook]WINDOWS hook (HOOK) function (2) - Password input processing
« Reply #1 on: November 18, 2023, 08:17:23 AM »
Dang, that must have taken you a while to write!  :-o

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: [XDrx-Hook]WINDOWS hook (HOOK) function (2) - Password input processing
« Reply #2 on: November 18, 2023, 09:37:10 AM »
You could also use the password_char attribute available in standard DCL.