flat assembler
Message board for the users of flat assembler.

Index > Windows > Need help GetStdHandle!!

Author
Thread Post new topic Reply to topic
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP
Every time I try to use GetStdHandle and pass it -10 or -11 for the output or input handles, it does not work unless I use the macro invoke. here's the code that seems to be not working:

push -0x0A
call GetStdHandle

The only thing that works is:

invoke GetStdHandle,STD_OUTPUT_HANDLE

After dissassembling the program that uses "invoke", it pushes -0A as the parameter to GetStdHandle, just like I tried to do. I also have tried pushing -11 and -10 for the input and output handles, but every time it pops up the windows error box and shuts down.. Please Help!!
Post 22 Nov 2007, 17:58
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Code:
call [GetStdHandle]
    
Post 22 Nov 2007, 18:12
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
STD_OUTPUT_HANDLE = -0x0B

As for the error box is because you forgot the brackets, GetStdHandle is a pointer to function, but you are calling the address where this pointer is stored so the processor executes the pointer rather than the actual GetStdHandle's code.

Here is the proper way if you don't want to use invoke
Code:
push STD_OUTPUT_HANDLE 
call [GetStdHandle]
    

Also:
Code:
stdcall [GetStdHandle], STD_OUTPUT_HANDLE    
Post 22 Nov 2007, 18:18
View user's profile Send private message Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP
Oh.. Yeah, it's me Vid, kid you gave help to bout modulus thingies. Didn't know if were on.. Thanks!
Post 22 Nov 2007, 18:18
View user's profile Send private message Visit poster's website Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP
Yes, I didn't notice that little mistake ... I'm trying to get a console encrypted-password storing pgrm going, so I was using 0x0A for input buffer handle and 0x0B for output handle. Still working on some techinque I found for an almost-GetChar function. What am I doing wrong???

call AllocConsole

push -0x0A
call [GetStdHandle]
mov [inhandle],eax

push 0
push numread
push 1
push inchar
push [inhandle]
call [ReadConsole]

This is someone else's code, so bear with me while I debug it quick..
Post 22 Nov 2007, 18:24
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Quote:

call AllocConsole

Again? Rolling Eyes
Post 22 Nov 2007, 19:54
View user's profile Send private message Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP
Yeah.. sorry- just got that code and didn't look over it very well. It's goin good now, got handles workin for the buffers and I'm tryin to get the newilne workin.. Check this out:

message db 'Seperated Strings',0xD,'Newline!!',0

Not workin so far. probably another bug on my end..
Post 22 Nov 2007, 20:01
View user's profile Send private message Visit poster's website Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP
This is weird..

message1 db 'Praise the lord!!',0 ; just for testing..
message2 db 'Hello',0xA,'Newline ',0 ;Try newline

I used two WriteConsole calls and it came up with this

Praise the Lord!! lo
Newline

I don't know what is going on, the word Hello is cut off and I don't know why.. The ascii code 10 decimal, or 0xA, is making a newline but the previous word is cut off. Should I just use SetConsoleCursurPosition? but then, how do I define the structures to send to this API?? sorry for the newbieness, but I used to not need input or output in my prgs
Post 22 Nov 2007, 20:05
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Post entire source next time, and post code in [code] blocks.

Newline in windows should be 13, 10 (0xD, 0xA).
Post 22 Nov 2007, 20:13
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP
Here's what I've been having all the trouble with- Just trying to get the ReadConsole working on strings. It keeps overwriting and not working so well. Any suggestions?

Code:
format PE console

include 'C:\Documents and Settings\II K4RN4G3 II\Desktop\___\Fasm16723\INCLUDE\win32ax.inc'

section '.data' data readable writeable

  ;WriteConsole
  message    DB 'Enter a Number: ',0
  TryThis    DB 'Newline?',0
  numwritten DB ?

  ;ReadConsole
  numread    DD ?
  inchar     DB ?

  ;GetStdHandle
  inhandle   DD ?
  outhandle  DD ?

