flat assembler
Message board for the users of flat assembler.

Index > Windows > ScreenBufferSize

Author
Thread Post new topic Reply to topic
semiono



Joined: 31 Aug 2007
Posts: 176
Location: section '.code' executable
semiono
Code:
format PE Console
include '%fasm%\win32ax.inc'
section '.code' executable
start:
        invoke GetSystemMetrics,SM_CXSCREEN
        mov [x],eax
        cmp eax,800
        jne @f
        invoke RegCreateKeyEx,HKCU,'Console',NULL,NULL,REGT,KEY_WRITE,NULL,phkResult,NULL
        invoke RegSetValueEx,[phkResult],'CursorSize',NULL,REG_DWORD,@00000010,4
        invoke RegSetValueEx,[phkResult],'FaceName',NULL,REG_SZ,'Lucida Console',14
        invoke RegSetValueEx,[phkResult],'FontFamily',NULL,REG_DWORD,@00000036,4
        invoke RegSetValueEx,[phkResult],'FontSize',NULL,REG_DWORD,@00120000,4
        invoke RegSetValueEx,[phkResult],'FullScreen',NULL,REG_DWORD,@00000000,4
        invoke RegSetValueEx,[phkResult],'ScreenBufferSize',NULL,REG_DWORD,@0012003a,4
        invoke RegSetValueEx,[phkResult],'ScreenColors',NULL,REG_DWORD,@0000000e,4
        invoke RegSetValueEx,[phkResult],'WindowPosition',NULL,REG_DWORD,@001c004e,4
        invoke RegSetValueEx,[phkResult],'WindowSize',NULL,REG_DWORD,@0012003a,4
        invoke RegCloseKey,[phkResult]
        jmp sh
@@:
        cmp eax,1024
        jne @f
        invoke RegCreateKeyEx,HKCU,'Console',NULL,NULL,REGT,KEY_WRITE,NULL,phkResult,NULL
        invoke RegSetValueEx,[phkResult],'CursorSize',NULL,REG_DWORD,@00000010,4
        invoke RegSetValueEx,[phkResult],'FaceName',NULL,REG_SZ,'Lucida Console',14
        invoke RegSetValueEx,[phkResult],'FontFamily',NULL,REG_DWORD,@00000036,4
        invoke RegSetValueEx,[phkResult],'FontSize',NULL,REG_DWORD,@00120000,4
        invoke RegSetValueEx,[phkResult],'FullScreen',NULL,REG_DWORD,@00000000,4
        invoke RegSetValueEx,[phkResult],'ScreenBufferSize',NULL,REG_DWORD,@0018004a,4
        invoke RegSetValueEx,[phkResult],'ScreenColors',NULL,REG_DWORD,@0000000e,4
        invoke RegSetValueEx,[phkResult],'WindowPosition',NULL,REG_DWORD,@001c0064,4
        invoke RegSetValueEx,[phkResult],'WindowSize',NULL,REG_DWORD,@0018004a,4
        invoke RegCloseKey,[phkResult]
        jmp sh
@@:
        cmp eax,1152
        jne @f
        invoke RegCreateKeyEx,HKCU,'Console',NULL,NULL,REGT,KEY_WRITE,NULL,phkResult,NULL
        invoke RegSetValueEx,[phkResult],'CursorSize',NULL,REG_DWORD,@00000010,4
        invoke RegSetValueEx,[phkResult],'FaceName',NULL,REG_SZ,'Lucida Console',14
        invoke RegSetValueEx,[phkResult],'FontFamily',NULL,REG_DWORD,@00000036,4
        invoke RegSetValueEx,[phkResult],'FontSize',NULL,REG_DWORD,@00120000,4
        invoke RegSetValueEx,[phkResult],'FullScreen',NULL,REG_DWORD,@00000000,4
        invoke RegSetValueEx,[phkResult],'ScreenBufferSize',NULL,REG_DWORD,@00190050,4
        invoke RegSetValueEx,[phkResult],'ScreenColors',NULL,REG_DWORD,@0000000a,4
        invoke RegSetValueEx,[phkResult],'WindowPosition',NULL,REG_DWORD,@001c0082,4
        invoke RegSetValueEx,[phkResult],'WindowSize',NULL,REG_DWORD,@00190050,4
        invoke RegCloseKey,[phkResult]
        jmp sh
