TL; DR - 1-й код просто показывает, что происходит, прежде чем он действительно начинает делать свое дело. Посмотрите на 2-й код, это то, что делает мой ASM для шифрования строки. Посмотрите на 3-й ящик, он показывает результат. Эки = ч. (код в целом сделан из C ++ и встроенной сборки)
Как я могу вернуть его обратно, чтобы он вернулся к своему «родителю» (исходное состояние, до шифрования).
Итак, я получил ассемблерный код, который шифрует данную строку (тело написано на C ++, простой cin и couts + for loop для цикла каждого символа, ничего серьезного, но вопрос относится к сборке)
Это то, что происходит перед тем, как перейти к процедуре шифрования: (другая функция)
push eax // Push EAX(Ekey) value to the stack
push ecx // Push ECX(character to be encrypted) value to the stack
movzx ecx, temp_char // Copies the contents of the temp_char to the ECX register and zero extends the value.
lea eax, EKey // Load the address of EKey, into EAX
call encrypt // pushes the return address onto the stack and transfers control to a calling label(In this case, it's encrypt).
mov temp_char, al // Copy AL into temp_char variable.
pop ecx // Get value from the top of the stack into ECX.
pop eax // EAX, gets value from the top of the stack.
Моя процедура шифрования выглядит следующим образом: просто уточнить, мои комментарии. Есть большая вероятность, что они верны, или некоторые из них могут быть неправильными. (Извините, я все еще учусь)
push ebp // Save the old base pointer value.
mov ebp, esp // esp; Set the new base pointer value.
sub esp, 12 // Make room for 3 registers
push ebx // Push EBX value to the stack
push edx // Push EDX value to the stack
push ecx // Push ECX(character to be encrypted) value to the stack
movzx edx, byte ptr[eax] // Taking first byte from EAX(Ekey), zero-extending it with 0's , moving that into EDX
and edx, 0x43 // Starting from the most significant bit. EDX will be set to 0x00(zeroed out) if 2nd, 7th and 8th bits are 0's. Otherwise if any bits are 1 within the mask, the resulting value will be non-zero
cmp edx, 0x00 // See if EDX is equal to 0.
jnz x16 // If EDX != 0 go to X16.
mov edx, 0x07 // If EDX will be equal to 0, set EDX value to 0x07..
x16: inc dl // Add one to the 'DL' register. Character variable moves up // DL is 1st byte of EDX.
mov dword ptr[eax], edx // dword 4 bytes, EDX value into EAX(Ekey) and zero extend it to 4 bytes.
pop ebx // Getting value from the top of the stack, and storing it in the EBX.
y16 : dec ebx // Decrement EBX by 1.
dec edx // Decrement EDX by 1.
jnz y16 // If EDX != 0 go to Y16.
not bl // Reverse contents of BL. Such as., (Before 0101, after 1010.) <- Example. So given input will be revesed for encryption purposes. BL, is a 1st byte of EBX.
pop edx // Restores original value of EDX
mov eax, ebx // Move contents from EBX register into EAX(Ekey) register.
pop ebx // Get value from the top of the stack, and then store it in EBX. EAX(Ekey) => EBX.
mov esp, ebp // Deallocate local variables
pop ebp // Restore the caller's base pointer value
ret // Gets address from the top of the stack(In this case it's EBX) and returns the value as result. Returning the final result.
Это то, что он делает со строкой "скоро"
Date: 04/07/2018 Time: 13:53:36
Original string = soon Hex = 73 6f 6f 6e
Encrypted string = ÍÒÓÕ Hex = cd d2 d3 d5
Я потратил неучтенные часы на это, чтобы «повернуть вспять», но мне в голову не пришло ничего важного. Конечным результатом было то, что мне не хватает одной клавиатуры. Я уже посмотрел в Интернете (включая стекопоток), как достичь этой цели, хотя мне это не удалось. Так что это мое последнее прибежище здесь.
Как мне отменить эти инструкции, чтобы вернуть их к исходной строке?