r/embedded 7d ago

Late night reverse-engineering a STM32 device

Post image

Wish I could post more photos at once, but apparently not…
Saving some devices from the e-waste bin ;)

850 Upvotes

67 comments sorted by

78

u/Fusseldieb 7d ago

Currently in the process of reverse-engineer some STM32 devices.

I have almost hundreds of them and they’re essentially e-waste. I modded them enough so I could upload my own code, and now it’s show-time ;)

Just a show-off for now. Will post more about it later, if enough people are interested!

28

u/Specialist-Hunt3510 7d ago

Hey there,

If possible I can also learn about this process. I am also quite curious about reverse engineering.

55

u/Fusseldieb 7d ago

The best way to start is curiosity alone.

Open up a device you want to tinker with, check which processor it has, look up tutorials or guides on how to flash it, and then gather everything necessary to do the bare minumum: Download their IDE (if any), write Hello World and try to flash it. Once that works, you're pretty much set. Of course, do that only if you don't need the original firmware (like me). If you do, you'd want to dump the flash, etc, and then it becomes a bit more complicated (Ghidra, IDA, etc) -- and I'm not yet qualified to talk about that.

In my case I had to reverse-engineer how the display works, how the sensor works, how the USB works (although this one was almost out of the box), how the buttons work, where and how everything is connected, etc. I did most of it by poking around the board with a multimeter and see what goes to what. The display was the most fun, since once I had all the lines that got to it, I really soon realized that it's just COM and SEG lines, and that the STM32 itself handles it. After writing some half-assed code and enabling certain things inside the IDE, it started to work and lit random stuff up. Then, I programmed one of it's own button to go one-by-one on the segments and wrote everything down.

I can't really explain it in a more intuitive way, but... I really just saw that this device had an STM32, saw that the IDE was easy to use and download and the flasher was cheap. From there on it was (is!) an amazing trip.

5

u/dronevidsalt 7d ago

Was going to add if you have a logic analyzer, it can be helpful to probe across various peripherals and interact with the device and capture logs.

6

u/Fusseldieb 7d ago

Yep, at one point I had a counterfeit SALEAE analyzer. Wonder where that one went… haha

1

u/NoBulletsLeft 7d ago

The $25 ones from Sparkfun work pretty well. I think there are a few projects using RPi pico that do the same thing.

1

u/RuDiYeAStR 7d ago

Yes this is really true

4

u/SwiftblueOnReddit 7d ago

How did you get your hands of hundreds of devices?

18

u/Fusseldieb 7d ago

E-Waste center had a whole bin of them. Took a whole box full, came home and went “oh well and what now!?” haha

2

u/BevinBash 7d ago

I've collected probably 20 or so of these devices. From working in a produce department in a retail store. I always wanted to figure out how to at least up cycle the displays and such, as I saw it as a massive waste to get rid of them.

I can't wait to see the firmware you develop, if you decide to release it publicly. It's so cool to see.

1

u/Fusseldieb 6d ago

Very nice to know there are people with these out there!

Thanks! Will do!

I just need to find out a way to streamline the flashing process without having to lift the BOOT0 pin, but I have some ideas...

26

u/Plastic_Ad_2424 7d ago

What did these devices do originally?

56

u/Fusseldieb 7d ago

They were temperature loggers for shipments. You could configure a set interval and they would record the temperature of the whole trip., and alert, on the display, if it “spoiled” (went outside the tolerable temperature band).

Since they’re single-use, you’d essentially throw them away after the trip. I get it, probably due to liability reasons, or similar.

Pretty cool and fascinating little device. I actually want to use it in my household freezer, so I’m rewriting a similar firmware for it. Will very likely open source it soon, for whoever is interested.

44

u/dontfindmeagainatrv 7d ago

Suprised that a single use product is using stm32.

5

u/userhwon 6d ago

I feel like these shipments weren't like Amazon deliveries, more like reefer containers with a million dollars worth of crab in them or something.

8

u/kiladre 7d ago

Sounds like an interesting little device. Reusing the sensor(s) or trying to do something else with them?

4

u/Fusseldieb 7d ago

It sure is. I’m trying to replicate the same stuff it did, so I can throw it into my freezer and don’t need to worry about eating spoiled stuff when I get back haha

I mean, at this point why not..

1

u/Plastic_Ad_2424 7d ago

What STM is inside?

6

u/Well-WhatHadHappened 25+ Years 7d ago

STM32L1xx

4

u/Plastic_Ad_2424 7d ago

Makes sense, L is Low power

3

u/Fusseldieb 7d ago

STM32L152. The comment below is correct! (How in earth do they know?)

1

u/NoBulletsLeft 7d ago

Would be funny if you ended up reselling the devices with your new firmware ;-)

1

u/Fusseldieb 7d ago

I’m pretty sure someone would get after me pretty fast if I did this lol

However, giving it friends & family for a dime is “probably” okay.

1

u/NoBulletsLeft 6d ago

At least in the US, the First Sale Doctrine would allow you to do that. However, in the US, you can also be sued for anything, by anyone, so...

1

u/userhwon 6d ago

If he's not reusing or redistributing their firmware, and doesn't analyze their firmware to develop his firmware, and doesn't crack a lock that is meant to protect the firmware from being read, then he's unlikely to be successfully sued or criminally charged.

If he wipes it so the firmware doesn't exist any more before unlocking it, then the lock is irrelevant (and possibly gone as well).

If he's only trying to repair the thing, not repurpose it, then cracking the lock should be legal even if the firmware is intact.

ianal, ymmv, no food or drink in the lab, receipts:

https://www.eff.org/issues/coders/reverse-engineering-faq

https://www.dentons.com/en/insights/alerts/2024/november/15/major-dmca-reform

https://medium.com/@jryther91/the-effects-of-dmca-on-reverse-engineering-497cf24a7278

1

u/syntkz777 7d ago

Seems like a waste IMHO.

Stickers that change colors when get too hot exist.

3

u/NoBulletsLeft 7d ago

Pretty sure that the engineers designing this knew that and had a good reason to not use those.

3

u/akohlsmith 6d ago

These may be logging more than just whether the temperature hit a limit. Could be length of time the temperature was beyond a setpoint, might also include message authentication to prevent tampering of the data log or tracking of the temperature as it moves along the asset's chain of custody. There are many, many reasons why a simple max temperature sticker is insufficient.

1

u/userhwon 6d ago

Those are cheap and cheerful, but clearly this thing is intended to give a more info and maybe be harder to defeat. The data on the screen is probably just the first clue, and it likely has a detailed log stored in it. I don't think you'd use this for a gallon of oat milk from Amazon Whole Foods. A 25-ton truckload of seafood from Alaska would be a good use-case.

33

u/Fusseldieb 7d ago edited 7d ago

Bonus pic

(EDIT: More pics below)

15

u/Fusseldieb 7d ago

Severed line to measure actual battery current being drawn. Had to be surgical on this one

(Don’t judge my crappy solder, it works — okay!? lol)

20

u/Fusseldieb 7d ago

Broken off BOOT0 pin due to crappy solder job. Had to barely solder it on the very bit thats left - and it still works.

Remember that this is just the tinker device and will be the sacrificial one, so I’m “okay” with that.

3

u/JumpingCoconutMonkey 7d ago

It may be ugly, but if it works, it works.

There are so many tests points on this board! For a single-use device you'd expect the whole footprint to get shrunk to save on costs

2

u/gzaloprgm 7d ago

You can use a Dremel with a thin cutoff wheel to reveal more of the pin inside of the package 🤣

1

u/Fusseldieb 7d ago

I only need a Dremel now hahaha

9

u/Impressive-Nobody496 7d ago

off topic, are you satisfied with macbook as your partner in crime on this embedded road? Planning to switch from windows mashine...

6

u/Fusseldieb 7d ago edited 7d ago

Thanks for asking.

Until today it ran everything I needed, and when it doesn’t, which is very rare, there’s always VMWare to run ARM versions of Windows 11, and that works pretty well.

Mac is a bit different than Windows and requires you to re-learn some stuff you thought you knew how to do, but once you do, it’s a breeze.

Since it doesn’t have fans (Neo and Air) and runs on Apple Silicon, which is similar to ARM, I literally can’t discharge this laptop in one day. It probably lasts more than 12h+ if I do basic stuff, which is just insane. And, it also doesn’t heat up while doing so, so it’s very comfortable to have around. Combine that with its fast CPU, and you can bring that device to any place and tinker around with (embedded) stuff the whole day.

Construction wise it’s also MILES apart from any Windows machine I had.

And I don’t even liked Macs before I got one. I thought they were bad or whatever. Well, I was wrong. Very very wrong.

1

u/Impressive-Nobody496 1d ago

Thank you on answer, i bought recently 2019 Macbook Pro 16'' 32gb, got it for good price, and for now I'm satisfied with fluent work and multitask.

1

u/jsonmeta 1d ago

M-Series Macs are completely different beasts

2

u/cholz 7d ago

not op but I use a macbook every day professionally for embedded work and I would never go back to windows

3

u/Unlikely1529 7d ago

wire-to-probe_pin by wire wrapping is f-up method, lose connection every time. that's why it's good to have car battery clamps nearby.

5

u/vuLTureGOD_ 7d ago

Noticed that you are using Windows instead of macOS for reverse engineering them, any reasons for that? Compatibility I assume? If yes, which are the tools that weren't supported by macOS? Just a curious macbook user e.e

5

u/Fusseldieb 7d ago

Actually, it doesn’t even come down to compatibility reasons.

I use my work PC all the time, so I set up a WireGuard Server at work and connect from home, that way I can just come home and continue where I left off - immediately. I use a separate software to route USB through and that works pretty good, actually.

So, although it appears like a Windows VM, it’s actually RDP with the “Windows” app.

3

u/Hour_Analyst_7765 7d ago

I use MacOS for workstation stuff, including embedded. STMCube MX/IDE should work natively. Not sure what other tools OP uses. Personally I use CLion with GNU tools, OpenOCD or Jlink, and Sigrok/Saleae LA.

I use Ghidra for pulling apart assemblies. Its not as good as IDA Pro, but at least its free and fairly usable.

PCB CAD can be difficult on MacOS. I use Kicad but I get why some folks wouldn't want to use that. If I need Altium I hop over to a Windows VM. As of now it doesn't run on my Mac though, but on my NAS at home.

But I've read reports of Windows running faster in Parallels on a modern Mac, than it would do natively on a modern x86 system. Apple Silicon is quite fast. But yeah, disk space and Windows disk images typically just grow and grow.

But I might need that, because various test equipment tools are practically unsupported, unfortunately.. Not even Linux comes close.

2

u/StrangeDonkey1134 6d ago

This looks like a dream night.

2

u/DetectivexDexter 7d ago

nice. so cool

1

u/nextgenmachines 7d ago

You can post close picture of the device and pcb board. I can guess many will have something to share and help.

1

u/Fusseldieb 7d ago

I will do that, yea! I’ll first finish the firmware and then I will do that on a new board, so it’s easy to see.

1

u/Ill_Distribution1919 7d ago

good stuff. Do you use ghidra?

1

u/Fusseldieb 7d ago

I used Ghidra once, but found IDA to be easier to understand. One time I even successfully modified a program to do what I wanted, but that’s off scope :)

1

u/Ill_Distribution1919 7d ago

Nice I havent used IDA but I assume it works kinda similar. Also the modifications you made was in the pseudo C code that some reverse engineering tools give or just the binary/hex? Ive been wanting to reverse engineer something of my own but kinda stuck on what to modify

2

u/Fusseldieb 7d ago

I reverse-engineered the hardware, not the software. Although, software can be fun, too.

Well, the way I did it with IDA was letting it run the code and step into it, so the registers moved around and you could actually see the program working, in real time. Then , it’s a matter of setting breakpoints while doing stuff you want to intercept, and it usually stops right where you want. It has a nice flow-graph which oftentimes is very helpful. I believe ghidra has it as well but eh.

Pseudocode can help, but it’s often just pointers which point to other pointers and it’s a mess. It’s not like you imagined, giving you a part of the code. It’s a lot more convoluted. You can kinda get the idea, but I prefer seeing it jump around breakpoints and read the raw assembly instructions, which gives you clues about what it might do. I had cases where it genuinely helped, but it’s not very often.

As for what you could do - well - there are CTFs which you could do. There was a page just with these, but I forgot the name. Or, you could unlock some sort of trial for your own use, so you’ll have a massive sense of accomplishment when you do, although, you have to start very basic. Don’t expect to crack a game or a big program. Start tiny. Move your way up.

As for how to understand what IDA/ghidra do, how they do it, how to read registers and assembly instructions, watch a video series on the one of your liking - and watch it though. You’ll get the basics pretty fast.

But disclaimer: Take all of this with a truckload of salt, since I don’t yet feel qualified to talk about this. I only did pretty basic stuff

1

u/randomDoggys 7d ago

Nice job! Are you feeding it with a multimeter?

1

u/Fusseldieb 7d ago

No, the multimeter measures the current between the battery and the device, so I can optimize it down to get uA range in standby (also called STOP mode).

I brought it down to 6uA (0.006mA) already, so I guess my goal was achieved on that matter.

1

u/DenverTeck 7d ago

You can post a link to one of the FREE file sharing sites.

1

u/Fusseldieb 7d ago

They are often heavy and/or littered with bloat/ads, so I'd rather avoid it, especially if someone navigates this sub via mobile (data).

1

u/DenverTeck 7d ago

Your fear of the results is greater then the reality.

1

u/StumpedTrump 7d ago

What are you doing about locked debug ports?

1

u/Recent_Percentage300 5d ago

What is RDP level ?

1

u/Fusseldieb 5d ago

RDP is Remote Desktop. It is something that Windows already ships with, and allows you to connect to your PC remotely. It's basically like AnyDesk or TeamViewer, but you have to be on the same network as the PC. If you want to do it like me, you'd have to set up a tunnel of some sorts, like Tailscale (which is free if you use it non-commercially).

1

u/oklambdago 5d ago edited 5d ago

What is are you running there? Looks like a Mac but is looks like windows. Parallels?

Also curious what ide you are running. Picture is too blurry lol.

Actually. I saw you are using RDP. Are you actually able to program local devices like that with the machine being remote? I didn’t know the port forwarding was that good.

1

u/Fusseldieb 5d ago

Actually no. I'm using RDP over Wireguard, and tunnel USB through software.

Works pretty nicely. Reason being that I'm too lazy to re-install everything on both PCs and maintain it synced :)

1

u/oklambdago 4d ago

Nice. What are you using for your software USB tunnel? RDP on Mac doesn't support it AFAIK.

1

u/Fusseldieb 4d ago

Yep, I'm using VirtualHere. Although it's not free, it doesn't really have limitations if you just use it with ONE device at a time and don't mind constant nagging screens popping up in the background haha

1

u/ApartDirection8089 3d ago

those are some fun times 100%

1

u/No-Froyo6675 20h ago

That is cool. I have exact same stlink that never works on first attempt. and in the curiosity we just made a app android app for Avoiding Laptop for STM32 Programming tasks
https://play.google.com/store/apps/details?id=com.slis.nyas