@@:
        cmp eax,1280
        jne sh
        invoke RegCreateKeyEx,HKCU,'Console',NULL,NULL,REGT,KEY_WRITE,NULL,phkResult,NULL
        invoke RegSetValueEx,[phkResult],'CursorSize',NULL,REG_DWORD,@00000010,4
        invoke RegSetValueEx,[phkResult],'FaceName',NULL,REG_SZ,'Lucida Console',14
        invoke RegSetValueEx,[phkResult],'FontFamily',NULL,REG_DWORD,@00000036,4
        invoke RegSetValueEx,[phkResult],'FontSize',NULL,REG_DWORD,@00120000,4
        invoke RegSetValueEx,[phkResult],'FullScreen',NULL,REG_DWORD,@00000000,4
        invoke RegSetValueEx,[phkResult],'ScreenBufferSize',NULL,REG_DWORD,@001c0050,4
        invoke RegSetValueEx,[phkResult],'ScreenColors',NULL,REG_DWORD,@0000000e,4
        invoke RegSetValueEx,[phkResult],'WindowPosition',NULL,REG_DWORD,@001c00c8,4
        invoke RegSetValueEx,[phkResult],'WindowSize',NULL,REG_DWORD,@001c0050,4
        invoke RegCloseKey,[phkResult]
sh:
        invoke GetStdHandle,STD_OUTPUT_HANDLE
        mov [stdo],eax
        mov [StartSTR.hStdOutput],eax
        invoke GetStdHandle,STD_INPUT_HANDLE
        mov [stdi],eax
        mov [StartSTR.hStdInput],eax

        invoke GetCommandLine
        mov [clcc],eax
@@:
        cmp byte [eax],NULL
        je exit
        cmp byte [eax],' '
        je @f
        inc eax
        jmp @r
@@:
        mov [rlcc],eax

        mov [StartSTR.cb],sinfo
        mov [StartSTR.dwFlags],STARTF_USESTDHANDLES

        invoke ExpandEnvironmentStrings,'%ProgramFiles%\Far\Far.exe',exec,MAX_PATH
        invoke CreateProcess,exec,[rlcc],NULL,NULL,\
               DETACHED_PROCESS,NORMAL_PRIORITY_CLASS,NULL,NULL,StartSTR,StartInfo
        cmp eax,NULL
        je exit

        invoke WaitForSingleObject,[StartInfo.hProcess],INFINITE
exit:
        invoke  WriteConsoleA,[stdo],finfo,49,NULL,NULL

        invoke CloseHandle,[stdo]
        invoke CloseHandle,[stdi]
        invoke ExitProcess,NULL

.end start

section '.data' readable

        HKCU = HKEY_CURRENT_USER
        REGT = REG_OPTION_NON_VOLATILE

        INFINITE dd 0xffffffff

        @00000000 dd 0x00000000
        @00000010 dd 0x00000010
        @0000000a dd 0x0000000a
        @0000000e dd 0x0000000e
        @00000036 dd 0x00000036
        @00120000 dd 0x00120000

        @001c004e dd 0x001c004e
        @0012003a dd 0x0012003a

        @001c0064 dd 0x001c0064
        @0018004a dd 0x0018004a

        @001c0082 dd 0x001c0082
        @00190050 dd 0x00190050

        @001c00c8 dd 0x001c00c8
        @001c0050 dd 0x001c0050

        sinfo STARTUPINFO
        finfo db '# Far.exe ''2.0.0.1420 ''2001-2005 GmbH, Semiono *',10


section '.data' readable writable

        phkResult dd ?
        x dd ?
        stdo dd NULL
        stdi dd NULL
        clcc dd ?
        rlcc dd ?
        exec db MAX_PATH dup ?

        StartSTR STARTUPINFO <>
        StartInfo PROCESS_INFORMATION <>    


Only after second start the cmd.exe get settings from reg. What is happens? Rolling Eyes
I try Invoke Sleep,1000 but it wrong. How to restart registry? Razz

I don't need finfo it's my stupid stub ))) But i have some problem here...
With params it work good - far.exe c:\zzz etc.
But there an empty params is kept quiet -
far.exe - nothing starting (in cmd.exe mode)! ??

Where is a CreateProcess bug? Mad

