flat assembler
Message board for the users of flat assembler.
Index
> Windows > using printf in GUI application Goto page 1, 2 Next |
Author |
|
revolution 10 Mar 2014, 12:03
GUI processes can open console windows and read and write them in the same way that a console process can open GUI windows and interact with the user. Console processes can also detach from the console and continue with just using a GUI. You can even close all console and GUI windows and have the process run in stealth mode (perhaps with just a tray icon to show current status).
Last edited by revolution on 10 Mar 2014, 13:48; edited 1 time in total |
|||
10 Mar 2014, 12:03 |
|
sleepsleep 10 Mar 2014, 12:52
so, what happened if you use printf in GUI windows application,
since there is not output console. |
|||
10 Mar 2014, 12:52 |
|
revolution 10 Mar 2014, 13:46
Try it and tell us what happens.
|
|||
10 Mar 2014, 13:46 |
|
sleepsleep 10 Mar 2014, 14:13
well,
i tried, using the template.asm provided in FASM example folder. Code: format PE GUI 4.0 entry start include '%include%\win32ax.inc' section '.text' code readable executable start: cinvoke printf,<'hello world',0> invoke GetModuleHandle,0 if you change the application type to console, a hello world will get printed out, now, if it is GUI 4.0 i am curious, as what happened inside when there is no standard output stream. |
|||
10 Mar 2014, 14:13 |
|
revolution 10 Mar 2014, 14:20
Check the error code. You should be doing this anyway as part of normal the programming procedure. Ignoring error codes is a great way to have bugs
|
|||
10 Mar 2014, 14:20 |
|
sleepsleep 10 Mar 2014, 14:38
revolution wrote: Check the error code. You should be doing this anyway as part of normal the programming procedure. Ignoring error codes is a great way to have bugs i don't get it? what should i check after using printf? |
|||
10 Mar 2014, 14:38 |
|
revolution 10 Mar 2014, 14:41
sleepsleep wrote: what should i check after using printf? Doesn't the C-library return error codes? I've never used it so I don't know what it does to indicate errors, but I assume there is something. If I am wrong and it has no error code to check then C is more broken that I thought. |
|||
10 Mar 2014, 14:41 |
|
sleepsleep 10 Mar 2014, 14:49
http://msdn.microsoft.com/en-us/library/aa272863%28v=vs.60%29.aspx
Quote:
|
|||
10 Mar 2014, 14:49 |
|
sleepsleep 10 Mar 2014, 14:50
i guess,
i would get negative value, just curious what happened when you do printf in GUI 4.0... |
|||
10 Mar 2014, 14:50 |
|
revolution 10 Mar 2014, 14:52
Tell us what error code you get. Why all the guessing when you have a computer right there in front of you?
|
|||
10 Mar 2014, 14:52 |
|
sleepsleep 10 Mar 2014, 15:05
ok, i am wrong,
and we got surprise, Code: section '.text' code readable executable start: cinvoke printf,<'hello world',0> cinvoke wsprintf,b1,<'ret = %ld',0>,eax invoke MessageBox,NULL,b1,b1,MB_OK invoke GetModuleHandle,0 section '.data' data readable writeable b1 rb 0xFF |
|||
10 Mar 2014, 15:05 |
|
revolution 10 Mar 2014, 15:18
So maybe your message was sent to the NSA. I hope you said nice things to them.
Anyhow, it appears as though the C-library is very broken in this respect since it returns success for something that clearly failed. BTW: No need for the zero terminators in the strings. The macros insert them automatically. |
|||
10 Mar 2014, 15:18 |
|
sleepsleep 10 Mar 2014, 15:47
revolution wrote:
oh, great, thanks, never knew this before, keep on putting 0 for a while already. |
|||
10 Mar 2014, 15:47 |
|
Heskeutz 10 Mar 2014, 16:25
revolution wrote: Anyhow, it appears as though the C-library is very broken in this respect since it returns success for something that clearly failed. |
|||
10 Mar 2014, 16:25 |
|
sleepsleep 10 Mar 2014, 16:40
Heskeutz wrote:
nope in GUI 4.0 |
|||
10 Mar 2014, 16:40 |
|
LocoDelAssembly 11 Mar 2014, 00:34
Tried the following code:
Code: format pe gui include 'win32ax.inc' cinvoke printf, msg invoke ExitProcess, 0 msg TCHAR "Hello World", 10, 0 align 4 ; Just to be safe data import library kernel32, 'kernel32.dll',\ msvcrt,'msvcrt.dll' include 'api/kernel32.inc' import msvcrt,\ printf, 'printf' end data Code: C:\Escritorio\Assembly\snippets>console.exe C:\Escritorio\Assembly\snippets>console.exe > test.txt C:\Escritorio\Assembly\snippets>type test.txt Hello World |
|||
11 Mar 2014, 00:34 |
|
sleepsleep 11 Mar 2014, 18:24
yeah, interesting,
maybe there is a hidden STD_OUTPUT_HANDLE for GUI application, not sure how big the buffer size before overflow, doesn't seem documented anywhere after a series of google. by logic then, a hidden STD_INPUT_HANDLE would be available too. |
|||
11 Mar 2014, 18:24 |
|
revolution 11 Mar 2014, 23:22
sleepsleep wrote: maybe there is a hidden STD_OUTPUT_HANDLE for GUI application, not sure how big the buffer size before overflow, doesn't seem documented anywhere after a series of google. |
|||
11 Mar 2014, 23:22 |
|
sleepsleep 12 Mar 2014, 01:14
i guess,
as you said, maybe it really ends up in \Device\Null Quote: In the Windows NT system and its successors, it is named \Device\Null internally, and the DOS NUL is an alias for it. However, at the command prompt, \\.\Null is not a valid destination, since the command prompt can only access a device through an alias. (Windows Fundamentals for Legacy PCs, a derivative of Windows XP, does not include NUL: in its default installation, which breaks some programs; however, it can easily be added by copying the device driver file null.sys from a full XP install.) Code: cinvoke printf,<'hello world',0> cinvoke wsprintf,b1,<'ret = %ld',0>,eax invoke MessageBox,NULL,b1,b1,MB_OK cinvoke scanf,'%s',b1 invoke MessageBox,NULL,b1,b1,MB_OK invoke GetModuleHandle,0 template.exe < hello.txt hello.txt got string hello world result where the word, "world" gone? |
|||
12 Mar 2014, 01:14 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.