The MASM Forum

Microsoft 64 bit MASM => Examples => Topic started by: HSE on May 01, 2024, 01:10:37 AM

Title: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on May 01, 2024, 01:10:37 AM
Hi all!!

This is a little tool with JJSearch tool general concept (also known as FindOnDisk (https://masm32.com/board/index.php?msg=30731)), wich is a very useful tool with some limitations. I made the new tool following Hutch's style and can be integrated in Masm64 SDK if tests are successful.

In this case, tool is limited to ANSI strings, and will fail with very long name files or non latin characters in directory names. I have one of each in the programming disk, then I erased that little noise  :biggrin:

The file system exploration is a classical example from Masm32 SDK, obviously translated to 64 bits.

Boyer-Moore implementations are from Mineiro's code (https://masm32.com/board/index.php?msg=109928). A little modification was critical, because that implementation crash when file size is an exact multiple of page size (like probably happen in many others tools that fail in my disk).

Critics and suggestions are welcome  :thumbsup:

Regards, HSE.

version 10 November 2024

(https://i.postimg.cc/sG4LfmzM/Looking-For.png) (https://postimg.cc/sG4LfmzM)
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on May 01, 2024, 08:10:26 AM
Added update of targets list modifications between application instances running simultaneously.

Updated files in first post.
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: jj2007 on May 01, 2024, 08:39:38 AM
Wickedly crafted :thumbsup:
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: Biterider on May 01, 2024, 03:28:33 PM
Hi HSE
Cool application. Tested the binary here without any problems.  :thumbsup:

Biterider
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: greenozon on May 01, 2024, 08:09:05 PM
Very interesting tool, thanks for your efforts HSE!
some feedback:

1) help button wanted to find .pdf file, is it available?
---------------------------
LookingFor:
---------------------------
Could not open LookingFor.pdf
---------------------------
OK 
---------------------------

2) I'd add some "Stop" button in case the end-user set some wide mask eg: "c:\"
the only way is to kill app then...

3) I tried to search some sample patterns (two) and after some time the app crashed
I've got crash dump in case of interest

https://prnt.sc/BFCNqFg2J3Tt (https://prnt.sc/BFCNqFg2J3Tt)    (Picture from VS opening crash dump)

Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on May 02, 2024, 12:49:00 AM
Hi greenozon!

Quote from: greenozon on May 01, 2024, 08:09:05 PM1) help button wanted to find .pdf file, is it available?

Yes, in .zip with binary. In .zip with source there is a .tex file to build .pdf.


Quote from: greenozon on May 01, 2024, 08:09:05 PMthe only way is to kill app then...

Yes, that is the way  :thumbsup:


Quote from: greenozon on May 01, 2024, 08:09:05 PM3) I tried to search some sample patterns (two) and after some time the app crashed
I've got crash dump in case of interest

That is szappend function in m64lib. The most probable thing is that your disk have a long path, or an  Unicode name in a file or directory. Building in console subsystem and TRACKING_CRASH equ 1, will show files correctly accesed, then the problem is close to last one.

In C:\ is most probable to have long paths or unicode names. I can search 260 Gb in D:\ after remove one of each, but to search in C:\ need to be more specific.

Anyway, if you write unicode files everywhere, a so simple ASCII search will not work for you.

Thanks very much, HSE


Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on May 02, 2024, 12:54:17 AM
Thanks JJ and Biterider  :thumbsup:
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: greenozon on May 02, 2024, 02:39:45 AM
You are right,
I was scanning C:\tmp that has the hell amount of trash :)
and yeah - it has weird dir names even including emojis!

do you support that zoo?
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on May 02, 2024, 03:18:41 AM
Quote from: greenozon on May 02, 2024, 02:39:45 AMdo you support that zoo?

It's mostly a tool to assist programming. And the targets are very simple ASCII files.

Because I don't even have tabs in most files, I forgot that  :biggrin:

