CLEO Help Question about 0C11

CLEO related
Status
Not open for further replies.

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
http://www.cplusplus.com/reference/cstring/memset/
it has 3 input parameters: destination, value and size. So you can do the following:

Code:
DEST_PLUS_SIZE = DEST + SIZE
for 0@ = DEST to DEST_PLUS_SIZE
write_mem pointer 0@ value VALUE size 1
end


Alternatively (does the same thing):

Code:
1@ = DEST
for 0@ = 0 to SIZE
write_mem pointer 1@ value VALUE size 1
1@ += 1
end
 
Last edited:

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
http://www.cplusplus.com/reference/cstring/memset/
it has 3 input parameters: destination, value and size. So you can do the following:

Code:
DEST_PLUS_SIZE = DEST + SIZE
for 0@ = DEST to DEST_PLUS_SIZE
write_mem pointer 0@ value VALUE size 1
end


Alternatively (does the same thing):

Code:
1@ = DEST
for 0@ = 0 to SIZE
1@ += 1
write_mem pointer 1@ value VALUE size 1
end

Okay i try it , thx.
 
Last edited:

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
just edited that post, 1@ should be increased after write_mem, my bad
Maybe you know what's wrong?
Tested both.
PHP:
:memset

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

// 0@ - destination, 1@ - value, 2@ - size
// Example: 0AB1: @memset destination 0@ value 32 size 1

for 3@ = 0 to 2@
0A8C: write_memory 0@ size 1 value 1@ virtual_protect 0
1@ += 1
end

0AB2: ret 0
PHP:
:memset

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

// 0@ - destination, 1@ - value, 2@ - size
// Example: 0AB1: @memset destination 0@ value 32 size 1 

0A8E: 4@ = 0@ + 2@ // int
for 3@ = 0@ to 4@
0A8C: write_memory 0@ size 1 value 1@ virtual_protect 0
end

0AB2: ret 0
 
Last edited:

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
In the first example you're adding to value instead of a pointer, so youre overwriting the same byte with different values repetitively
In the second example you're writing to 0@ instead of 3@, so you're overwriting the same byte repetitively

If all you want to do is to reset all bytes to 0, then you could try:
0A8C: write_memory 0@ size 100000 value 0 virtual_protect 0
 
Last edited:

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
In the first example you're adding to value instead of a pointer, so youre overwriting the same byte with different values repetitively
In the second example you're writing to 0@ instead of 3@, so you're overwriting the same byte repetitively

If all you want to do is to reset all bytes to 0, then you could try:
0A8C: write_memory 0@ size 100000 value 0 virtual_protect 0
Thanks for answer.
In the first example - i changed from 1@ += 1 to 0@ += 1 and i still get crash
In the second example - i changed write mem from 0@ to 3@ and i still get crash , sadly..
All i want is just make it work properly.
 

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
can you post the full code that crashes?
I just changing sampfuncs opcode to this snippets, that's help work without sampfuncs.
Code works perfect with sampfuncs opcode.
PHP:
{$CLEO .cs}

0000:

REPEAT
WAIT 0
UNTIL 0AFA:

WHILE TRUE
WAIT 0

call @GetNameFromFile_2206 0 2@
chatmsg "%s" -1 2@

END

:GetNameFromFile_2206
if
1@ = File.Open("CLEO\admin.txt", "rt")
jf @GetNameFromFile_2473
alloc 2@ 64
alloc 3@ 20000
0C11: memset destination 3@ value 0 size 20000 
0085: 4@ = 3@ // (int)
0C11: memset destination 3@ value 32 size 1 
3@ += 1

:GetNameFromFile_2296
if
File.ReadString(1@, 2@, 60)
jf @GetNameFromFile_2360
0C17: 5@ = strlen 2@
call @GetNameFromFile_2483 2 2@ 5@
//0C10: memcpy destination 3@ source 2@ size 5@
0AB1: @memcpy 3 destination 3@ source 2@ size 5@
005A: 3@ += 5@ // (int)

:GetNameFromFile_2360
0C11: memset destination 2@ value 0 size 64  
   File.EOF(1@)
