2015-08-09 101 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個額外的彈出窗口。