assembly conversion to basm

519 Views Asked by At

I'm trying to convert the CrapWOW Hash from http://www.team5150.com/~andrew/noncryptohashzoo/CrapWow.html to delphi or rather to basm. My asm skills are very limited, but i thought it wouldn't be too hard...

Anyway, with help of some webpages about asm conversion, I came to this, but it don't work... Especially, for the last part I have no Idea how to convert. Is this an assignment of the registers to the parameters and the return parameter?

function CrapWow(key: PAnsiChar; len, seed: Cardinal): Cardinal;
//finline u32 fastcall CrapWow( const u8 *key, u32 len, u32 seed ) {
// #if !defined(__LP64__) && !defined(_MSC_VER) && ( defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) )
// // esi = k, ebx = h
//  u32 hash;
//  asm(
asm
  lea esi, 5052acdbh[ecx+esi] //leal 0x5052acdb(%ecx,%esi), %esi
  mov ebx, ecx                //movl %ecx, %ebx
  cmp ecx, 8                  //cmpl $8, %ecx
  jb @DW

@QW:                        //QW%=:
  mov eax, 5052acdbh          //movl $0x5052acdb, %eax
  mul [edi]                   //mull (%edi)                  << CRASH HERE
  add ecx, -8                 //addl $-8, %ecx
  xor ebx, eax                //xorl %eax, %ebx
  xor esi, edx                //xorl %edx, %esi
  mov eax, 57559429h          //movl $0x57559429, %eax
  mul 4[edi]                  //mull 4(%edi)
  xor esi, eax                //xorl %eax, %esi
  xor ebx, edx                //xorl %edx, %ebx
  add edi, 8                  //addl $8, %edi
  cmp ecx, 8                  //cmpl $8, %ecx
  jae @QW                     //jae QW%=

@DW:                        //DW%=:
  cmp ecx, 4                  //cmpl $4, %ecx
  jb @B                       //jb B%=
  mov eax, 5052acdbh          //movl $0x5052acdb, %eax
  mul [edi]                   //mull (%edi)
  add edi, 4                  //addl $4, %edi
  xor ebx, eax                //xorl %eax, %ebx
  add ecx, -4                 //addl $-4, %ecx
  xor esi, edx                //xorl %edx, %esi

@B:                         //B%=:
  test ecx, ecx               //testl %ecx, %ecx
  jz @F                       //jz F%=
  shl ecx, 3                  //shll $3, %ecx
  mov edx, 1                  //movl $1, %edx
  mov eax, 57559429h          //movl $0x57559429, %eax
  shl edx, cl                 //shll %cl, %edx
  add edx, -1                 //addl $-1, %edx
  and edx, [edi]              //andl (%edi), %edx
  mul edx                     //mull %edx
  xor esi, eax                //xorl %eax, %esi
  xor ebx, edx                //xorl %edx, %ebx

@F:                         //F%=:
  lea edx, 5052acdbh[esi]     //leal 0x5052acdb(%esi), %edx
  xor edx, ebx                //xorl %ebx, %edx
  mov eax, 5052acdbh          //movl $0x5052acdb, %eax
  mul edx                     //mull %edx
  xor eax, ebx                //xorl %ebx, %eax
  xor esi, edx                //xorl %edx, %esi
  xor eax, esi                //xorl %esi, %eax

//No idea how to convert this...
//    : =a(hash), =c(len), =S(len), =D(key)
//    : c(len), S(seed), D(key)
//    : %ebx, %edx, cc
//  );
//  return hash;}
end;

I would be very glad to have some help on this.

knight_killer

2

There are 2 best solutions below

0
On

It looks EDI is used before being initialized. It seems to happen later with other registers as well. You should check how those registers are set by the original code compiler on entering the procedure code, and check you've copied it correctly. Looks also at comments to your question.

0
On

Yes ..It looks EDI is used before being initialized , you shuld pass len parametr by using pointer .. since you are using "mul [edi] " instruction .