Reverse Engineering Asked by bahar on August 2, 2021
I want to calculate CRC32 for Delphi mt38 and found the below assembly algorithm and converted it to C. It seems that this algorithm is defined for n = 256 or 1024. I want to calculate CRC32 for n = 1638400 and expect to get CRC32 = 0xFB6568AF for input data = {0}, but it doesn’t give the expected answer. How can I calculate it?
Thank you in advance.
The assembly algorithm:
CheckSum: ; CODE XREF: sub_CDBA6
movh.a a15, #@HIS(CKS_loop_count)
lea a15, [a15]@LOS(CKS_loop_count)
ld.b d15, [a15]0
jz16 d15, loc_CE256
mov32 d14, #0x100
j16 loc_CE25A
; ---------------------------------------------------------------------------
loc_CE256: ; CODE XREF: CheckSum
mov32 d14, #0x400
loc_CE25A: ; CODE XREF: CheckSum
mov16 d13, #0
movh.a a14, #@HIS(table_address)
lea a14, [a14]@LOS(table_address)
j16 loc_CE2FA
; ---------------------------------------------------------------------------
loc_CE266: ; CODE XREF: CheckSum:loc_CE2FA
movh.a a15, #@HIS(DATA_address)
ld32.a a7, [a15]@LOS(DATA_address)
ld16.bu d10, [a7]
ld32.w d12, dword_D0000D34
ld32.w d11, dword_D0000D30
jlt.u d12, d11, loc_CE286
call32 sub_7FCC0
add16 d11, d2
jlt.u d12, d11, loc_CE2A8
loc_CE286: ; CODE XREF: CheckSum+36
mov.u d6, #0xFFFF
ld32.w d15, CRC_value
sh32 d7, d15, #-8
addih d6, d6, #0xFF
and16 d7, d6
xor16 d15, d10
and32 d15, d15, #0xFF
addsc16.a a15, a14, d15, #2
ld16.w d15, [a15]
xor16 d15, d7
st32.w CRC_value, d15
loc_CE2A8: ; CODE XREF: CheckSum+40
movh.a a15, #@HIS(DATA_address)
ld32.a a7, [a15]@LOS(DATA_address)
add16.a a7, #1
lea a15, [a15]@LOS(DATA_address)
st16.a [a15], a7
ld32.w d15, dword_D0000D34
add16 d15, #1
st32.w dword_D0000D34, d15
ld32.w d7, dword_D0000D26
jlt.u d15, d7, loc_CE2F8
ld32.w d15, CRC_value
movh.a a15, #@HIS(CRC_Variable)
st32.w [a15]@LOS(CRC_Variable), d15
mov16 d15, #1
st32.b take_CKS_var, d15
movh.a a15, #@HIS(CKS_loop_count)
lea a15, [a15]@LOS(CKS_loop_count)
ld.b d15, [a15]0
jnz16 d15, loc_CE2FE
mov16 d15, #1
movh.a a15, #@HIS(CKS_loop_count)
lea a15, [a15]@LOS(CKS_loop_count)
st16.b [a15], d15
ret16
; ---------------------------------------------------------------------------
loc_CE2F8: ; CODE XREF: CheckSum+84
add16 d13, #1
loc_CE2FA: ; CODE XREF: CheckSum+22
jlt.u d13, d14, loc_CE266
loc_CE2FE: ; CODE XREF: CheckSum+A6
ret16
; End of function CheckSum
The converted C algorithm:
uint32_t crc32(uint32_t n, uint32_t *data) {
uint32_t i = 0;
uint32_t ch;
crc = 0xFFFFFFFF;
while (i < n) {
ch = data[i];
crc = ((crc >> 8) & 0xFFFFFF) ^
*(crc32_table + ((((crc ^ ch) & 0xFF) << 2) & 0xFF));
i++;
}
return crc;
}
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP