@echo off
:n - имя файла программы
set n=mdir
if exist %n%.obj del %n%.obj
if exist %n%.exe del %n%.exe
: -----------------------------------------
: assemble %n%.asm into an OBJ file
: -----------------------------------------
\MASM32\BIN\Ml.exe /c /coff /Fl %n%.asm
if errorlevel 1 goto errasm
: --------------------------------------------------
: link the main OBJ file with the resource OBJ file
: --------------------------------------------------
\MASM32\BIN\Link.exe /SUBSYSTEM:CONSOLE %n%.obj
if errorlevel 1 goto errlink
dir %n%.*
goto TheEnd
:errlink
: ----------------------------------------------------
: display message if there is an error during linking
: ----------------------------------------------------
echo.
echo There has been an error while linking this project.
echo.
goto TheEnd
:errasm
: -----------------------------------------------------
: display message if there is an error during assembly
: -----------------------------------------------------
echo.
echo There has been an error while assembling this project.
echo.
:TheEnd
pause
format PE console
entry start
include 'win32a.inc'
; #########################################################################
section '.data' readable writable
lf db 13,10,0
wCard db "*.txt",0
wCald.len = $ - wCard
notfound db "File not found",13,10,0
spc db " ",0
bytes db " bytes",0
fMtStrinG db "%lu",0
section '.bss' readable writable
hSearch dd ? ; search handle
sizeBuffer db 16 dup(?)
fBuffer db 256 dup (?) ; file name buffer
clBuffer db 128 dup (?) ; command line buffer
wfd WIN32_FIND_DATA <>
; #########################################################################
section '.code' code readable executable
start:
stdcall GetCL, 1, clBuffer ; get arg 1
cmp eax, 1
je @@13 ; if no arg
mov ecx, wCald.len ; copy *.txt into
mov esi, wCard ; clBuffer
mov edi, clBuffer
rep movsb
@@13:
invoke FindFirstFileA,clBuffer,wfd
cmp eax, INVALID_HANDLE_VALUE
jne @@14
cinvoke printf, notfound ; display "not found" message
jmp TheEnd
@@14:
mov [hSearch], eax
@@loop:
cinvoke printf, wfd.cFileName
mov al, [wfd.cFileName]
cmp al, "."
je nxt
cinvoke printf, spc
invoke printf, fMtStrinG, [wfd.nFileSizeLow]
invoke printf, bytes
nxt:
invoke printf, lf
@@next:
invoke FindNextFileA,[hSearch], wfd
cmp eax, 0
jne @@loop
invoke FindClose, [hSearch]
TheEnd:
invoke exit,0
; #########################################################################
proc GetCL uses esi edi, ArgNum:DWORD, ItemBuffer:DWORD
; -------------------------------------------------
; arguments returned in "ItemBuffer"
;
; arg 0 = program name
; arg 1 = 1st arg
; arg 2 = 2nd arg etc....
; -------------------------------------------------
; Return values in eax
;
; 1 = successful operation
; 2 = no argument exists at specified arg number
; 3 = non matching quotation marks
; 4 = empty quotation marks
; -------------------------------------------------
local lpCmdLine :DWORD
local cmdBuffer[192] :BYTE
local tmpBuffer[192] :BYTE
invoke GetCommandLineA
mov [lpCmdLine], eax ; address command line
; -------------------------------------------------
; count quotation marks to see if pairs are matched
; -------------------------------------------------
xor ecx, ecx ; zero ecx & use as counter
mov esi, [lpCmdLine]
@@1:
lodsb
cmp al, 0
je @@2
cmp al, 34 ; [ " ] character
jne @@1
inc ecx ; increment counter
jmp @@1
@@2:
push ecx ; save count
shr ecx, 1 ; integer divide ecx by 2
shl ecx, 1 ; multiply ecx by 2 to get dividend
pop eax ; put count in eax
cmp eax, ecx ; check if they are the same
je @@12
mov eax, 3 ; return 3 in eax = non matching quotation marks
ret
@@12:
; ------------------------
; replace tabs with spaces
; ------------------------
mov esi, [lpCmdLine]
lea edi, [cmdBuffer]
@@3:
lodsb
cmp al, 0
je rtOut
cmp al, 9 ; tab
jne rtIn
mov al, 32
rtIn:
stosb
jmp @@3
rtOut:
stosb ; write last byte
; -----------------------------------------------------------
; substitute spaces in quoted text with replacement character
; -----------------------------------------------------------
lea eax, [cmdBuffer]
mov esi, eax
mov edi, eax
subSt:
lodsb
cmp al, 0
jne @@4
jmp subOut
@@4:
cmp al, 34
jne subNxt
stosb
jmp subSl ; goto subloop
subNxt:
stosb
jmp subSt
subSl:
lodsb
cmp al, 32 ; space
jne @@5
mov al, 254 ; substitute character
@@5:
cmp al, 34
jne @@6
stosb
jmp subSt
@@6:
stosb
jmp subSl
subOut:
stosb ; write last byte
; ----------------------------------------------------
; the following code determines the correct arg number
; and writes the arg into the destination buffer
; ----------------------------------------------------
lea eax, [cmdBuffer]
mov esi, eax
lea edi, [tmpBuffer]
mov ecx, 0 ; use ecx as counter
; ---------------------------
; strip leading spaces if any
; ---------------------------
@@7:
lodsb
cmp al, 32
je @@7
l2St:
cmp ecx, [ArgNum] ; the number of the required cmdline arg
je clSubLp2
lodsb
cmp al, 0
je cl2Out
cmp al, 32
jne cl2Ovr ; if not space
@@8:
lodsb
cmp al, 32 ; catch consecutive spaces
je @@8
inc ecx ; increment arg count
cmp al, 0
je cl2Out
cl2Ovr:
jmp l2St
clSubLp2:
stosb
@@9:
lodsb
cmp al, 32
je cl2Out
cmp al, 0
je cl2Out
stosb
jmp @@9
cl2Out:
mov al, 0
stosb
; ------------------------------
; exit if arg number not reached
; ------------------------------
cmp ecx, [ArgNum]
jae @@17
mov edi, [ItemBuffer]
mov al, 0
stosb
mov eax, 2 ; return value of 2 means arg did not exist
ret
@@17:
; -------------------------------------------------------------
; remove quotation marks and replace the substitution character
; -------------------------------------------------------------
lea eax, [tmpBuffer]
mov esi, eax
mov edi, [ItemBuffer]
rqStart:
lodsb
cmp al, 0
je rqOut
cmp al, 34 ; dont write [ " ] mark
je rqStart
cmp al, 254
jne @@10
mov al, 32 ; substitute space
@@10:
stosb
jmp rqStart
rqOut:
stosb ; write zero terminator
; ------------------
; handle empty quote
; ------------------
mov esi, [ItemBuffer]
lodsb
cmp al, 0
jne @@11
mov eax, 4 ; return value for empty quote
ret
@@11:
mov eax, 1 ; return value success
ret
endp
; #########################################################################
section '.idata' data import readable writable
library msvcrt,'msvcrt.dll',\
kernel32,'kernel32.dll'
import msvcrt,\
printf,'printf',\
sprintf,'sprintf',\
exit,'exit'
import kernel32,\
FindFirstFileA,'FindFirstFileA',\
FindNextFileA,'FindNextFileA',\
FindClose,'FindClose',\
GetCommandLineA,'GetCommandLineA'
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.