240088 Assembly to PHP Translation

  • Status Closed
  • Budget N/A
  • Total Bids 1

Project Description

I have two functions written in Inline Assembly. These functions are Encrypt and Decrypt. It should be fairly simple to design two functions in PHP.

static UCHAR Decrypted[] = "Richards";

static UCHAR Encrypted[0x0008] =

{

0xAC,0x8F,0xDA,0xCD,0x93,0x32,0x08,0x25

};

static UCHAR PrivateKey[0x0080] =

{

0xF2,0x69,0x5E,0x41,0xC7,0x20,0x1C,0x65,0x35,0xF3,0x2D,0xA1,0x70,0x06,0xBA,0xFC,

0xA0,0xEF,0xB9,0x50,0x02,0x6F,0x99,0x6F,0x2A,0xB2,0x8E,0x98,0xAC,0x16,0x7A,0x0C,

0x0A,0xC9,0x01,0x2B,0x06,0x93,0xF5,0xCF,0x4C,0x69,0x62,0x69,0x73,0xFB,0x8B,0x34,

0x13,0x4D,0x3D,0x90,0xDE,0x4A,0x19,0xAF,0x03,0xDF,0xAB,0x22,0x57,0xD5,0xBF,0xA0,

0xB7,0x38,0x42,0x45,0x32,0x30,0x61,0x73,0x74,0x34,0x73,0x69,0x35,0x6C,0x73,0x32,

0x37,0xF3,0x2E,0xBA,0x91,0xC0,0xC6,0x05,0x90,0x45,0x23,0x8C,0x4E,0x58,0xC5,0x11,

0xE9,0x24,0xE3,0xB1,0xD5,0xA8,0xCF,0x9E,0x8F,0x80,0xDC,0x61,0x29,0xAC,0x76,0x48,

0x44,0x31,0x33,0x27,0x26,0x27,0xBC,0xCD,0x7F,0x0D,0x08,0xC8,0xFE,0x11,0xD5,0xFD

};

__stdcall Decryption( LPVOID Encrypted, LPVOID PrivateKey )

{

__asm{

sub esp,18h

mov eax,[esp+1Ch] // ->Encrypted String

push ebp

push ebx

push esi

push edi

mov si,[eax+00h]

mov dx,[eax+02h]

mov cx,[eax+04h]

mov ax,[eax+06h]

mov edi,[esp+30h] // ->PrivateKey

mov [esp+18h],esi

mov [esp+1Ch],edx

lea ebp,[edi+7Ch]

mov [esp+14h],ecx

mov [esp+10h],eax

mov dword ptr [esp+24h],0000000Fh // 16 loops

mov [esp+20h],ebp

mov di,ax

mov bx,cx

_004A18A5:

mov ebp,[esp+20h]

shl eax,0Bh

shr di,05h

or eax,edi

mov edi,ecx

not edi

and edi,esi

sub eax,edi

mov edi,ecx

and edi,edx

sub eax,edi

mov edi,edx

sub ax,[ebp+02h]

shl ecx,0Dh

shr bx,03h

not edi

or ecx,ebx

and edi,eax

sub ecx,edi

mov edi,edx

and edi,esi

mov [esp+10h],eax

sub ecx,edi

mov edi,edx

mov dx,[esp+1Ch]

sub cx,[ebp+00h]

shl edi,0Eh

shr dx,02h

or edi,edx

mov edx,esi

not edx

and edx,ecx

mov [esp+14h],ecx

sub edi,edx

mov edx,eax

and edx,esi

sub edi,edx

sub di,[ebp-02h]

mov edx,edi

mov edi,esi

mov si,[esp+18h]

mov [esp+1Ch],edx

shl edi,0Fh

shr si,1

or edi,esi

mov esi,eax

not esi

and esi,edx

sub edi,esi

mov esi,eax

and esi,ecx

sub edi,esi

sub di,[ebp-04h]

mov ebp,[esp+24h]

mov esi,edi

mov [esp+18h],esi

cmp ebp,0Bh

jz _004A1944 // First Loop

cmp ebp,05h // [ESP+10h] = 95B56701

jnz _004A1998 // [ESP+14h] = C796D77E

// [ESP+18h] = B065F692

_004A1944: // [ESP+1Ch] = A7559FB4

mov di,[esp+10h] // [ESP+20h] = Pointer to Last DWORD of PrivateKey

mov bx,[esp+14h] // [ESP+24h] = 0x0000000F - Loop Counter

mov eax,ecx

mov ecx,[esp+30h]

and eax,3Fh

and edx,3Fh

and esi,3Fh

sub di,[eax*2+ecx]

sub bx,[edx*2+ecx]

mov dx,[esi*2+ecx]

sub [esp+1ch],dx

mov [esp+10h],di

mov eax,[esp+10h]

mov [esp+14h],bx

mov edx,eax

and edx,3Fh

mov cx,[edx*2+ecx]

mov edx,[esp+1Ch]

sub [esp+18h],cx

mov ecx,[esp+14h]

mov esi,[esp+18h]

jmp _004A19A2

_004A1998:

mov di,[esp+10h]

mov bx,[esp+14h]

_004A19A2:

dec ebp

mov [esp+24h],ebp

mov ebp,[esp+20h]

sub ebp,08h

mov [esp+20h],ebp

mov ebp,[esp+24h]

test ebp,ebp

jge _004A18A5 // 16 loops

mov eax,[esp+2Ch]

mov dx,[esp+18h]

mov cx,[esp+1Ch]

mov [eax+06h],di

mov [eax+04h],bx

mov [eax+02h],cx

mov [eax+00h],dx

pop edi

pop esi

pop ebx

pop ebp

add esp,18h

ret 0008h

}

return true;

}