jf @GetNameFromFile_2296
free 2@
File.Close(1@)
0C11: memset destination 3@ value 32 size 1
0085: 3@ = 4@ // (int)
0C17: 5@ = strlen 3@
5@ += 1
alloc 6@ 5@
0C11: memset destination 6@ value 0 size 5@
0AB1: @memcpy 3 destination 6@ source 3@ size 5@
//0C10: memcpy destination 6@ source 3@ size 5@
4@ = 0
free 3@
return_true
goto @GetNameFromFile_2475

:GetNameFromFile_2473
return_false

:GetNameFromFile_2475
ret 1 6@

:GetNameFromFile_2483
1@ -= 1
005A: 0@ += 1@ // (int)
0A8D: 2@ = read_memory 0@ size 1 virtual_protect 0
if
  2@ == 10
jf @GetNameFromFile_2537
0C11: memset destination 0@ value 32 size 1
:GetNameFromFile_2537
0062: 0@ -= 1@ // (int)
ret 0

: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 destination 0@ value 32 size 1

for 3@ = 0 to 2@
0A8C: write_memory 0@ size 1 value 1@ virtual_protect 0
0@ += 1
end
0AB2: ret 0
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
my bad, it should be:

for 0@ = DEST to (DEST_PLUS_SIZE - 1)

or
for 0@ = 0 to (SIZE - 1)
 

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
my bad, it should be:

for 0@ = DEST to (DEST_PLUS_SIZE - 1)

or
for 0@ = 0 to (SIZE - 1)

still not work :/
PHP:
:memset

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

// 0@ - destination, 1@ - value, 2@ - size
// Example: 0AB1: @memset 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
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
the code you posted doesn't have any calls to that memset function so it's hard to tell if that is the problem but the "Example" comment under the ":memset" label has mistake, it doesn't have the number of parameters

It should be this:
0AB1: @memset number_of_parameters 3 destination 0@ value 32 size 1

Instead of this:
0AB1: @memset destination 0@ value 32 size 1
 

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
the code you posted doesn't have any calls to that memset function so it's hard to tell if that is the problem but the "Example" comment under the ":memset" label has mistake, it doesn't have the number of parameters

It should be this:
0AB1: @memset number_of_parameters 3 destination 0@ value 32 size 1

Instead of this:
0AB1: @memset destination 0@ value 32 size 1
I know about opcode " 0AB1: " params and returns very good , but this time you are right i forgot put how many params i writing to snippet, now working.
Thanks, i appreciate your help.

Now can use everyone , fully working. Big Thanks Monday.
PHP:
: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
PHP:
: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
 
Last edited:

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
C++:
2@ = strlen 0@
3@ = strlen 1@
memcpy(0@ + 2@, 1@, 3@)
memset(0@ + 2@ + 3@, 0, 1) // null char

tested , works perfect.
PHP:
:strcat

// 0@ - destination, 1@ - source
// Example: 0AB1: @strcat 2 destination 0@ source 1@

0AB1: @strlen 1 string 0@ _return: 2@
0AB1: @strlen 1 string 1@ _return: 3@
005A: 0@ += 2@  // (int)
0AB1: @memcpy 3 destination 0@ source 1@ size 3@
005A: 0@ += 3@  // (int)
0AB1: @memset 3 destination 0@ value 0 size 1
0AB2: ret 0

Also, all these functions(RtlFillMemory, strcat, strcpy etc.) are exported by ntdll, so u can use this tutorial, to make shorter and easier functions.
I know only samp.dll call , i first time see ntdll i have no idea how it works.

monday
springfield
Thanks for help , now i can finally make more stuff with snippets.
 
Last edited:

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
It sets each byte to have the same value.

If you have an array of bytes and you'd like to set all of the bytes to 0, you could create a loop like this:
Code:
for ADDRESS = ARRAY_POINTER to END_OF_ARRAY_POINTER
    write 0 at ADDRESS
end

You can notice that it takes 3 lines of this pseudocode (and would take even more lines of code in CLEO). So to make it shorter and more readable we can use "memset" function (which is what 0C11 opcode implements).

You could check these for practical examples:
https://www.geeksforgeeks.org/memset-c-example/
https://www.youtube.com/results?search_query=memset
 
Status
Not open for further replies.
Top