汇编和Win32API输入输出

发布于 2024-12-19 00:08:45 字数 1894 浏览 2 评论 0原文

我正在尝试解决这个问题,但有点难住了。我想做的是使用 win32 库中的 ReadConsole/WriteConsole 函数并让它在一定程度上工作,但就是不存在。我无法让第二个写入控制台正常工作。我认为我没有将缓冲区发送到右侧的变量。我一定在这里遗漏了一些东西,但我不知道它是什么。 这是我到目前为止所拥有的

TITLE MASM Template                     (main.asm)

  ; Description:
  ; 
   ; Revision date:

 INCLUDE Irvine32.inc
 BufSize = 80
 .data
  endl EQU <0dh,0ah>            ; end of line sequence

 ;variable holders
 firstN db ?
 fNSize db ($-firstN)

 ;messages for getting input
 fName LABEL BYTE
BYTE "Enter your first name", endl
 fNameSize DWORD ($-fName)

 ;output handlers
 consoleHandle HANDLE 0     ; handle to standard output device
 bytesWritten  DWORD ?      ; number of bytes written

 ;input handlers
 buffer BYTE BufSize DUP(?)
 stdInHandle HANDLE ?
 bytesRead   DWORD ?

 .code
 main PROC
 ; Get the console output handle:
    INVOKE GetStdHandle, STD_OUTPUT_HANDLE
  mov consoleHandle,eax

  ; Write a string to the console:
INVOKE WriteConsole,
  consoleHandle,        ; console output handle
  ADDR fName,           ; string pointer
  fNameSize,            ; string length
  ADDR bytesWritten,    ; returns num bytes written
  0                     ; not used

   ; Get handle to standard input
INVOKE GetStdHandle, STD_INPUT_HANDLE
   mov   stdInHandle,eax

   ; Wait for user input
 INVOKE ReadConsole, stdInHandle, ADDR buffer,
  BufSize, ADDR bytesRead, 0

 ;cheack to see if read consol worked
  mov esi, OFFSET buffer
  mov ecx, bytesRead
  mov ebx, TYPE buffer
  call DumpMem

 ;move the input into the variable
  mov firstN, TYPE  buffer



   ; Write a string to the console:
INVOKE WriteConsole,
  consoleHandle,        ; console output handle
  ADDR firstN,          ; string pointer
  fNSize,           ; string length
  ADDR bytesWritten,    ; returns num bytes written
  0                     ; not used


INVOKE ExitProcess,0
   main ENDP
  END main

感谢您的帮助:)

I am trying to figure this out but am stumped a bit. What I am trying to do is to use the ReadConsole/WriteConsole functions from the win32 lib and got it to work a degree but just not there. I am having trouble getting the second write console working correctly. I don't think I am sending the buffer to the variable right. I must be missing something here and I dont know what it is.
Here is what I have so far

TITLE MASM Template                     (main.asm)

  ; Description:
  ; 
   ; Revision date:

 INCLUDE Irvine32.inc
 BufSize = 80
 .data
  endl EQU <0dh,0ah>            ; end of line sequence

 ;variable holders
 firstN db ?
 fNSize db ($-firstN)

 ;messages for getting input
 fName LABEL BYTE
BYTE "Enter your first name", endl
 fNameSize DWORD ($-fName)

 ;output handlers
 consoleHandle HANDLE 0     ; handle to standard output device
 bytesWritten  DWORD ?      ; number of bytes written

 ;input handlers
 buffer BYTE BufSize DUP(?)
 stdInHandle HANDLE ?
 bytesRead   DWORD ?

 .code
 main PROC
 ; Get the console output handle:
    INVOKE GetStdHandle, STD_OUTPUT_HANDLE
  mov consoleHandle,eax

  ; Write a string to the console:
INVOKE WriteConsole,
  consoleHandle,        ; console output handle
  ADDR fName,           ; string pointer
  fNameSize,            ; string length
  ADDR bytesWritten,    ; returns num bytes written
  0                     ; not used

   ; Get handle to standard input
INVOKE GetStdHandle, STD_INPUT_HANDLE
   mov   stdInHandle,eax

   ; Wait for user input
 INVOKE ReadConsole, stdInHandle, ADDR buffer,
  BufSize, ADDR bytesRead, 0

 ;cheack to see if read consol worked
  mov esi, OFFSET buffer
  mov ecx, bytesRead
  mov ebx, TYPE buffer
  call DumpMem

 ;move the input into the variable
  mov firstN, TYPE  buffer



   ; Write a string to the console:
INVOKE WriteConsole,
  consoleHandle,        ; console output handle
  ADDR firstN,          ; string pointer
  fNSize,           ; string length
  ADDR bytesWritten,    ; returns num bytes written
  0                     ; not used


INVOKE ExitProcess,0
   main ENDP
  END main

Thanks for any help :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦初启 2024-12-26 00:08:45

firstN 和 fNSize 都是一个字节,这不是您想要的。只需对第二个 WriteConsole 调用执行此操作:

INVOKE WriteConsole,
  consoleHandle,        ; console output handle
  ADDR buffer,          ; string pointer
  bytesRead,            ; string length
  ADDR bytesWritten,    ; returns num bytes written
  0                     ; not used

firstN and fNSize are each a single byte and that's not what you want. Simply do this for the second WriteConsole call:

INVOKE WriteConsole,
  consoleHandle,        ; console output handle
  ADDR buffer,          ; string pointer
  bytesRead,            ; string length
  ADDR bytesWritten,    ; returns num bytes written
  0                     ; not used
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文