 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Emya Newbie cheater
Reputation: 0
Joined: 28 Jul 2024 Posts: 14
|
Posted: Mon Aug 19, 2024 3:41 pm Post subject: Int to String (asm) |
|
|
Hey... big guys... maybe what I'm doing is ridiculous...
But at 5 AM, I finally managed to create a pure assembly function that converts a string into a signed 4-byte integer and a single-precision float. This is a huge achievement for me.
But I'm not satisfied yet. I want to convert a 4-byte integer into a string. Is this too difficult for me?
If any of you have done something similar, could you share some ideas or thoughts? (I'm looking for a technical challenge)
|
|
Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4703
|
Posted: Mon Aug 19, 2024 4:53 pm Post subject: |
|
|
You're better off calling an API function. Using C:
Code: | globalalloc(foo,4096)
label(num)
label(strval)
{$c}
#include <stdlib.h>
void int_to_str(int v, char *str) {
_itoa(v, str, 10);
}
{$asm}
foo:
{$ccode}
extern int num;
extern char strval[252];
int_to_str(num, strval);
{$asm}
ret
foo+800:
num:
resd 1
strval:
resb 252
createthread(foo) |
Assembly:
Code: | globalalloc(foo,4096)
label(num)
label(strval)
foo:
push rbp
mov rbp,rsp
sub rsp,20
// char * _itoa( int value, char *buffer, int radix );
mov ecx,[num]
mov rdx,strval
mov r8d,#10
call _itoa
mov rsp,rbp
pop rbp
ret
foo+800:
num:
resd 1
strval:
resb 252
createthread(foo) |
If you don't want to use a function from some other API, search for "itoa implementation" to get examples. (compile C code to see assembly; might need to use `volatile` on inputs & outputs to force the compiler to actually generate code)
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
 |
Emya Newbie cheater
Reputation: 0
Joined: 28 Jul 2024 Posts: 14
|
Posted: Tue Aug 20, 2024 9:56 am Post subject: Maybe I need a usable template |
|
|
ParkourPenguin wrote: | You're better off calling an API function. Using C:
Code: | globalalloc(foo,4096)
label(num)
label(strval)
{$c}
#include <stdlib.h>
void int_to_str(int v, char *str) {
_itoa(v, str, 10);
}
{$asm}
foo:
{$ccode}
extern int num;
extern char strval[252];
int_to_str(num, strval);
{$asm}
ret
foo+800:
num:
resd 1
strval:
resb 252
createthread(foo) |
Assembly:
Code: | globalalloc(foo,4096)
label(num)
label(strval)
foo:
push rbp
mov rbp,rsp
sub rsp,20
// char * _itoa( int value, char *buffer, int radix );
mov ecx,[num]
mov rdx,strval
mov r8d,#10
call _itoa
mov rsp,rbp
pop rbp
ret
foo+800:
num:
resd 1
strval:
resb 252
createthread(foo) |
If you don't want to use a function from some other API, search for "itoa implementation" to get examples. (compile C code to see assembly; might need to use `volatile` on inputs & outputs to force the compiler to actually generate code) |
Ah... it's just unbelievable. The output code seems to be somewhere, but I don't have any programming background. I want to refine it into a callable template like the one below, but I'm too dumb to understand what the senior provided...
Maybe I need a usable template. I'll do my best to learn things
Code: |
alloc(code,$100)
createthread(code)
code:
push ebp
mov ebp,esp
pushad
push #114514
call Int_to_String
mov [String_output],eax
popad
mov esp,ebp
pop ebp
ret |
|
|
Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4703
|
Posted: Tue Aug 20, 2024 11:07 am Post subject: |
|
|
Ok, here's a more complete example using 32-bit code:
Code: | [ENABLE]
{$lua}
-- just makes a couple memory records if needed
if syntaxcheck then return end
assert(memrec, 'Assign script to table')
if memrec.Count == 0 then
createTimer(1,function()
local mrInput = AddressList.createMemoryRecord()
mrInput.Description = 'Input (number)'
mrInput.Address = 'input_number'
mrInput.Type = vtDword
mrInput.ShowAsSigned = true
mrInput.appendToEntry(memrec)
local mrOutput = AddressList.createMemoryRecord()
mrOutput.Description = 'Output (string)'
mrOutput.Address = 'output_string'
mrOutput.Type = vtString
mrOutput.String.Size = 252
mrOutput.appendToEntry(memrec)
end)
end
{$asm}
globalalloc(foo,4096)
label(input_number)
label(output_string)
foo:
push ebp
mov ebp,esp
push 10
push [input_number]
push output_string
call _itoa
mov esp,ebp
pop ebp
ret
foo+800:
input_number:
resd 1
output_string:
resb 252
registersymbol(input_number)
registersymbol(output_string)
createthread(foo)
[DISABLE] | I can't quite test this right now, but it should be correct
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
 |
Emya Newbie cheater
Reputation: 0
Joined: 28 Jul 2024 Posts: 14
|
Posted: Tue Aug 20, 2024 1:40 pm Post subject: dont use lua |
|
|
I’m very sorry for making you write so much code. Lua's efficiency is too slow. I have a new idea. First, calculate the number of digits like this:
mov eax,[ebp+08]
mov eax,[eax]
mov esi,01
xor edi,edi // digit count
newmem:
inc edi
imul esi,esi,#10
cmp esi,eax
jb newmem
Then, move the address where the output string should be placed to esi, and start from the end:
mov esi,str
add esi,edi
Next, I’ll figure out how to execute eax/10, obtain the remainder (units digit) and result (other digits), and then add bl,'0'. This way, I can fill in the string one digit at a time and complete the conversion from an unsigned 4-byte integer to a string!
Maybe one day in the future, I’ll come back and understand the advanced language code you’ve written. Love you, bro!
|
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|