Code: Select all
// code snippet to save string to file
code:
mov qword ptr [buffer], rsi // assuming rsi have the string buffer
pushfq
push rax
push rbx
push rcx
push rdx
push r8
push r9
call savefile
pop r9
pop r8
pop rdx
pop rcx
pop rbx
pop rax
popfq
// Function Call savefile
savefile:
sub rsp, 80
mov rax, 0
xor rax, rsp
mov [rsp+70], rax
mov rdx, qword ptr [buffer] // buffer to write
mov qword ptr [rsp+48], rdx // buffer to write
mov qword ptr [rsp+58], 0
xor eax, eax
xor r9d, r9d
mov [rsp+30], 0
mov rcx, FileName // full path filename
mov [rsp+28], 80
mov qword ptr [rsp+40], 0 // Bytes written
xor r8d, r8d
lea edx, [r9+4]
mov [rsp+68], al
mov [rsp+20], 4
call CreateFileA
mov rbx, rax
mov r8, FFFFFFFFFFFFFFFF
mov rax, qword ptr [rsp+48]
aloop: // get string length (null terminated)
inc r8
cmp byte ptr [rax+r8], 0
jnz short aloop // loop until end of string
mov byte ptr [rax+r8], 0a // pad linefeed
inc r8 // Length of string
lea r9, [rsp+40]
mov qword ptr [rsp+20], 0
mov rdx, [rsp+48]
mov rcx, rbx
call WriteFile
mov r8, qword ptr [rsp+40]
dec r8
mov rax, qword ptr [rsp+48]
mov byte ptr [rax+r8], 0
mov rcx, rbx
call CloseHandle
add rsp, 80
retn
nop
nop
nop
FileName:
db 'D:\games\myvaluesave.txt',0