• AVR Freaks

Hot!Decompile a PIC

Page: 12 > Showing page 1 of 2
Author
Meta
Senior Member
  • Total Posts : 153
  • Reward points : 0
  • Joined: 2008/02/11 06:33:46
  • Location: Spain
  • Status: offline
2020/07/12 03:06:20 (permalink)
0

Decompile a PIC

Hello:

Is there any source code about decompiling the PIC16F84A in C # or Java?

Regards.
#1

21 Replies Related Threads

    katela
    Super Member
    • Total Posts : 1833
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: offline
    Re: Decompile a PIC 2020/07/12 06:26:30 (permalink)
    -1 (1)
    When you say decompiling the PIC, what exactly do you mean? A free open source compiler for PIC...?

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #2
    Meta
    Senior Member
    • Total Posts : 153
    • Reward points : 0
    • Joined: 2008/02/11 06:33:46
    • Location: Spain
    • Status: offline
    Re: Decompile a PIC 2020/07/12 06:58:37 (permalink)
    +1 (1)
    What happens from the hex file to asm.
    #3
    NKurzman
    A Guy on the Net
    • Total Posts : 18858
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Decompile a PIC 2020/07/12 07:02:15 (permalink)
    +3 (3)
    That software is commonly known as a “disassembler”.
    #4
    upand_at_them
    Super Member
    • Total Posts : 585
    • Reward points : 0
    • Joined: 2005/05/16 07:02:38
    • Location: Pennsylvania
    • Status: offline
    Re: Decompile a PIC 2020/07/12 07:19:17 (permalink)
    +2 (2)
    Hex -> assembly?...yes
    Hex -> anything else?...NO
    #5
    Meta
    Senior Member
    • Total Posts : 153
    • Reward points : 0
    • Joined: 2008/02/11 06:33:46
    • Location: Spain
    • Status: offline
    Re: Decompile a PIC 2020/07/12 07:19:18 (permalink)
    0
    Yes.
    #6
    1and0
    Access is Denied
    • Total Posts : 10999
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Decompile a PIC 2020/07/12 08:10:03 (permalink)
    +1 (1)
    In MPLAB, import your hex file and view the program memory (disassembly listing).
     
    #7
    Meta
    Senior Member
    • Total Posts : 153
    • Reward points : 0
    • Joined: 2008/02/11 06:33:46
    • Location: Spain
    • Status: offline
    Re: Decompile a PIC 2020/07/12 10:08:25 (permalink)
    0
    In the MPLAB I don't like it, because the operand shows it to you with numbers. For example:

       0:   16 83      bsf 0x03, 5
       1:   01 86      clrf 0x06
       2:   30 1F      movlw 0x1F
       3:   00 85      movwf 0x05
       4:   12 83      bcf 0x03, 5
       5:   10 06      bcf 0x06, 0


     
    With Visual C # I want to program it to display like this:

       0:   16 83      bsf STATUS, RP0  
       1:   01 86      clrf TRISB      
       2:   30 1F      movlw 0x1F       
       3:   00 85      movwf TRISA
       4:   12 83      bcf STATUS, RP0   
       5:   10 06      bcf PORTB, 0     


     
    Do you understand what I want to do?
     
    Thanks.
    #8
    W4GNS.
    Senior Member
    • Total Posts : 37
    • Reward points : 0
    • Joined: 2009/11/16 18:23:19
    • Location: Dixie
    • Status: offline
    Re: Decompile a PIC 2020/07/12 10:34:15 (permalink)
    #9
    NorthGuy
    Super Member
    • Total Posts : 6228
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: Decompile a PIC 2020/07/12 12:01:57 (permalink)
    +1 (1)
    Meta
    Do you understand what I want to do?

     
    These symbols depend on what bank is selected, which is impossible to tell just by looking at the instruction codes.
     
    #10
    Meta
    Senior Member
    • Total Posts : 153
    • Reward points : 0
    • Joined: 2008/02/11 06:33:46
    • Location: Spain
    • Status: offline
    Re: Decompile a PIC 2020/07/12 12:08:12 (permalink)
    0
    Exact. There is a trick.
    The program looks at which memory bank you are in. In this case there are only two memory banks for the PIC16F84A.

    C # has to read the times that this bank finds at this moment and then apply the corresponding instructions.
    #11
    1and0
    Access is Denied
    • Total Posts : 10999
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Decompile a PIC 2020/07/12 12:33:55 (permalink)
    +1 (1)
    Meta
    Exact. There is a trick.
    The program looks at which memory bank you are in. In this case there are only two memory banks for the PIC16F84A.

    C # has to read the times that this bank finds at this moment and then apply the corresponding instructions.

    You will have to write a "smart" disassembler, no easy task!
     
    #12
    Meta
    Senior Member
    • Total Posts : 153
    • Reward points : 0
    • Joined: 2008/02/11 06:33:46
    • Location: Spain
    • Status: offline
    Re: Decompile a PIC 2020/07/12 12:58:19 (permalink)
    -1 (1)
    It is not easy, nor is it impossible. The compiler knows what it compiles. When decompiling you have to help him.

    Try to follow these steps.
     
     
    In summary

    MOVF PORTB, F

    MOVF H'0006', H'0001'

    00001000 1 000 0110


     
    Then I adapt it to English.
     
    Download
     
    ;)
    #13
    ric
    Super Member
    • Total Posts : 28009
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Decompile a PIC 2020/07/12 13:44:43 (permalink)
    +5 (5)
    You are over simplifying it.
    Your disassembler would have to fully emulate the operation of the PIC, and execute the entire program, tracking the state of the bank select bits. You do not always have the bank select code in the instructions immediately before the memory access, they could have been executed before a GOTO or CALL from somewhere else.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #14
    NorthGuy
    Super Member
    • Total Posts : 6228
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: Decompile a PIC 2020/07/12 14:14:45 (permalink)
    +2 (2)
    Meta
    It is not easy, nor is it impossible.



    The bank selection is run-time. It is possible that the same instruction at the same location accesses different banks at different passes. I did that :) So, there are indeed cases where it is completely impossible. For some situations, you can make a good guess, other times you can't. And, of course, you need wisdom to tell these situations apart.
    #15
    Meta
    Senior Member
    • Total Posts : 153
    • Reward points : 0
    • Joined: 2008/02/11 06:33:46
    • Location: Spain
    • Status: offline
    Re: Decompile a PIC 2020/07/12 14:22:59 (permalink)
    -2 (2)
    No need emulator.

    Just by reading in the hex, if there is operation code of
    16 83 bsf STATE, RP0

    And the other of
    12 83 bcf STATE, RP0

    The C # program is made one more.
    #16
    1and0
    Access is Denied
    • Total Posts : 10999
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Decompile a PIC 2020/07/12 14:38:42 (permalink)
    +1 (1)
    Meta
    No need emulator.

    Just by reading in the hex, if there is operation code of
    16 83 bsf STATE, RP0

    And the other of
    12 83 bcf STATE, RP0

    You are assuming linear operations from lower address to higher address. It is often not the case, especially when the hex file is created by an assembly code written by an "experienced" programmer.  As said, the banking instructions are usually not located immediately before a memory access instruction.
    #17
    1and0
    Access is Denied
    • Total Posts : 10999
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Decompile a PIC 2020/07/12 14:55:23 (permalink)
    +2 (2)
    For example,
    bsf     STATUS,RP0
    clrf    TRISB
    goto    label
    clrf    PORTB

    PORTB and TRISB have the same offset address, so will your disassembler treats this as PORTB or TRISB? This is only a simple example, there are other situations more difficult like what NorthGuy described where the same instruction can access two or more different banks. I've also done that. ;)
     
    #18
    ric
    Super Member
    • Total Posts : 28009
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Decompile a PIC 2020/07/12 15:04:37 (permalink)
    +2 (2)
    Meta
    No need emulator.

    Just by reading in the hex, if there is operation code of
    16 83 bsf STATE, RP0

    And the other of
    12 83 bcf STATE, RP0

    So you didn't understand my description at all. How much experience of PIC16F assembly code do you actually have?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #19
    Meta
    Senior Member
    • Total Posts : 153
    • Reward points : 0
    • Joined: 2008/02/11 06:33:46
    • Location: Spain
    • Status: offline
    Re: Decompile a PIC 2020/07/12 15:12:49 (permalink)
    0
    I have understood them.

    So it can't be done.
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2020 APG vNext Commercial Version 4.5