Hello there !
Can someone help me to translate 3 functions from
c to asm ??????
These are the functions :
void boot_chksum(byte * data, word size, dword * chksum, byte * shift)
{
word i;
for (i = 0; i < size; i++) {
*chksum += data << *shift;
(*shift)++;
*shift %= 0x0D;
}
}
void boot_chksum_all(byte * data, word size, word * chksum)
{
byte x;
dword i;
*chksum = 0;
for (i = 0; i < 0x3FFFE; i++) {
x = i < size ? data : -1;
*chksum += i & 1 ? x << 8 : x;
}
}
dword boot_crypt_sub(dword * buffer)
{
word i, carry = 0;
dword s1, s2, s3, x, out = 0;
for (i = 0; i < 8; i++) {
x = buffer + (buffer << 4) + (buffer << 5) + (buffer << 6) + carry;
carry = x >> 20;
x &= 0xFFFFF;
buffer = x;
out += x;
}
return out;
}
Thanx for reading this... :alright:
Can someone help me to translate 3 functions from
c to asm ??????
These are the functions :
void boot_chksum(byte * data, word size, dword * chksum, byte * shift)
{
word i;
for (i = 0; i < size; i++) {
*chksum += data << *shift;
(*shift)++;
*shift %= 0x0D;
}
}
void boot_chksum_all(byte * data, word size, word * chksum)
{
byte x;
dword i;
*chksum = 0;
for (i = 0; i < 0x3FFFE; i++) {
x = i < size ? data : -1;
*chksum += i & 1 ? x << 8 : x;
}
}
dword boot_crypt_sub(dword * buffer)
{
word i, carry = 0;
dword s1, s2, s3, x, out = 0;
for (i = 0; i < 8; i++) {
x = buffer + (buffer << 4) + (buffer << 5) + (buffer << 6) + carry;
carry = x >> 20;
x &= 0xFFFFF;
buffer = x;
out += x;
}
return out;
}
Thanx for reading this... :alright:
I like the practice in seeing C code as ASM, but I'll leave the rest to you. I have removed the call by reference crap and returned the relevant data in registers:
boot_chksum PROC uses ebx esi edi, bcDATA:DWORD, bcSIZE:DWORD, chksum:DWORD, shift:DWORD
mov edi,chksum
xor ebx,ebx ; i
mov esi,bcDATA
mov edx,shift ; initial shift
@@: mov ecx,edx
movzx eax,byte ptr [esi + ebx]
shl eax,cl
add edi,eax
inc edx
mov eax,edx
cdq
mov ecx,13
div ecx
inc ebx
cmp ebx,bcSIZE
jne @B
mov eax,edi ; chksum
; edx is new shift value
; all other data unchanged
ret
boot_chksum ENDP
This is certainly not optimal - just a couple minutes of typing, but it's better than VC++ came up with - f0dder knows how to improve that output. ;)thanx for helping me bitRAKE !
I succesfuly translated the other functions but
i'm not having any luck with boot_crypt_sub.
Please help me with this ... Please, please, please !!!
bye :stupid:
I succesfuly translated the other functions but
i'm not having any luck with boot_crypt_sub.
Please help me with this ... Please, please, please !!!
bye :stupid:
Why do you not post your attempt?
Please, do so in the future.
Replace all the undefined labels with registers and this proc might work?
Please, do so in the future.
Replace all the undefined labels with registers and this proc might work?
boot_crypt_sub PROC uses ebx esi edi,buffer:DWORD
mov _buffer,buffer
xor _i,_i
xor carry,carry
xor _out,_out
@@: mov eax,[_buffer + _i * 4]
mov _x,eax
shl eax,4 ; all this shift adds can be replaced with one mul ;)
add _x,eax
shl eax,1
add _x,eax
shl eax,1
add _x,eax
add _x,carry
mov carry,_x
shr carry,20
and _x,0FFFFFh
mov [_buffer + _i * 4],_x
add _out,_x
inc _i
cmp _i,8
jne @B
mov eax,_out
ret
boot_crypt_sub ENDP