Patching an embedded synthesiser OS from 1996 with Ghidra
blog.petersobot.com
blog.petersobot.com
1) identify relative addresses of all C-style strings from the start of the binary
2) identify all absolute read addresses
3) find the load address where the most read addresses correspond to the most strings
This solves the problem for me in the vast majority of cases. If you don't have strings, function prologues work as well.
I don't think there's any tooling for this yet. I've had to write the same algorithm over and over. It works regardless of any header information at the start of the binary, though it will fail if there is data between chunks (but you may see multiple valid alignments that can hint to something like this happening)
1. check if in the .so/.dll you can spot any function referring to any recognizable (occurring only once) kind of binary blob - like images, or strings too
2. find the same function in the raw image, Ghidra's decompiler helps so much in this
3. find the address supposed to be pointing to the same binary blob (assuming that this blob is the same in the emulated and the real version)
4. scan the raw image for that same blob you have in the emulated version
5. do the maths to find the base address of the raw image.
Obviously all of this works if the raw binary image you have all refers to the same flat memory space and there's no partial relocation by the bootloader/program accepting this image going on.
Don't ask me about that time I painfully spent so much time without knowing I had one file with the odd name of "emulator.dll" staring at me all that time...
I have an expensive robotic cat toy that the manufacturer stopped supporting and I’ve been working on reverse engineering the firmware in my free time to better understand how it works. I have no background in reverse engineering so I’ve been learning a lot about identifying hardware, reading data sheets, and of course fumbling through Ghidra to disassemble the firmware.
After getting your bearings it becomes pretty easy to recognize the patterns of various standard C library functions like strlen, memcpy, etc. Others can be more challenging. Of course, with bespoke embedded hardware it can be much more difficult.
Ghidra really is an amazingly useful tool (clunky, yes — but very powerful and of course it’s free.) It makes me curious about commercial offerings and if they are worth buying as a hobbyist.
I used it for the Disney bb8 robot firmware which was a fun hobby project.
You can download it from https://www.elektronauts.com/t/machinedrum-sps1-uw-x-06-rele.... They’ve unfortunately kept the details of how they did it somewhat private (I believe at the request of Elektron), though some notes on their initial reverse engineering can be found here: https://github.com/jmamma/MIDICtrl20_MegaCommand/issues/88
[0] https://github.com/HexFiend/HexFiend/tree/master/templates
The biggest hint I could give anyone looking to disassemble a synthesiser operating system is to direct your attention towards the code processing individual MIDI messages. The code is invariably is huge mess, however you'll be able to very quickly identify the operating system's core functions, since the corresponding SysEx parameter numbers clearly identify what functionality you're looking at.
My exercise today made me realize just how much more difficult the modification of the binary is than simply understanding it, as well as how much I hate the x86 architecture (and CISC in general).
It's unfortunate that he wouldn't share what the goal was - what he wanted to patch and why.
I second the sentiment, knowledge of the main goal would add context about the reverse engineering process
As the other comment notes, I’m not sure if MAME can actually properly emulate any music hardware. There’s a skeleton Elektron Machinedrum/Monomachine in there for example but it can’t really do anything interesting (although this thread talks a bit about how some hackers used it to help reverse engineer and ultimately create their own firmware for the Machinedrum, see my other comment for more details: https://github.com/jmamma/MIDICtrl20_MegaCommand/issues/88)
Another project which may be of interest is this emulation of the Motorola DSP536xx DSP, which was used in a lot of classic late 90s hardware synths: https://dsp56300.wordpress.com. It can actually run Access Virus ROMs pretty much perfectly and apparently on an M1 the performance is pretty good, it’s usable but crackly on my i9 Mac. They’re hoping to be able to emulate many more synths which used the same DSP but for now the Virus is the focus.
1) Seed checkum with initial_value
2) Add a data uint sized to the checksum
3) Shift up by 1 bit while feeding back the MSB to the LSB.
4) GOTO 2 until you have consume all the data.
Not sure why you would process with usual addition instead of GF2 addition.
But I am almost existentially disappointed by the opening sentence - ‘For reasons I won’t get into’…
It’s like - why?
The reasons we drive ourselves to do these frankly insane hacking experiments are almost always as interesting as the process itself for me.
The reason for that is - in this case - there are literally thousands of sampler synths with frankly a shitton more features than even what OP has implemented - why use this particular one?
The turntablist community - for instance - vastly prefers a frankly ancient and specific model of turntable (Technical SL-1200 or equivalent) - therefore the community to mod and update this decades-old hardware is dedicated and does similarly amazing things.
The SL-1200 is preferred for its build quality, it’s amazing motor, it’s weight; and it’s reliability.
It however lacks some frankly essential features from newer turntables - reverse, ultrapitch, pitch lock, USB support - but it’s still the most highly sought after and standard unit for the craft.
What makes this particular synthesizer the same - so valuable, so irreplaceable to OP’s craft - that drove them to such an insane level of deconstructing and reflashing the software? I, like - must know…XD
I mean - cool flex - but why?
I'll give you a hint - the post was originally twice as long and _did_ go into detail about why I wanted to patch something, but a reviewer of the post pointed out that I could potentially have run afoul of one or more laws in one or more countries if I had succeeded in doing so.
My observations:
- The renaming into *source = *destination was very confusing.
- I expected (sweet, sweet) 68k assembly, but it's all decompiled to C!
- For some reason MAME supports this musical instrument, and OP's work helped that project boot their emulation, sweet!
> It looks like we’re coping a bunch of data from ROM into RAM - specifically from 0x0001860a to 0x02130000.
line 33 should have been named `src` and 34 should have been named `dst`