Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

assembly - How to push a 64bit int in NASM?

I'm trying to push a 64bit integer but when assembling NASM seems to want to see it as a DWORD not a QWORD.

I'm using ASM to create the shellcode I need to inject a 64bit DLL into a 64bit process. The first QWORD is the old instruction pointer, the second is the address containing the address of the DLL, the third is the address of LoadLibrary. The placeholders are filled in at runtime.

section .text
global _start   

_start:
BITS 64
PUSH QWORD 0xACEACEACACEACEAC
PUSHFQ
push rax
PUSH QWORD 0xACEACEACACEACEAC
MOV RAX, 0xACEACEACACEACEAC
CALL RAX
pop RAX
POPFQ
RETN
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is no push imm64 instruction. As a workaround you can do one of the following:

  1. go through a register: mov rax, 0xACEACEACACEACEAC; push rax
  2. go through memory: push qword [rel foo]
  3. write it in two parts: push dword low32; mov dword [rsp+4], high32 or sub rsp,8; mov dword [rsp], low32; mov dword [rsp+4], high32
  4. use sign-extension if your immediate allows it

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...