From 349ef0fad2580a9772535f8d0e34f2e44605d4e0 Mon Sep 17 00:00:00 2001 From: ghidra1 Date: Fri, 13 Sep 2019 14:06:56 -0400 Subject: [PATCH] GT-3149 Corrected bitfield packing for ARM/AARCH64 for Windows PE. Imposed default Thumb context setting for PE and MSCoff ARM32 imports with addition of v8T ARM variant. Corrected ARM pattern alignment issues. Corrected DBViewer long value rendering. --- .../app/plugin/debug/DbViewerComponent.java | 2 +- .../plugin/debug/dbtable/LongRenderer.java | 12 +++++-- .../sleigh/SleighLanguageProvider.java | 5 ++- .../AARCH64/data/languages/AARCH64_win.cspec | 3 ++ Ghidra/Processors/ARM/certification.manifest | 2 +- .../Processors/ARM/data/languages/ARM.ldefs | 33 +++++++++++++++++++ .../Processors/ARM/data/languages/ARM.opinion | 12 +++---- .../ARM/data/languages/ARM_win.cspec | 3 ++ .../languages/{ARM.pspec => ARMtTHUMB.pspec} | 26 +++++++++++++++ .../ARM/data/patterns/ARM_BE_patterns.xml | 25 +++++++++----- .../ARM/data/patterns/ARM_LE_patterns.xml | 26 ++++++++++----- 11 files changed, 121 insertions(+), 28 deletions(-) rename Ghidra/Processors/ARM/data/languages/{ARM.pspec => ARMtTHUMB.pspec} (52%) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/debug/DbViewerComponent.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/debug/DbViewerComponent.java index 3d163f1a9b..456a9d3888 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/debug/DbViewerComponent.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/debug/DbViewerComponent.java @@ -200,12 +200,12 @@ class DbViewerComponent extends JPanel { GTable gTable = new GTable(); if (table.getRecordCount() <= 10000) { model = new DbSmallTableModel(table); - gTable.setDefaultRenderer(Long.class, new LongRenderer()); } else { model = new DbLargeTableModel(table); } gTable.setModel(model); + gTable.setDefaultRenderer(Long.class, new LongRenderer()); JScrollPane scroll = new JScrollPane(gTable); panel.add(scroll, BorderLayout.CENTER); diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/debug/dbtable/LongRenderer.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/debug/dbtable/LongRenderer.java index 0f48c65bd5..db9ff3d5f1 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/debug/dbtable/LongRenderer.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/debug/dbtable/LongRenderer.java @@ -17,18 +17,19 @@ package ghidra.app.plugin.debug.dbtable; import java.awt.Component; -import javax.swing.*; +import javax.swing.JLabel; +import javax.swing.SwingConstants; import docking.widgets.table.GTableCellRenderer; import docking.widgets.table.GTableCellRenderingData; +import ghidra.docking.settings.Settings; public class LongRenderer extends GTableCellRenderer { @Override public Component getTableCellRendererComponent(GTableCellRenderingData data) { - JLabel renderer = - (JLabel) super.getTableCellRendererComponent(data); + JLabel renderer = (JLabel) super.getTableCellRendererComponent(data); renderer.setHorizontalAlignment(SwingConstants.LEADING); @@ -39,4 +40,9 @@ public class LongRenderer extends GTableCellRenderer { protected String getText(Object value) { return value == null ? "" : "0x" + Long.toHexString((Long) value); } + + @Override + protected String formatNumber(Number value, Settings settings) { + return getText(value); + } } diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/SleighLanguageProvider.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/SleighLanguageProvider.java index 0a6b4ef363..ae5cedb58a 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/SleighLanguageProvider.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/SleighLanguageProvider.java @@ -369,7 +369,10 @@ public class SleighLanguageProvider implements LanguageProvider { catch (SleighException ex) { // Error with the manual shouldn't prevent language from loading Msg.error(this, ex.getMessage()); } - descriptions.put(id, description); + if (descriptions.put(id, description) != null) { + Msg.showError(this, null, "Duplicate Sleigh Language ID", + "Language " + id + " previously defined: " + defsFile); + } } parser.end(start); } diff --git a/Ghidra/Processors/AARCH64/data/languages/AARCH64_win.cspec b/Ghidra/Processors/AARCH64/data/languages/AARCH64_win.cspec index 587b253557..156fc99d37 100644 --- a/Ghidra/Processors/AARCH64/data/languages/AARCH64_win.cspec +++ b/Ghidra/Processors/AARCH64/data/languages/AARCH64_win.cspec @@ -25,6 +25,9 @@ + + + diff --git a/Ghidra/Processors/ARM/certification.manifest b/Ghidra/Processors/ARM/certification.manifest index 821d08ab0f..fb30db5de9 100644 --- a/Ghidra/Processors/ARM/certification.manifest +++ b/Ghidra/Processors/ARM/certification.manifest @@ -5,7 +5,6 @@ data/languages/ARM.cspec||GHIDRA||||END| data/languages/ARM.dwarf||GHIDRA||||END| data/languages/ARM.ldefs||GHIDRA||||END| data/languages/ARM.opinion||GHIDRA||||END| -data/languages/ARM.pspec||GHIDRA||||END| data/languages/ARM.sinc||GHIDRA||||END| data/languages/ARM4_be.slaspec||GHIDRA||||END| data/languages/ARM4_le.slaspec||GHIDRA||||END| @@ -30,6 +29,7 @@ data/languages/ARMinstructions.sinc||GHIDRA||||END| data/languages/ARMneon.dwarf||GHIDRA||||END| data/languages/ARMneon.sinc||GHIDRA||||END| data/languages/ARMt.pspec||GHIDRA||||END| +data/languages/ARMtTHUMB.pspec||GHIDRA||||END| data/languages/ARMt_v45.pspec||GHIDRA||||END| data/languages/ARMv8.sinc||GHIDRA||||END| data/languages/old/ARMv5.lang||GHIDRA||||END| diff --git a/Ghidra/Processors/ARM/data/languages/ARM.ldefs b/Ghidra/Processors/ARM/data/languages/ARM.ldefs index 1b14ea0c54..929560c95a 100644 --- a/Ghidra/Processors/ARM/data/languages/ARM.ldefs +++ b/Ghidra/Processors/ARM/data/languages/ARM.ldefs @@ -18,6 +18,23 @@ + + Generic ARM/Thumb v8 little endian (Thumb is default) + + + + + + + + + Generic ARM/Thumb v8 big endian (Thumb is default) + + + + + + - - + + @@ -11,8 +11,8 @@ - - + + @@ -32,7 +32,7 @@ - - + + diff --git a/Ghidra/Processors/ARM/data/languages/ARM_win.cspec b/Ghidra/Processors/ARM/data/languages/ARM_win.cspec index 24c476dc0e..9e71ff4a04 100644 --- a/Ghidra/Processors/ARM/data/languages/ARM_win.cspec +++ b/Ghidra/Processors/ARM/data/languages/ARM_win.cspec @@ -22,6 +22,9 @@ + + + diff --git a/Ghidra/Processors/ARM/data/languages/ARM.pspec b/Ghidra/Processors/ARM/data/languages/ARMtTHUMB.pspec similarity index 52% rename from Ghidra/Processors/ARM/data/languages/ARM.pspec rename to Ghidra/Processors/ARM/data/languages/ARMtTHUMB.pspec index d92ed07517..cc30cec13c 100644 --- a/Ghidra/Processors/ARM/data/languages/ARM.pspec +++ b/Ghidra/Processors/ARM/data/languages/ARMtTHUMB.pspec @@ -1,15 +1,19 @@ + + + + @@ -23,6 +27,7 @@ + @@ -31,8 +36,29 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/Ghidra/Processors/ARM/data/patterns/ARM_BE_patterns.xml b/Ghidra/Processors/ARM/data/patterns/ARM_BE_patterns.xml index 1614593376..c74608db5e 100644 --- a/Ghidra/Processors/ARM/data/patterns/ARM_BE_patterns.xml +++ b/Ghidra/Processors/ARM/data/patterns/ARM_BE_patterns.xml @@ -63,13 +63,15 @@ 11100101 00101101 1110.... ........ 0x........ 0xe24dd... 0xe5 0x2d 0xe0 0x08 0xe1a0c00d 0xe92d.... + - 0xe24dd... 11101001 00101101 .1...... ....0000 + 0xe24dd... 11101001 00101101 .1...... ....0000 + @@ -77,36 +79,49 @@ 11101001 00101101 .1...... ....0000 + + + + 11101001 00101101 .1...... ....0000 + + + + - 0xe24dd... 11100101 00101101 1110.... ........ + 0xe24dd... 11100101 00101101 1110.... ........ + 11100101 00101101 1110.... ........ 0xe24dd... + 11101001 00101101 .1...... ....0000 0x........ 0xe24dd... + 11100101 00101101 1110.... ........ 0x........ 0xe24dd... + 0xe1a0c00d 0xe92d.... + @@ -183,10 +198,4 @@ - - 11101001 00101101 .1...... ....0000 - - - - diff --git a/Ghidra/Processors/ARM/data/patterns/ARM_LE_patterns.xml b/Ghidra/Processors/ARM/data/patterns/ARM_LE_patterns.xml index 57f48d2280..7e18bea070 100644 --- a/Ghidra/Processors/ARM/data/patterns/ARM_LE_patterns.xml +++ b/Ghidra/Processors/ARM/data/patterns/ARM_LE_patterns.xml @@ -64,6 +64,7 @@ 0x08 0xe0 0x2d 0xe5 0x0dc0a0e1 0x....2de9 ........ .1...... 00101101 11101001 + @@ -71,20 +72,30 @@ 0x..d.4de2 ....0000 .1...... 00101101 11101001 + + ....0000 .1...... 00101101 11101001 + - + + + ........ .1...... 00101101 11101001 + + + + 0x..d.4de2 ........ 1110.... 00101101 11100101 + @@ -92,6 +103,7 @@ ........ 1110.... 00101101 11100101 0x..d.4de2 + @@ -99,6 +111,7 @@ ....0000 .1...... 00101101 11101001 0x........ 0x..d.4de2 + @@ -106,12 +119,14 @@ ........ 1110.... 00101101 11100101 0x........ 0x..d.4de2 + 0x0dc0a0e1 0x....2de9 + @@ -189,13 +204,6 @@ - - ........ .1...... 00101101 11101001 - - - - - @@ -290,6 +298,7 @@ add ip,lr,r3, lsl #0x1 | add lr,lr,r3, lsl #0x1 bx ip | bx lr --> + @@ -304,6 +313,7 @@ add ip,lr,r3, lsl #0x1 | add lr,lr,r3, lsl #0x1 bx ip | bx lr --> +