__stdcall Encryption( LPVOID Decrypted, LPVOID PrivateKey )

{

__asm{

push ebp

push ebx

push ecx

push esi

push edi

mov eax,[esp+08h]

mov cx,[eax+00h]

mov dx,[eax+02h]

mov si,[eax+04h]

mov di,[eax+06h]

mov eax,[esp+1Ch]

mov dword ptr [esp+10h],00000000h

lea ebx,[eax+04h]

_004A1777:

mov eax,edi

mov ebp,edi

not eax

and eax,edx

and ebp,esi

add eax,ebp

mov ebp,edi

add ax,[ebx-04h]

add ecx,eax

mov ax,cx

add ecx,ecx

shr ax,0Fh

or ecx,eax

mov eax,ecx

and ebp,ecx

not eax

and eax,esi

add eax,ebp

add ax,[ebx-02h]

add edx,eax

mov ax,dx

shr ax,0Eh

shl edx,02h

or edx,eax

mov ebp,edx

mov eax,edx

not ebp

and ebp,edi

and eax,ecx

add esi,ebp

add eax,esi

add ax,[ebx]

mov si,ax

shr si,0Dh

shl eax,03h

or esi,eax

mov eax,esi

mov ebp,esi

not eax

and eax,ecx

and ebp,edx

add eax,ebp

add ax,[ebx+02h]

add eax,edi

mov edi,eax

shl edi,05h

shr ax,0Bh

or edi,eax

mov eax,[esp+10h]

cmp eax,04h

jz _004A17FA

cmp eax,0Ah

jnz _004A182E

_004A17FA:

mov eax,[esp+1Ch]

mov ebp,edi

and ebp,3Fh

mov bp,[ebp*2+eax]

add ecx,ebp

mov ebp,ecx

and ebp,3Fh

mov bp,[ebp*2+eax]

add edx,ebp

mov ebp,edx

and ebp,3Fh

mov bp,[ebp*2+eax]

add esi,ebp

mov ebp,esi

and ebp,3Fh

mov ax,[ebp*2+eax]

add edi,eax

mov eax,[esp+10h]

_004A182E:

inc eax

add ebx,08h

cmp eax,0Fh

mov [esp+10h],eax

jle _004A1777

mov eax,[esp+18h]

mov [eax+06h],di

mov [eax+04h],si

mov [eax+02h],dx

mov [eax+00h],cx

pop edi

pop esi

pop ecx

pop ebx

pop ebp

ret 0008h

}

return true;

}

Get free quotes for a project like this
Awarded to:
Skills Required

Looking to make some money?

  • Set your budget and the timeframe
  • Outline your proposal
  • Get paid for your work

Hire Freelancers who also bid on this project

    • Forbes
    • The New York Times
    • Time
    • Wall Street Journal
    • Times Online