PS INFINITE defined in masm32 only Confused

_________________
Memory=8388608
Post 07 Oct 2010, 21:14
View user's profile Send private message ICQ Number Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 176
Location: section '.code' executable
semiono
Code:
        mov [StartSTR.cb],sinfo
        mov [StartSTR.dwFlags],STARTF_USEPOSITION ;STARTF_USESTDHANDLES
        mov dword [StartSTR.dwX],0x0
        mov dword [StartSTR.dwY],0x1c

        invoke CreateProcess,exec,[rlcc],NULL,NULL,\
               CREATE_NEW_CONSOLE,NORMAL_PRIORITY_CLASS,NULL,NULL,StartSTR,StartInfo ;DETACHED_PROCESS
    

not result! Confused
Post 07 Oct 2010, 23:33
View user's profile Send private message ICQ Number Reply with quote
lemask



Joined: 04 Oct 2010
Posts: 19
lemask
Have you checked the return codes?
Post 08 Oct 2010, 06:32
View user's profile Send private message Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 176
Location: section '.code' executable
semiono
What is SIZE INFO in fasm?

mov [StartSTR.cb], SIZE INFO < masm32


mov [StartSTR.cb], $-sinfo ??
Post 12 Oct 2010, 14:14
View user's profile Send private message ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17252
Location: In your JS exploiting you and your system
revolution
Code:
mov [StartSTR.cb],sizeof.STARTUPINFO    
Post 12 Oct 2010, 14:17
View user's profile Send private message Visit poster's website Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 176
Location: section '.code' executable
semiono
* I have an idea to collect myself %fasm%\const.inc

1. What is right from that -

INFINITE dd 0xffffffff or INFINITE equ 0xffffffff or INFINITE = 0xffffffff

Shocked

2. If it possible i want make like that

Code:
; const.inc
section '.code' executable readable writable ; not sure that !
        invoke ExpandEnvironmentStrings,'%WinDir%',WinDir,MAX_PATH
WinDir dd ?    


Code:
 ; code.asm
include '%fasm%/const.inc'
 section '.data' data readable writable
       lpFile db WinDir,'\Path\File.exe',0 
    

But it's not correctly. How it possible to improove? Confused
Post 12 Oct 2010, 18:13
View user's profile Send private message ICQ Number Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
semiono,

That depends on whether you need -1 directly, or an address of -1. dd gives you latter, equ and = make it plain.

WinDir dd ? is only 4-byte (i.e. char) buffer for the result of ExpandEnvironmentStrings(), perhaps it's not enough. Wink

db WinDir is rarely a correct directive (hint: any WinDir value outside [-128…255] range will raise complaints from compiler).
Post 12 Oct 2010, 18:33
View user's profile Send private message Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 176
Location: section '.code' executable
semiono
Code:
format PE Console
include '%fasm%\win32ax.inc'
section '.code' executable
start:
        invoke GetConsoleWindow
               mov [hWnd],eax
               lea eax,[@rc]
        invoke GetWindowRect,[hWnd],eax
        invoke SetWindowPos,[hWnd],HWND_TOP,50,28,1024,480,SWP_SHOWWINDOW

        invoke CreateProcess,NULL,'cmd.exe',NULL,NULL,TRUE,NULL,NULL,NULL,@si,@pi

        invoke WaitForSingleObject,[@pi.hProcess],INFINITE
        invoke CloseHandle,[@pi.hProcess]
        invoke CloseHandle,[@pi.hProcess]
exit:
        invoke ExitProcess,NULL

.end start

section '.data' readable writable

        INFINITE = 0xffffffff
        @si STARTUPINFO
        @pi PROCESS_INFORMATION
        @rc RECT
        hWnd dd ?    

Good work!

Please, anybody, what is need to initializate the SetConsoleTextAttribute?
Structures, Handles... How it's to?...
is it not need call CreateConsoleScreenBuffer?

Some full code examples is enough for me Very Happy

