10

I extracted a .hex file from a PIC16F88. For example:

:020000040000FA
:100000008F3083160F0570388F009B0183129F017C
:1000100083169F0107309C0005108312051483127C
:1000200003131730A0006730A1002930A2000A1284
:100030008A11A20B17280A128A11A10B15280A127D
:100040008A11A00B13280510831203131730A00088
:100050006730A1002930A2000A128A11A20B2C28B5
:100060000A128A11A10B2A280A128A11A00B282829
:020070000D2859
:02400E00782F09
:02401000FF3F70
:00000001FF

In MPLAB, I imported this .hex file and found the disassembly code, in this case:

 1   000     308F  MOVLW 0x8f                             
 2   001     1683  BSF 0x3, 0x5                           
 3   002     050F  ANDWF 0xf, W                           
 4   003     3870  IORLW 0x70                             
 5   004     008F  MOVWF 0xf                              
 6   005     019B  CLRF 0x1b                              
 7   006     1283  BCF 0x3, 0x5                           
 8   007     019F  CLRF 0x1f                              
 9   008     1683  BSF 0x3, 0x5                           
10   009     019F  CLRF 0x1f                              
11   00A     3007  MOVLW 0x7                              
12   00B     009C  MOVWF 0x1c                             
13   00C     1005  BCF 0x5, 0                             
14   00D     1283  BCF 0x3, 0x5                           
15   00E     1405  BSF 0x5, 0                             
16   00F     1283  BCF 0x3, 0x5                           
17   010     1303  BCF 0x3, 0x6                           
18   011     3017  MOVLW 0x17                             
19   012     00A0  MOVWF 0x20                             
20   013     3067  MOVLW 0x67                             
21   014     00A1  MOVWF 0x21                             
22   015     3029  MOVLW 0x29                             
23   016     00A2  MOVWF 0x22                             
24   017     120A  BCF 0xa, 0x4                           
25   018     118A  BCF 0xa, 0x3                           
26   019     0BA2  DECFSZ 0x22, F                         
27   01A     2817  GOTO 0x17                              
28   01B     120A  BCF 0xa, 0x4                           
29   01C     118A  BCF 0xa, 0x3                           
30   01D     0BA1  DECFSZ 0x21, F                         
31   01E     2815  GOTO 0x15                              
32   01F     120A  BCF 0xa, 0x4                           
33   020     118A  BCF 0xa, 0x3                           
34   021     0BA0  DECFSZ 0x20, F                         
35   022     2813  GOTO 0x13                              
36   023     1005  BCF 0x5, 0                             
37   024     1283  BCF 0x3, 0x5                           
38   025     1303  BCF 0x3, 0x6                           
39   026     3017  MOVLW 0x17                             
40   027     00A0  MOVWF 0x20                             
41   028     3067  MOVLW 0x67                             
42   029     00A1  MOVWF 0x21                             
43   02A     3029  MOVLW 0x29                             
44   02B     00A2  MOVWF 0x22                             
45   02C     120A  BCF 0xa, 0x4                           
46   02D     118A  BCF 0xa, 0x3                           
47   02E     0BA2  DECFSZ 0x22, F                         
48   02F     282C  GOTO 0x2c                              
49   030     120A  BCF 0xa, 0x4                           
50   031     118A  BCF 0xa, 0x3                           
51   032     0BA1  DECFSZ 0x21, F                         
52   033     282A  GOTO 0x2a                              
53   034     120A  BCF 0xa, 0x4                           
54   035     118A  BCF 0xa, 0x3                           
55   036     0BA0  DECFSZ 0x20, F                         
56   037     2828  GOTO 0x28                              
57   038     280D  GOTO 0xd   

Now I want to know with what compiler this code is compiled. How can I do that? I'm looking for general ways to check what compiler made some ASM code. The code listed is just an example.

  • 3
    Excellent question, recovering the toolchain provenance of the binary code you've specified, at the very least, requires comparing the results of various PIC compilers, I don't know PIC assembly but the last two instructions look interesting for identifying the compiler (Provided your disassembler has misinterpreted the information at 0x38, how can the instruction possibly be called?). Some compilers generate prologues to functions intended for quick-n-dirty later patching that can be a giveaway as well. Best of luck! – ŹV - Mar 24 '13 at 16:05
  • 5
    You might also consider that this might not be compiled code at all.. but was written as asm. – cb88 Mar 25 '13 at 19:55
  • 1
    @zv_ I think your comment should be an answer. I don't think the question should focus on a specific sample and your technique should be generic enough to accept. – amccormack Mar 28 '13 at 22:51
  • I think this question should be rephrased and should focus on general PIC compiler detection and not just your sample. It is OK to use your code as a "for instance" but you should rephrase so that you can accept answers that describe the technique and not just the answer of "general-pic-compiler-1" – amccormack Mar 28 '13 at 22:54
  • @amccormack I agree that zv_'s comment can be an answer. I also edited the question. – user187 Mar 29 '13 at 6:43
3

(Answer converted from comment)

Recovering the toolchain provenance of the binary code you've specified, at the very least, requires comparing the results of various PIC compilers, I don't know PIC assembly but the last two instructions look interesting for identifying the compiler (Provided your disassembler has misinterpreted the information at 0x38, how can the instruction possibly be called?).

Some compilers generate prologues to functions intended for quick-n-dirty later patching that can be a giveaway as well. Best of luck!

Your Answer

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