Voici un petit programme, qui a l'heure d'aujourd'hui m'est fort utile.
Dans mon entreprise on possède un serveur AIX, ce dernier lance différent traitements tout les soirs.
De temps a autre, il fallait contrôler certains de ces traitements.
2 solutions s'offraient, soit par l'éditeur VI, soit par un utilitaire de style "Ultra édit".
La première solution était assez fastidieuse, quand a la seconde, c'était une solution payante et de plus les dates des fichiers ne correspondait pas a la réalité.
J'ai donc développé un petit utilitaire pour pouvoir visualiser ces fichiers de log.
Mon premier jet fut dans une solution en DHTML. Pourquoi le "DHTML", uniquement par rapport à la politique de l'entreprise.
Cette application marchait très bien jusqu'a ce que les répertoires contenant les logs, soit trop volumineux.
J'ai donc rajouté un petit prog en assembleur afin d'augmenter la vitesse.
Source / Exemple :
; compil me with MASM32
.486
.model flat, stdcall
option casemap :none ; case sensitive
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\macros\macros.asm
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
File_Input db "C:\rep.tmp",0
h_Input dd 0
File_Output db "C:\dir.htm", 0
h_Output dd 0
Buffer_In db 128 dup (0)
File_struct OFSTRUCT <>
BW dd 0
Temp db 10 dup (0)
dir db 260 dup (0)
Txt00 db "<table>",13,10,0
Txt01 db "<TR><TD><IMG SRC='images\paper.gif'></TD><TD><font color=green style='cursor:hand' OnMouseDown = 'parent.edit(",34,0
Txt11 db "<TR><TD><IMG SRC='images\close.gif'></TD><TD><font color=blue style='cursor:hand' OnMouseDown = 'parent.dir( ",34,0
Txt02 db 34,");'>",0
Txt03 db "</Font></TD><TD>",0
Txt04 db "</TD></TR>",13,10,0
Txt05 db "</b></TD><td width='15'></td><TD>",0
Txt06 db "</TD><TD align=right><B>",0
Txt07 db " oKoMoGo"
Txt08 db "</TD><TD>",0
Txt09 db "</TD><td width='15'></td><TD>",0
DSize dd 0
Txt99 db 13,10,"</table>",0
.code
start:
invoke GetCL,1,ADDR dir ; dir is the first param of call this programme
;create the file to write
invoke OpenFile, offset File_Output, offset File_struct, OF_CREATE ; create new file
mov h_Output, eax ; save its handle
invoke WriteFile, h_Output, offset Txt00, 9, offset BW, NULL
;read
invoke OpenFile, offset File_Input, offset File_struct, GENERIC_READ ; open file
mov h_Input, eax ; save its handle
mov ebx, offset Buffer_In ; point to tempory string
debut: ; read the first line
invoke ReadFile,h_Input,ebx,1,offset BW,NULL ; read open file char by char
mov al,[ebx] ; push it in the tempory string
cmp BW,0 ; end of read ?
je fin ; yes leave programm
cmp al,13 ; loop until is carriage return
jne debut
invoke ReadFile,h_Input,ebx,1,offset BW,NULL ; read again for chr(10) last chr(13)
loop00: ; read a line
mov ebx,offset Buffer_In
invoke ReadFile,h_Input,ebx,57,offset BW,NULL ; read the 57 first char
cmp BW,0 ; end of the file ?
je fin ; yes quit
add ebx,57
loop01:
invoke ReadFile,h_Input,ebx,1,offset BW,NULL ; read open file char by char
mov al,[ebx] ; push it in the tempory string
cmp al,13 ; compare the char by return carrige
je fin_ligne ; chr(13)=yes -> end of line
inc ebx ; else inc position in the tempory string
jmp loop01
fin_ligne:
Xor al,al
mov [ebx],al ; terminate the string by chr(0)
mov ebx,offset Buffer_In ; go to the begining of tempory string
mov al,[ebx] ; read the first char
cmp al,"d" ; char is "d" ?
je directory ; yes -> is directory go to directory
cmp al,"l" ; char is "l" ?
je loop00 ; yes -> virtual dir do nothing
;fichier
file:
invoke WriteFile, h_Output, offset Txt01, 111, offset BW, NULL ; write Txt01
suite:
invoke lstrlen, offset dir ; get len of param dir
invoke WriteFile, h_Output,offset dir, eax, offset BW, NULL ; write dir
mov ebx,offset Buffer_In
add ebx,57 ; begin the tempory buffer at then char 57
invoke lstrlen, ebx ; get len of the tempory buffer
invoke WriteFile, h_Output, ebx, eax, offset BW, NULL ; write the tempory buffer
invoke WriteFile, h_Output, offset Txt02, 5, offset BW, NULL ; write Txt02
invoke lstrlen, ebx
invoke WriteFile, h_Output, ebx, eax, offset BW, NULL ; write the tempory buffer
invoke WriteFile, h_Output, offset Txt03,16, offset BW, NULL ; write Txt03
mov ebx,offset Buffer_In
invoke WriteFile, h_Output, ebx, 10, offset BW, NULL ; write right(txt,10)
invoke WriteFile, h_Output, offset Txt09, 29, offset BW, NULL ; write Txt09
invoke WriteFile, h_Output, offset Txt06, 24, offset BW, NULL ; write Txt06
add ebx,43 ; position char 43 of tempory string
loop03:
dec ebx ; write the size of file
mov al,[ebx] ; found the first number after space
cmp al,32
jne loop03
xor ecx,ecx
mov edx,ebx
loop04:
inc edx ; found the last number before space
inc ecx
mov al,[edx]
cmp al,32
jne loop04
mov eax,ebx
mov ebx,edx
xor edx,edx
mov [ebx],dl
inc ebx
mov DSize,offset Txt07 ; convert in ko, mo or go
mov eax,sval (eax)
cmp eax,1024
jl suite2
shr eax,10
add DSize,2
cmp eax,1024
jl suite2
shr eax,10
add DSize,2
cmp eax,1024
jl suite2
shr eax,10
add DSize,2
suite2:
mov edx,ustr$(eax)
invoke lstrlen , edx
invoke WriteFile, h_Output, edx, eax, offset BW, NULL ; write the number
invoke WriteFile, h_Output, offset Txt08, 9, offset BW, NULL ; write Txt08
invoke WriteFile, h_Output, DSize, 2, offset BW, NULL ; write type of size o ko mo go
invoke WriteFile, h_Output, offset Txt05, 33, offset BW, NULL ; write Txt05
invoke WriteFile, h_Output, ebx, 12, offset BW, NULL ; write the date
invoke WriteFile, h_Output, offset Txt04, 12, offset BW, NULL ; write Txt04
invoke ReadFile , h_Input, ebx,1,offset BW,NULL ; read one char
cmp BW,0 ; error -> end of file
je fin
jmp loop00
directory:
invoke WriteFile, h_Output, offset Txt11, 111, offset BW, NULL ; write Txt11
jmp suite
fin:
invoke WriteFile, h_Output, offset Txt99, 10, offset BW, NULL ; write Txt99
invoke CloseHandle, h_Output ; close the file
invoke ExitProcess, 0
end start
Conclusion :
Ce prog n'est pas 100 % en assembleur, mais le code assembleur ci joint peut etre une bonne base pour la manipulation de chaine et de fichier.
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.