News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

InString

Started by Grincheux, December 24, 2015, 06:43:38 PM

Previous topic - Next topic

Grincheux

I make a search using instring.
The patterns are ".jpg" ".png"
For 90% the result is OK but when there is a '?' into the string it returns OK
example :
Quote
http://www3.smartadserver.com/call/pubi/63121/490986/25988/S/[timestamp]/?
http://www.larevueautomobile.com/css-voiture/Plus-Photo.png
/images/Sexy/Girls-and-Cars/Sexy_Girls_and_Cars_028.jpg
/photo-voiture/photo-voiture.php?src=/images/Sexy/Girls-and-Cars/Exterieur/Sexy_Hot_ Babes_Cars_369.jpg
/photo-voiture/photo-voiture.php?src=/images/Sexy/Girls-and-Cars/Sexy_Hot_ Ba/Sexy_Girls_and_Cars_026.jpg

If I make a search on '?' it returns NOMATCH

Strange?


TouEnMasm

seems to be a replacement char as use dir

DIR ?ab.xxx                                ? is one char of any value
DIR ?ab*.xxx                              * is further char (any value)

If .??g                        must return    .jpg and .png
Fa is a musical note to play with CL

jj2007

Quote from: Grincheux on December 24, 2015, 06:43:38 PM
If I make a search on '?' it returns NOMATCH

Strange?

Strange indeed. Can you post a complete example? You mean Masm32 InString?

invoke InString, 1, chr$("Test?"), chr$("?") works fine.

MB Instr_() has also a case-insensitive mode, in case that helps.

Grincheux

;=====================================================================================
.Data
;=====================================================================================

szFmtDateAndTime Byte "%s/Grumpy - %4.4X%2.2X%2.2X%2.2X%2.2X%2.2X%4.4X.txt",0
szFmtGruppy Byte "%8.8d%-512s",10,0
szGrumpyError Byte "Cannot create Grumpy file!",0
szPattern_0 Byte "?",0
szPattern_1 Byte ".jpg",0
szPattern_2 Byte ".jpeg",0
szPattern_3 Byte ".png",0
szPattern_4 Byte ".gif",0

LoadWebPage PROC USES EBX EDI ESI,__hWnd:HWND,__lpszPageWeb:LPSTR
LOCAL _hFile:HANDLE
LOCAL _szTmp[1024]:Byte
LOCAL _St:SYSTEMTIME
LOCAL _lpszString:LPSTR

INVOKE wsprintf,ADDR _szTmp,ADDR szFmtDateAndTime,ADDR szWrkDirectory,_St.wYear,_St.wMonth,_St.wDay,_St.wHour,_St.wMinute,_St.wSecond,_St.wMilliseconds

INVOKE CreateFile,ADDR _szTmp,GENERIC_READ+GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL

cmp eax,INVALID_HANDLE_VALUE
je @Error_1

mov _hFile,eax

INVOKE RtlZeroMemory,ADDR _szTmp,1024

Init
Let esi=FileRead$(__lpszPageWeb)

xor ebx, ebx

.While 1
inc ebx
.BREAK .IF !Extract$(esi,'img src="','"',xsLoop,1000)

mov _lpszString,eax

INVOKE lstrlen,eax

mov edx,_lpszString

cmp Byte Ptr [eax + edx - 1],'?'
je @NotFound ; Sauter la ligne si elle contient un '?'

INVOKE InString,1,_lpszString,ADDR szPattern_1

test eax,eax
jz @Found

INVOKE InString,1,_lpszString,ADDR szPattern_2

test eax,eax
jz @Found

INVOKE InString,1,_lpszString,ADDR szPattern_3

test eax,eax
jz @Found

INVOKE InString,1,_lpszString,ADDR szPattern_4

test eax,eax
jnz @NotFound

@Found :

INVOKE wsprintf,ADDR _szTmp,ADDR szFmtGruppy,ebx,_lpszString
INVOKE File_Write,_hFile,ADDR _szTmp,521

@NotFound :
.Endw

INVOKE CloseHandle,_hFile

ret

@Error_1 :

INVOKE FatalError,__hWnd,NULL,ADDR szGrumpyError

ret
LoadWebPage ENDP


jj2007

Undefined symbols szWrkDirectory & File_Write...

TouEnMasm

; #########################################################################

;       The subloop code for this algorithm was redesigned by EKO to
;       perform the comparison in reverse which reduced the number
;       of instructions required to set up the branch comparison.