Updated in first post.
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: NoCforMe on May 02, 2024, 03:48:22 AM
Quote from: greenozon on May 01, 2024, 08:09:05 PMVery interesting tool, thanks for your efforts HSE!
some feedback:

2) I'd add some "Stop" button in case the end-user set some wide mask eg: "c:\"
the only way is to kill app then...
I second that emotion.

My own file-finder app runs the disk-scanning code in a separate thread with a "Cancel" button visible to stop things if they run too long. Very easy to implement.
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on May 02, 2024, 04:25:00 AM
Quote from: NoCforMe on May 02, 2024, 03:48:22 AMemotion.
¿?  :biggrin:

 :thumbsup: A better solution. Updated in first post.

Thanks, HSE.
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: greenozon on May 02, 2024, 06:44:22 PM
Tried the fresh bits from 1st post
sometimes app exists (crashes? but no core dump) in case you press "Find" but not set base directory
https://prnt.sc/AS-Y42QDxHSb (https://prnt.sc/AS-Y42QDxHSb)
Also if base dir is empty the "Cancel" button continues to be visible instead of "Find" as no operation was started...
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on May 02, 2024, 10:17:35 PM
Hi greenozon!

Quote from: greenozon on May 02, 2024, 06:44:22 PMsometimes app exists (crashes? but no core dump) in case you press "Find" but not set base directory
https://prnt.sc/AS-Y42QDxHSb

That it's weird. A message box open when no valid path (at least "\") or no validad file name (at least "*") is provided.

But I have to see because "\*" have to fail, but that work if first run "\*.*". Something remain in some buffer. Perhaps I will take some time and try to improve all path thing. 

Quote from: greenozon on May 02, 2024, 06:44:22 PMAlso if base dir is empty the "Cancel" button continues to be visible instead of "Find" as no operation was started...

Corrected  :thumbsup:

Thanks, HSE.
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: greenozon on May 03, 2024, 05:02:28 PM
Nice, nice! great progress :thumbsup:

but still hitting crash dumps sometimes, eg:

https://prnt.sc/Rl0sPvzGc7HS (https://prnt.sc/Rl0sPvzGc7HS)
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on May 06, 2024, 03:27:56 AM
Hi greenozon!

Quote from: greenozon on May 03, 2024, 05:02:28 PMbut still hitting crash dumps sometimes, eg:

:thumbsup:  Apparently that is an ASCII MessageBox with a Unicode string. A little more elaborated error processing is not working yet.

Updated in first post.

Thanks, HSE

Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on May 15, 2024, 01:15:27 AM
Hi all!

I have some ideas about mask for file inclusion and exclusion, but finally don't have much sense  :biggrin:

Then I made just very standard: now  is available " * " for all files to search, " *. " for files without extension and for only extension files " .* " was already working.

Update in first post.

Regards, HSE.
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: six_L on May 15, 2024, 02:29:47 PM
Hi,HSE
Great! Looking for some files at attosecond.

Regard.
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: greenozon on May 15, 2024, 07:31:24 PM
If I set dir to say
c:\ddd
(the dir is real and has files in it)

and pressing "Find" button
I"m hitting strange error: (which repeats 2 times in a row)

---------------------------
LookingFor
---------------------------
Fail to set directory
---------------------------
OK   
---------------------------

also even after error the Cancel button is still actual


2) If I apppend \ to the dir like
C:\ddd\
then tehre is another error

---------------------------
LookingFor
---------------------------
Name or extension target problem
---------------------------
OK   
---------------------------


and button returns immediately to Find

3) if set c:\ddd* then app eats 100% CPU and doing nothing
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on May 15, 2024, 10:02:18 PM
Hi six_L!

Quote from: six_L on May 15, 2024, 02:29:47 PMGreat! Looking for some files at attosecond.

:thumbsup: Thanks.

Regards, HSE

Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on May 15, 2024, 10:33:13 PM
Hi greenozon!

The target must have a path and a file mask. Perhaps it's no so clear in the help  :rolleyes:

