Getting through a bit of ARM code - Page 1
Forum section: electronics / general

author: metertech58761
author_rank: Frequent Contributor
timestamp: August 12, 2025, 06:47:00 am
content: So, as stated elsewhere, I've been working on gathering data on various components of a system that uses the power distribution grid as its communications medium. At first, I considered gathering any and all data that I could get my hands on. For a variety of reasons, I narrowed the scope of my project to earlier components powered by various MC6800 derivatives (i.e., 6801, HC11, 68HC05C9A, and 6809).At this point, I am nearly finished, but I still need to put out feelers through other channels to locate the last few components I need to document specific details.However, part of me still wants to build a modernized version of a couple pieces of equipment, powered by something Arduino-like. Most of the assembly code I have at hand should be fairly straightforward to rewrite in more modern languages, but not the main algorithm. Part converts the data block into a bit stream to be sent out, and the other, far more complicated, section reassembles a misshapen blob of 1s and 0s back into the original data block.One of the newer pieces of equipment I know of is relatively simple, little more than a honking big latching relay, status LED, and a pushbutton. Code file is 64K, most of which (~51K) is two long sequences of 04, repeated. The MPU in this case is (unfortunately?) the Reneseas M30622F8PGP-U3C.In the brief bit of searching I did, I saw references to a tool or tools to convert ARM code back into C statements?I also sought out and downloaded the ARM architecture reference manual... I went from being confused over why a mere ~100MB PDF was taking so long to open, to being absolutely floored when I saw the page count: over FOURTEEN THOUSAND PAGES!¿håå? Halp!OK,thatimmediately validated the decision regarding my project's scope that I mentioned earlier.Still... if there IS such a tool that can possibly convert ARM binary into C, I'd like to know about it - most of this code file I mentioned is going to be that algorithm.Now what?

author: eutectique
author_rank: Frequent Contributor
timestamp: August 12, 2025, 10:28:24 am
content: Quote from: metertech58761 on August 12, 2025, 06:47:00 amGhidra :https://github.com/NationalSecurityAgency/ghidraIt has some quirks in naming the variables, but otherwise is very useful.

author: metertech58761
author_rank: Frequent Contributor
timestamp: August 12, 2025, 11:35:16 pm
content: Well, it looks like I got it installed and running, but I have to spend some serious time RTFM...I managed to name the project and import the file, then I'm not sure, but Avast suddenly had a fit, then I have no clue what to do next.

author: westfw
author_rank: Super Contributor
timestamp: August 18, 2025, 02:45:28 am
content: QuoteWhat file are you looking at? I have the ARMv6m Architecture Reference Manual (Cortex M0, M0+) (436 pages) and the ARMv7m manual (Cortex M3, M4, M4F) (858 pages) and the ARMv8m manual (several variations M23, M33, etc) (2147 pages)Did you manage some download that has ALL the different architectures in it?Edit: Ah! "Architecture Reference Manual for A-profile architecture" is indeed 14000+ pages.Probably not a great starting point!

author: metertech58761
author_rank: Frequent Contributor
timestamp: August 20, 2025, 12:04:47 am
content: Like being in Algebra I and trying to look up something in a senior-level Calculus book!I have my work cut out for me, that's for sure.Hopefully I can get the archive neatened up in the next few days and get those feelers put out, then I can dive in and learn this Ghidra business.Case anyone else wants a look, I'll leave a copy of the .bin and the core part of the schematic showing how the PIC is hooked up in-circuit.

author: metertech58761
author_rank: Frequent Contributor
timestamp: September 04, 2025, 03:20:32 am
content: i'm usually good at figuring things out, but i'm out of my depth on this.So, the steps I took -open GhidraFile / new project / non-sharedSet directory and name projectOpen project, import binarySet format - raw binarySet language to M16C/60I'm then presented a message in the Import Results dialog:"Failed to add language defined memory block due to conflict: SFR: start_address=RAM:0000, uninitialized, length=0x3ff"I noted and then dismissed the dialog.I then double-clicked imported file in the project.Ghidra offers to analyze - yesAccepted defaultsAnd then I'm simply lost. I don't know f there's some other file i'm supposed to bring into the mix or what.

author: westfw
author_rank: Super Contributor
timestamp: September 05, 2025, 08:59:12 am
content: QuoteWait. What?QuoteThat's NOT an ARM chip...QuoteI'm not sure what that mean WRT analyzing it...

author: metertech58761
author_rank: Frequent Contributor
timestamp: September 10, 2025, 08:12:39 am
content: I have not been able to find anything specific to programming this MPU - the opcodes, what decompiler to use, etc.I can see that this requires something well beyond the abilities of someone who merely has a casual interest in programming.All I wanted to do was try and turn this binary file back into assembly, perhaps further back into the original C code. I think I was expecting too much.I think the only way forward is to take the 68xx disassembly I DO have and work with that. I was just hoping to save a bit of time by reverse-engineering something a bit more modern.

author: radiolistener
author_rank: Super Contributor
timestamp: September 10, 2025, 08:39:48 am
content: It is unlikely that you will find a tool capable of automatically generating working C code from the binary. The most effective approach is to work manually with a disassembler, complemented by various C decompilers, including AI-based ones. These tools can significantly speed up understanding the code’s logic, even though they won’t produce functional source code.

author: Nominal Animal
author_rank: Super Contributor
timestamp: September 10, 2025, 08:59:19 am
content: Quote from: metertech58761 on September 10, 2025, 08:12:39 amThere is quite a lot of documentationat renesas.com for M16C/62P. For opcodes etc., you want the "M16C/60, M16C/20 Series Assembly Language Programming Guidelines". (Remember to add the "+ ShowNhidden items" below the scrollable list, so you can see the interesting docs.)The instruction set architecture is "M16C". The original C toolchain was either Renesas' own, or based on IAR C, butOpen Source Tools for Renesas'M16C legacy toolchainsshould support it. Because it is based on GNU GCC using ELF object files, it will contain disassebly and object file manipulation tools also. You'll need to tell the tools that your processor family is 62P (typically via command-line options or environment variables), but other than that it should be relatively straightforward to work with. Just remember that it is a fork, a modified version, of the vanilla/upstream GNU GCC toolchain, so if you see oddities or crashes it may not be the GNU folks' doing at all.Edited to add: Latest version ofGhidradoes support M16C/60, so is a very good option for reverse-engineering (decompiling and analysing) the binaries. It can decompile binaries to C, with the standard limitations (generated symbol names and so on, sometimes odd C control structures withgotos and such).

author: metertech58761
author_rank: Frequent Contributor
timestamp: September 14, 2025, 10:28:16 pm
content: radiolistener: Well that bricks my line of thought. Will just work with the 68xx code then.