[SNIPPET] Search text in text

// 0AB1: call @search_text_in_the_text 2 0@ 1@ // 0@ - ?????, 1@ - ?????
:search_text_in_the_text
var
    2@:int
    3@:int
    4@:int
    5@:int
    7@:int
    8@:int
end
7@ = 0
0C17: 4@ = strlen 0@
0C17: 8@ = strlen 1@
if or
8@ > 4@
8@ <= 0
then
    059A: return_false
    ret 0
end
0AC8: 6@ = 1024
0C11: memset destination 6@ value 0 size 1024
0C10: memcpy destination 6@ source 1@ size 8@
for 5@ = 0 to 4@
0A8D: 2@ = read_memory 0@ size 1 virtual_protect 0
0A8D: 3@ = read_memory 1@ size 1 virtual_protect 0
    if 2@ == 3@
    then
        inc(1@)
        inc(7@)
    else
        7@ = 0
        0C10: memcpy destination 1@ source 6@ size 8@   
    end
    if 7@ == 8@
    then
        0485: return_true
        ret 0   
    end
inc(0@)
end
059A: return_false
0AC9: 6@
ret 0
 
Joined
Feb 18, 2005
Messages
2,963
Reaction score
267
Re: Search text in text

This was useful before SAMPFUNCS 2.4, as of 2.5+ you can just use:

Code:
0C18: 1@ = strstr string1 0@ string2 "HEY"
 

Z0DY

Well-known member
Joined
Feb 20, 2013
Messages
225
Reaction score
0
Re: Search text in text

for this u need sampfuncs too, Opi ._.
 

Parazitas

God
Joined
Jan 2, 2017
Messages
3,116
Solutions
5
Reaction score
882
Location
Lithuania
100% working without SAMPFUNCS

PHP:
:search_text_in_the_text
{
    Example: 0AB1: call @search_text_in_the_text 2 String1 0@ String2 1@ 
    In: 0@ - text; 1@ - string;
    Out: True or False;
}
var 
    2@:int
    3@:int
    4@:int
    5@:int
    7@:int
    8@:int
end
7@ = 0
0AB1: @strlen 1 string 0@ _return: 4@
0AB1: @strlen 1 string 1@ _return: 8@
if or 
8@ > 4@
8@ <= 0
then
    059A: return_false
    0AB2: ret 0
end
0AC8: 6@ = allocate_memory_size 1024
0AB1: @memset 3 destination 6@ value 0 size 1024
0AB1: @memcpy 3 destination 6@ source 1@ size 8@  
for 5@ = 0 to 4@
0A8D: 2@ = read_memory 0@ size 1 virtual_protect 0
0A8D: 3@ = read_memory 1@ size 1 virtual_protect 0
    if 2@ == 3@
    then 
        inc(1@)
        inc(7@)
    else
        7@ = 0 
        0AB1: @memcpy 3 destination 1@ source 6@ size 8@   
    end
    if 7@ == 8@
    then
        0485: return_true
        0AB2: ret 0    
    end
inc(0@) 
end
059A: return_false
0AC9: 6@
0AB2: ret 0

:strlen
{
    Example: 0AB1: @strlen 1 string 1@ return: 3@
    In: 0@ - text;
    Out: 1@ - size;
}
for 1@ = 0 to 1024
    0A8D: 2@ = read_memory 0@ size 1 virtual_protect 0
    if not 2@ == 0
    jf break
    0@ += 1
end
0AB2: ret 1 1@

:memcpy

var
0@ : integer
1@ : integer
2@ : integer
3@ : integer
end

// 0@ - destination, 1@ - source, 2@ - size
// Example: 0AB1: @memcpy 3 destination 0@ source 1@ size 2@

dec(2@)
for 3@ = 0 to 2@
    0A8D: 4@ = read_memory 1@ size 1 virtual_protect 0
    0A8C: write_memory 0@ size 1 value 4@ virtual_protect 0
    1@ += 1
    0@ += 1
end
0AB2: ret 0

:memset

var
0@ : integer
1@ : integer
2@ : integer
3@ : integer
end

// 0@ - destination, 1@ - value, 2@ - size
// Example: 0AB1: @memset 3 destination 0@ value 32 size 1
2@ -= 1
for 3@ = 0 to 2@
0A8C: write_memory 0@ size 1 value 1@ virtual_protect 0
0@ += 1
end
0AB2: ret 0

or

http://ugbase.eu/index.php?threads/snippet-iftextcontains-function.18796/
 
Last edited:
Top