Quote from: greenozon on May 15, 2024, 07:31:24 PMc:\ddd
(the dir is real and has files in it)

and pressing "Find" button
I"m hitting strange error: (which repeats 2 times in a row)

---------------------------
LookingFor
---------------------------
Fail to set directory
---------------------------
OK 
---------------------------

also even after error the Cancel button is still actual

In this case you are searching "c:\" as path and "ddd" as mask. Because it's searching entire C: disk, is failing to access some long path or unicode name directory. 

After message, it skip that directory and search reasume (I think).

Quote from: greenozon on May 15, 2024, 07:31:24 PM3) if set c:\ddd* then app eats 100% CPU and doing nothing

In this case you are searching "c:\" as path and "ddd*" as mask. Probably it's the same that case 1 but, because wildcard, check the mask it's slower (again I think). I will test these cases.

The correct target for this search could be:c:\ddd\*
Quote from: greenozon on May 15, 2024, 07:31:24 PM2) If I apppend \ to the dir like
C:\ddd\
then tehre is another error

---------------------------
LookingFor
---------------------------
Name or extension target problem
---------------------------
OK 
---------------------------
and button returns immediately to Find

That it's correct because there is no mask. Perhaps error message need to be a little more verbose  :thumbsup:

Thanks very much, HSE
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on May 16, 2024, 10:05:56 PM
Hi all!

Some error messages a bit more descriptive, and now catch some error to access target path.

Update in first post.

Regards, HSE.
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: greenozon on May 17, 2024, 06:22:35 AM
Thanks a lot for the fresh build!
new err boxes are much better, but.. found out this one -

---------------------------
LookingFor:
---------------------------
Could not open
---------------------------
OK   
---------------------------

it happens when fill in very long value in the 1st drop down
also it's tricky to show this err...
try to click and on Find by mouse -> nothing
press Space -> gotcha
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on May 17, 2024, 08:14:08 AM
Hi greenozon!

Quote from: greenozon on May 17, 2024, 06:22:35 AM---------------------------
LookingFor:
---------------------------
Could not open
---------------------------
OK 
---------------------------

That could be an error or not, but anyway a good point  :thumbsup:

That message popup after click in some filename that match definitions.

You can see how that work in procedure ListProc, inside more.inc file.

If file extension is .bat or .CMD, shell call \masm64\qeditor. That is hardcoded but you can change path or editor and rebuild program. This necessary to prevent file execution.

Perhaps that also happen with other extensions associated with a program not present or moved.

Because is a tool for programming, is expected that extensions of interest have associated an editor.

Quote from: greenozon on May 17, 2024, 06:22:35 AMtry to click and on Find by mouse -> nothing
press Space -> gotcha

:thumbsup: There are remains from early development  :biggrin:

Thanks, HSE.
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on May 26, 2024, 07:48:45 AM
I all!

I failed to reproduce greenozon problem :sad:

Anyway now editor for *.bat, *.cmd, and *.js is not longer hardcoded.

Quote from:  LookingFor.pdfClicking with mouse or pressing Enter key will open selected file in result list. Because is a tool for programming, is expected that extensions of interest have associated an editor.
   
   Executable files will not open to prevent unwanted runnings.
   
   In similar way *.bat, *.cmd and *.js files will not run. But in this cases they will open in an editor. By default /masm64/qeditor is that editor. But is possible to select a new path or editor. If default or stored editor fail, a dialog will ask a new path or editor. Later, editor could be changed in LookingFor.ini file.

Update in first post.

Regards, HSE.
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on June 04, 2024, 03:58:05 AM
Minor update to help file (in first post). Now Release 1.0
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on July 03, 2024, 02:19:44 AM
Hi all!

File system exploration example in Masm32 SDK check file attributes:
        .if wfd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY
and that worked well.

Just now happen that, when you customize directory icon, another bit is added (readonly). Then these directories are ignored  :biggrin: , unless you change file attributes evaluation to bits instead of values:
        .if wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY

Update in first post.