---
Code:
format PE Console
include '%fasm%\win32ax.inc'
section '.code' executable
start:
        invoke GetStdHandle,STD_OUTPUT_HANDLE
               mov [@si.hStdOutput],eax

        invoke GetConsoleWindow
               mov [hWnd],eax
               lea eax,[@rc]

        invoke GetWindowRect,[hWnd],eax
        invoke SetWindowPos,[hWnd],HWND_TOP,0,38,1024,480,SWP_SHOWWINDOW
        invoke SetConsoleTextAttribute,[@si.hStdOutput],0x0009

        invoke CreateProcess,NULL,'cmd.exe',NULL,NULL,TRUE,NULL,NULL,NULL,@si,@pi

        invoke WaitForSingleObject,[@pi.hProcess],INFINITE
        invoke CloseHandle,[@pi.hProcess]
        invoke CloseHandle,[@pi.hProcess]
exit:
        invoke ExitProcess,NULL

.end start

section '.data' readable writable

        INFINITE = 0xffffffff
        @si STARTUPINFO
        @pi PROCESS_INFORMATION
        @rc RECT
        hWnd dd ?    

Ok!


Last edited by semiono on 26 Oct 2010, 00:30; edited 1 time in total
Post 25 Oct 2010, 20:28
View user's profile Send private message ICQ Number Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 176
Location: section '.code' executable
semiono
Image
SetCurrentConsoleFontEx >8---
Minimum supported client Windows Vista


What do for XP ! Mad

SetConsoleFontSize() isn't declared but i need (Lucida Console 18 ) font.
Is it something good more undeclarated ?
Post 26 Oct 2010, 00:29
View user's profile Send private message ICQ Number Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: behind the arc
Picnic
There is a method programmatically to change console font in runtime using some undocumented Windows functions, although it is a bit tricky.
Code:
;struct _CONSOLE_FONT {
;        DWORD index;
;        COORD dim;
;} CONSOLE_FONT;

;SetConsoleFont(HANDLE hOutput, DWORD fontIndex);
;GetConsoleFontInfo(HANDLE hOutput, BOOL bMaximize, DWORD numFonts, CONSOLE_FONT* info);
;GetNumberOfConsoleFonts(); 
    


Here is some code i've written based on a C++ sample, program loops through all available console fonts and display sizes.
It works on my XP but i never test it on Vista or 7.
Use at your own risk.
Code:

            format PE CONSOLE 4.0
            entry main

            include "win32axp.inc"

            
section ".idata" import data readable writeable

            library kernel32, "KERNEL32.DLL",\
                user32, "USER32.DLL"

            include "\api\kernel32.inc"
            include "\api\user32.inc"

            SetConsoleFont equ PSetConsoleFont
            GetConsoleFontInfo equ PGetConsoleFontInfo
            GetNumberOfConsoleFonts equ PGetNumberOfConsoleFonts

.data
            szSetConsoleFont db "SetConsoleFont",0
            szGetConsoleFontInfo db "GetConsoleFontInfo",0
            szGetNumberOfConsoleFonts db "GetNumberOfConsoleFonts",0

            kernel32 db "kernel32.dll",0
            ErrorTxt db "API Failed",0
            FoundTxt db "Found font X(%d) Y(%d)",13,10,0

Align 4
            Temp1                     dd 0
            hModule                   dd 0
            hOut                      dd 0
            hBuffer                   dd 0
            FontArray                 dd 0
            NumberOfFonts             dd 0
            PSetConsoleFont           dd 0
            PGetConsoleFontInfo       dd 0
            PGetNumberOfConsoleFonts  dd 0

            ;CONSOLE_FONT:
            ;        .index dd ?
            ;        .x dw ?
            ;        .y dw ?

.code
main:
            invoke GetModuleHandle, kernel32
            call TestAPI
            mov [hModule], eax

            ; Undocumented API's

            stdcall LoadFunc, [hModule], szSetConsoleFont, PSetConsoleFont
            stdcall LoadFunc, [hModule], szGetConsoleFontInfo, PGetConsoleFontInfo
            stdcall LoadFunc, [hModule], szGetNumberOfConsoleFonts, PGetNumberOfConsoleFonts

            invoke GetStdHandle, STD_OUTPUT_HANDLE
            mov [hOut], eax

            invoke GetNumberOfConsoleFonts
            .if ~eax
                     ; No fonts found
                     ;
                     mov eax, 1
                     jmp Exit
             .endif

            mov [NumberOfFonts], eax

