Masm32 SDK description, downloads and other helpful links
Started by JK, December 28, 2022, 12:21:43 AM
if 32 bit32 bit code here ...else64 bit code here ...endif
Quoteif 32 bit32 bit code here ...else64 bit code here ...endif
Quote from: hutch-- on December 28, 2022, 01:25:35 AMIt does not sound like much fun though.
Quote from: JK on December 28, 2022, 01:16:41 AMMust i really write two versionsPseudo code:Code Select Expandif 32 bit32 bit code here ...else64 bit code here ...endif ... or is there a more elegant way?
invoke SendMessage, rbx, EM_EXLIMITTEXT, 0, -1 ; no limit invoke SendMessage, rbx, WM_SETFONT, rv(GetStockObject, ANSI_FIXED_FONT), 0
Quote from: JK on December 28, 2022, 12:21:43 AMWhich would be the most elegant way of doing it? I´m looking for a generic solution for this problem, not only for SendMessage but for all cases, where a 32 bit value must be passed to an API or a procdure expecting a 32 bit value in 64 bit and a 64 bit value in 64 bit.
···if TARGET_BITNESS eq 64 XAX textequ <rax> XBX textequ <rbx> XCX textequ <rcx> XDX textequ <rdx> XDI textequ <rdi> XSI textequ <rsi> XBP textequ <rbp> XSP textequ <rsp>else XAX textequ <eax> XBX textequ <ebx> XCX textequ <ecx> XDX textequ <edx> XDI textequ <edi> XSI textequ <esi> XBP textequ <ebp> XSP textequ <esp>endif···
Quotefreg_push / freg_pop: store and retrive GPR from stack.freg_peek retrieve in a GPR last value stored without remotion.7.3.2 Pseudo push/pop variablesfreg_pushv / freg_popv: store and retrive variables from stack.freg_peekv retrieve in a variable last value stored without remotion.These requiere a GPR to move value (by default are EAX and R10 but you can use other).7.3.3 Correctionsfreg_correction is a not so automatic correction for unbalanced number of push/pop. That happen in conditional flow. Must be positive before extra pop and negative before extra push.
QuoteA big problem in code translations from 32 bits to 64 bits it's related to X64 ABI Calling Convention. RCX and RDX have an specific function in 64 bits that ECX and EDX never have in 32 bits.Beside, more simple replacement of registers, like XCX that become ECX in 32 bits and RCX in 64 bits, sometimes result incomplete because 32 bits registers can be used like DWORD or like POINTER, and they are same thing in 32 bits but have differents sizes in 64 bits.But in 64 bits you have more registers. Then this macro make a systematic replace of registers to use exclusive 64 bits registers instead of RCX and RDX, and prefix "__" or "_" declare if register is used like DWORD or POINTER
int 3 jinvoke SendMessage, rbx, WM_SETFONT, rv(GetStockObject, ANSI_FIXED_FONT), 0 nops 2
0040114A |. CC int30040114B |. 6A 0B push 0B0040114D |. FF15 E4444000 call near [4044E4] ; GetStockObject00401153 |. 6A 00 push 000401155 |. 50 push eax00401156 |. 6A 30 push 3000401158 |. 53 push ebx00401159 |. FF15 E0444000 call near [4044E0] ; SendMessage0040115F |. 90 nop00401160 |. 90 nop
1400011FA | CC | int3 |1400011FB | B9 0B000000 | mov ecx,B |140001200 | FF15 AE330000 | call [<&GetStockObject>] |140001206 | 45:33C9 | xor r9d,r9d |140001209 | 4C:8BC0 | mov r8,rax |14000120C | BA 30000000 | mov edx,30 |140001211 | 48:8BCB | mov rcx,rbx |140001214 | FF15 92330000 | call [<&SendMessageA>] |14000121A | 90 | nop |14000121B | 90 | nop |
48:C7C2 30000000 | mov rdx,30BA 30000000 | mov edx,306A 30 | push 305A | pop rdx
invoke SendMessage handle, message, set64(32_bit_variable), set64_signed(32_bit_variable)
Quote from: JK on December 28, 2022, 03:35:07 AM"set64_signed" sign extends "32_bit_variable" in 64 bit code
and rax, 0 ; set to zero mov eax, -123 ; leaves the upper half of rax at zero or rax, 0ffffffff00000000h
and rax, 0 ; set to zero mov eax, -123 ; leaves the upper half of rax at zero .DATA Minus1 dq 0ffffffff00000000h .CODE or rax, Minus1
Quote from: jj2007 on December 28, 2022, 04:39:34 AMUnfortunately, there is no movsx rax, eax
movsxd rax, eax
Quote from: HSE on December 28, 2022, 04:58:13 AMQuote from: jj2007 on December 28, 2022, 04:39:34 AMUnfortunately, there is no movsx rax, eax Code Select Expandmovsxd rax, eax