2015-08-09 108 views
1

以下汇编代码的结果是什么?对数和指数,这个汇编代码是做什么的?

fld qword ptr [address2] 
fld qword ptr [address1] 
fldl2e 
fmulp ST(1),ST 
fld ST(0) 
frndint 
fxch ST(1) 
fsub ST,ST(1) 
f2xm1 
fld1 
faddp ST(1),ST 
fscale 

在这里,我不明白这段代码在做什么。我已经解释是如下:

value[address2]^(2^(value[address1]*log2(e)-roundf(value[address1]*log2(e))))

这是没有意义的。有人能纠正我吗?

回答

3

下次请在反汇编旁边张贴您尝试的评论。把所有东西都打出来看看我是否和你在同一个地方会花费很长时间。另外,我通常不会看到整个stackexchange for reverse engineering.,但那里有一些优秀的x86专家。

比方说v1 = contents of addr1v2 = ... [addr2]

fld qword ptr [address2] ; st(0) = v2 
fld qword ptr [address1] ; st(0) = v1, st(1) = v2 
fldl2e      ; st0 = l2e = log_2(e); st1=v1 st2=v2 
fmulp ST(1),ST   ; st0 = v1*l2e; st2=v2 
fld ST(0)     ; st0 = v1*l2e; st1=v1*l2e st2=v2 
frndint     ; st0 = round(v1*l2e); st1=v1*l2e st2=v2 
fxch ST(1)    ; st0 = v1*l2e; st1=round(v1*l2e) st2=v2 
; careful here, this is fsub, NOT fsubp 
fsub ST,ST(1)   ; st0 = v1*l2e - round(v1*l2e) = fractional part of v1*l2e = v1l2efrac; st1=round(v1*l2e) st2=v2 
f2xm1      ; st0 = 2^(v1l2efrac)-1; st1=round(v1*l2e) st2=v2 
fld1      ; st0 = 1.0; st1 = 2^(v1l2efrac)-1 st2=round(v1*l2e) st3=v2 
faddp ST(1),ST   ; st0 = 1.0 + 2^(v1l2efrac)-1 = 2^v1l2efrac; st1=round(v1*l2e) st2=v2 
    ; st0 = 2^v1l2efrac; st1=round(v1*l2e); st2=v2 
fscale     ; st0 = 2^v1l2efrac * 2^round(v1*l2e); st1=round(v1*l2e) st2=v2 
    ; st0 = 2^(v1l2efrac + round(v1*l2e)); st1=round(v1*l2e) st2=v2 
    ; simplify: fractional part + integer part = whole 
    ; st0 = 2^(v1*l2e); st1=round(v1*l2e) st2=v2 
    ; simplify: x^y = 2^(y * log2(x)) 
    ; st0 = e^v1;  st1=round(v1*l2e) st2=v2 

所以最后,st(0) = e^[address1],其他2个值仍然在FP堆栈上。 (FP堆栈其余部分的内容以及它的深度是您分析时忽略的一个重点,FP堆栈的压入和弹出必须平衡(除了在st(0)中留下返回值),以便可以用作检查您是否正确地跟踪了一段代码。)

AFAICT,v2保留在FP堆栈的最后,并且在计算中未使用。看起来您的跟踪中有2个额外的弹出窗口。