Ghidra is a software reverse engineering (SRE) framework
GP-1247: Changes to support Android 12
GhidraKnight87d4858cf237
diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/app/util/opinion/DexLoader.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/app/util/opinion/DexLoader.javaindex e999a606d3..7631a235a3 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/app/util/opinion/DexLoader.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/app/util/opinion/DexLoader.java@@ -37,7 +37,7 @@ public class DexLoader extends AbstractLibrarySupportLoader {}@Override- public String getName( ) {+ public String getName() {return "Dalvik Executable (DEX)";}@@ -70,83 +70,106 @@ public class DexLoader extends AbstractLibrarySupportLoader {public void load(ByteProvider provider, LoadSpec loadSpec, List<Option> options,Program program, TaskMonitor monitor, MessageLog log) throws IOException {- monitor.setMessage( "DEX Loader: creating dex memory" );+ monitor.setMessage(getMonitorMessagePrimary());try {- Address start = program.getAddressFactory().getDefaultAddressSpace().getAddress( 0x0 );+ Address start = program.getAddressFactory().getDefaultAddressSpace().getAddress(0x0);long length = provider.length();try (InputStream inputStream = provider.getInputStream(0)) {- program.getMemory().createInitializedBlock(".dex", start, inputStream, length,- monitor, false);+ program.getMemory()+ .createInitializedBlock(getMemoryBlockName(), start, inputStream, length,+ monitor, false);}- BinaryReader reader = new BinaryReader( provider, true );- DexHeader header = DexHeaderFactory.getDexHeader( reader );+ BinaryReader reader = new BinaryReader(provider, true);+ DexHeader header = DexHeaderFactory.getDexHeader(reader);- monitor.setMessage( "DEX Loader: creating method byte code" );+ monitor.setMessage(getMonitorMessageSecondary());- createMethodLookupMemoryBlock( program, monitor );- createMethodByteCodeBlock( program, length, monitor);+ createMethodLookupMemoryBlock(program, monitor);+ createMethodByteCodeBlock(program, length, monitor);- for ( ClassDefItem item : header.getClassDefs( ) ) {- monitor.checkCanceled( );+ for (ClassDefItem item : header.getClassDefs()) {+ monitor.checkCanceled();- ClassDataItem classDataItem = item.getClassDataItem( );- if ( classDataItem == null ) {+ ClassDataItem classDataItem = item.getClassDataItem();+ if (classDataItem == null) {continue;}- createMethods( program, header, item, classDataItem.getDirectMethods( ), monitor, log );- createMethods( program, header, item, classDataItem.getVirtualMethods( ), monitor, log );+ createMethods(program, header, item, classDataItem.getDirectMethods(), monitor,+ log);+ createMethods(program, header, item, classDataItem.getVirtualMethods(), monitor,+ log);}}- catch ( Exception e) {- log.appendException( e );+ catch (Exception e) {+ log.appendException(e);}}- private void createMethodByteCodeBlock(Program program, long length, TaskMonitor monitor) throws Exception {- Address address = toAddr( program, DexUtil.METHOD_ADDRESS );- MemoryBlock block = program.getMemory( ).createInitializedBlock( "method_bytecode", address, length, (byte) 0xff, monitor, false );- block.setRead( true );- block.setWrite( false );- block.setExecute( true );+ protected void createMethodByteCodeBlock(Program program, long length, TaskMonitor monitor)+ throws Exception {+ Address address = toAddr(program, DexUtil.METHOD_ADDRESS);+ MemoryBlock block = program.getMemory()+ .createInitializedBlock("method_bytecode", address, length, (byte) 0xff, monitor,+ false);+ block.setRead(true);+ block.setWrite(false);+ block.setExecute(true);}- private void createMethodLookupMemoryBlock(Program program, TaskMonitor monitor) throws Exception {- Address address = toAddr( program, DexUtil.LOOKUP_ADDRESS );- MemoryBlock block = program.getMemory( ).createInitializedBlock( "method_lookup", address, DexUtil.MAX_METHOD_LENGTH, (byte) 0xff, monitor, false );- block.setRead( true );- block.setWrite( false );- block.setExecute( false );+ protected void createMethodLookupMemoryBlock(Program program, TaskMonitor monitor)+ throws Exception {+ Address address = toAddr(program, DexUtil.LOOKUP_ADDRESS);+ MemoryBlock block = program.getMemory()+ .createInitializedBlock("method_lookup", address, DexUtil.MAX_METHOD_LENGTH,+ (byte) 0xff, monitor, false);+ block.setRead(true);+ block.setWrite(false);+ block.setExecute(false);}- private void createMethods( Program program, DexHeader header, ClassDefItem item, List< EncodedMethod > methods, TaskMonitor monitor, MessageLog log ) throws Exception {- for ( int i = 0 ; i < methods.size( ) ; ++i ) {- monitor.checkCanceled( );+ protected void createMethods(Program program, DexHeader header, ClassDefItem item,+ List<EncodedMethod> methods, TaskMonitor monitor, MessageLog log) throws Exception {+ for (int i = 0; i < methods.size(); ++i) {+ monitor.checkCanceled();- EncodedMethod encodedMethod = methods.get( i );+ EncodedMethod encodedMethod = methods.get(i);- CodeItem codeItem = encodedMethod.getCodeItem( );+ CodeItem codeItem = encodedMethod.getCodeItem();- Address methodIndexAddress = DexUtil.toLookupAddress( program, encodedMethod.getMethodIndex( ) );+ Address methodIndexAddress =+ DexUtil.toLookupAddress(program, encodedMethod.getMethodIndex());- if ( codeItem == null ) {//external method- //TODO+ if (codeItem == null) {+ //external method}else {- Address methodAddress = toAddr( program, DexUtil.METHOD_ADDRESS + encodedMethod.getCodeOffset( ) );+ Address methodAddress =+ toAddr(program, DexUtil.METHOD_ADDRESS + encodedMethod.getCodeOffset());- byte [] instructionBytes = codeItem.getInstructionBytes( );- program.getMemory( ).setBytes( methodAddress, instructionBytes );+ byte[] instructionBytes = codeItem.getInstructionBytes();+ program.getMemory().setBytes(methodAddress, instructionBytes);- program.getMemory( ).setInt( methodIndexAddress, (int) methodAddress.getOffset( ) );+ program.getMemory().setInt(methodIndexAddress, (int) methodAddress.getOffset());}}}- private Address toAddr( Program program, long offset ) {- return program.getAddressFactory( ).getDefaultAddressSpace( ).getAddress( offset );+ protected Address toAddr(Program program, long offset) {+ return program.getAddressFactory().getDefaultAddressSpace().getAddress(offset);+ }++ protected String getMemoryBlockName() {+ return ".dex";}-}+ protected String getMonitorMessagePrimary() {+ return "DEX Loader: creating dex memory";+ }++ protected String getMonitorMessageSecondary() {+ return "DEX Loader: creating method byte code";+ }+}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/analyzers/FileFormatAnalyzer.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/analyzers/FileFormatAnalyzer.javaindex 1c9237717c..ca96b658f2 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/analyzers/FileFormatAnalyzer.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/analyzers/FileFormatAnalyzer.java@@ -46,7 +46,7 @@ public abstract class FileFormatAnalyzer implements Analyzer {}@Override- final public boolean added(Program program, AddressSetView set, TaskMonitor monitor,+ public final boolean added(Program program, AddressSetView set, TaskMonitor monitor,MessageLog log) throws CancelledException {try {return analyze(program, set, monitor, log);@@ -58,28 +58,28 @@ public abstract class FileFormatAnalyzer implements Analyzer {}@Override- final public void analysisEnded(Program program) {+ public void analysisEnded(Program program) {// do nothing}@Override- final public void registerOptions(Options options, Program program) {+ public void registerOptions(Options options, Program program) {// do nothing}@Override- final public void optionsChanged(Options options, Program program) {+ public void optionsChanged(Options options, Program program) {// do nothing}@Override- final public boolean removed(Program program, AddressSetView set, TaskMonitor monitor,+ public boolean removed(Program program, AddressSetView set, TaskMonitor monitor,MessageLog log) throws CancelledException {return false;}@Override- final public boolean supportsOneTimeAnalysis() {+ public boolean supportsOneTimeAnalysis() {return false;}@@ -121,15 +121,6 @@ public abstract class FileFormatAnalyzer implements Analyzer {if (isAscii && bytes.length > 1) {changeFormatToString(component);}-/*- if (component.getFieldName().equals("magic") ||- component.getFieldName().equals("identifier") ||- component.getFieldName().equals("compression") ||- component.getFieldName().equals("format") ||- component.getFieldName().equals("type")) {- changeFormatToString(component);- }-*/}address = address.add(data.getLength());}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtAnalyzer.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtAnalyzer.javaindex 1ecfb7a5ec..1e386edd9a 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtAnalyzer.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtAnalyzer.java@@ -54,7 +54,7 @@ public class ArtAnalyzer extends FileFormatAnalyzer {@Overridepublic boolean isPrototype() {- return true;+ return false;}@Override@@ -75,7 +75,7 @@ public class ArtAnalyzer extends FileFormatAnalyzer {DataType headerDataType = header.toDataType();//only set "image base" when ART header not defined at "image begin"- //---this really only opens when ART is "added to" OAT program+ //---this only happens when ART is "added to" OAT programAddress imageBase = toAddr(program, header.getImageBegin());if (BinaryLoader.BINARY_NAME.equals(program.getExecutableFormat())) {diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtBlock.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtBlock.javaindex b324b04617..e436432226 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtBlock.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtBlock.java@@ -17,7 +17,8 @@ package ghidra.file.formats.android.art;import java.io.IOException;-import ghidra.app.util.bin.*;+import ghidra.app.util.bin.BinaryReader;+import ghidra.app.util.bin.StructConverter;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;@@ -85,8 +86,7 @@ public class ArtBlock implements StructConverter, ArtCompression {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String name = StructConverterUtil.parseName(ArtBlock.class);- Structure structure = new StructureDataType(name, 0);+ Structure structure = new StructureDataType(ArtBlock.class.getSimpleName(), 0);structure.setCategoryPath(new CategoryPath("/art"));structure.add(DWORD, "storage_mode_", storage_mode_.name());structure.add(DWORD, "data_offset_", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtConstants.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtConstants.javaindex 499ddf6923..0d12c309c3 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtConstants.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtConstants.java@@ -20,7 +20,7 @@ import ghidra.program.model.listing.Program;import ghidra.program.model.mem.MemoryBlock;/**- * https://android.googlesource.com/platform/art/+/master/runtime/image.cc+ * https://android.googlesource.com/platform/art/+/master/runtime/image.cc#31*/public final class ArtConstants {@@ -42,6 +42,7 @@ public final class ArtConstants {public final static String VERSION_PIE_RELEASE = "056";public final static String VERSION_10_RELEASE = "074";//Qpublic final static String VERSION_11_RELEASE = "085";//R+ public final static String VERSION_12_RELEASE = "099";//S// "005",// kitkat-release// "009",// lollipop-release@@ -75,6 +76,7 @@ public final class ArtConstants {VERSION_PIE_RELEASE,VERSION_10_RELEASE,VERSION_11_RELEASE,+ VERSION_12_RELEASE,//@formatter:on};diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtFactory.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtFactory.javaindex 27e70bce18..93518174e3 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtFactory.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtFactory.java@@ -20,6 +20,7 @@ import java.io.IOException;import ghidra.app.util.bin.BinaryReader;import ghidra.file.formats.android.art.android10.ArtHeader_10;import ghidra.file.formats.android.art.android11.ArtHeader_11;+import ghidra.file.formats.android.art.android12.ArtHeader_12;import ghidra.file.formats.android.art.kitkat.ArtHeader_KitKat;import ghidra.file.formats.android.art.lollipop.ArtHeader_Lollipop;import ghidra.file.formats.android.art.lollipop.ArtHeader_LollipopMR1WFC;@@ -45,7 +46,7 @@ public final class ArtFactory {String version = reader.readAsciiString(4, 4);if (magic.equals(ArtConstants.MAGIC)) {if (ArtConstants.isSupportedVersion(version)) {- switch (version ) {+ switch (version) {case ArtConstants.VERSION_KITKAT_RELEASE:return new ArtHeader_KitKat(reader);case ArtConstants.VERSION_LOLLIPOP_RELEASE:@@ -70,6 +71,8 @@ public final class ArtFactory {return new ArtHeader_10(reader);case ArtConstants.VERSION_11_RELEASE:return new ArtHeader_11(reader);+ case ArtConstants.VERSION_12_RELEASE:+ return new ArtHeader_12(reader);}}}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtField.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtField.javaindex 81bea98836..8896657cb8 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtField.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtField.java@@ -17,7 +17,8 @@ package ghidra.file.formats.android.art;import java.io.IOException;-import ghidra.app.util.bin.*;+import ghidra.app.util.bin.BinaryReader;+import ghidra.app.util.bin.StructConverter;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;@@ -58,8 +59,7 @@ public class ArtField implements StructConverter {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String name = StructConverterUtil.parseName(ArtField.class);- Structure structure = new StructureDataType(name, 0);+ Structure structure = new StructureDataType(ArtField.class.getSimpleName(), 0);structure.setCategoryPath(new CategoryPath("/art"));structure.add(new Pointer32DataType(), "declaring_class_", null);structure.add(DWORD, "access_flags_", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtFieldGroup.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtFieldGroup.javaindex 32840aa03d..a8aae349d0 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtFieldGroup.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtFieldGroup.java@@ -19,7 +19,8 @@ import java.io.IOException;import java.util.ArrayList;import java.util.List;-import ghidra.app.util.bin.*;+import ghidra.app.util.bin.BinaryReader;+import ghidra.app.util.bin.StructConverter;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;@@ -53,8 +54,8 @@ public class ArtFieldGroup implements StructConverter {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String name = StructConverterUtil.parseName(ArtFieldGroup.class);- Structure structure = new StructureDataType(name + "_" + fieldCount, 0);+ Structure structure = new StructureDataType(+ ArtFieldGroup.class.getSimpleName() + "_" + fieldCount, 0);structure.setCategoryPath(new CategoryPath("/art"));structure.add(DWORD, "fieldCount", null);for (int i = 0; i < fieldCount; ++i) {diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtHeader.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtHeader.javaindex 13943c9af9..a79f8df095 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtHeader.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtHeader.java@@ -19,7 +19,8 @@ import java.io.IOException;import java.util.ArrayList;import java.util.List;-import ghidra.app.util.bin.*;+import ghidra.app.util.bin.BinaryReader;+import ghidra.app.util.bin.StructConverter;import ghidra.program.model.data.*;import ghidra.program.model.listing.Program;import ghidra.util.exception.DuplicateNameException;@@ -137,8 +138,7 @@ public abstract class ArtHeader implements StructConverter {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(ArtHeader.class);- Structure structure = new StructureDataType(className, 0);+ Structure structure = new StructureDataType(ArtHeader.class.getSimpleName(), 0);structure.add(STRING, 4, "magic_", null);structure.add(STRING, 4, "version_", null);structure.setCategoryPath(new CategoryPath("/art"));diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtImageSectionsFactory.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtImageSectionsFactory.javanew file mode 100644index 0000000000..7e5ea3a3ac--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtImageSectionsFactory.java@@ -0,0 +1,64 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.art;++import java.io.IOException;++import ghidra.app.util.bin.BinaryReader;+import ghidra.file.formats.android.art.android10.ImageSections_10;+import ghidra.file.formats.android.art.android12.ImageSections_12;+import ghidra.file.formats.android.art.marshmallow.ImageSections_Marshmallow;+import ghidra.file.formats.android.art.nougat.ImageSections_Nougat;+import ghidra.file.formats.android.art.nougat.ImageSections_NougatMR2Pixel;+import ghidra.file.formats.android.art.oreo.ImageSections_Oreo;+import ghidra.file.formats.android.art.oreo.ImageSections_OreoMR1;+import ghidra.file.formats.android.art.pie.ImageSections_Pie;++public final class ArtImageSectionsFactory {++ /**+ * Every major version of Android has a different ImageSections enum,+ * this method will return the appropriate section one.+ * @param reader the binary reader for the ART file+ * @param artHeader the ART Header containing the sections+ * @returns the ImageSections for the specified ART version+ */+ public static ArtImageSections getArtImageSections(BinaryReader reader, ArtHeader artHeader)+ throws IOException {+ switch (artHeader.getVersion()) {+ case ArtConstants.VERSION_MARSHMALLOW_RELEASE:+ return new ImageSections_Marshmallow(reader, artHeader);+ case ArtConstants.VERSION_NOUGAT_RELEASE:+ return new ImageSections_Nougat(reader, artHeader);+ case ArtConstants.VERSION_NOUGAT_MR2_PIXEL_RELEASE:+ return new ImageSections_NougatMR2Pixel(reader, artHeader);+ case ArtConstants.VERSION_OREO_RELEASE:+ case ArtConstants.VERSION_OREO_DR1_RELEASE:+ return new ImageSections_Oreo(reader, artHeader);+ case ArtConstants.VERSION_OREO_MR1_RELEASE:+ return new ImageSections_OreoMR1(reader, artHeader);+ case ArtConstants.VERSION_PIE_RELEASE:+ return new ImageSections_Pie(reader, artHeader);+ case ArtConstants.VERSION_10_RELEASE:+ case ArtConstants.VERSION_11_RELEASE:+ return new ImageSections_10(reader, artHeader);+ case ArtConstants.VERSION_12_RELEASE:+ return new ImageSections_12(reader, artHeader);+ }+ throw new IOException(+ "Unsupported ART version for ImageSections: " + artHeader.getVersion());+ }+}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtMethod.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtMethod.javaindex dd34ff2582..0a6b1bd2ac 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtMethod.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtMethod.java@@ -17,7 +17,8 @@ package ghidra.file.formats.android.art;import java.io.IOException;-import ghidra.app.util.bin.*;+import ghidra.app.util.bin.BinaryReader;+import ghidra.app.util.bin.StructConverter;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;@@ -259,8 +260,7 @@ public class ArtMethod implements StructConverter {DataType ptr32 = new Pointer32DataType();DataType ptr64 = new Pointer64DataType();- String name = StructConverterUtil.parseName(ArtMethod.class);- Structure struct = new StructureDataType(name, 0);+ Structure struct = new StructureDataType(ArtMethod.class.getSimpleName(), 0);struct.setCategoryPath(new CategoryPath("/art"));if (ArtConstants.VERSION_MARSHMALLOW_RELEASE.equals(artVersion)) {diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtMethodGroup.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtMethodGroup.javaindex 7b7f98e603..0f5318535a 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtMethodGroup.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/ArtMethodGroup.java@@ -19,7 +19,8 @@ import java.io.IOException;import java.util.ArrayList;import java.util.List;-import ghidra.app.util.bin.*;+import ghidra.app.util.bin.BinaryReader;+import ghidra.app.util.bin.StructConverter;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;@@ -65,8 +66,8 @@ public class ArtMethodGroup implements StructConverter {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String name = StructConverterUtil.parseName(ArtMethodGroup.class);- Structure structure = new StructureDataType(name + "_" + methodCount, 0);+ Structure structure = new StructureDataType(+ ArtMethodGroup.class.getSimpleName() + "_" + methodCount, 0);structure.setCategoryPath(new CategoryPath("/art"));if (pointerSize == 8) {structure.add(QWORD, "methodCount", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/UnsupportedArtVersionException.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/UnsupportedArtVersionException.javaindex 2c1975aaaf..6c99a4e172 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/UnsupportedArtVersionException.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/UnsupportedArtVersionException.java@@ -15,9 +15,9 @@*/package ghidra.file.formats.android.art;-final class UnsupportedArtVersionException extends Exception {+public final class UnsupportedArtVersionException extends Exception {UnsupportedArtVersionException(String magic, String version) {- super("Unsupported ART version: " + version);+ super("Unsupported ART (" + magic.trim() + ") for version: " + version);}}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/android10/ArtHeader_10.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/android10/ArtHeader_10.javaindex b49e180ce2..df5f55a938 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/android10/ArtHeader_10.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/android10/ArtHeader_10.java@@ -20,7 +20,6 @@ import java.util.ArrayList;import java.util.List;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;import ghidra.file.formats.android.art.*;import ghidra.file.formats.android.util.DecompressionManager;import ghidra.program.model.data.DataType;@@ -79,7 +78,7 @@ public class ArtHeader_10 extends ArtHeader {image_roots_ = reader.readNextInt();pointer_size_ = reader.readNextInt();- sections = new ImageSections_10(reader, this);+ sections = ArtImageSectionsFactory.getArtImageSections(reader, this);sections.parseSections(reader);parseImageMethods(reader);@@ -157,8 +156,9 @@ public class ArtHeader_10 extends ArtHeader {}/**- * App images currently require a boot image,- * if the size is non zero then it is an app image header.+ * App images currently require a boot image, if the size is non zero then it is+ * an app image header.+ ** @return true if this header represents an app image*/public boolean isAppImage() {@@ -196,12 +196,11 @@ public class ArtHeader_10 extends ArtHeader {public DataType toDataType() throws DuplicateNameException, IOException {Structure structure = (Structure) super.toDataType();- String className = StructConverterUtil.parseName(ArtHeader_10.class);try {- structure.setName(className);+ structure.setName(ArtHeader_10.class.getSimpleName());}catch (InvalidNameException e) {- //ignore, just use original name should this fail+ // ignore, just use original name should this fail}structure.add(DWORD, "image_reservation_size_", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/android11/ArtHeader_11.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/android11/ArtHeader_11.javaindex 2f625b404a..f2b1d3c5ed 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/android11/ArtHeader_11.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/android11/ArtHeader_11.java@@ -20,10 +20,8 @@ import java.util.ArrayList;import java.util.List;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;import ghidra.file.formats.android.art.*;import ghidra.file.formats.android.art.android10.ImageMethod_10;-import ghidra.file.formats.android.art.android10.ImageSections_10;import ghidra.file.formats.android.util.DecompressionManager;import ghidra.program.model.data.DataType;import ghidra.program.model.data.Structure;@@ -85,7 +83,7 @@ public class ArtHeader_11 extends ArtHeader {image_roots_ = reader.readNextInt();pointer_size_ = reader.readNextInt();- sections = new ImageSections_10(reader, this);+ sections = ArtImageSectionsFactory.getArtImageSections(reader, this);sections.parseSections(reader);parseImageMethods(reader);@@ -210,9 +208,8 @@ public class ArtHeader_11 extends ArtHeader {public DataType toDataType() throws DuplicateNameException, IOException {Structure structure = (Structure) super.toDataType();- String className = StructConverterUtil.parseName(ArtHeader_11.class);try {- structure.setName(className);+ structure.setName(ArtHeader_11.class.getSimpleName());}catch (InvalidNameException e) {//ignorediff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/android12/ArtHeader_12.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/android12/ArtHeader_12.javanew file mode 100644index 0000000000..5a683deaa8--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/android12/ArtHeader_12.java@@ -0,0 +1,54 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.art.android12;++import java.io.IOException;++import ghidra.app.util.bin.BinaryReader;+import ghidra.file.formats.android.art.android11.ArtHeader_11;+import ghidra.program.model.data.DataType;+import ghidra.program.model.data.Structure;+import ghidra.util.InvalidNameException;+import ghidra.util.exception.DuplicateNameException;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/android-s-beta-4/runtime/image.h#418+ * https://android.googlesource.com/platform/art/+/refs/heads/android-s-beta-4/runtime/image.cc#33+ *+ * https://android.googlesource.com/platform/art/+/refs/heads/android-s-beta-5/runtime/image.h#418+ * https://android.googlesource.com/platform/art/+/refs/heads/android-s-beta-5/runtime/image.cc#33+ *+ * https://android.googlesource.com/platform/art/+/refs/heads/android12-release/runtime/image.h#418+ * https://android.googlesource.com/platform/art/+/refs/heads/android12-release/runtime/image.cc#33+ */+public class ArtHeader_12 extends ArtHeader_11 {++ public ArtHeader_12(BinaryReader reader) throws IOException {+ super(reader);+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ Structure structure = (Structure) super.toDataType();+ try {+ structure.setName(ArtHeader_12.class.getSimpleName());+ }+ catch (InvalidNameException e) {+ // ignore+ }+ return structure;+ }+}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/android12/ImageSections_12.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/android12/ImageSections_12.javanew file mode 100644index 0000000000..a16929d285--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/android12/ImageSections_12.java@@ -0,0 +1,110 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.art.android12;++import ghidra.app.util.bin.BinaryReader;+import ghidra.file.formats.android.art.ArtHeader;+import ghidra.file.formats.android.art.ArtImageSections;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/android-s-beta-4/runtime/image.h#254+ *+ * https://android.googlesource.com/platform/art/+/refs/heads/android-s-beta-4/runtime/image.h#254+ */+public class ImageSections_12 extends ArtImageSections {+ public final static int kSectionObjects = 0;+ public final static int kSectionArtFields = 1;+ public final static int kSectionArtMethods = 2;+ public final static int kSectionRuntimeMethods = 3;+ public final static int kSectionImTables = 4;+ public final static int kSectionIMTConflictTables = 5;+ public final static int kSectionInternedStrings = 6;+ public final static int kSectionClassTable = 8;+ public final static int kSectionStringReferenceOffsets = 9;+ public final static int kSectionMetadata = 10;+ public final static int kSectionImageBitmap = 11;+ public final static int kSectionCount = 12; // Number of elements in enum.++ public ImageSections_12(BinaryReader reader, ArtHeader header) {+ super(reader, header);+ }++ @Override+ public int get_kSectionObjects() {+ return kSectionObjects;+ }++ @Override+ public int get_kSectionArtFields() {+ return kSectionArtFields;+ }++ @Override+ public int get_kSectionArtMethods() {+ return kSectionArtMethods;+ }++ @Override+ public int get_kSectionRuntimeMethods() {+ return kSectionRuntimeMethods;+ }++ @Override+ public int get_kSectionImTables() {+ return kSectionImTables;+ }++ @Override+ public int get_kSectionIMTConflictTables() {+ return kSectionIMTConflictTables;+ }++ @Override+ public int get_kSectionDexCacheArrays() {+ return UNSUPPORTED_SECTION;+ }++ @Override+ public int get_kSectionInternedStrings() {+ return kSectionInternedStrings;+ }++ @Override+ public int get_kSectionClassTable() {+ return kSectionClassTable;+ }++ @Override+ public int get_kSectionStringReferenceOffsets() {+ return kSectionStringReferenceOffsets;+ }++ @Override+ public int get_kSectionMetadata() {+ return kSectionMetadata;+ }++ @Override+ public int get_kSectionImageBitmap() {+ return kSectionImageBitmap;+ }++ @Override+ public int get_kSectionCount() {+ return kSectionCount;+ }++}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/kitkat/ArtHeader_KitKat.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/kitkat/ArtHeader_KitKat.javaindex 45106f2bec..f297992fd1 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/kitkat/ArtHeader_KitKat.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/kitkat/ArtHeader_KitKat.java@@ -18,7 +18,6 @@ package ghidra.file.formats.android.art.kitkat;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;import ghidra.file.formats.android.art.ArtHeader;import ghidra.program.model.data.DataType;import ghidra.program.model.data.Structure;@@ -152,11 +151,11 @@ public class ArtHeader_KitKat extends ArtHeader {public DataType toDataType() throws DuplicateNameException, IOException {Structure structure = (Structure) super.toDataType();- String className = StructConverterUtil.parseName(ArtHeader_KitKat.class);try {- structure.setName(className);+ structure.setName(ArtHeader_KitKat.class.getSimpleName());}catch (InvalidNameException e) {+ //ignore}structure.add(DWORD, "image_begin_", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/lollipop/ArtHeader_Lollipop.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/lollipop/ArtHeader_Lollipop.javaindex 73861ccb85..e472c815f0 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/lollipop/ArtHeader_Lollipop.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/lollipop/ArtHeader_Lollipop.java@@ -18,7 +18,6 @@ package ghidra.file.formats.android.art.lollipop;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;import ghidra.file.formats.android.art.ArtHeader;import ghidra.program.model.data.DataType;import ghidra.program.model.data.Structure;@@ -128,11 +127,11 @@ public class ArtHeader_Lollipop extends ArtHeader {public DataType toDataType() throws DuplicateNameException, IOException {Structure structure = (Structure) super.toDataType();- String className = StructConverterUtil.parseName(ArtHeader_Lollipop.class);try {- structure.setName(className);+ structure.setName(ArtHeader_Lollipop.class.getSimpleName());}catch (InvalidNameException e) {+ //ignore}structure.add(DWORD, "image_begin_", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/lollipop/ArtHeader_LollipopMR1WFC.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/lollipop/ArtHeader_LollipopMR1WFC.javaindex 03d597e387..53a053aa89 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/lollipop/ArtHeader_LollipopMR1WFC.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/lollipop/ArtHeader_LollipopMR1WFC.java@@ -18,7 +18,6 @@ package ghidra.file.formats.android.art.lollipop;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;import ghidra.file.formats.android.art.ArtHeader;import ghidra.program.model.data.DataType;import ghidra.program.model.data.Structure;@@ -127,11 +126,11 @@ public class ArtHeader_LollipopMR1WFC extends ArtHeader {public DataType toDataType() throws DuplicateNameException, IOException {Structure structure = (Structure) super.toDataType();- String className = StructConverterUtil.parseName(ArtHeader_LollipopMR1WFC.class);try {- structure.setName(className);+ structure.setName(ArtHeader_LollipopMR1WFC.class.getSimpleName());}catch (InvalidNameException e) {+ //ignore}structure.add(DWORD, "image_begin_", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/marshmallow/ArtHeader_Marshmallow.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/marshmallow/ArtHeader_Marshmallow.javaindex 24e2a337b1..f143c1fbc9 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/marshmallow/ArtHeader_Marshmallow.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/marshmallow/ArtHeader_Marshmallow.java@@ -18,9 +18,7 @@ package ghidra.file.formats.android.art.marshmallow;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;-import ghidra.file.formats.android.art.ArtHeader;-import ghidra.file.formats.android.art.ArtImageSections;+import ghidra.file.formats.android.art.*;import ghidra.program.model.data.DataType;import ghidra.program.model.data.Structure;import ghidra.program.model.listing.Program;@@ -69,7 +67,7 @@ public class ArtHeader_Marshmallow extends ArtHeader {pointer_size_ = reader.readNextInt();compile_pic_ = reader.readNextInt();- sections = new ImageSections_Marshmallow(reader, this);+ sections = ArtImageSectionsFactory.getArtImageSections(reader, this);sections.parseSections(reader);for (int i = 0; i < image_methods_.length; ++i) {@@ -144,9 +142,8 @@ public class ArtHeader_Marshmallow extends ArtHeader {public DataType toDataType() throws DuplicateNameException, IOException {Structure structure = (Structure) super.toDataType();- String className = StructConverterUtil.parseName(ArtHeader_Marshmallow.class);try {- structure.setName(className);+ structure.setName(ArtHeader_Marshmallow.class.getSimpleName());}catch (InvalidNameException e) {}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/nougat/ArtHeader_Nougat.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/nougat/ArtHeader_Nougat.javaindex 6c8c64d0f4..d66cee0e1e 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/nougat/ArtHeader_Nougat.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/nougat/ArtHeader_Nougat.java@@ -18,7 +18,6 @@ package ghidra.file.formats.android.art.nougat;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;import ghidra.file.formats.android.art.*;import ghidra.file.formats.android.util.DecompressionManager;import ghidra.program.model.data.DataType;@@ -62,10 +61,6 @@ public class ArtHeader_Nougat extends ArtHeader implements ArtCompression {parse(reader);}- protected ArtImageSections getImageSections(BinaryReader reader) {- return new ImageSections_Nougat(reader, this);- }-@Overrideprotected void parse(BinaryReader reader) throws IOException {image_begin_ = reader.readNextInt();@@ -85,7 +80,7 @@ public class ArtHeader_Nougat extends ArtHeader implements ArtCompression {compile_pic_ = reader.readNextInt();is_pic_ = reader.readNextInt();- sections = getImageSections(reader);+ sections = ArtImageSectionsFactory.getArtImageSections(reader, this);sections.parseSections(reader);parseImageMethods(reader);@@ -212,9 +207,8 @@ public class ArtHeader_Nougat extends ArtHeader implements ArtCompression {public DataType toDataType() throws DuplicateNameException, IOException {Structure structure = (Structure) super.toDataType();- String className = StructConverterUtil.parseName(ArtHeader_Nougat.class);try {- structure.setName(className);+ structure.setName(ArtHeader_Nougat.class.getSimpleName());}catch (InvalidNameException e) {//ignore, just use original name should this faildiff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/nougat/ArtHeader_NougatMR2Pixel.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/nougat/ArtHeader_NougatMR2Pixel.javaindex 31bbf6bf37..a4580ad827 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/nougat/ArtHeader_NougatMR2Pixel.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/nougat/ArtHeader_NougatMR2Pixel.java@@ -18,8 +18,6 @@ package ghidra.file.formats.android.art.nougat;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;-import ghidra.file.formats.android.art.ArtImageSections;import ghidra.program.model.data.DataType;import ghidra.program.model.data.Structure;import ghidra.util.InvalidNameException;@@ -34,10 +32,6 @@ public class ArtHeader_NougatMR2Pixel extends ArtHeader_Nougat {super(reader);}- protected ArtImageSections getImageSections(BinaryReader reader) {- return new ImageSections_NougatMR2Pixel(reader, this);- }-@Overridepublic int getArtMethodCountForVersion() {return ImageMethod_Nougat.kImageMethodsCount.ordinal();@@ -46,9 +40,8 @@ public class ArtHeader_NougatMR2Pixel extends ArtHeader_Nougat {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {Structure structure = (Structure) super.toDataType();- String className = StructConverterUtil.parseName(ArtHeader_NougatMR2Pixel.class);try {- structure.setName(className);+ structure.setName(ArtHeader_NougatMR2Pixel.class.getSimpleName());}catch (InvalidNameException e) {//ignorediff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/oreo/ArtHeader_Oreo.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/oreo/ArtHeader_Oreo.javaindex d3837fcce8..dca9f0c7ce 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/oreo/ArtHeader_Oreo.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/oreo/ArtHeader_Oreo.java@@ -18,8 +18,6 @@ package ghidra.file.formats.android.art.oreo;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;-import ghidra.file.formats.android.art.ArtImageSections;import ghidra.file.formats.android.art.nougat.ArtHeader_NougatMR2Pixel;import ghidra.program.model.data.DataType;import ghidra.program.model.data.Structure;@@ -35,10 +33,6 @@ public class ArtHeader_Oreo extends ArtHeader_NougatMR2Pixel {super(reader);}- protected ArtImageSections getImageSections(BinaryReader reader) {- return new ImageSections_Oreo(reader, this);- }-@Overridepublic int getArtMethodCountForVersion() {return ImageMethod_Oreo.kImageMethodsCount.ordinal();@@ -47,9 +41,8 @@ public class ArtHeader_Oreo extends ArtHeader_NougatMR2Pixel {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {Structure structure = (Structure) super.toDataType();- String className = StructConverterUtil.parseName(ArtHeader_Oreo.class);try {- structure.setName(className);+ structure.setName(ArtHeader_Oreo.class.getSimpleName());}catch (InvalidNameException e) {//ignorediff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/oreo/ArtHeader_OreoMR1.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/oreo/ArtHeader_OreoMR1.javaindex e61493ad68..bdd85ba7aa 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/oreo/ArtHeader_OreoMR1.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/oreo/ArtHeader_OreoMR1.java@@ -18,8 +18,6 @@ package ghidra.file.formats.android.art.oreo;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;-import ghidra.file.formats.android.art.ArtImageSections;import ghidra.program.model.data.DataType;import ghidra.program.model.data.Structure;import ghidra.util.InvalidNameException;@@ -34,10 +32,6 @@ public class ArtHeader_OreoMR1 extends ArtHeader_Oreo {super(reader);}- protected ArtImageSections getImageSections(BinaryReader reader) {- return new ImageSections_OreoMR1(reader, this);- }-@Overridepublic int getArtMethodCountForVersion() {return ImageMethod_Oreo.kImageMethodsCount.ordinal();@@ -46,9 +40,8 @@ public class ArtHeader_OreoMR1 extends ArtHeader_Oreo {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {Structure structure = (Structure) super.toDataType();- String className = StructConverterUtil.parseName(ArtHeader_OreoMR1.class);try {- structure.setName(className);+ structure.setName(ArtHeader_OreoMR1.class.getSimpleName());}catch (InvalidNameException e) {//ignorediff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/pie/ArtHeader_Pie.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/pie/ArtHeader_Pie.javaindex ea3c5bff2f..d4351141d6 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/pie/ArtHeader_Pie.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/art/pie/ArtHeader_Pie.java@@ -18,7 +18,6 @@ package ghidra.file.formats.android.art.pie;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;import ghidra.file.formats.android.art.*;import ghidra.file.formats.android.util.DecompressionManager;import ghidra.program.model.data.DataType;@@ -82,7 +81,7 @@ public class ArtHeader_Pie extends ArtHeader implements ArtCompression {compile_pic_ = reader.readNextInt();is_pic_ = reader.readNextInt();- sections = new ImageSections_Pie(reader, this);+ sections = ArtImageSectionsFactory.getArtImageSections(reader, this);sections.parseSections(reader);parseImageMethods(reader);@@ -205,9 +204,8 @@ public class ArtHeader_Pie extends ArtHeader implements ArtCompression {public DataType toDataType() throws DuplicateNameException, IOException {Structure structure = (Structure) super.toDataType();- String className = StructConverterUtil.parseName(ArtHeader_Pie.class);try {- structure.setName(className);+ structure.setName(ArtHeader_Pie.class.getSimpleName());}catch (InvalidNameException e) {//ignorediff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/bootimg/BootImageHeaderV0.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/bootimg/BootImageHeaderV0.javaindex 1bdd5ec5a5..e46a495494 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/bootimg/BootImageHeaderV0.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/bootimg/BootImageHeaderV0.java@@ -94,7 +94,7 @@ public class BootImageHeaderV0 extends BootImageHeader {@Overridepublic int getRamdiskOffset() {- return page_size + getKernelPageCount() * page_size;//see header comment...+ return page_size + getKernelPageCount() * page_size;}public int getRamdiskAddress() {diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/bootimg/BootImageHeaderV3.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/bootimg/BootImageHeaderV3.javaindex 7ea072c480..5b9f7cee30 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/bootimg/BootImageHeaderV3.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/bootimg/BootImageHeaderV3.java@@ -67,7 +67,7 @@ public class BootImageHeaderV3 extends BootImageHeader {*/@Overridepublic int getKernelPageCount() {- return (int)(pageAlign(kernel_size) / BootImageConstants.V3_PAGE_SIZE);+ return (int) (pageAlign(kernel_size) / BootImageConstants.V3_PAGE_SIZE);}@Overridediff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/cdex/CDexLoader.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/cdex/CDexLoader.javaindex e92522141d..e654251e53 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/cdex/CDexLoader.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/cdex/CDexLoader.java@@ -16,21 +16,14 @@package ghidra.file.formats.android.cdex;import java.io.IOException;-import java.io.InputStream;import java.util.*;-import ghidra.app.util.Option;import ghidra.app.util.bin.BinaryReader;import ghidra.app.util.bin.ByteProvider;-import ghidra.app.util.importer.MessageLog;import ghidra.app.util.opinion.*;import ghidra.file.formats.android.dex.DexHeaderFactory;-import ghidra.file.formats.android.dex.format.*;-import ghidra.file.formats.android.dex.util.DexUtil;-import ghidra.program.model.address.Address;-import ghidra.program.model.listing.Program;-import ghidra.program.model.mem.MemoryBlock;-import ghidra.util.task.TaskMonitor;+import ghidra.file.formats.android.dex.format.DexConstants;+import ghidra.file.formats.android.dex.format.DexHeader;public class CDexLoader extends DexLoader {@@ -82,98 +75,18 @@ public class CDexLoader extends DexLoader {}@Override- public void load(ByteProvider provider, LoadSpec loadSpec, List<Option> options,- Program program, TaskMonitor monitor, MessageLog log) throws IOException {-- monitor.setMessage("CDEX Loader: creating cdex memory");- try {- Address start = program.getAddressFactory().getDefaultAddressSpace().getAddress(0x0);- long length = provider.length();-- try (InputStream inputStream = provider.getInputStream(0)) {- program.getMemory()- .createInitializedBlock(".cdex", start, inputStream, length, monitor,- false);- }-- BinaryReader reader = new BinaryReader(provider, true);- DexHeader header = DexHeaderFactory.getDexHeader(reader);-- monitor.setMessage("CDEX Loader: creating method byte code");-- createMethodLookupMemoryBlock(program, monitor);- createMethodByteCodeBlock(program, length, monitor);-- for (ClassDefItem item : header.getClassDefs()) {- monitor.checkCanceled();-- ClassDataItem classDataItem = item.getClassDataItem();- if (classDataItem == null) {- continue;- }-- createMethods(program, header, item, classDataItem.getDirectMethods(), monitor,- log);- createMethods(program, header, item, classDataItem.getVirtualMethods(), monitor,- log);- }- }- catch (Exception e) {- log.appendException(e);- }+ protected String getMemoryBlockName() {+ return ".cdex";}- private void createMethodByteCodeBlock(Program program, long length, TaskMonitor monitor)- throws Exception {- Address address = toAddr(program, DexUtil.METHOD_ADDRESS);- MemoryBlock block = program.getMemory()- .createInitializedBlock("method_bytecode", address, length, (byte) 0xff, monitor,- false);- block.setRead(true);- block.setWrite(false);- block.setExecute(true);- }-- private void createMethodLookupMemoryBlock(Program program, TaskMonitor monitor)- throws Exception {- Address address = toAddr(program, DexUtil.LOOKUP_ADDRESS);- MemoryBlock block = program.getMemory()- .createInitializedBlock("method_lookup", address, DexUtil.MAX_METHOD_LENGTH,- (byte) 0xff, monitor, false);- block.setRead(true);- block.setWrite(false);- block.setExecute(false);- }-- private void createMethods(Program program, DexHeader header, ClassDefItem item,- List<EncodedMethod> methods, TaskMonitor monitor, MessageLog log) throws Exception {- for (int i = 0; i < methods.size(); ++i) {- monitor.checkCanceled();-- EncodedMethod encodedMethod = methods.get(i);-- CodeItem codeItem = encodedMethod.getCodeItem();-- Address methodIndexAddress =- DexUtil.toLookupAddress(program, encodedMethod.getMethodIndex());-- if (codeItem == null) {- //external method, ignore- }- else {- Address methodAddress =- toAddr(program, DexUtil.METHOD_ADDRESS + encodedMethod.getCodeOffset());-- byte[] instructionBytes = codeItem.getInstructionBytes();- program.getMemory().setBytes(methodAddress, instructionBytes);-- program.getMemory().setInt(methodIndexAddress, (int) methodAddress.getOffset());- }- }+ @Override+ protected String getMonitorMessagePrimary() {+ return "CDEX Loader: creating cdex memory";}- private Address toAddr(Program program, long offset) {- return program.getAddressFactory().getDefaultAddressSpace().getAddress(offset);+ @Override+ protected String getMonitorMessageSecondary() {+ return "CDEX Loader: creating method byte code";}}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/DexHeaderFactory.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/DexHeaderFactory.javaindex 76f9ab91a7..310f67393f 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/DexHeaderFactory.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/DexHeaderFactory.java@@ -74,16 +74,34 @@ public final class DexHeaderFactory {* @throws IOException should an error occur reading DEX bytes*/public final static DexHeader getDexHeader(BinaryReader reader) throws IOException {+ return getDexHeader(reader, true);+ }++ /**+ * Attempts to create DEX header using the specified Byte Provider.+ * NOTE: Use a new binary reader instance, where the underlying ByteProvider is+ * based to start of DEX/CDEX. Reading CDEX format requires lots of re-indexing.+ * @param reader the binary reader to use to create DEX header+ * @param fullParse true if parse method should be invoked+ * @return the DEX header+ * @throws IOException should an error occur reading DEX bytes+ */+ public final static DexHeader getDexHeader(BinaryReader reader, boolean fullParse)+ throws IOException {long index = reader.getPointerIndex();String magic = new String(reader.readByteArray(index, 4));if (DexConstants.DEX_MAGIC_BASE.equals(magic)) {DexHeader header = new DexHeader(reader);- header.parse(reader);+ if (fullParse) {+ header.parse(reader);+ }return header;}if (CDexConstants.MAGIC.equals(magic)) {CDexHeader header = new CDexHeader(reader);- header.parse(reader);+ if (fullParse) {+ header.parse(reader);+ }return header;}throw new IOException("Not a recognized DEX/CDEX variant: " + magic);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/analyzer/DexAnalysisState.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/analyzer/DexAnalysisState.javaindex 366cb893c4..abdd1fb5db 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/analyzer/DexAnalysisState.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/analyzer/DexAnalysisState.java@@ -24,7 +24,6 @@ import ghidra.app.plugin.core.analysis.AnalysisStateInfo;import ghidra.file.formats.android.dex.DexHeaderFactory;import ghidra.file.formats.android.dex.format.*;import ghidra.file.formats.android.dex.util.DexUtil;-import ghidra.framework.main.AppInfo;import ghidra.program.model.address.Address;import ghidra.program.model.address.AddressSpace;import ghidra.program.model.listing.Program;diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/analyzer/DexHeaderFormatAnalyzer.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/analyzer/DexHeaderFormatAnalyzer.javaindex 0955a35b14..9d3369ec8d 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/analyzer/DexHeaderFormatAnalyzer.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/analyzer/DexHeaderFormatAnalyzer.java@@ -23,13 +23,20 @@ import ghidra.app.util.importer.MessageLog;import ghidra.file.analyzers.FileFormatAnalyzer;import ghidra.file.formats.android.cdex.CDexConstants;import ghidra.file.formats.android.dex.format.DexConstants;+import ghidra.framework.options.Options;import ghidra.program.model.address.Address;import ghidra.program.model.address.AddressSetView;import ghidra.program.model.listing.Program;+import ghidra.util.exception.NotEmptyException;import ghidra.util.task.TaskMonitor;public class DexHeaderFormatAnalyzer extends FileFormatAnalyzer {+ private static final String CREATE_FRAGMENTS_OPTION_NAME = "Create Fragments";+ private static final boolean CREATE_FRAGMENTS_DEFAULT = true;++ private boolean isCreateFragments = CREATE_FRAGMENTS_DEFAULT;+@Overridepublic boolean analyze(Program program, AddressSetView set, TaskMonitor monitor, MessageLog log)throws Exception {@@ -41,12 +48,21 @@ public class DexHeaderFormatAnalyzer extends FileFormatAnalyzer {return true;}- DexHeaderFormatMarkup markup = new DexHeaderFormatMarkup(program, baseAddress);+ DexHeaderFormatMarkup markup = new DexHeaderFormatMarkup(this, program, baseAddress);markup.markup(monitor, log);return true;}+ boolean isCreateFragments() {+ return isCreateFragments;+ }++ @Override+ public void removeEmptyFragments(Program program) throws NotEmptyException {+ super.removeEmptyFragments(program);+ }+@Overridepublic boolean canAnalyze(Program program) {ByteProvider provider =@@ -83,4 +99,20 @@ public class DexHeaderFormatAnalyzer extends FileFormatAnalyzer {public boolean isPrototype() {return false;}++ @Override+ public void registerOptions(Options options, Program program) {+ super.registerOptions(options, program);//do super+ options.registerOption(CREATE_FRAGMENTS_OPTION_NAME, CREATE_FRAGMENTS_DEFAULT, null,+ "If selected, then create Program Tree fragments for each DEX element. Disable to speed up analysis.");+ }++ @Override+ public void optionsChanged(Options options, Program program) {+ super.optionsChanged(options, program);//do super++ isCreateFragments = options.getBoolean(CREATE_FRAGMENTS_OPTION_NAME,+ CREATE_FRAGMENTS_DEFAULT);+ }+}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/analyzer/DexHeaderFormatMarkup.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/analyzer/DexHeaderFormatMarkup.javaindex b43c7fc575..544ce1898d 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/analyzer/DexHeaderFormatMarkup.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/analyzer/DexHeaderFormatMarkup.java@@ -22,86 +22,39 @@ import java.util.List;import ghidra.app.cmd.disassemble.DisassembleCommand;import ghidra.app.util.importer.MessageLog;import ghidra.file.formats.android.cdex.CDexCodeItem;-import ghidra.file.formats.android.dex.format.AccessFlags;-import ghidra.file.formats.android.dex.format.AnnotationItem;-import ghidra.file.formats.android.dex.format.AnnotationSetItem;-import ghidra.file.formats.android.dex.format.AnnotationSetReferenceItem;-import ghidra.file.formats.android.dex.format.AnnotationSetReferenceList;-import ghidra.file.formats.android.dex.format.AnnotationsDirectoryItem;-import ghidra.file.formats.android.dex.format.ClassDataItem;-import ghidra.file.formats.android.dex.format.ClassDefItem;-import ghidra.file.formats.android.dex.format.CodeItem;-import ghidra.file.formats.android.dex.format.DebugInfoItem;-import ghidra.file.formats.android.dex.format.DexHeader;-import ghidra.file.formats.android.dex.format.EncodedArrayItem;-import ghidra.file.formats.android.dex.format.EncodedCatchHandler;-import ghidra.file.formats.android.dex.format.EncodedCatchHandlerList;-import ghidra.file.formats.android.dex.format.EncodedField;-import ghidra.file.formats.android.dex.format.EncodedMethod;-import ghidra.file.formats.android.dex.format.FieldAnnotationsItem;-import ghidra.file.formats.android.dex.format.FieldIDItem;-import ghidra.file.formats.android.dex.format.MapItem;-import ghidra.file.formats.android.dex.format.MapItemTypeCodes;-import ghidra.file.formats.android.dex.format.MapList;-import ghidra.file.formats.android.dex.format.MethodAnnotationsItem;-import ghidra.file.formats.android.dex.format.MethodIDItem;-import ghidra.file.formats.android.dex.format.ParameterAnnotationsItem;-import ghidra.file.formats.android.dex.format.PrototypesIDItem;-import ghidra.file.formats.android.dex.format.StringDataItem;-import ghidra.file.formats.android.dex.format.StringIDItem;-import ghidra.file.formats.android.dex.format.TryItem;-import ghidra.file.formats.android.dex.format.TypeIDItem;-import ghidra.file.formats.android.dex.format.TypeItem;-import ghidra.file.formats.android.dex.format.TypeList;+import ghidra.file.formats.android.dex.format.*;import ghidra.file.formats.android.dex.util.DexUtil;import ghidra.program.database.ProgramCompilerSpec;import ghidra.program.flatapi.FlatProgramAPI;import ghidra.program.model.address.Address;-import ghidra.program.model.data.CategoryPath;-import ghidra.program.model.data.DWordDataType;-import ghidra.program.model.data.DataType;-import ghidra.program.model.data.DataTypeConflictHandler;-import ghidra.program.model.data.DataTypeManager;-import ghidra.program.model.data.PointerDataType;-import ghidra.program.model.data.TypedefDataType;+import ghidra.program.model.data.*;import ghidra.program.model.lang.Language;import ghidra.program.model.lang.Register;-import ghidra.program.model.listing.Data;-import ghidra.program.model.listing.Function;+import ghidra.program.model.listing.*;import ghidra.program.model.listing.Function.FunctionUpdateType;-import ghidra.program.model.listing.Group;-import ghidra.program.model.listing.LocalVariableImpl;-import ghidra.program.model.listing.ParameterImpl;-import ghidra.program.model.listing.Program;-import ghidra.program.model.listing.ProgramFragment;-import ghidra.program.model.listing.ProgramModule;-import ghidra.program.model.listing.ReturnParameterImpl;-import ghidra.program.model.listing.Variable;import ghidra.program.model.mem.Memory;import ghidra.program.model.mem.MemoryBlock;-import ghidra.program.model.symbol.Namespace;-import ghidra.program.model.symbol.RefType;-import ghidra.program.model.symbol.SourceType;-import ghidra.program.model.symbol.Symbol;-import ghidra.program.model.symbol.SymbolTable;-import ghidra.program.model.symbol.SymbolUtilities;+import ghidra.program.model.symbol.*;import ghidra.util.NumericUtilities;-import ghidra.util.exception.CancelledException;-import ghidra.util.exception.DuplicateNameException;-import ghidra.util.exception.InvalidInputException;-import ghidra.util.exception.NotEmptyException;+import ghidra.util.exception.*;import ghidra.util.task.TaskMonitor;public class DexHeaderFormatMarkup {+ private DexHeaderFormatAnalyzer analyzer;private Program program;private Address baseAddress;private FlatProgramAPI api;+ private DexHeaderFragmentManager fragmentManager;- public DexHeaderFormatMarkup(Program program, Address baseAddress) {+ public DexHeaderFormatMarkup(DexHeaderFormatAnalyzer analyzer, Program program,+ Address baseAddress) {+ this.analyzer = analyzer;this.program = program;this.baseAddress = baseAddress;this.api = new FlatProgramAPI(program);+ this.fragmentManager =+ new DexHeaderFragmentManager(program, baseAddress, api, analyzer.isCreateFragments());}public boolean markup(TaskMonitor monitor, MessageLog log) throws Exception {@@ -121,7 +74,7 @@ public class DexHeaderFormatMarkup {DexHeader header = analysisState.getHeader();processHeader(header);- createInitialFragments(header, monitor);+ fragmentManager.createInitialFragments(header, monitor);ProgramCompilerSpec.enableJavaLanguageDecompilation(program);createNamespaces(header, monitor, log);@@ -136,14 +89,17 @@ public class DexHeaderFormatMarkup {createMethods(header, monitor, log);+ fragmentManager.createFragments(monitor, log);+monitor.setMessage("DEX: cleaning up tree");- removeEmptyFragments();+ analyzer.removeEmptyFragments(program);return true;}private void createNamespaces(DexHeader header, TaskMonitor monitor, MessageLog log)throws Exception {+monitor.setMessage("DEX: creating namespaces");monitor.setMaximum(header.getClassDefsIdsSize());monitor.setProgress(0);@@ -167,6 +123,7 @@ public class DexHeaderFormatMarkup {private void createMethods(DexHeader header, TaskMonitor monitor, MessageLog log)throws Exception {+monitor.setMessage("DEX: creating methods");monitor.setMaximum(header.getClassDefsIdsSize());monitor.setProgress(0);@@ -186,6 +143,7 @@ public class DexHeaderFormatMarkup {private void createMethods(DexHeader header, ClassDefItem item, List<EncodedMethod> methods,TaskMonitor monitor, MessageLog log) throws Exception {+String className = DexUtil.convertTypeIndexToString(header, item.getClassIndex());Namespace classNameSpace = DexUtil.createNameSpaceFromMangledClassName(program, className);if (classNameSpace == null) {@@ -232,6 +190,7 @@ public class DexHeaderFormatMarkup {private Symbol createMethodSymbol(Address methodAddress, String methodName,Namespace classNameSpace, MessageLog log) {+program.getSymbolTable().addExternalEntryPoint(methodAddress);try {return program.getSymbolTable()@@ -289,9 +248,8 @@ public class DexHeaderFormatMarkup {int registerIndex = codeItem.getRegistersSize() - codeItem.getIncomingSize();- //TODO create local variables in betweenfor (int i = 0; i < registerIndex; ++i) {- DataType localDataType = null;//TODO+ DataType localDataType = null;//default to UndefinedDataType of appropriate sizeRegister localRegister = language.getRegister("v" + i);try {LocalVariableImpl local =@@ -303,7 +261,7 @@ public class DexHeaderFormatMarkup {}}- Variable returnVar = null;+ Variable returnVar = null;//default to UndefinedDataType of appropriate sizeList<Variable> paramList = new ArrayList<>();int prototypeIndex = Short.toUnsignedInt(methodID.getProtoIndex());@@ -373,11 +331,12 @@ public class DexHeaderFormatMarkup {Address headerAddress = baseAddress.add(0x0);DataType headerDataType = header.toDataType();api.createData(headerAddress, headerDataType);- api.createFragment("header", headerAddress, headerDataType.getLength());+ fragmentManager.createHeaderFragment(headerAddress, headerDataType);}private void processClassDefs(DexHeader header, TaskMonitor monitor, MessageLog log)throws Exception {+monitor.setMessage("DEX: processing class definitions");monitor.setMaximum(header.getClassDefsIdsSize());monitor.setProgress(0);@@ -392,7 +351,7 @@ public class DexHeaderFormatMarkup {DataType dataType = item.toDataType();api.createData(address, dataType);- api.createFragment("classes", address, dataType.getLength());+ fragmentManager.classesAddressSet.add(address, address.add(dataType.getLength() - 1));createClassDefSymbol(header, item, address);processClassInterfaces(header, item, monitor);@@ -409,6 +368,7 @@ public class DexHeaderFormatMarkup {private void createProgramDataTypes(DexHeader header, TaskMonitor monitor, MessageLog log)throws CancelledException {+monitor.setMessage("DEX: creating program datatypes");monitor.setMaximum(header.getTypeIdsSize());monitor.setProgress(0);@@ -469,13 +429,15 @@ public class DexHeaderFormatMarkup {private void processClassStaticValues(DexHeader header, ClassDefItem item, TaskMonitor monitor)throws DuplicateNameException, IOException, Exception {+if (item.getStaticValuesOffset() > 0) {EncodedArrayItem staticValues = item.getStaticValues();Address staticAddress =baseAddress.add(DexUtil.adjustOffset(item.getStaticValuesOffset(), header));DataType staticDataType = staticValues.toDataType();api.createData(staticAddress, staticDataType);- api.createFragment("class_static_values", staticAddress, staticDataType.getLength());+ fragmentManager.classStaticValuesAddressSet.add(staticAddress,+ staticAddress.add(staticDataType.getLength() - 1));StringBuilder builder = new StringBuilder();builder.append("Class: " +@@ -489,6 +451,7 @@ public class DexHeaderFormatMarkup {private void processClassDataItem(DexHeader header, ClassDefItem item, TaskMonitor monitor,MessageLog log) throws DuplicateNameException, IOException, Exception {+if (item.getClassDataOffset() > 0) {ClassDataItem classDataItem = item.getClassDataItem();Address classDataAddress =@@ -501,7 +464,8 @@ public class DexHeaderFormatMarkup {log.appendMsg("Unable to create class data item at " + classDataAddress);return;}- api.createFragment("class_data", classDataAddress, classDataDataType.getLength());+ fragmentManager.classDataAddressSet.add(classDataAddress,+ classDataAddress.add(classDataDataType.getLength() - 1));StringBuilder builder = new StringBuilder();builder.append("Class: " +@@ -523,6 +487,7 @@ public class DexHeaderFormatMarkup {private void processEncodedFields(DexHeader header, List<EncodedField> instanceFields,TaskMonitor monitor) throws Exception {+int index = 0;for (int i = 0; i < instanceFields.size(); ++i) {monitor.checkCanceled();@@ -548,12 +513,14 @@ public class DexHeaderFormatMarkup {DataType dataType = field.toDataType();api.createData(address, dataType);api.setPlateComment(address, builder.toString());- api.createFragment("encoded_fields", address, dataType.getLength());+ fragmentManager.encodedFieldsAddressSet.add(address,+ address.add(dataType.getLength() - 1));}}private void processEncodedMethods(DexHeader header, ClassDefItem item,List<EncodedMethod> methods, TaskMonitor monitor) throws Exception {+for (int i = 0; i < methods.size(); ++i) {monitor.checkCanceled();@@ -574,7 +541,8 @@ public class DexHeaderFormatMarkup {DataType dataType = method.toDataType();api.createData(address, dataType);api.setPlateComment(address, builder.toString());- api.createFragment("encoded_methods", address, dataType.getLength());+ fragmentManager.encodedMethodsAddressSet.add(address,+ address.add(dataType.getLength() - 1));processCodeItem(header, item, method, methodID);}@@ -621,7 +589,9 @@ public class DexHeaderFormatMarkup {int codeItemDataTypeLength = codeItemDataType.getLength();- api.createFragment("code_item", codeAddress, codeItemDataTypeLength);+ fragmentManager.codeItemAddressSet.add(codeAddress,+ codeAddress.add(codeItemDataTypeLength - 1));+Address tempAddress = codeAddress.add(codeItemDataTypeLength);tempAddress = processCodeItemTrys(tempAddress, codeItem);processCodeItemHandlers(codeItem, tempAddress);@@ -636,7 +606,8 @@ public class DexHeaderFormatMarkup {DebugInfoItem debug = codeItem.getDebugInfo();DataType debugDataType = debug.toDataType();api.createData(debugAddress, debugDataType);- api.createFragment("debug_info", debugAddress, debugDataType.getLength());+ fragmentManager.debugInfoAddressSet.add(debugAddress,+ debugAddress.add(debugDataType.getLength() - 1));}}}@@ -644,6 +615,7 @@ public class DexHeaderFormatMarkup {private void processCodeItemHandlers(CodeItem codeItem, Address tempAddress)throws DuplicateNameException, IOException, Exception {+EncodedCatchHandlerList handlerList = codeItem.getHandlerList();if (handlerList == null) {return;@@ -651,24 +623,28 @@ public class DexHeaderFormatMarkup {DataType handlerDataType = handlerList.toDataType();api.createData(tempAddress, handlerDataType);- api.createFragment("handlers", tempAddress, handlerDataType.getLength());+ fragmentManager.handlersAddressSet.add(tempAddress,+ tempAddress.add(handlerDataType.getLength() - 1));tempAddress = tempAddress.add(handlerDataType.getLength());for (EncodedCatchHandler handler : handlerList.getHandlers()) {DataType dataType = handler.toDataType();api.createData(tempAddress, dataType);- api.createFragment("handlers", tempAddress, dataType.getLength());+ fragmentManager.handlersAddressSet.add(tempAddress,+ tempAddress.add(dataType.getLength() - 1));tempAddress = tempAddress.add(dataType.getLength());}}private Address processCodeItemTrys(Address codeAddress, CodeItem codeItem)throws DuplicateNameException, IOException, Exception {+Address tempAddress = codeAddress;for (TryItem tryItem : codeItem.getTries()) {DataType dataType = tryItem.toDataType();api.createData(tempAddress, dataType);- api.createFragment("try", tempAddress, dataType.getLength());+ fragmentManager.tryAddressSet.add(tempAddress,+ tempAddress.add(dataType.getLength() - 1));tempAddress = tempAddress.add(dataType.getLength());}return tempAddress;@@ -677,13 +653,15 @@ public class DexHeaderFormatMarkup {private void processClassAnnotations(DexHeader header, ClassDefItem item, TaskMonitor monitor,MessageLog log)throws DuplicateNameException, IOException, Exception, CancelledException {+if (item.getAnnotationsOffset() > 0) {AnnotationsDirectoryItem annotationsDirectoryItem = item.getAnnotationsDirectoryItem();Address annotationsAddress =baseAddress.add(DexUtil.adjustOffset(item.getAnnotationsOffset(), header));DataType annotationsDataType = annotationsDirectoryItem.toDataType();api.createData(annotationsAddress, annotationsDataType);- api.createFragment("annotations", annotationsAddress, annotationsDataType.getLength());+ fragmentManager.annotationsAddressSet.add(annotationsAddress,+ annotationsAddress.add(annotationsDataType.getLength() - 1));if (annotationsDirectoryItem.getClassAnnotationsOffset() > 0) {Address classAddress = baseAddress.add(DexUtil.adjustOffset(@@ -691,7 +669,8 @@ public class DexHeaderFormatMarkup {AnnotationSetItem setItem = annotationsDirectoryItem.getClassAnnotations();DataType setItemDataType = setItem.toDataType();api.createData(classAddress, setItemDataType);- api.createFragment("class_annotations", classAddress, setItemDataType.getLength());+ fragmentManager.classAnnotationsAddressSet.add(classAddress,+ classAddress.add(setItemDataType.getLength() - 1));processAnnotationSetItem(setItem, monitor, log);}for (FieldAnnotationsItem field : annotationsDirectoryItem.getFieldAnnotations()) {@@ -701,7 +680,8 @@ public class DexHeaderFormatMarkup {AnnotationSetItem setItem = field.getAnnotationSetItem();DataType setItemDataType = setItem.toDataType();api.createData(fieldAddress, setItemDataType);- api.createFragment("annotation_fields", fieldAddress, setItemDataType.getLength());+ fragmentManager.annotationFieldsAddressSet.add(fieldAddress,+ fieldAddress.add(setItemDataType.getLength() - 1));processAnnotationSetItem(setItem, monitor, log);}for (MethodAnnotationsItem method : annotationsDirectoryItem.getMethodAnnotations()) {@@ -711,8 +691,8 @@ public class DexHeaderFormatMarkup {AnnotationSetItem setItem = method.getAnnotationSetItem();DataType setItemDataType = setItem.toDataType();api.createData(methodAddress, setItemDataType);- api.createFragment("annotation_methods", methodAddress,- setItemDataType.getLength());+ fragmentManager.annotationMethodsAddressSet.add(methodAddress,+ methodAddress.add(setItemDataType.getLength() - 1));processAnnotationSetItem(setItem, monitor, log);}for (ParameterAnnotationsItem parameter : annotationsDirectoryItem@@ -724,8 +704,8 @@ public class DexHeaderFormatMarkup {parameter.getAnnotationSetReferenceList();DataType listDataType = annotationSetReferenceList.toDataType();api.createData(parameterAddress, listDataType);- api.createFragment("annotation_parameters", parameterAddress,- listDataType.getLength());+ fragmentManager.annotationParametersAddressSet.add(parameterAddress,+ parameterAddress.add(listDataType.getLength() - 1));for (AnnotationSetReferenceItem refItem : annotationSetReferenceList.getItems()) {AnnotationItem annotationItem = refItem.getItem();@@ -735,8 +715,8 @@ public class DexHeaderFormatMarkup {baseAddress.add(DexUtil.adjustOffset(annotationsItemOffset, header));DataType annotationItemDataType = annotationItem.toDataType();api.createData(annotationItemAddress, annotationItemDataType);- api.createFragment("annotation_item", annotationItemAddress,- annotationItemDataType.getLength());+ fragmentManager.annotationItemAddressSet.add(annotationItemAddress,+ annotationItemAddress.add(annotationItemDataType.getLength() - 1));}}}@@ -745,13 +725,15 @@ public class DexHeaderFormatMarkup {private void processClassInterfaces(DexHeader header, ClassDefItem item, TaskMonitor monitor)throws Exception {+if (item.getInterfacesOffset() > 0) {TypeList interfaces = item.getInterfaces();Address interfaceAddress =baseAddress.add(DexUtil.adjustOffset(item.getInterfacesOffset(), header));DataType interfaceDataType = interfaces.toDataType();api.createData(interfaceAddress, interfaceDataType);- api.createFragment("interfaces", interfaceAddress, interfaceDataType.getLength());+ fragmentManager.interfacesAddressSet.add(interfaceAddress,+ interfaceAddress.add(interfaceDataType.getLength() - 1));StringBuilder builder = new StringBuilder();builder.append("Class: " +@@ -775,7 +757,7 @@ public class DexHeaderFormatMarkup {// AnnotationItem aItem = offsetItem.getItem();// DataType aDataType = aItem.toDataType();// api.createData( aAddress, aDataType);-// api.createFragment( "annotation_items", aAddress, aDataType.getLength());+// fragmentManager.annotationItemAddressSet.add(address, address.add( aDataType.getLength()-1));// }}catch (Exception e) {@@ -797,7 +779,7 @@ public class DexHeaderFormatMarkup {DataType dataType = item.toDataType();api.createData(address, dataType);- api.createFragment("methods", address, dataType.getLength());+ fragmentManager.methodsAddressSet.add(address, address.add(dataType.getLength() - 1));StringBuilder builder = new StringBuilder();builder.append("Method Index: 0x" + Integer.toHexString(methodIndex) + "\n");@@ -840,6 +822,7 @@ public class DexHeaderFormatMarkup {private void processFields(DexHeader header, TaskMonitor monitor, MessageLog log)throws Exception {+monitor.setMessage("DEX: processing fields");monitor.setMaximum(header.getFieldIdsSize());monitor.setProgress(0);@@ -850,7 +833,7 @@ public class DexHeaderFormatMarkup {monitor.incrementProgress(1);DataType dataType = item.toDataType();api.createData(address, dataType);- api.createFragment("fields", address, dataType.getLength());+ fragmentManager.fieldsAddressSet.add(address, address.add(dataType.getLength() - 1));StringBuilder builder = new StringBuilder();builder.append("Field Index: 0x" + Integer.toHexString(index) + "\n");@@ -869,6 +852,7 @@ public class DexHeaderFormatMarkup {private void processPrototypes(DexHeader header, TaskMonitor monitor, MessageLog log)throws Exception {+monitor.setMessage("DEX: processing prototypes");monitor.setMaximum(header.getProtoIdsSize());monitor.setProgress(0);@@ -879,7 +863,8 @@ public class DexHeaderFormatMarkup {monitor.incrementProgress(1);DataType dataType = item.toDataType();Data data = api.createData(address, dataType);- api.createFragment("prototypes", address, dataType.getLength());+ fragmentManager.prototypesAddressSet.add(address,+ address.add(dataType.getLength() - 1));StringBuilder builder = new StringBuilder();builder.append("Prototype Index: 0x" + Integer.toHexString(index) + "\n");@@ -921,6 +906,7 @@ public class DexHeaderFormatMarkup {private void processTypes(DexHeader header, TaskMonitor monitor, MessageLog log)throws Exception {+monitor.setMessage("DEX: processing types");monitor.setMaximum(header.getTypeIdsSize());monitor.setProgress(0);@@ -931,7 +917,7 @@ public class DexHeaderFormatMarkup {monitor.incrementProgress(1);DataType dataType = item.toDataType();api.createData(address, dataType);- api.createFragment("types", address, dataType.getLength());+ fragmentManager.typesAddressSet.add(address, address.add(dataType.getLength() - 1));StringBuilder builder = new StringBuilder();builder.append("Type Index: 0x" + Integer.toHexString(index) + "\n");@@ -946,6 +932,7 @@ public class DexHeaderFormatMarkup {private void processMap(DexHeader header, TaskMonitor monitor, MessageLog log)throws Exception {+MapList mapList = header.getMapList();if (mapList == null) {return;@@ -957,7 +944,8 @@ public class DexHeaderFormatMarkup {baseAddress.add(DexUtil.adjustOffset(header.getMapOffset(), header));DataType mapListDataType = mapList.toDataType();api.createData(mapListAddress, mapListDataType);- api.createFragment("map", mapListAddress, mapListDataType.getLength());+ fragmentManager.mapAddressSet.add(mapListAddress,+ mapListAddress.add(mapListDataType.getLength() - 1));StringBuilder builder = new StringBuilder();for (MapItem item : header.getMapList().getItems()) {monitor.checkCanceled();@@ -966,17 +954,9 @@ public class DexHeaderFormatMarkup {api.setPlateComment(mapListAddress, builder.toString());}- private void createInitialFragments(DexHeader header, TaskMonitor monitor) throws Exception {- monitor.setMessage("DEX: creating fragments");-- if (header.getDataSize() > 0) {- Address start = baseAddress.add(header.getDataOffset());- api.createFragment("data", start, header.getDataSize());- }- }-private void processStrings(DexHeader header, TaskMonitor monitor, MessageLog log)throws Exception {+monitor.setMessage("DEX: processing strings");monitor.setMaximum(header.getStringIdsSize());monitor.setProgress(0);@@ -1004,7 +984,8 @@ public class DexHeaderFormatMarkup {api.createData(stringDataAddress, stringDataType);api.setPlateComment(stringDataAddress,Integer.toHexString(index) + "\n" + string.trim());- api.createFragment("string_data", stringDataAddress, stringDataType.getLength());+ fragmentManager.stringDataAddressSet.add(stringDataAddress,+ stringDataAddress.add(stringDataType.getLength() - 1));createStringSymbol(stringDataAddress, string, "strings");}@@ -1019,7 +1000,8 @@ public class DexHeaderFormatMarkup {DataType dataType = item.toDataType();try {Data data = api.createData(address, dataType);- api.createFragment("strings", address, dataType.getLength());+ fragmentManager.stringsDataSet.add(address, address.add(dataType.getLength() - 1));+api.setPlateComment(address, "String Index: 0x" + Integer.toHexString(index) +"\nString: " + string.trim() + "\nString Data Address: " + stringDataAddress);createStringSymbol(address, string, "string_data");@@ -1055,16 +1037,4 @@ public class DexHeaderFormatMarkup {}}- protected void removeEmptyFragments() throws NotEmptyException {- ProgramModule rootModule = program.getListing().getRootModule("Program Tree");- Group[] children = rootModule.getChildren();- for (Group child : children) {- if (child instanceof ProgramFragment) {- ProgramFragment fragment = (ProgramFragment) child;- if (fragment.isEmpty()) {- rootModule.removeChild(fragment.getName());- }- }- }- }}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/analyzer/DexHeaderFragmentManager.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/analyzer/DexHeaderFragmentManager.javanew file mode 100644index 0000000000..6ab71a28a1--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/analyzer/DexHeaderFragmentManager.java@@ -0,0 +1,148 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.dex.analyzer;++import ghidra.app.util.importer.MessageLog;+import ghidra.file.formats.android.dex.format.CodeItem;+import ghidra.file.formats.android.dex.format.DexHeader;+import ghidra.program.flatapi.FlatProgramAPI;+import ghidra.program.model.address.*;+import ghidra.program.model.data.DataType;+import ghidra.program.model.listing.*;+import ghidra.util.exception.*;+import ghidra.util.task.TaskMonitor;++/**+ * A class to manage DEX fragment creation.+ * Allows address ranges to coalesce before being created.+ * Fragment creation is slow, so support option to skip it.+ */+class DexHeaderFragmentManager {++ private Program program;+ private Address baseAddress;+ private FlatProgramAPI api;+ private boolean isCreateFragments;++ AddressSet classesAddressSet = new AddressSet();+ AddressSet classStaticValuesAddressSet = new AddressSet();+ AddressSet classDataAddressSet = new AddressSet();+ AddressSet codeItemAddressSet = new AddressSet();+ AddressSet encodedFieldsAddressSet = new AddressSet();+ AddressSet encodedMethodsAddressSet = new AddressSet();+ AddressSet debugInfoAddressSet = new AddressSet();+ AddressSet handlersAddressSet = new AddressSet();+ AddressSet tryAddressSet = new AddressSet();+ AddressSet annotationsAddressSet = new AddressSet();+ AddressSet classAnnotationsAddressSet = new AddressSet();+ AddressSet annotationFieldsAddressSet = new AddressSet();+ AddressSet annotationMethodsAddressSet = new AddressSet();+ AddressSet annotationParametersAddressSet = new AddressSet();+ AddressSet annotationItemAddressSet = new AddressSet();+ AddressSet interfacesAddressSet = new AddressSet();+ AddressSet methodsAddressSet = new AddressSet();+ AddressSet fieldsAddressSet = new AddressSet();+ AddressSet prototypesAddressSet = new AddressSet();+ AddressSet typesAddressSet = new AddressSet();+ AddressSet mapAddressSet = new AddressSet();+ AddressSet stringDataAddressSet = new AddressSet();+ AddressSet stringsDataSet = new AddressSet();++ AddressSet[] addressSets = new AddressSet[] {+ classesAddressSet, classStaticValuesAddressSet, classDataAddressSet,+ codeItemAddressSet,+ encodedFieldsAddressSet, encodedMethodsAddressSet,+ debugInfoAddressSet, handlersAddressSet, tryAddressSet,+ annotationsAddressSet, classAnnotationsAddressSet,+ annotationFieldsAddressSet, annotationMethodsAddressSet,+ annotationParametersAddressSet, annotationItemAddressSet,+ interfacesAddressSet, methodsAddressSet, fieldsAddressSet,+ prototypesAddressSet, typesAddressSet, mapAddressSet,+ stringDataAddressSet, stringsDataSet,+ };++ private String[] addressSetNames = new String[] {+ "classes", "class_static_values", "class_data", CodeItem.CODE_ITEM,+ "encoded_fields", "encoded_methods", "debug_info",+ "handlers", "try", "annotations", "class_annotations",+ "annotation_fields", "annotation_methods", "annotation_parameters", "annotation_item",+ "interfaces", "methods", "fields", "prototypes", "types", "map", "string_data", "strings",+ };++ DexHeaderFragmentManager(Program program, Address baseAddress, FlatProgramAPI api,+ boolean isCreateFragments) {+ this.program = program;+ this.baseAddress = baseAddress;+ this.api = api;+ this.isCreateFragments = isCreateFragments;+ }++ void createFragments(TaskMonitor monitor, MessageLog log) throws CancelledException {+ if (!isCreateFragments) {+ return;+ }+ monitor.initialize(addressSetNames.length);+ for (int i = 0; i < addressSetNames.length; i++) {+ createFragment(addressSetNames[i], addressSets[i], monitor, log);+ }+ }++ void createFragment(String fragmentName, AddressSet addressSet, TaskMonitor monitor,+ MessageLog log) throws CancelledException {++ if (!isCreateFragments) {+ return;+ }+ monitor.incrementProgress(1);+ monitor.checkCanceled();+ monitor.setMessage("DEX: creating fragment: " + fragmentName + " ...");+ try {+ ProgramModule module = program.getListing().getDefaultRootModule();+ ProgramFragment fragment = api.getFragment(module, fragmentName);+ if (fragment == null) {+ fragment = module.createFragment(fragmentName);+ }+ for (AddressRange range : addressSet) {+ monitor.checkCanceled();+ fragment.move(range.getMinAddress(), range.getMaxAddress());+ }+ }+ catch (Exception e) {+ log.appendMsg(e.getMessage());+ }+ }++ void createInitialFragments(DexHeader header, TaskMonitor monitor) throws Exception {+ if (!isCreateFragments) {+ return;+ }++ monitor.setMessage("DEX: creating fragments");+ if (header.getDataSize() > 0) {+ Address start = baseAddress.add(header.getDataOffset());+ api.createFragment("data", start, header.getDataSize());+ }+ }++ void createHeaderFragment(Address headerAddress, DataType headerDataType)+ throws DuplicateNameException, NotFoundException {++ if (!isCreateFragments) {+ return;+ }+ api.createFragment("header", headerAddress, headerDataType.getLength());+ }+}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/format/CodeItem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/format/CodeItem.javaindex 2e5910bf3c..ea77c94d3f 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/format/CodeItem.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/format/CodeItem.java@@ -40,6 +40,8 @@ import ghidra.util.exception.DuplicateNameException;*/public class CodeItem implements StructConverter {+ public static final String CODE_ITEM = "code_item";+protected short registersSize;protected short incomingSize;protected short outgoingSize;@@ -200,7 +202,7 @@ public class CodeItem implements StructConverter {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {String suffix = hasPadding() ? "_p" : "";- String name = "code_item" + "_" + (instructionSize * 2) + suffix;+ String name = CODE_ITEM + "_" + (instructionSize * 2) + suffix;Structure structure = new StructureDataType(name, 0);structure.add(WORD, "registers_size", null);structure.add(WORD, "ins_size", null);@@ -212,16 +214,6 @@ public class CodeItem implements StructConverter {if (hasPadding()) {structure.add(WORD, "padding", null);}- // for ( int i = 0 ; i < tries.size( ) ; ++i ) {- // DataType dataType = tries.get( i ).toDataType( );- // structure.add( dataType, "tries_" + i, null );- // unique = dataType.getLength( );- // }- // if ( triesSize != 0 ) {- // DataType dataType = handlers.toDataType( );- // structure.add( dataType, "handlers", null );- // unique = dataType.getLength( );- // }structure.setCategoryPath(new CategoryPath("/dex/code_item"));return structure;}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/fbpk/FBPK.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/fbpk/FBPK.javaindex 78da4b1b8e..c4e5c2b24c 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/fbpk/FBPK.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/fbpk/FBPK.java@@ -19,7 +19,8 @@ import java.io.IOException;import java.util.ArrayList;import java.util.List;-import ghidra.app.util.bin.*;+import ghidra.app.util.bin.BinaryReader;+import ghidra.app.util.bin.StructConverter;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;@@ -71,8 +72,7 @@ public class FBPK implements StructConverter {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(FBPK.class);- Structure struct = new StructureDataType(className, 0);+ Structure struct = new StructureDataType(FBPK.class.getSimpleName(), 0);struct.add(STRING, FBPK_Constants.FBPK.length(), "magic", null);struct.add(DWORD, "unknown1", null);struct.add(STRING, FBPK_Constants.VERSION_MAX_LENGTH, "version", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/fbpk/FBPK_Partition.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/fbpk/FBPK_Partition.javaindex 1c142981f1..9158adfc00 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/fbpk/FBPK_Partition.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/fbpk/FBPK_Partition.java@@ -92,8 +92,7 @@ public class FBPK_Partition implements StructConverter {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(FBPK_Partition.class);- Structure struct = new StructureDataType(className, 0);+ Structure struct = new StructureDataType(FBPK_Partition.class.getSimpleName(), 0);struct.add(DWORD, "type", null);struct.add(STRING, FBPK_Constants.NAME_MAX_LENGTH, "name", null);struct.add(DWORD, "dataSize", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/fbpk/FBPT.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/fbpk/FBPT.javaindex f993d194ef..dd3cfd6892 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/fbpk/FBPT.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/fbpk/FBPT.java@@ -19,7 +19,8 @@ import java.io.IOException;import java.util.ArrayList;import java.util.List;-import ghidra.app.util.bin.*;+import ghidra.app.util.bin.BinaryReader;+import ghidra.app.util.bin.StructConverter;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;@@ -147,8 +148,7 @@ public class FBPT implements StructConverter {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(FBPT.class);- Structure struct = new StructureDataType(className, 0);+ Structure struct = new StructureDataType(FBPT.class.getSimpleName(), 0);struct.add(STRING, FBPK_Constants.FBPT.length(), "magic", null);struct.add(DWORD, "unknown1", null);struct.add(DWORD, "unknown2", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/fbpk/FBPT_Entry.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/fbpk/FBPT_Entry.javaindex 14152e2647..096e526414 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/fbpk/FBPT_Entry.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/fbpk/FBPT_Entry.java@@ -17,7 +17,8 @@ package ghidra.file.formats.android.fbpk;import java.io.IOException;-import ghidra.app.util.bin.*;+import ghidra.app.util.bin.BinaryReader;+import ghidra.app.util.bin.StructConverter;import ghidra.program.model.data.*;import ghidra.util.InvalidNameException;import ghidra.util.exception.DuplicateNameException;@@ -78,15 +79,14 @@ public class FBPT_Entry implements StructConverter {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(FBPT_Entry.class);- Structure struct = new StructureDataType(className, 0);+ Structure struct = new StructureDataType(FBPT_Entry.class.getSimpleName(), 0);struct.add(STRING, FBPK_Constants.NAME_MAX_LENGTH, "name", null);struct.add(STRING, FBPK_Constants.NAME_MAX_LENGTH + 1, "guid1", null);struct.add(STRING, FBPK_Constants.NAME_MAX_LENGTH + 1, "guid2", null);struct.add(STRING, 2, "padding", null);if (FBPK_Constants.LAST_PARTITION_ENTRY.equals(name) || isLast) {try {- struct.setName(className + "_last");+ struct.setName(FBPT_Entry.class.getSimpleName() + "_last");}catch (InvalidNameException e) {//ignorediff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatClass.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatClass.javadeleted file mode 100644index 93ee482513..0000000000--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatClass.java+++ /dev/null@@ -1,166 +0,0 @@-/* ###- * IP: GHIDRA- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */-package ghidra.file.formats.android.oat;--import java.io.IOException;-import java.util.ArrayList;-import java.util.List;--import ghidra.app.util.bin.*;-import ghidra.file.formats.android.dex.format.ClassDataItem;-import ghidra.program.model.data.*;-import ghidra.util.exception.DuplicateNameException;--/**- *- * https://android.googlesource.com/platform/art/+/kitkat-release/runtime/oat_file.h#144- *- * https://android.googlesource.com/platform/art/+/lollipop-release/runtime/oat_file.h#205- *- * https://android.googlesource.com/platform/art/+/marshmallow-release/runtime/oat_file.h#200- *- */-public class OatClass implements StructConverter {-- private String oatVersion;-- private short status;- private short type;- private int bitmapSize;- private byte[] bitmap = new byte[0];- private List<OatMethodOffsets> methodOffsets = new ArrayList<OatMethodOffsets>();-- OatClass(BinaryReader reader, ClassDataItem classDataItem, String oatVersion)- throws IOException {- this.oatVersion = oatVersion;-- status = reader.readNextShort();- type = reader.readNextShort();-- int methodOffsetsCount = 0;-- if (type == OatClassType.kOatClassSomeCompiled.ordinal()) {- bitmapSize = reader.readNextInt();- bitmap = reader.readNextByteArray(bitmapSize);-- //For every set bit, there will be a corresponding entry in method_offsets.;- for (int i = 0; i < bitmapSize; ++i) {- methodOffsetsCount += Integer.bitCount(Byte.toUnsignedInt(bitmap[i]));- }- }- else if (type == OatClassType.kOatClassAllCompiled.ordinal()) {- methodOffsetsCount =- classDataItem.getDirectMethodsSize() + classDataItem.getVirtualMethodsSize();- }-- for (int i = 0; i < methodOffsetsCount; ++i) {- methodOffsets.add(OatMethodOffsetsFactory.getOatMethodOffsets(reader, oatVersion));- }- }-- /**- * State of class during compilation- * @return the class status- */- public short getStatus() {- return status;- }-- /**- * Returns the class type- * @return the OAT class type- * @see OatClassType- */- public short getType() {- return type;- }-- /**- * Size of compiled methods bitmap (present only when type = 1)- * @return size of methods bitmap- */- public int getBitmapSize() {- return bitmapSize;- }-- /**- * Compiled methods bitmap (present only when type = 1)- * @return methods bitmap- */- public byte[] getBitmap() {- return bitmap;- }-- /**- * Returns true if this method index is declared native in the bitmap- * @param methodIndex the method index- * @return true if this method index is declared native in the bitmap- */- public boolean isMethodNative(int methodIndex) {- int bytePos = methodIndex / 8;- int bitPos = methodIndex % 8;- return (((bitmap[bytePos] >> bitPos) & 0x1) == 0x1);- }-- /**- * methodOffsets is a list of offset that points to the generated- * native code for each compiled method.- * @return list of method offsets- */- public List<OatMethodOffsets> getMethodOffsets() {- return methodOffsets;- }-- @Override- public DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(OatClass.class);-- if (bitmapSize > 0) {- className += "_" + bitmapSize;- }- if (methodOffsets.size() > 0) {- className += "_" + methodOffsets.size();- }-- Structure structure = new StructureDataType(className, 0);-- //structure.add( WORD, "status", null );- if (oatVersion.equals(OatConstants.VERSION_OREO_M2_RELEASE)) {- structure.add(OatClassStatus_OreoM2.toDataType(), "status", null);- }- else {- structure.add(OatClassStatus.toDataType(), "status", null);- }-- structure.add(WORD, "type", null);-- if (type == OatClassType.kOatClassSomeCompiled.ordinal()) {- structure.add(DWORD, "bitmapSize", null);- if (bitmapSize > 0) {- DataType bitmapDataType = new ArrayDataType(BYTE, bitmapSize, BYTE.getLength());- structure.add(bitmapDataType, "bitmap", null);- }- }-- for (int i = 0; i < methodOffsets.size(); ++i) {- structure.add(methodOffsets.get(i).toDataType(), "methodOffsets_" + i, null);- }-- structure.setCategoryPath(new CategoryPath("/oat"));- return structure;- }--}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatClassStatus.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatClassStatus.javadeleted file mode 100644index 3c982d60d2..0000000000--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatClassStatus.java+++ /dev/null@@ -1,160 +0,0 @@-/* ###- * IP: GHIDRA- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */-package ghidra.file.formats.android.oat;--import java.lang.reflect.Field;--import ghidra.program.model.data.*;--/**- *- * See https://android.googlesource.com/platform/art/+/marshmallow-release/runtime/mirror/class.h- *- */-public final class OatClassStatus {-- /**- * Class that's temporarily used till class linking time- * has its (vtable) size figured out and has been cloned to one with the- * right size which will be the one used later. The old one is retired and- * will be gc'ed once all refs to the class point to the newly- * cloned version.- */- public final static short kStatusRetired = -3;-- /**- * Class is erroneous. We need to distinguish between classes that- * have been resolved and classes that have not. This is important- * because the const-class instruction needs to return a previously- * resolved class even if its subsequent initialization failed.- * We also need this to decide whether to wrap a previous initialization- * failure in ClassDefNotFound error or not.- */- public final static short kStatusErrorResolved = -2;-- /**- * Class is erroneous. We need to distinguish between classes that- * have been resolved and classes that have not. This is important- * because the const-class instruction needs to return a previously- * resolved class even if its subsequent initialization failed.- * We also need this to decide whether to wrap a previous initialization- * failure in ClassDefNotFound error or not.- */- public final static short kStatusErrorUnresolved = -1;-- /**- * If a Class cannot be found in the class table by FindClass,- * it allocates an new one with AllocClass in the kStatusNotReady- * and calls LoadClass. Note if it does find a class, it may- * not be kStatusResolved and it will try to push it forward toward kStatusResolved.- */- public final static short kStatusNotReady = 0;-- /**- * LoadClass populates with Class with information from the DexFile,- * moving the status to kStatusIdx, indicating that the Class value- * in super_class_ has not been populated. The new Class can- * then be inserted into the classes table.- */- public final static short kStatusIdx = 1;-- /**- * After taking a lock on Class, the ClassLinker will attempt- * to move a kStatusIdx class forward to kStatusLoaded by using- * ResolveClass to initialize the super_class_ and ensuring the- * interfaces are resolved.- */- public final static short kStatusLoaded = 2;-- /**- * Class is just cloned with the right size from temporary- * class that's acting as a placeholder for linking. The old- * class will be retired. New class is set to this status first- * before moving on to being resolved.- */- public final static short kStatusResolving = 3;-- /**- * Still holding the lock on Class, the ClassLinker- * shows linking is complete and fields of the Class populated by making- * it kStatusResolved. Java allows circularities of the form where a super- * class has a field that is of the type of the sub class. We need to be able- * to fully resolve super classes while resolving types for fields.- */- public final static short kStatusResolved = 4;-- /** In the process of being verified. */- public final static short kStatusVerifying = 5;-- /**- * The verifier sets a class to this state if it encounters a soft- * failure at compile time. This often happens when there are unresolved- * classes in other dex files, and this status marks a class as- * needing to be verified again at runtime.- */- public final static short kStatusRetryVerificationAtRuntime = 6;-- /** Retrying verification at runtime. */- public final static short kStatusVerifyingAtRuntime = 7;-- /** Logically part of linking; done pre-init. */- public final static short kStatusVerified = 8;-- /** Class init in progress. */- public final static short kStatusInitializing = 9;-- /** Ready to go. */- public final static short kStatusInitialized = 10;-- public final static short kStatusMax = 11;-- /**- * Returns the field name for the given value.- * If not found, simply returns a hex string of the value.- * @param value the field value- * @return the field name- */- public static String toString(short value) {- for (Field field : OatClassStatus.class.getDeclaredFields()) {- try {- Object obj = field.get(null);- if (obj != null && obj.equals(value)) {- return field.getName();- }- }- catch (Exception e) {- //ignore...- }- }- return OatClassStatus.class.getSimpleName() + ":0x" + Integer.toHexString(value);- }-- public static DataType toDataType() {- EnumDataType enumDataType = new EnumDataType(OatClassStatus.class.getSimpleName(), 2);- for (Field field : OatClassStatus.class.getDeclaredFields()) {- try {- Object obj = field.get(null);- enumDataType.add(field.getName(), (short) obj);- }- catch (Exception e) {- //ignore...- }- }- enumDataType.setCategoryPath(new CategoryPath("/oat"));- return enumDataType;- }--}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatClassStatus_OreoM2.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatClassStatus_OreoM2.javadeleted file mode 100644index 53a81a58ad..0000000000--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatClassStatus_OreoM2.java+++ /dev/null@@ -1,164 +0,0 @@-/* ###- * IP: GHIDRA- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */-package ghidra.file.formats.android.oat;--import java.lang.reflect.Field;--import ghidra.program.model.data.*;-import ghidra.util.UniversalIdGenerator;--/**- *- * See https://android.googlesource.com/platform/art/+/marshmallow-release/runtime/mirror/class.h- *- */-public final class OatClassStatus_OreoM2 {-- /**- * Class that's temporarily used till class linking time- * has its (vtable) size figured out and has been cloned to one with the- * right size which will be the one used later. The old one is retired and- * will be gc'ed once all refs to the class point to the newly- * cloned version.- */- public final static short kStatusRetired = -3;-- /**- * Class is erroneous. We need to distinguish between classes that- * have been resolved and classes that have not. This is important- * because the const-class instruction needs to return a previously- * resolved class even if its subsequent initialization failed.- * We also need this to decide whether to wrap a previous initialization- * failure in ClassDefNotFound error or not.- */- public final static short kStatusErrorResolved = -2;-- /**- * Class is erroneous. We need to distinguish between classes that- * have been resolved and classes that have not. This is important- * because the const-class instruction needs to return a previously- * resolved class even if its subsequent initialization failed.- * We also need this to decide whether to wrap a previous initialization- * failure in ClassDefNotFound error or not.- */- public final static short kStatusErrorUnresolved = -1;-- /**- * If a Class cannot be found in the class table by FindClass,- * it allocates an new one with AllocClass in the kStatusNotReady- * and calls LoadClass. Note if it does find a class, it may- * not be kStatusResolved and it will try to push it forward toward kStatusResolved.- */- public final static short kStatusNotReady = 0;-- /**- * LoadClass populates with Class with information from the DexFile,- * moving the status to kStatusIdx, indicating that the Class value- * in super_class_ has not been populated. The new Class can- * then be inserted shorto the classes table.- */- public final static short kStatusIdx = 1;-- /**- * After taking a lock on Class, the ClassLinker will attempt- * to move a kStatusIdx class forward to kStatusLoaded by using- * ResolveClass to initialize the super_class_ and ensuring the- * shorterfaces are resolved.- */- public final static short kStatusLoaded = 2;-- /**- * Class is just cloned with the right size from temporary- * class that's acting as a placeholder for linking. The old- * class will be retired. New class is set to this status first- * before moving on to being resolved.- */- public final static short kStatusResolving = 3;-- /**- * Still holding the lock on Class, the ClassLinker- * shows linking is complete and fields of the Class populated by making- * it kStatusResolved. Java allows circularities of the form where a super- * class has a field that is of the type of the sub class. We need to be able- * to fully resolve super classes while resolving types for fields.- */- public final static short kStatusResolved = 4;-- /** In the process of being verified. */- public final static short kStatusVerifying = 5;-- /**- * The verifier sets a class to this state if it encounters a soft- * failure at compile time. This often happens when there are unresolved- * classes in other dex files, and this status marks a class as- * needing to be verified again at runtime.- */- public final static short kStatusRetryVerificationAtRuntime = 6;-- /** Retrying verification at runtime. */- public final static short kStatusVerifyingAtRuntime = 7;-- /** Logically part of linking; done pre-init. */- public final static short kStatusVerified = 8;-- /** Superclass validation part of init done. */- public final static short kStatusSuperclassValidated = 9;-- /** Class init in progress. */- public final static short kStatusInitializing = 10;-- /** Ready to go. */- public final static short kStatusInitialized = 11;-- public final static short kStatusMax = 12;-- /**- * Returns the field name for the given value.- * If not found, simply returns a hex string of the value.- */- public static String toString(short value) {- for (Field field : OatClassStatus_OreoM2.class.getDeclaredFields()) {- try {- Object obj = field.get(null);- if (obj != null && obj.equals(value)) {- return field.getName();- }- }- catch (Exception e) {- //ignore...- }- }- return OatClassStatus_OreoM2.class.getSimpleName() + ":0x" + Integer.toHexString(value);- }-- public static DataType toDataType() {- EnumDataType enumDataType =- new EnumDataType(OatClassStatus_OreoM2.class.getSimpleName(), 2);- for (Field field : OatClassStatus_OreoM2.class.getDeclaredFields()) {- try {- Object obj = field.get(null);- enumDataType.add(field.getName(), (short) obj);- }- catch (Exception e) {- e.printStackTrace();- //ignore...- }- }- enumDataType.setCategoryPath(new CategoryPath("/oat"));- return enumDataType;- }--}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatConstants.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatConstants.javaindex c9592568ff..f0b93b61ff 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatConstants.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatConstants.java@@ -77,6 +77,7 @@ public final class OatConstants {public final static String version_q_preview_1 = "166";public final static String VERSION_10_RELEASE = "170";public final static String VERSION_11_RELEASE = "183";+ public final static String VERSION_12_RELEASE = "195";public final static int VERSION_LENGTH = 3;//3 bytes in length@@ -101,6 +102,7 @@ public final class OatConstants {VERSION_PIE_RELEASE,VERSION_10_RELEASE,VERSION_11_RELEASE,+ VERSION_12_RELEASE,};/** Keys from the OAT header "key/value" store. */diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatExecAnalyzer.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatExecAnalyzer.javaindex 564c55cdd5..9146c5343b 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatExecAnalyzer.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatExecAnalyzer.java@@ -18,6 +18,8 @@ package ghidra.file.formats.android.oat;import ghidra.app.util.bin.*;import ghidra.app.util.importer.MessageLog;import ghidra.file.analyzers.FileFormatAnalyzer;+import ghidra.file.formats.android.oat.quickmethod.OatQuickMethodHeader;+import ghidra.file.formats.android.oat.quickmethod.OatQuickMethodHeaderFactory;import ghidra.program.model.address.Address;import ghidra.program.model.address.AddressSetView;import ghidra.program.model.data.DataType;diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatFileSystem.javaindex eeeb0d7420..a740f6ae76 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatFileSystem.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatFileSystem.java@@ -21,7 +21,9 @@ import java.util.*;import generic.continues.RethrowContinuesFactory;import ghidra.app.util.bin.*;import ghidra.app.util.bin.format.elf.*;+import ghidra.app.util.importer.MessageLog;import ghidra.file.formats.android.dex.format.DexHeader;+import ghidra.file.formats.android.oat.oatdexfile.OatDexFile;import ghidra.formats.gfilesystem.*;import ghidra.formats.gfilesystem.annotations.FileSystemInfo;import ghidra.formats.gfilesystem.factory.GFileSystemBaseFactory;@@ -100,7 +102,7 @@ public class OatFileSystem extends GFileSystemBase {ElfSectionHeader roDataSection = elf.getSection(ElfSectionHeaderConstants.dot_rodata);if (roDataSection == null) {- //TODO should we check?+ throw new IOException("rodata section does not exist.");}baseOffset = roDataSection.getOffset();@@ -109,8 +111,7 @@ public class OatFileSystem extends GFileSystemBase {new ByteProviderWrapper(provider, baseOffset, roDataSection.getSize());BinaryReader reader = new BinaryReader(wrapper, elf.isLittleEndian());OatHeader oatHeader = OatHeaderFactory.newOatHeader(reader);- //oatHeader.parse( reader, null );- OatHeaderFactory.parseOatHeader(oatHeader, reader, monitor);+ OatHeaderFactory.parseOatHeader(oatHeader, null, reader, monitor, new MessageLog());monitor.incrementProgress(1);dexFileList = oatHeader.getOatDexFileList();@@ -184,7 +185,7 @@ public class OatFileSystem extends GFileSystemBase {throw new IOException("Invalid / unknown file: " + file);}OatDexFile oatDexFileHeader = dexFileList.get(index);- return new ByteProviderWrapper(provider, oatDexFileHeader.getDexFileOffset(),+ return new ByteProviderWrapper(provider, baseOffset + oatDexFileHeader.getDexFileOffset(),oatDexFileHeader.getDexHeader().getFileSize(), file.getFSRL());}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader.javaindex de1c69d4f2..d949df5bcb 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader.java@@ -16,10 +16,13 @@package ghidra.file.formats.android.oat;import java.io.IOException;-import java.util.List;+import java.util.*;import ghidra.app.util.bin.BinaryReader;import ghidra.app.util.bin.StructConverter;+import ghidra.file.formats.android.oat.bundle.OatBundle;+import ghidra.file.formats.android.oat.oatdexfile.OatDexFile;+import ghidra.file.formats.android.oat.oatdexfile.OatDexFileFactory;/*** Base OatHeader implementations@@ -34,6 +37,16 @@ public abstract class OatHeader implements StructConverter {protected String magic;protected String version;+ protected List<String> orderedKeyList = new ArrayList<String>();//ordered as defined+ protected Map<String, String> key_value_store_ = new HashMap<String, String>();++ protected List<OatDexFile> oatDexFileList = new ArrayList<OatDexFile>();++ /**+ * Base constructor for the OAT headers.+ * @param reader the binary reader with the file bytes.+ * @throws IOException if an IO exception occurs.+ */protected OatHeader(BinaryReader reader) throws IOException {magic = new String(reader.readNextByteArray(OatConstants.MAGIC.length()));version = reader.readNextAsciiString(4);@@ -43,12 +56,34 @@ public abstract class OatHeader implements StructConverter {* Parses the OAT header beyond the MAGIC and VERSION fields.* The "additionalData" is used to future proof the parsers.* For example, its needed for handling vdex files.+ * @param reader the binary reader with the file bytes.+ * @param bundle the fake OAT bundle containing the DEX, VDEX, etc.+ * @throws IOException if an IO exception occurs.+ * @throws UnsupportedOatVersionException if the OAT version is not supported.*/- abstract public void parse(BinaryReader reader, Object additionalData)- throws IOException, UnsupportedOatVersionException;+ public void parse(BinaryReader reader, OatBundle bundle)+ throws IOException, UnsupportedOatVersionException {++ int count = 0;+ while (count < getKeyValueStoreSize()) {+ String key = reader.readNextAsciiString();+ String value = reader.readNextAsciiString();+ count += key.length() + 1;+ count += value.length() + 1;+ orderedKeyList.add(key);+ key_value_store_.put(key, value);+ }++ reader.setPointerIndex(getOatDexFilesOffset(reader));+ for (int i = 0; i < getDexFileCount(); ++i) {+ oatDexFileList.add(+ OatDexFileFactory.getOatDexFile(reader, getVersion(), bundle));+ }+ }/*** Returns the MAGIC string, i.e. "oat\n".+ * @return the MAGIC string, i.e. "oat\n".*/public String getMagic() {return magic;@@ -56,39 +91,55 @@ public abstract class OatHeader implements StructConverter {/*** Returns the VERSION string, e.g. "001", "009", etc.+ * @return the VERSION string, e.g. "001", "009", etc.*/public String getVersion() {return version;}+ /**+ * Returns the binary offset to the DEX files.+ * @param reader the binary reader with the file bytes.+ * @return the binary offset to the DEX files.+ */+ abstract public int getOatDexFilesOffset(BinaryReader reader);+/*** Returns the number of DEX files embedded inside this OAT file.+ * @return the number of DEX files embedded inside this OAT file.*/abstract public int getDexFileCount();/*** Returns the size (in bytes) of the Key/Value store contained inside this OAT file.+ * @return the size (in bytes) of the Key/Value store contained inside this OAT file.*/abstract public int getKeyValueStoreSize();/*** Returns a list of the OatDexFileHeader, a structure defining the embedded DEX files.+ * @return a list of the OatDexFileHeader, a structure defining the embedded DEX files.*/abstract public List<OatDexFile> getOatDexFileList();/*** Returns the OAT instruction set (ARM, X86, etc).+ * @return the OAT instruction set (ARM, X86, etc).*/abstract public OatInstructionSet getInstructionSet();/**- * Returns the offset to the executable code, relative to the "oatdata" symbol.+ * Returns the offset to the executable code.+ * Relative to the "oatdata" symbol.* The executable code can also be located using the "oatexec" symbol.+ * @return the offset to the executable code.*/abstract public int getExecutableOffset();/*** Returns the OAT checksum value.+ * @return the OAT checksum value.*/abstract public int getChecksum();+}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeaderAnalyzer.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeaderAnalyzer.javaindex f2437288f6..64c8efec78 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeaderAnalyzer.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeaderAnalyzer.java@@ -22,6 +22,7 @@ import ghidra.app.util.bin.format.elf.ElfSectionHeaderConstants;import ghidra.app.util.importer.MessageLog;import ghidra.file.analyzers.FileFormatAnalyzer;import ghidra.file.formats.android.dex.format.DexHeader;+import ghidra.file.formats.android.oat.oatdexfile.OatDexFile;import ghidra.program.model.address.Address;import ghidra.program.model.address.AddressSetView;import ghidra.program.model.data.*;@@ -57,7 +58,7 @@ public class OatHeaderAnalyzer extends FileFormatAnalyzer {@Overridepublic boolean isPrototype() {- return true;+ return false;}@Overridediff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeaderFactory.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeaderFactory.javaindex a2ff1c278c..f3c960afe2 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeaderFactory.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeaderFactory.java@@ -19,8 +19,8 @@ import java.io.IOException;import ghidra.app.util.bin.BinaryReader;import ghidra.app.util.importer.MessageLog;-import ghidra.file.formats.android.vdex.VdexFactory;-import ghidra.file.formats.android.vdex.VdexHeader;+import ghidra.file.formats.android.oat.bundle.OatBundle;+import ghidra.file.formats.android.oat.bundle.OatBundleFactory;import ghidra.program.model.listing.Program;import ghidra.util.task.TaskMonitor;@@ -62,35 +62,21 @@ public final class OatHeaderFactory {return new OatHeader_10(reader);case OatConstants.VERSION_11_RELEASE:return new OatHeader_11(reader);+ case OatConstants.VERSION_12_RELEASE:+ return new OatHeader_12(reader);}}}throw new UnsupportedOatVersionException(magic, version);}- public final static void parseOatHeader(OatHeader oatHeader, BinaryReader reader,- TaskMonitor monitor) throws UnsupportedOatVersionException, IOException {-- parseOatHeader(oatHeader, null, reader, monitor, new MessageLog());- }-public final static void parseOatHeader(OatHeader oatHeader, Program oatProgram,BinaryReader reader, TaskMonitor monitor, MessageLog log)throws UnsupportedOatVersionException, IOException {- if (oatHeader.getVersion().equals(OatConstants.VERSION_OREO_RELEASE) ||- oatHeader.getVersion().equals(OatConstants.VERSION_OREO_M2_RELEASE) ||- oatHeader.getVersion().equals(OatConstants.VERSION_PIE_RELEASE) ||- oatHeader.getVersion().equals(OatConstants.VERSION_10_RELEASE) ||- oatHeader.getVersion().equals(OatConstants.VERSION_11_RELEASE)) {-- //TODO move instantiation into parse method (will need program?)- VdexHeader vdexHeader = VdexFactory.loadVdexHeader(oatProgram, monitor, log);- oatHeader.parse(reader, vdexHeader);- }- else {- oatHeader.parse(reader, null);- }+ OatBundle bundle = OatBundleFactory.getOatBundle(oatProgram, oatHeader, monitor, log);+ oatHeader.parse(reader, bundle);+ bundle.close();}}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_10.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_10.javaindex 5dcf4e7e52..c59512b885 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_10.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_10.java@@ -19,7 +19,7 @@ import java.io.IOException;import java.util.*;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;+import ghidra.file.formats.android.oat.oatdexfile.OatDexFile;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;@@ -36,10 +36,6 @@ public class OatHeader_10 extends OatHeader {protected int quick_resolution_trampoline_offset_;protected int quick_to_interpreter_bridge_offset_;protected int key_value_store_size_;- protected Map<String, String> key_value_store_ = new HashMap<String, String>();- protected List<String> orderedKeyList = new ArrayList<String>();//ordered as defined-- protected List<OatDexFile> oatDexFileList = new ArrayList<OatDexFile>();OatHeader_10(BinaryReader reader) throws IOException {super(reader);@@ -59,23 +55,8 @@ public class OatHeader_10 extends OatHeader {}@Override- public void parse(BinaryReader reader, Object additionalData)- throws IOException, UnsupportedOatVersionException {- int count = 0;- while (count < key_value_store_size_) {- String key = reader.readNextAsciiString();- String value = reader.readNextAsciiString();- count += key.length() + 1;- count += value.length() + 1;- orderedKeyList.add(key);- key_value_store_.put(key, value);- }-- reader.setPointerIndex(oat_dex_files_offset_);- for (int i = 0; i < dex_file_count_; ++i) {- oatDexFileList- .add(OatDexFileFactory.getOatDexFile(reader, getVersion(), additionalData));- }+ public int getOatDexFilesOffset(BinaryReader reader) {+ return oat_dex_files_offset_;}@Override@@ -110,8 +91,7 @@ public class OatHeader_10 extends OatHeader {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(OatHeader_10.class);- Structure structure = new StructureDataType(className, 0);+ Structure structure = new StructureDataType(OatHeader_10.class.getSimpleName(), 0);structure.add(STRING, 4, "magic_", null);structure.add(STRING, 4, "version_", null);structure.add(DWORD, "oat_checksum_", null);@@ -134,6 +114,7 @@ public class OatHeader_10 extends OatHeader {structure.add(STRING, value.length() + 1, "key_value_store_[" + i + "].value", null);}+ structure.setCategoryPath(new CategoryPath("/oat"));return structure;}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_11.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_11.javaindex 3d338db51e..e00e1b30aa 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_11.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_11.java@@ -19,7 +19,7 @@ import java.io.IOException;import java.util.*;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;+import ghidra.file.formats.android.oat.oatdexfile.OatDexFile;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;@@ -37,10 +37,6 @@ public class OatHeader_11 extends OatHeader {protected int quick_resolution_trampoline_offset_;protected int quick_to_interpreter_bridge_offset_;protected int key_value_store_size_;- protected Map<String, String> key_value_store_ = new HashMap<String, String>();- protected List<String> orderedKeyList = new ArrayList<String>();//ordered as defined-- protected List<OatDexFile> oatDexFileList = new ArrayList<OatDexFile>();OatHeader_11(BinaryReader reader) throws IOException {super(reader);@@ -61,23 +57,8 @@ public class OatHeader_11 extends OatHeader {}@Override- public void parse(BinaryReader reader, Object additionalData)- throws IOException, UnsupportedOatVersionException {- int count = 0;- while (count < key_value_store_size_) {- String key = reader.readNextAsciiString();- String value = reader.readNextAsciiString();- count += key.length() + 1;- count += value.length() + 1;- orderedKeyList.add(key);- key_value_store_.put(key, value);- }-- reader.setPointerIndex(oat_dex_files_offset_);- for (int i = 0; i < dex_file_count_; ++i) {- oatDexFileList- .add(OatDexFileFactory.getOatDexFile(reader, getVersion(), additionalData));- }+ public int getOatDexFilesOffset(BinaryReader reader) {+ return oat_dex_files_offset_;}@Override@@ -112,8 +93,7 @@ public class OatHeader_11 extends OatHeader {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(OatHeader_11.class);- Structure structure = new StructureDataType(className, 0);+ Structure structure = new StructureDataType(OatHeader_11.class.getSimpleName(), 0);structure.add(STRING, 4, "magic_", null);structure.add(STRING, 4, "version_", null);structure.add(DWORD, "oat_checksum_", null);@@ -137,6 +117,7 @@ public class OatHeader_11 extends OatHeader {structure.add(STRING, value.length() + 1, "key_value_store_[" + i + "].value", null);}+ structure.setCategoryPath(new CategoryPath("/oat"));return structure;}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_12.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_12.javanew file mode 100644index 0000000000..1281e524d3--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_12.java@@ -0,0 +1,132 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat;++import java.io.IOException;+import java.util.*;++import ghidra.app.util.bin.BinaryReader;+import ghidra.file.formats.android.oat.oatdexfile.OatDexFile;+import ghidra.program.model.data.*;+import ghidra.util.exception.DuplicateNameException;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/android-s-beta-5/runtime/oat.h#125+ *+ * https://android.googlesource.com/platform/art/+/refs/heads/android12-release/runtime/oat.h#125+ */+public class OatHeader_12 extends OatHeader {+ protected int oat_checksum_;+ protected int instruction_set_;+ protected int instruction_set_features_bitmap_;+ protected int dex_file_count_;+ protected int oat_dex_files_offset_;+ protected int executable_offset_;+ protected int jni_dlsym_lookup_offset_;+ protected int jni_dlsym_lookup_critical_trampoline_offset_;+ protected int quick_generic_jni_trampoline_offset_;+ protected int quick_imt_conflict_trampoline_offset_;+ protected int quick_resolution_trampoline_offset_;+ protected int quick_to_interpreter_bridge_offset_;+ protected int nterp_trampoline_offset_;+ protected int key_value_store_size_;++ OatHeader_12(BinaryReader reader) throws IOException {+ super(reader);++ oat_checksum_ = reader.readNextInt();+ instruction_set_ = reader.readNextInt();+ instruction_set_features_bitmap_ = reader.readNextInt();+ dex_file_count_ = reader.readNextInt();+ oat_dex_files_offset_ = reader.readNextInt();+ executable_offset_ = reader.readNextInt();+ jni_dlsym_lookup_offset_ = reader.readNextInt();+ jni_dlsym_lookup_critical_trampoline_offset_ = reader.readNextInt();+ quick_generic_jni_trampoline_offset_ = reader.readNextInt();+ quick_imt_conflict_trampoline_offset_ = reader.readNextInt();+ quick_resolution_trampoline_offset_ = reader.readNextInt();+ quick_to_interpreter_bridge_offset_ = reader.readNextInt();+ nterp_trampoline_offset_ = reader.readNextInt();+ key_value_store_size_ = reader.readNextInt();+ }++ @Override+ public int getOatDexFilesOffset(BinaryReader reader) {+ return oat_dex_files_offset_;+ }++ @Override+ public int getDexFileCount() {+ return dex_file_count_;+ }++ @Override+ public int getKeyValueStoreSize() {+ return key_value_store_size_;+ }++ @Override+ public List<OatDexFile> getOatDexFileList() {+ return oatDexFileList;+ }++ @Override+ public OatInstructionSet getInstructionSet() {+ return OatInstructionSet.valueOf(instruction_set_);+ }++ @Override+ public int getExecutableOffset() {+ return executable_offset_;+ }++ @Override+ public int getChecksum() {+ return oat_checksum_;+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ Structure structure = new StructureDataType(OatHeader_12.class.getSimpleName(), 0);+ structure.add(STRING, 4, "magic_", null);+ structure.add(STRING, 4, "version_", null);+ structure.add(DWORD, "oat_checksum_", null);+ structure.add(DWORD, OatInstructionSet.DISPLAY_NAME, null);+ structure.add(DWORD, "instruction_set_features_bitmap_", null);+ structure.add(DWORD, "dex_file_count_", null);+ structure.add(DWORD, "oat_dex_files_offset_", null);+ structure.add(DWORD, "executable_offset_", null);+ structure.add(DWORD, "jni_dlsym_lookup_offset_", null);+ structure.add(DWORD, "jni_dlsym_lookup_critical_trampoline_offset_", null);+ structure.add(DWORD, "quick_generic_jni_trampoline_offset_", null);+ structure.add(DWORD, "quick_imt_conflict_trampoline_offset_", null);+ structure.add(DWORD, "quick_resolution_trampoline_offset_", null);+ structure.add(DWORD, "quick_to_interpreter_bridge_offset_", null);+ structure.add(DWORD, "nterp_trampoline_offset_", null);+ structure.add(DWORD, "key_value_store_size_", null);++ for (int i = 0; i < orderedKeyList.size(); ++i) {+ String key = orderedKeyList.get(i);+ String value = key_value_store_.get(key);+ structure.add(STRING, key.length() + 1, "key_value_store_[" + i + "].key", null);+ structure.add(STRING, value.length() + 1, "key_value_store_[" + i + "].value", null);+ }++ structure.setCategoryPath(new CategoryPath("/oat"));+ return structure;+ }++}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_KitKat.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_KitKat.javaindex 8814916757..115b15a11a 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_KitKat.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_KitKat.java@@ -16,10 +16,12 @@package ghidra.file.formats.android.oat;import java.io.IOException;+import java.util.Collections;import java.util.List;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;+import ghidra.file.formats.android.oat.bundle.OatBundle;+import ghidra.file.formats.android.oat.oatdexfile.OatDexFile;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;@@ -56,10 +58,15 @@ public class OatHeader_KitKat extends OatHeader {}@Override- public void parse(BinaryReader reader, Object additionalData) throws IOException {+ public void parse(BinaryReader reader, OatBundle bundle) throws IOException {//do nothing}+ @Override+ public int getOatDexFilesOffset(BinaryReader reader) {+ return -1;//not supported+ }+public int getChecksum() {return adler32_checksum_;}@@ -117,20 +124,17 @@ public class OatHeader_KitKat extends OatHeader {@Overridepublic int getKeyValueStoreSize() {- // TODO Auto-generated method stubreturn 0;}@Overridepublic List<OatDexFile> getOatDexFileList() {- // TODO Auto-generated method stub- return null;+ return Collections.emptyList();}@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(OatHeader_KitKat.class);- Structure structure = new StructureDataType(className, 0);+ Structure structure = new StructureDataType(OatHeader_KitKat.class.getSimpleName(), 0);structure.add(STRING, 4, "magic_", null);structure.add(STRING, 4, "version_", null);structure.add(DWORD, "adler32_checksum_", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Lollipop.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Lollipop.javaindex 7f219ed755..ff93975c9a 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Lollipop.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Lollipop.java@@ -19,7 +19,7 @@ import java.io.IOException;import java.util.*;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;+import ghidra.file.formats.android.oat.oatdexfile.OatDexFile;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;@@ -48,11 +48,6 @@ public class OatHeader_Lollipop extends OatHeader {protected int image_file_location_oat_data_begin_;protected int key_value_store_size_;- protected List<String> orderedKeyList = new ArrayList<String>();//ordered as defined- protected Map<String, String> key_value_store_ = new HashMap<String, String>();-- protected List<OatDexFile> oatDexFileList = new ArrayList<OatDexFile>();-OatHeader_Lollipop(BinaryReader reader) throws IOException {super(reader);adler32_checksum_ = reader.readNextInt();@@ -77,21 +72,9 @@ public class OatHeader_Lollipop extends OatHeader {}@Override- public void parse(BinaryReader reader, Object additionalData) throws IOException {- int count = 0;- while (count < key_value_store_size_) {- String key = reader.readNextAsciiString();- String value = reader.readNextAsciiString();- count += key.length() + 1;- count += value.length() + 1;- key_value_store_.put(key, value);- orderedKeyList.add(key);- }-- for (int i = 0; i < dex_file_count_; ++i) {- oatDexFileList- .add(OatDexFileFactory.getOatDexFile(reader, getVersion(), additionalData));- }+ public int getOatDexFilesOffset(BinaryReader reader) {+ //the DEX offset is the current reader offset!+ return (int)reader.getPointerIndex();}@Override@@ -126,8 +109,7 @@ public class OatHeader_Lollipop extends OatHeader {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(OatHeader_Lollipop.class);- Structure structure = new StructureDataType(className, 0);+ Structure structure = new StructureDataType(OatHeader_Lollipop.class.getSimpleName(), 0);structure.add(STRING, 4, "magic_", null);structure.add(STRING, 4, "version_", null);structure.add(DWORD, "adler32_checksum_", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Marshmallow.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Marshmallow.javaindex 544a481807..9222e7aa56 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Marshmallow.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Marshmallow.java@@ -19,7 +19,7 @@ import java.io.IOException;import java.util.*;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;+import ghidra.file.formats.android.oat.oatdexfile.OatDexFile;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;@@ -45,11 +45,6 @@ class OatHeader_Marshmallow extends OatHeader {protected int image_file_location_oat_data_begin_;protected int key_value_store_size_;- protected List<String> orderedKeyList = new ArrayList<String>();//ordered as defined- protected Map<String, String> key_value_store_ = new HashMap<String, String>();-- protected List<OatDexFile> oatDexFileList = new ArrayList<OatDexFile>();-OatHeader_Marshmallow(BinaryReader reader) throws IOException {super(reader);@@ -72,22 +67,9 @@ class OatHeader_Marshmallow extends OatHeader {}@Override- public void parse(BinaryReader reader, Object additionalData)- throws IOException, UnsupportedOatVersionException {- int count = 0;- while (count < key_value_store_size_) {- String key = reader.readNextAsciiString();- String value = reader.readNextAsciiString();- count += key.length() + 1;- count += value.length() + 1;- key_value_store_.put(key, value);- orderedKeyList.add(key);- }-- for (int i = 0; i < dex_file_count_; ++i) {- oatDexFileList- .add(OatDexFileFactory.getOatDexFile(reader, getVersion(), additionalData));- }+ public int getOatDexFilesOffset(BinaryReader reader) {+ //the DEX offset is the current reader offset!+ return (int)reader.getPointerIndex();}@Override@@ -150,8 +132,7 @@ class OatHeader_Marshmallow extends OatHeader {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(OatHeader_Marshmallow.class);- Structure structure = new StructureDataType(className, 0);+ Structure structure = new StructureDataType(OatHeader_Marshmallow.class.getSimpleName(), 0);structure.add(STRING, 4, "magic_", null);structure.add(STRING, 4, "version_", null);structure.add(DWORD, "adler32_checksum_", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Nougat.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Nougat.javaindex 10db04d2ac..89efec0cee 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Nougat.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Nougat.java@@ -18,7 +18,6 @@ package ghidra.file.formats.android.oat;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;import ghidra.program.model.data.DataType;import ghidra.util.exception.DuplicateNameException;@@ -32,8 +31,7 @@ public class OatHeader_Nougat extends OatHeader_Marshmallow {public DataType toDataType() throws DuplicateNameException, IOException {DataType dataType = super.toDataType();try {- String className = StructConverterUtil.parseName(OatHeader_Nougat.class);- dataType.setName(className);+ dataType.setName(OatHeader_Nougat.class.getSimpleName());}catch (Exception e) {//ignorediff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Oreo.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Oreo.javaindex b95b7ae809..460147424b 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Oreo.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Oreo.java@@ -18,7 +18,6 @@ package ghidra.file.formats.android.oat;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;import ghidra.program.model.data.DataType;import ghidra.util.exception.DuplicateNameException;@@ -32,8 +31,7 @@ public class OatHeader_Oreo extends OatHeader_Marshmallow {public DataType toDataType() throws DuplicateNameException, IOException {DataType dataType = super.toDataType();try {- String className = StructConverterUtil.parseName(OatHeader_Oreo.class);- dataType.setName(className);+ dataType.setName(OatHeader_Oreo.class.getSimpleName());}catch (Exception e) {//ignorediff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Oreo_M2.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Oreo_M2.javaindex 3b2f307c87..a04c99ad15 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Oreo_M2.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Oreo_M2.java@@ -19,7 +19,7 @@ import java.io.IOException;import java.util.*;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;+import ghidra.file.formats.android.oat.oatdexfile.OatDexFile;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;@@ -46,11 +46,6 @@ class OatHeader_Oreo_M2 extends OatHeader {protected int image_file_location_oat_data_begin_;protected int key_value_store_size_;- protected List<String> orderedKeyList = new ArrayList<String>();//ordered as defined- protected Map<String, String> key_value_store_ = new HashMap<String, String>();-- protected List<OatDexFile> oatDexFileList = new ArrayList<OatDexFile>();-OatHeader_Oreo_M2(BinaryReader reader) throws IOException {super(reader);@@ -74,24 +69,8 @@ class OatHeader_Oreo_M2 extends OatHeader {}@Override- public void parse(BinaryReader reader, Object additionalData)- throws IOException, UnsupportedOatVersionException {- int count = 0;- while (count < key_value_store_size_) {- String key = reader.readNextAsciiString();- String value = reader.readNextAsciiString();- count += key.length() + 1;- count += value.length() + 1;- key_value_store_.put(key, value);- orderedKeyList.add(key);- }-- reader.setPointerIndex(oat_dex_files_offset_);-- for (int i = 0; i < dex_file_count_; ++i) {- oatDexFileList- .add(OatDexFileFactory.getOatDexFile(reader, getVersion(), additionalData));- }+ public int getOatDexFilesOffset(BinaryReader reader) {+ return oat_dex_files_offset_;}@Override@@ -152,14 +131,9 @@ class OatHeader_Oreo_M2 extends OatHeader {return adler32_checksum_;}- public int getOatDexFilesOffset() {- return oat_dex_files_offset_;- }-@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(OatHeader_Oreo_M2.class);- Structure structure = new StructureDataType(className, 0);+ Structure structure = new StructureDataType(OatHeader_Oreo_M2.class.getSimpleName(), 0);structure.add(STRING, 4, "magic_", null);structure.add(STRING, 4, "version_", null);structure.add(DWORD, "adler32_checksum_", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Pie.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Pie.javaindex ab42f52b91..4b5cdf1419 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Pie.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatHeader_Pie.java@@ -19,7 +19,7 @@ import java.io.IOException;import java.util.*;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;+import ghidra.file.formats.android.oat.oatdexfile.OatDexFile;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;@@ -46,11 +46,6 @@ class OatHeader_Pie extends OatHeader {protected int image_file_location_oat_data_begin_;protected int key_value_store_size_;- protected List<String> orderedKeyList = new ArrayList<String>();//ordered as defined- protected Map<String, String> key_value_store_ = new HashMap<String, String>();-- protected List<OatDexFile> oatDexFileList = new ArrayList<OatDexFile>();-OatHeader_Pie(BinaryReader reader) throws IOException {super(reader);adler32_checksum_ = reader.readNextInt();@@ -73,23 +68,8 @@ class OatHeader_Pie extends OatHeader {}@Override- public void parse(BinaryReader reader, Object additionalData)- throws IOException, UnsupportedOatVersionException {- int count = 0;- while (count < key_value_store_size_) {- String key = reader.readNextAsciiString();- String value = reader.readNextAsciiString();- count += key.length() + 1;- count += value.length() + 1;- key_value_store_.put(key, value);- orderedKeyList.add(key);- }-- reader.setPointerIndex(oat_dex_files_offset_);- for (int i = 0; i < dex_file_count_; ++i) {- oatDexFileList- .add(OatDexFileFactory.getOatDexFile(reader, getVersion(), additionalData));- }+ public int getOatDexFilesOffset(BinaryReader reader) {+ return oat_dex_files_offset_;}@Override@@ -124,8 +104,7 @@ class OatHeader_Pie extends OatHeader {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(OatHeader_Pie.class);- Structure structure = new StructureDataType(className, 0);+ Structure structure = new StructureDataType(OatHeader_Pie.class.getSimpleName(), 0);structure.add(STRING, 4, "magic_", null);structure.add(STRING, 4, "version_", null);structure.add(DWORD, "adler32_checksum_", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatUtilities.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatUtilities.javaindex f1dcca37e9..72af489afa 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatUtilities.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatUtilities.java@@ -34,14 +34,14 @@ import ghidra.program.model.mem.MemoryBlock;import ghidra.program.model.symbol.Symbol;import ghidra.program.model.symbol.SymbolTable;-final class OatUtilities {+public final class OatUtilities {/*** Returns a BinaryReader based at the "oatdata" symbol.* The ".rodata" section contains the OAT information.* Returns null when the "oatdata" symbol does not exist.*/- final static BinaryReader getBinaryReader(Program program) {+ public static BinaryReader getBinaryReader(Program program) {if (OatConstants.isOAT(program)) {Symbol symbol = getOatDataSymbol(program);if (symbol != null && symbol.getName().equals(OatConstants.SYMBOL_OAT_DATA)) {@@ -53,11 +53,11 @@ final class OatUtilities {return null;}- final static boolean isELF(Program program) {+ public static boolean isELF(Program program) {return ElfLoader.ELF_NAME.equals(program.getExecutableFormat());}- final static Symbol getOatDataSymbol(Program program) {+ public static Symbol getOatDataSymbol(Program program) {if (isELF(program)) {MemoryBlock block = program.getMemory().getBlock(ElfSectionHeaderConstants.dot_rodata);if (block != null) {@@ -72,7 +72,7 @@ final class OatUtilities {return null;}- final static Symbol getOatExecSymbol(Program program) {+ public static Symbol getOatExecSymbol(Program program) {if (isELF(program)) {MemoryBlock block = program.getMemory().getBlock(ElfSectionHeaderConstants.dot_text);if (block != null) {@@ -87,7 +87,7 @@ final class OatUtilities {return null;}- final static Symbol getOatLastWordSymbol(Program program) {+ public static Symbol getOatLastWordSymbol(Program program) {if (isELF(program)) {MemoryBlock block = program.getMemory().getBlock(ElfSectionHeaderConstants.dot_text);if (block != null) {@@ -102,23 +102,14 @@ final class OatUtilities {return null;}-// final static Symbol getSymbol( Program program, String name ) {-// SymbolTable symbolTable = program.getSymbolTable( );-// List< Symbol > symbols = symbolTable.getSymbols( name, program.getGlobalNamespace( ) );-// if ( symbols.size( ) != 1 ) {-// return null;//TODO-// }-// return symbols.get( 0 );-// }-- final static List<EncodedMethod> getAllMethods(ClassDataItem classDataItem) {+ public static List<EncodedMethod> getAllMethods(ClassDataItem classDataItem) {List<EncodedMethod> list = new ArrayList<EncodedMethod>();list.addAll(classDataItem.getDirectMethods());list.addAll(classDataItem.getVirtualMethods());return list;}- final static Address adjustForThumbAsNeeded(OatHeader oatHeader, Program program,+ public static Address adjustForThumbAsNeeded(OatHeader oatHeader, Program program,Address address, MessageLog log) {long displacement = address.getOffset();if (oatHeader.getInstructionSet() == OatInstructionSet.kThumb2) {diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/UnsupportedOatVersionException.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/UnsupportedOatVersionException.javaindex f54ab17de6..75032716f9 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/UnsupportedOatVersionException.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/UnsupportedOatVersionException.java@@ -18,6 +18,10 @@ package ghidra.file.formats.android.oat;public final class UnsupportedOatVersionException extends Exception {public UnsupportedOatVersionException(String magic, String version) {- super("Unsupported OAT (" + magic + ") for version: " + version);+ super("Unsupported OAT (" + magic.trim() + ") for version: " + version);+ }++ public UnsupportedOatVersionException(String message) {+ super(message);}}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/bundle/EmptyOatBundle.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/bundle/EmptyOatBundle.javanew file mode 100644index 0000000000..7c451e2ca6--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/bundle/EmptyOatBundle.java@@ -0,0 +1,67 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.bundle;++import java.util.List;++import ghidra.file.formats.android.art.ArtHeader;+import ghidra.file.formats.android.dex.format.DexHeader;+import ghidra.file.formats.android.oat.OatHeader;+import ghidra.file.formats.android.vdex.VdexHeader;++/**+ * An empty implementation used for initial+ * loading of the OAT header.+ */+public class EmptyOatBundle implements OatBundle {++ private OatHeader oatHeader;++ EmptyOatBundle(OatHeader oatHeader) {+ this.oatHeader = oatHeader;+ }++ @Override+ public void close() {+ oatHeader = null;+ }++ @Override+ public OatHeader getOatHeader() {+ return oatHeader;+ }++ @Override+ public ArtHeader getArtHeader() {+ return null;+ }++ @Override+ public VdexHeader getVdexHeader() {+ return null;+ }++ @Override+ public List<DexHeader> getDexHeaders() {+ return null;+ }++ @Override+ public DexHeader getDexHeaderByChecksum(int checksum) {+ return null;+ }++}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/bundle/FullOatBundle.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/bundle/FullOatBundle.javanew file mode 100644index 0000000000..cb31d3073e--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/bundle/FullOatBundle.java@@ -0,0 +1,318 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.bundle;++import java.io.IOException;+import java.util.*;++import org.apache.commons.io.FilenameUtils;++import ghidra.app.util.bin.*;+import ghidra.app.util.importer.MessageLog;+import ghidra.file.formats.android.art.*;+import ghidra.file.formats.android.dex.DexHeaderFactory;+import ghidra.file.formats.android.dex.format.DexHeader;+import ghidra.file.formats.android.oat.OatHeader;+import ghidra.file.formats.android.vdex.*;+import ghidra.framework.model.DomainFile;+import ghidra.framework.model.DomainFolder;+import ghidra.program.model.listing.Program;+import ghidra.util.exception.CancelledException;+import ghidra.util.task.TaskMonitor;++public class FullOatBundle implements OatBundle {++ private Program oatProgram;+ private OatHeader oatHeader;+ private VdexHeader vdexHeader;+ private ArtHeader artHeader;+ private List<DexHeader> dexHeaders = new ArrayList<>();+ private Map<Integer, DexHeader> dexHeadersMap = new HashMap<>();++ private boolean isLittleEndian;++ FullOatBundle(Program oatProgram, OatHeader oatHeader, TaskMonitor monitor,+ MessageLog log) {++ this.oatProgram = oatProgram;+ this.oatHeader = oatHeader;++ this.isLittleEndian = !oatProgram.getLanguage().isBigEndian();++ loadVdexHeader(oatProgram, monitor, log);+ loadDexHeaders(oatProgram, monitor, log);+ loadArtHeader(oatProgram, monitor, log);+ }++ @Override+ public void close() {+ oatProgram = null;+ oatHeader = null;+ vdexHeader = null;+ artHeader = null;+ dexHeaders.clear();+ dexHeadersMap.clear();+ }++ @Override+ public DexHeader getDexHeaderByChecksum(int checksum) {+ for (DexHeader dexHeader : dexHeaders) {+ if (dexHeader.getChecksum() == checksum) {+ return dexHeader;+ }+ }+ if (vdexHeader != null) {+ for (int i = 0; i < vdexHeader.getDexChecksums().length; ++i) {+ if (vdexHeader.getDexChecksums()[i] == checksum) {+ //first check in VDEX, then check for DEX+ if (vdexHeader.getDexHeaderList().size() > i) {+ return vdexHeader.getDexHeaderList().get(i);+ }+ //get from map by classesN.dex index+ return dexHeadersMap.get(i);+ }+ }+ }+ return null;//could NOT find matching dex header, probably not imported yet+ }++ public ArtHeader getArtHeader() {+ return artHeader;+ }++ @Override+ public OatHeader getOatHeader() {+ return oatHeader;+ }++ public List<DexHeader> getDexHeaders() {+ return dexHeaders;+ }++ public VdexHeader getVdexHeader() {+ return vdexHeader;+ }++ private void loadVdexHeader(Program oatProgram, TaskMonitor monitor, MessageLog log) {+ monitor.setMessage("Loading VDEX headers...");++ String baseName = FilenameUtils.removeExtension(oatProgram.getName());+ String vdexProgramName = baseName + VDEX;++ DomainFile domainFile = oatProgram.getDomainFile();+ DomainFolder parentFolder = domainFile.getParent();++ //first, look in current project for VDEX file....+ if (lookInProjectFolder(HeaderType.VDEX, parentFolder,+ vdexProgramName, monitor, log)) {+ return;+ }+ if (lookInProjectFolder(HeaderType.VDEX, parentFolder.getParent(),+ vdexProgramName, monitor, log)) {+ return;+ }+ }++ private void loadDexHeaders(Program oatProgram, TaskMonitor monitor, MessageLog log) {+ monitor.setMessage("Loading DEX headers...");++ DomainFolder odexApkFolder = getOdexApkOrJarFolder();+ if (odexApkFolder != null) {+ for (DomainFile file : odexApkFolder.getFiles()) {+ if (monitor.isCancelled()) {+ break;+ }+ if (file.getName().startsWith(CLASSES) && file.getName().endsWith(DEX)) {+ lookInProjectFolder(HeaderType.DEX, odexApkFolder, file.getName(),+ monitor, log);+ }+ }+ }++ DomainFolder apkOrJarFolder = getApkOrJarFolder();+ if (apkOrJarFolder != null) {+ for (DomainFile file : apkOrJarFolder.getFiles()) {+ if (monitor.isCancelled()) {+ break;+ }+ if (file.getName().startsWith(CLASSES) && file.getName().endsWith(DEX)) {+ lookInProjectFolder(HeaderType.DEX, apkOrJarFolder, file.getName(),+ monitor, log);+ }+ }+ }++ DomainFolder appVdexFolder = getAppVdexFolder();+ if (appVdexFolder != null) {+ for (DomainFile file : appVdexFolder.getFiles()) {+ if (monitor.isCancelled()) {+ break;+ }+ if (file.getName().startsWith(CDEX)) {+ lookInProjectFolder(HeaderType.CDEX, appVdexFolder, file.getName(),+ monitor, log);+ }+ }+ }+ }++ private void loadArtHeader(Program oatProgram, TaskMonitor monitor, MessageLog log) {+ monitor.setMessage("Loading ART headers...");++ String baseName = FilenameUtils.removeExtension(oatProgram.getName());+ String artProgramName = baseName + ART;++ DomainFile domainFile = oatProgram.getDomainFile();+ DomainFolder parentFolder = domainFile.getParent();++ //first, look in current project for ART file....+ if (lookInProjectFolder(HeaderType.ART, parentFolder,+ artProgramName, monitor, log)) {+ return;+ }+ if (lookInProjectFolder(HeaderType.ART, parentFolder.getParent(),+ artProgramName, monitor, log)) {+ return;+ }+ }++ /**+ * Looks in the specified project folder for a program with the specified name.+ * If found, then create a header of the specified type.+ * @param type the FileType+ * @param parentFolder the project folder+ * @param programName the program name+ * @param monitor the task monitor+ * @param log the message log+ */+ private boolean lookInProjectFolder(HeaderType type, DomainFolder parentFolder,+ String programName,+ TaskMonitor monitor, MessageLog log) {++ DomainFile child = parentFolder.getFile(programName);+ if (child != null) {+ Program program = null;+ try {+ program = (Program) child.getDomainObject(this, true, true, monitor);+ ByteProvider provider =+ new MemoryByteProvider(program.getMemory(), program.getMinAddress());+ return makeHeader(type, programName, provider, monitor);+ }+ catch (Exception e) {+ log.appendMsg("Unable to locate matching: " + type);+ }+ finally {+ if (program != null) {+ program.release(this);+ }+ }+ }+ return false;+ }++ private int getDexIndex(String dexName) {+ try {+ if (dexName.startsWith(CLASSES) && dexName.endsWith(DEX)) {+ String indexString =+ dexName.substring(CLASSES.length(), dexName.length() - DEX.length());+ if (indexString.length() == 0) {//this case is where name is "classes.dex"+ return 0;+ }+ //this case handles classes2.dex, classes3.dex, ... classesN.dex+ return Integer.parseInt(indexString) - 1;//must subtract one since Android starts counting at 1!!+ }+ }+ catch (Exception e) {+ //ignore+ }+ return -1;+ }++ private DomainFolder getApkOrJarFolder() {+ String baseName = FilenameUtils.removeExtension(oatProgram.getName());++ DomainFile domainFile = oatProgram.getDomainFile();+ String pathName = domainFile.getPathname();+ if (pathName.matches(".*/[^/]*/[^/]*")) {+ DomainFolder parentFolder = domainFile.getParent();//APP_DIR/oat/platform/+ parentFolder = parentFolder.getParent();//APP_DIR/oat/+ parentFolder = parentFolder.getParent();//APP_DIR/++ if (parentFolder.getFolder(baseName + APK) != null) {+ return parentFolder.getFolder(baseName + APK);//APP_DIR/APP.apk/+ }+ else if (parentFolder.getFolder(baseName + JAR) != null) {+ return parentFolder.getFolder(baseName + JAR);//APP_DIR/APP.jar/+ }+ }+ return null;+ }++ private DomainFolder getAppVdexFolder() {+ String baseName = FilenameUtils.removeExtension(oatProgram.getName());+ DomainFile domainFile = oatProgram.getDomainFile();+ DomainFolder parentFolder = domainFile.getParent();+ return parentFolder.getFolder(baseName + VDEX);+ }++ /**+ * ODEX files can contain APKs or JARs.+ */+ private DomainFolder getOdexApkOrJarFolder() {+ String baseName = FilenameUtils.removeExtension(oatProgram.getName());+ DomainFile domainFile = oatProgram.getDomainFile();+ DomainFolder parentFolder = domainFile.getParent();+ parentFolder = parentFolder.getFolder(baseName + ODEX);//APP_DIR.odex/+ if (parentFolder != null) {+ if (parentFolder.getFolder(baseName + APK) != null) {+ return parentFolder.getFolder(baseName + APK);//APP_DIR/APP.apk/+ }+ else if (parentFolder.getFolder(baseName + JAR) != null) {+ return parentFolder.getFolder(baseName + JAR);//APP_DIR/APP.jar/+ }+ }+ return null;+ }++ private boolean makeHeader(HeaderType type, String programName, ByteProvider provider,+ TaskMonitor monitor) throws IOException, UnsupportedVdexVersionException,+ CancelledException, UnsupportedArtVersionException {++ BinaryReader reader = new BinaryReader(provider, isLittleEndian);+ switch (type) {+ case ART: {+ ArtHeader artHeader = ArtFactory.newArtHeader(reader);+ this.artHeader = artHeader;+ return true;+ }+ case CDEX:+ case DEX: {+ DexHeader dexHeader = DexHeaderFactory.getDexHeader(reader, true);+ dexHeaders.add(dexHeader);+ dexHeadersMap.put(getDexIndex(programName), dexHeader);+ return true;+ }+ case VDEX: {+ VdexHeader vdexHeader = VdexFactory.getVdexHeader(reader);+ vdexHeader.parse(reader, monitor);+ this.vdexHeader = vdexHeader;+ return true;+ }+ }+ return false;+ }++}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/bundle/OatBundle.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/bundle/OatBundle.javanew file mode 100644index 0000000000..e67dccd1e5--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/bundle/OatBundle.java@@ -0,0 +1,80 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.bundle;++import java.util.List;++import ghidra.file.formats.android.art.ArtHeader;+import ghidra.file.formats.android.dex.format.DexHeader;+import ghidra.file.formats.android.oat.OatHeader;+import ghidra.file.formats.android.vdex.VdexHeader;++/**+ * A fictitious class to locate, open, and store all of the files+ * related to Android OAT/ART.+ */+public interface OatBundle {++ public enum HeaderType {+ ART, CDEX, DEX, VDEX,+ };++ public static final String APK = ".apk";+ public static final String ART = ".art";+ public static final String CLASSES = "classes";+ public static final String CDEX = "cdex";+ public static final String DEX = ".dex";+ public static final String JAR = ".jar";+ public static final String OAT = ".oat";+ public static final String ODEX = ".odex";+ public static final String VDEX = ".vdex";++ /**+ * Closes the bundle and release any resources.+ */+ public void close();++ /**+ * Returns the corresponding OAT header.+ * @return the corresponding OAT header.+ */+ public OatHeader getOatHeader();++ /**+ * Returns the corresponding ART header.+ * @return the corresponding ART header.+ */+ public ArtHeader getArtHeader();++ /**+ * Returns the corresponding OAT header.+ * @return the corresponding OAT header.+ */+ public VdexHeader getVdexHeader();++ /**+ * Returns the corresponding DEX headers.+ * @return the corresponding DEX headers.+ */+ public List<DexHeader> getDexHeaders();++ /**+ * Returns the DEX header with the specified checksum.+ * @return the DEX header with the specified checksum.+ */+ public DexHeader getDexHeaderByChecksum(int checksum);++}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/bundle/OatBundleFactory.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/bundle/OatBundleFactory.javanew file mode 100644index 0000000000..f1837e7db2--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/bundle/OatBundleFactory.java@@ -0,0 +1,35 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.bundle;++import ghidra.app.util.importer.MessageLog;+import ghidra.file.formats.android.oat.OatHeader;+import ghidra.program.model.listing.Program;+import ghidra.util.task.TaskMonitor;++public final class OatBundleFactory {++ public static OatBundle getOatBundle(Program oatProgram, OatHeader oatHeader,+ TaskMonitor monitor, MessageLog log) {++ // OAT program is required to fully load the bundle.+ // If program is null, then create an empty bundle.+ if (oatProgram == null) {+ return new EmptyOatBundle(oatHeader);+ }+ return new FullOatBundle(oatProgram, oatHeader, monitor, log);+ }+}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass.javanew file mode 100644index 0000000000..5fa0ce8da0--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass.java@@ -0,0 +1,144 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.oatclass;++import java.io.IOException;+import java.util.ArrayList;+import java.util.List;++import ghidra.app.util.bin.BinaryReader;+import ghidra.app.util.bin.StructConverter;+import ghidra.file.formats.android.oat.OatConstants;+import ghidra.file.formats.android.oat.oatmethod.OatMethodOffsets;+import ghidra.program.model.data.DataType;+import ghidra.util.InvalidNameException;+import ghidra.util.exception.DuplicateNameException;++/**+ * Base class for OatClass versions+ *+ */+public abstract class OatClass implements StructConverter {++ protected String oatVersion;++ protected short status_;+ protected short type_;++ protected List<OatMethodOffsets> methods_pointer_ = new ArrayList<OatMethodOffsets>();++ protected OatClassStatusEnum statusEnum;++ protected OatClass(BinaryReader reader, String oatVersion) throws IOException {++ this.oatVersion = oatVersion;++ status_ = reader.readNextShort();++ switch (oatVersion) {+ case OatConstants.VERSION_KITKAT_RELEASE: {+ statusEnum = OatClassStatusEnum_K.kStatusInitialized.get(status_);+ break;+ }+ case OatConstants.VERSION_LOLLIPOP_RELEASE:+ case OatConstants.VERSION_LOLLIPOP_MR1_FI_RELEASE:+ case OatConstants.VERSION_LOLLIPOP_WEAR_RELEASE:+ case OatConstants.VERSION_MARSHMALLOW_RELEASE:+ case OatConstants.VERSION_NOUGAT_RELEASE:+ case OatConstants.VERSION_NOUGAT_MR1_RELEASE: {+ statusEnum = OatClassStatusEnum_L_M_N.kStatusMax.get(status_);+ break;+ }+ case OatConstants.VERSION_OREO_RELEASE: {+ statusEnum = OatClassStatusEnum_O.kStatusMax.get(status_);+ break;+ }+ case OatConstants.VERSION_OREO_M2_RELEASE: {+ statusEnum = OatClassStatusEnum_O_M2.kStatusMax.get(status_);+ break;+ }+ case OatConstants.VERSION_PIE_RELEASE:+ case OatConstants.VERSION_10_RELEASE: {+ statusEnum = OatClassStatusEnum_P_10.kLast.get(status_);+ break;+ }+ case OatConstants.VERSION_11_RELEASE:+ case OatConstants.VERSION_12_RELEASE: {+ statusEnum = OatClassStatusEnum_11_12.kLast.get(status_);+ break;+ }+ default: {+ statusEnum = new OatClassStatusEnum_Invalid(status_);+ break;+ }+ }+ }++ /**+ * State of class during compilation+ * @return the class status+ */+ public final short getStatus() {+ return status_;+ }++ public final OatClassType getType() {+ for (OatClassType type : OatClassType.values()) {+ if (type.ordinal() == type_) {+ return type;+ }+ }+ return OatClassType.kOatClassMax;//invalid state+ }++ /**+ * methodOffsets is a list of offset that points to the generated+ * native code for each compiled method.+ * @return list of method offsets+ */+ public final List<OatMethodOffsets> getMethodOffsets() {+ return methods_pointer_;+ }++ /**+ * Returns true if this method index is declared native in the bitmap+ * @param methodIndex the method index+ * @return true if this method index is declared native in the bitmap+ */+ public abstract boolean isMethodNative(int methodIndex);++ /**+ * Renames the data type with the specified prefix.+ * Prefix is delimited by the second underscore character.+ * If no underscore exist, then entire data type name is changed to the prefix.+ * @param dataType the data type to rename+ * @param prefix the prefix to use in data type name+ * @throws InvalidNameException if the name is invalid+ * @throws DuplicateNameException if the name already exists.+ */+ protected void renameDataType(DataType dataType, String prefix)+ throws InvalidNameException, DuplicateNameException {+ String currentName = dataType.getName();+ int underscorePos = currentName.indexOf('_');+ underscorePos = currentName.indexOf('_', underscorePos + 1);+ if (underscorePos == -1) {+ dataType.setName(prefix);+ }+ else {+ dataType.setName(prefix + currentName.substring(underscorePos));+ }+ }+}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassFactory.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassFactory.javanew file mode 100644index 0000000000..c230285ab0--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassFactory.java@@ -0,0 +1,59 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.oatclass;++import java.io.IOException;++import ghidra.app.util.bin.BinaryReader;+import ghidra.file.formats.android.dex.format.ClassDataItem;+import ghidra.file.formats.android.oat.OatConstants;+import ghidra.file.formats.android.oat.UnsupportedOatVersionException;++public class OatClassFactory {++ public static OatClass getOatClass(BinaryReader reader, ClassDataItem classDataItem,+ String oatVersion) throws IOException, UnsupportedOatVersionException {++ switch (oatVersion) {+ case OatConstants.VERSION_KITKAT_RELEASE:+ return new OatClass_KitKat(reader, classDataItem, oatVersion);+ case OatConstants.VERSION_LOLLIPOP_RELEASE:+ case OatConstants.VERSION_LOLLIPOP_MR1_FI_RELEASE:+ case OatConstants.VERSION_LOLLIPOP_WEAR_RELEASE:+ return new OatClass_Lollipop(reader, classDataItem, oatVersion);+ case OatConstants.VERSION_MARSHMALLOW_RELEASE:+ return new OatClass_Marshmallow(reader, classDataItem, oatVersion);+ case OatConstants.VERSION_NOUGAT_RELEASE:+ case OatConstants.VERSION_NOUGAT_MR1_RELEASE:+ return new OatClass_Nougat(reader, classDataItem, oatVersion);+ case OatConstants.VERSION_OREO_RELEASE:+ return new OatClass_Oreo(reader, classDataItem, oatVersion);+ case OatConstants.VERSION_OREO_M2_RELEASE:+ return new OatClass_OreoM2(reader, classDataItem, oatVersion);+ case OatConstants.VERSION_PIE_RELEASE:+ return new OatClass_Pie(reader, classDataItem, oatVersion);+ case OatConstants.VERSION_10_RELEASE:+ return new OatClass_Android10(reader, classDataItem, oatVersion);+ case OatConstants.VERSION_11_RELEASE:+ return new OatClass_Android11(reader, classDataItem, oatVersion);+ case OatConstants.VERSION_12_RELEASE:+ return new OatClass_Android12(reader, classDataItem, oatVersion);+ default:+ throw new UnsupportedOatVersionException(+ "OatClass not supported for OAT Version: " + oatVersion);+ }+ }+}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum.javanew file mode 100644index 0000000000..61a3b5f406--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum.java@@ -0,0 +1,24 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.oatclass;++import ghidra.app.util.bin.StructConverter;++public interface OatClassStatusEnum extends StructConverter {++ public OatClassStatusEnum get(short value);++}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum_11_12.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum_11_12.javanew file mode 100644index 0000000000..7092367b3a--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum_11_12.java@@ -0,0 +1,81 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.oatclass;++import java.io.IOException;++import ghidra.program.model.data.*;+import ghidra.util.exception.DuplicateNameException;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/android11-release/runtime/class_status.h#82+ *+ * https://android.googlesource.com/platform/art/+/refs/heads/android12-release/runtime/class_status.h#82+ */+public enum OatClassStatusEnum_11_12 implements OatClassStatusEnum {++ kNotReady(0),+ kRetired(1),+ kErrorResolved(2),+ kErrorUnresolved(3),+ kIdx(4),+ kLoaded(5),+ kResolving(6),+ kResolved(7),+ kVerifying(8),+ kRetryVerificationAtRuntime(9),+ kVerifiedNeedsAccessChecks(10),+ kVerified(11),+ kSuperclassValidated(12),+ kInitializing(13),+ kInitialized(14),+ kVisiblyInitialized(15),+ kLast(15);// kLast = kVisiblyInitialized++ private byte value;++ private OatClassStatusEnum_11_12(byte value) {+ this.value = value;+ }++ private OatClassStatusEnum_11_12(int value) {+ this.value = (byte) value;+ }++ public byte getValue() {+ return value;+ }++ @Override+ public OatClassStatusEnum get(short value) {+ for (OatClassStatusEnum_11_12 valueX : values()) {+ if (valueX.getValue() == value) {+ return valueX;+ }+ }+ return null;//invalid case+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ EnumDataType enumDataType = new EnumDataType(OatClassStatusEnum_11_12.class.getSimpleName(), 2);+ for (OatClassStatusEnum_11_12 valueX : values()) {+ enumDataType.add(valueX.name(), valueX.getValue());+ }+ enumDataType.setCategoryPath(new CategoryPath("/oat"));+ return enumDataType;+ }+}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum_Invalid.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum_Invalid.javanew file mode 100644index 0000000000..850764d301--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum_Invalid.java@@ -0,0 +1,44 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.oatclass;++import java.io.IOException;++import ghidra.program.model.data.*;+import ghidra.util.exception.DuplicateNameException;++class OatClassStatusEnum_Invalid implements OatClassStatusEnum {++ private short value;++ OatClassStatusEnum_Invalid(short value) {+ this.value = value;+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ EnumDataType enumDataType = new EnumDataType(OatClassStatusEnum_Invalid.class.getSimpleName(), 2);+ enumDataType.add("INVALID", value);+ enumDataType.setCategoryPath(new CategoryPath("/oat"));+ return enumDataType;+ }++ @Override+ public OatClassStatusEnum get(short value) {+ return this;+ }++}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum_K.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum_K.javanew file mode 100644index 0000000000..110fa1c2c3--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum_K.java@@ -0,0 +1,74 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.oatclass;++import java.io.IOException;++import ghidra.program.model.data.*;+import ghidra.util.exception.DuplicateNameException;++/**+ * https://android.googlesource.com/platform/art/+/kitkat-release/runtime/mirror/class.h#112+ *+ */+public enum OatClassStatusEnum_K implements OatClassStatusEnum {++ kStatusError(-1),+ kStatusNotReady(0),+ kStatusIdx(1),+ kStatusLoaded(2),+ kStatusResolved(3),+ kStatusVerifying(4),+ kStatusRetryVerificationAtRuntime(5),+ kStatusVerifyingAtRuntime(6),+ kStatusVerified(7),+ kStatusInitializing(8),+ kStatusInitialized(9);++ private short value;++ private OatClassStatusEnum_K(short value) {+ this.value = value;+ }++ private OatClassStatusEnum_K(int value) {+ this.value = (short) value;+ }++ public short getValue() {+ return value;+ }++ @Override+ public OatClassStatusEnum get(short value) {+ for (OatClassStatusEnum_K valueX : values()) {+ if (valueX.getValue() == value) {+ return valueX;+ }+ }+ return null;//invalid case+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ EnumDataType enumDataType = new EnumDataType(OatClassStatusEnum_K.class.getSimpleName(), 2);+ for (OatClassStatusEnum_K valueX : values()) {+ enumDataType.add(valueX.name(), valueX.getValue());+ }+ enumDataType.setCategoryPath(new CategoryPath("/oat"));+ return enumDataType;+ }+}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum_L_M_N.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum_L_M_N.javanew file mode 100644index 0000000000..9206a11d19--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum_L_M_N.java@@ -0,0 +1,84 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.oatclass;++import java.io.IOException;++import ghidra.program.model.data.*;+import ghidra.util.exception.DuplicateNameException;++/**+ * https://android.googlesource.com/platform/art/+/lollipop-release/runtime/mirror/class.h#133+ *+ * https://android.googlesource.com/platform/art/+/refs/heads/lollipop-mr1-fi-release/runtime/mirror/class.h#138+ *+ * https://android.googlesource.com/platform/art/+/refs/heads/lollipop-wear-release/runtime/mirror/class.h#119+ *+ * https://android.googlesource.com/platform/art/+/marshmallow-release/runtime/mirror/class.h#112+ *+ * https://android.googlesource.com/platform/art/+/nougat-release/runtime/mirror/class.h#116+ */+public enum OatClassStatusEnum_L_M_N implements OatClassStatusEnum {++ kStatusRetired(-2),+ kStatusError(-1),+ kStatusNotReady(0),+ kStatusIdx(1),+ kStatusLoaded(2),+ kStatusResolving(3),+ kStatusResolved(4),+ kStatusVerifying(5),+ kStatusRetryVerificationAtRuntime(6),+ kStatusVerifyingAtRuntime(7),+ kStatusVerified(8),+ kStatusInitializing(9),+ kStatusInitialized(10),+ kStatusMax(11);++ private short value;++ private OatClassStatusEnum_L_M_N(short value) {+ this.value = value;+ }++ private OatClassStatusEnum_L_M_N(int value) {+ this.value = (short) value;+ }++ public short getValue() {+ return value;+ }++ @Override+ public OatClassStatusEnum get(short value) {+ for (OatClassStatusEnum_L_M_N valueX : values()) {+ if (valueX.getValue() == value) {+ return valueX;+ }+ }+ return null;//invalid case+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ EnumDataType enumDataType = new EnumDataType(OatClassStatusEnum_L_M_N.class.getSimpleName(), 2);+ for (OatClassStatusEnum_L_M_N valueX : values()) {+ enumDataType.add(valueX.name(), valueX.getValue());+ }+ enumDataType.setCategoryPath(new CategoryPath("/oat"));+ return enumDataType;+ }+}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum_O.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum_O.javanew file mode 100644index 0000000000..82695cf2ff--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum_O.java@@ -0,0 +1,77 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.oatclass;++import java.io.IOException;++import ghidra.program.model.data.*;+import ghidra.util.exception.DuplicateNameException;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/oreo-release/runtime/mirror/class.h#128+ */+public enum OatClassStatusEnum_O implements OatClassStatusEnum {++ kStatusRetired(-3),+ kStatusErrorResolved(-2),+ kStatusErrorUnresolved(-1),+ kStatusNotReady(0),+ kStatusIdx(1),+ kStatusLoaded(2),+ kStatusResolving(3),+ kStatusResolved(4),+ kStatusVerifying(5),+ kStatusRetryVerificationAtRuntime(6),+ kStatusVerifyingAtRuntime(7),+ kStatusVerified(8),+ kStatusInitializing(9),+ kStatusInitialized(10),+ kStatusMax(11);++ private short value;++ private OatClassStatusEnum_O(short value) {+ this.value = value;+ }++ private OatClassStatusEnum_O(int value) {+ this.value = (short) value;+ }++ public short getValue() {+ return value;+ }++ @Override+ public OatClassStatusEnum get(short value) {+ for (OatClassStatusEnum_O valueX : values()) {+ if (valueX.getValue() == value) {+ return valueX;+ }+ }+ return null;//invalid case+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ EnumDataType enumDataType = new EnumDataType(OatClassStatusEnum_O.class.getSimpleName(), 2);+ for (OatClassStatusEnum_O valueX : values()) {+ enumDataType.add(valueX.name(), valueX.getValue());+ }+ enumDataType.setCategoryPath(new CategoryPath("/oat"));+ return enumDataType;+ }+}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum_O_M2.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum_O_M2.javanew file mode 100644index 0000000000..714e1ffa86--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum_O_M2.java@@ -0,0 +1,78 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.oatclass;++import java.io.IOException;++import ghidra.program.model.data.*;+import ghidra.util.exception.DuplicateNameException;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/oreo-m2-release/runtime/mirror/class.h#128+ */+public enum OatClassStatusEnum_O_M2 implements OatClassStatusEnum {++ kStatusRetired(-3),+ kStatusErrorResolved(-2),+ kStatusErrorUnresolved(-1),+ kStatusNotReady(0),+ kStatusIdx(1),+ kStatusLoaded(2),+ kStatusResolving(3),+ kStatusResolved(4),+ kStatusVerifying(5),+ kStatusRetryVerificationAtRuntime(6),+ kStatusVerifyingAtRuntime(7),+ kStatusVerified(8),+ kStatusSuperclassValidated(9),+ kStatusInitializing(10),+ kStatusInitialized(11),+ kStatusMax(12);++ private short value;++ private OatClassStatusEnum_O_M2(short value) {+ this.value = value;+ }++ private OatClassStatusEnum_O_M2(int value) {+ this.value = (short) value;+ }++ public short getValue() {+ return value;+ }++ @Override+ public OatClassStatusEnum get(short value) {+ for (OatClassStatusEnum_O_M2 valueX : values()) {+ if (valueX.getValue() == value) {+ return valueX;+ }+ }+ return null;//invalid case+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ EnumDataType enumDataType = new EnumDataType(OatClassStatusEnum_O_M2.class.getSimpleName(), 2);+ for (OatClassStatusEnum_O_M2 valueX : values()) {+ enumDataType.add(valueX.name(), valueX.getValue());+ }+ enumDataType.setCategoryPath(new CategoryPath("/oat"));+ return enumDataType;+ }+}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum_P_10.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum_P_10.javanew file mode 100644index 0000000000..0f72b2a42d--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassStatusEnum_P_10.java@@ -0,0 +1,81 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.oatclass;++import java.io.IOException;++import ghidra.program.model.data.*;+import ghidra.util.exception.DuplicateNameException;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/pie-release/runtime/class_status.h#74+ *+ * https://android.googlesource.com/platform/art/+/refs/heads/android10-release/runtime/class_status.h#74+ *+ */+public enum OatClassStatusEnum_P_10 implements OatClassStatusEnum {++ kNotReady(0),+ kRetired(1),+ kErrorResolved(2),+ kErrorUnresolved(3),+ kIdx(4),+ kLoaded(5),+ kResolving(6),+ kResolved(7),+ kVerifying(8),+ kRetryVerificationAtRuntime(9),+ kVerifyingAtRuntime(10),+ kVerified(11),+ kSuperclassValidated(12),+ kInitializing(13),+ kInitialized(14),+ kLast(14);// kLast = kInitialized++ private byte value;++ private OatClassStatusEnum_P_10(byte value) {+ this.value = value;+ }++ private OatClassStatusEnum_P_10(int value) {+ this.value = (byte) value;+ }++ public byte getValue() {+ return value;+ }++ @Override+ public OatClassStatusEnum get(short value) {+ for (OatClassStatusEnum_P_10 valueX : values()) {+ if (valueX.getValue() == value) {+ return valueX;+ }+ }+ return null;//invalid case+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ EnumDataType enumDataType = new EnumDataType(OatClassStatusEnum_P_10.class.getSimpleName(), 2);+ for (OatClassStatusEnum_P_10 valueX : values()) {+ enumDataType.add(valueX.name(), valueX.getValue());+ }+ enumDataType.setCategoryPath(new CategoryPath("/oat"));+ return enumDataType;+ }+}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatClassType.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassType.javasimilarity index 64%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatClassType.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassType.javaindex 0fb59c849b..7496a86dc1 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatClassType.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClassType.java@@ -13,7 +13,11 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.oatclass;++import java.lang.reflect.Field;++import ghidra.program.model.data.*;/*** OatMethodOffsets are currently 5x32-bits=160-bits long, so if we can@@ -23,6 +27,7 @@ package ghidra.file.formats.android.oat;** https://android.googlesource.com/platform/art/+/lollipop-release/runtime/oat.h#152*+ * https://android.googlesource.com/platform/art/+/refs/heads/android-s-beta-5/runtime/oat_file.h#66*/public enum OatClassType {@@ -48,5 +53,25 @@ public enum OatClassType {* }* . . .*/- kOatClassMax//3+ kOatClassMax;//3++ /**+ * Converts this ENUM into a data type.+ * @return this ENUM converted into a data type+ */+ public static DataType toData() {+ EnumDataType enumDataType =+ new EnumDataType(OatClassType.class.getSimpleName(), 2);+ for (Field field : OatClassType.class.getDeclaredFields()) {+ try {+ OatClassType obj = (OatClassType) field.get(null);+ enumDataType.add(field.getName(), (short)obj.ordinal());+ }+ catch (Exception e) {+ //ignore...+ }+ }+ enumDataType.setCategoryPath(new CategoryPath("/oat"));+ return enumDataType;+ }}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/TypeLookupTableEntry_Android10.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Android10.javasimilarity index 53%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/TypeLookupTableEntry_Android10.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Android10.javaindex 056c41e15f..6abc851102 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/TypeLookupTableEntry_Android10.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Android10.java@@ -13,43 +13,35 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.oatclass;import java.io.IOException;-import ghidra.app.util.bin.*;+import ghidra.app.util.bin.BinaryReader;+import ghidra.file.formats.android.dex.format.ClassDataItem;import ghidra.program.model.data.DataType;import ghidra.util.exception.DuplicateNameException;/**- * https://android.googlesource.com/platform/art/+/refs/heads/android10-release/libdexfile/dex/type_lookup_table.h#110- * https://android.googlesource.com/platform/art/+/refs/heads/android11-release/libdexfile/dex/type_lookup_table.h#110+ * https://android.googlesource.com/platform/art/+/refs/heads/android10-release/runtime/oat_file.h#248*/-public class TypeLookupTableEntry_Android10 implements StructConverter {+public class OatClass_Android10 extends OatClass_Pie {- private int str_offset;- private short data;-- public TypeLookupTableEntry_Android10(BinaryReader reader) throws IOException {- str_offset = reader.readNextInt();- data = reader.readNextShort();- }-- public int getStringOffset() {- return str_offset;- }-- public short getData() {- return data;- }-- public boolean isEmpty() {- return str_offset == 0;+ OatClass_Android10(BinaryReader reader, ClassDataItem classDataItem, String oatVersion)+ throws IOException {+ super(reader, classDataItem, oatVersion);}@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- return StructConverterUtil.toDataType(TypeLookupTableEntry_Android10.class);+ DataType dataType = super.toDataType();+ try {+ renameDataType(dataType, OatClass_Android10.class.getSimpleName());+ }+ catch (Exception e) {+ //ignore...+ }+ return dataType;}}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Android11.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Android11.javanew file mode 100644index 0000000000..befc53ba76--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Android11.java@@ -0,0 +1,47 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.oatclass;++import java.io.IOException;++import ghidra.app.util.bin.BinaryReader;+import ghidra.file.formats.android.dex.format.ClassDataItem;+import ghidra.program.model.data.DataType;+import ghidra.util.exception.DuplicateNameException;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/android11-release/runtime/oat_file.h#278+ */+public class OatClass_Android11 extends OatClass_Android10 {++ OatClass_Android11(BinaryReader reader, ClassDataItem classDataItem, String oatVersion)+ throws IOException {+ super(reader, classDataItem, oatVersion);+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ DataType dataType = super.toDataType();+ try {+ renameDataType(dataType, OatClass_Android11.class.getSimpleName());+ }+ catch (Exception e) {+ //ignore...+ }+ return dataType;+ }++}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Android12.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Android12.javanew file mode 100644index 0000000000..ce11ad562a--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Android12.java@@ -0,0 +1,142 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.oatclass;++import java.io.IOException;++import ghidra.app.util.bin.BinaryReader;+import ghidra.file.formats.android.dex.format.ClassDataItem;+import ghidra.file.formats.android.oat.oatmethod.OatMethodOffsetsFactory;+import ghidra.program.model.data.*;+import ghidra.util.NumericUtilities;+import ghidra.util.exception.DuplicateNameException;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/android-s-beta-5/runtime/oat_file.h#283+ */+public class OatClass_Android12 extends OatClass {++ //https://android.googlesource.com/platform/art/+/master/libartbase/base/bit_vector.h#38+ public static final int kWordBytes = 4;++ private int num_methods_;++ private byte[] bitmap_ = new byte[0];++ OatClass_Android12(BinaryReader reader, ClassDataItem classDataItem, String oatVersion)+ throws IOException {++ super(reader, oatVersion);++ type_ = reader.readNextShort();++ if (type_ == OatClassType.kOatClassNoneCompiled.ordinal()) {+ return;+ }++ num_methods_ = reader.readNextInt();++ int methodOffsetsCount = 0;++ if (type_ == OatClassType.kOatClassSomeCompiled.ordinal()) {+ bitmap_ = reader.readNextByteArray(getBitmapSize());++ //For every set bit, there will be a corresponding entry in method_offsets.;+ for (int i = 0; i < bitmap_.length; ++i) {+ methodOffsetsCount += Integer.bitCount(Byte.toUnsignedInt(bitmap_[i]));+ }+ }+ else if (type_ == OatClassType.kOatClassAllCompiled.ordinal()) {+ methodOffsetsCount =+ classDataItem.getDirectMethodsSize() + classDataItem.getVirtualMethodsSize();+ }++ for (int i = 0; i < methodOffsetsCount; ++i) {+ methods_pointer_.add(OatMethodOffsetsFactory.getOatMethodOffsets(reader, oatVersion));+ }+ }++ public int getNumMethods() {+ return num_methods_;+ }++ /**+ * Compiled methods bitmap (present only when type = 1)+ * @return methods bitmap+ */+ public byte[] getBitmap() {+ return bitmap_;+ }++ /**+ * Returns true if this method index is declared native in the bitmap+ * @param methodIndex the method index+ * @return true if this method index is declared native in the bitmap+ */+ public boolean isMethodNative(int methodIndex) {+ int bytePos = (methodIndex / 8);+ int bitPos = methodIndex % 8;+ return (((bitmap_[bytePos] >> bitPos) & 0x1) == 0x1);+ }++ /**+ * Computes the number of bytes required to store the bitmap.+ * @return the number of bytes required to store the bitmap+ */+ private int getBitmapSize() {+ if (num_methods_ == 0) {+ return 0;+ }+ int size = (int)NumericUtilities.getUnsignedAlignedValue(num_methods_, 32);+ return size / 8;+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ String className = OatClass_Android12.class.getSimpleName();++ if (methods_pointer_.size() > 0) {+ className += "_" + methods_pointer_.size();+ }+ if (bitmap_.length > 0) {+ className += "_" + bitmap_.length;+ }++ Structure structure = new StructureDataType(className, 0);+ structure.add(statusEnum.toDataType(), "status_", null);+ structure.add(OatClassType.toData(), "type", null);++ if (type_ != OatClassType.kOatClassNoneCompiled.ordinal()) {+ structure.add(DWORD, "num_methods_", null);++ if (type_ == OatClassType.kOatClassSomeCompiled.ordinal()) {+ if (bitmap_.length > 0) {+ DataType bitmapDataType =+ new ArrayDataType(BYTE, bitmap_.length, BYTE.getLength());+ structure.add(bitmapDataType, "bitmap", null);+ }+ }++ for (int i = 0; i < methods_pointer_.size(); ++i) {+ structure.add(methods_pointer_.get(i).toDataType(), "methods_pointer_" + i, null);+ }+ }++ structure.setCategoryPath(new CategoryPath("/oat"));+ return structure;+ }++}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_KitKat.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_KitKat.javanew file mode 100644index 0000000000..118172bc6b--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_KitKat.java@@ -0,0 +1,57 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.oatclass;++import java.io.IOException;++import ghidra.app.util.bin.BinaryReader;+import ghidra.file.formats.android.dex.format.ClassDataItem;+import ghidra.program.model.data.*;+import ghidra.util.exception.DuplicateNameException;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/kitkat-release/runtime/oat_file.h#156+ */+public class OatClass_KitKat extends OatClass {++ private int methods_pointer_;++ public OatClass_KitKat(BinaryReader reader, ClassDataItem classDataItem, String oatVersion)+ throws IOException {++ super(reader, oatVersion);+ methods_pointer_ = reader.readNextInt();+ }++ public int getMethodsPointer() {+ return methods_pointer_;+ }++ @Override+ public boolean isMethodNative(int methodIndex) {+ return false;+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ Structure structure = new StructureDataType(OatClass_KitKat.class.getSimpleName(), 0);+ structure.add(statusEnum.toDataType(), "status_", null);+ structure.add(DWORD, "methods_pointer_", null);+ structure.setCategoryPath(new CategoryPath("/oat"));+ return structure;+ }++}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Lollipop.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Lollipop.javanew file mode 100644index 0000000000..e1afe95ca7--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Lollipop.java@@ -0,0 +1,125 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.oatclass;++import java.io.IOException;++import ghidra.app.util.bin.BinaryReader;+import ghidra.file.formats.android.dex.format.ClassDataItem;+import ghidra.file.formats.android.oat.oatmethod.OatMethodOffsetsFactory;+import ghidra.program.model.data.*;+import ghidra.util.exception.DuplicateNameException;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/lollipop-release/runtime/oat_file.h#205+ *+ * https://android.googlesource.com/platform/art/+/refs/heads/lollipop-mr1-fi-release/runtime/oat_file.h#202+ *+ * https://android.googlesource.com/platform/art/+/refs/heads/lollipop-wear-release/runtime/oat_file.h#211+ */+public class OatClass_Lollipop extends OatClass {++ private int bitmap_size_;+ private byte[] bitmap_ = new byte[0];++ OatClass_Lollipop(BinaryReader reader, ClassDataItem classDataItem, String oatVersion)+ throws IOException {++ super(reader, oatVersion);++ type_ = reader.readNextShort();++ int methodOffsetsCount = 0;++ if (type_ == OatClassType.kOatClassSomeCompiled.ordinal()) {+ bitmap_size_ = reader.readNextInt();+ bitmap_ = reader.readNextByteArray(bitmap_size_);++ //For every set bit, there will be a corresponding entry in method_offsets.;+ for (int i = 0; i < bitmap_size_; ++i) {+ methodOffsetsCount += Integer.bitCount(Byte.toUnsignedInt(bitmap_[i]));+ }+ }+ else if (type_ == OatClassType.kOatClassAllCompiled.ordinal()) {+ methodOffsetsCount =+ classDataItem.getDirectMethodsSize() + classDataItem.getVirtualMethodsSize();+ }++ for (int i = 0; i < methodOffsetsCount; ++i) {+ methods_pointer_.add(OatMethodOffsetsFactory.getOatMethodOffsets(reader, oatVersion));+ }+ }++ /**+ * Size of compiled methods bitmap (present only when type = 1)+ * @return size of methods bitmap+ */+ public int getBitmapSize() {+ return bitmap_size_;+ }++ /**+ * Compiled methods bitmap (present only when type = 1)+ * @return methods bitmap+ */+ public byte[] getBitmap() {+ return bitmap_;+ }++ /**+ * Returns true if this method index is declared native in the bitmap+ * @param methodIndex the method index+ * @return true if this method index is declared native in the bitmap+ */+ public boolean isMethodNative(int methodIndex) {+ int bytePos = methodIndex / 8;+ int bitPos = methodIndex % 8;+ return (((bitmap_[bytePos] >> bitPos) & 0x1) == 0x1);+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ String className = OatClass_Lollipop.class.getSimpleName();++ if (bitmap_size_ > 0) {+ className += "_" + bitmap_size_;+ }+ if (methods_pointer_.size() > 0) {+ className += "_" + methods_pointer_.size();+ }++ Structure structure = new StructureDataType(className, 0);++ structure.add(statusEnum.toDataType(), "status_", null);+ structure.add(WORD, "type_", null);++ if (type_ == OatClassType.kOatClassSomeCompiled.ordinal()) {+ structure.add(DWORD, "bitmap_size_", null);+ if (bitmap_size_ > 0) {+ DataType bitmapDataType = new ArrayDataType(BYTE, bitmap_size_, BYTE.getLength());+ structure.add(bitmapDataType, "bitmap_", null);+ }+ }++ for (int i = 0; i < methods_pointer_.size(); ++i) {+ structure.add(methods_pointer_.get(i).toDataType(), "methods_pointer_" + i, null);+ }++ structure.setCategoryPath(new CategoryPath("/oat"));+ return structure;+ }++}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Marshmallow.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Marshmallow.javanew file mode 100644index 0000000000..22ef0b709f--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Marshmallow.java@@ -0,0 +1,47 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.oatclass;++import java.io.IOException;++import ghidra.app.util.bin.BinaryReader;+import ghidra.file.formats.android.dex.format.ClassDataItem;+import ghidra.program.model.data.DataType;+import ghidra.util.exception.DuplicateNameException;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/marshmallow-release/runtime/oat_file.h#200+ */+public class OatClass_Marshmallow extends OatClass_Lollipop {++ OatClass_Marshmallow(BinaryReader reader, ClassDataItem classDataItem, String oatVersion)+ throws IOException {+ super(reader, classDataItem, oatVersion);+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ DataType dataType = super.toDataType();+ try {+ renameDataType(dataType, OatClass_Marshmallow.class.getSimpleName());+ }+ catch (Exception e) {+ //ignore...+ }+ return dataType;+ }++}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Nougat.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Nougat.javanew file mode 100644index 0000000000..a385b9fecb--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Nougat.java@@ -0,0 +1,47 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.oatclass;++import java.io.IOException;++import ghidra.app.util.bin.BinaryReader;+import ghidra.file.formats.android.dex.format.ClassDataItem;+import ghidra.program.model.data.DataType;+import ghidra.util.exception.DuplicateNameException;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/nougat-release/runtime/oat_file.h#197+ */+public class OatClass_Nougat extends OatClass_Marshmallow {++ OatClass_Nougat(BinaryReader reader, ClassDataItem classDataItem, String oatVersion)+ throws IOException {+ super(reader, classDataItem, oatVersion);+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ DataType dataType = super.toDataType();+ try {+ renameDataType(dataType, OatClass_Nougat.class.getSimpleName());+ }+ catch (Exception e) {+ //ignore...+ }+ return dataType;+ }++}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Oreo.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Oreo.javanew file mode 100644index 0000000000..9550e63bfd--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Oreo.java@@ -0,0 +1,47 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.oatclass;++import java.io.IOException;++import ghidra.app.util.bin.BinaryReader;+import ghidra.file.formats.android.dex.format.ClassDataItem;+import ghidra.program.model.data.DataType;+import ghidra.util.exception.DuplicateNameException;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/oreo-release/runtime/oat_file.h#213+ */+public class OatClass_Oreo extends OatClass_Nougat {++ OatClass_Oreo(BinaryReader reader, ClassDataItem classDataItem, String oatVersion)+ throws IOException {+ super(reader, classDataItem, oatVersion);+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ DataType dataType = super.toDataType();+ try {+ renameDataType(dataType, OatClass_Oreo.class.getSimpleName());+ }+ catch (Exception e) {+ //ignore...+ }+ return dataType;+ }++}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_OreoM2.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_OreoM2.javanew file mode 100644index 0000000000..3bbea9b5a5--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_OreoM2.java@@ -0,0 +1,47 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.oatclass;++import java.io.IOException;++import ghidra.app.util.bin.BinaryReader;+import ghidra.file.formats.android.dex.format.ClassDataItem;+import ghidra.program.model.data.DataType;+import ghidra.util.exception.DuplicateNameException;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/oreo-m2-release/runtime/oat_file.h#219+ */+public class OatClass_OreoM2 extends OatClass_Oreo {++ OatClass_OreoM2(BinaryReader reader, ClassDataItem classDataItem, String oatVersion)+ throws IOException {+ super(reader, classDataItem, oatVersion);+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ DataType dataType = super.toDataType();+ try {+ renameDataType(dataType, OatClass_OreoM2.class.getSimpleName());+ }+ catch (Exception e) {+ //ignore...+ }+ return dataType;+ }++}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Pie.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Pie.javanew file mode 100644index 0000000000..a8ef49d652--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatclass/OatClass_Pie.java@@ -0,0 +1,46 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.oatclass;++import java.io.IOException;++import ghidra.app.util.bin.BinaryReader;+import ghidra.file.formats.android.dex.format.ClassDataItem;+import ghidra.program.model.data.DataType;+import ghidra.util.exception.DuplicateNameException;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/pie-release/runtime/oat_file.h#248+ */+public class OatClass_Pie extends OatClass_OreoM2 {++ OatClass_Pie(BinaryReader reader, ClassDataItem classDataItem, String oatVersion)+ throws IOException {+ super(reader, classDataItem, oatVersion);+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ DataType dataType = super.toDataType();+ try {+ renameDataType(dataType, OatClass_Pie.class.getSimpleName());+ }+ catch (Exception e) {+ //ignore...+ }+ return dataType;+ }+}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile.javasimilarity index 92%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile.javaindex 9c78be8f2a..96c216a57b 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile.java@@ -13,18 +13,18 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.oatdexfile;import ghidra.app.util.bin.StructConverter;-import ghidra.app.util.bin.StructConverterUtil;import ghidra.app.util.importer.MessageLog;import ghidra.file.formats.android.dex.format.DexHeader;+import ghidra.file.formats.android.oat.OatHeader;import ghidra.program.model.listing.Program;import ghidra.util.task.TaskMonitor;public abstract class OatDexFile implements StructConverter {- public static final String PREFIX = StructConverterUtil.parseName(OatDexFile.class);+ public static final String PREFIX = OatDexFile.class.getSimpleName();/*** Returns the path string (not null terminated).diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFileFactory.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFileFactory.javasimilarity index 60%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFileFactory.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFileFactory.javaindex cc793064c6..5c6e7ea1eb 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFileFactory.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFileFactory.java@@ -13,17 +13,18 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.oatdexfile;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;-import ghidra.file.formats.android.vdex.VdexHeader;+import ghidra.file.formats.android.oat.OatConstants;+import ghidra.file.formats.android.oat.bundle.OatBundle;public final class OatDexFileFactory {public final static OatDexFile getOatDexFile(BinaryReader reader, String oatVersion,- Object additionalData) throws IOException {+ OatBundle bundle) throws IOException {switch (oatVersion) {case OatConstants.VERSION_KITKAT_RELEASE:@@ -38,27 +39,20 @@ public final class OatDexFileFactory {case OatConstants.VERSION_NOUGAT_MR1_RELEASE:return new OatDexFile_Nougat(reader);case OatConstants.VERSION_OREO_RELEASE:- case OatConstants.VERSION_OREO_DR3_RELEASE: {- VdexHeader vdexHeader = (VdexHeader) additionalData;- return new OatDexFile_Oreo(reader, vdexHeader);- }- case OatConstants.VERSION_OREO_M2_RELEASE: {- VdexHeader vdexHeader = (VdexHeader) additionalData;- return new OatDexFile_OreoM2(reader, vdexHeader);- }- case OatConstants.VERSION_PIE_RELEASE: {- VdexHeader vdexHeader = (VdexHeader) additionalData;- return new OatDexFile_Pie(reader, vdexHeader);- }- case OatConstants.VERSION_10_RELEASE: {- VdexHeader vdexHeader = (VdexHeader) additionalData;- return new OatDexFile_Android10(reader, vdexHeader);- }- case OatConstants.VERSION_11_RELEASE: {- VdexHeader vdexHeader = (VdexHeader) additionalData;- return new OatDexFile_Android11(reader, vdexHeader);- }+ case OatConstants.VERSION_OREO_DR3_RELEASE:+ return new OatDexFile_Oreo(reader, bundle);+ case OatConstants.VERSION_OREO_M2_RELEASE:+ return new OatDexFile_OreoM2(reader, bundle);+ case OatConstants.VERSION_PIE_RELEASE:+ return new OatDexFile_Pie(reader, bundle);+ case OatConstants.VERSION_10_RELEASE:+ return new OatDexFile_Android10(reader, bundle);+ case OatConstants.VERSION_11_RELEASE:+ return new OatDexFile_Android11(reader, bundle);+ case OatConstants.VERSION_12_RELEASE:+ return new OatDexFile_Android12(reader, bundle);}+throw new IOException("Unsupported OAT version: " + oatVersion);}}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFileUtilities.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFileUtilities.javasimilarity index 91%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFileUtilities.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFileUtilities.javaindex 488c0aae07..832ee3930f 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFileUtilities.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFileUtilities.java@@ -13,7 +13,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.oatdexfile;import java.util.List;@@ -21,6 +21,12 @@ import ghidra.app.util.bin.*;import ghidra.app.util.importer.MessageLog;import ghidra.file.formats.android.dex.format.*;import ghidra.file.formats.android.dex.util.DexUtil;+import ghidra.file.formats.android.oat.OatHeader;+import ghidra.file.formats.android.oat.OatUtilities;+import ghidra.file.formats.android.oat.oatclass.*;+import ghidra.file.formats.android.oat.oatmethod.OatMethodOffsets;+import ghidra.file.formats.android.oat.quickmethod.OatQuickMethodHeader;+import ghidra.file.formats.android.oat.quickmethod.OatQuickMethodHeaderFactory;import ghidra.program.model.address.Address;import ghidra.program.model.data.*;import ghidra.program.model.listing.*;@@ -60,6 +66,7 @@ public final class OatDexFileUtilities {DataType dword = new DWordDataType();try {for (int i = 0; i < dexHeader.getClassDefsIdsSize(); ++i) {+ program.getListing().clearCodeUnits(address, address, false, monitor);program.getListing().createData(address, dword);int value = program.getMemory().getInt(address);Address destinationAddress = oatDataSymbol.getAddress().add(value);@@ -80,7 +87,7 @@ public final class OatDexFileUtilities {BinaryReader oatClassHeaderReader =new BinaryReader(oatClassHeaderProvider, !program.getLanguage().isBigEndian());- OatClass oatClassHeader = new OatClass(oatClassHeaderReader,+ OatClass oatClassHeader = OatClassFactory.getOatClass(oatClassHeaderReader,classDefItem.getClassDataItem(), oatHeader.getVersion());markupMethod(oatHeader, oatClassHeader, dexHeader, classDefItem, program,@@ -111,13 +118,13 @@ public final class OatDexFileUtilities {List<EncodedMethod> allMethods =OatUtilities.getAllMethods(classDefItem.getClassDataItem());- if (oatClassHeader.getType() == OatClassType.kOatClassAllCompiled.ordinal()) {+ if (oatClassHeader.getType() == OatClassType.kOatClassAllCompiled) {for (int j = 0; j < oatClassHeader.getMethodOffsets().size(); ++j) {monitor.checkCanceled();OatMethodOffsets methodOffset = oatClassHeader.getMethodOffsets().get(j);if (methodOffset.getCodeOffset() == 0) {- continue;//TODO what does 0 mean?+ continue;//undefined address}Address toAddr = oatDataSymbol.getAddress().add(methodOffset.getCodeOffset());toAddr = OatUtilities.adjustForThumbAsNeeded(oatHeader, program, toAddr, log);@@ -131,14 +138,14 @@ public final class OatDexFileUtilities {symbolTable.createLabel(toAddr, methodName, classNameSpace, SourceType.ANALYSIS);}}- else if (oatClassHeader.getType() == OatClassType.kOatClassSomeCompiled.ordinal()) {+ else if (oatClassHeader.getType() == OatClassType.kOatClassSomeCompiled) {int offset = 0;for (int j = 0; j < allMethods.size(); ++j) {monitor.checkCanceled();if (oatClassHeader.isMethodNative(j)) {OatMethodOffsets methodOffset = oatClassHeader.getMethodOffsets().get(offset++);if (methodOffset.getCodeOffset() == 0) {- continue;//TODO what does 0 mean?+ continue;//undefined address}Address toAddr = oatDataSymbol.getAddress().add(methodOffset.getCodeOffset());toAddr = OatUtilities.adjustForThumbAsNeeded(oatHeader, program, toAddr, log);@@ -154,10 +161,10 @@ public final class OatDexFileUtilities {}}}- else if (oatClassHeader.getType() == OatClassType.kOatClassNoneCompiled.ordinal()) {+ else if (oatClassHeader.getType() == OatClassType.kOatClassNoneCompiled) {// do nothing... all methods are still dalvik}- else if (oatClassHeader.getType() == OatClassType.kOatClassMax.ordinal()) {+ else if (oatClassHeader.getType() == OatClassType.kOatClassMax) {throw new RuntimeException("invalid state!!");}}@@ -170,15 +177,17 @@ public final class OatDexFileUtilities {ReferenceManager referenceManager = program.getReferenceManager();Listing listing = program.getListing();+ listing.clearCodeUnits(address, address, false, monitor);Data oatClassHeaderData = listing.createData(address, oatClassHeader.toDataType());+for (int j = 0; j < oatClassHeaderData.getNumComponents(); ++j) {monitor.checkCanceled();Data component = oatClassHeaderData.getComponent(j);- if (component.getFieldName().startsWith("methodOffsets_")) {+ if (component.getFieldName().startsWith("methods_pointer_")) {Data methodOffsetData = component.getComponent(0);Scalar scalar = methodOffsetData.getScalar(0);if (scalar.getUnsignedValue() == 0) {- continue;//TODO what does 0 mean?+ continue;//undefined address}Address toAddr = oatDataSymbol.getAddress().add(scalar.getUnsignedValue());toAddr = OatUtilities.adjustForThumbAsNeeded(oatHeader, program, toAddr, log);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_Android10.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Android10.javasimilarity index 74%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_Android10.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Android10.javaindex 49c96c2a44..205c03f53b 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_Android10.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Android10.java@@ -13,13 +13,12 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.oatdexfile;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;-import ghidra.file.formats.android.vdex.VdexHeader;+import ghidra.file.formats.android.oat.bundle.OatBundle;import ghidra.program.model.data.DataType;import ghidra.util.exception.DuplicateNameException;@@ -29,16 +28,16 @@ import ghidra.util.exception.DuplicateNameException;*/public class OatDexFile_Android10 extends OatDexFile_Pie {- public OatDexFile_Android10(BinaryReader reader, VdexHeader vdexHeader) throws IOException {- super(reader, vdexHeader);+ public OatDexFile_Android10(BinaryReader reader, OatBundle bundle) throws IOException {+ super(reader, bundle);}@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {DataType dataType = super.toDataType();try {- String className = StructConverterUtil.parseName(OatDexFile_Android10.class);- dataType.setName(className);+ dataType.setName(OatDexFile_Android10.class.getSimpleName()+ "_" ++ getDexFileLocation().length());}catch (Exception e) {//ignorediff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_Android11.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Android11.javasimilarity index 74%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_Android11.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Android11.javaindex 6400f8393d..174f3938ff 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_Android11.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Android11.java@@ -13,13 +13,12 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.oatdexfile;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;-import ghidra.file.formats.android.vdex.VdexHeader;+import ghidra.file.formats.android.oat.bundle.OatBundle;import ghidra.program.model.data.DataType;import ghidra.util.exception.DuplicateNameException;@@ -29,16 +28,16 @@ import ghidra.util.exception.DuplicateNameException;*/public class OatDexFile_Android11 extends OatDexFile_Pie {- public OatDexFile_Android11(BinaryReader reader, VdexHeader vdexHeader) throws IOException {- super(reader, vdexHeader);+ public OatDexFile_Android11(BinaryReader reader, OatBundle bundle) throws IOException {+ super(reader, bundle);}@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {DataType dataType = super.toDataType();try {- String className = StructConverterUtil.parseName(OatDexFile_Android11.class);- dataType.setName(className);+ dataType.setName(OatDexFile_Android11.class.getSimpleName() + "_" ++ getDexFileLocation().length());}catch (Exception e) {//ignorediff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Android12.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Android12.javanew file mode 100644index 0000000000..a59cbc7024--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Android12.java@@ -0,0 +1,226 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.oatdexfile;++import java.io.IOException;++import ghidra.app.util.bin.BinaryReader;+import ghidra.app.util.importer.MessageLog;+import ghidra.file.formats.android.dex.format.DexHeader;+import ghidra.file.formats.android.oat.OatHeader;+import ghidra.file.formats.android.oat.OatUtilities;+import ghidra.file.formats.android.oat.bundle.OatBundle;+import ghidra.file.formats.android.oat.tlt.TypeLookupTable;+import ghidra.file.formats.android.oat.tlt.TypeLookupTableFactory;+import ghidra.program.model.address.Address;+import ghidra.program.model.data.*;+import ghidra.program.model.listing.*;+import ghidra.program.model.scalar.Scalar;+import ghidra.program.model.symbol.*;+import ghidra.util.exception.DuplicateNameException;+import ghidra.util.task.TaskMonitor;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/android-s-beta-5/runtime/oat_file.h#596+ */+public class OatDexFile_Android12 extends OatDexFile {++ private int dex_file_location_;+ private String canonical_dex_file_location_;+ private int dex_file_location_checksum_;+ private int dex_file_pointer_;+ private int lookup_table_data_;+ private int method_bss_mapping_;+ private int type_bss_mapping_;+ private int public_type_bss_mapping_;+ private int package_type_bss_mapping_;+ private int string_bss_mapping_;+ private int oat_class_offsets_pointer_;+ private int lookup_table_;+ private int dex_layout_sections_;//according to spec this field should exist, but it does not++ private TypeLookupTable typeLookupTable;++ private long _offset;+ private DexHeader dexHeader;++ public OatDexFile_Android12(BinaryReader reader, OatBundle bundle)+ throws IOException {++ _offset = reader.getPointerIndex();++ dex_file_location_ = reader.readNextInt();+ canonical_dex_file_location_ = reader.readNextAsciiString(dex_file_location_);+ dex_file_location_checksum_ = reader.readNextInt();+ dex_file_pointer_ = reader.readNextInt();+ lookup_table_data_ = reader.readNextInt();+ method_bss_mapping_ = reader.readNextInt();+ type_bss_mapping_ = reader.readNextInt();+ public_type_bss_mapping_ = reader.readNextInt();+ package_type_bss_mapping_ = reader.readNextInt();+ string_bss_mapping_ = reader.readNextInt();+ oat_class_offsets_pointer_ = reader.readNextInt();+ lookup_table_ = reader.readNextInt();++ //dex_layout_sections_ = reader.readNextInt( );//according to spec this field should exist, but it does not++ BinaryReader typeLookupTableReader = reader.clone(lookup_table_);+ typeLookupTable = TypeLookupTableFactory.getTypeLookupTable(typeLookupTableReader,+ bundle.getOatHeader().getVersion());++ dexHeader = bundle.getDexHeaderByChecksum(dex_file_location_checksum_);+ }++ @Override+ public int getDexFileChecksum() {+ return dex_file_location_checksum_;+ }++ @Override+ public String getDexFileLocation() {+ return canonical_dex_file_location_;+ }++ @Override+ public int getDexFileOffset() {+ return dex_file_pointer_;+ }++ @Override+ public DexHeader getDexHeader() {+ return dexHeader;+ }++ @Override+ public boolean isDexHeaderExternal() {+ return true;+ }++ @Override+ public void markup(OatHeader oatHeader, Program program, TaskMonitor monitor, MessageLog log)+ throws Exception {++ Symbol oatDataSymbol = OatUtilities.getOatDataSymbol(program);+ Address address = oatDataSymbol.getAddress();++ Address dataAddress = address.add(_offset);++ program.getListing().setComment(dataAddress, CodeUnit.PLATE_COMMENT, getDexFileLocation());+ program.getListing().clearCodeUnits(dataAddress, dataAddress, false, monitor);+ Data data = program.getListing().createData(dataAddress, toDataType());++ for (int i = 0; i < data.getNumComponents(); ++i) {+ monitor.checkCanceled();+ Data componentI = data.getComponent(i);+ if (componentI.getFieldName().startsWith("lookup_table_data_") ||+ componentI.getFieldName().startsWith("oat_class_offsets_pointer_") ||+ componentI.getFieldName().startsWith("lookup_table_data_") ||+ componentI.getFieldName().startsWith("method_bss_mapping_") ||+ componentI.getFieldName().startsWith("type_bss_mapping_") ||+ componentI.getFieldName().startsWith("public_type_bss_mapping_") ||+ componentI.getFieldName().startsWith("package_type_bss_mapping_") ||+ componentI.getFieldName().startsWith("string_bss_mapping_") ||+ componentI.getFieldName().startsWith("oat_class_offsets_pointer_") ||+ componentI.getFieldName().startsWith("lookup_table_") ||+ componentI.getFieldName().startsWith("dex_layout_sections_")) {++ Scalar scalar = componentI.getScalar(0);+ if (scalar.getUnsignedValue() == 0) {+ continue;+ }++ Address destinationAddress = address.add(scalar.getUnsignedValue());+ program.getReferenceManager()+ .addMemoryReference(componentI.getMinAddress(), destinationAddress,+ RefType.DATA, SourceType.ANALYSIS, 0);+ program.getSymbolTable()+ .createLabel(destinationAddress, componentI.getFieldName(),+ SourceType.ANALYSIS);++ if (componentI.getFieldName().startsWith("lookup_table_data_")) {+ OatDexFileUtilities.markupLookupTableData(this.getClass(), destinationAddress,+ dexHeader, oatHeader, program, monitor, log);+ }+ else if (componentI.getFieldName().startsWith("lookup_table_")) {+ if (typeLookupTable != null) {+ DataType dataType = typeLookupTable.toDataType();+ program.getListing().createData(destinationAddress, dataType);+ }+ }+ }+ }+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ Structure structure = new StructureDataType(+ OatDexFile_Android12.class.getSimpleName() + "_" + dex_file_location_, 0);++ structure.add(DWORD, "dex_file_location_", null);+ structure.add(STRING, dex_file_location_, "canonical_dex_file_location_", null);+ structure.add(DWORD, "dex_file_location_checksum_", null);+ structure.add(DWORD, "dex_file_pointer_", null);+ structure.add(DWORD, "lookup_table_data_", null);+ structure.add(DWORD, "method_bss_mapping_", null);+ structure.add(DWORD, "type_bss_mapping_", null);+ structure.add(DWORD, "public_type_bss_mapping_", null);+ structure.add(DWORD, "package_type_bss_mapping_", null);+ structure.add(DWORD, "string_bss_mapping_", null);+ structure.add(DWORD, "oat_class_offsets_pointer_", null);+ structure.add(DWORD, "lookup_table_", null);+ //structure.add( DWORD, "dex_layout_sections_", null );//according to spec this field should exist, but it does not++ structure.setCategoryPath(new CategoryPath("/oat"));+ return structure;+ }++ public int getLookupTableData() {+ return lookup_table_data_;+ }++ public int getTypeBssMapping() {+ return type_bss_mapping_;+ }++ public int getPublicTypeBssMapping() {+ return public_type_bss_mapping_;+ }++ public int getStringBssMapping() {+ return string_bss_mapping_;+ }++ public int getOatClassOffsetsPointer() {+ return oat_class_offsets_pointer_;+ }++ public int getDexLayoutSections() {+ return dex_layout_sections_;+ }++ public int getMethodBssMapping() {+ return method_bss_mapping_;+ }++ public int getPackageTypeBssMapping() {+ return package_type_bss_mapping_;+ }++ public int getLookupTable() {+ return lookup_table_;+ }++}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_KitKat.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_KitKat.javasimilarity index 57%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_KitKat.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_KitKat.javaindex cf14fe7e3c..48972ec832 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_KitKat.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_KitKat.java@@ -13,7 +13,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.oatdexfile;import java.io.IOException;import java.util.ArrayList;@@ -22,16 +22,21 @@ import java.util.List;import ghidra.app.util.bin.*;import ghidra.app.util.importer.MessageLog;import ghidra.file.formats.android.dex.DexHeaderFactory;-import ghidra.file.formats.android.dex.format.*;+import ghidra.file.formats.android.dex.format.ClassDefItem;+import ghidra.file.formats.android.dex.format.DexHeader;import ghidra.file.formats.android.dex.util.DexUtil;+import ghidra.file.formats.android.oat.OatHeader;+import ghidra.file.formats.android.oat.OatUtilities;+import ghidra.file.formats.android.oat.oatclass.OatClass;+import ghidra.file.formats.android.oat.oatclass.OatClassFactory;import ghidra.program.model.address.Address;import ghidra.program.model.data.*;import ghidra.program.model.listing.*;import ghidra.program.model.mem.Memory;import ghidra.program.model.scalar.Scalar;import ghidra.program.model.symbol.*;-import ghidra.program.model.util.CodeUnitInsertionException;-import ghidra.util.exception.*;+import ghidra.util.exception.CancelledException;+import ghidra.util.exception.DuplicateNameException;import ghidra.util.task.TaskMonitor;/**@@ -97,6 +102,7 @@ class OatDexFile_KitKat extends OatDexFile {@Overridepublic void markup(OatHeader oatHeader, Program program, TaskMonitor monitor, MessageLog log)throws Exception {+Symbol oatDataSymbol = OatUtilities.getOatDataSymbol(program);Address address = oatDataSymbol.getAddress();@@ -159,13 +165,14 @@ class OatDexFile_KitKat extends OatDexFile {BinaryReader oatClassHeaderReader =new BinaryReader(oatClassHeaderProvider, !program.getLanguage().isBigEndian());- OatClass oatClassHeader = new OatClass(oatClassHeaderReader,+ OatClass oatClassHeader = OatClassFactory.getOatClass(oatClassHeaderReader,classDefItem.getClassDataItem(), oatHeader.getVersion());- markupMethod(oatHeader, oatClassHeader, dexHeader, classDefItem, program, symbolTable,- oatDataSymbol, classNameSpace, log, monitor);+ OatDexFileUtilities.markupMethod(oatHeader, oatClassHeader, dexHeader, classDefItem,+ program, oatDataSymbol, classNameSpace, log, monitor);- markupClassHeaderData(program, oatDataSymbol, offsetAddress, oatHeader, oatClassHeader,+ OatDexFileUtilities.markupClassHeaderData(program, oatDataSymbol, offsetAddress,+ oatHeader, oatClassHeader,log, monitor);}}@@ -191,135 +198,6 @@ class OatDexFile_KitKat extends OatDexFile {}}- private void markupMethod(OatHeader oatHeader, OatClass oatClassHeader, DexHeader dexHeader,- ClassDefItem classDefItem, Program program, SymbolTable symbolTable,- Symbol oatDataSymbol, Namespace classNameSpace, MessageLog log, TaskMonitor monitor)- throws CancelledException, InvalidInputException {-- if (classDefItem.getClassDataOffset() == 0) {- return;- }- List<EncodedMethod> allMethods =- OatUtilities.getAllMethods(classDefItem.getClassDataItem());-- if (oatClassHeader.getType() == OatClassType.kOatClassAllCompiled.ordinal()) {- for (int j = 0; j < oatClassHeader.getMethodOffsets().size(); ++j) {- monitor.checkCanceled();- monitor.setMaximum(oatClassHeader.getMethodOffsets().size());- monitor.setProgress(j);-- OatMethodOffsets methodOffset = oatClassHeader.getMethodOffsets().get(j);- if (methodOffset.getCodeOffset() == 0) {- continue;//TODO what does 0 mean?- }- Address toAddr = oatDataSymbol.getAddress().add(methodOffset.getCodeOffset());- toAddr = OatUtilities.adjustForThumbAsNeeded(oatHeader, program, toAddr, log);-- EncodedMethod encodedMethod = allMethods.get(j);-- MethodIDItem methodID = dexHeader.getMethods().get(encodedMethod.getMethodIndex());-- String methodName = DexUtil.convertToString(dexHeader, methodID.getNameIndex());-- symbolTable.createLabel(toAddr, methodName, classNameSpace, SourceType.ANALYSIS);- }- }- else if (oatClassHeader.getType() == OatClassType.kOatClassSomeCompiled.ordinal()) {- int offset = 0;- for (int j = 0; j < allMethods.size(); ++j) {- monitor.checkCanceled();- monitor.setMaximum(allMethods.size());- monitor.setProgress(j);-- if (oatClassHeader.isMethodNative(j)) {- OatMethodOffsets methodOffset = oatClassHeader.getMethodOffsets().get(offset++);- if (methodOffset.getCodeOffset() == 0) {- continue;//TODO what does 0 mean?- }- Address toAddr = oatDataSymbol.getAddress().add(methodOffset.getCodeOffset());- toAddr = OatUtilities.adjustForThumbAsNeeded(oatHeader, program, toAddr, log);-- EncodedMethod encodedMethod = allMethods.get(j);- MethodIDItem methodID =- dexHeader.getMethods().get(encodedMethod.getMethodIndex());-- String methodName = DexUtil.convertToString(dexHeader, methodID.getNameIndex());-- symbolTable.createLabel(toAddr, methodName, classNameSpace,- SourceType.ANALYSIS);- }- }- }- else if (oatClassHeader.getType() == OatClassType.kOatClassNoneCompiled.ordinal()) {- // do nothing... all methods are still dalvik- }- else if (oatClassHeader.getType() == OatClassType.kOatClassMax.ordinal()) {- throw new RuntimeException("invalid state!!");- }- }-- private void markupClassHeaderData(Program program, Symbol oatDataSymbol, Address address,- OatHeader oatHeader, OatClass oatClassHeader, MessageLog log, TaskMonitor monitor)- throws Exception {-- SymbolTable symbolTable = program.getSymbolTable();- ReferenceManager referenceManager = program.getReferenceManager();- Listing listing = program.getListing();-- Data oatClassHeaderData = listing.createData(address, oatClassHeader.toDataType());- for (int j = 0; j < oatClassHeaderData.getNumComponents(); ++j) {- monitor.checkCanceled();- monitor.setMaximum(oatClassHeaderData.getNumComponents());- monitor.setProgress(j);-- Data component = oatClassHeaderData.getComponent(j);- if (component.getFieldName().startsWith("methodOffsets_")) {- Data methodOffsetData = component.getComponent(0);- Scalar scalar = methodOffsetData.getScalar(0);- if (scalar.getUnsignedValue() == 0) {- continue;//TODO what does 0 mean?- }- Address toAddr = oatDataSymbol.getAddress().add(scalar.getUnsignedValue());- toAddr = OatUtilities.adjustForThumbAsNeeded(oatHeader, program, toAddr, log);- referenceManager.addMemoryReference(methodOffsetData.getMinAddress(), toAddr,- RefType.DATA, SourceType.ANALYSIS, 0);- symbolTable.addExternalEntryPoint(toAddr);-- Address quickHeaderAddress = toAddr.subtract(OatQuickMethodHeaderFactory- .getOatQuickMethodHeaderSize(oatHeader.getVersion()));- if (listing.isUndefined(quickHeaderAddress, quickHeaderAddress)) {- ByteProvider oqmhProvider =- new MemoryByteProvider(program.getMemory(), quickHeaderAddress);- BinaryReader quickReader =- new BinaryReader(oqmhProvider, !program.getLanguage().isBigEndian());- OatQuickMethodHeader quickHeader = OatQuickMethodHeaderFactory- .getOatQuickMethodHeader(quickReader, oatHeader.getVersion());- DataType dataType = quickHeader.toDataType();- try {- listing.createData(quickHeaderAddress, dataType);- }- catch (CodeUnitInsertionException e) {- log.appendMsg(e.getMessage());- }- }--// Address oqmhAddress = toAddr.subtract( OatQuickMethodHeader001to064.SIZE );-// if ( listing.isUndefined( oqmhAddress, oqmhAddress ) ) {-// ByteProvider oqmhProvider = new MemoryByteProvider( program.getMemory( ), oqmhAddress );-// BinaryReader oqmhReader = new BinaryReader( oqmhProvider, !program.getLanguage( ).isBigEndian( ) );-// OatQuickMethodHeader oqmh = new OatQuickMethodHeader001to064( oqmhReader );-// DataType dataType = oqmh.toDataType( );-// try {-// listing.createData( oqmhAddress, dataType );-// }-// catch ( CodeUnitInsertionException e ) {-// log.appendMsg( e.getMessage( ) );-// }-// }- }- }- }-private List<Data> getOatDexFileHeaderData(Data oatHeaderData, TaskMonitor monitor)throws Exception {List<Data> list = new ArrayList<Data>();@@ -353,9 +231,8 @@ class OatDexFile_KitKat extends OatDexFile {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(OatDexFile_KitKat.class);- Structure structure =- new StructureDataType(className + "_" + oat_class_offsets_pointer_.length, 0);+ Structure structure = new StructureDataType(OatDexFile_KitKat.class.getSimpleName() ++ "_" + oat_class_offsets_pointer_.length, 0);structure.add(DWORD, "dex_file_location_size_", null);structure.add(STRING, dex_file_location_size_, "dex_file_location_", null);structure.add(DWORD, "dex_file_location_checksum_", null);@@ -363,6 +240,7 @@ class OatDexFile_KitKat extends OatDexFile {Structure dexClassOffsetsStructure =new StructureDataType("dexClassOffsets_" + oat_class_offsets_pointer_.length, 0);+for (int i = 0; i < oat_class_offsets_pointer_.length; ++i) {dexClassOffsetsStructure.add(DWORD, "oat_class_offsets_pointer_" + i, null);}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_Lollipop.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Lollipop.javasimilarity index 88%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_Lollipop.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Lollipop.javaindex 0bcd08195d..b375cd3bb1 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_Lollipop.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Lollipop.java@@ -13,12 +13,11 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.oatdexfile;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;import ghidra.program.model.data.DataType;import ghidra.util.exception.DuplicateNameException;@@ -37,7 +36,7 @@ class OatDexFile_Lollipop extends OatDexFile_KitKat {public DataType toDataType() throws DuplicateNameException, IOException {DataType dataType = super.toDataType();try {- dataType.setName(StructConverterUtil.parseName(OatDexFile_Lollipop.class) + "_" ++ dataType.setName(OatDexFile_Lollipop.class.getSimpleName() + "_" +oat_class_offsets_pointer_.length);}catch (Exception e) {diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_Marshmallow.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Marshmallow.javasimilarity index 88%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_Marshmallow.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Marshmallow.javaindex 42d90550f5..9054928d2d 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_Marshmallow.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Marshmallow.java@@ -13,12 +13,11 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.oatdexfile;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;import ghidra.program.model.data.DataType;import ghidra.util.exception.DuplicateNameException;@@ -37,7 +36,7 @@ class OatDexFile_Marshmallow extends OatDexFile_Lollipop {public DataType toDataType() throws DuplicateNameException, IOException {DataType dataType = super.toDataType();try {- dataType.setName(StructConverterUtil.parseName(OatDexFile_Marshmallow.class) + "_" ++ dataType.setName(OatDexFile_Marshmallow.class.getSimpleName() + "_" +oat_class_offsets_pointer_.length);}catch (Exception e) {diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_Nougat.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Nougat.javasimilarity index 94%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_Nougat.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Nougat.javaindex fe642209bf..a4599d06fa 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_Nougat.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Nougat.java@@ -13,7 +13,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.oatdexfile;import java.io.IOException;@@ -21,6 +21,8 @@ import ghidra.app.util.bin.*;import ghidra.app.util.importer.MessageLog;import ghidra.file.formats.android.dex.DexHeaderFactory;import ghidra.file.formats.android.dex.format.DexHeader;+import ghidra.file.formats.android.oat.OatHeader;+import ghidra.file.formats.android.oat.OatUtilities;import ghidra.program.model.address.Address;import ghidra.program.model.data.*;import ghidra.program.model.listing.*;@@ -151,9 +153,8 @@ class OatDexFile_Nougat extends OatDexFile {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(OatDexFile_Nougat.class);- Structure structure =- new StructureDataType(className + "_" + Integer.toHexString(dex_file_location_), 0);+ Structure structure = new StructureDataType(OatDexFile_Nougat.class.getSimpleName() ++ "_" + Integer.toHexString(dex_file_location_), 0);structure.add(DWORD, "dex_file_location_", null);structure.add(STRING, dex_file_location_, "canonical_dex_file_location_", null);structure.add(DWORD, "dex_file_location_checksum_", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_Oreo.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Oreo.javasimilarity index 57%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_Oreo.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Oreo.javaindex a8ecbd235c..8b188f3bd4 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_Oreo.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Oreo.java@@ -13,12 +13,14 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.oatdexfile;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;-import ghidra.file.formats.android.vdex.VdexHeader;+import ghidra.file.formats.android.oat.bundle.OatBundle;+import ghidra.program.model.data.DataType;+import ghidra.util.exception.DuplicateNameException;/***@@ -26,22 +28,9 @@ import ghidra.file.formats.android.vdex.VdexHeader;*/class OatDexFile_Oreo extends OatDexFile_Nougat {- private VdexHeader vdexHeader;-- OatDexFile_Oreo(BinaryReader reader, VdexHeader vdexHeader) throws IOException {+ OatDexFile_Oreo(BinaryReader reader, OatBundle bundle) throws IOException {super(reader);- this.vdexHeader = vdexHeader;- if (vdexHeader != null) {- for (int i = 0; i < vdexHeader.getDexChecksums().length; ++i) {- if (vdexHeader.getDexChecksums()[i] == getDexFileChecksum()) {- dexHeader = vdexHeader.getDexHeaderList().get(i);- }- }- }- }-- public VdexHeader getVdexHeader() {- return vdexHeader;+ dexHeader = bundle.getDexHeaderByChecksum(dex_file_location_checksum_);}@Override@@ -49,4 +38,16 @@ class OatDexFile_Oreo extends OatDexFile_Nougat {return true;}+ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ DataType dataType = super.toDataType();+ try {+ dataType.setName(OatDexFile_Oreo.class.getSimpleName() + "_" ++ "_" + Integer.toHexString(dex_file_location_));+ }+ catch (Exception e) {+ //ignore+ }+ return dataType;+ }}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_OreoM2.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_OreoM2.javasimilarity index 88%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_OreoM2.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_OreoM2.javaindex bee4077bda..2bc639da03 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_OreoM2.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_OreoM2.java@@ -13,15 +13,16 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.oatdexfile;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;import ghidra.app.util.importer.MessageLog;import ghidra.file.formats.android.dex.format.DexHeader;-import ghidra.file.formats.android.vdex.VdexHeader;+import ghidra.file.formats.android.oat.OatHeader;+import ghidra.file.formats.android.oat.OatUtilities;+import ghidra.file.formats.android.oat.bundle.OatBundle;import ghidra.program.model.address.Address;import ghidra.program.model.data.*;import ghidra.program.model.listing.Data;@@ -49,7 +50,7 @@ class OatDexFile_OreoM2 extends OatDexFile {private long _offset;private DexHeader dexHeader;- OatDexFile_OreoM2(BinaryReader reader, VdexHeader vdexHeader) throws IOException {+ OatDexFile_OreoM2(BinaryReader reader, OatBundle bundle) throws IOException {_offset = reader.getPointerIndex();dex_file_location_ = reader.readNextInt();@@ -61,13 +62,7 @@ class OatDexFile_OreoM2 extends OatDexFile {oat_class_offsets_pointer_ = reader.readNextInt();dex_cache_arrays_ = reader.readNextInt();- if (vdexHeader != null) {- for (int i = 0; i < vdexHeader.getDexChecksums().length; ++i) {- if (vdexHeader.getDexChecksums()[i] == getDexFileChecksum()) {- dexHeader = vdexHeader.getDexHeaderList().get(i);- }- }- }+ dexHeader = bundle.getDexHeaderByChecksum(dex_file_location_checksum_);}@Override@@ -118,6 +113,7 @@ class OatDexFile_OreoM2 extends OatDexFile {Address address = oatDataSymbol.getAddress();Address dataAddress = address.add(_offset);+ program.getListing().clearCodeUnits(dataAddress, dataAddress, false, monitor);Data data = program.getListing().createData(dataAddress, toDataType());for (int i = 0; i < data.getNumComponents(); ++i) {@@ -149,8 +145,8 @@ class OatDexFile_OreoM2 extends OatDexFile {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(OatDexFile_OreoM2.class);- Structure structure = new StructureDataType(className + "_" + dex_file_location_, 0);+ Structure structure = new StructureDataType(+ OatDexFile_OreoM2.class.getSimpleName() + "_" + dex_file_location_, 0);structure.add(DWORD, "dex_file_location_", null);structure.add(STRING, dex_file_location_, "canonical_dex_file_location_", null);structure.add(DWORD, "dex_file_location_checksum_", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_Pie.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Pie.javasimilarity index 82%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_Pie.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Pie.javaindex fdc3313404..fa65085bde 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatDexFile_Pie.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatdexfile/OatDexFile_Pie.java@@ -13,15 +13,18 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.oatdexfile;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;import ghidra.app.util.importer.MessageLog;import ghidra.file.formats.android.dex.format.DexHeader;-import ghidra.file.formats.android.vdex.VdexHeader;+import ghidra.file.formats.android.oat.OatHeader;+import ghidra.file.formats.android.oat.OatUtilities;+import ghidra.file.formats.android.oat.bundle.OatBundle;+import ghidra.file.formats.android.oat.tlt.TypeLookupTable;+import ghidra.file.formats.android.oat.tlt.TypeLookupTableFactory;import ghidra.program.model.address.Address;import ghidra.program.model.data.*;import ghidra.program.model.listing.Data;@@ -49,10 +52,12 @@ class OatDexFile_Pie extends OatDexFile {private int lookup_table_;private int dex_layout_sections_;//according to spec this field should exist, but it does not+ private TypeLookupTable typeLookupTable;+private long _offset;private DexHeader dexHeader;- OatDexFile_Pie(BinaryReader reader, VdexHeader vdexHeader) throws IOException {+ OatDexFile_Pie(BinaryReader reader, OatBundle bundle) throws IOException {_offset = reader.getPointerIndex();dex_file_location_ = reader.readNextInt();@@ -65,18 +70,13 @@ class OatDexFile_Pie extends OatDexFile {string_bss_mapping_ = reader.readNextInt();oat_class_offsets_pointer_ = reader.readNextInt();lookup_table_ = reader.readNextInt();- //dex_layout_sections_ = reader.readNextInt( );//according to spec this field should exist, but it does not-- if (vdexHeader != null) {- for (int i = 0; i < vdexHeader.getDexChecksums().length; ++i) {- if (vdexHeader.getDexChecksums()[i] == getDexFileChecksum()) {- if (vdexHeader.getDexHeaderList().size() > i) {- dexHeader = vdexHeader.getDexHeaderList().get(i);- break;- }- }- }- }+ //dex_layout_sections_ = reader.readNextInt( );//according to spec this field should exist, but it does not++ BinaryReader typeLookupTableReader = reader.clone(lookup_table_);+ typeLookupTable = TypeLookupTableFactory.getTypeLookupTable(typeLookupTableReader,+ bundle.getOatHeader().getVersion());++ dexHeader = bundle.getDexHeaderByChecksum(dex_file_location_checksum_);}@Override@@ -139,6 +139,7 @@ class OatDexFile_Pie extends OatDexFile {Address address = oatDataSymbol.getAddress();Address dataAddress = address.add(_offset);+ program.getListing().clearCodeUnits(dataAddress, dataAddress, false, monitor);Data data = program.getListing().createData(dataAddress, toDataType());for (int i = 0; i < data.getNumComponents(); ++i) {@@ -171,15 +172,20 @@ class OatDexFile_Pie extends OatDexFile {OatDexFileUtilities.markupLookupTableData(this.getClass(), destinationAddress,dexHeader, oatHeader, program, monitor, log);}+ else if (componentI.getFieldName().startsWith("lookup_table_")) {+ if (typeLookupTable != null) {+ DataType dataType = typeLookupTable.toDataType();+ program.getListing().createData(destinationAddress, dataType);+ }+ }}}}@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(OatDexFile_Pie.class);-- Structure structure = new StructureDataType(className + "_" + dex_file_location_, 0);+ Structure structure = new StructureDataType(+ OatDexFile_Pie.class.getSimpleName() + "_" + dex_file_location_, 0);structure.add(DWORD, "dex_file_location_", null);structure.add(STRING, dex_file_location_, "canonical_dex_file_location_", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatMethodOffsets.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatmethod/OatMethodOffsets.javasimilarity index 93%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatMethodOffsets.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatmethod/OatMethodOffsets.javaindex d2073918c5..171eeda5f1 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatMethodOffsets.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatmethod/OatMethodOffsets.java@@ -13,7 +13,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.oatmethod;import java.io.IOException;@@ -35,6 +35,7 @@ import ghidra.util.exception.DuplicateNameException;* https://android.googlesource.com/platform/art/+/refs/heads/pie-release/runtime/oat.h#177* https://android.googlesource.com/platform/art/+/refs/heads/android10-release/runtime/oat.h#150* https://android.googlesource.com/platform/art/+/refs/heads/android11-release/runtime/oat_file.h#75+ * https://android.googlesource.com/platform/art/+/refs/heads/android-s-beta-5/runtime/oat_file.h#75*/public class OatMethodOffsets implements StructConverter {diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatMethodOffsetsFactory.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatmethod/OatMethodOffsetsFactory.javasimilarity index 69%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatMethodOffsetsFactory.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatmethod/OatMethodOffsetsFactory.javaindex d9d5e23c32..fe7aea071e 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatMethodOffsetsFactory.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatmethod/OatMethodOffsetsFactory.java@@ -13,24 +13,25 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.oatmethod;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;+import ghidra.file.formats.android.oat.OatConstants;public final class OatMethodOffsetsFactory {public final static OatMethodOffsets getOatMethodOffsets(BinaryReader reader, String oatVersion)throws IOException {- if (oatVersion.equals(OatConstants.VERSION_KITKAT_RELEASE)) {- return new OatMethodOffsets_KitKat(reader);- }- else if (oatVersion.equals(OatConstants.VERSION_LOLLIPOP_RELEASE)) {- return new OatMethodOffsets_Lollipop(reader);- }- else {- return new OatMethodOffsets(reader);++ switch (oatVersion) {+ case OatConstants.VERSION_KITKAT_RELEASE:+ return new OatMethodOffsets_KitKat(reader);+ case OatConstants.VERSION_LOLLIPOP_RELEASE:+ return new OatMethodOffsets_Lollipop(reader);+ default:+ return new OatMethodOffsets(reader);}}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatMethodOffsets_KitKat.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatmethod/OatMethodOffsets_KitKat.javasimilarity index 97%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatMethodOffsets_KitKat.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatmethod/OatMethodOffsets_KitKat.javaindex c37487d80d..934f961d38 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatMethodOffsets_KitKat.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatmethod/OatMethodOffsets_KitKat.java@@ -13,7 +13,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.oatmethod;import java.io.IOException;diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatMethodOffsets_Lollipop.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatmethod/OatMethodOffsets_Lollipop.javasimilarity index 96%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatMethodOffsets_Lollipop.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatmethod/OatMethodOffsets_Lollipop.javaindex b19f44a617..9c5f98eb78 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatMethodOffsets_Lollipop.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/oatmethod/OatMethodOffsets_Lollipop.java@@ -13,7 +13,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.oatmethod;import java.io.IOException;diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatQuickMethodHeader.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeader.javasimilarity index 88%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatQuickMethodHeader.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeader.javaindex b910e34c07..d62461fa88 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatQuickMethodHeader.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeader.java@@ -13,12 +13,12 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.quickmethod;import ghidra.app.util.bin.StructConverter;public abstract class OatQuickMethodHeader implements StructConverter {- protected abstract int getCodeSize();+ public abstract int getCodeSize();}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatQuickMethodHeaderFactory.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeaderFactory.javasimilarity index 91%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatQuickMethodHeaderFactory.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeaderFactory.javaindex 0c0d99a70c..2c109bbdd0 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatQuickMethodHeaderFactory.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeaderFactory.java@@ -13,11 +13,12 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.quickmethod;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;+import ghidra.file.formats.android.oat.OatConstants;public final class OatQuickMethodHeaderFactory {@@ -40,6 +41,8 @@ public final class OatQuickMethodHeaderFactory {case OatConstants.VERSION_10_RELEASE:case OatConstants.VERSION_11_RELEASE:return 8;+ case OatConstants.VERSION_12_RELEASE:+ return 4;}throw new IOException("OatQuickMethodHeader unsupported OAT version: " + oatVersion);}@@ -64,6 +67,8 @@ public final class OatQuickMethodHeaderFactory {case OatConstants.VERSION_10_RELEASE:case OatConstants.VERSION_11_RELEASE:return new OatQuickMethodHeader_Android10(reader);+ case OatConstants.VERSION_12_RELEASE:+ return new OatQuickMethodHeader_Android12(reader);}throw new IOException("OatQuickMethodHeader unsupported OAT version: " + oatVersion);}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatQuickMethodHeader_Android10.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeader_Android10.javasimilarity index 89%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatQuickMethodHeader_Android10.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeader_Android10.javaindex c24ff0aaf3..ed51aae418 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatQuickMethodHeader_Android10.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeader_Android10.java@@ -13,12 +13,11 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.quickmethod;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;@@ -63,8 +62,7 @@ public class OatQuickMethodHeader_Android10 extends OatQuickMethodHeader {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(OatQuickMethodHeader_Android10.class);- Structure structure = new StructureDataType(className, 0);+ Structure structure = new StructureDataType(OatQuickMethodHeader_Android10.class.getSimpleName(), 0);structure.add(DWORD, "vmap_table_offset_", null);structure.add(DWORD, "code_size_", null);structure.setCategoryPath(new CategoryPath("/oat"));diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeader_Android12.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeader_Android12.javanew file mode 100644index 0000000000..a758e54605--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeader_Android12.java@@ -0,0 +1,59 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.quickmethod;++import java.io.IOException;++import ghidra.app.util.bin.BinaryReader;+import ghidra.program.model.data.*;+import ghidra.util.exception.DuplicateNameException;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/android-s-beta-5/runtime/oat_quick_method_header.h#160+ *+ */+public class OatQuickMethodHeader_Android12 extends OatQuickMethodHeader {++ public static final int kShouldDeoptimizeMask = 0x80000000;+ public static final int kIsCodeInfoMask = 0x40000000;+ public static final int kCodeInfoMask = 0x3FFFFFFF; // If kIsCodeInfoMask is set.+ public static final int kCodeSizeMask = 0x3FFFFFFF; // If kIsCodeInfoMask is clear.++ private int data_;++ OatQuickMethodHeader_Android12(BinaryReader reader) throws IOException {+ data_ = reader.readNextInt();+ }++ public int getData() {+ return data_;+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ Structure structure =+ new StructureDataType(OatQuickMethodHeader_Android12.class.getSimpleName(), 0);+ structure.add(DWORD, "data_", null);+ structure.setCategoryPath(new CategoryPath("/oat"));+ return structure;+ }++ @Override+ public int getCodeSize() {+ return data_ & kCodeSizeMask;+ }++}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatQuickMethodHeader_Lollipop.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeader_Lollipop.javasimilarity index 91%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatQuickMethodHeader_Lollipop.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeader_Lollipop.javaindex 52d62660fb..132787d2e5 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatQuickMethodHeader_Lollipop.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeader_Lollipop.java@@ -13,11 +13,11 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.quickmethod;import java.io.IOException;-import ghidra.app.util.bin.*;+import ghidra.app.util.bin.BinaryReader;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;@@ -71,8 +71,7 @@ public class OatQuickMethodHeader_Lollipop extends OatQuickMethodHeader {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(OatQuickMethodHeader_Lollipop.class);- Structure structure = new StructureDataType(className, 0);+ Structure structure = new StructureDataType(OatQuickMethodHeader_Lollipop.class.getSimpleName(), 0);structure.add(DWORD, "mapping_table_offset_", null);structure.add(DWORD, "vmap_table_offset_", null);structure.add(frame_info_.toDataType(), "frame_info_", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatQuickMethodHeader_LollipopMR1.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeader_LollipopMR1.javasimilarity index 92%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatQuickMethodHeader_LollipopMR1.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeader_LollipopMR1.javaindex bf9b10bf35..d2c45285b7 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatQuickMethodHeader_LollipopMR1.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeader_LollipopMR1.java@@ -13,11 +13,11 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.quickmethod;import java.io.IOException;-import ghidra.app.util.bin.*;+import ghidra.app.util.bin.BinaryReader;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;@@ -83,8 +83,8 @@ public class OatQuickMethodHeader_LollipopMR1 extends OatQuickMethodHeader {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(OatQuickMethodHeader_LollipopMR1.class);- Structure structure = new StructureDataType(className, 0);+ Structure structure =+ new StructureDataType(OatQuickMethodHeader_LollipopMR1.class.getSimpleName(), 0);structure.add(DWORD, "mapping_table_offset_", null);structure.add(DWORD, "vmap_table_offset_", null);structure.add(DWORD, "gc_map_offset_", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatQuickMethodHeader_Nougat.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeader_Nougat.javasimilarity index 90%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatQuickMethodHeader_Nougat.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeader_Nougat.javaindex 100fe42f4c..7b84160286 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatQuickMethodHeader_Nougat.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeader_Nougat.java@@ -13,12 +13,11 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.quickmethod;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;@@ -76,8 +75,8 @@ public class OatQuickMethodHeader_Nougat extends OatQuickMethodHeader {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(OatQuickMethodHeader_Nougat.class);- Structure structure = new StructureDataType(className, 0);+ Structure structure =+ new StructureDataType(OatQuickMethodHeader_Nougat.class.getSimpleName(), 0);structure.add(DWORD, "mapping_table_offset_", null);structure.add(frame_info_.toDataType(), "frame_info_", null);structure.add(DWORD, "code_size_", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatQuickMethodHeader_Oreo.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeader_Oreo.javasimilarity index 93%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatQuickMethodHeader_Oreo.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeader_Oreo.javaindex 1e95d6daf9..5446f86bd0 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/OatQuickMethodHeader_Oreo.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeader_Oreo.java@@ -13,12 +13,11 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.quickmethod;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;@@ -91,8 +90,8 @@ public class OatQuickMethodHeader_Oreo extends OatQuickMethodHeader {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(OatQuickMethodHeader_Oreo.class);- Structure structure = new StructureDataType(className, 0);+ Structure structure =+ new StructureDataType(OatQuickMethodHeader_Oreo.class.getSimpleName(), 0);structure.add(DWORD, "vmap_table_offset_", null);structure.add(DWORD, "method_info_offset_", null);structure.add(frame_info_.toDataType(), "frame_info_", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/QuickMethodFrameInfo.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/QuickMethodFrameInfo.javasimilarity index 98%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/QuickMethodFrameInfo.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/QuickMethodFrameInfo.javaindex e77784ba79..6eba837bc8 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/QuickMethodFrameInfo.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/QuickMethodFrameInfo.java@@ -13,7 +13,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.quickmethod;import java.io.IOException;diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/TypeLookupTable.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTable.javasimilarity index 95%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/TypeLookupTable.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTable.javaindex 812d2fbbf9..e1a9cc6851 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/TypeLookupTable.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTable.java@@ -13,7 +13,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.tlt;import ghidra.app.util.bin.StructConverter;diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/TypeLookupTableEntry.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTableEntry.javasimilarity index 57%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/TypeLookupTableEntry.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTableEntry.javaindex daab1c39f5..59094a4267 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/TypeLookupTableEntry.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTableEntry.java@@ -13,52 +13,62 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.tlt;import java.io.IOException;-import ghidra.app.util.bin.*;-import ghidra.program.model.data.DataType;+import ghidra.app.util.bin.BinaryReader;+import ghidra.app.util.bin.StructConverter;+import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;/**+ * https://android.googlesource.com/platform/art/+/nougat-release/runtime/type_lookup_table.h#99* https://android.googlesource.com/platform/art/+/oreo-release/runtime/type_lookup_table.h#100* https://android.googlesource.com/platform/art/+/oreo-m2-release/runtime/type_lookup_table.h#100* https://android.googlesource.com/platform/art/+/pie-release/runtime/type_lookup_table.h#102*- **/public class TypeLookupTableEntry implements StructConverter {- private int str_offset;- private short data;- private short next_pos_delta;+ protected int str_offset_;+ protected int data_;+ protected short next_pos_delta_;++ protected TypeLookupTableEntry() {+ //do nothing+ }public TypeLookupTableEntry(BinaryReader reader) throws IOException {- str_offset = reader.readNextInt();- data = reader.readNextShort();- next_pos_delta = reader.readNextShort();+ str_offset_ = reader.readNextInt();+ data_ = Short.toUnsignedInt(reader.readNextShort());+ next_pos_delta_ = reader.readNextShort();}public int getStringOffset() {- return str_offset;+ return str_offset_;}- public short getData() {- return data;+ public int getData() {+ return data_;}public short getNextPosDelta() {- return next_pos_delta;+ return next_pos_delta_;}public boolean isEmpty() {- return str_offset == 0;+ return str_offset_ == 0;}@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- return StructConverterUtil.toDataType(TypeLookupTableEntry.class);+ Structure structure = new StructureDataType(TypeLookupTableEntry.class.getSimpleName(), 0);+ structure.add(DWORD, "str_offset_", null);+ structure.add(WORD, "data_", null);+ structure.add(WORD, "next_pos_delta_", null);+ structure.setCategoryPath(new CategoryPath("/oat"));+ return structure;}}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTableEntry_Android10.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTableEntry_Android10.javanew file mode 100644index 0000000000..d820214d22--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTableEntry_Android10.java@@ -0,0 +1,60 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.tlt;++import java.io.IOException;++import ghidra.app.util.bin.BinaryReader;+import ghidra.program.model.data.*;+import ghidra.util.exception.DuplicateNameException;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/android10-release/libdexfile/dex/type_lookup_table.h#110+ * https://android.googlesource.com/platform/art/+/refs/heads/android11-release/libdexfile/dex/type_lookup_table.h#110+ * https://android.googlesource.com/platform/art/+/refs/heads/android12-release/libdexfile/dex/type_lookup_table.h#110+ */+public class TypeLookupTableEntry_Android10 extends TypeLookupTableEntry {++ public TypeLookupTableEntry_Android10(BinaryReader reader) throws IOException {+ super();+ str_offset_ = reader.readNextInt();+ data_ = reader.readNextInt();+ }++ public boolean isLast(int mask_bits) {+ return getNextPosDelta(mask_bits) == 0;+ }++ public int getNextPosDelta(int mask_bits) {+ return data_ & getMask(mask_bits);+ }++ public int getMask(int mask_bits) {+ //DCHECK_LE(mask_bits, 16u);+ //return ~(std::numeric_limits<uint32_t>::max() << mask_bits);+ return ~(-1 << mask_bits);+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ Structure structure = new StructureDataType(TypeLookupTableEntry_Android10.class.getSimpleName(), 0);+ structure.add(DWORD, "str_offset_", null);+ structure.add(DWORD, "data_", null);+ structure.setCategoryPath(new CategoryPath("/oat"));+ return structure;+ }++}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTableFactory.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTableFactory.javanew file mode 100644index 0000000000..86cddf0ad6--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTableFactory.java@@ -0,0 +1,51 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.tlt;++import java.io.IOException;++import ghidra.app.util.bin.BinaryReader;+import ghidra.file.formats.android.oat.OatConstants;+import ghidra.file.formats.android.oat.UnsupportedOatVersionException;++public final class TypeLookupTableFactory {++ public final static TypeLookupTable getTypeLookupTable(BinaryReader reader, String oatVersion)+ throws IOException {++ switch (oatVersion) {+ case OatConstants.VERSION_NOUGAT_RELEASE:+ case OatConstants.VERSION_NOUGAT_MR1_RELEASE:+ return new TypeLookupTable_Nougat(reader);+ case OatConstants.VERSION_OREO_RELEASE:+ case OatConstants.VERSION_OREO_M2_RELEASE:+ case OatConstants.VERSION_OREO_DR3_RELEASE:+ return new TypeLookupTable_Oreo(reader);+ case OatConstants.VERSION_PIE_RELEASE:+ return new TypeLookupTable_Pie(reader);+ case OatConstants.VERSION_10_RELEASE:+ return new TypeLookupTable_Android10(reader);+ case OatConstants.VERSION_11_RELEASE:+ return new TypeLookupTable_Android11(reader);+ case OatConstants.VERSION_12_RELEASE:+ return new TypeLookupTable_Android12(reader);+ default:+ throw new IOException(new UnsupportedOatVersionException(+ "Unsupported TypeLookupTable for OAT version " + oatVersion));+ }+ }++}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/TypeLookupTable_Android10.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTable_Android10.javasimilarity index 57%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/TypeLookupTable_Android10.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTable_Android10.javaindex 31b3626ee9..c224a6abc0 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/TypeLookupTable_Android10.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTable_Android10.java@@ -13,45 +13,55 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.tlt;import java.io.IOException;import java.util.ArrayList;import java.util.List;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;/**- * https://android.googlesource.com/platform/art/+/oreo-release/runtime/type_lookup_table.h#161- * https://android.googlesource.com/platform/art/+/oreo-m2-release/runtime/type_lookup_table.h#161+ * https://android.googlesource.com/platform/art/+/refs/heads/android10-release/libdexfile/dex/type_lookup_table.h#35*/public class TypeLookupTable_Android10 extends TypeLookupTable {private int dex_file_begin_;private int mask_bits_;- private List<TypeLookupTableEntry> entries_ = new ArrayList<TypeLookupTableEntry>();- // owns_entries_ specifies if the lookup table owns the entries_ array.+ private int entries_;private int owns_entries_;+ protected List<TypeLookupTableEntry> entryList = new ArrayList<>();+public TypeLookupTable_Android10(BinaryReader reader) throws IOException {- // TODO Auto-generated constructor stub+ dex_file_begin_ = reader.readNextInt();+ mask_bits_ = reader.readNextInt();+ entries_ = reader.readNextInt();+ owns_entries_ = reader.readNextInt();++ while (true) {+ TypeLookupTableEntry entry = new TypeLookupTableEntry_Android10(reader);+ entryList.add(entry);+ if (entry.isEmpty()) {+ break;+ }+ }}public int getDexFileBegin() {return dex_file_begin_;}- public List<TypeLookupTableEntry> getEntries() {- return entries_;- }-public int getMaskBits() {return mask_bits_;}+ public int getEntries() {+ return entries_;+ }+/*** owns_entries_ specifies if the lookup table owns the entries_ array.*/@@ -59,18 +69,20 @@ public class TypeLookupTable_Android10 extends TypeLookupTable {return owns_entries_ == 0;}+ public List<TypeLookupTableEntry> getEntryList() {+ return entryList;+ }+@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(getClass());- Structure struct = new StructureDataType(className, 0);- struct.add(DWORD, "dex_file_begin_", null);- struct.add(DWORD, "raw_data_length_", null);- struct.add(DWORD, "mask_", null);- for (int i = 0; i < entries_.size(); ++i) {- struct.add(entries_.get(i).toDataType(), "entry_" + i, null);- }- struct.add(DWORD, "owns_entries_", null);- return struct;+ Structure structure = new StructureDataType(+ TypeLookupTable_Android10.class.getSimpleName() + "_" + entryList.size(), 0);+ structure.add(DWORD, "dex_file_begin_", null);+ structure.add(DWORD, "mask_bits_", null);+ structure.add(DWORD, "entries_", null);+ structure.add(DWORD, "owns_entries_", null);+ structure.setCategoryPath(new CategoryPath("/oat"));+ return structure;}}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTable_Android11.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTable_Android11.javanew file mode 100644index 0000000000..e6fd61ab19--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTable_Android11.java@@ -0,0 +1,47 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.tlt;++import java.io.IOException;++import ghidra.app.util.bin.BinaryReader;+import ghidra.program.model.data.DataType;+import ghidra.util.exception.DuplicateNameException;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/android11-release/libdexfile/dex/type_lookup_table.h#35+ *+ */+public class TypeLookupTable_Android11 extends TypeLookupTable_Android10 {++ public TypeLookupTable_Android11(BinaryReader reader) throws IOException {+ super(reader);+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ DataType dataType = super.toDataType();+ try {+ dataType.setName(+ TypeLookupTable_Android11.class.getSimpleName() + "_" + entryList.size());+ }+ catch (Exception e) {+ //ignore+ }+ return dataType;+ }++}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTable_Android12.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTable_Android12.javanew file mode 100644index 0000000000..efe0012d60--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTable_Android12.java@@ -0,0 +1,46 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.tlt;++import java.io.IOException;++import ghidra.app.util.bin.BinaryReader;+import ghidra.program.model.data.DataType;+import ghidra.util.exception.DuplicateNameException;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/android12-release/libdexfile/dex/type_lookup_table.h#35+ */+public class TypeLookupTable_Android12 extends TypeLookupTable_Android10 {++ public TypeLookupTable_Android12(BinaryReader reader) throws IOException {+ super(reader);+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ DataType dataType = super.toDataType();+ try {+ dataType.setName(+ TypeLookupTable_Android12.class.getSimpleName() + "_" + entryList.size());+ }+ catch (Exception e) {+ //ignore+ }+ return dataType;+ }++}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTable_Nougat.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTable_Nougat.javanew file mode 100644index 0000000000..606a420b95--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTable_Nougat.java@@ -0,0 +1,80 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.oat.tlt;++import java.io.IOException;+import java.util.ArrayList;+import java.util.List;++import ghidra.app.util.bin.BinaryReader;+import ghidra.program.model.data.*;+import ghidra.util.exception.DuplicateNameException;++/**+ * https://android.googlesource.com/platform/art/+/nougat-release/runtime/type_lookup_table.h+ */+public class TypeLookupTable_Nougat extends TypeLookupTable {++ private int dex_file_;+ private int mask_;+ private int entries_;+ private int owns_entries_;++ private List<TypeLookupTableEntry> entryList = new ArrayList<TypeLookupTableEntry>();++ public TypeLookupTable_Nougat(BinaryReader reader) throws IOException {+ dex_file_ = reader.readNextInt();+ mask_ = reader.readNextInt();+ entries_ = reader.readNextInt();+ owns_entries_ = reader.readNextInt();+ }++ public int getDexFile() {+ return dex_file_;+ }++ public int getMask() {+ return mask_;+ }++ public int getEntries() {+ return entries_;+ }++ /**+ * owns_entries_ specifies if the lookup table owns the entries_ array.+ */+ public boolean isOwnsEntries() {+ return owns_entries_ == 0;+ }++ public List<TypeLookupTableEntry> getEntryList() {+ return entryList;+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ Structure structure = new StructureDataType(+ TypeLookupTable_Nougat.class.getSimpleName() + "_" + entryList.size(), 0);+ structure.add(DWORD, "dex_file_", null);+ structure.add(DWORD, "mask_", null);+ structure.add(DWORD, "entries_", null);+ structure.add(DWORD, "owns_entries_", null);+ structure.setCategoryPath(new CategoryPath("/oat"));+ return structure;+ }++}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/TypeLookupTable_Oreo.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTable_Oreo.javasimilarity index 65%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/TypeLookupTable_Oreo.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTable_Oreo.javaindex a196f00cc8..a707cbac7f 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/TypeLookupTable_Oreo.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTable_Oreo.java@@ -13,14 +13,13 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.tlt;import java.io.IOException;import java.util.ArrayList;import java.util.List;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;@@ -33,12 +32,17 @@ public class TypeLookupTable_Oreo extends TypeLookupTable {private int dex_file_begin_;private int raw_data_length_;private int mask_;- private List<TypeLookupTableEntry> entries_ = new ArrayList<TypeLookupTableEntry>();- // owns_entries_ specifies if the lookup table owns the entries_ array.+ private int entries_;private int owns_entries_;+ private List<TypeLookupTableEntry> entryList = new ArrayList<TypeLookupTableEntry>();+public TypeLookupTable_Oreo(BinaryReader reader) throws IOException {- // TODO Auto-generated constructor stub+ dex_file_begin_ = reader.readNextInt();+ raw_data_length_ = reader.readNextInt();+ mask_ = reader.readNextInt();+ entries_ = reader.readNextInt();+ owns_entries_ = reader.readNextInt();}public int getDexFileBegin() {@@ -53,7 +57,7 @@ public class TypeLookupTable_Oreo extends TypeLookupTable {return mask_;}- public List<TypeLookupTableEntry> getEntries() {+ public int getEntries() {return entries_;}@@ -64,18 +68,21 @@ public class TypeLookupTable_Oreo extends TypeLookupTable {return owns_entries_ == 0;}+ public List<TypeLookupTableEntry> getEntryList() {+ return entryList;+ }+@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(TypeLookupTable_Oreo.class);- Structure struct = new StructureDataType(className, 0);- struct.add(DWORD, "dex_file_begin_", null);- struct.add(DWORD, "raw_data_length_", null);- struct.add(DWORD, "mask_", null);- for (int i = 0; i < entries_.size(); ++i) {- struct.add(entries_.get(i).toDataType(), "entry_" + i, null);- }- struct.add(DWORD, "owns_entries_", null);- return struct;+ Structure structure = new StructureDataType(+ TypeLookupTable_Oreo.class.getSimpleName() + "_" + entryList.size(), 0);+ structure.add(DWORD, "dex_file_begin_", null);+ structure.add(DWORD, "raw_data_length_", null);+ structure.add(DWORD, "mask_", null);+ structure.add(DWORD, "entries_", null);+ structure.add(DWORD, "owns_entries_", null);+ structure.setCategoryPath(new CategoryPath("/oat"));+ return structure;}}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/TypeLookupTable_Pie.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTable_Pie.javasimilarity index 58%rename from Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/TypeLookupTable_Pie.javarename to Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTable_Pie.javaindex ff3a608963..27765fadb8 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/TypeLookupTable_Pie.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/tlt/TypeLookupTable_Pie.java@@ -13,31 +13,36 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.file.formats.android.oat;+package ghidra.file.formats.android.oat.tlt;import java.io.IOException;import java.util.ArrayList;import java.util.List;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;/**- * https://android.googlesource.com/platform/art/+/pie-release/runtime/type_lookup_table.h#102+ * https://android.googlesource.com/platform/art/+/oreo-release/runtime/type_lookup_table.h#161+ * https://android.googlesource.com/platform/art/+/oreo-m2-release/runtime/type_lookup_table.h#161*/public class TypeLookupTable_Pie extends TypeLookupTable {private int dex_data_begin_;private int raw_data_length_;private int mask_;- private List<TypeLookupTableEntry> entries_ = new ArrayList<TypeLookupTableEntry>();- // owns_entries_ specifies if the lookup table owns the entries_ array.+ private int entries_;private int owns_entries_;+ private List<TypeLookupTableEntry> entryList = new ArrayList<TypeLookupTableEntry>();+public TypeLookupTable_Pie(BinaryReader reader) throws IOException {- // TODO Auto-generated constructor stub+ dex_data_begin_ = reader.readNextInt();+ raw_data_length_ = reader.readNextInt();+ mask_ = reader.readNextInt();+ entries_ = reader.readNextInt();+ owns_entries_ = reader.readNextInt();}public int getDexDataBegin() {@@ -52,7 +57,7 @@ public class TypeLookupTable_Pie extends TypeLookupTable {return mask_;}- public List<TypeLookupTableEntry> getEntries() {+ public int getEntries() {return entries_;}@@ -63,18 +68,21 @@ public class TypeLookupTable_Pie extends TypeLookupTable {return owns_entries_ == 0;}+ public List<TypeLookupTableEntry> getEntryList() {+ return entryList;+ }+@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(TypeLookupTable_Pie.class);- Structure struct = new StructureDataType(className, 0);- struct.add(DWORD, "dex_data_begin_", null);- struct.add(DWORD, "raw_data_length_", null);- struct.add(DWORD, "mask_", null);- for (int i = 0; i < entries_.size(); ++i) {- struct.add(entries_.get(i).toDataType(), "entry_" + i, null);- }- struct.add(DWORD, "owns_entries_", null);- return struct;+ Structure structure = new StructureDataType(+ TypeLookupTable_Pie.class.getSimpleName() + "_" + entryList.size(), 0);+ structure.add(DWORD, "dex_data_begin_", null);+ structure.add(DWORD, "raw_data_length_", null);+ structure.add(DWORD, "mask_", null);+ structure.add(DWORD, "entries_", null);+ structure.add(DWORD, "owns_entries_", null);+ structure.setCategoryPath(new CategoryPath("/oat"));+ return structure;}}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/UnsupportedVdexVersionException.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/UnsupportedVdexVersionException.javaindex f57bd6584d..a8cefe4efd 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/UnsupportedVdexVersionException.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/UnsupportedVdexVersionException.java@@ -15,7 +15,7 @@*/package ghidra.file.formats.android.vdex;-final class UnsupportedVdexVersionException extends Exception {+public final class UnsupportedVdexVersionException extends Exception {UnsupportedVdexVersionException(String magic, String version) {super("Unsupported VDEX version: " + version);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexConstants.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexConstants.javaindex 896f264bcc..f4b69e1a5f 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexConstants.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexConstants.java@@ -48,8 +48,7 @@ public final class VdexConstants {public final static String VERSION_PIE_RELEASE = "019";public final static String VERSION_10_RELEASE = "021";public final static String VERSION_11_RELEASE = "021";-- public final static String version_master = "021";+ public final static String VERSION_12_RELEASE = "027";/*** The format version of the dex section header and the dex section,@@ -74,8 +73,16 @@ public final class VdexConstants {/*** NOTE: only going to support RELEASE versions*/- public final static String[] SUPPORTED_VERSIONS = new String[] { VERSION_OREO_RELEASE,- VERSION_OREO_M2_RELEASE, VERSION_PIE_RELEASE, VERSION_10_RELEASE, VERSION_11_RELEASE, };+ //@formatter:off+ public final static String[] SUPPORTED_VERSIONS = new String[] {+ VERSION_OREO_RELEASE,+ VERSION_OREO_M2_RELEASE,+ VERSION_PIE_RELEASE,+ VERSION_10_RELEASE,+ VERSION_11_RELEASE,+ VERSION_12_RELEASE,+ };+ //@formatter:onpublic final static boolean isSupportedVersion(String version) {for (String supportedVersion : SUPPORTED_VERSIONS) {diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexFactory.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexFactory.javaindex 03c2dd8672..3d7a2cc80a 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexFactory.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexFactory.java@@ -15,17 +15,10 @@*/package ghidra.file.formats.android.vdex;-import java.io.File;import java.io.IOException;-import org.apache.commons.io.FilenameUtils;--import ghidra.app.util.bin.*;-import ghidra.app.util.importer.MessageLog;-import ghidra.framework.model.DomainFile;-import ghidra.framework.model.DomainFolder;-import ghidra.program.model.listing.Program;-import ghidra.util.task.TaskMonitor;+import ghidra.app.util.bin.BinaryReader;+import ghidra.file.formats.android.vdex.android12.VdexHeader_12;public final class VdexFactory {@@ -55,82 +48,12 @@ public final class VdexFactory {if (version.equals(VdexConstants.VERSION_11_RELEASE)) {return new VdexHeader_11(reader);}- }- }- throw new UnsupportedVdexVersionException(magic, version);- }-- public static VdexHeader loadVdexHeader(Program program, TaskMonitor monitor, MessageLog log) {-- if (program == null) {- return null;- }-- String vdexProgramName = FilenameUtils.removeExtension(program.getName());-- //first, look in current project for VDEX file....-- DomainFile domainFile = program.getDomainFile();- DomainFolder parentFolder = domainFile.getParent();- VdexHeader vdexHeader =- scanProjectFolder(parentFolder, vdexProgramName, program, monitor, log);- if (vdexHeader == null) {- vdexHeader =- scanProjectFolder(parentFolder.getParent(), vdexProgramName, program, monitor, log);- }- if (vdexHeader != null) {- return vdexHeader;- }-- //then, try to locate the VDEX on disk, in same folder where binary was imported....-- String oatFilePath = program.getExecutablePath();-- if (oatFilePath.endsWith(".odex") || oatFilePath.endsWith(".oat")) {- String vdexFilePath = FilenameUtils.removeExtension(oatFilePath);- File vdexFile = new File(vdexFilePath);- try (ByteProvider vdexProvider = new RandomAccessByteProvider(vdexFile)) {- BinaryReader vdexReader =- new BinaryReader(vdexProvider, !program.getLanguage().isBigEndian());- vdexHeader = getVdexHeader(vdexReader);- vdexHeader.parse(vdexReader, monitor);- return vdexHeader;- }- catch (Exception e) {- log.appendMsg("Unable to locate matching VDEX.");- }- }-- return null;- }-- private static VdexHeader scanProjectFolder(DomainFolder parentFolder, String vdexProgramName,- Program program, TaskMonitor monitor, MessageLog log) {-- DomainFile child = parentFolder.getFile(vdexProgramName);- if (child != null) {- try {- Object consumer = new Object();- Program vdexProgram =- (Program) child.getDomainObject(consumer, true, true, monitor);- try {- ByteProvider vdexProvider = new MemoryByteProvider(vdexProgram.getMemory(),- vdexProgram.getMinAddress());- BinaryReader vdexReader =- new BinaryReader(vdexProvider, !program.getLanguage().isBigEndian());- VdexHeader vdexHeader = getVdexHeader(vdexReader);- vdexHeader.parse(vdexReader, monitor);- return vdexHeader;- }- finally {- vdexProgram.release(consumer);+ if (version.equals(VdexConstants.VERSION_12_RELEASE)) {+ return new VdexHeader_12(reader);}}- catch (Exception e) {- log.appendMsg("Unable to locate matching VDEX.");- }}- return null;+ throw new UnsupportedVdexVersionException(magic, version);}}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexHeaderAnalyzer.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexHeaderAnalyzer.javaindex 6e4d218399..de9a3cc0d2 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexHeaderAnalyzer.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexHeaderAnalyzer.java@@ -57,7 +57,7 @@ public class VdexHeaderAnalyzer extends FileFormatAnalyzer {@Overridepublic boolean isPrototype() {- return true;+ return false;}@Override@@ -65,7 +65,7 @@ public class VdexHeaderAnalyzer extends FileFormatAnalyzer {throws Exception {Address address = VdexConstants.findVDEX(program);if (address == null) {- log.appendMsg(getClass().getSimpleName() + " - no vdex header found, skipping");+ log.appendMsg(getClass().getSimpleName() + " - no vdex header found in memory, skipping");return true;}ByteProvider provider = new MemoryByteProvider(program.getMemory(), address);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexHeader_10.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexHeader_10.javaindex 6160891f9e..51070a2589 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexHeader_10.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexHeader_10.java@@ -19,7 +19,8 @@ import java.io.IOException;import java.util.ArrayList;import java.util.List;-import ghidra.app.util.bin.*;+import ghidra.app.util.bin.BinaryReader;+import ghidra.app.util.bin.ByteProviderWrapper;import ghidra.file.formats.android.dex.DexHeaderFactory;import ghidra.file.formats.android.dex.format.DexHeader;import ghidra.program.model.data.*;@@ -79,7 +80,7 @@ public class VdexHeader_10 extends VdexHeader {}}else if (VdexConstants.kDexSectionVersionEmpty.equals(dex_section_version_)) {- stringTable = new VdexStringTable( reader );+ stringTable = new VdexStringTable(reader);}else {throw new UnsupportedVdexVersionException(@@ -136,8 +137,8 @@ public class VdexHeader_10 extends VdexHeader {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(VdexHeader_10.class);- Structure structure = new StructureDataType(className + "_" + number_of_dex_files_, 0);+ Structure structure = new StructureDataType(+ VdexHeader_10.class.getSimpleName() + "_" + number_of_dex_files_, 0);structure.add(STRING, 4, "magic_", null);structure.add(STRING, 4, "verifier_deps_version_", null);structure.add(STRING, 4, "dex_section_version_", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexHeader_11.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexHeader_11.javaindex 5d5301df97..d5fc7cb06c 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexHeader_11.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexHeader_11.java@@ -18,7 +18,6 @@ package ghidra.file.formats.android.vdex;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;-import ghidra.app.util.bin.StructConverterUtil;import ghidra.program.model.data.DataType;import ghidra.util.exception.DuplicateNameException;@@ -32,8 +31,7 @@ public class VdexHeader_11 extends VdexHeader_10 {public DataType toDataType() throws DuplicateNameException, IOException {DataType dataType = super.toDataType();try {- String className = StructConverterUtil.parseName(VdexHeader_11.class);- dataType.setName(className);+ dataType.setName(VdexHeader_11.class.getSimpleName());}catch (Exception e) {//ignore...diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexHeader_Oreo.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexHeader_Oreo.javaindex 3c6aaa253e..14d24799e9 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexHeader_Oreo.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexHeader_Oreo.java@@ -111,8 +111,8 @@ public class VdexHeader_Oreo extends VdexHeader {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(VdexHeader_Oreo.class);- Structure structure = new StructureDataType(className + "_" + number_of_dex_files_, 0);+ Structure structure = new StructureDataType(+ VdexHeader_Oreo.class.getSimpleName() + "_" + number_of_dex_files_, 0);structure.add(STRING, 4, "magic_", null);structure.add(STRING, 4, "version_", null);structure.add(DWORD, "number_of_dex_files_", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexHeader_Pie.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexHeader_Pie.javaindex d53eb155f0..84b29a35c6 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexHeader_Pie.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexHeader_Pie.java@@ -19,7 +19,8 @@ import java.io.IOException;import java.util.ArrayList;import java.util.List;-import ghidra.app.util.bin.*;+import ghidra.app.util.bin.BinaryReader;+import ghidra.app.util.bin.ByteProviderWrapper;import ghidra.file.formats.android.dex.DexHeaderFactory;import ghidra.file.formats.android.dex.format.DexHeader;import ghidra.program.model.data.*;@@ -123,8 +124,8 @@ public class VdexHeader_Pie extends VdexHeader {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(VdexHeader_Pie.class);- Structure structure = new StructureDataType(className + "_" + number_of_dex_files_, 0);+ Structure structure = new StructureDataType(+ VdexHeader_Pie.class.getSimpleName() + "_" + number_of_dex_files_, 0);structure.add(STRING, 4, "magic_", null);structure.add(STRING, 4, "verifier_deps_version_", null);structure.add(STRING, 4, "dex_section_version_", null);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexStringTable.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexStringTable.javaindex 6207717363..1453c7ac0f 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexStringTable.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/VdexStringTable.java@@ -54,8 +54,8 @@ public class VdexStringTable implements StructConverter {@Overridepublic DataType toDataType() throws DuplicateNameException, IOException {- String className = StructConverterUtil.parseName(VdexStringTable.class);- Structure structure = new StructureDataType(className + "_" + stringCount, 0);+ Structure structure =+ new StructureDataType(VdexStringTable.class.getSimpleName() + "_" + stringCount, 0);structure.add(BYTE, "stringCount", null);for (int i = 0; i < stringCount; ++i) {String string = strings.get(i);diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/android12/VdexHeader_12.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/android12/VdexHeader_12.javanew file mode 100644index 0000000000..3c5a6f9657--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/android12/VdexHeader_12.java@@ -0,0 +1,203 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.vdex.android12;++import java.io.IOException;+import java.util.ArrayList;+import java.util.List;++import org.apache.commons.lang3.ArrayUtils;++import ghidra.app.util.bin.BinaryReader;+import ghidra.app.util.bin.ByteProviderWrapper;+import ghidra.file.formats.android.dex.DexHeaderFactory;+import ghidra.file.formats.android.dex.format.DexHeader;+import ghidra.file.formats.android.vdex.*;+import ghidra.program.model.data.*;+import ghidra.util.exception.CancelledException;+import ghidra.util.exception.DuplicateNameException;+import ghidra.util.task.TaskMonitor;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/android-s-beta-5/runtime/vdex_file.h#129+ *+ * https://android.googlesource.com/platform/art/+/refs/heads/android12-release/runtime/vdex_file.h#129+ *+ */+public class VdexHeader_12 extends VdexHeader {++ private String vdex_version_;+ private int number_of_sections_;+ private List<VdexSectionHeader_12> sections = new ArrayList<>();+ private List<Integer> checksums = new ArrayList<>();++ public VdexHeader_12(BinaryReader reader)+ throws IOException, UnsupportedVdexVersionException {+ super(reader);+ vdex_version_ = reader.readNextAsciiString(4);+ number_of_sections_ = reader.readNextInt();+ }++ @Override+ public void parse(BinaryReader reader, TaskMonitor monitor)+ throws IOException, CancelledException {++ for (int i = 0; i < number_of_sections_; ++i) {+ monitor.checkCanceled();+ sections.add(new VdexSectionHeader_12(reader));+ }++ parseChecksums(reader, monitor);+ parseDexFiles(reader, monitor);+ parseVerifierDeps(reader, monitor);+ parseTypeLookupTable(reader, monitor);+ }++ private void parseChecksums(BinaryReader reader, TaskMonitor monitor)+ throws CancelledException, IOException {+ VdexSectionHeader_12 checksumSection =+ sections.get(VdexSection_12.kChecksumSection.ordinal());+ if (checksumSection.getSectionSize() > 0) {+ reader.setPointerIndex(checksumSection.getSectionOffset());+ for (int i = 0; i < checksumSection.getSectionSize() / 4; ++i) {+ monitor.checkCanceled();+ checksums.add(reader.readNextInt());+ }+ }+ }++ private void parseDexFiles(BinaryReader reader, TaskMonitor monitor)+ throws CancelledException, IOException {+ VdexSectionHeader_12 dexFileSection =+ sections.get(VdexSection_12.kDexFileSection.ordinal());+ if (dexFileSection.getSectionSize() > 0) {+ reader.setPointerIndex(dexFileSection.getSectionOffset());++ dexHeaderStartsList.add(Integer.toUnsignedLong(dexFileSection.getSectionOffset()));++ ByteProviderWrapper wrappedProvider = new ByteProviderWrapper(+ reader.getByteProvider(), dexFileSection.getSectionOffset(),+ dexFileSection.getSectionSize());++ BinaryReader wrappedReader =+ new BinaryReader(wrappedProvider, reader.isLittleEndian());++ DexHeader cdexHeader = DexHeaderFactory.getDexHeader(wrappedReader);+ dexHeaderList.add(cdexHeader);+ }+ }++ private void parseVerifierDeps(BinaryReader reader, TaskMonitor monitor)+ throws CancelledException, IOException {+ VdexSectionHeader_12 verifierDepsSection =+ sections.get(VdexSection_12.kVerifierDepsSection.ordinal());+ if (verifierDepsSection.getSectionSize() > 0) {+ reader.setPointerIndex(verifierDepsSection.getSectionOffset());+ //TODO+ }+ }++ private void parseTypeLookupTable(BinaryReader reader, TaskMonitor monitor)+ throws CancelledException, IOException {+ VdexSectionHeader_12 typeLookupTableSection =+ sections.get(VdexSection_12.kTypeLookupTableSection.ordinal());+ if (typeLookupTableSection.getSectionSize() > 0) {+ reader.setPointerIndex(typeLookupTableSection.getSectionOffset());+ //TODO+ }+ }++ @Override+ public int getVerifierDepsSize() {+ return 0;//not used in this VDEX version+ }++ @Override+ public int getQuickeningInfoSize() {+ return 0;//not used in this VDEX version+ }++ @Override+ public int[] getDexChecksums() {+ return ArrayUtils.toPrimitive(checksums.toArray(new Integer[checksums.size()]));+ }++ @Override+ public boolean isDexHeaderEmbeddedInDataType() {+ return true;+ }++ @Override+ public DexSectionHeader_002 getDexSectionHeader_002() {+ return null;//not used in this VDEX version+ }++ public String getVdexVersion() {+ return vdex_version_;+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ Structure structure = new StructureDataType(VdexHeader_12.class.getSimpleName(), 0);+ structure.add(STRING, 4, "magic_", null);+ structure.add(STRING, 4, "vdex_version_", null);+ structure.add(DWORD, "number_of_sections_", null);++ for (int i = 0; i < sections.size(); ++i) {+ structure.add(sections.get(i).toDataType(), "section_" + i, null);+ }++ for (int i = 0; i < checksums.size(); ++i) {+ structure.add(DWORD, "checksum_" + i, null);+ }++ toDataTypeDexFile(structure);+ toDataTypeVerifierDeps(structure);+ toDataTypeTypeLookupTable(structure);++ return structure;+ }++ private void toDataTypeDexFile(Structure structure) {+ VdexSectionHeader_12 dexFileSection =+ sections.get(VdexSection_12.kDexFileSection.ordinal());+ if (dexFileSection.getSectionSize() > 0) {+ DataType array =+ new ArrayDataType(BYTE, dexFileSection.getSectionSize(), BYTE.getLength());+ structure.add(array, "cdex", null);+ }+ }++ private void toDataTypeVerifierDeps(Structure structure) {+ VdexSectionHeader_12 verifierDepsSection =+ sections.get(VdexSection_12.kVerifierDepsSection.ordinal());+ if (verifierDepsSection.getSectionSize() > 0) {+ DataType array =+ new ArrayDataType(BYTE, verifierDepsSection.getSectionSize(), BYTE.getLength());+ structure.add(array, "verifier_deps", null);+ }+ }++ private void toDataTypeTypeLookupTable(Structure structure) {+ VdexSectionHeader_12 typeLookupTableSection =+ sections.get(VdexSection_12.kTypeLookupTableSection.ordinal());+ if (typeLookupTableSection.getSectionSize() > 0) {+ DataType array =+ new ArrayDataType(BYTE, typeLookupTableSection.getSectionSize(), BYTE.getLength());+ structure.add(array, "type_lookup_table", null);+ }+ }+}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/android12/VdexSectionHeader_12.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/android12/VdexSectionHeader_12.javanew file mode 100644index 0000000000..559bee9c8e--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/android12/VdexSectionHeader_12.java@@ -0,0 +1,63 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.vdex.android12;++import java.io.IOException;++import ghidra.app.util.bin.BinaryReader;+import ghidra.app.util.bin.StructConverter;+import ghidra.program.model.data.*;+import ghidra.util.exception.DuplicateNameException;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/android-s-beta-5/runtime/vdex_file.h#92+ *+ */+public class VdexSectionHeader_12 implements StructConverter {++ private VdexSection_12 section_kind;+ private int section_offset;+ private int section_size;++ public VdexSectionHeader_12(BinaryReader reader) throws IOException {+ section_kind = VdexSection_12.values()[reader.readNextInt()];+ section_offset = reader.readNextInt();+ section_size = reader.readNextInt();+ }++ public VdexSection_12 getSectionKind() {+ return section_kind;+ }++ public int getSectionOffset() {+ return section_offset;+ }++ public int getSectionSize() {+ return section_size;+ }++ @Override+ public DataType toDataType() throws DuplicateNameException, IOException {+ String className = VdexSectionHeader_12.class.getSimpleName();+ Structure structure = new StructureDataType(className, 0);+ structure.add(DWORD, "section_kind", null);+ structure.add(DWORD, "section_offset", null);+ structure.add(DWORD, "section_size", null);+ return structure;+ }++}diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/android12/VdexSection_12.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/android12/VdexSection_12.javanew file mode 100644index 0000000000..1d8f7f0d08--- /dev/null+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/vdex/android12/VdexSection_12.java@@ -0,0 +1,28 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.file.formats.android.vdex.android12;++/**+ * https://android.googlesource.com/platform/art/+/refs/heads/android-s-beta-5/runtime/vdex_file.h#80+ *+ */+public enum VdexSection_12 {+ kChecksumSection,+ kDexFileSection,+ kVerifierDepsSection,+ kTypeLookupTableSection,+ kNumberOfSections,+}diff --git a/Ghidra/Processors/Dalvik/certification.manifest b/Ghidra/Processors/Dalvik/certification.manifestindex ac404338dc..5a2df59c27 100644--- a/Ghidra/Processors/Dalvik/certification.manifest+++ b/Ghidra/Processors/Dalvik/certification.manifest@@ -8,6 +8,7 @@ data/languages/Dalvik_Base.sinc||GHIDRA||||END|data/languages/Dalvik_Base.slaspec||GHIDRA||||END|data/languages/Dalvik_DEX_Android10.slaspec||GHIDRA||||END|data/languages/Dalvik_DEX_Android11.slaspec||GHIDRA||||END|+data/languages/Dalvik_DEX_Android12.slaspec||GHIDRA||||END|data/languages/Dalvik_DEX_KitKat.slaspec||GHIDRA||||END|data/languages/Dalvik_DEX_Lollipop.slaspec||GHIDRA||||END|data/languages/Dalvik_DEX_Marshmallow.slaspec||GHIDRA||||END|@@ -22,6 +23,7 @@ data/languages/Dalvik_OpCode_73_unused.sinc||GHIDRA||||END|data/languages/Dalvik_OpCode_79_unused.sinc||GHIDRA||||END|data/languages/Dalvik_OpCode_7A_unused.sinc||GHIDRA||||END|data/languages/Dalvik_OpCode_E3_EA_dex.sinc||GHIDRA||||END|+data/languages/Dalvik_OpCode_E3_EA_unused.sinc||GHIDRA||||END|data/languages/Dalvik_OpCode_EB_F2_iput_iget.sinc||GHIDRA||||END|data/languages/Dalvik_OpCode_EB_F2_unused.sinc||GHIDRA||||END|data/languages/Dalvik_OpCode_F3_unused.sinc||GHIDRA||||END|diff --git a/Ghidra/Processors/Dalvik/data/languages/Dalvik.ldefs b/Ghidra/Processors/Dalvik/data/languages/Dalvik.ldefsindex f40714b7ec..9045716b10 100644--- a/Ghidra/Processors/Dalvik/data/languages/Dalvik.ldefs+++ b/Ghidra/Processors/Dalvik/data/languages/Dalvik.ldefs@@ -136,4 +136,16 @@<compiler name="default" spec="Dalvik_Base.cspec" id="default"/></language>+ <language processor="Dalvik"+ endian="little"+ size="32"+ variant="DEX Android12"+ version="1.0"+ slafile="Dalvik_DEX_Android12.sla"+ processorspec="Dalvik_Base.pspec"+ id="Dalvik:LE:32:DEX_Android12">+ <description>Dalvik DEX Android12</description>+ <compiler name="default" spec="Dalvik_Base.cspec" id="default"/>+ </language>+</language_definitions>diff --git a/Ghidra/Processors/Dalvik/data/languages/Dalvik_DEX_Android12.slaspec b/Ghidra/Processors/Dalvik/data/languages/Dalvik_DEX_Android12.slaspecnew file mode 100644index 0000000000..bd9ee176d0--- /dev/null+++ b/Ghidra/Processors/Dalvik/data/languages/Dalvik_DEX_Android12.slaspec@@ -0,0 +1,30 @@+#------------------------------------------------------------------------------------+# Sleigh specification file for DALVIK VM+#------------------------------------------------------------------------------------++# Source:+# https://android.googlesource.com/platform/art/+/refs/heads/android-s-beta-5/libdexfile/dex/dex_instruction_list.h++@include "Dalvik_Base.sinc"++@include "Dalvik_OpCode_3E_43_unused.sinc"++@include "Dalvik_OpCode_73_unused.sinc"++@include "Dalvik_OpCode_79_unused.sinc"+@include "Dalvik_OpCode_7A_unused.sinc"++@include "Dalvik_OpCode_E3_EA_unused.sinc"++@include "Dalvik_OpCode_EB_F2_unused.sinc"++@include "Dalvik_OpCode_F3_unused.sinc"+@include "Dalvik_OpCode_F4_unused.sinc"+@include "Dalvik_OpCode_F5_unused.sinc"+@include "Dalvik_OpCode_F6_unused.sinc"+@include "Dalvik_OpCode_F7_unused.sinc"+@include "Dalvik_OpCode_F8_unused.sinc"+@include "Dalvik_OpCode_F9_unused.sinc"++@include "Dalvik_OpCode_FA_FD_dex.sinc"+@include "Dalvik_OpCode_FE_FF_dex.sinc"\ No newline at end of filediff --git a/Ghidra/Processors/Dalvik/data/languages/Dalvik_OpCode_E3_EA_unused.sinc b/Ghidra/Processors/Dalvik/data/languages/Dalvik_OpCode_E3_EA_unused.sincnew file mode 100644index 0000000000..121b476ea2--- /dev/null+++ b/Ghidra/Processors/Dalvik/data/languages/Dalvik_OpCode_E3_EA_unused.sinc@@ -0,0 +1,71 @@+#------------------------------------------------------------------------------------+#------------------------------------------------------------------------------------+# V(0xE3, UNUSED_E3, "unused-e3", k10x, false, kUnknown, 0, kVerifyError) \++:unused_e3 is inst0=0xe3+{+ #no pCode+}++#------------------------------------------------------------------------------------+#------------------------------------------------------------------------------------+# V(0xE4, UNUSED_E4, "unused-e4", k10x, false, kUnknown, 0, kVerifyError) \++:unused_e4 is inst0=0xe4+{+ #no pCode+}++#------------------------------------------------------------------------------------+#------------------------------------------------------------------------------------+# V(0xE5, UNUSED_E5, "unused-e5", k10x, false, kUnknown, 0, kVerifyError) \++:unused_e5 is inst0=0xe5+{+ #no pCode+}++#------------------------------------------------------------------------------------+#------------------------------------------------------------------------------------+# V(0xE6, UNUSED_E6, "unused-e6", k10x, false, kUnknown, 0, kVerifyError) \++:unused_e6 is inst0=0xe6+{+ #no pCode+}++#------------------------------------------------------------------------------------+#------------------------------------------------------------------------------------+# V(0xE7, UNUSED_E7, "unused-e7", k10x, false, kUnknown, 0, kVerifyError) \++:unused_e7 is inst0=0xe7+{+ #no pCode+}++#------------------------------------------------------------------------------------+#------------------------------------------------------------------------------------+# V(0xE8, UNUSED_E8, "unused-e8", k10x, false, kUnknown, 0, kVerifyError) \++:unused_e8 is inst0=0xe8+{+ #no pCode+}++#------------------------------------------------------------------------------------+#------------------------------------------------------------------------------------+# V(0xE9, UNUSED_E9, "unused-e9", k10x, false, kUnknown, 0, kVerifyError) \++:unused_e9 is inst0=0xe9+{+ #no pCode+}++#------------------------------------------------------------------------------------+#------------------------------------------------------------------------------------+# V(0xEA, UNUSED_EA, "unused-ea", k10x, false, kUnknown, 0, kVerifyError) \++:unused_ea is inst0=0xea+{+ #no pCode+}