Assembly 这个代码是做什么的?德尔福asm

Assembly 这个代码是做什么的?德尔福asm,assembly,Assembly,我试图解析加密的&RQ历史记录,但我真的无法理解asm代码。它被嵌入到Delphi函数中 有人能帮我理解吗 procedure decritt(var s:string; key:integer); asm mov ecx, key mov dl, cl shr ecx, 20 mov dh, cl mov esi, s mov esi, [esi] or esi, esi // nil string jz @OUT // now esi points to th

我试图解析加密的&RQ历史记录,但我真的无法理解asm代码。它被嵌入到Delphi函数中

有人能帮我理解吗

procedure decritt(var s:string; key:integer);
 asm
 mov ecx, key
 mov dl, cl
 shr ecx, 20
 mov dh, cl

 mov esi, s
 mov esi, [esi]
 or  esi, esi    // nil string
 jz  @OUT

// now esi points to the first character of the string

 mov ah, 10111000b

 mov ecx, length(s)
 or  ecx, ecx
 jz  @OUT
@IN:
 mov al, [esi]
 xor al, ah
 rol al, 3
 xor al, dh
 sub al, dl

 mov [esi], al
 inc esi
 ror ah, 3
 dec ecx
 jnz @IN
@OUT:
 end; // decritt

谢谢。

< P>此C++代码将是等价的:

void encrypt(std::string s, int key) {

    const char dl = key;
    const char dh = key >> 20;
    char ah = 0xB8;

    for (int i=0; i<s.length(); ++i) {
        char c = s[i];
        c ^= ah;
        c = (c<<3)|(c>>5); // rotate a char three bits left
        c ^= dh;
        c -= dl;
        s[i] = c;
        ah = (ah>>3)|(ah<<5);
    }
}
void加密(std::string s,int key){
const char dl=键;
const char dh=键>>20;
字符ah=0xB8;

对于(inti=0;i>3)|(啊Yay),我终于让它工作了。下面是生成的python代码:

def decrypt(self, string, key):
    decrypted = []

    dl = key & 0xffff
    dh = key >> 20
    ah = 0xb8

    for i in xrange(0, len(string)):
        c = ord(string[i])
        c ^= ah & 0xff
        c = ((c<<3)|(c>>5)) & 0xff
        c ^= dh & 0xff
        c = (c - dl) & 0xff

        decrypted.append(chr(c & 0xff))
        ah = ((ah>>3)|(ah<<5)) & 0xff

    return "".join(decrypted)
def解密(self、string、key):
解密=[]
dl=键&0xffff
dh=键>>20
ah=0xb8
对于x范围内的i(0,len(字符串)):
c=ord(字符串[i])
c^=ah&0xff
c=((c5))&0xff
c^=dh&0xff
c=(c-dl)&0xff
解密的.append(chr(c&0xff))

ah=((ah>>3)|(ah汇编函数接受一个加密字符串和解密密钥。对密钥使用一些固定的数学运算,它可以解密字符串。我发现了一个Delphi示例,它做了同样的操作,但更简单


如果需要,您可以将ekini的Python代码转换为Delphi,以去除Delphi应用程序中的asm代码。

它看起来不错,但不起作用。不知道为什么。密钥是300109517,生成的字符串应该是“hello world”,加密字符串是“\xdd\x92\x06\xb8\xcf\x0f\x65\x81\x9c\xf3\x07”你可以用一个调试器进行一两次迭代,然后观察它们的值,啊,看看它们的值是否与我的C程序中同名变量的值匹配。