; #########################################################################

    .486
    .model flat, stdcall  ; 32 bit memory model
    option casemap :none  ; case sensitive

    StrLen PROTO :DWORD

    .code

; ########################################################################

InString proc startpos:DWORD,lpSource:DWORD,lpPattern:DWORD

  ; ------------------------------------------------------------------
  ; InString searches for a substring in a larger string and if it is
  ; found, it returns its position in eax.
  ;
  ; It uses a one (1) based character index (1st character is 1,
  ; 2nd is 2 etc...) for both the "StartPos" parameter and the returned
  ; character position.
  ;
  ; Return Values.
  ; If the function succeeds, it returns the 1 based index of the start
  ; of the substring.
  ;  0 = no match found
  ; -1 = substring same length or longer than main string
  ; -2 = "StartPos" parameter out of range (less than 1 or longer than
  ; main string)
  ; ------------------------------------------------------------------

    LOCAL sLen:DWORD
    LOCAL pLen:DWORD

    push ebx
    push esi
    push edi

    invoke StrLen,lpSource
    mov sLen, eax           ; source length
    invoke StrLen,lpPattern
    mov pLen, eax           ; pattern length

    cmp startpos, 1
    jge @F
    mov eax, -2
    jmp isOut               ; exit if startpos not 1 or greater
  @@:

    dec startpos            ; correct from 1 to 0 based index

    cmp  eax, sLen
    jl @F
    mov eax, -1
    jmp isOut               ; exit if pattern longer than source
  @@:

    sub sLen, eax           ; don't read past string end
    inc sLen

    mov ecx, sLen
    cmp ecx, startpos
    jg @F
    mov eax, -2
    jmp isOut               ; exit if startpos is past end
  @@:

  ; ----------------
  ; setup loop code
  ; ----------------
    mov esi, lpSource
    mov edi, lpPattern
    mov al, [edi]           ; get 1st char in pattern

    add esi, ecx            ; add source length
    neg ecx                 ; invert sign
    add ecx, startpos       ; add starting offset

    jmp Scan_Loop

    align 16

  ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

  Pre_Scan:
    inc ecx                 ; start on next byte

  Scan_Loop:
    cmp al, [esi+ecx]       ; scan for 1st byte of pattern
    je Pre_Match            ; test if it matches
    inc ecx
    js Scan_Loop            ; exit on sign inversion

    jmp No_Match

  Pre_Match:
    lea ebx, [esi+ecx]      ; put current scan address in EBX
    mov edx, pLen           ; put pattern length into EDX

  Test_Match:
    mov ah, [ebx+edx-1]     ; load last byte of pattern length in main string
    cmp ah, [edi+edx-1]     ; compare it with last byte in pattern
    jne Pre_Scan            ; jump back on mismatch
    dec edx
    jnz Test_Match          ; 0 = match, fall through on match

  ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

  Match:
    add ecx, sLen
    mov eax, ecx
    inc eax
    jmp isOut
   
  No_Match:
    xor eax, eax

  isOut:
    pop edi
    pop esi
    pop ebx

    ret

InString endp

; ########################################################################
Fa is a musical note to play with CL

TouEnMasm


I prefered this one (improved)


; #########################################################################

      .386                      ; force 32 bit code
      .model flat, stdcall      ; memory model & calling convention
      option casemap :none      ; case sensitive

      ; --------------------------------
      ; Les fichiers inclus içi
      ; --------------------------------
       include \masm32\include\windows.inc
      ; include \masm32\include\gdi32.inc
      ; include \masm32\include\user32.inc
      ; include perso32.inc
include macros.txt
      ; ---------------------------------------------------------
      ; Les PROTO sont tous regroupés dans un fichier .inc du même
      ; nom que la librairie .lib
      ; ---------------------------------------------------------
EXTERNDEF LongZtexte:PROTO  :DWORD ;or lstrlen ...
; DeplaceMax  =   max len search
      ;

    .code


; ########################################################################
chercherChaine proc Debut:DWORD,Contenant:DWORD,Chercher:DWORD,Methode:DWORD
; syntaxe Methode comme VB ,0 binaire,1 texte
; demarre Debut a 1 signifie au premier caractere
; retour eax position relative premier carac. de la chaine trouvé  comme VB
; eax 0 pas trouvé ou divers incidents
; limite de recherche fixé par LongZtexte

Local LongCont       :DWORD
Local PointCont      :DWORD
Local LongCherche    :DWORD
Local DeplaceMax     :DWORD
local retour         :DWORD
Pushad 
mov retour,0 ;par défaut échec
mov eax,Debut

.if eax < 1
mov retour,0
jmp FinChercherChaine
.endif

invoke LongZtexte,Contenant

.if eax == -1
mov retour,-1
jmp FinChercherChaine
.elseif eax < 1
mov retour,0
jmp FinChercherChaine
.endif
mov LongCont,eax

invoke LongZtexte,Chercher
.if eax == -1
mov retour,-1
jmp FinChercherChaine
.elseif eax < 1
mov retour,0
jmp FinChercherChaine
.endif

;la chaine de recherche doit etre <= en taille a l'autre
mov LongCherche,eax
mov ecx,LongCont
cmp eax,ecx
jle ValidData
mov retour,0
jmp FinChercherChaine
ValidData:
;la position de depart+long cherche =< long contenant si = deplace =0 ecx,1
mov eax, Debut        ;relatif a la chaine
add eax,LongCherche
dec eax
.if eax > LongCont
mov retour,0
jmp FinChercherChaine
.endif
mov ecx,LongCont
inc ecx           ;sinon -1 en sortie pour zero dep
sub ecx,eax
mov DeplaceMax,ecx ;nombre de déplacements possible du pointeur de recherche

; les données sont valides
;InsTxt Message," les données sont valides",0
;INVOKE     MessageBox, Hwnd, addr Message, addr titre, MB_YESNO

cld
PuPo PointCont,Debut
dec  PointCont       
mov esi,Contenant
add esi,Debut           ;1° car pointeur 0
dec esi      ;esi chaine contenant + position de depart -1
dec esi                  ;est incremente de nouveau par progresse contenant
mov edi,Chercher        ;di sur contenu ?
ProgresseContenant:
inc esi
inc PointCont           ;position de trouver
xor ebx,ebx
xor eax,eax
xor edx,edx             ;dl byte cherche
ProgresseContenu:
mov al,byte ptr [esi+ebx]
.if Methode == 1        ;en majuscules
.if eax > 96 && eax < 123
sub al,32
.endif
.endif
mov dl,byte ptr [edi+ebx]
.if Methode ==1        ;en majuscules
.if edx > 96 && edx < 123
sub dl,32
.endif
.endif

inc ebx
cmp al,dl
jnz NegatifResult
cmp ebx,LongCherche
jnz ProgresseContenu   ;continu la comparaison
jmp ChaineTrouve
NegatifResult:
dec DeplaceMax     ;decremente compteur dep
jnz ProgresseContenant
mov retour,0 ;pas trouvé
jmp FinChercherChaine
ChaineTrouve:
mov eax,PointCont     ;trouvé a quel position
mov retour,eax

FinChercherChaine:
popad
mov eax,retour     
ret
chercherChaine endp


Fa is a musical note to play with CL

jj2007

Quote from: ToutEnMasm on December 25, 2015, 12:26:47 AM

I prefered this one (improved)


   mov retour,0   ;par défaut échec
   mov eax,Debut

   .if eax < 1
      mov retour,0
      jmp FinChercherChaine
   .endif

Improved?


guga

I´m not being able to open it. Nothing is being showed neither i´m allowed to type a address. The app is designed to grab images from the web, right ? or it is the skeleton of the disassembler ?

Here shows only a blank screen mainly with a button and a edit box from where i cant type 
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

Grincheux


Siekmanski

Or rename the file $CatchWebImages.zip to CatchWebImages.zip
Creative coders use backward thinking techniques as a strategy.

Grincheux

The source is updated.

In the main loop I did not call TranslateMessage!

TouEnMasm

Quote
Improved?
improved since further years.If the start index of the chain is < 1 ,not allowed.
The based index of the chain is 1.
If eax = 0,no chain found,1 first letter and so on
Fa is a musical note to play with CL

Grincheux

#14
Now the program is finished.
It downloads images from the web : *.jpg, *.jpeg, *.gif and *.png
Into the program folder a directory named "Work" is created for storing downloaded files.

Sorry but the image needed to be removed. Feel free to post another image that does not have pretty girls in it.  :biggrin:

It does not display the downloaded files, because I have a problem with GdipCreateHBITMAPFromBitmap wich crashes.

The program can be downloaded Here