flat assembler
Message board for the users of flat assembler.

Index > Windows > FindWindow with dynamically classname

Author
Thread Post new topic Reply to topic
semiono



Joined: 31 Aug 2007
Posts: 198
Location: section '.code' executable
semiono 16 May 2024, 00:49
Code:
invoke FindWindow,'JUCE_18f7ea58f3e',NULL    


How make it like JUCE_18* or JUCE_18+(x) etc.
for lame user

without deep diving to asm low level Very Happy

--

dark side of this XML – Through hardship to the stars
Code:
<?xml version="1.0" encoding="UTF-8"?>
<PROPERTIES>
... bla-bla

  <VALUE name="ui::main_window">
    <ui::main_window width="1280" height="746" full_screen="0"/>
  </VALUE>
...
</PROPERTIES>
    

_________________
Windows 9, FL Studio 19
Post 16 May 2024, 00:49
View user's profile Send private message Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 732
Ali.Z 16 May 2024, 01:21
if i understand correctly then, you are trying to change a window title that belong to another process?

you can use SetWindowText or send the title directly to window's main proc using SendMessage (wm_settext)

note that if the target tend to change its title based on user action, then you need to obtain hwnd by supplying the class atom or class name.

_________________
Asm For Wise Humans
Post 16 May 2024, 01:21
View user's profile Send private message Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 198
Location: section '.code' executable
semiono 16 May 2024, 01:40
I want to find window and set size: with and height.
But window class every time changes the name.
JUCE_18f7ea58f3e
JUCE_18f7ae781a
JUCE_18f58f3ezzz
Every new start app class name different. I can't find this win.
Post 16 May 2024, 01:40
View user's profile Send private message Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 732
Ali.Z 16 May 2024, 01:52
sorry i didnt realize you're trying to change class name.

there is no known method of changing class name once it is registered(*), your best bet is to hook window creation function and change class name there or hook createwindowexa/w.

if you just want to change window TITLE or name then you can safely ignore the class.

try executing the target with CreateProcess, fill STARTUPINO struct, after window created you will get its hwnd. (may not work for every target)

the other method is by using toolhelp32snapshot, looping thru a list of all tasks, just compare the executable name, if found get main thread id, use thread id to get main window's hwnd.


(*)
not technically correct, but require some serious hacking into windows structure, it has been done in past.

_________________
Asm For Wise Humans
Post 16 May 2024, 01:52
View user's profile Send private message Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 198
Location: section '.code' executable
semiono 16 May 2024, 02:46
No, I don't want to change name. I don't need to change name.
I want to set window size. I need catch an application window and send screen X and screen Y rectangle.

https://www.autohotkey.com/docs/v2/misc/WinTitle.htm#ahk_class
«ClassName accepts a regular expression.»

With AHK I can FindWindow with bla-bla name class, but with Fasm probably.

invoke FindWindow - required full name vs wild card.
Post 16 May 2024, 02:46
View user's profile Send private message Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 732
Ali.Z 16 May 2024, 02:59
ah im not ahk expert, but based on docs.

Code:
WinMove, ,JUCE,x,y    


if for some reason it didnt work,
Code:
Run, <file.exe> ; might not be required
WinWait, , JUCE
WinActivate ; last found window
WinMove, ,,x,y ; last window    

_________________
Asm For Wise Humans
Post 16 May 2024, 02:59
View user's profile Send private message Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 732
Ali.Z 16 May 2024, 03:12
semiono wrote:
invoke FindWindow - required full name vs wild card.


Ali.Z wrote:
try executing the target with CreateProcess, fill STARTUPINO struct, after window created you will get its hwnd. (may not work for every target)

the other method is by using toolhelp32snapshot, looping thru a list of all tasks, just compare the executable name, if found get main thread id, use thread id to get main window's hwnd.


both methods will give you hwnd, first easier but wont work for some win32 programs, 2nd (toolhelp) require more setup, but guaranteed to work.

_________________
Asm For Wise Humans
Post 16 May 2024, 03:12
View user's profile Send private message Reply with quote
Hrstka



Joined: 05 May 2008
Posts: 61
Location: Czech republic
Hrstka 16 May 2024, 08:21
You will probably need to call EnumWindows. Inside the callback function you can use GetClassName and compare the strings to find the appropriate window.
Post 16 May 2024, 08:21
View user's profile Send private message Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 198
Location: section '.code' executable
semiono 16 May 2024, 19:04
Code:
include '%fasm%/win64ax.inc'
section '.code' executable
start:
        sub rsp,8

        invoke EnumWindows,EnumWindowsProc,NULL
        invoke MessageBoxTimeout,HWND_DESKTOP,_sb,'',MB_TOPMOST,LANG_NEUTRAL,5000
exit:
        invoke ExitProcess,NULL

proc    EnumWindowsProc,hWnd,lParam

        mov [hWnd],rcx
        mov [lParam],rdx

        invoke GetWindowText,[hWnd],_wt,128
        test eax,eax
        jz @f
        invoke lstrcat,_sb,_wt
        invoke lstrcat,_sb,_nl
@@:
        mov eax,TRUE
        ret
endp

section '.data' readable writeable

        _nl db 13,10,NULL
        _sb rb 4096
        _wt rb 128
    


I have a list. How to scasb only 'Calc' example text ? Very Happy
How scan string? Embarassed
Post 16 May 2024, 19:04
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1040
Location: Russia
macomics 16 May 2024, 21:18
Code:
        lea     rdx, [_wt]
        lea     r9, [_template]
        xor     rcx, rcx
  @@:
        cmp     byte [r9 + rcx], 0
        jz      @f
        cmp     byte [rdx + rcx], 0
        jz      not_found
        mov     al, [rdx + rcx]
        cmp     al,  [r9 + rcx]
        jnz     not_found
        inc     rcx
        jmp     @b
  @@:
        cmp     byte [rdx + rcx], 0
        jz      match_found
 ; str starts with template
        jmp     next_window
  not_found:
 ; str != template
        jmp     next_window
  match_found:
 ; str == template
  next_window:
 ; ...

 _template db 'JUCE_18', 0    
Post 16 May 2024, 21:18
View user's profile Send private message Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 198
Location: section '.code' executable
semiono 17 May 2024, 00:08
Thanks!!!
Post 17 May 2024, 00:08
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4071
Location: vpcmpistri
bitRAKE 17 May 2024, 07:16
semiono wrote:
How scan string? Embarassed
There are many ways ...
Code:
        lea rdi, [_template]
        lea rsi, [_wt]
        mov ecx, _template_bytes
        repz cmpsb
        jz .found
.not_found:
        ; ...
.found:    
... need save non-volatile registers.

Code:
        mov ecx, _template_bytes
@@:     mov al, [_template + rcx - 1]
        cmp al, [_wt + rcx - 1]
        loopz @B
        jz .found
.not_found:
        ; ...
.found:    
... force base address 32-bit.
Code:
_template db 'JUCE_18'
_template_bytes = $ - _template    

Code:
        mov rdx, 'JUCE_18' shl 8
        mov rax, [_wt]
        shl rax, 8
        cmp rax, rdx
        jz .found
.not_found:
        ; ...
.found:    
Code:
        mov rax, 'JUCE_18' shl 8
        cmp [_wt-1], rax
        jz .found
.not_found:
        ; ...
.found:

        db 0 ; fixed prefix byte
_wt     rb 128    

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 17 May 2024, 07:16
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.