c++ - Storing EAX register in a variable -


i working on bonus assignment class in have rip out keygen executable , use __asm directive in c++ straight insert assembly code (with little editing).

the result follows:

int main(int argc, char** argv) {      char username[] = "username";     int sernum;      __asm {          lea edx, [username];              //put user name in edx          lea eax, dword ptr[edx];          //put user name in eax         lea ebx, dword ptr[username + 1]; // put "sername" in ebx         mov ecx, 0x00000000;              // random initializing         mov ebp, 0x00000000;         mov esi, 0x00000000;         mov edi, 0x00000000;      count_loop:;          mov cl, byte ptr ds : [eax];     // code length of user name         inc eax;         test cl, cl;         jnz short count_loop;          sub eax, ebx;         mov ebx, eax;         sar ebx, 1;         movsx ebp, byte ptr ds : [ebx + edx];         imul ebp, ebp, 0x3e8;         xor eax, eax;          cmp ebx, 2;         jl short skip_jump;          mov edi, edi;      gen_loop:;          movsx ecx, byte ptr ds : [edx + eax];        //generate key somehow         lea ecx, dword ptr ds : [ecx + ecx * 4];         lea esi, dword ptr ds : [esi + ecx * 2];         movsx ecx, byte ptr ds : [edx + eax + 1];         lea ecx, dword ptr ds : [ecx + ecx * 4];         lea edi, dword ptr ds : [edi + ecx * 2];         add eax, 2;         lea ecx, dword ptr ds : [ebx - 1];         cmp eax, ecx;         jl short gen_loop;      skip_jump:;          cmp eax, ebx;         jge short odd_skip;         movsx eax, byte ptr ds : [eax + edx];         lea edx, dword ptr ds : [eax + eax * 4];         lea ebp, dword ptr ss : [ebp + edx * 2];      odd_skip:;          lea eax, dword ptr ds : [edi + esi];         add eax, ebp;                                  // store final key in eax     }; } 

the problem need contents of eax now. not sure how store eax in variable. ideas? have never worked assembly , told wouldn't have know how use it. think lied us....

a common function calling convention x86 cdecl, function's integral return value saved in eax register. example, simple assembly function can be:

#include "stdio.h"  int f() {     __asm     {         mov eax, 42 // setting eax 42 here     } }  int main() {     int = f();     printf("%i\n", i);      return 0; } 

what have appears intel syntax, might want compile inline assembly -masm=intel flag.

compiling visual studio on windows 10 64 bit, , running executable produce in terminal:

42 

the original f() functionally equivalent (as far can tell):

int f() {     return 42; } 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -