Reverse Engineering Asked by Unicornux on September 12, 2020
Recently I try to reverse piece of assembly code that written for C166/C167 Arch.
But I have a problem with some places for convert to C
code, such as:
loc_1892:
mov r9, #4
add r9, r0
mov r12, #0FFFFh
mov r4, r9
add r4, #2
calls 0, sub_37C2
mov r13, r4
mov r14, r5
mov r15, #6
calls 0, CRC_16_Calculate
and in sub_37C2
:
sub_37C2:
mov r5, r4
shr r5, #14
shl r5, #1
mov r5, [r5+0FE00h] ; ==> Or DPP0
bmov r4.14, r5.0
bmov r4.15, r5.1
shr r5, #2
rets
also in CRC_16_Calculate
:
loc_29A4:
mov r4, r13
mov r5, r14
add r13, #1
addc r14, #0
exts r5, #1
movb rl3, [r4]
movbz r7, rl3
I guess in sub_37C2
code try to convert the near address to far. But I can’t convert this to C code correctly.
My CRC16 implementation shown below:
static uint16_t Crc16(uint8_t* cBuffer, uint16_t iBufLen, uint16_t wPreset)
{
uint16_t temp;
while (iBufLen--)
{
temp = *cBuffer++;
for (uint8_t j = 0; j < 8; ++j)
{
if ((wPreset ^ temp) & 0x01) wPreset = (wPreset >> 1) ^ 0xA001;
else wPreset >>= 1;
temp >>= 1;
}
}
return wPreset;
}
As you see, I convert loc_29A4
to temp = *cBuffer++
where temp
is uint16
but cBuffer
is uint8_t
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP