我继承的一个最近的 Delphi 项目在 ASM 中有一个过程。我是一个完整的 ASM 新手,所以我不明白。我已经阅读了各种 ASM 指令以尝试破译程序流程,但我仍然不明白。
有 ASM 经验的人可以帮助我理解并将以下过程翻译成英文(然后我可以翻译回 Delphi,这样代码将来更容易阅读!!!)
Mem1的声明是一个Byte数组[0..15];. 并且Mem2 是 LongInt。
这是程序:
procedure TForm1.XorMem(var Mem1; const Mem2; Count : Cardinal); register;
begin
asm
push esi
push edi
mov esi, eax //esi = Mem1
mov edi, edx //edi = Mem2
push ecx //save byte count
shr ecx, 2 //convert to dwords
jz @Continue
cld
@Loop1: //xor dwords at a time
mov eax, [edi]
xor [esi], eax
add esi, 4
add edi, 4
dec ecx
jnz @Loop1
@Continue: //handle remaining bytes (3 or less)
pop ecx
and ecx, 3
jz @Done
@Loop2: //xor remaining bytes
mov al, [edi]
xor [esi], al
inc esi
inc edi
dec ecx
jnz @Loop2
@Done:
pop edi
pop esi
end;
end;
编辑:感谢 Roman R,我已将 ASM 转换回 Delphi
procedure TForm1.XorMem2(var Mem1; const Mem2 :LongInt; Count : Cardinal);
var
Key : array [0..3] of byte absolute Mem1;
Num : array [0..3] of byte absolute Mem2;
idx : byte;
begin
for Idx := 0 to Count -1 do Key[idx] := Key[idx] Xor Num[idx];
end;