News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Boyer Moore search function

Started by Magnum, March 20, 2013, 04:35:26 AM

Previous topic - Next topic

Magnum

I read the include files for the Boyer–Moore string search algorithm, but I don't understand some of the parameters.

Is srcLngth:DWORD how many bytes into the program that you want to search ?

And I would like to learn how to find every instance of the search string.

Thanks.


.data

SourceStr      db "Where is it ?",0
SearchStr      db "mint77",0

.code

start:

; BMBinSearch proc startpos:DWORD,                 start position
;                  lpSource:DWORD,srcLngth:DWORD,  address to start
;                  lpSubStr:DWORD,subLngth:DWORD
jmp next
new db "mint77"
next:

invoke BMBinSearch,0,ADDR SourceStr,200,ADDR SearchStr,6
add eax,OFFSET SourceStr  ; result in eax is the offset where pattern was found
                               

invoke MessageBox, 0,eax,addr SourceStr, 1


      invoke ExitProcess,0

end start
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

MichaelW

You pass the length, in bytes, of the data to be searched in srcLngth. The only non-obvious details that I can see are that startpos is a byte index, and that to continue a search you would normally set its value to the return value of the previous search, plus 1.

;==============================================================================
    include \masm32\include\masm32rt.inc
;==============================================================================
    .data
              ;          1         2         3         4         5
              ;012345678901234567890123456789012345678901234567890123
        s1 db "this is my brother Darryl and my other brother Darryl.",0
        s2 db "Darryl",0
    .code
;==============================================================================
start:
;==============================================================================
    invoke BMBinSearch, 0, ADDR s1, SIZEOF s1 - 1, ADDR s2, SIZEOF s2 - 1
    push eax
    mov esi, OFFSET s1
    add esi, eax
    printf("%d\t%s\n",eax, esi)

    pop eax
    add eax, 1
    invoke BMBinSearch, eax, ADDR s1, SIZEOF s1 - 1, ADDR s2, SIZEOF s2 - 1
    mov esi, OFFSET s1
    add esi, eax
    printf("%d\t%s\n\n",eax, esi)

    inkey
    exit
;==============================================================================
end start

Well Microsoft, here's another nice mess you've gotten us into.

Magnum

Thanks.

I am wanting to search the entire program for the string. (Data and Code)

I am interested in developing a self-healing program.

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

ragdog

Hi Andy

You want to search "mint77" Maker (signatur) in a code section?


.code
start:
jmp @F
Signatur::
db "mint77"
@@:
    mov esi,Signatur
    .if dword ptr [esi]=="tnim"
    .if word ptr [esi+4]=="77"
        invoke crt_puts,CTEXT ("Signatur found"),CR,LF
    .endif
    .endif


Magnum

Thanks ragdog.

invoke crt_puts isn't working.

I found it here, but no where else unless it's in a library.

Andy

  ; ------------------------------------------
  ; prototypes for EXPORT msvcrt functions
  ; ------------------------------------------

externdef _imp__puts:PTR c_msvcrt
    crt_puts equ <_imp__puts>
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

ragdog

It is a library Msvcrt.inc and Lib

For not use a console app replace it with MessagesBox or a return value

dedndave

you can also use the print macro

        print   chr$("Signature found"),13,10

Magnum

Thanks.

What we could use would be something like this.

.code

MessBox "Asmers rock",0

It would automatically add the text to the data section.

Just a thought.

---------------

Anyone very familar with motors ?

I have a high speed leaf blower motor that is semi-functional.

I cleaned the commutator as best I could.

The end of the brushes wasn't worn evenly like I have seen on alternator brushes.

Should I polish the ends ?



Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

you might be able to buy replacements for them
if crap got in there, it may have "ground" them up

MichaelW

Not necessarily, Owl crap is a good lubricant.
Well Microsoft, here's another nice mess you've gotten us into.

dedndave

lol
well, i have an old SkilSaw, similar to this one



a few years back, i used it to cut some external siding - the composite kind
it is good siding, as it will take considerable punishment
but the dust created when cutting it does a job on electric motor brushes
for now, i am using a black and decker circular saw

i was pleasantly surprised to see how many different replacement brushes were available

http://www.ereplacementparts.com/carbon-brush-cb113-p-11731.html

but, i was disappointed not to find what i needed
there is probably a substitution that i am not aware of

thing is - i am getting old, and i seem to care less about having a bunch of nice construction tools   :lol:
when i was younger, i had always wanted to build my own house, "someday"
someday has come and gone, and i am not as interested
i have done enough construction for this lifetime   :redface:

hutch--

Andy,

If the brushes are not stuffed, what you need to do is be able to access the commutator while the motor is running, if you are careful you can use a piece of emery paper to clean up the commutator surface so that it smooths out the brush wear. Make a point of not electrocuting yourself by not touching any live parts.

Magnum

The leaf blower produces 180 m.p.h. winds, so I have been cleaning it by rotating by hand.

I once got quite a jolt when I cut through a wire going to an analog TV tube.

The TV hadn't been used in 5 years, so I thought that is was safe.

I  was using gloves and insulated wire cutters but it still made my hair stand up.

Later I understood what capacitors do.

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Magnum

2 pics of the motor.

http://s1127.photobucket.com/user/bicycle77017/media/Motor1_zps0b0fc792.jpg.html?sort=3&o=0
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

K_F

I cannot see the pic, maybe you can zip it and post as an attachment.

Check List
1) If it's an AC motor (AC mains plug) and has DC commutators - Big white(any colour) phase shift capacitor might be phutt - replace Capacitor (local electrical store should havim)
2) Check the motor commutators.. are these worn badly (indented) - happens after long term use => throw away/replace motor
3) Check motor wiring.. is the insulation golden or reddish colour (normal) - if dark and blackened (smells bad) = you might have commutator wiring shorts => throw away/replace motor and Capacitor
4) Check for loose wiring connections... any loose wire will start to burn and have a 'burnt toast' look.... smell it (It smells like cr.p).

Never touch the TV HT lead .. ever - The TV is one big capacitor
:)

'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'