Skip to content

Instantly share code, notes, and snippets.

@DeRegem
Last active November 3, 2015 18:14
Show Gist options
  • Save DeRegem/d23968b4fe11359150bb to your computer and use it in GitHub Desktop.
Save DeRegem/d23968b4fe11359150bb to your computer and use it in GitHub Desktop.
format PE
entry main
section '.text' code readable executable
main:
push intro1
push format_output
call [printf]
add esp,8
push string1
push format_input
call [scanf]
add esp,8
push string1
push intro2
push format_output
call [printf]
add esp,8
push string2
push format_input
call [scanf]
add esp,8
mov edi,string2
pop esi
xor ebx,ebx
xor ecx,ecx
xor edx,edx
; edx=indice de coincidencia de string
; ecx=indice de string principal
; ebx=indice de substring
_bucle:
movzx eax,byte[esi]
cmp eax,0
je _final_sin_coincidencia
cmp al,byte[edi+ebx]
je _coincidencia
xor edx,edx
xor ebx,ebx
inc esi
inc ecx
jmp _bucle
_coincidencia:
mov edx,ecx
inc esi
inc ebx
inc ecx
cmp byte[edi+ebx],0
je _final_con_coincidencia
jmp _bucle
_final:
push num
push format_input
call [scanf]
add esp, 8
push 0
call [exit]
ret
_final_con_coincidencia:
push edx
push format_output2
call [printf]
add esp,8
jmp _final
_final_sin_coincidencia:
push outputsin
push format_output
call [printf]
add esp,8
jmp _final
section '.data' data readable writeable
num db ?
string1 rb 128
string2 rb 128
format_input db "%s",0
format_output db "%s",10,0
format_output2 db "%d",10,0
outputsin db "Sin coincidencias",0
intro1 db "Ingrese string",0
intro2 db "Ingrese substring",0
section '.idata' data import readable
include "macro\import32.inc"
library msvcrt, "MSVCRT.DLL"
import msvcrt,\
printf ,'printf',\
scanf ,'scanf',\
exit ,'exit'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment