IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Contribuez Assembleur Discussion :

modificateur de texte


Sujet :

Contribuez Assembleur

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Mars 2013
    Messages
    397
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2013
    Messages : 397
    Points : 424
    Points
    424
    Par défaut modificateur de texte
    Un petit modificateur de texte qui fonctionne par rotation de byte dans un registre.
    Le but est de pouvoir modifier un texte de différente façon à chaque affichage, puis qu'il repasse par les mêmes états mais en sens inverse.

    exemple:
    modifier db 0,1,2,3,4,5,4,3,2,1,0

    Vous pouvez le tester en modifiant la valeur de "modnum".

    Ca a été fait à la va-vite, je ne l'ai pas testé en situation réelle donc il est possible qu'il contienne une erreur.
    Il suffit de faire jumper le programme, par exemple, ou bien l'intégrer dans un autre code, qui l'appellera sous forme de proc.

    Ne fonctionne que pour ascii et il s'agit d'un code x64 pour Linux, mais facilement adaptable pour Windows, en modifiant le "printf" et le "exit".

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
     
    	mov	edi,texte
    	call	strlen
     
    	mov	esi,modifier
    	add	sil,byte [modnum]
     
    	cmp	byte [modnum],10
    	jnz	@f
    	xor	byte [modnum],10
     
         @@:
    	cmp	byte [esi],0
    	jnz	@f
    	push	@store
    	jmp	next
         @@:
    	cmp	byte [esi],1
    	jnz	@f
    	push	mod1
    	jmp	next
         @@:
    	cmp	byte [esi],2
    	jnz	@f
    	push	mod2
    	jmp	next
         @@:
    	cmp	byte [esi],3
    	jnz	@f
    	push	mod3
    	jmp	next
         @@:
    	cmp	byte [esi],4
    	jnz	@f
    	push	mod4
    	jmp	next
         @@:
    	push	mod5
     
     
       next:
    	mov	esi,texte
    	mov	edi,txtbuf
    	mov	dl,4
         @@:
    	dec	cx
    	jz	@end
    	lodsb
    	ror	eax,8
    	dec	dl
    	jnz	@b
     
    	jmp	qword [rsp]
     
     @store:
    	stosd
    	mov	dl,4
    	jmp	@b
       @end:
    	inc	byte [modnum]
     
     
     
    	mov	esi,txtbuf
    	mov	edi,forms
    	xor	eax,eax
    	call	[printf]
     
    	xor	edi,edi
    	mov	eax,_exit
    	syscall
     
     
     
       mod1:
    	rol	ax,8
    	jmp	@store
       mod2:
    	rol	eax,16
    	jmp	@store
       mod3:
    	rol	ax,8
    	rol	eax,16
    	jmp	@store
       mod4:
    	rol	eax,16
    	rol	ax,8
    	jmp	@store
       mod5:
    	rol	ax,8
    	rol	eax,16
    	rol	ax,8
    	jmp	@store
     
     
     strlen:
    	xor	cx,cx
    	xor	al,al
    	not	cx
    	repnz	scasb
    	not	cx
    	ret
     
    txtbuf rb 1024
     
    texte db 'A table is a form of furniture with a flat horizontal upper surface used to support objects of interest, for storage, show, and/or manipulation. The surface must be held stable; for reasons of simplicity, this is usually done by support from below by either a column, a "base", or at least three columnar "stands". In special situations, table surfaces may be supported from a nearby wall, or suspended from above. wikipedia',0
     
    modifier db 0,1,2,3,4,5,4,3,2,1,0
    modnum db 0
     
    forms db '%s',10,0

    edit:ajout version x32
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
     
    	mov	edi,texte
    	call	strlen
     
    	mov	esi,modifier
    	add	si,word [modnum]
     
    	cmp	byte [modnum],10
    	jnz	@f
    	xor	byte [modnum],10
     
         @@:
    	cmp	byte [esi],0
    	jnz	@f
    	push	@store
    	jmp	next
         @@:
    	cmp	byte [esi],1
    	jnz	@f
    	push	mod1
    	jmp	next
         @@:
    	cmp	byte [esi],2
    	jnz	@f
    	push	mod2
    	jmp	next
         @@:
    	cmp	byte [esi],3
    	jnz	@f
    	push	mod3
    	jmp	next
         @@:
    	cmp	byte [esi],4
    	jnz	@f
    	push	mod4
    	jmp	next
         @@:
    	push	mod5
     
     
       next:
    	mov	esi,texte
    	mov	edi,txtbuf
    	mov	dl,4
         @@:
    	dec	cx
    	jz	@end
    	lodsb
    	ror	eax,8
    	dec	dl
    	jnz	@b
     
    	jmp	dword [esp]
     
     @store:
    	stosd
    	mov	dl,4
    	jmp	@b
       @end:
    	inc	byte [modnum]
     
     
     
    	push	txtbuf
    	push	forms
    	call	[printf]
     
    	xor	edi,edi
    	mov	eax,_exit
    	int	0x80
     
     
     
       mod1:
    	rol	ax,8
    	jmp	@store
       mod2:
    	rol	eax,16
    	jmp	@store
       mod3:
    	rol	ax,8
    	rol	eax,16
    	jmp	@store
       mod4:
    	rol	eax,16
    	rol	ax,8
    	jmp	@store
       mod5:
    	rol	ax,8
    	rol	eax,16
    	rol	ax,8
    	jmp	@store
     
     
     strlen:
    	xor	cx,cx
    	xor	al,al
    	not	cx
    	repnz	scasb
    	not	cx
    	ret
     
    txtbuf rb 1024
     
    texte db 'A table is a form of furniture with a flat horizontal upper surface used to support objects of interest, for storage, show, and/or manipulation. The surface must be held stable; for reasons of simplicity, this is usually done by support from below by either a column, a "base", or at least three columnar "stands". In special situations, table surfaces may be supported from a nearby wall, or suspended from above. wikipedia',0
     
    modifier db 0,1,2,3,4,5,4,3,2,1,0
    modnum dw 0
     
    forms db '%s',10,0

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Mars 2013
    Messages
    397
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2013
    Messages : 397
    Points : 424
    Points
    424
    Par défaut
    Ce code pourrait être intéressant à donner en exercice à des élèves.
    Ca changerait des codes ennuyeux habituels, du style msdos en 2013, ou truc du genre "blablabla... combien y-a t-il de pommes dans le rayon fruit et légume ?"

    L'énoncé:
    Créer un modificateur de texte.

    Contraintes:
    - L'ordre des lettres de chaque mot doit être modifié, et chaque lettre doit être préservée (code ascii non détruit par la modification).
    - Créer 5 modifications différentes d'ordre des lettres.
    - Le programme doit passer par chaque modification dans un ordre, puis repasser par chacune de ces modifications mais en sens inverse.
    - Chaque modification doit être affiché à l'écran.
    - Un timer de une seconde doit etre utilisé entre l'affichage de chaque modification.

    Ce qui est bien c'est que ce genre de code peut être codé d'un tas de façon différentes.
    C'est ce qui pourrait être interessant à voir.. Comment chaque personne imaginerait le code.
    J'ai d'ailleurs légèrement modifié le code en rédigeant ce post, histoire de montrer une autre façon de faire, et aussi pour le compléter en version complète.

    Le code peut être encore beaucoup amélioré. Pas forcément niveau performance, mais niveau technique, complexité.
    C'est d'ailleurs un exemple parfait pour implémenter du code-automodifiant

    [Version Win32, mais comme pour les autres, très simple à adapter pour Linux en modifiant les imports, et en x64 en modifiant les adresses].
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
     
    format PE console 5.0
    include 'include/windows/win32a.inc'
     
    ;--------------------------------------------------
    section '.text' code readable executable
    ;--------------------------------------------------
     
    entry $
     
    	mov	edi,texte
    	call	strlen
    	mov	[texte_len],ecx
      begin:
    	mov	esi,modifier
    	add	esi,dword [modnum]
     
    	cmp	byte [modnum],10
    	jnz	@f
    	xor	byte [modnum],10
         @@:
    	mov	edi,mod_addr
    	xor	al,al
    	not	al
         @@:
    	inc	al
    	add	edi,4
    	cmp	byte [esi],al
    	jnz	@b
     
    	push	dword [edi]
     
    	mov	esi,texte
    	mov	edi,txtbuf
    	mov	ecx,[texte_len]
        @re:
    	mov	dl,4
         @@:
    	mov	al,[esi]
    	inc	esi
    	ror	eax,8
    	dec	dl
    	jnz	@b
     
    	jmp	dword [esp]
     
     @store:
    	mov	[edi],eax
    	add	edi,4
    	sub	ecx,4
    	jnz	@re
     
    	inc	byte [modnum]
     
    	cinvoke	printf,forms,txtbuf
    	cinvoke	puts,crlf
    	cinvoke	Sleep,1000
     
    	dec	[nbrloop]
    	jnz	begin
     
    	invoke	ExitProcess,0
     
     
     
       mod1:
    	rol	ax,8
    	jmp	@store
       mod2:
    	rol	eax,16
    	jmp	@store
       mod3:
    	rol	ax,8
    	rol	eax,16
    	jmp	@store
       mod4:
    	rol	eax,16
    	rol	ax,8
    	jmp	@store
       mod5:
    	rol	ax,8
    	rol	eax,16
    	rol	ax,8
    	jmp	@store
     
     
     strlen:
    	xor	ecx,ecx
    	xor	al,al
         @@:
    	inc	edi
    	inc	ecx
    	cmp	byte [edi],al
    	jnz	@b
    	ret
     
    ;--------------------------------------------------
    section '.data' data readable writeable
    ;--------------------------------------------------
     
    txtbuf rb 1024
     
    texte db 'A table is a form of furniture with a flat horizontal upper surface used to support objects of interest, for storage, show, and/or manipulation. The surface must be held stable; for reasons of simplicity, this is usually done by support from below by either a column, a "base", or at least three columnar "stands". In special situations, table surfaces may be supported from a nearby wall, or suspended from above. wikipedia',0
     
    texte_len dd 0
     
    mod_addr dd 0,@store,mod1,mod2,mod3,mod4,mod5
    modifier db 0,1,2,3,4,5,4,3,2,1,0
    modnum dd 0
     
    nbrloop db 11
    crlf db 13,10,0
     
    forms db '%s',10,0
     
    ;--------------------------------------------------
    section '.idata' import data readable writeable
    ;--------------------------------------------------
     
    library kernel32,'kernel32.dll',\
    	msvcrt,'msvcrt.dll',\
    	user32,'user32.dll'
     
    include 'include/windows/api/kernel32.inc'
    include 'include/windows/api/user32.inc'
     
    import msvcrt,\
    printf,'printf',\
    puts,'puts'

Discussions similaires

  1. afficher du texte
    Par Mau dans le forum OpenGL
    Réponses: 10
    Dernier message: 24/06/2003, 15h31
  2. taille du texte dans un viewport
    Par pitounette dans le forum OpenGL
    Réponses: 3
    Dernier message: 22/07/2002, 12h06
  3. combobox->text
    Par clovis dans le forum C++Builder
    Réponses: 18
    Dernier message: 21/06/2002, 15h43
  4. fichier binaire ou texte
    Par soussou dans le forum C++Builder
    Réponses: 4
    Dernier message: 14/06/2002, 13h39
  5. Réponses: 2
    Dernier message: 10/06/2002, 11h03

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo