The MASM Forum

General => The Campus => Topic started by: Grincheux on December 24, 2015, 06:43:38 PM

Title: InString
Post by: Grincheux on December 24, 2015, 06:43:38 PM
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?

Title: Re: InString
Post by: TouEnMasm on December 24, 2015, 07:51:08 PM
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
Title: Re: InString
Post by: jj2007 on December 24, 2015, 08:41:20 PM
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_() (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1153) has also a case-insensitive mode, in case that helps.
Title: Re: InString
Post by: Grincheux on December 24, 2015, 09:33:55 PM
;=====================================================================================
.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

Title: Re: InString
Post by: jj2007 on December 24, 2015, 10:07:09 PM
Undefined symbols szWrkDirectory & File_Write...
Title: Re: InString
Post by: TouEnMasm on December 25, 2015, 12:18:05 AM
; #########################################################################

;       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

; ########################################################################
Title: Re: InString
Post by: TouEnMasm on December 25, 2015, 12:26:47 AM

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


Title: Re: InString
Post by: jj2007 on December 25, 2015, 05:10:51 AM
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?
Title: Re: InString
Post by: Grincheux on December 25, 2015, 07:16:41 AM
Entire project (http://www.phrio.biz/download/$CatchWebImages.zip)
Title: Re: InString
Post by: guga on December 25, 2015, 08:11:37 AM
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 
Title: Re: InString
Post by: Grincheux on December 25, 2015, 04:16:18 PM
You could paste
Title: Re: InString
Post by: Siekmanski on December 25, 2015, 04:31:19 PM
Or rename the file $CatchWebImages.zip to CatchWebImages.zip
Title: Re: InString
Post by: Grincheux on December 25, 2015, 05:06:06 PM
The source is updated.

In the main loop I did not call TranslateMessage!
Title: Re: InString
Post by: TouEnMasm on December 25, 2015, 06:37:27 PM
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
Title: Re: InString
Post by: Grincheux on December 27, 2015, 06:44:42 AM
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 (http://www.phrio.biz/download/$CatchWebImages.zip)
Title: Re: InString
Post by: hutch-- on December 27, 2015, 11:36:30 AM
Philippe,

Sorry to be a party pooper but we must keep titz 'n arse out of the forum as many of our visitors read the forum from work where they have porn filters.
Title: Re: InString
Post by: Grincheux on December 28, 2015, 03:54:01 AM
Ok, I removed the link
Title: Re: InString
Post by: Grincheux on December 28, 2015, 04:03:24 AM
The new version is available here (http://www.phrio.biz/download/$CatchWebImages.zip)

I removed MasmBasic functions (sorry JJ2007) because it could cover all the cases.
First versions were searching for <img src= but there are cases where theres is an id="cccc" between img and src
Accept format JPG, JPEG, GIF & PNG
*.jpeg files are renamed *.jpg

Supports the following syntaxes:


The program does not support base64 images introduced by "<img src="data:image/".
It cannot catch the avatars of this forum!!!

Next step : Import an html file from the disk.
Title: Re: InString
Post by: Siekmanski on December 28, 2015, 07:46:58 AM
Quote from: Grincheux on December 28, 2015, 04:03:24 AM
It cannot catch the avatars of this forum!!!

Yes, you can  :badgrin:

; uses urlmon.lib

.data
URL_1   db "http://masm32.com/board/index.php?action=dlattach;attach=4892;type=avatar",0
NAME_1  db "Grincheux.jpg",0

.code
    invoke  URLDownloadToFile,0,addr URL_1,addr NAME_1,0,0
Title: Re: InString
Post by: Grincheux on December 28, 2015, 01:38:12 PM
New version available here (http://www.phrio.biz/download/$CatchWebImages.exe)
The zip file has been deleted and replaced with a 7Zip SFX file.
Corrected a bug while creating font used in edit control.
Corrected a bug when calling VirtualFree, the memory used to load the file was not released!
Removed unused variables.
Added a flag in CreateFile while creating the file to download. In some cases empty files where created or files were written entirely.
Flush the cash before the downloaded file is closed.
Title: Re: InString
Post by: TouEnMasm on December 28, 2015, 08:36:54 PM
Here some sample who can interest you
From the internet explorer,copy the url in the clipboard and switch to webimage
Title: Re: InString
Post by: TouEnMasm on December 28, 2015, 08:57:31 PM

need to know how interpret:
index.php?PHPSESSID=8b66972e915875a2a5ed239bbb76b96b&amp;action=dlattach;attach=407;type=avatar
PHPSESSID is the key
Title: Re: InString
Post by: Grincheux on December 28, 2015, 09:23:29 PM
WebImage : Le mien ne fait rien de plus.
Title: Re: InString
Post by: TouEnMasm on December 28, 2015, 09:53:48 PM
I see that Siekmanski just rename the file to save it.
I will try that but which extension give it ?

Title: Re: InString
Post by: Grincheux on December 29, 2015, 02:14:37 AM
Jut run $CatchWebImages.exe it the uncompress all the files
Inside this file there is CatchWebImages.exe which is the real program.
Title: Re: InString
Post by: Grincheux on December 29, 2015, 04:00:11 AM
Who wrote WebImage?
Title: Re: InString
Post by: TouEnMasm on December 29, 2015, 04:55:01 AM
Quote
Who wrote WebImage?
it's me,I hope i have find a soluce and post it soon.
Title: Re: InString
Post by: Grincheux on December 29, 2015, 04:57:09 AM
What is the problem?
Title: Re: InString
Post by: TouEnMasm on December 29, 2015, 05:31:26 AM

the problem is to give a valid file name to:
index.php?PHPSESSID=8b66972e915875a2a5ed239bbb76b96b&amp;action=dlattach;attach=407;type=avatar
and give it the correct extension
Title: Re: InString
Post by: jj2007 on December 29, 2015, 05:40:42 AM
Quote from: ToutEnMasm on December 29, 2015, 05:31:26 AM

the problem is to give a valid file name to:
index.php?PHPSESSID=8b66972e915875a2a5ed239bbb76b96b&amp;action=dlattach;attach=407;type=avatar
and give it the correct extension

No problem :bgrin:

include \masm32\MasmBasic\Res\MbGui.asm
  .if !Exist("Yves.jpg")
      void FileRead$("http://masm32.com/board/index.php?action=dlattach;attach=407;type=avatar")
      Rename "~FrLocal.tmp", "Yves.jpg"
  .endif
Event Paint
  GuiImage hWnd, "Yves.jpg"
  GuiTextBox 99.9-150, 10, 140, 50, "Yves is a prominent member of the Masm32 forum", bcol RgbCol(255, 255, 80)
GuiEnd
Title: Re: InString
Post by: guga on December 29, 2015, 06:19:50 AM
Hi Yves...Maybe this can help

Can you be able to read the contents of the php, right ?

On Firefox, for example, the contents of this page is:

<html><head><meta content="width=device-width; height=device-height;" name="viewport"><link href="resource://gre/res/ImageDocument.css" rel="stylesheet"><link href="resource://gre/res/TopLevelImageDocument.css" rel="stylesheet"><link href="chrome://global/skin/media/TopLevelImageDocument.css" rel="stylesheet"><title>avatar_1133_1344617402.gif (GIF Image, 98&nbsp;×&nbsp;83 pixels)</title></head><body><img alt="http://masm32.com/board/index.php?action=dlattach;attach=407;type=avatar" src="http://masm32.com/board/index.php?action=dlattach;attach=407;type=avatar"></body></html>

Note, that on this case, the name of the image is inside the title tag of the html code.
Title: Re: InString
Post by: Grincheux on December 29, 2015, 07:21:29 AM
Quotethe problem is to give a valid file name to:
index.php?PHPSESSID=8b66972e915875a2a5ed239bbb76b96b&amp;action=dlattach;attach=407;type=avatar

Replace any symbol less than 32 with '_'
Ensure the new name is less than MAX_PATH
Append any extension

Here is what I do
Quote
.Data
szFmtWebImage   Byte   "%s\Grumpy-%8.8d.%s",0
.Code
                     mov      _dwCount,0

                     push   edi
                     INVOKE   PathFindExtension,_lpszFileName
                     add      eax,1
                     mov      edi,eax

@LoopCount :

                     add      _dwCount,1

                     INVOKE   wsprintf,_lpszWebImageFile,ADDR szFmtWebImage,ADDR szWrkDirectory,_dwCount,edi
                     INVOKE   PathFileExists,_lpszWebImageFile

                     test   eax,eax
                     jnz      @LoopCount
Title: Re: InString
Post by: Grincheux on December 29, 2015, 07:23:20 AM
An internet file name can be more than 2880 bytes long and MAX_PATH is 260.
Title: Re: InString
Post by: Siekmanski on December 29, 2015, 07:27:12 AM
Hi ToutEnMasm,

Just skip "PHPSESSID=8b66972e915875a2a5ed239bbb76b96b&amp;" no cookies needed to download the avatar.

To know the kind of image-format, you could check the file by reading the first 10 bytes and check those and then write the correct file-extension.

BMP = BM at offset 0
GIF = GIF87a or GIF89a at offset 0
JPG = JFIF at offset 6
PNG = PNG at offset 1

If you download the second html-page of Topic InString = http://masm32.com/board/index.php?topic=4946.15

Then search for "avatar" src=" you'll find 5 different avatars

http://masm32.com/board/index.php?action=dlattach;attach=2;type=avatar     hutch
http://masm32.com/board/index.php?action=dlattach;attach=4892;type=avatar  Grincheux
http://masm32.com/board/index.php?action=dlattach;attach=164;type=avatar   Siekmanski
http://masm32.com/board/index.php?action=dlattach;attach=407;type=avatar   ToutEnMasm
http://masm32.com/board/index.php?action=dlattach;attach=6;type=avatar     jj2007
Title: Re: InString
Post by: Grincheux on December 29, 2015, 07:59:50 AM
Each time I dowload a file I add one to the counter then I call InvalidateRect but it is updated when all is finished.
How could I do?
Title: Re: InString
Post by: Grincheux on December 29, 2015, 04:41:29 PM
New version availabale Here (http://www.phrio.biz/download/$CatchWebImages.exe)
Changed the backgound image.
Problem with GdipCreateHBITMAPFromBitmap resolved. In fact GDI+ was not initialized!
Now it draws the last downloaded image.
I would like to draw each images when they are downloaded but I don't know how.
I made a thread because I thought it resolves the problem, but it is false.
Help me please.

PS : Download $CatchWebImages.exe and launch it to uncompress all the files it contains. Run CatchWebImages.exe to see the program running.

My archives files always beguins with a '$'

Have fun! :eusa_dance:
Title: Re: InString
Post by: TouEnMasm on December 29, 2015, 07:35:26 PM
This one download the avatar. follow the link,source codes are included
explain:
The URLDownloadToFile function put the following file in a temporary file
index.php?PHPSESSID=ed5e68d87494a206f290a7e5e4ec6a01&amp;action=dlattach;attach=2;type=avatar
When done:
FindMimeFromData search the extension of the file in the data
movefile rename the temp file giving it the correct extension
http://masm32.com/board/index.php?topic=4946.msg53311#msg53311
Title: Re: InString
Post by: Grincheux on December 30, 2015, 06:45:10 AM
(http://www.phrio.biz/download/CatchWebImages_Demo.jpg)

This is the latest version (http://www.phrio.biz/download/$CatchWebImages.exe)

I have added a listbox which displays the images. :eusa_clap: :eusa_clap: :eusa_clap: :eusa_clap: :eusa_clap:
Title: Re: InString
Post by: Siekmanski on December 30, 2015, 07:54:27 AM
Cool  8)

Works OK here with Windows 8.1
Title: Re: InString
Post by: Grincheux on January 01, 2016, 07:05:43 AM
New version available : Binary and source codes (http://www.phrio.biz/download/$CatchWebImages.exe)
New version available : Binary only (http://www.phrio.biz/download/CatchWebImages.exe)

Corrected a small bug when an url was HTTPS:.
Added an other possible of detecting images under java.
Each file as temporary name but with the good image extension.
Added the base web page name, for example it it beguins by img/ccccccccc I forgot to specify http://www.bidule.com/
Removed dead code

Happy new year everybody, black, white, yellow, red...