Hey folks,
i need some help with the DOS-box.
I'm using a normal win32 app, based on a dialogbox.
the progi is now supposed to open a DOS-box
write for example the line: C:\help needed
read the line: unknown file or command
and close the dos box again
How do i do that ?
regards
i need some help with the DOS-box.
I'm using a normal win32 app, based on a dialogbox.
the progi is now supposed to open a DOS-box
write for example the line: C:\help needed
read the line: unknown file or command
and close the dos box again
How do i do that ?
regards
Here's the Source of my unfinished (and I think, I'd never finish it)
command.com replacement. Hope this helps!
command.com replacement. Hope this helps!
; #########################################################################
.386
.model flat, stdcall
option casemap :none
; #########################################################################
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\shell32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\shell32.lib
; #########################################################################
CPut PROTO :DWORD
CPutErr PROTO :DWORD
CGet PROTO
GetCmd PROTO
ListLong PROTO
ChangeDir PROTO
Execute PROTO
; #########################################################################
.data
; ############################################## console strings
szConTitle db "WinShell Konsole v0.10", 0
szConAbout db "Copyright 2001 by bAZiK", 13,10, 0
szNewLine db 13, 10, 0
szError db "Error: Command or File not found!", 13,10,13,10, 0
szTimeFormat db "HH:mm:ss", 0
szDateFormat db "dd.MM.yyyy", 0
szChgError db "Error: Directory not found!", 13,10, 0
szShellError db "Error: File not found!", 13,10, 0
; ############################################## console commands
szExit db "exit", 0
szll db "ll", 0
szcd db "cd", 0
szx db "x", 0
; ############################################## wsprintf templates
szConPrompt db "%s > ", 0
szListFormat db "%s %s %s %35s %13lu", 0
szTotalFormat db "Total Size: %lu Byte(s)", 13,10, 0
; ############################################## structures
wfd WIN32_FIND_DATA <>
syst SYSTEMTIME <>
ft FILETIME <>
; #########################################################################
.data?
szOutputBuffer db 512 dup (?)
szInputBuffer db 512 dup (?)
szCmdBuffer db 512 dup (?)
szDirBuffer db 512 dup (?)
szListBuffer db 512 dup (?)
szAttribBuffer db 20 dup (?)
szTimeBuffer db 20 dup (?)
szDateBuffer db 20 dup (?)
szTotalBuffer db 512 dup (?)
szChgBuffer db 512 dup (?)
szShellBuffer db 512 dup (?)
hFind dd ?
hInput dd ?
hOutput dd ?
hWritten dd ?
hRead dd ?
hMenu dd ?
hConWin dd ?
lpTotalSize dd ?
; #########################################################################
.code
start:
invoke GetStdHandle, STD_INPUT_HANDLE
mov hInput, eax
invoke GetStdHandle, STD_OUTPUT_HANDLE
mov hOutput, eax
invoke SetConsoleTitle, addr szConTitle
invoke SetConsoleTextAttribute, hOutput, FOREGROUND_RED or \
FOREGROUND_GREEN or \
FOREGROUND_BLUE or \
FOREGROUND_INTENSITY or \
BACKGROUND_BLUE
invoke CPut, addr szConTitle
invoke CPut, addr szNewLine
invoke CPut, addr szConAbout
invoke SetConsoleTextAttribute, hOutput, FOREGROUND_RED or \
FOREGROUND_GREEN or \
FOREGROUND_BLUE or \
FOREGROUND_INTENSITY
invoke CPut, addr szNewLine
@@:
call CGet
call GetCmd
cmp byte ptr [szCmdBuffer], 0 ; return gedr?ckt
je @B
invoke lstrcmp, addr szCmdBuffer, addr szExit
.if eax == 0
jmp @F
.endif
invoke lstrcmp, addr szCmdBuffer, addr szll
.if eax == 0
call ListLong
jmp @B
.endif
invoke lstrcmp, addr szCmdBuffer, addr szcd
.if eax == 0
call ChangeDir
invoke CPut, addr szNewLine
jmp @B
.endif
invoke lstrcmp, addr szCmdBuffer, addr szx
.if eax == 0
call Execute
invoke CPut, addr szNewLine
jmp @B
.endif
invoke CPutErr, addr szError
jmp @B
@@:
invoke ExitProcess, 0
; #########################################################################
Execute proc
invoke RtlZeroMemory, addr szShellBuffer, 512
lea edi, szInputBuffer
lea esi, szShellBuffer
add edi, 2 ; 'x '
@@:
mov al, byte ptr [edi]
cmp al, 13
je @F
mov byte ptr [esi], al
inc edi
inc esi
or al, al
jnz @B
@@:
invoke ShellExecute, 0, 0, addr szShellBuffer, 0, \
addr szDirBuffer, SW_SHOWNORMAL
cmp eax, ERROR_FILE_NOT_FOUND
jne @F
invoke CPutErr, addr szShellError
@@:
ret
Execute endp
; #########################################################################
ChangeDir proc
invoke RtlZeroMemory, addr szChgBuffer, 512
lea edi, szInputBuffer
lea esi, szChgBuffer
add edi, 3 ; 'cd '
@@:
mov al, byte ptr [edi]
cmp al, 13
je @F
mov byte ptr [esi], al
inc edi
inc esi
or al, al
jnz @B
@@:
invoke SetCurrentDirectory, addr szChgBuffer
cmp eax, 0
jne @F
invoke CPutErr, addr szChgError
@@:
ret
ChangeDir endp
; #########################################################################
ListLong proc
mov eax, 0
mov lpTotalSize, eax
invoke CPut, addr szNewLine
invoke lstrlen, addr szDirBuffer
lea edi, szDirBuffer
add edi, eax
mov byte ptr [edi], 42 ; *
invoke FindFirstFile, addr szDirBuffer, addr wfd
mov hFind, eax
@@:
lea edi, szAttribBuffer
mov eax, wfd.dwFileAttributes
.if (eax & FILE_ATTRIBUTE_DIRECTORY)
mov byte ptr [edi], 100 ; d
.else
mov byte ptr [edi], 45 ; -
.endif
inc edi
.if (eax & FILE_ATTRIBUTE_ARCHIVE)
mov byte ptr [edi], 97 ; a
.else
mov byte ptr [edi], 45 ; -
.endif
inc edi
.if (eax & FILE_ATTRIBUTE_SYSTEM)
mov byte ptr [edi], 115 ; s
.else
mov byte ptr [edi], 45 ; -
.endif
inc edi
.if (eax & FILE_ATTRIBUTE_HIDDEN)
mov byte ptr [edi], 104 ; h
.else
mov byte ptr [edi], 45 ; -
.endif
inc edi
.if (eax & FILE_ATTRIBUTE_READONLY)
mov byte ptr [edi], 114 ; r
.else
mov byte ptr [edi], 45 ; -
.endif
invoke FileTimeToLocalFileTime, addr wfd.ftLastWriteTime, addr ft
invoke FileTimeToSystemTime, addr ft, addr syst
invoke GetTimeFormat, 0, 0, addr syst, \
addr szTimeFormat, addr szTimeBuffer, 20
invoke GetDateFormat, 0, 0, addr syst, addr szDateFormat, \
addr szDateBuffer, 20
mov eax, MAXDWORD
mov ebx, wfd.nFileSizeHigh
imul ebx
add eax, wfd.nFileSizeLow
mov edx, eax
add lpTotalSize, edx
invoke wsprintf, addr szListBuffer, addr szListFormat, \
addr szAttribBuffer, addr szDateBuffer, \
addr szTimeBuffer, addr wfd.cFileName, edx
invoke CPut, addr szListBuffer
invoke CPut, addr szNewLine
invoke RtlZeroMemory, addr szListBuffer, 512 ; clear buffer
invoke FindNextFile, hFind, addr wfd
invoke GetLastError
cmp eax, ERROR_NO_MORE_FILES
jne @B
invoke CPut, addr szNewLine
invoke wsprintf, addr szTotalBuffer, addr szTotalFormat, lpTotalSize
invoke CPut, addr szTotalBuffer
invoke CPut, addr szNewLine
invoke CloseHandle, hFind
ret
ListLong endp
; #########################################################################
CPutErr proc lpText:DWORD
invoke SetConsoleTextAttribute, hOutput, FOREGROUND_RED or \
FOREGROUND_INTENSITY
invoke CPut, lpText
invoke SetConsoleTextAttribute, hOutput, FOREGROUND_RED or \
FOREGROUND_GREEN or \
FOREGROUND_BLUE or \
FOREGROUND_INTENSITY
ret
CPutErr endp
; #########################################################################
CPut proc lpText:DWORD
invoke lstrlen, lpText
invoke WriteFile, hOutput, lpText, eax, addr hWritten, 0
mov eax, hWritten
ret
CPut endp
; #########################################################################
CGet proc
invoke RtlZeroMemory, addr szDirBuffer, 512
invoke GetCurrentDirectory, 512, addr szDirBuffer
lea edi, szDirBuffer
add edi, eax
cmp byte ptr [edi-1], "\"
je @F
mov byte ptr [edi], "\"
@@:
invoke wsprintf, addr szOutputBuffer, addr szConPrompt, addr szDirBuffer
invoke CPut, addr szOutputBuffer
invoke RtlZeroMemory, addr szInputBuffer, 512
invoke ReadFile, hInput, addr szInputBuffer, 512, addr hRead, 0
mov eax, hRead
ret
CGet endp
; #########################################################################
GetCmd proc
invoke RtlZeroMemory, addr szCmdBuffer, 512
lea edi, szInputBuffer
lea esi, szCmdBuffer
@@:
mov al, byte ptr [edi]
cmp al, 32
je @F
cmp al, 13
je @F
mov byte ptr [esi], al
inc edi
inc esi
or al, al
jnz @B
@@:
ret
GetCmd endp
; #########################################################################
end start
; #########################################################################
Well, i figured out how to start
My console opens, but the windows closes right away again
and it doesn't write the line it is supposed to write...
Here's the code
What i actually wanna do is make my progi work like a batchfile
would it work this way ?
as soon as a line is written to the console, is it like somebody presses enter ?
regards Olli
My console opens, but the windows closes right away again
and it doesn't write the line it is supposed to write...
Here's the code
;#########################################################################
.386
.model flat, stdcall
option casemap :none ; case sensitive
;#########################################################################
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
;#########################################################################
.data
text db "dir /p/w",0
;#########################################################################
.data?
hInput dd ?
hOutput dd ?
written dd ?
;#########################################################################
.code
start:
invoke AllocConsole ; create console
invoke GetStdHandle,STD_INPUT_HANDLE ; get the handles
mov hInput,eax
invoke GetStdHandle,STD_OUTPUT_HANDLE
mov hOutput,eax
invoke WriteConsole,addr hOutput,addr text,4,addr written,NULL
end start
What i actually wanna do is make my progi work like a batchfile
would it work this way ?
as soon as a line is written to the console, is it like somebody presses enter ?
regards Olli
Olli,
you told us how to start a "DOS-Box", but actually you just wanted to start a console window. Ok, to write to you newly created console, your last line should look like:
JAPHETH
you told us how to start a "DOS-Box", but actually you just wanted to start a console window. Ok, to write to you newly created console, your last line should look like:
invoke WriteConsole,hOutput,addr text,8,addr written,NULL
JAPHETH
sorry you guys,
that still doesn't solve it.
it's just the number of characters to be written,
I'm sure I'll get the problem with writing to the console.
But what i can't solve is when i start my program the console appears, and disappears after a sec again.
if i try it again the program crashes
any ideas how to solve that ?
PS: My program is suposed to work like a batch file
I appreciate every single post
regards Olli
that still doesn't solve it.
it's just the number of characters to be written,
I'm sure I'll get the problem with writing to the console.
But what i can't solve is when i start my program the console appears, and disappears after a sec again.
if i try it again the program crashes
any ideas how to solve that ?
PS: My program is suposed to work like a batch file
I appreciate every single post
regards Olli