flat assembler
Message board for the users of flat assembler.

Index > Windows > FillConsoleOutputAttribute doesn't work?

Author
Thread Post new topic Reply to topic
TmX



Joined: 02 Mar 2006
Posts: 821
Location: Jakarta, Indonesia
TmX
I have a C code, which sets the console background color to green:
Code:

#include <windows.h>

#define FOREGROUND_WHITE        FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN

int main(void){
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD coord = {0,0};
    DWORD result;
    FillConsoleOutputAttribute(handle, FOREGROUND_WHITE | BACKGROUND_GREEN, 500, coord, &result);
    printf("Hello world");
    return 0;
}
    


In this is my FASM translation:
Code:

format PE console 4.0

include 'win32a.inc'

entry start

section '.data' data readable writeable 
handle dd ? 
struc COORD {
    .X dw ?
    .Y dw ?
}
coord COORD
result dw ?
msg db 'Hello world',0
fmt db '%s', 0
color dd 13 

section '.code' readable executable
start:
    invoke GetStdHandle, STD_OUTPUT_HANDLE
    mov [handle], eax
    mov [coord.X], 0
    mov [coord.Y], 0
    invoke FillConsoleOutputAttribute, handle, [color], 500, coord, result 
    invoke printf, fmt, msg
    invoke ExitProcess, 0

section '.idata' data import readable writeable
library kernel32, 'kernel32.dll', msvcrt, 'msvcrt.dll'
import kernel32, ExitProcess, 'ExitProcess',\ 
                 GetStdHandle, 'GetStdHandle',\
                 FillConsoleOutputAttribute, 'FillConsoleOutputAttribute'
import msvcrt, printf, 'printf'
    


But that doesn't work?
Any help?
BTW, how to translate this part into FASM:
Code:
#define FOREGROUND_WHITE       FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN    

Embarassed
Post 03 May 2012, 04:45
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
Coord must be passed directly, it is not a pointer:
Code:
 ..., dword[coord], ...    
Post 03 May 2012, 04:56
View user's profile Send private message Visit poster's website Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
[handle] not handle
result dd not dw

FOREGROUND_WHITE EQU FOREGROUND_RED + FOREGROUND_BLUE + FOREGROUND_GREEN
Post 03 May 2012, 08:21
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Code:
invoke FillConsoleOutputAttribute, [handle], 0xff, 500, dword[coord], result    


NOTE: 0xff specifies foreground and background color attributes.
Post 03 May 2012, 08:43
View user's profile Send private message 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.