section '.code' code readable executable

  start:
        ;Get Input Buffer Handle
        push -10
        call [GetStdHandle]
        mov [inhandle],eax

        ;Get Output Buffer Handle
        push -11
        call [GetStdHandle]
        mov [outhandle],eax

        ;Write initial Message to console
        push 0
        push numwritten
        push 16
        push message
        push [outhandle]
        call [WriteConsole]

        ;Read in 2 bytes from the console
        push 0
        push numread
        push 2
        push inchar
        push [inhandle]
        call [ReadConsole]

        ;Display the bytes read from console
        push 0
        push numwritten
        push numread    ; Numread from previous call
        push inchar        ;Using buffer from previous call
        push [outhandle]
        call [WriteConsole]

        ;Read in 2 bytes- This function doesn't even call properly
        push 0
        push numread      ;Overwrite other variable please?
        push 2                 
        push inchar           ;Buffer used before, should be overwritten here
        push [inhandle]
        call [ReadConsole]

        push 0
        call [ExitProcess]
   .end start
    
Post 22 Nov 2007, 20:58
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
inchar must be buffer big enough to hold entire string. Otherwise, data following it are rewritten by what you read. Your buffer has only single byte, but you are reading 2 characters. that means one byte of following "inhandle" will be overwritten.

use something like this:

Code:
inchar rb 100  ;100 byte buffer
    
Post 22 Nov 2007, 21:09
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP
Thanks again- I got all things set up and now I'm organizing the encrypted file structure. Just going to be a console app, not a command-line only thing. If I find a code section on this web site, I'll post the app there once I get it finished in a few days.
Post 22 Nov 2007, 23:47
View user's profile Send private message Visit poster's website Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Why do you insist on using magic numbers instead of symbolic constants? bad bad bad practice.
Post 23 Nov 2007, 03:17
View user's profile Send private message Visit poster's website Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP
Some one else's code, as I said before... Just tried to throw it together in a hurry, I have long since fixed those problems. The only thing now that is a mystery to me is how I can manually create a structure and pass it to SetConsoleCursorPosition. Using the fasm macros isn't working too well either. Here's the section of code that doesn't want to send the structure to API call.

Code:
section '.data' data readable writeable

struc pos x,y
{
     .x dw x
     .y dw y
}

;GetStdHandle
hStdIn         DD 1
hStdOut        DD 1

;PauseTemp
PauseRead      RB 2
PauseChar      RB 100

;ConsolePrint
NumWritten     RB 2
message        DB 'Hello',0

section '.code' code readable executable

SetConsoleCursorPos:
        ;Save eax, used for handle transfer
        push eax

        ;Get Input Buffer Handle
        push -0x0A
        call [GetStdHandle]
        mov [hStdIn],eax

        ;Get Output Buffer Handle
        push -0x0B
        call [GetStdHandle]
        mov [hStdOut],eax

        consolepos pos 4,5

        ;SetCursorPos. to 4,5
        push [consolepos]
        push [hStdOut]
        call [SetConsoleCursorPosition]

        ;Test Printout
        push 0
        push NumWritten
        push 5             ; "Hello"
        push message
        push [hStdOut]
        call [WriteConsole]

        call PauseTemp  ; Just a ReadConsole call
        push 0
        call [ExitProcess]

.end SetConsoleCursorPos
    
Post 23 Nov 2007, 19:39
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2914
Location: [RSP+8*5]
bitRAKE
consolepos should be in the data section - not the middle of the code.
Post 23 Nov 2007, 22:09
View user's profile Send private message Visit poster's website Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP
I thought that I tried that already, but I'll check again.. I'm flying through the rest of the code but I keep getting stuck on any sort of output/input. I'm not used to having user-friendly programs . Thanks twice bitRAKE lol
Post 23 Nov 2007, 22:18
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.