Accueil > > > UN EDITEUR DE FICHIER UNIX DEPUIS WINDOWS
UN EDITEUR DE FICHIER UNIX DEPUIS WINDOWS
Information sur la source
Description
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
- ; 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
; 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.
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
[FRAMEWORK 4] LES TASKS ET LE THREAD UI[FRAMEWORK 4] LES TASKS ET LE THREAD UI par fathi
Je viens de passer quelques temps au TechDay's et j'ai pu voir pas mal de session intéressante. Par contre une chose m'a un peu étonné lors de certaines de ces sessions qui abordaient les améliorations du framework .NET (donc le 4.5) : en gros, bea...
Cliquez pour lire la suite de l'article par fathi WORKFLOW FOUNDATION 3 A UN PIED DANS LA TOMBEWORKFLOW FOUNDATION 3 A UN PIED DANS LA TOMBE par JeremyJeanson
Depuis déjà un an, je conseille vivement les utilisateurs de Workflow Foundation 3 à migrer vers la version 4. L'information qui va suivre ne devrait donc pas trop prendre au dépourvu les personnes qui m'ont suivi. Je profite de ce poste, pour faire le re...
Cliquez pour lire la suite de l'article par JeremyJeanson TECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PCTECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PC par ROMELARD Fabrice
Speakers: Thierry Rapatout, Antoine Petit et Xavier Trebbia Cette session entre dans le cadre des RDV Décideurs des TechDays 2012, elle est liée à la consumérisation de l'IT et la mise en place du "DeskTop as a Service" dans de plus en ...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : SYSTEM CENTER SERVICE MANAGER 2012 VUE D'ENSEMBLETECHDAYS PARIS 2012 : SYSTEM CENTER SERVICE MANAGER 2012 VUE D'ENSEMBLE par ROMELARD Fabrice
Speakers: Julien Marechal, Gautier Confiant, Sébastien MEYER La session débute par le positionnement de la solution System Center par rapport aux concepts d'organisation ITIL. Le portail du catalogue de se...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : PLEINIèRE SECOND JOURTECHDAYS PARIS 2012 : PLEINIèRE SECOND JOUR par ROMELARD Fabrice
Après une première journée dédiée aux développeurs, cette seconde journée est dédiée au monde des entreprises et de ses applications. Ainsi, cette pleinière est dédiée à faire un 360 de l'évolution des applications Business aux demandes ac...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|