-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
STM8 architecture support #16498
Comments
Hi. This seems like a very interesting issue. I think I will have to read up on a lot of stuff to tackle this, but nevertheless, I would like to work on this issue. |
Cool! All yours :) but i think it will be better to work on this new arch in extras instead in core. It will be easier and it can be moved into core when needed |
Also looking for a good disassembler/visualizer for STM8 hex files. Subbing to this thread... |
I dont know which format is this. Can you provide a sample file, documentation or implementation to look at Right now you can disassemble, analyze and decompile stm8 binaries in r2 using the r2ghidra plugin:
|
@trufae send me an email and I will share a hex file with you |
Hi. I am sorry for the long period of silence. I think I bit off more than I could chew back then. But now I think I am in a position to tackle this.
Given that r2ghidra can be used for stm8 binaries, is a separate plugin for stm8 still required? |
sleigh is like 100 times slower than any native r2 plugin to disassemble/analyse anything, and the quality of the results is usually not as good because the translation to sleigh to esil is poor, also stm8 is a 3rd party plugin, so its not that well. maintained, so yeah, i think its always better to have everthing well maintained in the core and not to depend on other stuff unless you have no other options |
Shall I add support for stm8 in |
Yes. In case you want to implement support for stm8. The libr/arch is the right place |
I don't think Ghidra has STM8 as a built-in target right now, actually:
However there are third party modules that you can add to your Ghidra extensions: https://github.com/esaulenka/ghidra_STM8 ... and/or write an arch plugin for the stm8 in r2. Here's the datasheet for one of them in the family and the actual CPU instructions (opcodes). Here I'm leaving a firmware I just dumped from controller and display boards from an exercise threadmill I found in the trash if you or other folks need more examples ;) |
And if you need a text-based working disassembler today to compare while you implement support in r2, have a look at naken_asm:
|
It's normal that r2ghidra doesnt catch the stm8 plugin, because
i just fixed that and pushed. (requires r2 update to support 24bit registers) porting that stm8 disassembler to r2 can be done in 15min, will do that later, shoudln't take more than 15min What i find out after those fixes is:
Actually stm8 is a very simple architecture and should be easy to add full support in r2. I plan to sync the ghidra decompiler with latest from the NSA before r2-5.9. But i dont have enough hands to handle that yet. So I'll ping you when the stm8 support is pushed in r2 (hopefully today) |
Also, this code looks probably more updated and easy to contribute/integrate with r2 https://github.com/volbus/gmtdisas |
Another sauce of inspiration https://github.com/derbroti/Stm8Ida Any volunteer to extend Capstone with support for STM8? that can probably be the better place to benefit everyone in the RE scene |
Cannot repro your screenshot above :/ Would adding this 24 bit ghidra sleigh PR for stm8 help with the 24 bit errors at least?
|
Memory map for the control firmware file. Repro scripts in brainstorm/treadmill-re@181d19f ... if I defined the above memory map with would It works quite well on Ghidra, after defining the memory map, a ton of functions make a lot more sense, as expected. |
why are you running aaaa? i just did af;pdg . i just fixed the stupid 24bit warning message in master btw |
just recompiled latest r2 and latest r2ghidra and tested the same commands you did and it works well |
recompiled both r2 and r2ghidra and I'm getting the following output, so not quite yet what you got on #16498 (comment): threadmill-re$ ./r2/anal.sh
ERROR: Parse error @ line 170 (Invalid register type)
ERROR: Parse error @ line 170 (Invalid register type)
WARN: Cannot derive CC from reg profile
WARN: Missing calling conventions for 'r2ghidra' 64. Deriving it from the regprofile
ERROR: Parse error @ line 170 (Invalid register type)
ERROR: Parse error @ line 170 (Invalid register type)
WARN: set your favourite calling convention in `e anal.cc=?`
Do you want to print 30577 lines? (y/N) I'll investigate a bit about the calling convention for this stm8 code... EDIT: Adding an arbitrary |
i dont know what the script is doing but i see several wrong things before reaching the calling convention issue.
|
#!/bin/sh
r2 -a r2ghidra -n -i r2/anal.r2 control/flash.bin Then
And here's what you were asking for so indeed there's no reg profile for stm8:
|
You are correct. This decompilation looks nice but its wrong. R2ghidra is far from perfect. Not only because of bugs in ghidra, but also because the analysis from r2<>r2ghidra differs if you want something more reliable but less readable i would go for r2dec (pdd) or pdc. i am working on a new decmpiler but wont be a thing until next year. I dont think r2dec supports dtm8 but should be easy to extend. And pdc is completely arch independent. |
@rpv-tomsk #22887 native support for stm8 is now ready to be merged |
well that was merged already so closing |
Is your feature request related to a problem? Please describe.
It would be nice if r2 supported the STM8 architecture for disassembly.
Describe the solution you'd like
Ideally a STM8 disassembler and corresponding analysis would be implemented as a plugin.
Describe alternatives you've considered
An alternative solution is to use naken_asm, but this is missing many analysis features that r2 could provide.
Additional context
The wikipedia page provides some documentation, more information is of course available in the official STM8 programming manual.
I've seen the radare2 plugin documentation, but it isn't that extensive in regards to the interfaces to radare.
The text was updated successfully, but these errors were encountered: