Hi
I finally have some time to experiment a bit with this idea.
It wasn't as hard as I expected as most of the parts already existed.
The macro I call PrintF supports format specifiers used to interpret the passed varargs, as well as escape sequences to use non-printable characters or MASM special characters.
The documentation as well as the code can be found in the attached file.
ObjAsm users will find the macro in the System.inc file.
Example:
lea xdi, cBuffer
mov CHR ptr [xdi], 0
mov xsi, 12345678h
PrintF xdi, 'The content at memory location ¦HXh is ¦F3 ml ¦ST', xsi, $CReal4(1.23), $OfsCStr("(current reading)")
DbgStr cBuffer
lea xdi, cBuffer
PrintF xdi, "Memory at \[¦HXh\]: ¦EB", xsi, $CReal8(1.23456789123456789)
DbgStr cBuffer
Result:
cBuffer = The content at memory location 12345678h is 1.230 ml (current reading)
cBuffer = Memory at <12345678h>: 1.23456789123E+0000
The code generated runs much faster than a printf call because it is tailored by the macro for this specific case.
In this case, the code for ANSI characters in 64-bit looks like this:
lea rdi,[cBuffer]
mov byte ptr [rdi],0
mov rsi,12345678h
mov dword ptr [rdi],20656854h
mov dword ptr [rdi+4],746E6F63h
mov dword ptr [rdi+8],20746E65h
mov dword ptr [rdi+0Ch],6D207461h
mov dword ptr [rdi+10h],726F6D65h
mov dword ptr [rdi+14h],6F6C2079h
mov dword ptr [rdi+18h],69746163h
mov word ptr [rdi+1Ch],6E6Fh
mov byte ptr [rdi+1Eh],20h
add rdi,1Fh
mov rcx,rdi
mov rdx,rsi
call qword2hexA (07FF79E371880h)
add rdi,10h
mov dword ptr [rdi],73692068h
mov byte ptr [rdi+4],20h
add rdi,5
fld dword ptr [CR4_P1p23 (07FF79E373728h)]
mov rcx,rdi
xor edx,edx
mov r8d,3
xor r9d,r9d
call St0ToStrA (07FF79E3714B0h)
fstp st(0)
mov rcx,rdi
call StrLengthA (07FF79E371460h)
lea rdi,[rdi+rax]
mov dword ptr [rdi],206C6D20h
add rdi,4
mov rcx,rdi
mov rdx,7FF79E373730h
call StrCopyA (07FF79E371480h)
mov rcx,rdi
call StrLengthA (07FF79E371460h)
lea rdi,[rdi+rax]
mov byte ptr [rdi],0
Biterider