问题描述
因此,我试图在x64中实现,以在运行时确定参数数量和类型的函数来实现该功能,但由于未通过测试用例,因此我似乎未处理堆栈参数。这是masm中的代码:
PUBLIC makeuniquecall
.data
makeuniquecall_jmp_table dq zero_zero,one_zero,two_zero,three_zero ; ordinary
makeuniquecall_jmp_table_one dq zero_one,one_one,two_one,three_one ; single precision
makeuniquecall_jmp_table_two dq zero_two,one_two,two_two,three_two ; double precision
.code
makeuniquecall PROC
;rcx - function pointer
;rdx - raw argument data
;r8 - a byte array specifying each register parameter if it's float and the last qword is the size of the rest
push r12
push r13
push r14
mov r12,rcx
mov r13,rdx
mov r14,r8
; first store the stack vars
mov rax,[r14 + 4] ; retrieve size of stack
sub rsp,rax
mov rdi,rsp
xor rdx,rdx
mov r8,8
div r8
mov rcx,rax
mov rsi,r13
add rsi,32
rep movs qword ptr [rdi],qword ptr [rsi] ; here somehow the 5th parameter is not correctly trasnfered
xor r10,r10
cycle:
mov rax,r14
add rax,r10
movzx rax,byte ptr [rax]
test rax,rax
jnz jmp_one
lea rax,makeuniquecall_jmp_table
jmp qword ptr[rax + r10 * 8]
jmp_one:
cmp rax,1
jnz jmp_two
lea rax,makeuniquecall_jmp_table_one
jmp qword ptr[rax + r10 * 8]
jmp_two:
lea rax,makeuniquecall_jmp_table_two
jmp qword ptr[rax + r10 * 8]
zero_zero::
mov rcx,qword ptr[r13+r10*8]
jmp continue
one_zero::
mov rdx,qword ptr[r13+r10*8]
jmp continue
two_zero::
mov r8,qword ptr[r13+r10*8]
jmp continue
three_zero::
mov r9,qword ptr[r13+r10*8]
jmp continue
zero_one::
movss xmm0,dword ptr[r13+r10*8]
jmp continue
one_one::
movss xmm1,dword ptr[r13+r10*8]
jmp continue
two_one::
movss xmm2,dword ptr[r13+r10*8]
jmp continue
three_one::
movss xmm3,dword ptr[r13+r10*8]
jmp continue
zero_two::
movsd xmm0,qword ptr[r13+r10*8]
jmp continue
one_two::
movsd xmm1,qword ptr[r13+r10*8]
jmp continue
two_two::
movsd xmm2,qword ptr[r13+r10*8]
jmp continue
three_two::
movsd xmm3,qword ptr[r13+r10*8]
continue:
inc r10
cmp r10,4
jb cycle
mov r14,[r14 + 4] ; retrieve size of stack
call r12
add rsp,r14
pop r14
pop r13
pop r12
ret
makeuniquecall ENDP
END
这是我的测试用例:
int functiontest(double a0,float a1,char* a2,wchar_t* a3,double a4)
{
printf("%d %f %s %ls %d",a0,a1,a2,a3,a4);
}
main()
{
#pragma pack(push,1)
struct { char data[4]; size_t stack; } footprint = { {2,1,0},sizeof (double) };
#pragma pack(pop)
makeuniquecall(functiontest,(struct { double m0; float m1; char* m2,* m3; double m4; }) {
3.66,3.66,"3.66",L"3.66",3.77
},& footprint);
}
似乎第五个参数(a4
)不是我最初传递的-3.77-为什么有任何想法?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)