Regards, HSE.
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: jj2007 on July 03, 2024, 04:45:31 AM
Quote from: HSE on July 03, 2024, 02:19:44 AM.if wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY

Check in debugger. I remember that at least one assembler version (ml.exe?) had problems with the single ampersand.
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on July 03, 2024, 05:42:04 AM
Quote from: jj2007 on July 03, 2024, 04:45:31 AMI remember that at least one assembler version (ml.exe?) had problems with the single ampersand.

No problem. This is Masm64 SDK (Vasily's macro).
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: greenozon on July 07, 2024, 06:38:28 PM
Using latest build - 1.2

there are some handles leakage when you run then stop then run again -> it is only increasing (sometimes -1)
eg:
https://prnt.sc/0KjFpGqsQ9Jj (https://prnt.sc/0KjFpGqsQ9Jj)
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: greenozon on July 07, 2024, 06:39:09 PM
If during active Find operation you click for example Help button the debugger reports some heap corruption cases, eg:

https://prnt.sc/DeiF_aN7w__U (https://prnt.sc/DeiF_aN7w__U)
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on July 08, 2024, 03:27:04 AM
Hi greenozon!

Quote from: greenozon on July 07, 2024, 06:39:09 PMIf during active Find operation you click for example Help button the debugger reports some heap corruption cases, eg:

:thumbsup: Fantastic. There was a problem in that situation. Solved.

Quote from: greenozon on July 07, 2024, 06:38:28 PMthere are some handles leakage when you run then stop then run again -> it is only increasing (sometimes -1)

I found at least some of them  :thumbsup:

Updated in first post.

Thanks, HSE.



Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: greenozon on July 10, 2024, 05:23:43 PM
Thanks a lot HSE!
I start to love this small tiny piece of mastership!
:thumbsup::thumbsup::thumbsup:
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on July 11, 2024, 07:48:21 AM
Hi greenozon!

Quote from: greenozon on July 10, 2024, 05:23:43 PMI start to love this small tiny piece of mastership!

Your tests and reports made a great contribution. Thanks to you  :thumbsup:

HSE
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on July 19, 2024, 11:39:47 PM
Hi all!

The return value from BMSearch was missing when file size is 0, then there were false positives. 

Updated in first post.

HSE


Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on July 28, 2024, 08:40:55 AM
Hi all!!

Take a while to find how subclass the edit inside the combobox, but finally is so easy  :biggrin:
Then now search also can begin pressing return key in any edit.

Using OA_Tool (https://masm32.com/board/index.php?topic=7862.0) (after a little addition (https://masm32.com/board/index.php?topic=7862.msg132630#msg132630)) I cleaned not used local variables and unnecessary register preservations. Some ANNOTATIONs, beside to allow source code analysis by the tool, help to understand why some procedures don't need to preserve registers and where they are preserved.

Updated in first post.

HSE
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: Biterider on July 28, 2024, 03:48:11 PM
Quote from: HSE on July 28, 2024, 08:40:55 AMUsing OA_Tool (https://masm32.com/board/index.php?topic=7862.0) (after a little addition (https://masm32.com/board/index.php?topic=7862.msg132630#msg132630)) I cleaned not used local variables and unnecessary register preservations. Some ANNOTATIONs, beside to allow source code analysis by the tool, help to understand why some procedures don't need to preserve registers and where they are preserved.
Cool, really cool  :thumbsup:

Biterider
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: Biterider on July 28, 2024, 04:55:44 PM
Hi HSE
I have a feature request  :cool:
Pressing the '-' button brings up a message box saying 'Target not found'. To close it, pressing <ESC> quits the application, which is a bit odd. Perhaps it would be better to press <ESC> twice. The first closes the popup and the second closes the application.

I noticed that pressing <ESC> does not close the About dialogue box, which should be consistent with the behaviour with the rest of the application.

Biterider
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on July 29, 2024, 01:41:58 AM
Hi Biterider

Very interesting. I will see  :thumbsup:

Meanwhile close messages with <ENTER>, like I do  :biggrin:  :biggrin:

So far <ESC> work like you suggest when file in the list is open, because I close qEditor with <ESC>.

Thanks, HSE
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on July 29, 2024, 08:15:45 AM
Updated in first post  :thumbsup:
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: Biterider on July 29, 2024, 04:47:15 PM
Hi HSE
It works perfectly  :biggrin:
Congrats  :thumbsup:

Biterider
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on August 15, 2024, 04:08:24 AM
Hi all!

Lately, program take point always like a word separator.
But point also can be part of a name (at beginning) that you search.
Then now the point character can be evaluated in both cases. If you want that point work always like word separator you must change to "1" the "point" option in the .ini file.

LATER: that was a confuse idea. I remove that.

Updated in first post.

HSE



Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on August 15, 2024, 11:09:33 PM
Just to note some curiosity for me.

ML64, beside to allow names that begin with a point, also allow that names in structures. Then is possible:
test2 struct
    .left qword 0
test2 ends

.data
      test3 test2 {2}

.code
      conout str$(test3..left),lf

      mov test3..left, 1

      conout str$(test3..left),lf

Some idea from all this was to add an option that search full words surrounded for at list a point. A little experimental, and perhaps not so useful, but without any process cost if not used :biggrin:
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: greenozon on August 17, 2024, 10:33:50 PM
@HSE
I see you are doing nice version numbering, but only on archive filename level...
would you mind to add the tool version into points 1/2/3 - whatever works best for you
https://prnt.sc/VlNFiVsG5h5T (https://prnt.sc/VlNFiVsG5h5T)

thanks!
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on August 18, 2024, 03:02:25 AM
Hi greenozon!

No problem  :thumbsup:

Updated in first post.

Can you look in about dialog if trimming work and cpu name is aligned now?


Thank, HSE
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: Biterider on August 18, 2024, 03:26:34 AM
Hi HSE
When resizing (enlarging) the application dialog, I noticed a glitch with the "+" button (see picture).
When resizing the dialog, there is no minimum size and the controls starts to overlap.
Perhaps you can set a lower limit when resizing.

Biterider

(https://i.postimg.cc/PL6LTw2M/image.png) (https://postimg.cc/PL6LTw2M)


Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on August 18, 2024, 09:26:48 AM
Hi Biterider!

Quote from: Biterider on August 18, 2024, 03:26:34 AMI noticed a glitch with the "+" button (see picture).

Thanks very much. Without that red thing I could never find what "+" button you are talking about  :biggrin:  :biggrin:  :biggrin:

Clipsiblings style was missing. I don't know why there was no problem with first line buttons :rolleyes:

Thanks, HSE
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: Biterider on August 18, 2024, 03:16:21 PM
Hi
Quote from: HSE on August 18, 2024, 09:26:48 AMClipsiblings style was missing.
Works now  :thumbsup:

Biterider
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: greenozon on August 19, 2024, 05:42:17 PM
@HSE thanks a lot and Happy Monday! :)

one minor issue:
after making window very very small and then recover it's size -
one label looks like got corrupted forever whatever you do afterwards...
eg:

https://prnt.sc/_M6ZskICItNm
Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on August 20, 2024, 05:06:13 AM
Hi greenozon

Probably problem is related also to missing Clipsiblings style, but I don't see that here.

Anyway, Biterider is right, interface look broken in small sizes. Then I put a limit to minimization.

In theory, minimum size rely on system font size configuration.

Thanks, HSE.

Title: Re: LookingFor: A Masm64 tool to find strings in files.
Post by: HSE on November 11, 2024, 04:13:36 AM
Hi all!

  Now list of targets can be sorted by name, addition and retrieves. Then 2 numbers are stored with targets in .ini file.

  To sort by name I write a little function that use a character's table. An interesting feature is that you can change the table. I think this idea is somewhere in the forum, but I failed to find where  :biggrin:

  Updated in first post.

  Regards, HSE.