flat assembler
Message board for the users of flat assembler.
Index
> Linux > Use the fword to switch 32/64 bitness mode on the fly |
Author |
|
Furs 23 Feb 2023, 12:51
revolution wrote:
I guess the "correct" way here to do it from 64-bit code is to do your own allocator like Wine does (since it also supports 32-bit on 64-bit processes recently), you'll need to specify the addresses for mmap in this case and handle failure or fragmentation. But I guess allocating it in 32-bit code is easier. |
|||
23 Feb 2023, 12:51 |
|
revolution 23 Feb 2023, 23:16
Using indirect calls allows for going 32-->64-->32 and back.
Code: format elf executable at 1 shl 16 STDOUT_FILENO = 1 SYS32_write = 4 SYS32_exit = 1 SYS64_write = 1 SYS64_exit = 60 CS_TOGGLE = 0x10 ; offset is +-16 entry $ ;initialise call pointers mov eax,cs mov word[print_hello_32+4],ax xor eax,CS_TOGGLE mov word[print_hello_64+4],ax call [print_hello_64] mov eax,SYS32_exit xor ebx,ebx int 0x80 print_hello_32 df 0:_print_hello_32 _print_hello_32: use32 mov eax,SYS32_write mov ebx,STDOUT_FILENO mov ecx,text32 mov edx,len32 int 0x80 retf print_hello_64 df 0:_print_hello_64 _print_hello_64: use64 call [print_hello_32] mov eax,SYS64_write mov edi,STDOUT_FILENO lea rsi,[text64] mov edx,len64 syscall retfd text32 db 'Hello from 32-bit code!',10 len32 = $ - text32 text64 db 'Hello from 64-bit code!',10 len64 = $ - text64 |
|||
23 Feb 2023, 23:16 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.