Форумчанин
Регистрация: 22.05.2009
Сообщений: 248
|
Delphi XE2 x64 asm написанная под x32 преобразование к x64
Есть такая функция procedure EnCipher(var Source: AnsiString),
источник http://delphiworld.narod.ru/base/encode_s_coder.html
Для приложения в Delphi XE2 x64, попробовал преобразовать, чтобы работало в нем:
Код:
procedure EnCipher(var Source: AnsiString)
{Low order, 7-bit ASCII (char. 32-127) encryption designed for database use.
Control and high order (8 bit) characters are passed through unchanged.
Uses a hybrid method...random table substitution with bit-mangled output.
No passwords to worry with (the built-in table is the password). Not industrial
strength but enough to deter the casual hacker or snoop. Even repeating char.
sequences have little discernable pattern once encrypted.
NOTE: When displaying encrypted strings, remember that some characters
within the output range are interpreted by VCL components
example, '&'.}
asm
Push RSI //Save the good stuff
Push RDI
Or RAX,RAX
Jz @Done
Push RAX
Call UniqueString
Pop RAX
Mov RSI,[RAX] //String address into ESI
Or RSI,RSI
Jz @Done
Mov RCX,[RSI-4] //String Length into ECX
Jrcxz @Done //Abort on null string
Mov RDX,RCX //initialize EDX with length
Lea RDI,@ECTbl //Table address into EDI
Cld //make sure we go forward
@L1:
Xor RAX,RAX
Lodsb //Load a byte from string
Sub AX,32 //Adjust to zero base
Js @Next //Ignore if control char.
Cmp AX,95
Jg @Next //Ignore if high order char.
Mov AL,[RDI+RAX] //get the table value
Test CX,3 //screw it up some
Jz @L2
Rol RDX,3
@L2:
And DL,31
Xor AL,DL
Add RDX,RCX
Add RDX,RAX
Add AL,32 //adjust to output range
Mov [RSI-1],AL //write it back into string
@Next:
Dec RCX
Jnz @L1
// Loop @L1 //do it again if necessary
@Done:
Pop RDI
Pop RSI
Jmp @Exit
// Ret //this does not work with Delphi 3 - EFD 971022
@ECTbl: //The encipher table
DB 75,85,86,92,93,95,74,76,84,87,91,94
DB 63,73,77,83,88,90,62,64,72,78,82,89
DB 51,61,65,71,79,81,50,52,60,66,70,80
DB 39,49,53,59,67,69,38,40,48,54,58,68
DB 27,37,41,47,55,57,26,28,36,42,46,56
DB 15,25,29,35,43,45,14,16,24,30,34,44
DB 06,13,17,23,31,33,05,07,12,18,22,32
DB 01,04,08,11,19,21,00,02,03,09,10,20
@Exit:
end
P.S. Плохо знаю ассемблер, что требуется учесть в преобразовании к x64 еще, чтобы работало? То есть заменил EDI - RDI, ESI -RSI, ECX - RCX и так далее.
|