;---------------------------------------------------------
; Allocate: (NumberOfFonts*SIZEOF.CONSOLE_FONT)
;           +Length_of_Buffer
;
;---------------------------------------------------------
            lea eax, [(eax*8)+256]
            invoke LocalAlloc, LMEM_ZEROINIT, eax
            call TestAPI
            mov [hBuffer], eax
            add eax, 256
            mov [FontArray], eax                        

            invoke GetConsoleFontInfo, [hOut], 0, [NumberOfFonts], [FontArray]
            mov ebx, [FontArray]

;---------------------------------------------------------
; Loop through all available console fonts
; and display sizes.
;
;---------------------------------------------------------
@@:         invoke GetConsoleFontSize, [hOut], dword [ebx]
            movzx ecx, ax
            shr eax, 16
            mov edx, eax
            cinvoke wsprintf, [hBuffer], FoundTxt, ecx, edx
            invoke WriteConsole, [hOut], [hBuffer], eax, Temp1, 0
            invoke SetConsoleFont, [hOut], dword [ebx]
            call TestAPI
            invoke Sleep, 1000
            add ebx, 8
            dec [NumberOfFonts]
            ja @B

            xor eax, eax
Exit:       invoke ExitProcess, eax

;---------------------------------------------------------
proc LoadFunc uses ecx edx, hMod, lpName, pFunc
;
;---------------------------------------------------------
            invoke GetProcAddress, [hMod], [lpName]
            call TestAPI
            mov edx, [pFunc]
            mov [edx], eax
            ret
endp

;---------------------------------------------------------
TestAPI:
;
;---------------------------------------------------------
            test eax, eax
            jnz @F
            invoke MessageBox, HWND_DESKTOP, ErrorTxt, 0, MB_OK
            mov eax, 1
            jmp Exit
@@:         ret

    


Last edited by Picnic on 27 Oct 2010, 19:54; edited 1 time in total
Post 27 Oct 2010, 07:19
View user's profile Send private message Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 176
Location: section '.code' executable
semiono
Thanks!!!!!!!!!!!!!!!!!! "Use at your own risk." Very well
Good!!! And I don't need Vista anyway! Smile
----
I went to test Smile
Post 27 Oct 2010, 14:44
View user's profile Send private message ICQ Number Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: behind the arc
Picnic
You're welcome semiono.
p.s: I did a small change in 'Allocate' part.
Post 27 Oct 2010, 20:00
View user's profile Send private message Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 176
Location: section '.code' executable
semiono
Picnic, this code available to set (Lucida Console 18 ) ?
Is it only Raster Fonts enums?
On the fly i don't understant what is font i see in animation...

And please, howto set some assign font n x m and stop enums other?
I can't quickly read and modify yor large code Smile
Post 27 Oct 2010, 21:47
View user's profile Send private message ICQ Number Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: behind the arc
Picnic
Quote:
Is it only Raster Fonts enums?
It appears so, yes. Haven't figure out how to enum Lucida fonts yet.



Quote:
howto set some assign font n x m and stop enums other

ebx is loaded with the FontArray start address and each font entry in table is a CONSOLE_FONT structure which occupies 8 bytes, so
Code:
invoke SetConsoleFont, [hOut], dword [ebx+0]    
will set console font to the first entry in table, dword [ebx+8] on the second and so on.



Line below returns font size values in eax
Code:
invoke GetConsoleFontSize, [hOut], dword [ebx]     

Split eax lowword-highword (width-height) to ecx-edx
Code:
               
movzx ecx, ax
shr eax, 16
mov edx, eax             
    


Hope this helps.
Post 27 Oct 2010, 23:02
View user's profile Send private message Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 176
Location: section '.code' executable
semiono
Thanks!
Post 28 Oct 2010, 02:35
View user's profile Send private message ICQ Number Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 176
Location: section '.code' executable
semiono
regs way - close console and try again Laughing


Description:
Download
Filename: $$FAR$$.asm
Filesize: 5.76 KB
Downloaded: 61 Time(s)


_________________
Memory=8388608
Post 29 Oct 2010, 02:28
View user's profile Send private message ICQ Number Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 176
Location: section '.code' executable
semiono
What you say about it?

push TRUE vs jmp's
...

And how it work?
lpData dd NULL dup NULL Smile
Post 29 Oct 2010, 02:43
View user's profile Send private message ICQ Number 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-2020, Tomasz Grysztar.

Powered by rwasa.