News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

EnumDeviceDrivers.asm

Started by correy, December 13, 2010, 04:40:33 AM

Previous topic - Next topic

correy

;本文改编自masm32v10的一个程序。
;相关的api资料在windows的win32.hlp里面没有找到。

.386
.model flat,stdcall
option casemap:none
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
include psapi.inc
includelib psapi.lib

.data
correy db "made by correy",0
spaces db "        ",0
nowindowstitle db "没有窗口标题!",0
entry db 13,10
outtitle db "按回车键退出!",0

.data?
paths db 512 dup (?)
x dd ?
buffer db 512 dup (?)
hstdin dd ?
hstdout dd ?

.code
start:
invoke GetStdHandle,-10
mov hstdin,eax
invoke GetStdHandle,-11
mov hstdout,eax
    invoke EnumDeviceDrivers,0,0,ADDR x
    invoke EnumDeviceDrivers,addr paths,x,ADDR x
    shr x, 2
    lea esi,paths
  again:
    invoke GetDeviceDriverFileName,[esi],addr buffer,512
    invoke lstrlen,addr buffer
    invoke WriteFile,hstdout,addr buffer,eax,0,0
    invoke WriteFile,hstdout,addr entry,2,0,0
    add esi, 4
    sub x, 1
    cmp x,0
    jne again
   
invoke WriteFile,hstdout,addr outtitle,sizeof outtitle,0,0
invoke ReadFile,hstdin,addr buffer,sizeof buffer,addr x,0
ret
end start
;made at 2010.08.28

jj2007

Your code works perfectly, thanks.
Welcome to the forum, correy :U

P.S.: You should full paths without the drive letter as shown below, since some people do not set environment variables, for various reasons.
include \masm32\include\masm32rt.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\psapi.inc
includelib \masm32\lib\psapi.lib

japheth

Good work!

However, variable paths can receive 512 / 4 = 128 entries only. That might be too small. Worse, your program does not care about a buffer overflow.

Here's a slightly modified version:


.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\psapi.inc

includelib kernel32.lib
includelib psapi.lib

.code

main proc

local hstdout:dword
local tabsiz:dword
local dwWritten:dword
local buffer[512]:byte

invoke GetStdHandle,STD_OUTPUT_HANDLE
mov hstdout,eax
invoke EnumDeviceDrivers, 0, 0, ADDR tabsiz
sub esp, tabsiz
mov esi, esp
push 0
invoke EnumDeviceDrivers, esi, tabsiz, esp
pop ecx
shr ecx,2
again:
push ecx
invoke GetDeviceDriverFileName, [esi], addr buffer, sizeof buffer
add esi, 4
invoke lstrlen, addr buffer
mov word ptr [buffer+eax], 0A0Dh
add eax,2
lea ecx, dwWritten
invoke WriteFile, hstdout, addr buffer, eax, ecx, 0
pop ecx
loop again
add esp,tabsiz
ret
main endp

start:
call main
invoke ExitProcess, 0

end start


Note that it still may crash if the buffer space exceeds 4096 bytes.

Magnum

Quote from: correy on December 13, 2010, 04:40:33 AM
;本文改编自masm32v10的一个程序。
;相关的api资料在windows的win32.hlp里面没有找到。

.data
correy db "made by correy",0
spaces db "        ",0
nowindowstitle db "没有窗口标题!",0
entry db 13,10
outtitle db "按回车键退出!",0


Are those Chinese characters?

How do you get them on your screen?

Have a great day,
                         Andy

dedndave

not Chinese - Martian   :P

welcome to the forum, Correy  :U

(Andy - unicode text)

Magnum

Thanks "Mr. Terse."  :bg

I would like to learn how to use Unicode to output Korean text.



Have a great day,
                         Andy

Farabi

フォーラムへようこそ
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Quote from: Magnum on December 13, 2010, 12:38:02 PM
Thanks "Mr. Terse."  :bg

I would like to learn how to use Unicode to output Korean text.





It simple, use CreateWindowExW for the richedit control
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

correy

thanks all.
i come from Chinese.