3


i am working a little bit with Ghidra. My assembly code doesn't match with the decompiled code:

                             *                          FUNCTION                          *
                             **************************************************************
                             undefined __stdcall CalCrc8(undefined4 param_1, int para
                               assume LRset = 0x0
                               assume TMode = 0x1
             undefined         r0:1           <RETURN>
             undefined4        r0:4           param_1
             int               r1:4           param_2
             int               r2:4           param_3
                             CalCrc8                                         XREF[2]:     Entry Point(*), 
                                                                                          Frame_Cap:0005a2b8(c)  
        00059dd8 05 4b           ldr        r3,[DAT_00059df0]                                = 0005F314h
        00059dda 10 b5           push       { r4, lr }
        00059ddc 8a 18           add        param_3,param_2,param_3
        00059dde 7b 44           add        r3,pc
        00059de0 03 e0           b          LAB_00059dea
                             LAB_00059de2                                    XREF[1]:     00059dec(j)  
        00059de2 11 f8 01 4b     ldrb.w     r4,[param_2],#0x1
        00059de6 60 40           eor        param_1,r4
        00059de8 18 5c           ldrb       param_1,[r3,param_1]=>Crc8Table               = 
                             LAB_00059dea                                    XREF[1]:     00059de0(j)  
        00059dea 91 42           cmp        param_2,param_3
        00059dec f9 d1           bne        LAB_00059de2
        00059dee 10 bd           pop        { r4, pc }
                             DAT_00059df0                                    XREF[1]:     CalCrc8:00059dd8(R)  
        00059df0 14 f3 05 00     undefined4 0005F314h                                        ?  ->  0005f314
void CalCrc8(undefined4 param_1,int param_2,int param_3)

{
  param_3 = param_2 + param_3;
  while (param_2 != param_3) {
    param_2 = param_2 + 1;
  }
  return;
}

The XOR (address 00059de6) and fetching the value from the CRC8Table is missing. How do i fix the decompiled code?

The architecture is ARM32v8.

-1

The question was a while ago, but i think the trick was to change the return type of the function "CalcCrc8"

Edit: Ghidra doesn't recognize the return type in this example. It thinks that it is void, in reality it was something else. It probably interprets a machine-instruction wrongly as a return? So edit the return type of the function parameter to your needed return type (probably look at the assembler code). For my case, the rest of the function was then interpreted correctly by ghidra.

1
  • Hi @AndiYo would you mind sharing how? E.g. a shortcut you used or a screenshot of the menu item(s) you used?! – 0xC0000022L Feb 25 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.