Prerequisites:
Install Ghidra SRE v11.1.1 and fix ARMTHUMBinstructions.sinc
.
Since about 2019 there has been a bug in Ghidra SRE where FF FF
is treated as an BL 0xFFE
instruction in v5t architecture. This causes an infinity loop in auto-analysis.
You should apply patch ARMTHUMBinstructions.sinc if you want to work with Siemens firmwares.
Obtain fullflash from your phone and remove FFS & EEPROM from it.
This is important for auto-analysis, beacause FFS and EEPROM contain ambiguous data which can be treated as instructions.
You can download a collection of the fullflashes with already removed FFS and EEPROM: fullflashes.zip.
Run the disassembler and click: File -> Import File
Select your fullflash.bin
Choose the appropriate disassembler settings:
Raw Binary
ARM v5t 32 little
FULLFLASH
A0000000
Then click on fullflash.bin
in the project files.
Reject automatic analysis (press No).
Click Window -> Memory Map
and select attributes for "FULLFLASH":
R W X Volatile
[x] [ ] [x] [ ]
It is very important to UNCHECK W
checkbox, since this directly affects the result of decompilation.
Click Analysis -> Auto Analyse
Change analysis settings:
Disable:
Embedded media
.Non-returning functions - discovered
. This seems to cause disassembly to stop in a lot of places it shouldn't.Create Address Tables
. This seems to be better as a one-shot after initial analysis, to avoid creating data from runs of things that could be addresses.Demangler GNU
.Enable:
Scalar operand references
.Shared return calls
with [x] Allow conditional jumps
.Click "APPLY". DO NOT CLICK "ANALYZE"!!!
Close analysis window.
Window -> Memory Map
IO
0xF0000000
0x0F000000
[x] Read [x] Write [ ] Execute [x] Volatile [ ] Overlay
You should import all memory dumps which you previously made (RAM memory dump).
Example with RAM:
Click File -> Add to Program
Select your dump file, for e.g. C81v51_RAM_A8000000_00800000.bin
.
Select apropriate settings:
RAM
0xA8000000
And click "OK".
Click Window -> Memory Map
and select attributes for "RAM":
R W X Volatile
[x] [x] [x] [ ]
Window -> Script Manager
ghidra_scripts.zip
.swilib-types-PLATFORM.h
from the Swilib data types for dissasembler.File -> Parse C Source...
Clear profile
(eraser icon).swilib-types-PLATFORM.h
to the "Source files to parse".ARM v5t 32 little
.Parse to Program -> Continue -> Don't use Open Archives -> OK
cpu-PHONE.txt
or cpu-pmb887x.txt
from the CPU IO registers.Window -> Script Manager -> ImportSymbolsWithDataType.java -> Run Script
cpu-PHONE.txt
or cpu-pmb887x.txt
.symbols-PHONE.txt
from the Firmware symbols for dissasembler.Window -> Script Manager -> ImportSymbolsWithDataType.java -> Run Script
symbols-PHONE.txt
.This will take a while because some auto-analysis has been started.
Once you see "Finished" in the Script Console - you can cancel this analysis process and go to the next step.
Auto analysis
Analysis -> Auto Analyse 'fullflash.bin'
This will take a while (~1 hour), this is not a fast process. Be patient.
One-shot analysis
Analysis -> One-shot -> Create Address Tables