diff --git a/Ghidra/Features/Base/certification.manifest b/Ghidra/Features/Base/certification.manifest index e3f1b99718..6123bdc3c9 100644 --- a/Ghidra/Features/Base/certification.manifest +++ b/Ghidra/Features/Base/certification.manifest @@ -236,7 +236,6 @@ data/typeinfo/golang/patchverdiffs/go1.24.4.json.diff||GHIDRA||||END| data/typeinfo/golang/patchverdiffs/go1.24.5.json.diff||GHIDRA||||END| data/typeinfo/golang/patchverdiffs/go1.24.6.json.diff||GHIDRA||||END| data/typeinfo/mac_10.9/mac_osx.gdt||GHIDRA||||END| -data/typeinfo/rust/rust-common.gdt||GHIDRA||||END| data/typeinfo/win32/msvcrt/clsids.txt||GHIDRA||reviewed||END| data/typeinfo/win32/msvcrt/guids.txt||GHIDRA||reviewed||END| data/typeinfo/win32/msvcrt/iids.txt||GHIDRA||||END| diff --git a/Ghidra/Features/Base/data/ExtensionPoint.manifest b/Ghidra/Features/Base/data/ExtensionPoint.manifest index cdcb72472e..711f68ce96 100644 --- a/Ghidra/Features/Base/data/ExtensionPoint.manifest +++ b/Ghidra/Features/Base/data/ExtensionPoint.manifest @@ -5,6 +5,9 @@ FieldFactory FieldMouseHandler StringHandler Loader +SourceLanguage +SourceLanguageDataArchive +SourceLanguageSpecExtension TableRowMapper ScriptProvider Recognizer diff --git a/Ghidra/Features/Base/ghidra_scripts/RemoveSourceLanguage.java b/Ghidra/Features/Base/ghidra_scripts/RemoveSourceLanguage.java new file mode 100644 index 0000000000..5a5197098e --- /dev/null +++ b/Ghidra/Features/Base/ghidra_scripts/RemoveSourceLanguage.java @@ -0,0 +1,49 @@ +/* ### + * 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. + */ +//Removes a source language from the program +//@category Program + +import java.util.*; + +import ghidra.app.script.GhidraScript; +import ghidra.app.util.sourcelanguage.SourceLanguageID; + +public class RemoveSourceLanguage extends GhidraScript { + + @Override + public void run() throws Exception { + if (currentProgram == null) { + return; + } + + Set idSet = currentProgram.getSourceLanguageIDs(); + if (idSet.isEmpty()) { + println("No source languages found in " + currentProgram); + } + + Set selected = new HashSet<>(askChoices("Remove Source Language(s)", + "Select source languages to remove from the program", new ArrayList<>(idSet))); + + // Remove from the "Source Language" program property + idSet.removeIf(selected::contains); + currentProgram.setSourceLanguageIDs(idSet); + + // Future: Remove associated spec extensions if possible + + // Future: Remove associated data archives if possible + } + +} diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/ApplyDataArchiveAnalyzer.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/ApplyDataArchiveAnalyzer.java index b300fbb549..a4f5b4b601 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/ApplyDataArchiveAnalyzer.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/ApplyDataArchiveAnalyzer.java @@ -27,6 +27,7 @@ import ghidra.app.plugin.core.datamgr.util.DataTypeArchiveUtility; import ghidra.app.services.*; import ghidra.app.util.bin.format.golang.rtti.GoRttiMapper; import ghidra.app.util.importer.MessageLog; +import ghidra.app.util.sourcelanguage.SourceLanguageService; import ghidra.framework.Application; import ghidra.framework.model.*; import ghidra.framework.options.OptionType; @@ -194,6 +195,38 @@ public class ApplyDataArchiveAnalyzer extends AbstractAnalyzer { } } } + + // Add source language data archives + result.addAll(getSourceLanguageDTMs(program, log, monitor)); + + return result; + } + + private List getSourceLanguageDTMs(Program program, MessageLog log, + TaskMonitor monitor) { + List result = new ArrayList<>(); + for (ResourceFile file : SourceLanguageService.getDataArchives(program, + program.getSourceLanguageIDs(), log, monitor)) { + if (monitor.isCancelled()) { + break; + } + try { + DataTypeManager dtm = dtmService.openArchive(file, false); + result.add(dtm); + } + catch (Exception e) { + Throwable cause = e.getCause(); + if (cause instanceof VersionException) { + log.appendMsg("Apply Data Archives", + "Unable to open archive %s: %s".formatted(file, cause.toString())); + } + else { + String msg = Objects.requireNonNullElse(e.getMessage(), e.toString()); + log.appendMsg("Apply Data Archives", + "Unexpected Error opening archive %s: %s".formatted(file, msg)); + } + } + } return result; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/SourceLanguageAnalyzer.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/SourceLanguageAnalyzer.java new file mode 100644 index 0000000000..4f01109807 --- /dev/null +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/SourceLanguageAnalyzer.java @@ -0,0 +1,102 @@ +/* ### + * 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.app.plugin.core.analysis; + +import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; + +import ghidra.app.services.*; +import ghidra.app.util.importer.MessageLog; +import ghidra.app.util.sourcelanguage.SourceLanguageID; +import ghidra.app.util.sourcelanguage.SourceLanguageService; +import ghidra.framework.options.Options; +import ghidra.program.model.address.AddressSetView; +import ghidra.program.model.listing.Program; +import ghidra.util.exception.CancelledException; +import ghidra.util.task.TaskMonitor; + +/** + * Adds/updates source language-specific support to the program + */ +public class SourceLanguageAnalyzer extends AbstractAnalyzer { + + private final static String NAME = "Source Language Support"; + private final static String DESCRIPTION = + "Adds/updates source language-specific support to the program"; + + private static String OPTION_NAME_SPEC_EXTENSIONS = "Add specification extensions"; + private static String OPTION_DESC_SPEC_EXTENSIONS = + "Add any source language-specific specification extensions to the program."; + private static boolean OPTION_DEFAULT_SPEC_EXTENSIONS = true; + + private AtomicBoolean analysisStarted = new AtomicBoolean(false); + private boolean addSpecExtensions = OPTION_DEFAULT_SPEC_EXTENSIONS; + + /** + * Creates a new {@link SourceLanguageAnalyzer} + */ + public SourceLanguageAnalyzer() { + super(NAME, DESCRIPTION, AnalyzerType.BYTE_ANALYZER); + setPriority(AnalysisPriority.FORMAT_ANALYSIS.before().before().before().before().before()); + setDefaultEnablement(true); + } + + @Override + public boolean added(Program program, AddressSetView set, TaskMonitor monitor, MessageLog log) + throws CancelledException { + + // Enforce that the below code only executes once per analysis session + if (analysisStarted.getAndSet(true)) { + return true; + } + + // Look for new source languages in the program + Set ids = SourceLanguageService.find(program, log, monitor); + + // Update the "Source Languages" program property + program.setSourceLanguageIDs(ids); + + // Optionally add source language spec extensions + if (addSpecExtensions) { + if (program.hasExclusiveAccess()) { + SourceLanguageService.addSpecExtensions(program, ids, log, monitor); + } + else { + log.appendMsg( + NAME + ": Cannot add spec extensions without exclusive access to program."); + } + } + + return true; + } + + @Override + public void registerOptions(Options options, Program program) { + options.registerOption(OPTION_NAME_SPEC_EXTENSIONS, OPTION_DEFAULT_SPEC_EXTENSIONS, null, + OPTION_DESC_SPEC_EXTENSIONS); + } + + @Override + public void optionsChanged(Options options, Program program) { + addSpecExtensions = + options.getBoolean(OPTION_NAME_SPEC_EXTENSIONS, OPTION_DEFAULT_SPEC_EXTENSIONS); + } + + @Override + public void analysisEnded(Program program) { + analysisStarted.set(false); + } +} diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/RustUtilities.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/RustUtilities.java deleted file mode 100644 index 2fe10fed5c..0000000000 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/RustUtilities.java +++ /dev/null @@ -1,150 +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.app.plugin.core.analysis.rust; - -import java.io.IOException; -import java.io.InputStream; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.xml.sax.SAXException; - -import generic.jar.ResourceFile; -import ghidra.app.plugin.processors.sleigh.SleighException; -import ghidra.app.util.bin.format.elf.info.ElfComment; -import ghidra.app.util.opinion.ElfLoader; -import ghidra.framework.Application; -import ghidra.framework.store.LockException; -import ghidra.program.database.SpecExtension; -import ghidra.program.model.address.Address; -import ghidra.program.model.address.AddressSet; -import ghidra.program.model.lang.Language; -import ghidra.program.model.lang.Processor; -import ghidra.program.model.listing.Program; -import ghidra.program.model.mem.MemoryBlock; -import ghidra.util.Msg; -import ghidra.util.bytesearch.*; -import ghidra.util.exception.CancelledException; -import ghidra.util.task.TaskMonitor; -import ghidra.xml.XmlParseException; - -/** - * Rust utility functions - */ -public class RustUtilities { - - private static final java.util.regex.Pattern ELF_COMMENT_REGEX = - java.util.regex.Pattern.compile("^rustc version .*$"); - - /** - * Checks if the specified program contains Rust stuff, either by metadata or by searching - * the specified {@link MemoryBlock} for byte pattern signatures. - *

- * This may be used by loaders to determine if a program was compiled with rust. - * If the program is determined to be rust, then the compiler property is set to - * {@link RustConstants#RUST_COMPILER}. - * - * @param program The {@link Program} - * @param block The {@link MemoryBlock} to scan for Rust signatures - * @param monitor The monitor - * @return True if the given {@link MemoryBlock} is not null and contains a Rust signature; - * otherwise, false - * @throws IOException if there was an IO-related error - * @throws CancelledException if the user cancelled the operation - */ - public static boolean isRust(Program program, MemoryBlock block, TaskMonitor monitor) - throws IOException, CancelledException { - - if ( ElfLoader.isElf(program)) { - // ELF binaries can contain a ".comment" section that records the toolchains that - // produced the binary. Search this first as its quick and easy. - ElfComment elfComments = ElfComment.fromProgram(program); - if ( elfComments != null ) { - for(String s : elfComments.getCommentStrings() ) { - if (ELF_COMMENT_REGEX.matcher(s).matches()) { - return true; - } - } - } - } - - if (block == null) { - return false; - } - - // Use a MemoryBytePatternSearch for more efficient byte searching over a list of potential - // byte signatures. The below action sets our supplied boolean to true on a match, which we - // can later query and use as a return value for this method. - GenericMatchAction action = - new GenericMatchAction(new AtomicBoolean()) { - @Override - public void apply(Program prog, Address addr, Match match) { - getMatchValue().set(true); - } - }; - MemoryBytePatternSearcher searcher = new MemoryBytePatternSearcher("Rust signatures"); - for (byte[] sig : RustConstants.RUST_SIGNATURES) { - searcher.addPattern(new GenericByteSequencePattern(sig, action)); - } - - searcher.search(program, new AddressSet(block.getAddressRange()), monitor); - - return action.getMatchValue().get(); - } - - /** - * Returns true if the given program has earlier been tagged as having a Rust compiler by - * the loader. - * - * @param program {@link Program} - * @return boolean true if program's compiler property includes rust - */ - public static boolean isRustProgram(Program program) { - String name = program.getCompiler(); - return name != null && name.contains(RustConstants.RUST_COMPILER); - } - - public static int addExtensions(Program program, TaskMonitor monitor, String subPath) - throws IOException { - Language language = program.getLanguageCompilerSpecPair().getLanguage(); - Processor processor = language.getProcessor(); - int bitSize = language.getLanguageDescription().getSize(); - String spath = RustConstants.RUST_EXTENSIONS_PATH + subPath + bitSize; - ResourceFile module = Application.getModuleDataSubDirectory(processor.toString(), spath); - - int extensionCount = 0; - - ResourceFile[] files = module.listFiles(); - if (files != null) { - for (ResourceFile file : files) { - InputStream stream = file.getInputStream(); - byte[] bytes = stream.readAllBytes(); - String xml = new String(bytes); - - try { - SpecExtension extension = new SpecExtension(program); - extension.addReplaceCompilerSpecExtension(xml, monitor); - extensionCount++; - } - catch (SleighException | SAXException | XmlParseException | LockException e) { - Msg.error(RustUtilities.class, - "Failed to load Rust cspec extension: " + file.getAbsolutePath(), e); - } - } - } - - return extensionCount; - } -} diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/util/DataTypeArchiveUtility.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/util/DataTypeArchiveUtility.java index 733cda8895..98d23a5cd2 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/util/DataTypeArchiveUtility.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/util/DataTypeArchiveUtility.java @@ -18,7 +18,6 @@ package ghidra.app.plugin.core.datamgr.util; import java.util.*; import generic.jar.ResourceFile; -import ghidra.app.plugin.core.analysis.rust.RustConstants; import ghidra.app.plugin.core.datamgr.archive.DataTypeManagerHandler; import ghidra.app.util.opinion.*; import ghidra.framework.Application; @@ -143,10 +142,6 @@ public class DataTypeArchiveUtility { list.add("generic_clib"); } - if (program.getCompiler().contains(RustConstants.RUST_COMPILER)) { - list.add("rust-common"); - } - return list; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/ElfLoader.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/ElfLoader.java index ba73124d73..dd341a4e76 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/ElfLoader.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/ElfLoader.java @@ -23,7 +23,6 @@ import ghidra.app.util.bin.ByteProvider; import ghidra.app.util.bin.format.elf.*; import ghidra.app.util.bin.format.golang.GoConstants; import ghidra.app.util.bin.format.golang.rtti.GoRttiMapper; -import ghidra.app.util.bin.format.swift.SwiftUtils; import ghidra.framework.model.DomainObject; import ghidra.framework.model.ProjectData; import ghidra.framework.options.Options; @@ -206,9 +205,6 @@ public class ElfLoader extends AbstractLibrarySupportLoader { List sectionNames = Arrays.stream(elf.getSections()) .map(ElfSectionHeader::getNameAsString) .toList(); - if (SwiftUtils.isSwift(sectionNames)) { - return SwiftUtils.SWIFT_COMPILER; - } if (GoRttiMapper.hasGolangSections(sectionNames)) { return GoConstants.GOLANG_CSPEC_NAME; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/ElfProgramBuilder.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/ElfProgramBuilder.java index 9d5f07d62b..28ead6ffa3 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/ElfProgramBuilder.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/ElfProgramBuilder.java @@ -25,8 +25,6 @@ import org.apache.commons.compress.compressors.xz.XZCompressorInputStream; import org.apache.commons.lang3.StringUtils; import ghidra.app.cmd.label.SetLabelPrimaryCmd; -import ghidra.app.plugin.core.analysis.rust.RustConstants; -import ghidra.app.plugin.core.analysis.rust.RustUtilities; import ghidra.app.util.*; import ghidra.app.util.bin.*; import ghidra.app.util.bin.format.MemoryLoadable; @@ -188,8 +186,6 @@ class ElfProgramBuilder extends MemorySectionResolver implements ElfLoadHelper { markupElfInfoProducers(monitor); - setCompiler(monitor); - success = true; } finally { @@ -2464,22 +2460,6 @@ class ElfProgramBuilder extends MemorySectionResolver implements ElfLoadHelper { } } - private void setCompiler(TaskMonitor monitor) throws CancelledException { - // Check for Rust - try { - if (RustUtilities.isRust(program, memory.getBlock(ElfSectionHeaderConstants.dot_rodata), - monitor)) { - program.setCompiler(RustConstants.RUST_COMPILER); - int extensionCount = RustUtilities.addExtensions(program, monitor, - RustConstants.RUST_EXTENSIONS_UNIX); - log.appendMsg("Installed " + extensionCount + " Rust cspec extensions"); - } - } - catch (IOException e) { - log.appendMsg("Rust error: " + e.getMessage()); - } - } - private void markupHashTable(TaskMonitor monitor) { ElfDynamicTable dynamicTable = elf.getDynamicTable(); diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoLoader.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoLoader.java index f554812e25..cc0923a054 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoLoader.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoLoader.java @@ -28,7 +28,6 @@ import ghidra.app.util.bin.format.macho.*; import ghidra.app.util.bin.format.macho.commands.*; import ghidra.app.util.bin.format.macho.dyld.DyldArchitecture; import ghidra.app.util.bin.format.macho.dyld.DyldCacheHeader; -import ghidra.app.util.bin.format.swift.SwiftUtils; import ghidra.app.util.bin.format.ubi.*; import ghidra.app.util.importer.MessageLog; import ghidra.formats.gfilesystem.*; @@ -543,9 +542,6 @@ public class MachoLoader extends AbstractLibrarySupportLoader { .flatMap(seg -> seg.getSections().stream()) .map(section -> section.getSectionName()) .toList(); - if (SwiftUtils.isSwift(sectionNames)) { - return SwiftUtils.SWIFT_COMPILER; - } if (GoRttiMapper.hasGolangSections(sectionNames)) { return GoConstants.GOLANG_CSPEC_NAME; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoPrelinkProgramBuilder.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoPrelinkProgramBuilder.java index de98e133bc..ab365928a8 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoPrelinkProgramBuilder.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoPrelinkProgramBuilder.java @@ -30,7 +30,8 @@ import ghidra.app.util.importer.MessageLog; import ghidra.program.database.mem.FileBytes; import ghidra.program.model.address.Address; import ghidra.program.model.listing.*; -import ghidra.util.exception.*; +import ghidra.util.exception.CancelledException; +import ghidra.util.exception.DuplicateNameException; import ghidra.util.task.TaskMonitor; /** @@ -173,12 +174,6 @@ public class MachoPrelinkProgramBuilder extends MachoProgramBuilder { return machoInfoList; } - @Override - protected void renameObjMsgSendRtpSymbol() - throws DuplicateNameException, InvalidInputException { - // Do nothing. This is not applicable for a PRELINK Mach-O. - } - @Override protected void markupChainedFixups(MachHeader header, List

fixups) throws CancelledException { diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoProgramBuilder.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoProgramBuilder.java index 20680e2840..9fe79ff434 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoProgramBuilder.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoProgramBuilder.java @@ -15,14 +15,11 @@ */ package ghidra.app.util.opinion; -import java.io.IOException; import java.math.BigInteger; import java.util.*; import org.apache.commons.collections4.map.LazySortedMap; -import ghidra.app.plugin.core.analysis.rust.RustConstants; -import ghidra.app.plugin.core.analysis.rust.RustUtilities; import ghidra.app.util.MemoryBlockUtils; import ghidra.app.util.bin.*; import ghidra.app.util.bin.format.RelocationException; @@ -40,8 +37,6 @@ import ghidra.app.util.bin.format.macho.dyld.DyldChainedPtr.DyldChainType; import ghidra.app.util.bin.format.macho.dyld.DyldFixup; import ghidra.app.util.bin.format.macho.relocation.*; import ghidra.app.util.bin.format.macho.threadcommand.ThreadCommand; -import ghidra.app.util.bin.format.objc.ObjcUtils; -import ghidra.app.util.bin.format.objc.objc1.Objc1Constants; import ghidra.app.util.importer.MessageLog; import ghidra.framework.options.Options; import ghidra.program.database.function.OverlappingFunctionException; @@ -173,9 +168,7 @@ public class MachoProgramBuilder { } // Perform additional actions - renameObjMsgSendRtpSymbol(); fixupProgramTree(null); // should be done last to account for new memory blocks - setCompiler(provider.getName()); } /** @@ -1808,53 +1801,6 @@ public class MachoProgramBuilder { } } - protected void setCompiler(String source) throws CancelledException { - if (ObjcUtils.isObjc(program)) { - try { - program.setCompiler(ObjcUtils.OBJC_COMPILER); - int count = ObjcUtils.addExtensions(program, monitor); - if (count > 0) { - log.appendMsg("%s: installed %d objc SpecExtensions".formatted(source, count)); - } - } - catch (IOException e) { - log.appendMsg("%s: objc error - %s".formatted(source, e.getMessage())); - } - return; - } - - try { - Section section = - machoHeader.getSection(SegmentNames.SEG_TEXT, SectionNames.TEXT_CONST); - if (section != null && RustUtilities.isRust(program, - memory.getBlock(space.getAddress(section.getAddress())), monitor)) { - program.setCompiler(RustConstants.RUST_COMPILER); - int count = RustUtilities.addExtensions(program, monitor, - RustConstants.RUST_EXTENSIONS_UNIX); - if (count > 0) { - log.appendMsg("%s: installed %d rust SpecExtensions".formatted(source, count)); - } - } - } - catch (IOException e) { - log.appendMsg("%s: Rust error - %s".formatted(source, e.getMessage())); - } - } - - protected void renameObjMsgSendRtpSymbol() - throws DuplicateNameException, InvalidInputException { - Address address = space.getAddress(Objc1Constants.OBJ_MSGSEND_RTP); - Symbol symbol = program.getSymbolTable().getPrimarySymbol(address); - if (symbol != null && symbol.isDynamic()) { - symbol.setName(Objc1Constants.OBJC_MSG_SEND_RTP_NAME, SourceType.IMPORTED); - } - else { - program.getSymbolTable() - .createLabel(address, Objc1Constants.OBJC_MSG_SEND_RTP_NAME, - SourceType.IMPORTED); - } - } - /** * Associates the given {@link Symbol} with the correct external {@link Library} (fixing * the {@code } association) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/PeLoader.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/PeLoader.java index db63ddf73d..1d3c866289 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/PeLoader.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/PeLoader.java @@ -23,8 +23,6 @@ import org.apache.commons.io.FilenameUtils; import com.google.common.primitives.Bytes; -import ghidra.app.plugin.core.analysis.rust.RustConstants; -import ghidra.app.plugin.core.analysis.rust.RustUtilities; import ghidra.app.util.MemoryBlockUtils; import ghidra.app.util.Option; import ghidra.app.util.bin.BinaryReader; @@ -39,7 +37,6 @@ import ghidra.app.util.bin.format.pe.ImageCor20Header.ImageCor20Flags; import ghidra.app.util.bin.format.pe.PortableExecutable.SectionLayout; import ghidra.app.util.bin.format.pe.debug.DebugCOFFSymbol; import ghidra.app.util.bin.format.pe.debug.DebugDirectoryParser; -import ghidra.app.util.bin.format.swift.SwiftUtils; import ghidra.app.util.importer.MessageLog; import ghidra.framework.model.DomainObject; import ghidra.framework.options.Options; @@ -925,9 +922,7 @@ public class PeLoader extends AbstractPeDebugLoader { BorlandCpp("borland:c++", "borlandcpp"), BorlandUnk("borland:unknown", "borlandcpp"), CLI("cli", "cli"), - Rustc(RustConstants.RUST_COMPILER, RustConstants.RUST_COMPILER), GOLANG("golang", "golang"), - Swift(SwiftUtils.SWIFT_COMPILER, SwiftUtils.SWIFT_COMPILER), Unknown("unknown", "unknown"), // The following values represent the presence of ambiguous indicators @@ -981,34 +976,6 @@ public class PeLoader extends AbstractPeDebugLoader { DOSHeader dh = pe.getDOSHeader(); - // Check for Rust. Program object is required, which may be null. - try { - if (program != null && RustUtilities.isRust(program, - program.getMemory().getBlock(".rdata"), monitor)) { - try { - int extensionCount = RustUtilities.addExtensions(program, monitor, - RustConstants.RUST_EXTENSIONS_WINDOWS); - log.appendMsg("Installed " + extensionCount + " Rust cspec extensions"); - } - catch (IOException e) { - log.appendMsg("Rust error: " + e.getMessage()); - } - return CompilerEnum.Rustc; - } - } - catch (CancelledException e) { - // Move on - } - - // Check for Swift - List sectionNames = - Arrays.stream(pe.getNTHeader().getFileHeader().getSectionHeaders()) - .map(section -> section.getName()) - .toList(); - if (SwiftUtils.isSwift(sectionNames)) { - return CompilerEnum.Swift; - } - // Check for managed code (.NET) if (pe.getNTHeader().getOptionalHeader().isCLI()) { return CompilerEnum.CLI; diff --git a/Ghidra/Features/SwiftDemangler/Module.manifest b/Ghidra/Features/Objective-C/Module.manifest similarity index 100% rename from Ghidra/Features/SwiftDemangler/Module.manifest rename to Ghidra/Features/Objective-C/Module.manifest diff --git a/Ghidra/Features/Objective-C/README.md b/Ghidra/Features/Objective-C/README.md new file mode 100644 index 0000000000..6d6c37b186 --- /dev/null +++ b/Ghidra/Features/Objective-C/README.md @@ -0,0 +1,3 @@ +# Objective-C + +The module provides improved support for binaries written in the Objective-C programming language. \ No newline at end of file diff --git a/Ghidra/Features/Objective-C/build.gradle b/Ghidra/Features/Objective-C/build.gradle new file mode 100644 index 0000000000..13b0a437a0 --- /dev/null +++ b/Ghidra/Features/Objective-C/build.gradle @@ -0,0 +1,25 @@ +/* ### + * 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. + */ +apply from: "$rootProject.projectDir/gradle/distributableGhidraModule.gradle" +apply from: "$rootProject.projectDir/gradle/javaProject.gradle" +apply plugin: 'eclipse' + +eclipse.project.name = 'Features Objective-C' + +dependencies { + api project(":Base") + api project(":Decompiler") +} diff --git a/Ghidra/Features/Objective-C/certification.manifest b/Ghidra/Features/Objective-C/certification.manifest new file mode 100644 index 0000000000..f113bb0589 --- /dev/null +++ b/Ghidra/Features/Objective-C/certification.manifest @@ -0,0 +1,12 @@ +##VERSION: 2.0 +Module.manifest||GHIDRA||||END| +README.md||GHIDRA||||END| +data/extensions.json||GHIDRA||||END| +data/extensions/aarch64/chkstk_darwin_fixup.xml||GHIDRA||||END| +data/extensions/aarch64/objc_getProperty_fixup.xml||GHIDRA||||END| +data/extensions/aarch64/objc_load_fixup.xml||GHIDRA||||END| +data/extensions/aarch64/objc_msgSend_stub.xml||GHIDRA||||END| +data/extensions/aarch64/objc_release_fixup.xml||GHIDRA||||END| +data/extensions/aarch64/objc_retain_fixup.xml||GHIDRA||||END| +data/extensions/aarch64/objc_setProperty_fixup.xml||GHIDRA||||END| +data/extensions/aarch64/objc_store_fixup.xml||GHIDRA||||END| diff --git a/Ghidra/Features/Objective-C/data/extensions.json b/Ghidra/Features/Objective-C/data/extensions.json new file mode 100644 index 0000000000..b534057d01 --- /dev/null +++ b/Ghidra/Features/Objective-C/data/extensions.json @@ -0,0 +1,8 @@ +[ + { + "processor": "AARCH64", + "endian": "little", + "size": "64", + "directory": "extensions/aarch64" + } +] diff --git a/Ghidra/Processors/AARCH64/data/extensions/objc/chkstk_darwin_fixup.xml b/Ghidra/Features/Objective-C/data/extensions/aarch64/chkstk_darwin_fixup.xml similarity index 100% rename from Ghidra/Processors/AARCH64/data/extensions/objc/chkstk_darwin_fixup.xml rename to Ghidra/Features/Objective-C/data/extensions/aarch64/chkstk_darwin_fixup.xml diff --git a/Ghidra/Processors/AARCH64/data/extensions/objc/objc_getProperty_fixup.xml b/Ghidra/Features/Objective-C/data/extensions/aarch64/objc_getProperty_fixup.xml similarity index 100% rename from Ghidra/Processors/AARCH64/data/extensions/objc/objc_getProperty_fixup.xml rename to Ghidra/Features/Objective-C/data/extensions/aarch64/objc_getProperty_fixup.xml diff --git a/Ghidra/Processors/AARCH64/data/extensions/objc/objc_load_fixup.xml b/Ghidra/Features/Objective-C/data/extensions/aarch64/objc_load_fixup.xml similarity index 100% rename from Ghidra/Processors/AARCH64/data/extensions/objc/objc_load_fixup.xml rename to Ghidra/Features/Objective-C/data/extensions/aarch64/objc_load_fixup.xml diff --git a/Ghidra/Processors/AARCH64/data/extensions/objc/objc_msgSend_stub.xml b/Ghidra/Features/Objective-C/data/extensions/aarch64/objc_msgSend_stub.xml similarity index 100% rename from Ghidra/Processors/AARCH64/data/extensions/objc/objc_msgSend_stub.xml rename to Ghidra/Features/Objective-C/data/extensions/aarch64/objc_msgSend_stub.xml diff --git a/Ghidra/Processors/AARCH64/data/extensions/objc/objc_release_fixup.xml b/Ghidra/Features/Objective-C/data/extensions/aarch64/objc_release_fixup.xml similarity index 100% rename from Ghidra/Processors/AARCH64/data/extensions/objc/objc_release_fixup.xml rename to Ghidra/Features/Objective-C/data/extensions/aarch64/objc_release_fixup.xml diff --git a/Ghidra/Processors/AARCH64/data/extensions/objc/objc_retain_fixup.xml b/Ghidra/Features/Objective-C/data/extensions/aarch64/objc_retain_fixup.xml similarity index 100% rename from Ghidra/Processors/AARCH64/data/extensions/objc/objc_retain_fixup.xml rename to Ghidra/Features/Objective-C/data/extensions/aarch64/objc_retain_fixup.xml diff --git a/Ghidra/Processors/AARCH64/data/extensions/objc/objc_setProperty_fixup.xml b/Ghidra/Features/Objective-C/data/extensions/aarch64/objc_setProperty_fixup.xml similarity index 100% rename from Ghidra/Processors/AARCH64/data/extensions/objc/objc_setProperty_fixup.xml rename to Ghidra/Features/Objective-C/data/extensions/aarch64/objc_setProperty_fixup.xml diff --git a/Ghidra/Processors/AARCH64/data/extensions/objc/objc_store_fixup.xml b/Ghidra/Features/Objective-C/data/extensions/aarch64/objc_store_fixup.xml similarity index 100% rename from Ghidra/Processors/AARCH64/data/extensions/objc/objc_store_fixup.xml rename to Ghidra/Features/Objective-C/data/extensions/aarch64/objc_store_fixup.xml diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/analysis/ObjcMessageAnalyzer.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/plugin/core/analysis/ObjcMessageAnalyzer.java similarity index 99% rename from Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/analysis/ObjcMessageAnalyzer.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/plugin/core/analysis/ObjcMessageAnalyzer.java index f2f594b55a..ded91bf1f1 100644 --- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/analysis/ObjcMessageAnalyzer.java +++ b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/plugin/core/analysis/ObjcMessageAnalyzer.java @@ -32,6 +32,7 @@ import ghidra.app.util.bin.format.objc.objc2.*; import ghidra.app.util.importer.MessageLog; import ghidra.app.util.opinion.MachoLoader; import ghidra.app.util.opinion.MachoProgramBuilder; +import ghidra.app.util.sourcelanguage.ObjcSourceLanguageSpecExtension; import ghidra.framework.options.OptionType; import ghidra.framework.options.Options; import ghidra.program.model.address.*; @@ -275,8 +276,9 @@ public class ObjcMessageAnalyzer extends AbstractAnalyzer { String cc = CompilerSpec.CALLING_CONVENTION_unknown; if (isStub) { if (program.getDataTypeManager() - .getCallingConvention(ObjcUtils.OBJC_MSGSEND_STUBS_CC) != null) { - cc = ObjcUtils.OBJC_MSGSEND_STUBS_CC; + .getCallingConvention( + ObjcSourceLanguageSpecExtension.OBJC_MSGSEND_STUBS) != null) { + cc = ObjcSourceLanguageSpecExtension.OBJC_MSGSEND_STUBS; } } @@ -998,7 +1000,8 @@ public class ObjcMessageAnalyzer extends AbstractAnalyzer { if (args.length >= 2 && args[1].getDataType().equals(dataTypes.sel)) { signature.setArguments(ArrayUtils.remove(args, 1)); } - signature.setCallingConvention(ObjcUtils.OBJC_MSGSEND_STUBS_CC); + signature.setCallingConvention( + ObjcSourceLanguageSpecExtension.OBJC_MSGSEND_STUBS); HighFunctionDBUtil.writeOverride(funcMgr.getFunctionContaining(fromAddress), fromAddress, signature); } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/ObjcTypeMetadataAnalyzer.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/plugin/core/analysis/ObjcTypeMetadataAnalyzer.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/ObjcTypeMetadataAnalyzer.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/plugin/core/analysis/ObjcTypeMetadataAnalyzer.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/AbstractObjcTypeMetadata.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/AbstractObjcTypeMetadata.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/AbstractObjcTypeMetadata.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/AbstractObjcTypeMetadata.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/ObjcMethod.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/ObjcMethod.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/ObjcMethod.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/ObjcMethod.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/ObjcMethodList.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/ObjcMethodList.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/ObjcMethodList.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/ObjcMethodList.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/ObjcMethodType.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/ObjcMethodType.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/ObjcMethodType.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/ObjcMethodType.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/ObjcState.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/ObjcState.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/ObjcState.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/ObjcState.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/ObjcTypeMetadataStructure.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/ObjcTypeMetadataStructure.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/ObjcTypeMetadataStructure.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/ObjcTypeMetadataStructure.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/ObjcUtils.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/ObjcUtils.java similarity index 84% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/ObjcUtils.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/ObjcUtils.java index 15c736f2e0..a7fb3baf9e 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/ObjcUtils.java +++ b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/ObjcUtils.java @@ -15,32 +15,25 @@ */ package ghidra.app.util.bin.format.objc; -import java.io.*; +import java.io.IOException; import java.math.BigInteger; import java.util.*; -import org.xml.sax.SAXException; - -import generic.jar.ResourceFile; import ghidra.app.cmd.data.CreateDataCmd; import ghidra.app.cmd.disassemble.DisassembleCommand; import ghidra.app.cmd.function.CreateFunctionCmd; import ghidra.app.cmd.register.SetRegisterCmd; -import ghidra.app.plugin.processors.sleigh.SleighException; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.objc.objc2.Objc2Constants; import ghidra.app.util.importer.MessageLog; -import ghidra.framework.Application; import ghidra.framework.cmd.BackgroundCommand; import ghidra.framework.cmd.Command; -import ghidra.framework.store.LockException; -import ghidra.program.database.SpecExtension; -import ghidra.program.database.SpecExtension.DocInfo; import ghidra.program.database.symbol.ClassSymbol; import ghidra.program.model.address.*; import ghidra.program.model.data.*; import ghidra.program.model.data.DataUtilities.ClearDataMode; -import ghidra.program.model.lang.*; +import ghidra.program.model.lang.Processor; +import ghidra.program.model.lang.Register; import ghidra.program.model.listing.Data; import ghidra.program.model.listing.Program; import ghidra.program.model.mem.Memory; @@ -51,24 +44,12 @@ import ghidra.util.Msg; import ghidra.util.exception.DuplicateNameException; import ghidra.util.exception.InvalidInputException; import ghidra.util.task.TaskMonitor; -import ghidra.xml.XmlParseException; /** * Objective-C utilities */ public final class ObjcUtils { - /** - * The Objective-C compiler name, used by {@link Program#setCompiler(String)} - */ - public static final String OBJC_COMPILER = "objc"; - - /** - * The Objective-C {@code _objc_msgSend} stub calling convention name (added with processor - * extension) - */ - public static final String OBJC_MSGSEND_STUBS_CC = "__objc_msgSend_stub"; - /** * String that prefixes Objective-C class symbols */ @@ -446,56 +427,4 @@ public final class ObjcUtils { } return name; } - - /** - * Adds Objective-C processor extensions to the {@link Program}, which include: - *
    - *
  • A special calling convention used by objc_msgSend stubs
  • - *
  • Call fixups to clear out a lot of Objective-C Automatic Reference Counting (ARC) clutter
  • - *
- * - * @param program The {@link Program} to add the extensions to - * @param monitor A cancelable task monitor - * @return The number of extensions successfully added - * @throws IOException if an IO-related error occurred - * @see Heros in Action: Analyzing Objective-C Binaries through Decompilation and IFDS - * @see RE//verse 2025: Langs Beyond The C - */ - public static int addExtensions(Program program, TaskMonitor monitor) throws IOException { - Language language = program.getLanguageCompilerSpecPair().getLanguage(); - Processor processor = language.getProcessor(); - String spath = "extensions/" + OBJC_COMPILER; - - int extensionCount = 0; - - try { - ResourceFile module = - Application.getModuleDataSubDirectory(processor.toString(), spath); - ResourceFile[] files = module.listFiles(); - if (files != null) { - for (ResourceFile file : files) { - InputStream stream = file.getInputStream(); - byte[] bytes = stream.readAllBytes(); - String xml = new String(bytes); - try { - SpecExtension extension = new SpecExtension(program); - DocInfo docInfo = extension.testExtensionDocument(xml); - if (SpecExtension.getCompilerSpecExtension(program, docInfo) == null) { - extension.addReplaceCompilerSpecExtension(xml, monitor); - extensionCount++; - } - } - catch (SleighException | SAXException | XmlParseException | LockException e) { - Msg.error(ObjcUtils.class, - "Failed to load Objective-C cspec extension: " + file, e); - } - } - } - } - catch (FileNotFoundException e) { - // fall thru - } - - return extensionCount; - } } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Category.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Category.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Category.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Category.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Class.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Class.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Class.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Class.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Constants.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Constants.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Constants.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Constants.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1InstanceVariable.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1InstanceVariable.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1InstanceVariable.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1InstanceVariable.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1InstanceVariableList.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1InstanceVariableList.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1InstanceVariableList.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1InstanceVariableList.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1MetaClass.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1MetaClass.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1MetaClass.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1MetaClass.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Method.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Method.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Method.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Method.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1MethodList.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1MethodList.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1MethodList.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1MethodList.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Module.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Module.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Module.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Module.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Protocol.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Protocol.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Protocol.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1Protocol.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1ProtocolList.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1ProtocolList.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1ProtocolList.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1ProtocolList.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1ProtocolMethod.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1ProtocolMethod.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1ProtocolMethod.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1ProtocolMethod.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1ProtocolMethodList.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1ProtocolMethodList.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1ProtocolMethodList.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1ProtocolMethodList.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1SymbolTable.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1SymbolTable.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1SymbolTable.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1SymbolTable.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1TypeEncodings.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1TypeEncodings.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1TypeEncodings.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1TypeEncodings.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1TypeMetadata.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1TypeMetadata.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1TypeMetadata.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc1/Objc1TypeMetadata.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Cache.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Cache.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Cache.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Cache.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Category.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Category.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Category.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Category.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Class.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Class.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Class.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Class.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2ClassRW.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2ClassRW.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2ClassRW.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2ClassRW.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Constants.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Constants.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Constants.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Constants.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2ImageInfo.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2ImageInfo.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2ImageInfo.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2ImageInfo.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Implementation.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Implementation.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Implementation.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Implementation.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2InstanceVariable.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2InstanceVariable.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2InstanceVariable.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2InstanceVariable.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2InstanceVariableList.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2InstanceVariableList.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2InstanceVariableList.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2InstanceVariableList.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2MessageReference.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2MessageReference.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2MessageReference.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2MessageReference.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Method.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Method.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Method.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Method.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2MethodList.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2MethodList.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2MethodList.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2MethodList.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Property.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Property.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Property.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Property.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2PropertyList.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2PropertyList.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2PropertyList.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2PropertyList.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Protocol.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Protocol.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Protocol.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2Protocol.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2ProtocolList.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2ProtocolList.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2ProtocolList.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2ProtocolList.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2TypeMetadata.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2TypeMetadata.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2TypeMetadata.java rename to Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/bin/format/objc/objc2/Objc2TypeMetadata.java diff --git a/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/sourcelanguage/MachoObjcSourceLanguage.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/sourcelanguage/MachoObjcSourceLanguage.java new file mode 100644 index 0000000000..27b2af87c7 --- /dev/null +++ b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/sourcelanguage/MachoObjcSourceLanguage.java @@ -0,0 +1,40 @@ +/* ### + * 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.app.util.sourcelanguage; + +import java.util.Arrays; + +import ghidra.app.util.bin.format.objc.objc2.Objc2Constants; +import ghidra.app.util.opinion.MachoLoader; +import ghidra.program.model.listing.Program; +import ghidra.program.model.mem.MemoryBlock; +import ghidra.util.task.TaskMonitor; + +/** + * The Mach-O Objective-C {@link SourceLanguage} class + */ +public class MachoObjcSourceLanguage extends ObjcSourceLanguage { + + @Override + public boolean existsIn(Program program, TaskMonitor monitor) { + if (!program.getExecutableFormat().equals(MachoLoader.MACH_O_NAME)) { + return false; + } + return Arrays.stream(program.getMemory().getBlocks()) + .map(MemoryBlock::getName) + .anyMatch(n -> n.startsWith(Objc2Constants.OBJC2_PREFIX)); + } +} diff --git a/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/sourcelanguage/ObjcSourceLanguage.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/sourcelanguage/ObjcSourceLanguage.java new file mode 100644 index 0000000000..483d8247b0 --- /dev/null +++ b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/sourcelanguage/ObjcSourceLanguage.java @@ -0,0 +1,29 @@ +/* ### + * 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.app.util.sourcelanguage; + +/** + * The base Objective-C {@link SourceLanguage} class + */ +public abstract class ObjcSourceLanguage implements SourceLanguage { + + public static final SourceLanguageID OBJC_ID = new SourceLanguageID("Objective-C"); + + @Override + public SourceLanguageID getID() { + return OBJC_ID; + } +} diff --git a/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/sourcelanguage/ObjcSourceLanguageSpecExtension.java b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/sourcelanguage/ObjcSourceLanguageSpecExtension.java new file mode 100644 index 0000000000..df15b2ee09 --- /dev/null +++ b/Ghidra/Features/Objective-C/src/main/java/ghidra/app/util/sourcelanguage/ObjcSourceLanguageSpecExtension.java @@ -0,0 +1,61 @@ +/* ### + * 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.app.util.sourcelanguage; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.List; + +import generic.jar.ResourceFile; +import ghidra.app.util.importer.MessageLog; +import ghidra.framework.Application; +import ghidra.program.database.SpecExtension; +import ghidra.program.model.listing.Program; +import ghidra.util.task.TaskMonitor; + +/** + * Objective-C {@link SpecExtension spec extensions} + */ +public class ObjcSourceLanguageSpecExtension implements SourceLanguageSpecExtension { + + /** + * The Objective-C {@code _objc_msgSend} stub calling convention name + */ + public static final String OBJC_MSGSEND_STUBS = "__objc_msgSend_stub"; + + @Override + public SourceLanguageID getCompatibleSourceLanguage() { + return ObjcSourceLanguage.OBJC_ID; + } + + @Override + public List getSpecExtensionRules(Program program, MessageLog log, + TaskMonitor monitor) { + final String filename = "extensions.json"; + try { + ResourceFile extensionConfigFile = Application.getModuleDataFile(filename); + return SpecExtensionUtils.readSpecExtensionJsonConfig(extensionConfigFile, program, log, + monitor); + } + catch (FileNotFoundException e) { + log.appendMsg("Failed to find module data file: " + filename); + } + catch (IOException e) { + log.appendException(e); + } + return List.of(); + } +} diff --git a/Ghidra/Features/Rust/Module.manifest b/Ghidra/Features/Rust/Module.manifest new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Ghidra/Features/Rust/README.md b/Ghidra/Features/Rust/README.md new file mode 100644 index 0000000000..3e0007b8ee --- /dev/null +++ b/Ghidra/Features/Rust/README.md @@ -0,0 +1,3 @@ +# Rust + +The module provides improved support for binaries written in the Rust programming language. diff --git a/Ghidra/Features/Rust/build.gradle b/Ghidra/Features/Rust/build.gradle new file mode 100644 index 0000000000..76407104ab --- /dev/null +++ b/Ghidra/Features/Rust/build.gradle @@ -0,0 +1,26 @@ +/* ### + * 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. + */ +apply from: "$rootProject.projectDir/gradle/distributableGhidraModule.gradle" +apply from: "$rootProject.projectDir/gradle/javaProject.gradle" +apply from: "$rootProject.projectDir/gradle/javaTestProject.gradle" +apply plugin: 'eclipse' + +eclipse.project.name = 'Features Rust' + +dependencies { + api project(":Base") + api project(":Decompiler") +} diff --git a/Ghidra/Features/Rust/certification.manifest b/Ghidra/Features/Rust/certification.manifest new file mode 100644 index 0000000000..a4608ef9aa --- /dev/null +++ b/Ghidra/Features/Rust/certification.manifest @@ -0,0 +1,17 @@ +##VERSION: 2.0 +##MODULE IP: Apache License 2.0 +Module.manifest||GHIDRA||||END| +README.md||GHIDRA||||END| +data/extensions.json||GHIDRA||||END| +data/extensions/unix32/cc.xml||GHIDRA||||END| +data/extensions/unix32/probe_fixup.xml||GHIDRA||||END| +data/extensions/unix32/try_fixup.xml||GHIDRA||||END| +data/extensions/unix64/cc.xml||GHIDRA||||END| +data/extensions/unix64/probe_fixup.xml||GHIDRA||||END| +data/extensions/unix64/try_fixup.xml||GHIDRA||||END| +data/extensions/windows32/probe_fixup.xml||GHIDRA||||END| +data/extensions/windows32/try_fixup.xml||GHIDRA||||END| +data/extensions/windows64/probe_fixup.xml||GHIDRA||||END| +data/extensions/windows64/try_fixup.xml||GHIDRA||||END| +data/typeinfo/rust-common.gdt||GHIDRA||||END| +data/types.json||GHIDRA||||END| diff --git a/Ghidra/Features/Rust/data/extensions.json b/Ghidra/Features/Rust/data/extensions.json new file mode 100644 index 0000000000..e8e0aff999 --- /dev/null +++ b/Ghidra/Features/Rust/data/extensions.json @@ -0,0 +1,40 @@ +[ + { + "processor": "x86", + "endian": "little", + "size": "32", + "formats": [ + "Mac OS X Mach-O", + "Executable and Linking Format (ELF)" + ], + "directory": "extensions/unix32" + }, + { + "processor": "x86", + "endian": "little", + "size": "64", + "formats": [ + "Mac OS X Mach-O", + "Executable and Linking Format (ELF)" + ], + "directory": "extensions/unix64" + }, + { + "processor": "x86", + "endian": "little", + "size": "32", + "formats": [ + "Portable Executable (PE)" + ], + "directory": "extensions/windows32" + }, + { + "processor": "x86", + "endian": "little", + "size": "64", + "formats": [ + "Portable Executable (PE)" + ], + "directory": "extensions/windows64" + } +] diff --git a/Ghidra/Processors/x86/data/extensions/rust/unix32/cc.xml b/Ghidra/Features/Rust/data/extensions/unix32/cc.xml similarity index 100% rename from Ghidra/Processors/x86/data/extensions/rust/unix32/cc.xml rename to Ghidra/Features/Rust/data/extensions/unix32/cc.xml diff --git a/Ghidra/Processors/x86/data/extensions/rust/unix32/probe_fixup.xml b/Ghidra/Features/Rust/data/extensions/unix32/probe_fixup.xml similarity index 100% rename from Ghidra/Processors/x86/data/extensions/rust/unix32/probe_fixup.xml rename to Ghidra/Features/Rust/data/extensions/unix32/probe_fixup.xml diff --git a/Ghidra/Processors/x86/data/extensions/rust/unix32/try_fixup.xml b/Ghidra/Features/Rust/data/extensions/unix32/try_fixup.xml similarity index 100% rename from Ghidra/Processors/x86/data/extensions/rust/unix32/try_fixup.xml rename to Ghidra/Features/Rust/data/extensions/unix32/try_fixup.xml diff --git a/Ghidra/Processors/x86/data/extensions/rust/unix64/cc.xml b/Ghidra/Features/Rust/data/extensions/unix64/cc.xml similarity index 100% rename from Ghidra/Processors/x86/data/extensions/rust/unix64/cc.xml rename to Ghidra/Features/Rust/data/extensions/unix64/cc.xml diff --git a/Ghidra/Processors/x86/data/extensions/rust/unix64/probe_fixup.xml b/Ghidra/Features/Rust/data/extensions/unix64/probe_fixup.xml similarity index 100% rename from Ghidra/Processors/x86/data/extensions/rust/unix64/probe_fixup.xml rename to Ghidra/Features/Rust/data/extensions/unix64/probe_fixup.xml diff --git a/Ghidra/Processors/x86/data/extensions/rust/unix64/try_fixup.xml b/Ghidra/Features/Rust/data/extensions/unix64/try_fixup.xml similarity index 100% rename from Ghidra/Processors/x86/data/extensions/rust/unix64/try_fixup.xml rename to Ghidra/Features/Rust/data/extensions/unix64/try_fixup.xml diff --git a/Ghidra/Processors/x86/data/extensions/rust/windows32/probe_fixup.xml b/Ghidra/Features/Rust/data/extensions/windows32/probe_fixup.xml similarity index 100% rename from Ghidra/Processors/x86/data/extensions/rust/windows32/probe_fixup.xml rename to Ghidra/Features/Rust/data/extensions/windows32/probe_fixup.xml diff --git a/Ghidra/Processors/x86/data/extensions/rust/windows32/try_fixup.xml b/Ghidra/Features/Rust/data/extensions/windows32/try_fixup.xml similarity index 100% rename from Ghidra/Processors/x86/data/extensions/rust/windows32/try_fixup.xml rename to Ghidra/Features/Rust/data/extensions/windows32/try_fixup.xml diff --git a/Ghidra/Processors/x86/data/extensions/rust/windows64/probe_fixup.xml b/Ghidra/Features/Rust/data/extensions/windows64/probe_fixup.xml similarity index 100% rename from Ghidra/Processors/x86/data/extensions/rust/windows64/probe_fixup.xml rename to Ghidra/Features/Rust/data/extensions/windows64/probe_fixup.xml diff --git a/Ghidra/Processors/x86/data/extensions/rust/windows64/try_fixup.xml b/Ghidra/Features/Rust/data/extensions/windows64/try_fixup.xml similarity index 100% rename from Ghidra/Processors/x86/data/extensions/rust/windows64/try_fixup.xml rename to Ghidra/Features/Rust/data/extensions/windows64/try_fixup.xml diff --git a/Ghidra/Features/Base/data/typeinfo/rust/rust-common.gdt b/Ghidra/Features/Rust/data/typeinfo/rust-common.gdt similarity index 100% rename from Ghidra/Features/Base/data/typeinfo/rust/rust-common.gdt rename to Ghidra/Features/Rust/data/typeinfo/rust-common.gdt diff --git a/Ghidra/Features/Rust/data/types.json b/Ghidra/Features/Rust/data/types.json new file mode 100644 index 0000000000..fd45d4d68e --- /dev/null +++ b/Ghidra/Features/Rust/data/types.json @@ -0,0 +1,5 @@ +[ + { + "file": "typeinfo/rust-common.gdt" + } +] diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/RustConstants.java b/Ghidra/Features/Rust/src/main/java/ghidra/app/plugin/core/analysis/rust/RustConstants.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/RustConstants.java rename to Ghidra/Features/Rust/src/main/java/ghidra/app/plugin/core/analysis/rust/RustConstants.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/RustDemanglerAnalyzer.java b/Ghidra/Features/Rust/src/main/java/ghidra/app/plugin/core/analysis/rust/RustDemanglerAnalyzer.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/RustDemanglerAnalyzer.java rename to Ghidra/Features/Rust/src/main/java/ghidra/app/plugin/core/analysis/rust/RustDemanglerAnalyzer.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/RustStringAnalyzer.java b/Ghidra/Features/Rust/src/main/java/ghidra/app/plugin/core/analysis/rust/RustStringAnalyzer.java similarity index 96% rename from Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/RustStringAnalyzer.java rename to Ghidra/Features/Rust/src/main/java/ghidra/app/plugin/core/analysis/rust/RustStringAnalyzer.java index 9ab182a422..3fca155a41 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/RustStringAnalyzer.java +++ b/Ghidra/Features/Rust/src/main/java/ghidra/app/plugin/core/analysis/rust/RustStringAnalyzer.java @@ -17,6 +17,7 @@ package ghidra.app.plugin.core.analysis.rust; import ghidra.app.services.*; import ghidra.app.util.importer.MessageLog; +import ghidra.app.util.sourcelanguage.RustSourceLanguage; import ghidra.framework.options.Options; import ghidra.program.model.address.*; import ghidra.program.model.data.DataUtilities; @@ -44,8 +45,7 @@ public class RustStringAnalyzer extends AbstractAnalyzer { @Override public boolean canAnalyze(Program program) { - String name = program.getCompiler(); - return name.contains(RustConstants.RUST_COMPILER); + return program.getSourceLanguageIDs().contains(RustSourceLanguage.RUST_ID); } @Override diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemangler.java b/Ghidra/Features/Rust/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemangler.java similarity index 92% rename from Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemangler.java rename to Ghidra/Features/Rust/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemangler.java index c87a41be09..256ee07555 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemangler.java +++ b/Ghidra/Features/Rust/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemangler.java @@ -15,9 +15,9 @@ */ package ghidra.app.plugin.core.analysis.rust.demangler; -import ghidra.app.plugin.core.analysis.rust.RustUtilities; import ghidra.app.util.demangler.*; -import ghidra.program.model.lang.CompilerSpec; +import ghidra.app.util.sourcelanguage.RustSourceLanguage; +import ghidra.app.util.sourcelanguage.RustSourceLanguageSpecExtension; import ghidra.program.model.listing.Program; /** @@ -36,7 +36,7 @@ public class RustDemangler implements Demangler { @Override public boolean canDemangle(Program program) { - return RustUtilities.isRustProgram(program); + return program.getSourceLanguageIDs().contains(RustSourceLanguage.RUST_ID); } @Override @@ -70,7 +70,7 @@ public class RustDemangler implements Demangler { if (options.applyCallingConvention() && demangledObject instanceof DemangledFunction demangledFunction) { - demangledFunction.setCallingConvention(CompilerSpec.CALLING_CONVENTION_rustcall); + demangledFunction.setCallingConvention(RustSourceLanguageSpecExtension.RUSTCALL); } demangledObject.setMangledContext(context); diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerFormat.java b/Ghidra/Features/Rust/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerFormat.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerFormat.java rename to Ghidra/Features/Rust/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerFormat.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerLegacy.java b/Ghidra/Features/Rust/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerLegacy.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerLegacy.java rename to Ghidra/Features/Rust/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerLegacy.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerOptions.java b/Ghidra/Features/Rust/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerOptions.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerOptions.java rename to Ghidra/Features/Rust/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerOptions.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerParser.java b/Ghidra/Features/Rust/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerParser.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerParser.java rename to Ghidra/Features/Rust/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerParser.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerV0.java b/Ghidra/Features/Rust/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerV0.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerV0.java rename to Ghidra/Features/Rust/src/main/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerV0.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/funcfixup/RustDWARFFunctionFixup.java b/Ghidra/Features/Rust/src/main/java/ghidra/app/util/bin/format/dwarf/funcfixup/RustDWARFFunctionFixup.java similarity index 92% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/funcfixup/RustDWARFFunctionFixup.java rename to Ghidra/Features/Rust/src/main/java/ghidra/app/util/bin/format/dwarf/funcfixup/RustDWARFFunctionFixup.java index 871e766455..e9c50714f1 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/funcfixup/RustDWARFFunctionFixup.java +++ b/Ghidra/Features/Rust/src/main/java/ghidra/app/util/bin/format/dwarf/funcfixup/RustDWARFFunctionFixup.java @@ -19,8 +19,8 @@ import java.io.IOException; import ghidra.app.util.bin.format.dwarf.*; import ghidra.app.util.bin.format.dwarf.DWARFFunction.CommitMode; +import ghidra.app.util.sourcelanguage.RustSourceLanguageSpecExtension; import ghidra.program.database.data.ProgramBasedDataTypeManagerDB; -import ghidra.program.model.lang.CompilerSpec; import ghidra.program.model.listing.Program; import ghidra.util.classfinder.ExtensionPointProperties; import ghidra.util.exception.InvalidInputException; @@ -54,12 +54,12 @@ public class RustDWARFFunctionFixup implements DWARFFunctionFixup { private String getRustCC(Program program) throws DWARFException { if (rustCC == null) { - rustCC = CompilerSpec.CALLING_CONVENTION_rustcall; + rustCC = RustSourceLanguageSpecExtension.RUSTCALL; try { // NOTE: this has a side effect of ensuring the rust cc is present in the program ProgramBasedDataTypeManagerDB dtm = (ProgramBasedDataTypeManagerDB) program.getDataTypeManager(); - dtm.getCallingConventionID(CompilerSpec.CALLING_CONVENTION_rustcall, false); + dtm.getCallingConventionID(RustSourceLanguageSpecExtension.RUSTCALL, false); } catch (InvalidInputException | IOException e) { throw new DWARFException("Unable to get Rust calling convention"); diff --git a/Ghidra/Features/Rust/src/main/java/ghidra/app/util/sourcelanguage/ElfRustSourceLanguage.java b/Ghidra/Features/Rust/src/main/java/ghidra/app/util/sourcelanguage/ElfRustSourceLanguage.java new file mode 100644 index 0000000000..015901f8ad --- /dev/null +++ b/Ghidra/Features/Rust/src/main/java/ghidra/app/util/sourcelanguage/ElfRustSourceLanguage.java @@ -0,0 +1,62 @@ +/* ### + * 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.app.util.sourcelanguage; + +import java.io.IOException; +import java.util.regex.Pattern; + +import ghidra.app.util.bin.format.elf.ElfSectionHeaderConstants; +import ghidra.app.util.bin.format.elf.info.ElfComment; +import ghidra.app.util.opinion.ElfLoader; +import ghidra.program.model.listing.Program; +import ghidra.program.model.mem.MemoryBlock; +import ghidra.util.exception.CancelledException; +import ghidra.util.task.TaskMonitor; + +/** + * The Elf Rust {@link SourceLanguage} class + */ +public class ElfRustSourceLanguage extends RustSourceLanguage { + + private static final Pattern ELF_COMMENT_REGEX = Pattern.compile("^rustc version .*$"); + + @Override + public boolean existsIn(Program program, TaskMonitor monitor) + throws IOException, CancelledException { + if (!program.getExecutableFormat().equals(ElfLoader.ELF_NAME)) { + return false; + } + + // ELF binaries can contain a ".comment" section that records the toolchains that + // produced the binary. Search this first as its quick and easy. + ElfComment elfComments = ElfComment.fromProgram(program); + if (elfComments != null) { + for (String s : elfComments.getCommentStrings()) { + if (ELF_COMMENT_REGEX.matcher(s).matches()) { + return true; + } + } + } + + for (MemoryBlock block : program.getMemory().getBlocks()) { + if (block.getName().equals(ElfSectionHeaderConstants.dot_rodata) && + isRust(program, block, monitor)) { + return true; + } + } + return false; + } +} diff --git a/Ghidra/Features/Rust/src/main/java/ghidra/app/util/sourcelanguage/MachoRustSourceLanguage.java b/Ghidra/Features/Rust/src/main/java/ghidra/app/util/sourcelanguage/MachoRustSourceLanguage.java new file mode 100644 index 0000000000..53f033bc92 --- /dev/null +++ b/Ghidra/Features/Rust/src/main/java/ghidra/app/util/sourcelanguage/MachoRustSourceLanguage.java @@ -0,0 +1,48 @@ +/* ### + * 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.app.util.sourcelanguage; + +import java.io.IOException; + +import ghidra.app.util.bin.format.macho.SectionNames; +import ghidra.app.util.bin.format.macho.commands.SegmentNames; +import ghidra.app.util.opinion.MachoLoader; +import ghidra.program.model.listing.Program; +import ghidra.program.model.mem.MemoryBlock; +import ghidra.util.exception.CancelledException; +import ghidra.util.task.TaskMonitor; + +/** + * The Mach-O Rust {@link SourceLanguage} class + */ +public class MachoRustSourceLanguage extends RustSourceLanguage { + + @Override + public boolean existsIn(Program program, TaskMonitor monitor) + throws IOException, CancelledException { + if (!program.getExecutableFormat().equals(MachoLoader.MACH_O_NAME)) { + return false; + } + for (MemoryBlock block : program.getMemory().getBlocks()) { + if (block.getName().equals(SectionNames.TEXT_CONST) && + block.getComment().equals(SegmentNames.SEG_TEXT) && + isRust(program, block, monitor)) { + return true; + } + } + return false; + } +} diff --git a/Ghidra/Features/Rust/src/main/java/ghidra/app/util/sourcelanguage/PeRustSourceLanguage.java b/Ghidra/Features/Rust/src/main/java/ghidra/app/util/sourcelanguage/PeRustSourceLanguage.java new file mode 100644 index 0000000000..fdbf3e53b5 --- /dev/null +++ b/Ghidra/Features/Rust/src/main/java/ghidra/app/util/sourcelanguage/PeRustSourceLanguage.java @@ -0,0 +1,45 @@ +/* ### + * 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.app.util.sourcelanguage; + +import java.io.IOException; + +import ghidra.app.util.opinion.PeLoader; +import ghidra.program.model.listing.Program; +import ghidra.program.model.mem.MemoryBlock; +import ghidra.util.exception.CancelledException; +import ghidra.util.task.TaskMonitor; + +/** + * The PE Rust {@link SourceLanguage} class + */ +public class PeRustSourceLanguage extends RustSourceLanguage { + + @Override + public boolean existsIn(Program program, TaskMonitor monitor) + throws IOException, CancelledException { + if (!program.getExecutableFormat().equals(PeLoader.PE_NAME)) { + return false; + } + for (MemoryBlock block : program.getMemory().getBlocks()) { + if (block.getName().equals(".rdata") && + isRust(program, block, monitor)) { + return true; + } + } + return false; + } +} diff --git a/Ghidra/Features/Rust/src/main/java/ghidra/app/util/sourcelanguage/RustSourceLanguage.java b/Ghidra/Features/Rust/src/main/java/ghidra/app/util/sourcelanguage/RustSourceLanguage.java new file mode 100644 index 0000000000..52da3e1079 --- /dev/null +++ b/Ghidra/Features/Rust/src/main/java/ghidra/app/util/sourcelanguage/RustSourceLanguage.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.app.util.sourcelanguage; + +import java.io.IOException; +import java.util.concurrent.atomic.AtomicBoolean; + +import ghidra.app.plugin.core.analysis.rust.RustConstants; +import ghidra.program.model.address.Address; +import ghidra.program.model.address.AddressSet; +import ghidra.program.model.listing.Program; +import ghidra.program.model.mem.MemoryBlock; +import ghidra.util.bytesearch.*; +import ghidra.util.exception.CancelledException; +import ghidra.util.task.TaskMonitor; + +/** + * The base Rust {@link SourceLanguage} class + */ +public abstract class RustSourceLanguage implements SourceLanguage { + + public static final SourceLanguageID RUST_ID = new SourceLanguageID("Rust"); + + @Override + public SourceLanguageID getID() { + return RUST_ID; + } + + /** + * Checks if the specified program contains Rust stuff, either by metadata or by searching + * the specified {@link MemoryBlock} for byte pattern signatures. + *

+ * This may be used by loaders to determine if a program was compiled with rust. + * If the program is determined to be rust, then the compiler property is set to + * {@link RustConstants#RUST_COMPILER}. + * + * @param program The {@link Program} + * @param block The {@link MemoryBlock} to scan for Rust signatures + * @param monitor The monitor + * @return True if the given {@link MemoryBlock} is not null and contains a Rust signature; + * otherwise, false + * @throws IOException if there was an IO-related error + * @throws CancelledException if the user cancelled the operation + */ + public boolean isRust(Program program, MemoryBlock block, TaskMonitor monitor) + throws IOException, CancelledException { + + if (block == null) { + return false; + } + + // Use a MemoryBytePatternSearch for more efficient byte searching over a list of potential + // byte signatures. The below action sets our supplied boolean to true on a match, which we + // can later query and use as a return value for this method. + GenericMatchAction action = + new GenericMatchAction(new AtomicBoolean()) { + @Override + public void apply(Program prog, Address addr, Match match) { + getMatchValue().set(true); + } + }; + MemoryBytePatternSearcher searcher = new MemoryBytePatternSearcher("Rust signatures"); + for (byte[] sig : RustConstants.RUST_SIGNATURES) { + searcher.addPattern(new GenericByteSequencePattern(sig, action)); + } + + searcher.search(program, new AddressSet(block.getAddressRange()), monitor); + + return action.getMatchValue().get(); + } +} diff --git a/Ghidra/Features/Rust/src/main/java/ghidra/app/util/sourcelanguage/RustSourceLanguageDataArchive.java b/Ghidra/Features/Rust/src/main/java/ghidra/app/util/sourcelanguage/RustSourceLanguageDataArchive.java new file mode 100644 index 0000000000..2afc4d583e --- /dev/null +++ b/Ghidra/Features/Rust/src/main/java/ghidra/app/util/sourcelanguage/RustSourceLanguageDataArchive.java @@ -0,0 +1,55 @@ +/* ### + * 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.app.util.sourcelanguage; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.List; + +import generic.jar.ResourceFile; +import ghidra.app.util.importer.MessageLog; +import ghidra.framework.Application; +import ghidra.program.model.listing.Program; +import ghidra.util.task.TaskMonitor; + +/** + * Rust data archives + */ +public class RustSourceLanguageDataArchive implements SourceLanguageDataArchive { + + @Override + public SourceLanguageID getCompatibleSourceLanguage() { + return RustSourceLanguage.RUST_ID; + } + + @Override + public List getDataArchiveRules(Program program, MessageLog log, + TaskMonitor monitor) { + final String filename = "types.json"; + try { + ResourceFile dataArchiveConfileFile = Application.getModuleDataFile(filename); + return DataArchiveUtils.readDataArchiveJsonConfig(dataArchiveConfileFile, program, log, + monitor); + } + catch (FileNotFoundException e) { + log.appendMsg("Failed to find module data file: " + filename); + } + catch (IOException e) { + log.appendException(e); + } + return List.of(); + } +} diff --git a/Ghidra/Features/Rust/src/main/java/ghidra/app/util/sourcelanguage/RustSourceLanguageSpecExtension.java b/Ghidra/Features/Rust/src/main/java/ghidra/app/util/sourcelanguage/RustSourceLanguageSpecExtension.java new file mode 100644 index 0000000000..0b1f67eccb --- /dev/null +++ b/Ghidra/Features/Rust/src/main/java/ghidra/app/util/sourcelanguage/RustSourceLanguageSpecExtension.java @@ -0,0 +1,61 @@ +/* ### + * 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.app.util.sourcelanguage; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.List; + +import generic.jar.ResourceFile; +import ghidra.app.util.importer.MessageLog; +import ghidra.framework.Application; +import ghidra.program.database.SpecExtension; +import ghidra.program.model.listing.Program; +import ghidra.util.task.TaskMonitor; + +/** + * Rust {@link SpecExtension spec extensions} + */ +public class RustSourceLanguageSpecExtension implements SourceLanguageSpecExtension { + + /** + * The Rust calling convention defined in the spec extension + */ + public static final String RUSTCALL = "__rustcall"; + + @Override + public SourceLanguageID getCompatibleSourceLanguage() { + return RustSourceLanguage.RUST_ID; + } + + @Override + public List getSpecExtensionRules(Program program, MessageLog log, + TaskMonitor monitor) { + final String filename = "extensions.json"; + try { + ResourceFile extensionConfigFile = Application.getModuleDataFile(filename); + return SpecExtensionUtils.readSpecExtensionJsonConfig(extensionConfigFile, program, log, + monitor); + } + catch (FileNotFoundException e) { + log.appendMsg("Failed to find module data file: " + filename); + } + catch (IOException e) { + log.appendException(e); + } + return List.of(); + } +} diff --git a/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerLegacyTest.java b/Ghidra/Features/Rust/src/test/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerLegacyTest.java similarity index 95% rename from Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerLegacyTest.java rename to Ghidra/Features/Rust/src/test/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerLegacyTest.java index ca40f1b8ed..56d3ec8915 100644 --- a/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerLegacyTest.java +++ b/Ghidra/Features/Rust/src/test/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerLegacyTest.java @@ -21,11 +21,11 @@ import org.junit.Test; import ghidra.app.util.demangler.DemangledException; import ghidra.app.util.demangler.DemangledObject; -import ghidra.program.model.lang.CompilerSpec; +import ghidra.app.util.sourcelanguage.RustSourceLanguageSpecExtension; public class RustDemanglerLegacyTest { - private static final String RUSTCALL = CompilerSpec.CALLING_CONVENTION_rustcall; + private static final String RUSTCALL = RustSourceLanguageSpecExtension.RUSTCALL; private static String[] symbols = { "_ZN43_$LT$char$u20$as$u20$core..fmt..Display$GT$3fmt17h31c4c24bbd08aa24E", diff --git a/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerV0Test.java b/Ghidra/Features/Rust/src/test/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerV0Test.java similarity index 100% rename from Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerV0Test.java rename to Ghidra/Features/Rust/src/test/java/ghidra/app/plugin/core/analysis/rust/demangler/RustDemanglerV0Test.java diff --git a/Ghidra/Features/Swift/Module.manifest b/Ghidra/Features/Swift/Module.manifest new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Ghidra/Features/SwiftDemangler/README.md b/Ghidra/Features/Swift/README.md similarity index 100% rename from Ghidra/Features/SwiftDemangler/README.md rename to Ghidra/Features/Swift/README.md diff --git a/Ghidra/Features/SwiftDemangler/build.gradle b/Ghidra/Features/Swift/build.gradle similarity index 94% rename from Ghidra/Features/SwiftDemangler/build.gradle rename to Ghidra/Features/Swift/build.gradle index 71ba191112..c69ae587be 100644 --- a/Ghidra/Features/SwiftDemangler/build.gradle +++ b/Ghidra/Features/Swift/build.gradle @@ -4,9 +4,9 @@ * 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. @@ -19,7 +19,7 @@ apply from: "$rootProject.projectDir/gradle/jacocoProject.gradle" apply from: "$rootProject.projectDir/gradle/javaTestProject.gradle" apply plugin: 'eclipse' -eclipse.project.name = 'Features SwiftDemangler' +eclipse.project.name = 'Features Swift' dependencies { api project(":Base") diff --git a/Ghidra/Features/Swift/certification.manifest b/Ghidra/Features/Swift/certification.manifest new file mode 100644 index 0000000000..d2aa9bf5d8 --- /dev/null +++ b/Ghidra/Features/Swift/certification.manifest @@ -0,0 +1,8 @@ +##VERSION: 2.0 +Module.manifest||GHIDRA||||END| +README.md||GHIDRA||||END| +data/extensions.json||GHIDRA||||END| +data/extensions/aarch64/swift_stdcall.xml||GHIDRA||||END| +data/extensions/aarch64/swift_thiscall.xml||GHIDRA||||END| +data/extensions/x86_64/swift_stdcall.xml||GHIDRA||||END| +data/extensions/x86_64/swift_thiscall.xml||GHIDRA||||END| diff --git a/Ghidra/Features/Swift/data/extensions.json b/Ghidra/Features/Swift/data/extensions.json new file mode 100644 index 0000000000..b7cef154e6 --- /dev/null +++ b/Ghidra/Features/Swift/data/extensions.json @@ -0,0 +1,14 @@ +[ + { + "processor": "AARCH64", + "endian": "little", + "size": "64", + "directory": "extensions/aarch64" + }, + { + "processor": "x86", + "endian": "little", + "size": "64", + "directory": "extensions/x86_64" + } +] diff --git a/Ghidra/Features/Swift/data/extensions/aarch64/swift_stdcall.xml b/Ghidra/Features/Swift/data/extensions/aarch64/swift_stdcall.xml new file mode 100644 index 0000000000..32a88e6499 --- /dev/null +++ b/Ghidra/Features/Swift/data/extensions/aarch64/swift_stdcall.xml @@ -0,0 +1,161 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Ghidra/Features/Swift/data/extensions/aarch64/swift_thiscall.xml b/Ghidra/Features/Swift/data/extensions/aarch64/swift_thiscall.xml new file mode 100644 index 0000000000..1a0130a647 --- /dev/null +++ b/Ghidra/Features/Swift/data/extensions/aarch64/swift_thiscall.xml @@ -0,0 +1,163 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Ghidra/Features/Swift/data/extensions/x86_64/swift_stdcall.xml b/Ghidra/Features/Swift/data/extensions/x86_64/swift_stdcall.xml new file mode 100644 index 0000000000..1021f7b980 --- /dev/null +++ b/Ghidra/Features/Swift/data/extensions/x86_64/swift_stdcall.xml @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Ghidra/Features/Swift/data/extensions/x86_64/swift_thiscall.xml b/Ghidra/Features/Swift/data/extensions/x86_64/swift_thiscall.xml new file mode 100644 index 0000000000..45c6333960 --- /dev/null +++ b/Ghidra/Features/Swift/data/extensions/x86_64/swift_thiscall.xml @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Ghidra/Features/SwiftDemangler/ghidra_scripts/SwiftDemanglerScript.java b/Ghidra/Features/Swift/ghidra_scripts/SwiftDemanglerScript.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/ghidra_scripts/SwiftDemanglerScript.java rename to Ghidra/Features/Swift/ghidra_scripts/SwiftDemanglerScript.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/plugin/core/analysis/SwiftDemanglerAnalyzer.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/plugin/core/analysis/SwiftDemanglerAnalyzer.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/plugin/core/analysis/SwiftDemanglerAnalyzer.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/plugin/core/analysis/SwiftDemanglerAnalyzer.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/SwiftTypeMetadataAnalyzer.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/plugin/core/analysis/SwiftTypeMetadataAnalyzer.java similarity index 92% rename from Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/SwiftTypeMetadataAnalyzer.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/plugin/core/analysis/SwiftTypeMetadataAnalyzer.java index fef5b75c75..e5147b3797 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/SwiftTypeMetadataAnalyzer.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/plugin/core/analysis/SwiftTypeMetadataAnalyzer.java @@ -4,9 +4,9 @@ * 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. @@ -19,8 +19,8 @@ import java.io.IOException; import ghidra.app.services.*; import ghidra.app.util.bin.format.swift.SwiftTypeMetadata; -import ghidra.app.util.bin.format.swift.SwiftUtils; import ghidra.app.util.importer.MessageLog; +import ghidra.app.util.sourcelanguage.SwiftSourceLanguage; import ghidra.program.model.address.AddressSetView; import ghidra.program.model.listing.Program; import ghidra.util.exception.CancelledException; @@ -41,7 +41,7 @@ public class SwiftTypeMetadataAnalyzer extends AbstractAnalyzer { @Override public boolean canAnalyze(Program program) { - return SwiftUtils.isSwift(program); + return program.getSourceLanguageIDs().contains(SwiftSourceLanguage.SWIFT_ID); } @Override diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/SwiftSection.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/SwiftSection.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/SwiftSection.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/SwiftSection.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/SwiftTypeMetadata.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/SwiftTypeMetadata.java similarity index 97% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/SwiftTypeMetadata.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/SwiftTypeMetadata.java index 55e21a3bba..3aade3a562 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/SwiftTypeMetadata.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/SwiftTypeMetadata.java @@ -168,7 +168,7 @@ public class SwiftTypeMetadata { throws CancelledException { monitor.setMessage("Parsing Swift entry point(s)..."); monitor.setIndeterminate(true); - for (MemoryBlock block : SwiftUtils.getSwiftBlocks(section, program)) { + for (MemoryBlock block : SwiftTypeMetadataUtils.getSwiftBlocks(section, program)) { monitor.checkCancelled(); Address blockStart = block.getStart(); try { @@ -196,7 +196,7 @@ public class SwiftTypeMetadata { monitor.setMessage("Parsing Swift builtin type descriptors..."); monitor.setIndeterminate(true); try { - for (MemoryBlock block : SwiftUtils.getSwiftBlocks(section, program)) { + for (MemoryBlock block : SwiftTypeMetadataUtils.getSwiftBlocks(section, program)) { Address blockStart = block.getStart(); reader.setPointerIndex(blockStart.getOffset()); int i = skipZeroEntries(reader, 0, block.getSize()); @@ -228,7 +228,7 @@ public class SwiftTypeMetadata { monitor.setMessage("Parsing Swift field descriptors..."); monitor.setIndeterminate(true); try { - for (MemoryBlock block : SwiftUtils.getSwiftBlocks(section, program)) { + for (MemoryBlock block : SwiftTypeMetadataUtils.getSwiftBlocks(section, program)) { Address blockStart = block.getStart(); reader.setPointerIndex(blockStart.getOffset()); int i = skipZeroEntries(reader, 0, block.getSize()); @@ -268,7 +268,7 @@ public class SwiftTypeMetadata { monitor.setMessage("Parsing Swift associated type descriptors..."); monitor.setIndeterminate(true); try { - for (MemoryBlock block : SwiftUtils.getSwiftBlocks(section, program)) { + for (MemoryBlock block : SwiftTypeMetadataUtils.getSwiftBlocks(section, program)) { Address blockStart = block.getStart(); reader.setPointerIndex(blockStart.getOffset()); int i = skipZeroEntries(reader, 0, block.getSize()); @@ -308,7 +308,7 @@ public class SwiftTypeMetadata { monitor.setMessage("Parsing Swift capture descriptors..."); monitor.setIndeterminate(true); try { - for (MemoryBlock block : SwiftUtils.getSwiftBlocks(section, program)) { + for (MemoryBlock block : SwiftTypeMetadataUtils.getSwiftBlocks(section, program)) { Address blockStart = block.getStart(); reader.setPointerIndex(blockStart.getOffset()); int i = skipZeroEntries(reader, 0, block.getSize()); @@ -357,7 +357,7 @@ public class SwiftTypeMetadata { monitor.setMessage("Parsing Swift multipayload enum descriptors..."); monitor.setIndeterminate(true); try { - for (MemoryBlock block : SwiftUtils.getSwiftBlocks(section, program)) { + for (MemoryBlock block : SwiftTypeMetadataUtils.getSwiftBlocks(section, program)) { Address blockStart = block.getStart(); reader.setPointerIndex(blockStart.getOffset()); int i = skipZeroEntries(reader, 0, block.getSize()); @@ -492,7 +492,7 @@ public class SwiftTypeMetadata { monitor.setMessage("Parsing Swift protocol conformance descriptors..."); monitor.setIndeterminate(true); try { - for (MemoryBlock block : SwiftUtils.getSwiftBlocks(section, program)) { + for (MemoryBlock block : SwiftTypeMetadataUtils.getSwiftBlocks(section, program)) { Address blockAddr = block.getStart(); for (int i = 0; i < block.getSize(); i += POINTER_SIZE) { monitor.checkCancelled(); diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/SwiftTypeMetadataStructure.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/SwiftTypeMetadataStructure.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/SwiftTypeMetadataStructure.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/SwiftTypeMetadataStructure.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/SwiftUtils.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/SwiftTypeMetadataUtils.java similarity index 73% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/SwiftUtils.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/SwiftTypeMetadataUtils.java index dc43e0ae4e..0f01e775fb 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/SwiftUtils.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/SwiftTypeMetadataUtils.java @@ -27,9 +27,7 @@ import ghidra.program.model.mem.MemoryBlock; /** * Swift-related utility methods */ -public class SwiftUtils { - - public static final String SWIFT_COMPILER = "swift"; +public class SwiftTypeMetadataUtils { /** * A {@link TypeDef pointer} to a relative 4-byte offset @@ -54,37 +52,6 @@ public class SwiftUtils { public static final PointerTypedef PTR_STRING = new PointerTypedef(null, StringDataType.dataType, 4, null, PointerType.RELATIVE); - /** - * {@return true if the given {@link Program} is a Swift program; otherwise, false} - * - * @param program The {@link Program} to check - */ - public static boolean isSwift(Program program) { - List prefixes = List.of("__swift", "swift", ".sw5"); - for (MemoryBlock block : program.getMemory().getBlocks()) { - if (prefixes.stream().anyMatch(prefix -> block.getName().startsWith(prefix))) { - return true; - } - } - return false; - } - - /** - * {@return true if the given {@link List} of section names contains a Swift section name; - * otherwise, false} - * - * @param sectionNames The {@link List} of section names to check - */ - public static boolean isSwift(List sectionNames) { - List prefixes = List.of("__swift", "swift", ".sw5"); - for (String sectionName : sectionNames) { - if (prefixes.stream().anyMatch(prefix -> sectionName.startsWith(prefix))) { - return true; - } - } - return false; - } - /** * {@return a {@link List} of {@link MemoryBlock}s that match the given {@link SwiftSection}} * diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/AssociatedTypeDescriptor.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/AssociatedTypeDescriptor.java similarity index 90% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/AssociatedTypeDescriptor.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/AssociatedTypeDescriptor.java index 96e9c58575..13b2836fa7 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/AssociatedTypeDescriptor.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/AssociatedTypeDescriptor.java @@ -21,7 +21,7 @@ import java.util.List; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.DataType; import ghidra.program.model.data.StructureDataType; import ghidra.util.exception.DuplicateNameException; @@ -53,8 +53,8 @@ public final class AssociatedTypeDescriptor extends SwiftTypeMetadataStructure { */ public AssociatedTypeDescriptor(BinaryReader reader) throws IOException { super(reader.getPointerIndex()); - conformingTypeName = reader.readNext(SwiftUtils::relativeString); - protocolTypeName = reader.readNext(SwiftUtils::relativeString); + conformingTypeName = reader.readNext(SwiftTypeMetadataUtils::relativeString); + protocolTypeName = reader.readNext(SwiftTypeMetadataUtils::relativeString); numAssociatedTypes = reader.readNextInt(); associatedTypeRecordSize = reader.readNextInt(); @@ -111,8 +111,8 @@ public final class AssociatedTypeDescriptor extends SwiftTypeMetadataStructure { @Override public DataType toDataType() throws DuplicateNameException, IOException { StructureDataType struct = new StructureDataType(CATEGORY_PATH, getStructureName(), 0); - struct.add(SwiftUtils.PTR_STRING, "ConformingTypeName", ""); - struct.add(SwiftUtils.PTR_STRING, "ProtocolTypeName", ""); + struct.add(SwiftTypeMetadataUtils.PTR_STRING, "ConformingTypeName", ""); + struct.add(SwiftTypeMetadataUtils.PTR_STRING, "ProtocolTypeName", ""); struct.add(DWORD, "NumAssociatedTypes", ""); struct.add(DWORD, "AssociatedTypeRecordSize", ""); return struct; diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/AssociatedTypeRecord.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/AssociatedTypeRecord.java similarity index 86% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/AssociatedTypeRecord.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/AssociatedTypeRecord.java index 130d9e4992..62cba3c6cb 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/AssociatedTypeRecord.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/AssociatedTypeRecord.java @@ -19,7 +19,7 @@ import java.io.IOException; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.DataType; import ghidra.program.model.data.StructureDataType; import ghidra.util.exception.DuplicateNameException; @@ -47,8 +47,8 @@ public final class AssociatedTypeRecord extends SwiftTypeMetadataStructure { */ public AssociatedTypeRecord(BinaryReader reader) throws IOException { super(reader.getPointerIndex()); - name = reader.readNext(SwiftUtils::relativeString); - substitutedTypeName = reader.readNext(SwiftUtils::relativeString); + name = reader.readNext(SwiftTypeMetadataUtils::relativeString); + substitutedTypeName = reader.readNext(SwiftTypeMetadataUtils::relativeString); } /** @@ -78,8 +78,8 @@ public final class AssociatedTypeRecord extends SwiftTypeMetadataStructure { @Override public DataType toDataType() throws DuplicateNameException, IOException { StructureDataType struct = new StructureDataType(CATEGORY_PATH, getStructureName(), 0); - struct.add(SwiftUtils.PTR_STRING, "Name", ""); - struct.add(SwiftUtils.PTR_STRING, "SubstitutedTypeName", ""); + struct.add(SwiftTypeMetadataUtils.PTR_STRING, "Name", ""); + struct.add(SwiftTypeMetadataUtils.PTR_STRING, "SubstitutedTypeName", ""); return struct; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/BuiltinTypeDescriptor.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/BuiltinTypeDescriptor.java similarity index 93% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/BuiltinTypeDescriptor.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/BuiltinTypeDescriptor.java index a52c2f2650..b1c7889c7f 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/BuiltinTypeDescriptor.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/BuiltinTypeDescriptor.java @@ -19,7 +19,7 @@ import java.io.IOException; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.DataType; import ghidra.program.model.data.StructureDataType; import ghidra.util.exception.DuplicateNameException; @@ -50,7 +50,7 @@ public final class BuiltinTypeDescriptor extends SwiftTypeMetadataStructure { */ public BuiltinTypeDescriptor(BinaryReader reader) throws IOException { super(reader.getPointerIndex()); - typeName = reader.readNext(SwiftUtils::relativeString); + typeName = reader.readNext(SwiftTypeMetadataUtils::relativeString); size = reader.readNextInt(); alignmentAndFlags = reader.readNextInt(); stride = reader.readNextInt(); @@ -105,7 +105,7 @@ public final class BuiltinTypeDescriptor extends SwiftTypeMetadataStructure { @Override public DataType toDataType() throws DuplicateNameException, IOException { StructureDataType struct = new StructureDataType(CATEGORY_PATH, getStructureName(), 0); - struct.add(SwiftUtils.PTR_STRING, "TypeName", ""); + struct.add(SwiftTypeMetadataUtils.PTR_STRING, "TypeName", ""); struct.add(DWORD, "Size", ""); struct.add(DWORD, "AlignmentAndFlags", ""); struct.add(DWORD, "Stride", ""); diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/CaptureDescriptor.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/CaptureDescriptor.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/CaptureDescriptor.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/CaptureDescriptor.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/CaptureTypeRecord.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/CaptureTypeRecord.java similarity index 91% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/CaptureTypeRecord.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/CaptureTypeRecord.java index 8a2659929e..70df2c5b0f 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/CaptureTypeRecord.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/CaptureTypeRecord.java @@ -19,7 +19,7 @@ import java.io.IOException; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.DataType; import ghidra.program.model.data.StructureDataType; import ghidra.util.exception.DuplicateNameException; @@ -46,7 +46,7 @@ public final class CaptureTypeRecord extends SwiftTypeMetadataStructure { */ public CaptureTypeRecord(BinaryReader reader) throws IOException { super(reader.getPointerIndex()); - mangledTypeName = reader.readNext(SwiftUtils::relativeString); + mangledTypeName = reader.readNext(SwiftTypeMetadataUtils::relativeString); } @@ -70,7 +70,7 @@ public final class CaptureTypeRecord extends SwiftTypeMetadataStructure { @Override public DataType toDataType() throws DuplicateNameException, IOException { StructureDataType struct = new StructureDataType(CATEGORY_PATH, getStructureName(), 0); - struct.add(SwiftUtils.PTR_STRING, "MangledTypeName", ""); + struct.add(SwiftTypeMetadataUtils.PTR_STRING, "MangledTypeName", ""); return struct; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/ConformanceFlags.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/ConformanceFlags.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/ConformanceFlags.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/ConformanceFlags.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/ContextDescriptorFlags.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/ContextDescriptorFlags.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/ContextDescriptorFlags.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/ContextDescriptorFlags.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/ContextDescriptorKind.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/ContextDescriptorKind.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/ContextDescriptorKind.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/ContextDescriptorKind.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/EntryPoint.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/EntryPoint.java similarity index 94% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/EntryPoint.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/EntryPoint.java index 78d41cd13e..19aea48e09 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/EntryPoint.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/EntryPoint.java @@ -19,7 +19,7 @@ import java.io.IOException; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.DataType; import ghidra.util.exception.DuplicateNameException; @@ -65,7 +65,7 @@ public final class EntryPoint extends SwiftTypeMetadataStructure { @Override public DataType toDataType() throws DuplicateNameException, IOException { - return SwiftUtils.PTR_RELATIVE; + return SwiftTypeMetadataUtils.PTR_RELATIVE; } } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/ExtraClassDescriptorFlags.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/ExtraClassDescriptorFlags.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/ExtraClassDescriptorFlags.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/ExtraClassDescriptorFlags.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/FieldDescriptor.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/FieldDescriptor.java similarity index 92% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/FieldDescriptor.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/FieldDescriptor.java index f05afab422..3ae92dced7 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/FieldDescriptor.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/FieldDescriptor.java @@ -21,7 +21,7 @@ import java.util.List; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.DataType; import ghidra.program.model.data.StructureDataType; import ghidra.util.exception.DuplicateNameException; @@ -54,7 +54,7 @@ public final class FieldDescriptor extends SwiftTypeMetadataStructure { */ public FieldDescriptor(BinaryReader reader) throws IOException { super(reader.getPointerIndex()); - mangledTypeName = reader.readNext(SwiftUtils::relativeString); + mangledTypeName = reader.readNext(SwiftTypeMetadataUtils::relativeString); superclass = reader.readNextInt(); kind = reader.readNextUnsignedShort(); fieldRecordSize = reader.readNextUnsignedShort(); @@ -120,8 +120,8 @@ public final class FieldDescriptor extends SwiftTypeMetadataStructure { @Override public DataType toDataType() throws DuplicateNameException, IOException { StructureDataType struct = new StructureDataType(CATEGORY_PATH, getStructureName(), 0); - struct.add(SwiftUtils.PTR_STRING, "MangledTypeName", ""); - struct.add(SwiftUtils.PTR_RELATIVE, "Superclass", ""); + struct.add(SwiftTypeMetadataUtils.PTR_STRING, "MangledTypeName", ""); + struct.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "Superclass", ""); struct.add(WORD, "Kind", ""); struct.add(WORD, "FieldRecordSize", ""); struct.add(DWORD, "NumFields", ""); diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/FieldRecord.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/FieldRecord.java similarity index 87% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/FieldRecord.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/FieldRecord.java index e4c6511bda..86ca4835f7 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/FieldRecord.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/FieldRecord.java @@ -19,7 +19,7 @@ import java.io.IOException; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.DataType; import ghidra.program.model.data.StructureDataType; import ghidra.util.exception.DuplicateNameException; @@ -49,8 +49,8 @@ public final class FieldRecord extends SwiftTypeMetadataStructure { public FieldRecord(BinaryReader reader) throws IOException { super(reader.getPointerIndex()); flags = reader.readNextInt(); - mangledTypeName = reader.readNext(SwiftUtils::relativeString); - fieldName = reader.readNext(SwiftUtils::relativeString); + mangledTypeName = reader.readNext(SwiftTypeMetadataUtils::relativeString); + fieldName = reader.readNext(SwiftTypeMetadataUtils::relativeString); } /** @@ -88,8 +88,8 @@ public final class FieldRecord extends SwiftTypeMetadataStructure { public DataType toDataType() throws DuplicateNameException, IOException { StructureDataType struct = new StructureDataType(CATEGORY_PATH, getStructureName(), 0); struct.add(DWORD, "Flags", ""); - struct.add(SwiftUtils.PTR_STRING, "MangledTypeName", ""); - struct.add(SwiftUtils.PTR_STRING, "FieldName", ""); + struct.add(SwiftTypeMetadataUtils.PTR_STRING, "MangledTypeName", ""); + struct.add(SwiftTypeMetadataUtils.PTR_STRING, "FieldName", ""); return struct; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/GenericContextDescriptorFlags.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/GenericContextDescriptorFlags.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/GenericContextDescriptorFlags.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/GenericContextDescriptorFlags.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/GenericParamDescriptor.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/GenericParamDescriptor.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/GenericParamDescriptor.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/GenericParamDescriptor.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/GenericParamKind.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/GenericParamKind.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/GenericParamKind.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/GenericParamKind.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/GenericRequirementFlags.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/GenericRequirementFlags.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/GenericRequirementFlags.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/GenericRequirementFlags.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/GenericRequirementKind.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/GenericRequirementKind.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/GenericRequirementKind.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/GenericRequirementKind.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/GenericRequirementLayoutKind.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/GenericRequirementLayoutKind.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/GenericRequirementLayoutKind.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/GenericRequirementLayoutKind.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/InvertibleProtocolKind.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/InvertibleProtocolKind.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/InvertibleProtocolKind.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/InvertibleProtocolKind.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/InvertibleProtocolSet.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/InvertibleProtocolSet.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/InvertibleProtocolSet.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/InvertibleProtocolSet.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/MetadataInitializationKind.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/MetadataInitializationKind.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/MetadataInitializationKind.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/MetadataInitializationKind.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/MetadataSourceRecord.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/MetadataSourceRecord.java similarity index 86% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/MetadataSourceRecord.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/MetadataSourceRecord.java index 7e42a69ebc..c16f3b188d 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/MetadataSourceRecord.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/MetadataSourceRecord.java @@ -19,7 +19,7 @@ import java.io.IOException; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.DataType; import ghidra.program.model.data.StructureDataType; import ghidra.util.exception.DuplicateNameException; @@ -47,8 +47,8 @@ public final class MetadataSourceRecord extends SwiftTypeMetadataStructure { */ public MetadataSourceRecord(BinaryReader reader) throws IOException { super(reader.getPointerIndex()); - mangledTypeName = reader.readNext(SwiftUtils::relativeString); - mangledMetadataSource = reader.readNext(SwiftUtils::relativeString); + mangledTypeName = reader.readNext(SwiftTypeMetadataUtils::relativeString); + mangledMetadataSource = reader.readNext(SwiftTypeMetadataUtils::relativeString); } /** @@ -78,8 +78,8 @@ public final class MetadataSourceRecord extends SwiftTypeMetadataStructure { @Override public DataType toDataType() throws DuplicateNameException, IOException { StructureDataType struct = new StructureDataType(CATEGORY_PATH, getStructureName(), 0); - struct.add(SwiftUtils.PTR_STRING, "MangledTypeName", ""); - struct.add(SwiftUtils.PTR_STRING, "MangledMetadataSource", ""); + struct.add(SwiftTypeMetadataUtils.PTR_STRING, "MangledTypeName", ""); + struct.add(SwiftTypeMetadataUtils.PTR_STRING, "MangledMetadataSource", ""); return struct; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/MethodDescriptorFlags.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/MethodDescriptorFlags.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/MethodDescriptorFlags.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/MethodDescriptorFlags.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/MethodDescriptorKind.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/MethodDescriptorKind.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/MethodDescriptorKind.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/MethodDescriptorKind.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/MultiPayloadEnumDescriptor.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/MultiPayloadEnumDescriptor.java similarity index 93% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/MultiPayloadEnumDescriptor.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/MultiPayloadEnumDescriptor.java index 09e9bae54d..dcf9fdb495 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/MultiPayloadEnumDescriptor.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/MultiPayloadEnumDescriptor.java @@ -19,7 +19,7 @@ import java.io.IOException; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.DataType; import ghidra.util.exception.DuplicateNameException; @@ -54,7 +54,7 @@ public final class MultiPayloadEnumDescriptor extends SwiftTypeMetadataStructure */ public MultiPayloadEnumDescriptor(BinaryReader reader) throws IOException { super(reader.getPointerIndex()); - typeName = reader.readNext(SwiftUtils::relativeString); + typeName = reader.readNext(SwiftTypeMetadataUtils::relativeString); int size = (reader.readNextInt() >> 16) & 0xffff; reader.setPointerIndex(reader.getPointerIndex() - 4); contents = reader.readNextIntArray(size); @@ -92,7 +92,7 @@ public final class MultiPayloadEnumDescriptor extends SwiftTypeMetadataStructure public static int peekContentsSize(BinaryReader reader) throws IOException { long origIndex = reader.getPointerIndex(); try { - reader.readNext(SwiftUtils::relativeString); + reader.readNext(SwiftTypeMetadataUtils::relativeString); return (reader.readNextInt() >> 16) & 0xffff; } finally { @@ -112,6 +112,6 @@ public final class MultiPayloadEnumDescriptor extends SwiftTypeMetadataStructure @Override public DataType toDataType() throws DuplicateNameException, IOException { - return SwiftUtils.PTR_STRING; + return SwiftTypeMetadataUtils.PTR_STRING; } } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/ProtocolRequirementFlags.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/ProtocolRequirementFlags.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/ProtocolRequirementFlags.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/ProtocolRequirementFlags.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/ProtocolRequirementKind.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/ProtocolRequirementKind.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/ProtocolRequirementKind.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/ProtocolRequirementKind.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetClassDescriptor.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetClassDescriptor.java similarity index 98% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetClassDescriptor.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetClassDescriptor.java index 4f9719ea4e..9f77995b0c 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetClassDescriptor.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetClassDescriptor.java @@ -21,7 +21,7 @@ import java.util.List; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.*; import ghidra.util.exception.DuplicateNameException; @@ -313,7 +313,7 @@ public final class TargetClassDescriptor extends TargetTypeContextDescriptor { "Union_MetadataNegativeSizeInWords_ResilientMetadataBounds"); union1.add(DWORD, "MetadataNegativeSizeInWords", "If this descriptor does not have a resilient superclass, this is the negative size of metadata objects of this class (in words)"); - union1.add(SwiftUtils.PTR_RELATIVE, "ResilientMetadataBounds", + union1.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "ResilientMetadataBounds", "If this descriptor has a resilient superclass, this is a reference to a cache holding the metadata's extends."); UnionDataType union2 = @@ -325,7 +325,7 @@ public final class TargetClassDescriptor extends TargetTypeContextDescriptor { StructureDataType struct = new StructureDataType(CATEGORY_PATH, getStructureName(), 0); struct.add(super.toDataType(), super.getStructureName(), ""); - struct.add(SwiftUtils.PTR_STRING, "SuperclassType", + struct.add(SwiftTypeMetadataUtils.PTR_STRING, "SuperclassType", "The type of the superclass, expressed as a mangled type name that can refer to the generic arguments of the subclass type"); struct.add(union1, "MetadataNegativeSizeInWords/ResilientMetadataBounds", null); struct.add(union2, "MetadataPositiveSizeInWords/ExtraClassFlags", null); diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetContextDescriptor.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetContextDescriptor.java similarity index 95% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetContextDescriptor.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetContextDescriptor.java index 7d3a107376..9ea7ae1a24 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetContextDescriptor.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetContextDescriptor.java @@ -19,7 +19,7 @@ import java.io.IOException; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.DataType; import ghidra.program.model.data.StructureDataType; import ghidra.util.exception.DuplicateNameException; @@ -87,7 +87,7 @@ public class TargetContextDescriptor extends SwiftTypeMetadataStructure { StructureDataType struct = new StructureDataType(CATEGORY_PATH, getMyStructureName(), 0); struct.add(flags.toDataType(), "Flags", "Flags describing the context, including its kind and format version"); - struct.add(SwiftUtils.PTR_RELATIVE_MASKED, "Parent", + struct.add(SwiftTypeMetadataUtils.PTR_RELATIVE_MASKED, "Parent", "The parent context, or null if this is a top-level context"); return struct; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetEnumDescriptor.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetEnumDescriptor.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetEnumDescriptor.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetEnumDescriptor.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetForeignMetadataInitialization.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetForeignMetadataInitialization.java similarity index 94% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetForeignMetadataInitialization.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetForeignMetadataInitialization.java index 729984a67c..e5cf3f7c33 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetForeignMetadataInitialization.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetForeignMetadataInitialization.java @@ -19,7 +19,7 @@ import java.io.IOException; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.DataType; import ghidra.program.model.data.StructureDataType; import ghidra.util.exception.DuplicateNameException; @@ -64,7 +64,7 @@ public class TargetForeignMetadataInitialization extends SwiftTypeMetadataStruct @Override public DataType toDataType() throws DuplicateNameException, IOException { StructureDataType struct = new StructureDataType(CATEGORY_PATH, getStructureName(), 0); - struct.add(SwiftUtils.PTR_RELATIVE, "CompletionFunction", + struct.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "CompletionFunction", "The completion function. The pattern will always be null."); return struct; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetGenericContextDescriptorHeader.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetGenericContextDescriptorHeader.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetGenericContextDescriptorHeader.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetGenericContextDescriptorHeader.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetGenericRequirementsDescriptor.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetGenericRequirementsDescriptor.java similarity index 89% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetGenericRequirementsDescriptor.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetGenericRequirementsDescriptor.java index a202e645ed..7b9840c6f5 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetGenericRequirementsDescriptor.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetGenericRequirementsDescriptor.java @@ -19,7 +19,7 @@ import java.io.IOException; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.*; import ghidra.util.exception.DuplicateNameException; @@ -115,16 +115,16 @@ public class TargetGenericRequirementsDescriptor extends SwiftTypeMetadataStruct UnionDataType union = new UnionDataType(CATEGORY_PATH, "Union_TargetGenericRequirementsDescriptor"); - union.add(SwiftUtils.PTR_RELATIVE, "Type", "A mangled representation of the same-type or base class the param is constrained to."); - union.add(SwiftUtils.PTR_RELATIVE, "Protocol", "The protocol the param is constrained to."); - union.add(SwiftUtils.PTR_RELATIVE, "Conformance", "The conformance the param is constrained to use."); + union.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "Type", "A mangled representation of the same-type or base class the param is constrained to."); + union.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "Protocol", "The protocol the param is constrained to."); + union.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "Conformance", "The conformance the param is constrained to use."); union.add(GenericRequirementLayoutKind.values()[0].toDataType(), "Layout", "The kind of layout constraint."); union.add(invertedProtocolsStruct, invertedProtocolsStruct.getName(), null); StructureDataType struct = new StructureDataType(CATEGORY_PATH, getStructureName(), 0); struct.add(flags.toDataType(), "Flags", null); - struct.add(SwiftUtils.PTR_RELATIVE, "Param", + struct.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "Param", "The type that's constrained, described as a mangled name."); struct.add(union, union.getName(), null); return struct; diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetGenericWitnessTable.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetGenericWitnessTable.java similarity index 93% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetGenericWitnessTable.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetGenericWitnessTable.java index ae41b7efae..d0884932be 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetGenericWitnessTable.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetGenericWitnessTable.java @@ -19,7 +19,7 @@ import java.io.IOException; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.DataType; import ghidra.program.model.data.StructureDataType; import ghidra.util.exception.DuplicateNameException; @@ -96,9 +96,9 @@ public class TargetGenericWitnessTable extends SwiftTypeMetadataStructure { struct.add(WORD, "WitnessTableSizeInWords", "The size of the witness table in words."); struct.add(WORD, "WitnessTablePrivateSizeInWordsAndRequiresInstantiation", "The amount of private storage to allocate before the address point, in words."); - struct.add(SwiftUtils.PTR_RELATIVE, "Instantiator", + struct.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "Instantiator", "The instantiation function, which is called after the template is copied."); - struct.add(SwiftUtils.PTR_RELATIVE, "PrivateData", "Private data for the instantiator."); + struct.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "PrivateData", "Private data for the instantiator."); return struct; } } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetMethodDescriptor.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetMethodDescriptor.java similarity index 94% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetMethodDescriptor.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetMethodDescriptor.java index e0160a6b2b..46a00a42c8 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetMethodDescriptor.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetMethodDescriptor.java @@ -19,7 +19,7 @@ import java.io.IOException; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.DataType; import ghidra.program.model.data.StructureDataType; import ghidra.util.exception.DuplicateNameException; @@ -79,7 +79,7 @@ public class TargetMethodDescriptor extends SwiftTypeMetadataStructure { public DataType toDataType() throws DuplicateNameException, IOException { StructureDataType struct = new StructureDataType(CATEGORY_PATH, getStructureName(), 0); struct.add(flags.toDataType(), "Flags", "Flags describing the method"); - struct.add(SwiftUtils.PTR_RELATIVE, "Impl", "The method implementation"); + struct.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "Impl", "The method implementation"); return struct; } } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetMethodOverrideDescriptor.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetMethodOverrideDescriptor.java similarity index 89% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetMethodOverrideDescriptor.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetMethodOverrideDescriptor.java index aedab51ed0..b6c1d8a6a5 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetMethodOverrideDescriptor.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetMethodOverrideDescriptor.java @@ -19,7 +19,7 @@ import java.io.IOException; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.DataType; import ghidra.program.model.data.StructureDataType; import ghidra.util.exception.DuplicateNameException; @@ -87,10 +87,10 @@ public class TargetMethodOverrideDescriptor extends SwiftTypeMetadataStructure { @Override public DataType toDataType() throws DuplicateNameException, IOException { StructureDataType struct = new StructureDataType(CATEGORY_PATH, getStructureName(), 0); - struct.add(SwiftUtils.PTR_RELATIVE_MASKED, "Class", + struct.add(SwiftTypeMetadataUtils.PTR_RELATIVE_MASKED, "Class", "The class containing the base method."); - struct.add(SwiftUtils.PTR_RELATIVE_MASKED, "Method", "The base method."); - struct.add(SwiftUtils.PTR_RELATIVE, "Impl", "The implementation of the override"); + struct.add(SwiftTypeMetadataUtils.PTR_RELATIVE_MASKED, "Method", "The base method."); + struct.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "Impl", "The implementation of the override"); return struct; } } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetObjCResilientClassStubInfo.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetObjCResilientClassStubInfo.java similarity index 95% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetObjCResilientClassStubInfo.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetObjCResilientClassStubInfo.java index 322d22b7ab..9b47b29cc3 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetObjCResilientClassStubInfo.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetObjCResilientClassStubInfo.java @@ -19,7 +19,7 @@ import java.io.IOException; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.DataType; import ghidra.program.model.data.StructureDataType; import ghidra.util.exception.DuplicateNameException; @@ -71,7 +71,7 @@ public class TargetObjCResilientClassStubInfo extends SwiftTypeMetadataStructure @Override public DataType toDataType() throws DuplicateNameException, IOException { StructureDataType struct = new StructureDataType(CATEGORY_PATH, getMyStructureName(), 0); - struct.add(SwiftUtils.PTR_RELATIVE, "Stub", + struct.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "Stub", "A relative pointer to an Objective-C resilient class stub."); return struct; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetOverrideTableHeader.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetOverrideTableHeader.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetOverrideTableHeader.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetOverrideTableHeader.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetProtocolConformanceDescriptor.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetProtocolConformanceDescriptor.java similarity index 95% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetProtocolConformanceDescriptor.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetProtocolConformanceDescriptor.java index 05c6b50330..5f436b11c3 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetProtocolConformanceDescriptor.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetProtocolConformanceDescriptor.java @@ -21,7 +21,7 @@ import java.util.List; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.DataType; import ghidra.program.model.data.StructureDataType; import ghidra.util.exception.DuplicateNameException; @@ -159,8 +159,8 @@ public final class TargetProtocolConformanceDescriptor extends SwiftTypeMetadata @Override public DataType toDataType() throws DuplicateNameException, IOException { StructureDataType struct = new StructureDataType(CATEGORY_PATH, getStructureName(), 0); - struct.add(SwiftUtils.PTR_RELATIVE_MASKED, "Protocol", "The protocol being conformed to"); - struct.add(SwiftUtils.PTR_RELATIVE, "TypeRef", + struct.add(SwiftTypeMetadataUtils.PTR_RELATIVE_MASKED, "Protocol", "The protocol being conformed to"); + struct.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "TypeRef", "Some description of the type that conforms to the protocol"); struct.add(DWORD, "WitnessTablePattern", "The witness table pattern, which may also serve as the witness table"); diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetProtocolDescriptor.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetProtocolDescriptor.java similarity index 93% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetProtocolDescriptor.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetProtocolDescriptor.java index e969e082ed..65bfa593e3 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetProtocolDescriptor.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetProtocolDescriptor.java @@ -21,7 +21,7 @@ import java.util.List; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.DataType; import ghidra.program.model.data.StructureDataType; import ghidra.util.exception.DuplicateNameException; @@ -49,7 +49,7 @@ public final class TargetProtocolDescriptor extends TargetContextDescriptor { */ public TargetProtocolDescriptor(BinaryReader reader) throws IOException { super(reader); - name = reader.readNext(SwiftUtils::relativeString); + name = reader.readNext(SwiftTypeMetadataUtils::relativeString); numRequirementsInSig = reader.readNextInt(); numRequirements = reader.readNextInt(); associatedTypeNames = reader.readNextInt(); @@ -131,11 +131,11 @@ public final class TargetProtocolDescriptor extends TargetContextDescriptor { public DataType toDataType() throws DuplicateNameException, IOException { StructureDataType struct = new StructureDataType(CATEGORY_PATH, getStructureName(), 0); struct.add(super.toDataType(), super.getStructureName(), ""); - struct.add(SwiftUtils.PTR_STRING, "Name", "The name of the protocol"); + struct.add(SwiftTypeMetadataUtils.PTR_STRING, "Name", "The name of the protocol"); struct.add(DWORD, "NumRequirementsInSignature", "The number of generic requirements in the requirement signature of the protocol"); struct.add(DWORD, "NumRequirements", "The number of requirements in the protocol"); - struct.add(SwiftUtils.PTR_RELATIVE, "AssociatedTypeNames", + struct.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "AssociatedTypeNames", "Associated type names, as a space-separated list in the same order as the requirements"); return struct; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetProtocolRequirement.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetProtocolRequirement.java similarity index 90% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetProtocolRequirement.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetProtocolRequirement.java index 007152df17..4b76fb9a30 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetProtocolRequirement.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetProtocolRequirement.java @@ -19,7 +19,7 @@ import java.io.IOException; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.*; import ghidra.util.exception.DuplicateNameException; @@ -68,8 +68,8 @@ public class TargetProtocolRequirement extends SwiftTypeMetadataStructure { public DataType toDataType() throws DuplicateNameException, IOException { UnionDataType union = new UnionDataType(CATEGORY_PATH, "Union_DefaultFuncImplementation_DefaultImplementation"); - union.add(SwiftUtils.PTR_RELATIVE, "DefaultFuncImplementation", null); - union.add(SwiftUtils.PTR_RELATIVE, "DefaultImplementation", null); + union.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "DefaultFuncImplementation", null); + union.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "DefaultImplementation", null); StructureDataType struct = new StructureDataType(CATEGORY_PATH, getStructureName(), 0); struct.add(flags.toDataType(), "Flags", null); diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetRelativeContextPointer.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetRelativeContextPointer.java similarity index 94% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetRelativeContextPointer.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetRelativeContextPointer.java index fb467bcf12..2648f50996 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetRelativeContextPointer.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetRelativeContextPointer.java @@ -19,7 +19,7 @@ import java.io.IOException; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.DataType; import ghidra.util.exception.DuplicateNameException; @@ -62,6 +62,6 @@ public class TargetRelativeContextPointer extends SwiftTypeMetadataStructure { @Override public DataType toDataType() throws DuplicateNameException, IOException { - return SwiftUtils.PTR_RELATIVE_MASKED; + return SwiftTypeMetadataUtils.PTR_RELATIVE_MASKED; } } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetRelativeProtocolRequirementPointer.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetRelativeProtocolRequirementPointer.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetRelativeProtocolRequirementPointer.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetRelativeProtocolRequirementPointer.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetResilientSuperclass.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetResilientSuperclass.java similarity index 93% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetResilientSuperclass.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetResilientSuperclass.java index 9a6bbfcae6..f57a1d0b04 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetResilientSuperclass.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetResilientSuperclass.java @@ -19,7 +19,7 @@ import java.io.IOException; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.DataType; import ghidra.program.model.data.StructureDataType; import ghidra.util.exception.DuplicateNameException; @@ -71,7 +71,7 @@ public class TargetResilientSuperclass extends SwiftTypeMetadataStructure { @Override public DataType toDataType() throws DuplicateNameException, IOException { StructureDataType struct = new StructureDataType(CATEGORY_PATH, getMyStructureName(), 0); - struct.add(SwiftUtils.PTR_RELATIVE, "Superclass", "The superclass of this class."); + struct.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "Superclass", "The superclass of this class."); return struct; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetResilientWitness.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetResilientWitness.java similarity index 92% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetResilientWitness.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetResilientWitness.java index 03e4544305..a3dfc0808e 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetResilientWitness.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetResilientWitness.java @@ -19,7 +19,7 @@ import java.io.IOException; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.*; import ghidra.util.exception.DuplicateNameException; @@ -68,8 +68,8 @@ public class TargetResilientWitness extends SwiftTypeMetadataStructure { public DataType toDataType() throws DuplicateNameException, IOException { UnionDataType union = new UnionDataType(CATEGORY_PATH, "Union_Impl_FuncImpl"); - union.add(SwiftUtils.PTR_RELATIVE, "Impl", null); - union.add(SwiftUtils.PTR_RELATIVE, "FuncImpl", null); + union.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "Impl", null); + union.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "FuncImpl", null); StructureDataType struct = new StructureDataType(CATEGORY_PATH, getStructureName(), 0); struct.add(TargetRelativeProtocolRequirementPointer.dataType, "Requirement", null); diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetResilientWitnessHeader.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetResilientWitnessHeader.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetResilientWitnessHeader.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetResilientWitnessHeader.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetSingletonMetadataInitialization.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetSingletonMetadataInitialization.java similarity index 90% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetSingletonMetadataInitialization.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetSingletonMetadataInitialization.java index f670a09e29..9ab1bc41b4 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetSingletonMetadataInitialization.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetSingletonMetadataInitialization.java @@ -19,7 +19,7 @@ import java.io.IOException; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.*; import ghidra.util.exception.DuplicateNameException; @@ -99,15 +99,15 @@ public class TargetSingletonMetadataInitialization extends SwiftTypeMetadataStru public DataType toDataType() throws DuplicateNameException, IOException { UnionDataType union = new UnionDataType(CATEGORY_PATH, "Union_IncompleteMetadata_ResilientPattern"); - union.add(SwiftUtils.PTR_RELATIVE, "IncompleteMetadata", + union.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "IncompleteMetadata", "The incomplete metadata, for structs, enums and classes without resilient ancestry."); - union.add(SwiftUtils.PTR_RELATIVE, "ResilientPattern", + union.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "ResilientPattern", "If the classes descriptor has a resilient superclass, this points at a pattern used to allcoate and initialize metadata for this class, since its size and contents is not known at compile time."); StructureDataType struct = new StructureDataType(CATEGORY_PATH, getStructureName(), 0); - struct.add(SwiftUtils.PTR_RELATIVE, "InitializationCache", "The initialization cache."); + struct.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "InitializationCache", "The initialization cache."); struct.add(union, union.getName(), null); - struct.add(SwiftUtils.PTR_RELATIVE, "CompletionFunction", + struct.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "CompletionFunction", "The completion function. The pattern will always be null, even for a resilient class."); return struct; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetStructDescriptor.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetStructDescriptor.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetStructDescriptor.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetStructDescriptor.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetTypeContextDescriptor.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetTypeContextDescriptor.java similarity index 90% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetTypeContextDescriptor.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetTypeContextDescriptor.java index 67ad43d0f3..2de633593f 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetTypeContextDescriptor.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetTypeContextDescriptor.java @@ -19,7 +19,7 @@ import java.io.IOException; import java.util.Map; import ghidra.app.util.bin.BinaryReader; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.DataType; import ghidra.program.model.data.StructureDataType; import ghidra.util.exception.DuplicateNameException; @@ -43,7 +43,7 @@ public class TargetTypeContextDescriptor extends TargetContextDescriptor { */ public TargetTypeContextDescriptor(BinaryReader reader) throws IOException { super(reader); - name = reader.readNext(SwiftUtils::relativeString); + name = reader.readNext(SwiftTypeMetadataUtils::relativeString); accessFunctionPtr = reader.readNextInt(); fields = reader.readNextInt(); } @@ -108,10 +108,10 @@ public class TargetTypeContextDescriptor extends TargetContextDescriptor { public DataType toDataType() throws DuplicateNameException, IOException { StructureDataType struct = new StructureDataType(CATEGORY_PATH, getMyStructureName(), 0); struct.add(super.toDataType(), super.getStructureName(), ""); - struct.add(SwiftUtils.PTR_STRING, "Name", "The name of the type"); - struct.add(SwiftUtils.PTR_RELATIVE, "AccessFunctionPtr", + struct.add(SwiftTypeMetadataUtils.PTR_STRING, "Name", "The name of the type"); + struct.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "AccessFunctionPtr", "A pointer to the metadata access function for this type"); - struct.add(SwiftUtils.PTR_RELATIVE, "Fields", + struct.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "Fields", "A pointer to the field descriptor for the type, if any"); return struct; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetTypeGenericContextDescriptorHeader.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetTypeGenericContextDescriptorHeader.java similarity index 93% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetTypeGenericContextDescriptorHeader.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetTypeGenericContextDescriptorHeader.java index 17f1907739..99e1191a97 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetTypeGenericContextDescriptorHeader.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetTypeGenericContextDescriptorHeader.java @@ -20,7 +20,7 @@ import java.util.List; import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.format.swift.SwiftTypeMetadataStructure; -import ghidra.app.util.bin.format.swift.SwiftUtils; +import ghidra.app.util.bin.format.swift.SwiftTypeMetadataUtils; import ghidra.program.model.data.DataType; import ghidra.program.model.data.StructureDataType; import ghidra.util.exception.DuplicateNameException; @@ -88,9 +88,9 @@ public class TargetTypeGenericContextDescriptorHeader extends SwiftTypeMetadataS @Override public DataType toDataType() throws DuplicateNameException, IOException { StructureDataType struct = new StructureDataType(CATEGORY_PATH, getStructureName(), 0); - struct.add(SwiftUtils.PTR_RELATIVE, "InstantiationCache", + struct.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "InstantiationCache", "The metadata instantiation cache."); - struct.add(SwiftUtils.PTR_RELATIVE, "DefaultInstantiationPattern", + struct.add(SwiftTypeMetadataUtils.PTR_RELATIVE, "DefaultInstantiationPattern", "The default instantiation pattern."); struct.add(base.toDataType(), "Base", "The base header."); return struct; diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetVTableDescriptorHeader.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetVTableDescriptorHeader.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TargetVTableDescriptorHeader.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TargetVTableDescriptorHeader.java diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TypeReferenceKind.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TypeReferenceKind.java similarity index 100% rename from Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/types/TypeReferenceKind.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/bin/format/swift/types/TypeReferenceKind.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/SwiftDemangledBuiltinType.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/SwiftDemangledBuiltinType.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/SwiftDemangledBuiltinType.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/SwiftDemangledBuiltinType.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/SwiftDemangledNodeKind.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/SwiftDemangledNodeKind.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/SwiftDemangledNodeKind.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/SwiftDemangledNodeKind.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/SwiftDemangledTree.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/SwiftDemangledTree.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/SwiftDemangledTree.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/SwiftDemangledTree.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/SwiftDemangler.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/SwiftDemangler.java similarity index 97% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/SwiftDemangler.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/SwiftDemangler.java index d49cf4eb58..983855aab5 100644 --- a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/SwiftDemangler.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/SwiftDemangler.java @@ -19,11 +19,11 @@ import java.io.IOException; import java.util.*; import ghidra.app.util.bin.format.swift.SwiftTypeMetadata; -import ghidra.app.util.bin.format.swift.SwiftUtils; import ghidra.app.util.demangler.*; import ghidra.app.util.demangler.swift.datatypes.SwiftDataTypeUtils; import ghidra.app.util.demangler.swift.nodes.SwiftNode; import ghidra.app.util.importer.MessageLog; +import ghidra.app.util.sourcelanguage.SwiftSourceLanguage; import ghidra.program.model.listing.Program; import ghidra.util.exception.CancelledException; import ghidra.util.task.TaskMonitor; @@ -66,7 +66,7 @@ public class SwiftDemangler implements Demangler { @Override public boolean canDemangle(Program program) { - return SwiftUtils.isSwift(program); + return program.getSourceLanguageIDs().contains(SwiftSourceLanguage.SWIFT_ID); } @Override diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/SwiftDemanglerOptions.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/SwiftDemanglerOptions.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/SwiftDemanglerOptions.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/SwiftDemanglerOptions.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/SwiftNativeDemangler.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/SwiftNativeDemangler.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/SwiftNativeDemangler.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/SwiftNativeDemangler.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftArray.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftArray.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftArray.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftArray.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftCharacter.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftCharacter.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftCharacter.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftCharacter.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftDataTypeUtils.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftDataTypeUtils.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftDataTypeUtils.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftDataTypeUtils.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftEnum.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftEnum.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftEnum.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftEnum.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftFunction.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftFunction.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftFunction.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftFunction.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftPrimitive.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftPrimitive.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftPrimitive.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftPrimitive.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftString.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftString.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftString.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftString.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftStructure.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftStructure.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftStructure.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftStructure.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftTuple.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftTuple.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftTuple.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/datatypes/SwiftTuple.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftAllocatorNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftAllocatorNode.java similarity index 88% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftAllocatorNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftAllocatorNode.java index 331f48e174..3c69a7719e 100644 --- a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftAllocatorNode.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftAllocatorNode.java @@ -4,9 +4,9 @@ * 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. @@ -20,7 +20,7 @@ import ghidra.app.util.demangler.DemangledException; import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind; import ghidra.app.util.demangler.swift.SwiftDemangler; import ghidra.app.util.demangler.swift.datatypes.SwiftFunction; -import ghidra.program.model.lang.CompilerSpec; +import ghidra.app.util.sourcelanguage.SwiftSourceLanguageSpecExtension; /** * A {@link SwiftDemangledNodeKind#Allocator} {@link SwiftNode} @@ -33,19 +33,19 @@ public class SwiftAllocatorNode extends SwiftNode { Demangled namespace = null; Demangled type = null; Demangled labelList = null; - String callingConvention = CompilerSpec.CALLING_CONVENTION_default; + String callingConvention = SwiftSourceLanguageSpecExtension.SWIFT_STDCALL; for (SwiftNode child : getChildren()) { switch (child.getKind()) { case Class: namespace = child.demangle(demangler); name = "__allocating_init"; - callingConvention = CompilerSpec.CALLING_CONVENTION_thiscall; + callingConvention = SwiftSourceLanguageSpecExtension.SWIFT_THISCALL; break; case Extension: namespace = child.demangle(demangler); if (child.hasChild(SwiftDemangledNodeKind.Class)) { name = "__allocating_init"; - callingConvention = CompilerSpec.CALLING_CONVENTION_thiscall; + callingConvention = SwiftSourceLanguageSpecExtension.SWIFT_THISCALL; } else if (child.hasChild(SwiftDemangledNodeKind.Protocol) || child.hasChild(SwiftDemangledNodeKind.Structure)) { diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftBoundGenericStructureNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftBoundGenericStructureNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftBoundGenericStructureNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftBoundGenericStructureNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftBuiltinTypeNameNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftBuiltinTypeNameNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftBuiltinTypeNameNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftBuiltinTypeNameNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftClassNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftClassNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftClassNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftClassNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftConstructorNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftConstructorNode.java similarity index 93% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftConstructorNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftConstructorNode.java index fc02dc718a..9316b14c3a 100644 --- a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftConstructorNode.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftConstructorNode.java @@ -4,9 +4,9 @@ * 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. @@ -19,7 +19,7 @@ import ghidra.app.util.demangler.*; import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind; import ghidra.app.util.demangler.swift.SwiftDemangler; import ghidra.app.util.demangler.swift.datatypes.SwiftFunction; -import ghidra.program.model.lang.CompilerSpec; +import ghidra.app.util.sourcelanguage.SwiftSourceLanguageSpecExtension; /** * A {@link SwiftDemangledNodeKind#Constructor} {@link SwiftNode} @@ -54,7 +54,7 @@ public class SwiftConstructorNode extends SwiftNode { } SwiftFunction function = new SwiftFunction(properties.mangled(), properties.originalDemangled(), name, namespace, - CompilerSpec.CALLING_CONVENTION_thiscall); + SwiftSourceLanguageSpecExtension.SWIFT_THISCALL); if (type instanceof DemangledFunction functionType) { function.setType(functionType, labelList); } diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftDeallocatorNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftDeallocatorNode.java similarity index 91% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftDeallocatorNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftDeallocatorNode.java index 7874a34eed..b443fa631d 100644 --- a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftDeallocatorNode.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftDeallocatorNode.java @@ -4,9 +4,9 @@ * 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. @@ -20,7 +20,7 @@ import ghidra.app.util.demangler.DemangledException; import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind; import ghidra.app.util.demangler.swift.SwiftDemangler; import ghidra.app.util.demangler.swift.datatypes.SwiftFunction; -import ghidra.program.model.lang.CompilerSpec; +import ghidra.app.util.sourcelanguage.SwiftSourceLanguageSpecExtension; /** * A {@link SwiftDemangledNodeKind#Deallocator} {@link SwiftNode} @@ -46,6 +46,6 @@ public class SwiftDeallocatorNode extends SwiftNode { return getUnknown(); } return new SwiftFunction(properties.mangled(), properties.originalDemangled(), name, - namespace, CompilerSpec.CALLING_CONVENTION_thiscall); + namespace, SwiftSourceLanguageSpecExtension.SWIFT_THISCALL); } } diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftDependentGenericParamTypeNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftDependentGenericParamTypeNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftDependentGenericParamTypeNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftDependentGenericParamTypeNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftDependentGenericTypeNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftDependentGenericTypeNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftDependentGenericTypeNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftDependentGenericTypeNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftDestructorNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftDestructorNode.java similarity index 92% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftDestructorNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftDestructorNode.java index 0519a09954..1dd9c217d1 100644 --- a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftDestructorNode.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftDestructorNode.java @@ -4,9 +4,9 @@ * 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. @@ -19,7 +19,7 @@ import ghidra.app.util.demangler.*; import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind; import ghidra.app.util.demangler.swift.SwiftDemangler; import ghidra.app.util.demangler.swift.datatypes.SwiftFunction; -import ghidra.program.model.lang.CompilerSpec; +import ghidra.app.util.sourcelanguage.SwiftSourceLanguageSpecExtension; /** * A {@link SwiftDemangledNodeKind#Destructor} {@link SwiftNode} @@ -46,7 +46,7 @@ public class SwiftDestructorNode extends SwiftNode { } SwiftFunction function = new SwiftFunction(properties.mangled(), properties.originalDemangled(), name, namespace, - CompilerSpec.CALLING_CONVENTION_thiscall); + SwiftSourceLanguageSpecExtension.SWIFT_THISCALL); if (namespace instanceof DemangledDataType type) { function.setReturnType(type); } diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftEnumNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftEnumNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftEnumNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftEnumNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftExtensionNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftExtensionNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftExtensionNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftExtensionNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftFunctionNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftFunctionNode.java similarity index 90% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftFunctionNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftFunctionNode.java index eea6e07e81..d2fd722458 100644 --- a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftFunctionNode.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftFunctionNode.java @@ -4,9 +4,9 @@ * 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. @@ -19,7 +19,7 @@ import ghidra.app.util.demangler.*; import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind; import ghidra.app.util.demangler.swift.SwiftDemangler; import ghidra.app.util.demangler.swift.datatypes.SwiftFunction; -import ghidra.program.model.lang.CompilerSpec; +import ghidra.app.util.sourcelanguage.SwiftSourceLanguageSpecExtension; /** * A {@link SwiftDemangledNodeKind#Function} {@link SwiftNode} @@ -32,7 +32,7 @@ public class SwiftFunctionNode extends SwiftNode { Demangled namespace = null; Demangled type = null; Demangled labelList = null; - String callingConvention = CompilerSpec.CALLING_CONVENTION_default; + String callingConvention = SwiftSourceLanguageSpecExtension.SWIFT_STDCALL; for (SwiftNode child : getChildren()) { switch (child.getKind()) { case Identifier: @@ -45,7 +45,7 @@ public class SwiftFunctionNode extends SwiftNode { name = child.demangle(demangler).getName(); break; case Class: - callingConvention = CompilerSpec.CALLING_CONVENTION_thiscall; + callingConvention = SwiftSourceLanguageSpecExtension.SWIFT_THISCALL; // Fall through case Enum: case Extension: diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftFunctionTypeNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftFunctionTypeNode.java similarity index 96% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftFunctionTypeNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftFunctionTypeNode.java index f7ad6b186a..f06e7e48d5 100644 --- a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftFunctionTypeNode.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftFunctionTypeNode.java @@ -4,9 +4,9 @@ * 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. @@ -19,7 +19,7 @@ import ghidra.app.util.demangler.*; import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind; import ghidra.app.util.demangler.swift.SwiftDemangler; import ghidra.app.util.demangler.swift.datatypes.*; -import ghidra.program.model.lang.CompilerSpec; +import ghidra.app.util.sourcelanguage.SwiftSourceLanguageSpecExtension; /** * A {@link SwiftDemangledNodeKind#FunctionType} {@link SwiftNode} @@ -45,7 +45,7 @@ public class SwiftFunctionTypeNode extends SwiftNode { } SwiftFunction function = new SwiftFunction(properties.mangled(), properties.originalDemangled(), "", - null, CompilerSpec.CALLING_CONVENTION_default); + null, SwiftSourceLanguageSpecExtension.SWIFT_STDCALL); // Parameters function.addParameters(SwiftDataTypeUtils.extractParameters(argumentTuple)); diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftGetterNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftGetterNode.java similarity index 90% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftGetterNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftGetterNode.java index 1eca9b3cdd..46f04da84e 100644 --- a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftGetterNode.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftGetterNode.java @@ -4,9 +4,9 @@ * 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. @@ -20,7 +20,7 @@ import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind; import ghidra.app.util.demangler.swift.SwiftDemangler; import ghidra.app.util.demangler.swift.datatypes.SwiftDataTypeUtils; import ghidra.app.util.demangler.swift.datatypes.SwiftFunction; -import ghidra.program.model.lang.CompilerSpec; +import ghidra.app.util.sourcelanguage.SwiftSourceLanguageSpecExtension; /** * A {@link SwiftDemangledNodeKind#Getter} {@link SwiftNode} @@ -31,7 +31,7 @@ public class SwiftGetterNode extends SwiftNode { public Demangled demangle(SwiftDemangler demangler) throws DemangledException { Demangled demangled = null; String name = "get_"; - String callingConvention = CompilerSpec.CALLING_CONVENTION_default; + String callingConvention = SwiftSourceLanguageSpecExtension.SWIFT_STDCALL; for (SwiftNode child : getChildren()) { switch (child.getKind()) { case Subscript: @@ -40,7 +40,7 @@ public class SwiftGetterNode extends SwiftNode { case Variable: demangled = child.demangle(demangler); if (child.hasChild(SwiftDemangledNodeKind.Class)) { - callingConvention = CompilerSpec.CALLING_CONVENTION_thiscall; + callingConvention = SwiftSourceLanguageSpecExtension.SWIFT_THISCALL; } break; default: diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftGlobalNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftGlobalNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftGlobalNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftGlobalNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftGlobalVariableOnceDeclListNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftGlobalVariableOnceDeclListNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftGlobalVariableOnceDeclListNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftGlobalVariableOnceDeclListNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftGlobalVariableOnceFunctionNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftGlobalVariableOnceFunctionNode.java similarity index 92% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftGlobalVariableOnceFunctionNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftGlobalVariableOnceFunctionNode.java index 5f01f65bd4..1b559fb89f 100644 --- a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftGlobalVariableOnceFunctionNode.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftGlobalVariableOnceFunctionNode.java @@ -4,9 +4,9 @@ * 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. @@ -19,7 +19,7 @@ import ghidra.app.util.demangler.*; import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind; import ghidra.app.util.demangler.swift.SwiftDemangler; import ghidra.app.util.demangler.swift.datatypes.SwiftFunction; -import ghidra.program.model.lang.CompilerSpec; +import ghidra.app.util.sourcelanguage.SwiftSourceLanguageSpecExtension; /** * A {@link SwiftDemangledNodeKind#GlobalVariableOnceFunction} {@link SwiftNode} @@ -56,6 +56,6 @@ public class SwiftGlobalVariableOnceFunctionNode extends SwiftNode { } } return new SwiftFunction(properties.mangled(), properties.originalDemangled(), - name.toString(), namespace, CompilerSpec.CALLING_CONVENTION_default); + name.toString(), namespace, SwiftSourceLanguageSpecExtension.SWIFT_STDCALL); } } diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftInOutNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftInOutNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftInOutNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftInOutNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftInitializerNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftInitializerNode.java similarity index 91% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftInitializerNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftInitializerNode.java index 5e28d1c633..fed9a1a909 100644 --- a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftInitializerNode.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftInitializerNode.java @@ -4,9 +4,9 @@ * 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. @@ -20,7 +20,7 @@ import ghidra.app.util.demangler.DemangledException; import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind; import ghidra.app.util.demangler.swift.SwiftDemangler; import ghidra.app.util.demangler.swift.datatypes.SwiftFunction; -import ghidra.program.model.lang.CompilerSpec; +import ghidra.app.util.sourcelanguage.SwiftSourceLanguageSpecExtension; /** * A {@link SwiftDemangledNodeKind#Initializer} {@link SwiftNode} @@ -46,6 +46,6 @@ public class SwiftInitializerNode extends SwiftNode { return getUnknown(); } return new SwiftFunction(properties.mangled(), properties.originalDemangled(), name, - namespace, CompilerSpec.CALLING_CONVENTION_default); + namespace, SwiftSourceLanguageSpecExtension.SWIFT_STDCALL); } } diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftLabelListNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftLabelListNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftLabelListNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftLabelListNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftLazyProtocolWitnessTableAccessorNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftLazyProtocolWitnessTableAccessorNode.java similarity index 91% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftLazyProtocolWitnessTableAccessorNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftLazyProtocolWitnessTableAccessorNode.java index 313d7e9aef..91c397d0f3 100644 --- a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftLazyProtocolWitnessTableAccessorNode.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftLazyProtocolWitnessTableAccessorNode.java @@ -4,9 +4,9 @@ * 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. @@ -20,7 +20,7 @@ import ghidra.app.util.demangler.DemangledException; import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind; import ghidra.app.util.demangler.swift.SwiftDemangler; import ghidra.app.util.demangler.swift.datatypes.SwiftFunction; -import ghidra.program.model.lang.CompilerSpec; +import ghidra.app.util.sourcelanguage.SwiftSourceLanguageSpecExtension; /** * A {@link SwiftDemangledNodeKind#LazyProtocolWitnessTableAccessor} {@link SwiftNode} @@ -46,6 +46,6 @@ public class SwiftLazyProtocolWitnessTableAccessorNode extends SwiftNode { return getUnknown(); } return new SwiftFunction(properties.mangled(), properties.originalDemangled(), name, - namespace, CompilerSpec.CALLING_CONVENTION_default); + namespace, SwiftSourceLanguageSpecExtension.SWIFT_STDCALL); } } diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftLocalDeclNameNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftLocalDeclNameNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftLocalDeclNameNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftLocalDeclNameNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftModifyAccessorNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftModifyAccessorNode.java similarity index 92% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftModifyAccessorNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftModifyAccessorNode.java index 9a98f639bf..3d1bcb9e5e 100644 --- a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftModifyAccessorNode.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftModifyAccessorNode.java @@ -4,9 +4,9 @@ * 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. @@ -20,7 +20,7 @@ import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind; import ghidra.app.util.demangler.swift.SwiftDemangler; import ghidra.app.util.demangler.swift.datatypes.SwiftDataTypeUtils; import ghidra.app.util.demangler.swift.datatypes.SwiftFunction; -import ghidra.program.model.lang.CompilerSpec; +import ghidra.app.util.sourcelanguage.SwiftSourceLanguageSpecExtension; /** * A {@link SwiftDemangledNodeKind#ModifyAccessor} {@link SwiftNode} @@ -31,7 +31,7 @@ public class SwiftModifyAccessorNode extends SwiftNode { public Demangled demangle(SwiftDemangler demangler) throws DemangledException { Demangled demangled = null; String name = "modify_"; - String callingConvention = CompilerSpec.CALLING_CONVENTION_thiscall; + String callingConvention = SwiftSourceLanguageSpecExtension.SWIFT_THISCALL; for (SwiftNode child : getChildren()) { switch (child.getKind()) { case Subscript: diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftOutlinedConsumeNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftOutlinedConsumeNode.java similarity index 90% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftOutlinedConsumeNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftOutlinedConsumeNode.java index 7f6478baa9..ca434f4d99 100644 --- a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftOutlinedConsumeNode.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftOutlinedConsumeNode.java @@ -4,9 +4,9 @@ * 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. @@ -19,7 +19,7 @@ import ghidra.app.util.demangler.*; import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind; import ghidra.app.util.demangler.swift.SwiftDemangler; import ghidra.app.util.demangler.swift.datatypes.SwiftFunction; -import ghidra.program.model.lang.CompilerSpec; +import ghidra.app.util.sourcelanguage.SwiftSourceLanguageSpecExtension; /** * A {@link SwiftDemangledNodeKind#OutlinedConsume} {@link SwiftNode} @@ -41,7 +41,7 @@ public class SwiftOutlinedConsumeNode extends SwiftNode { } SwiftFunction function = new SwiftFunction(properties.mangled(), properties.originalDemangled(), - "outlined_consume", null, CompilerSpec.CALLING_CONVENTION_default); + "outlined_consume", null, SwiftSourceLanguageSpecExtension.SWIFT_STDCALL); if (type instanceof DemangledDataType dt) { function.addParameter(new DemangledParameter(dt)); } diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftOutlinedCopyNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftOutlinedCopyNode.java similarity index 90% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftOutlinedCopyNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftOutlinedCopyNode.java index 59f0b37248..94b76715e5 100644 --- a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftOutlinedCopyNode.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftOutlinedCopyNode.java @@ -4,9 +4,9 @@ * 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. @@ -19,7 +19,7 @@ import ghidra.app.util.demangler.*; import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind; import ghidra.app.util.demangler.swift.SwiftDemangler; import ghidra.app.util.demangler.swift.datatypes.SwiftFunction; -import ghidra.program.model.lang.CompilerSpec; +import ghidra.app.util.sourcelanguage.SwiftSourceLanguageSpecExtension; /** * A {@link SwiftDemangledNodeKind#OutlinedCopy} {@link SwiftNode} @@ -41,7 +41,7 @@ public class SwiftOutlinedCopyNode extends SwiftNode { } SwiftFunction function = new SwiftFunction(properties.mangled(), properties.originalDemangled(), - "outlined_copy", null, CompilerSpec.CALLING_CONVENTION_default); + "outlined_copy", null, SwiftSourceLanguageSpecExtension.SWIFT_STDCALL); if (type instanceof DemangledDataType dt) { function.addParameter(new DemangledParameter(dt)); } diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftPrivateDeclNameNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftPrivateDeclNameNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftPrivateDeclNameNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftPrivateDeclNameNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftProtocolConformanceNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftProtocolConformanceNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftProtocolConformanceNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftProtocolConformanceNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftProtocolNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftProtocolNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftProtocolNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftProtocolNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftSetterNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftSetterNode.java similarity index 92% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftSetterNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftSetterNode.java index 59dbd96ecb..5b8a42a03f 100644 --- a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftSetterNode.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftSetterNode.java @@ -4,9 +4,9 @@ * 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. @@ -20,7 +20,7 @@ import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind; import ghidra.app.util.demangler.swift.SwiftDemangler; import ghidra.app.util.demangler.swift.datatypes.SwiftDataTypeUtils; import ghidra.app.util.demangler.swift.datatypes.SwiftFunction; -import ghidra.program.model.lang.CompilerSpec; +import ghidra.app.util.sourcelanguage.SwiftSourceLanguageSpecExtension; /** * A {@link SwiftDemangledNodeKind#Setter} {@link SwiftNode} @@ -31,7 +31,7 @@ public class SwiftSetterNode extends SwiftNode { public Demangled demangle(SwiftDemangler demangler) throws DemangledException { Demangled demangled = null; String name = "set_"; - String callingConvention = CompilerSpec.CALLING_CONVENTION_thiscall; + String callingConvention = SwiftSourceLanguageSpecExtension.SWIFT_THISCALL; for (SwiftNode child : getChildren()) { switch (child.getKind()) { case Subscript: diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftStructureNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftStructureNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftStructureNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftStructureNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftSubscriptNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftSubscriptNode.java similarity index 89% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftSubscriptNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftSubscriptNode.java index 11dc18a4e8..6123328302 100644 --- a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftSubscriptNode.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftSubscriptNode.java @@ -4,9 +4,9 @@ * 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. @@ -19,7 +19,7 @@ import ghidra.app.util.demangler.*; import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind; import ghidra.app.util.demangler.swift.SwiftDemangler; import ghidra.app.util.demangler.swift.datatypes.SwiftFunction; -import ghidra.program.model.lang.CompilerSpec; +import ghidra.app.util.sourcelanguage.SwiftSourceLanguageSpecExtension; /** * A {@link SwiftDemangledNodeKind#Subscript} {@link SwiftNode} @@ -32,11 +32,11 @@ public class SwiftSubscriptNode extends SwiftNode { Demangled namespace = null; Demangled type = null; Demangled labelList = null; - String callingConvention = CompilerSpec.CALLING_CONVENTION_default; + String callingConvention = SwiftSourceLanguageSpecExtension.SWIFT_STDCALL; for (SwiftNode child : getChildren()) { switch (child.getKind()) { case Class: - callingConvention = CompilerSpec.CALLING_CONVENTION_thiscall; + callingConvention = SwiftSourceLanguageSpecExtension.SWIFT_THISCALL; // Fall through case Structure: namespace = child.demangle(demangler); diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftTupleElementNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftTupleElementNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftTupleElementNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftTupleElementNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftTupleNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftTupleNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftTupleNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftTupleNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftTypeAliasNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftTypeAliasNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftTypeAliasNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftTypeAliasNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftTypeListNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftTypeListNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftTypeListNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftTypeListNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftTypeMetadataAccessFunctionNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftTypeMetadataAccessFunctionNode.java similarity index 92% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftTypeMetadataAccessFunctionNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftTypeMetadataAccessFunctionNode.java index 5d0e9efe22..e4f7646da1 100644 --- a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftTypeMetadataAccessFunctionNode.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftTypeMetadataAccessFunctionNode.java @@ -4,9 +4,9 @@ * 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. @@ -19,7 +19,7 @@ import ghidra.app.util.demangler.*; import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind; import ghidra.app.util.demangler.swift.SwiftDemangler; import ghidra.app.util.demangler.swift.datatypes.SwiftFunction; -import ghidra.program.model.lang.CompilerSpec; +import ghidra.app.util.sourcelanguage.SwiftSourceLanguageSpecExtension; /** * A {@link SwiftDemangledNodeKind#TypeMetadataAccessFunction} {@link SwiftNode} @@ -46,7 +46,7 @@ public class SwiftTypeMetadataAccessFunctionNode extends SwiftNode { } SwiftFunction function = new SwiftFunction(properties.mangled(), properties.originalDemangled(), name, namespace, - CompilerSpec.CALLING_CONVENTION_default); + SwiftSourceLanguageSpecExtension.SWIFT_STDCALL); if (namespace instanceof DemangledDataType type) { function.setReturnType(type); } diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftUnsafeMutableAddressorNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftUnsafeMutableAddressorNode.java similarity index 91% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftUnsafeMutableAddressorNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftUnsafeMutableAddressorNode.java index 618bb88583..8eb13bc6a4 100644 --- a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftUnsafeMutableAddressorNode.java +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftUnsafeMutableAddressorNode.java @@ -4,9 +4,9 @@ * 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. @@ -20,7 +20,7 @@ import ghidra.app.util.demangler.DemangledException; import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind; import ghidra.app.util.demangler.swift.SwiftDemangler; import ghidra.app.util.demangler.swift.datatypes.SwiftFunction; -import ghidra.program.model.lang.CompilerSpec; +import ghidra.app.util.sourcelanguage.SwiftSourceLanguageSpecExtension; /** * A {@link SwiftDemangledNodeKind#UnsafeMutableAddressor} {@link SwiftNode} @@ -46,6 +46,6 @@ public class SwiftUnsafeMutableAddressorNode extends SwiftNode { return getUnknown(); } return new SwiftFunction(properties.mangled(), properties.originalDemangled(), name, - namespace, CompilerSpec.CALLING_CONVENTION_default); + namespace, SwiftSourceLanguageSpecExtension.SWIFT_STDCALL); } } diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftUnsupportedNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftUnsupportedNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftUnsupportedNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftUnsupportedNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftVariableNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftVariableNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftVariableNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/SwiftVariableNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/generic/SwiftGenericDescriptorNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/generic/SwiftGenericDescriptorNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/generic/SwiftGenericDescriptorNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/generic/SwiftGenericDescriptorNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/generic/SwiftGenericIndexNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/generic/SwiftGenericIndexNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/generic/SwiftGenericIndexNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/generic/SwiftGenericIndexNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/generic/SwiftGenericPassthroughNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/generic/SwiftGenericPassthroughNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/generic/SwiftGenericPassthroughNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/generic/SwiftGenericPassthroughNode.java diff --git a/Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/generic/SwiftGenericTextNode.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/generic/SwiftGenericTextNode.java similarity index 100% rename from Ghidra/Features/SwiftDemangler/src/main/java/ghidra/app/util/demangler/swift/nodes/generic/SwiftGenericTextNode.java rename to Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/nodes/generic/SwiftGenericTextNode.java diff --git a/Ghidra/Features/Swift/src/main/java/ghidra/app/util/sourcelanguage/ElfSwiftSourceLanguage.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/sourcelanguage/ElfSwiftSourceLanguage.java new file mode 100644 index 0000000000..805c57054c --- /dev/null +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/sourcelanguage/ElfSwiftSourceLanguage.java @@ -0,0 +1,39 @@ +/* ### + * 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.app.util.sourcelanguage; + +import java.util.Arrays; + +import ghidra.app.util.opinion.ElfLoader; +import ghidra.program.model.listing.Program; +import ghidra.program.model.mem.MemoryBlock; +import ghidra.util.task.TaskMonitor; + +/** + * The Elf Swift {@link SourceLanguage} class + */ +public class ElfSwiftSourceLanguage extends SwiftSourceLanguage { + + @Override + public boolean existsIn(Program program, TaskMonitor monitor) { + if (!program.getExecutableFormat().equals(ElfLoader.ELF_NAME)) { + return false; + } + return Arrays.stream(program.getMemory().getBlocks()) + .map(MemoryBlock::getName) + .anyMatch(name -> name.startsWith("swift")); + } +} diff --git a/Ghidra/Features/Swift/src/main/java/ghidra/app/util/sourcelanguage/MachoSwiftSourceLanguage.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/sourcelanguage/MachoSwiftSourceLanguage.java new file mode 100644 index 0000000000..d5384c8704 --- /dev/null +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/sourcelanguage/MachoSwiftSourceLanguage.java @@ -0,0 +1,39 @@ +/* ### + * 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.app.util.sourcelanguage; + +import java.util.Arrays; + +import ghidra.app.util.opinion.MachoLoader; +import ghidra.program.model.listing.Program; +import ghidra.program.model.mem.MemoryBlock; +import ghidra.util.task.TaskMonitor; + +/** + * The Mach-O Swift {@link SourceLanguage} class + */ +public class MachoSwiftSourceLanguage extends SwiftSourceLanguage { + + @Override + public boolean existsIn(Program program, TaskMonitor monitor) { + if (!program.getExecutableFormat().equals(MachoLoader.MACH_O_NAME)) { + return false; + } + return Arrays.stream(program.getMemory().getBlocks()) + .map(MemoryBlock::getName) + .anyMatch(name -> name.startsWith("__swift")); + } +} diff --git a/Ghidra/Features/Swift/src/main/java/ghidra/app/util/sourcelanguage/PeSwiftSourceLanguage.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/sourcelanguage/PeSwiftSourceLanguage.java new file mode 100644 index 0000000000..30bb1b6006 --- /dev/null +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/sourcelanguage/PeSwiftSourceLanguage.java @@ -0,0 +1,39 @@ +/* ### + * 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.app.util.sourcelanguage; + +import java.util.Arrays; + +import ghidra.app.util.opinion.PeLoader; +import ghidra.program.model.listing.Program; +import ghidra.program.model.mem.MemoryBlock; +import ghidra.util.task.TaskMonitor; + +/** + * The PE Swift {@link SourceLanguage} class + */ +public class PeSwiftSourceLanguage extends SwiftSourceLanguage { + + @Override + public boolean existsIn(Program program, TaskMonitor monitor) { + if (!program.getExecutableFormat().equals(PeLoader.PE_NAME)) { + return false; + } + return Arrays.stream(program.getMemory().getBlocks()) + .map(MemoryBlock::getName) + .anyMatch(name -> name.startsWith(".sw5")); + } +} diff --git a/Ghidra/Features/Swift/src/main/java/ghidra/app/util/sourcelanguage/SwiftSourceLanguage.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/sourcelanguage/SwiftSourceLanguage.java new file mode 100644 index 0000000000..5c19cb7388 --- /dev/null +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/sourcelanguage/SwiftSourceLanguage.java @@ -0,0 +1,29 @@ +/* ### + * 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.app.util.sourcelanguage; + +/** + * The base Swift {@link SourceLanguage} class + */ +public abstract class SwiftSourceLanguage implements SourceLanguage { + + public static final SourceLanguageID SWIFT_ID = new SourceLanguageID("Swift"); + + @Override + public SourceLanguageID getID() { + return SWIFT_ID; + } +} diff --git a/Ghidra/Features/Swift/src/main/java/ghidra/app/util/sourcelanguage/SwiftSourceLanguageSpecExtension.java b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/sourcelanguage/SwiftSourceLanguageSpecExtension.java new file mode 100644 index 0000000000..b05e97b4e9 --- /dev/null +++ b/Ghidra/Features/Swift/src/main/java/ghidra/app/util/sourcelanguage/SwiftSourceLanguageSpecExtension.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.app.util.sourcelanguage; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.List; + +import generic.jar.ResourceFile; +import ghidra.app.util.importer.MessageLog; +import ghidra.framework.Application; +import ghidra.program.database.SpecExtension; +import ghidra.program.model.listing.Program; +import ghidra.util.task.TaskMonitor; + +/** + * Swift {@link SpecExtension spec extensions} + */ +public class SwiftSourceLanguageSpecExtension implements SourceLanguageSpecExtension { + + public static final String SWIFT_STDCALL = "__swift_stdcall"; + public static final String SWIFT_THISCALL = "__swift_thiscall"; + + @Override + public SourceLanguageID getCompatibleSourceLanguage() { + return SwiftSourceLanguage.SWIFT_ID; + } + + @Override + public List getSpecExtensionRules(Program program, MessageLog log, + TaskMonitor monitor) { + final String filename = "extensions.json"; + try { + ResourceFile extensionConfigFile = Application.getModuleDataFile(filename); + return SpecExtensionUtils.readSpecExtensionJsonConfig(extensionConfigFile, program, log, + monitor); + } + catch (FileNotFoundException e) { + log.appendMsg("Failed to find module data file: " + filename); + } + catch (IOException e) { + log.appendException(e); + } + return List.of(); + } +} diff --git a/Ghidra/Features/SwiftDemangler/src/test/java/ghidra/app/util/demangler/swift/SwiftDemanglerTest.java b/Ghidra/Features/Swift/src/test/java/ghidra/app/util/demangler/swift/SwiftDemanglerTest.java similarity index 92% rename from Ghidra/Features/SwiftDemangler/src/test/java/ghidra/app/util/demangler/swift/SwiftDemanglerTest.java rename to Ghidra/Features/Swift/src/test/java/ghidra/app/util/demangler/swift/SwiftDemanglerTest.java index 7ad9f33d95..fa4d065e24 100644 --- a/Ghidra/Features/SwiftDemangler/src/test/java/ghidra/app/util/demangler/swift/SwiftDemanglerTest.java +++ b/Ghidra/Features/Swift/src/test/java/ghidra/app/util/demangler/swift/SwiftDemanglerTest.java @@ -197,7 +197,7 @@ public class SwiftDemanglerTest extends AbstractGenericTest { String mangled = "_$s18SwiftDemanglerTest25testJunitFunctionAndTypes_6label2___________7label14____Si_SftSiz_s4Int8Vs5Int16Vs5Int32Vs5Int64VSus5UInt8Vs6UInt16Vs6UInt32Vs6UInt64VS2fS2dSSSaySiGSbSJtF"; String demangled = - "struct tuple2 default SwiftDemanglerTest::testJunitFunctionAndTypes(__int64 *,__int8 label2,__int16,__int32,__int64,unsigned __int64,unsigned __int8,unsigned __int16,unsigned __int32,unsigned __int64,float,float,double,double label14,struct Swift::String,Swift::Array<__int64>[],bool,struct Swift::Character)"; + "struct tuple2 __swift_stdcall SwiftDemanglerTest::testJunitFunctionAndTypes(__int64 *,__int8 label2,__int16,__int32,__int64,unsigned __int64,unsigned __int8,unsigned __int16,unsigned __int32,unsigned __int64,float,float,double,double label14,struct Swift::String,Swift::Array<__int64>[],bool,struct Swift::Character)"; if (!(demangler.demangle(mangled) instanceof DemangledFunction function)) { throw new AssertException("Demangled object is not a function"); @@ -241,7 +241,7 @@ public class SwiftDemanglerTest extends AbstractGenericTest { **********************************************************************/ String mangled = "_$s18SwiftDemanglerTest11MyStructureV6label1ACSi_tcfC"; String demangled = - "struct SwiftDemanglerTest::MyStructure default SwiftDemanglerTest::MyStructure::init(__int64 label1)"; + "struct SwiftDemanglerTest::MyStructure __swift_stdcall SwiftDemanglerTest::MyStructure::init(__int64 label1)"; if (!(demangler.demangle(mangled) instanceof DemangledFunction function)) { throw new AssertException("Demangled object is not a function"); @@ -285,7 +285,7 @@ public class SwiftDemanglerTest extends AbstractGenericTest { **********************************************************************/ String mangled = "_$s18SwiftDemanglerTest11MyStructureV8myMethod6label16label2S2i_SitF"; String demangled = - "__int64 default SwiftDemanglerTest::MyStructure::myMethod(__int64 label1,__int64 label2,struct SwiftDemanglerTest::MyStructure)"; + "__int64 __swift_stdcall SwiftDemanglerTest::MyStructure::myMethod(__int64 label1,__int64 label2,struct SwiftDemanglerTest::MyStructure)"; if (!(demangler.demangle(mangled) instanceof DemangledFunction function)) { throw new AssertException("Demangled object is not a function"); @@ -311,7 +311,7 @@ public class SwiftDemanglerTest extends AbstractGenericTest { **********************************************************************/ String mangled = "_$s18SwiftDemanglerTest11MyStructureV1zSivg"; String demangled = - "__int64 default SwiftDemanglerTest::MyStructure::get_z(struct SwiftDemanglerTest::MyStructure)"; + "__int64 __swift_stdcall SwiftDemanglerTest::MyStructure::get_z(struct SwiftDemanglerTest::MyStructure)"; if (!(demangler.demangle(mangled) instanceof DemangledFunction function)) { throw new AssertException("Demangled object is not a function"); @@ -336,7 +336,7 @@ public class SwiftDemanglerTest extends AbstractGenericTest { SwiftDemanglerTest.MyStructure.z.setter : Swift.Int **********************************************************************/ String mangled = "_$s18SwiftDemanglerTest11MyStructureV1zSivs"; - String demangled = "__thiscall SwiftDemanglerTest::MyStructure::set_z(__int64)"; + String demangled = "__swift_thiscall SwiftDemanglerTest::MyStructure::set_z(__int64)"; if (!(demangler.demangle(mangled) instanceof DemangledFunction function)) { throw new AssertException("Demangled object is not a function"); @@ -370,7 +370,7 @@ public class SwiftDemanglerTest extends AbstractGenericTest { **********************************************************************/ String mangled = "_$s18SwiftDemanglerTest11MyStructureVyS2icig"; String demangled = - "__int64 default SwiftDemanglerTest::MyStructure::get_subscript(__int64,struct SwiftDemanglerTest::MyStructure)"; + "__int64 __swift_stdcall SwiftDemanglerTest::MyStructure::get_subscript(__int64,struct SwiftDemanglerTest::MyStructure)"; if (!(demangler.demangle(mangled) instanceof DemangledFunction function)) { throw new AssertException("Demangled object is not a function"); @@ -404,7 +404,7 @@ public class SwiftDemanglerTest extends AbstractGenericTest { **********************************************************************/ String mangled = "_$s18SwiftDemanglerTest11MyStructureVyS2icis"; String demangled = - "__int64 __thiscall SwiftDemanglerTest::MyStructure::set_subscript(__int64)"; + "__int64 __swift_thiscall SwiftDemanglerTest::MyStructure::set_subscript(__int64)"; if (!(demangler.demangle(mangled) instanceof DemangledFunction function)) { throw new AssertException("Demangled object is not a function"); @@ -425,7 +425,7 @@ public class SwiftDemanglerTest extends AbstractGenericTest { **********************************************************************/ String mangled = "_$s18SwiftDemanglerTest7MyClassCMa"; String demangled = - "class SwiftDemanglerTest::MyClass * default SwiftDemanglerTest::MyClass::typeMetadataAccessor(void)"; + "class SwiftDemanglerTest::MyClass * __swift_stdcall SwiftDemanglerTest::MyClass::typeMetadataAccessor(void)"; if (!(demangler.demangle(mangled) instanceof DemangledFunction function)) { throw new AssertException("Demangled object is not a function"); @@ -462,7 +462,7 @@ public class SwiftDemanglerTest extends AbstractGenericTest { **********************************************************************/ String mangled = "_$s18SwiftDemanglerTest7MyClassC6label1ACSi_tcfC"; String demangled = - "class SwiftDemanglerTest::MyClass * __thiscall SwiftDemanglerTest::MyClass::__allocating_init(__int64 label1)"; + "class SwiftDemanglerTest::MyClass * __swift_thiscall SwiftDemanglerTest::MyClass::__allocating_init(__int64 label1)"; if (!(demangler.demangle(mangled) instanceof DemangledFunction function)) { throw new AssertException("Demangled object is not a function"); @@ -499,7 +499,7 @@ public class SwiftDemanglerTest extends AbstractGenericTest { **********************************************************************/ String mangled = "_$s18SwiftDemanglerTest7MyClassC6label1ACSi_tcfc"; String demangled = - "class SwiftDemanglerTest::MyClass * __thiscall SwiftDemanglerTest::MyClass::init(__int64 label1)"; + "class SwiftDemanglerTest::MyClass * __swift_thiscall SwiftDemanglerTest::MyClass::init(__int64 label1)"; if (!(demangler.demangle(mangled) instanceof DemangledFunction function)) { throw new AssertException("Demangled object is not a function"); @@ -543,7 +543,7 @@ public class SwiftDemanglerTest extends AbstractGenericTest { **********************************************************************/ String mangled = "_$s18SwiftDemanglerTest7MyClassC8myMethod6label16label2S2i_SitF"; String demangled = - "__int64 __thiscall SwiftDemanglerTest::MyClass::myMethod(__int64 label1,__int64 label2)"; + "__int64 __swift_thiscall SwiftDemanglerTest::MyClass::myMethod(__int64 label1,__int64 label2)"; if (!(demangler.demangle(mangled) instanceof DemangledFunction function)) { throw new AssertException("Demangled object is not a function"); @@ -569,7 +569,7 @@ public class SwiftDemanglerTest extends AbstractGenericTest { **********************************************************************/ String mangled = "_$s18SwiftDemanglerTest7MyClassC1zSivg"; String demangled = - "__int64 __thiscall SwiftDemanglerTest::MyClass::get_z(class SwiftDemanglerTest::MyClass *)"; + "__int64 __swift_thiscall SwiftDemanglerTest::MyClass::get_z(class SwiftDemanglerTest::MyClass *)"; if (!(demangler.demangle(mangled) instanceof DemangledFunction function)) { throw new AssertException("Demangled object is not a function"); @@ -594,7 +594,7 @@ public class SwiftDemanglerTest extends AbstractGenericTest { SwiftDemanglerTest.MyClass.z.setter : Swift.Int **********************************************************************/ String mangled = "_$s18SwiftDemanglerTest7MyClassC1zSivs"; - String demangled = "__thiscall SwiftDemanglerTest::MyClass::set_z(__int64)"; + String demangled = "__swift_thiscall SwiftDemanglerTest::MyClass::set_z(__int64)"; if (!(demangler.demangle(mangled) instanceof DemangledFunction function)) { throw new AssertException("Demangled object is not a function"); @@ -619,7 +619,7 @@ public class SwiftDemanglerTest extends AbstractGenericTest { SwiftDemanglerTest.MyClass.z.modify : Swift.Int **********************************************************************/ String mangled = "_$s18SwiftDemanglerTest7MyClassC1zSivM"; - String demangled = "__thiscall SwiftDemanglerTest::MyClass::modify_z(__int64)"; + String demangled = "__swift_thiscall SwiftDemanglerTest::MyClass::modify_z(__int64)"; if (!(demangler.demangle(mangled) instanceof DemangledFunction function)) { throw new AssertException("Demangled object is not a function"); @@ -638,7 +638,8 @@ public class SwiftDemanglerTest extends AbstractGenericTest { SwiftDemanglerTest.MyClass.__deallocating_deinit **********************************************************************/ String mangled = "_$s18SwiftDemanglerTest7MyClassCfD"; - String demangled = "__thiscall SwiftDemanglerTest::MyClass::__deallocating_init(void)"; + String demangled = + "__swift_thiscall SwiftDemanglerTest::MyClass::__deallocating_init(void)"; if (!(demangler.demangle(mangled) instanceof DemangledFunction function)) { throw new AssertException("Demangled object is not a function"); @@ -658,7 +659,7 @@ public class SwiftDemanglerTest extends AbstractGenericTest { **********************************************************************/ String mangled = "_$s18SwiftDemanglerTest7MyClassCfd"; String demangled = - "class SwiftDemanglerTest::MyClass * __thiscall SwiftDemanglerTest::MyClass::deinit(void)"; + "class SwiftDemanglerTest::MyClass * __swift_thiscall SwiftDemanglerTest::MyClass::deinit(void)"; if (!(demangler.demangle(mangled) instanceof DemangledFunction function)) { throw new AssertException("Demangled object is not a function"); @@ -696,7 +697,7 @@ public class SwiftDemanglerTest extends AbstractGenericTest { **********************************************************************/ String mangled = "_$s18SwiftDemanglerTest16MyAssociatedEnumO8myMethod6label1ACSi_tF"; String demangled = - "struct SwiftDemanglerTest::MyAssociatedEnum default SwiftDemanglerTest::MyAssociatedEnum::myMethod(__int64 label1,struct SwiftDemanglerTest::MyAssociatedEnum,undefined)"; + "struct SwiftDemanglerTest::MyAssociatedEnum __swift_stdcall SwiftDemanglerTest::MyAssociatedEnum::myMethod(__int64 label1,struct SwiftDemanglerTest::MyAssociatedEnum,undefined)"; if (!(demangler.demangle(mangled) instanceof DemangledFunction function)) { throw new AssertException("Demangled object is not a function"); diff --git a/Ghidra/Features/SwiftDemangler/certification.manifest b/Ghidra/Features/SwiftDemangler/certification.manifest deleted file mode 100644 index 6841c5219a..0000000000 --- a/Ghidra/Features/SwiftDemangler/certification.manifest +++ /dev/null @@ -1,3 +0,0 @@ -##VERSION: 2.0 -Module.manifest||GHIDRA||||END| -README.md||GHIDRA||||END| diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/sourcelanguage/DataArchiveUtils.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/sourcelanguage/DataArchiveUtils.java new file mode 100644 index 0000000000..179173255a --- /dev/null +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/sourcelanguage/DataArchiveUtils.java @@ -0,0 +1,79 @@ +/* ### + * 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.app.util.sourcelanguage; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; + +import com.google.gson.Gson; +import com.google.gson.stream.JsonReader; + +import generic.jar.ResourceFile; +import ghidra.app.util.importer.MessageLog; +import ghidra.app.util.sourcelanguage.SourceLanguageDataArchive.DataArchiveRule; +import ghidra.app.util.sourcelanguage.SourceLanguageSpecExtension.SpecExtensionRule; +import ghidra.program.database.SpecExtension; +import ghidra.program.model.listing.Program; +import ghidra.util.task.TaskMonitor; + +public class DataArchiveUtils { + + /** + * An entry from a spec extension JSON configuration file + * + * @param processor The name of the processor (could be empty/null for wildcard) + * @param endian The processor endianness ("little" or "big") (could be empty/null for wildcard) + * @param size The processor size (i.e., "32, "64", etc) (could be empty/null for wildcard) + * @param variant The processor variant (could be empty/null for wildcard) + * @param formats The names of the binary file formats (could be empty/null for wildcard) + * @param file The file path (relative to the JSON configuration file) of the data archive file + * to add + */ + private record JsonEntry(String processor, String endian, String size, String variant, + List formats, String file) {} + + /** + * {@return a {@link List} of {@link SpecExtensionRule}s based on the given JSON configuration + * file} + * + * @param jsonFile The JSON configuration file + * @param program The {@link Program} + * @param log The error log + * @param monitor The monitor + * @throws IOException if there was a problem reading the JSON configuration file or the + * {@link SpecExtension} XML files it references + */ + public static List readDataArchiveJsonConfig(ResourceFile jsonFile, + Program program, MessageLog log, TaskMonitor monitor) throws IOException { + List ret = new ArrayList<>(); + try (JsonReader reader = new JsonReader(new InputStreamReader(jsonFile.getInputStream()))) { + JsonEntry[] entries = new Gson().fromJson(reader, JsonEntry[].class); + if (entries == null) { + throw new EOFException(jsonFile + " was at end of file"); + } + for (JsonEntry entry : entries) { + if (entry == null) { + continue; + } + ResourceFile file = new ResourceFile(jsonFile.getParentFile(), entry.file()); + ret.add(new DataArchiveRule(entry.processor(), entry.endian(), entry.size(), + entry.variant(), entry.formats(), file)); + } + } + return ret; + } +} diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/sourcelanguage/SourceLanguage.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/sourcelanguage/SourceLanguage.java new file mode 100644 index 0000000000..c9f1923c58 --- /dev/null +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/sourcelanguage/SourceLanguage.java @@ -0,0 +1,45 @@ +/* ### + * 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.app.util.sourcelanguage; + +import java.io.IOException; + +import ghidra.program.model.listing.Program; +import ghidra.util.classfinder.ExtensionPoint; +import ghidra.util.exception.CancelledException; +import ghidra.util.task.TaskMonitor; + +/** + * An {@link ExtensionPoint} to dynamically support source language-specific features + */ +public interface SourceLanguage extends ExtensionPoint { + + /** + * {@return the {@link SourceLanguageID ID} of the source language} + */ + public SourceLanguageID getID(); + + /** + * {@return true if the source language exists in the given {@link Program}; otherwise false} + * + * @param program The {@link Program} + * @param monitor The {@link TaskMonitor} + * @throws IOException if an IO-related error occurred + * @throws CancelledException if the user cancelled the operation + */ + public boolean existsIn(Program program, TaskMonitor monitor) + throws IOException, CancelledException; +} diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/sourcelanguage/SourceLanguageDataArchive.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/sourcelanguage/SourceLanguageDataArchive.java new file mode 100644 index 0000000000..4c67064f16 --- /dev/null +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/sourcelanguage/SourceLanguageDataArchive.java @@ -0,0 +1,61 @@ +/* ### + * 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.app.util.sourcelanguage; + +import java.util.List; + +import generic.jar.ResourceFile; +import ghidra.app.util.importer.MessageLog; +import ghidra.program.model.listing.Program; +import ghidra.util.classfinder.ExtensionPoint; +import ghidra.util.task.TaskMonitor; + +/** + * An {@link ExtensionPoint} to dynamically support source language-specific data archives + */ +public interface SourceLanguageDataArchive extends ExtensionPoint { + + /** + * Processor-related attributes that form conditions for applying the given data archive + * contents to a program + * + * @param processor The name of the processor (required) + * @param endian The processor endianness ("little" or "big") (could be empty/null for wildcard) + * @param size The processor size (i.e., "32, "64", etc) (could be empty/null for wildcard) + * @param variant The processor variant (could be empty/null for wildcard) + * @param formats The names of the supported binary file formats (could be empty/null for + * wildcard) + * @param dataArchiveFile The data archive file + */ + public record DataArchiveRule(String processor, String endian, String size, String variant, + List formats, ResourceFile dataArchiveFile) {} + + /** + * {@return the {@link SourceLanguageID} of the source language this + * {@link SourceLanguageDataArchive} is compatible with} + */ + public SourceLanguageID getCompatibleSourceLanguage(); + + /** + * {@return the source language's {@link DataArchiveRule}s} + * + * @param program The {@link Program} + * @param log The error log + * @param monitor The {@link TaskMonitor} + */ + public List getDataArchiveRules(Program program, MessageLog log, + TaskMonitor monitor); +} diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/sourcelanguage/SourceLanguageID.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/sourcelanguage/SourceLanguageID.java new file mode 100644 index 0000000000..303ef3645e --- /dev/null +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/sourcelanguage/SourceLanguageID.java @@ -0,0 +1,83 @@ +/* ### + * 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.app.util.sourcelanguage; + +import java.util.Objects; +import java.util.regex.Pattern; + +import org.apache.commons.lang3.StringUtils; + +/** + * Represents a {@link SourceLanguage source language}'s ID + */ +public class SourceLanguageID implements Comparable { + + private static final Pattern VALID_ID_PATTERN = Pattern.compile("^[a-zA-Z0-9_.-]+$"); + + private final String id; + + /** + * Creates a new {@link SourceLanguageID}. + *

+ * An ID must not be blank or contain commas. + * + * @param id The {@link SourceLanguage}'s ID + * @throws IllegalArgumentException if the ID blank, null, or contains commas + */ + public SourceLanguageID(String id) { + if (StringUtils.isBlank(id)) { + throw new IllegalArgumentException("Source language 'id' cannot be null or blank"); + } + if (!VALID_ID_PATTERN.matcher(id).matches()) { + throw new IllegalArgumentException( + "Source language 'id' does not match regex: " + VALID_ID_PATTERN); + } + this.id = id; + } + + /** + * {@return the {@link SourceLanguage} ID as a string} + */ + public String getIdAsString() { + return id; + } + + @Override + public String toString() { + return id; + } + + @Override + public int compareTo(SourceLanguageID o) { + return id.compareTo(o.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof SourceLanguageID other)) { + return false; + } + return Objects.equals(id, other.id); + } +} diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/sourcelanguage/SourceLanguageService.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/sourcelanguage/SourceLanguageService.java new file mode 100644 index 0000000000..94a823777c --- /dev/null +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/sourcelanguage/SourceLanguageService.java @@ -0,0 +1,225 @@ +/* ### + * 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.app.util.sourcelanguage; + +import java.io.IOException; +import java.util.*; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; + +import generic.jar.ResourceFile; +import ghidra.app.util.importer.MessageLog; +import ghidra.app.util.sourcelanguage.SourceLanguageDataArchive.DataArchiveRule; +import ghidra.app.util.sourcelanguage.SourceLanguageSpecExtension.SpecExtensionRule; +import ghidra.program.database.SpecExtension; +import ghidra.program.database.SpecExtension.DocInfo; +import ghidra.program.model.lang.LanguageDescription; +import ghidra.program.model.listing.Program; +import ghidra.util.classfinder.ClassSearcher; +import ghidra.util.classfinder.ExtensionPoint; +import ghidra.util.exception.CancelledException; +import ghidra.util.task.TaskMonitor; + +/** + * A service for applying source language-related {@link ExtensionPoint}s to a {@link Program} + */ +public class SourceLanguageService { + + /** + * Finds any {@link SourceLanguage}s that + * {@link SourceLanguage#existsIn(Program, TaskMonitor) exist in} the given program, and + * returns their {@link SourceLanguageID}s. + *

+ * NOTE: This method does a fresh scan using + * {@link SourceLanguage#existsIn(Program, TaskMonitor)} and does not check + * {@link Program#getSourceLanguageIDs()}, so it may be slow. + * + * @param program The {@link Program} + * @param log The error log + * @param monitor The {@link TaskMonitor} + * @return The {@link SourceLanguageID}s of the found {@link SourceLanguage}s + * @throws CancelledException if the user cancelled the operation + */ + public static Set find(Program program, MessageLog log, TaskMonitor monitor) + throws CancelledException { + Set foundSet = new HashSet<>(); + for (SourceLanguage sourceLanguage : ClassSearcher.getInstances(SourceLanguage.class)) { + monitor.checkCancelled(); + SourceLanguageID id = sourceLanguage.getID(); + if (foundSet.contains(id)) { + continue; + } + try { + if (sourceLanguage.existsIn(program, monitor)) { + foundSet.add(id); + } + } + catch (IOException e) { + log.appendMsg("Problem checking for %s in %s: %s".formatted(id, program.getName(), + e.getMessage())); + } + } + return foundSet; + } + + /** + * Adds any {@link SourceLanguageSpecExtension}s that are compatible with the given set of + * {@link SourceLanguageID}s to the {@link Program} + * + * @param program The {@link Program} + * @param sourceLanguageIDs The {@link SourceLanguageID}s + * @param log The error log + * @param monitor The {@link TaskMonitor} + */ + public static void addSpecExtensions(Program program, Set sourceLanguageIDs, + MessageLog log, TaskMonitor monitor) { + for (SourceLanguageSpecExtension slse : ClassSearcher + .getInstances(SourceLanguageSpecExtension.class)) { + if (!sourceLanguageIDs.contains(slse.getCompatibleSourceLanguage())) { + continue; + } + for (SpecExtensionRule rule : slse.getSpecExtensionRules(program, log, monitor)) { + try { + processSpecExtensionRule(rule, program, log, monitor); + } + catch (Exception e) { + log.appendMsg("Failed to process spec extension: " + e.getMessage()); + } + } + } + } + + /** + * Processes a single {@link SpecExtensionRule} and adds the spec extension it defines to the + * given {@link Program} + * + * @param rule The {@link SpecExtensionRule} to process + * @param program The {@link Program} + * @param log The error log + * @param monitor The {@link TaskMonitor} + * @return True if a spec extension was added to the {@link Program}; otherwise, false + * @throws Exception if there was a problem processing the {@link SpecExtensionRule} + */ + private static boolean processSpecExtensionRule(SpecExtensionRule rule, Program program, + MessageLog log, TaskMonitor monitor) throws Exception { + LanguageDescription desc = program.getLanguageCompilerSpecPair().getLanguageDescription(); + String programProcessor = desc.getProcessor().toString(); + String programEndian = desc.getEndian().toString(); + String programSize = Integer.toString(desc.getSize()); + String programVariant = desc.getVariant(); + String programFormat = program.getExecutableFormat(); + + if (!rule.processor().equals(programProcessor)) { + return false; + } + if (!StringUtils.isEmpty(rule.endian()) && !rule.endian().equals(programEndian)) { + return false; + } + if (!StringUtils.isEmpty(rule.size()) && !rule.size().equals(programSize)) { + return false; + } + if (!StringUtils.isEmpty(rule.variant()) && !rule.variant().equals(programVariant)) { + return false; + } + if (!CollectionUtils.isEmpty(rule.formats()) && + rule.formats().stream().noneMatch(programFormat::equals)) { + return false; + } + + SpecExtension specExtension = new SpecExtension(program); + String xml = rule.contents(); + DocInfo docInfo = specExtension.testExtensionDocument(xml); + if (SpecExtension.getCompilerSpecExtension(program, docInfo) == null) { + specExtension.addReplaceCompilerSpecExtension(xml, monitor); + } + return true; + } + + /** + * Adds any {@link SourceLanguageDataArchive}s that are compatible with the given set of + * {@link SourceLanguageID}s to the {@link Program} + * + * @param program The {@link Program} + * @param sourceLanguageIDs The {@link SourceLanguage} + * @param log The error log + * @param monitor The {@link TaskMonitor} + * @return The number of data archives that were added to the {@link Program} + */ + public static List getDataArchives(Program program, + Set sourceLanguageIDs, MessageLog log, TaskMonitor monitor) { + List ret = new ArrayList<>(); + for (SourceLanguageDataArchive slda : ClassSearcher + .getInstances(SourceLanguageDataArchive.class)) { + if (!sourceLanguageIDs.contains(slda.getCompatibleSourceLanguage())) { + continue; + } + for (DataArchiveRule rule : slda.getDataArchiveRules(program, log, monitor)) { + try { + ResourceFile file = processDataArchiveRule(rule, program, log, monitor); + if (file != null) { + ret.add(file); + } + } + catch (Exception e) { + log.appendMsg("Failed to process data archive: " + e.getMessage()); + } + } + } + return ret; + } + + /** + * Processes a single {@link DataArchiveRule} and returns the data archive file if the archive + * should be applied to the program + * + * @param rule The {@link DataArchiveRule} to process + * @param program The {@link Program} + * @param log The error log + * @param monitor The {@link TaskMonitor} + * @return The data archive file that should be applied to the program, or {@code null} if + * it should not be applied + * @throws Exception if there was a problem processing the {@link DataArchiveRule} + */ + private static ResourceFile processDataArchiveRule(DataArchiveRule rule, Program program, + MessageLog log, TaskMonitor monitor) throws Exception { + LanguageDescription desc = program.getLanguageCompilerSpecPair().getLanguageDescription(); + String programProcessor = desc.getProcessor().toString(); + String programEndian = desc.getEndian().toString(); + String programSize = Integer.toString(desc.getSize()); + String programVariant = desc.getVariant(); + String programFormat = program.getExecutableFormat(); + + if (!StringUtils.isEmpty(rule.processor()) && !rule.processor().equals(programProcessor)) { + return null; + } + if (!StringUtils.isEmpty(rule.endian()) && !rule.endian().equals(programEndian)) { + return null; + } + if (!StringUtils.isEmpty(rule.size()) && !rule.size().equals(programSize)) { + return null; + } + if (!StringUtils.isEmpty(rule.variant()) && !rule.variant().equals(programVariant)) { + return null; + } + if (!CollectionUtils.isEmpty(rule.formats()) && + rule.formats().stream().noneMatch(programFormat::equals)) { + return null; + } + + return rule.dataArchiveFile(); + } +} diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/sourcelanguage/SourceLanguageSpecExtension.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/sourcelanguage/SourceLanguageSpecExtension.java new file mode 100644 index 0000000000..77aad0b26a --- /dev/null +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/sourcelanguage/SourceLanguageSpecExtension.java @@ -0,0 +1,62 @@ +/* ### + * 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.app.util.sourcelanguage; + +import java.util.List; + +import ghidra.app.util.importer.MessageLog; +import ghidra.program.database.SpecExtension; +import ghidra.program.model.listing.Program; +import ghidra.util.classfinder.ExtensionPoint; +import ghidra.util.task.TaskMonitor; + +/** + * An {@link ExtensionPoint} to dynamically support source language-specific + * {@link SpecExtension spec extensions} + */ +public interface SourceLanguageSpecExtension extends ExtensionPoint { + + /** + * Processor-related attributes that form conditions for applying the given spec extension + * contents to a program + * + * @param processor The name of the processor (required) + * @param endian The processor endianness ("little" or "big") (could be empty/null for wildcard) + * @param size The processor size (i.e., "32, "64", etc) (could be empty/null for wildcard) + * @param variant The processor variant (could be empty/null for wildcard) + * @param formats The names of the supported binary file formats (could be empty/null for + * wildcard) + * @param contents The contents of the {@link SpecExtension}, which is currently always XML + */ + public record SpecExtensionRule(String processor, String endian, String size, String variant, + List formats, String contents) {} + + /** + * {@return the {@link SourceLanguageID} of the source language this + * {@link SourceLanguageSpecExtension} is compatible with} + */ + public SourceLanguageID getCompatibleSourceLanguage(); + + /** + * {@return the source language's {@link SpecExtensionRule}s} + * + * @param program The {@link Program} + * @param log The error log + * @param monitor The {@link TaskMonitor} + */ + public List getSpecExtensionRules(Program program, MessageLog log, + TaskMonitor monitor); +} diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/sourcelanguage/SpecExtensionUtils.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/sourcelanguage/SpecExtensionUtils.java new file mode 100644 index 0000000000..49bfc37ac4 --- /dev/null +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/sourcelanguage/SpecExtensionUtils.java @@ -0,0 +1,107 @@ +/* ### + * 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.app.util.sourcelanguage; + +import java.io.*; +import java.util.*; + +import com.google.gson.Gson; +import com.google.gson.stream.JsonReader; + +import generic.jar.ResourceFile; +import ghidra.app.util.importer.MessageLog; +import ghidra.app.util.sourcelanguage.SourceLanguageSpecExtension.SpecExtensionRule; +import ghidra.program.database.SpecExtension; +import ghidra.program.model.listing.Program; +import ghidra.util.task.TaskMonitor; + +public class SpecExtensionUtils { + + /** + * An entry from a spec extension JSON configuration file + * + * @param processor The name of the processor (required) + * @param endian The processor endianness ("little" or "big") (could be empty/null for wildcard) + * @param size The processor size (i.e., "32, "64", etc) (could be empty/null for wildcard) + * @param variant The processor variant (could be empty/null for wildcard) + * @param formats The names of the binary file formats (could be empty/null for wildcard) + * @param directory The directory path (relative to the JSON configuration file) of the spec + * extension files to add + */ + private record JsonEntry(String processor, String endian, String size, String variant, + List formats, String directory) {} + + + /** + * {@return the given {@link SpecExtension} XML file's contents} + * + * @param xmlFile A {@link SpecExtension} XML file + * @throws IOException if there was a problem reading the XML file + */ + public static String readSpecExtensionXmlFile(ResourceFile xmlFile) throws IOException { + return new String(xmlFile.getInputStream().readAllBytes()); + } + + /** + * {@return a {@link List} of {@link SpecExtension} XML file contents found in the given + * directory} + * + * @param dir A directory containing {@link SpecExtension} XML files + * @throws IOException if there was a problem reading the XML files + */ + public static List readSpecExtensionDir(ResourceFile dir) throws IOException { + List ret = new ArrayList<>(); + ResourceFile[] files = Objects.requireNonNullElse(dir.listFiles(), new ResourceFile[0]); + for (ResourceFile f : files) { + ret.add(readSpecExtensionXmlFile(f)); + } + return ret; + } + + /** + * {@return a {@link List} of {@link SpecExtensionRule}s based on the given JSON configuration + * file} + * + * @param jsonFile The JSON configuration file + * @param program The {@link Program} + * @param log The error log + * @param monitor The monitor + * @throws IOException if there was a problem reading the JSON configuration file or the + * {@link SpecExtension} XML files it references + */ + public static List readSpecExtensionJsonConfig(ResourceFile jsonFile, + Program program, MessageLog log, TaskMonitor monitor) throws IOException { + List ret = new ArrayList<>(); + try (JsonReader reader = new JsonReader(new InputStreamReader(jsonFile.getInputStream()))) { + JsonEntry[] entries = new Gson().fromJson(reader, JsonEntry[].class); + if (entries == null) { + throw new EOFException(jsonFile + " was at end of file"); + } + for (JsonEntry entry : entries) { + if (entry == null) { + continue; + } + ResourceFile dir = new ResourceFile(jsonFile.getParentFile(), entry.directory()); + List specExtensionXmls = readSpecExtensionDir(dir); + for (String xml : specExtensionXmls) { + ret.add(new SpecExtensionRule(entry.processor(), entry.endian(), + entry.size(), entry.variant(), entry.formats(), xml)); + } + } + } + return ret; + } +} diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/ProgramDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/ProgramDB.java index e54be07605..e3bee45402 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/ProgramDB.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/ProgramDB.java @@ -18,12 +18,14 @@ package ghidra.program.database; import java.io.IOException; import java.math.BigInteger; import java.util.*; +import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import db.DBHandle; import ghidra.app.plugin.processors.generic.LanguageFixupUtil; import ghidra.app.plugin.processors.sleigh.SleighLanguage; +import ghidra.app.util.sourcelanguage.SourceLanguageID; import ghidra.framework.Application; import ghidra.framework.data.DomainObjectAdapterDB; import ghidra.framework.data.OpenMode; @@ -162,6 +164,7 @@ public class ProgramDB extends DomainObjectAdapterDB implements Program, ChangeM private static final String EXECUTE_PATH = "Execute Path"; private static final String EXECUTE_FORMAT = "Execute Format"; private static final String IMAGE_OFFSET = "Image Offset"; + private static final String SOURCE_LANGUAGES = "Source Languages"; // // The numbering of managers controls the order in which they are notified. @@ -643,6 +646,28 @@ public class ProgramDB extends DomainObjectAdapterDB implements Program, ChangeM pl.setString(COMPILER, compiler); } + @Override + public Set getSourceLanguageIDs() { + Set ret = new HashSet<>(); + String value = getOptions(PROGRAM_INFO).getString(SOURCE_LANGUAGES, ""); + for (String entry : value.split(",")) { + entry = entry.trim(); + if (!entry.isEmpty()) { + ret.add(new SourceLanguageID(entry)); + } + } + return ret; + } + + @Override + public void setSourceLanguageIDs(Set sourceLanguageIDs) { + String combined = sourceLanguageIDs.stream() + .map(SourceLanguageID::getIdAsString) + .sorted() + .collect(Collectors.joining(", ")); + getOptions(PROGRAM_INFO).setString(SOURCE_LANGUAGES, combined); + } + @Override public CategoryPath getPreferredRootNamespaceCategoryPath() { return preferredRootNamespaceCategory; diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/Program.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/Program.java index 792c82ecdf..71b0c75ecb 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/Program.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/Program.java @@ -16,7 +16,9 @@ package ghidra.program.model.listing; import java.util.Date; +import java.util.Set; +import ghidra.app.util.sourcelanguage.SourceLanguageID; import ghidra.framework.store.LockException; import ghidra.program.database.IntRangeMap; import ghidra.program.database.ProgramOverlayAddressSpace; @@ -179,6 +181,22 @@ public interface Program extends DataTypeManagerDomainObject, ProgramArchitectur */ public void setCompiler(String compiler); + /** + * {@return the {@link SourceLanguageID}s of the source languages found in the program} + */ + default public Set getSourceLanguageIDs() { + return Set.of(); + } + + /** + * Sets the {@link SourceLanguageID}s of the source languages found in the program + * + * @param sourceLanguageIDs The {@link Set} of {@link SourceLanguageID}s + */ + default public void setSourceLanguageIDs(Set sourceLanguageIDs) { + throw new UnsupportedOperationException(); + } + /** * Gets the preferred root data type category path which corresponds * to the global namespace of a namespace-based storage area. Preference diff --git a/Ghidra/Processors/AARCH64/certification.manifest b/Ghidra/Processors/AARCH64/certification.manifest index 28010dca3d..824c6bcf3f 100644 --- a/Ghidra/Processors/AARCH64/certification.manifest +++ b/Ghidra/Processors/AARCH64/certification.manifest @@ -2,14 +2,6 @@ Module.manifest||GHIDRA||||END| README.md||GHIDRA||||END| data/aarch64-pltThunks.xml||GHIDRA||||END| -data/extensions/objc/chkstk_darwin_fixup.xml||GHIDRA||||END| -data/extensions/objc/objc_getProperty_fixup.xml||GHIDRA||||END| -data/extensions/objc/objc_load_fixup.xml||GHIDRA||||END| -data/extensions/objc/objc_msgSend_stub.xml||GHIDRA||||END| -data/extensions/objc/objc_release_fixup.xml||GHIDRA||||END| -data/extensions/objc/objc_retain_fixup.xml||GHIDRA||||END| -data/extensions/objc/objc_setProperty_fixup.xml||GHIDRA||||END| -data/extensions/objc/objc_store_fixup.xml||GHIDRA||||END| data/languages/AARCH64.cspec||GHIDRA||||END| data/languages/AARCH64.dwarf||GHIDRA||||END| data/languages/AARCH64.ldefs||GHIDRA||||END| @@ -24,7 +16,6 @@ data/languages/AARCH64_base_PACoptions.sinc||GHIDRA||||END| data/languages/AARCH64_golang.cspec||GHIDRA||||END| data/languages/AARCH64_golang.register.info||GHIDRA||||END| data/languages/AARCH64_ilp32.cspec||GHIDRA||||END| -data/languages/AARCH64_swift.cspec||GHIDRA||||END| data/languages/AARCH64_win.cspec||GHIDRA||||END| data/languages/AARCH64base.sinc||GHIDRA||||END| data/languages/AARCH64instructions.sinc||GHIDRA||||END| diff --git a/Ghidra/Processors/AARCH64/data/languages/AARCH64.ldefs b/Ghidra/Processors/AARCH64/data/languages/AARCH64.ldefs index 633ec3d451..58bb44108b 100644 --- a/Ghidra/Processors/AARCH64/data/languages/AARCH64.ldefs +++ b/Ghidra/Processors/AARCH64/data/languages/AARCH64.ldefs @@ -13,7 +13,6 @@ - diff --git a/Ghidra/Processors/AARCH64/data/languages/AARCH64.opinion b/Ghidra/Processors/AARCH64/data/languages/AARCH64.opinion index 2655181d5e..c8beb91ba8 100644 --- a/Ghidra/Processors/AARCH64/data/languages/AARCH64.opinion +++ b/Ghidra/Processors/AARCH64/data/languages/AARCH64.opinion @@ -8,16 +8,10 @@ - - - - - - diff --git a/Ghidra/Processors/AARCH64/data/languages/AARCH64_swift.cspec b/Ghidra/Processors/AARCH64/data/languages/AARCH64_swift.cspec deleted file mode 100644 index a78ec35644..0000000000 --- a/Ghidra/Processors/AARCH64/data/languages/AARCH64_swift.cspec +++ /dev/null @@ -1,393 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Ghidra/Processors/AARCH64/data/languages/AppleSilicon.ldefs b/Ghidra/Processors/AARCH64/data/languages/AppleSilicon.ldefs index 438a3f92a5..e26a418abe 100644 --- a/Ghidra/Processors/AARCH64/data/languages/AppleSilicon.ldefs +++ b/Ghidra/Processors/AARCH64/data/languages/AppleSilicon.ldefs @@ -11,7 +11,6 @@ id="AARCH64:LE:64:AppleSilicon"> AppleSilicon ARM v8.5-A LE instructions, LE data, AMX extensions - diff --git a/Ghidra/Processors/x86/certification.manifest b/Ghidra/Processors/x86/certification.manifest index 71dfe24947..a1625ccaf2 100644 --- a/Ghidra/Processors/x86/certification.manifest +++ b/Ghidra/Processors/x86/certification.manifest @@ -1,16 +1,6 @@ ##VERSION: 2.0 Module.manifest||GHIDRA||||END| README.md||GHIDRA||||END| -data/extensions/rust/unix32/cc.xml||GHIDRA||||END| -data/extensions/rust/unix32/probe_fixup.xml||GHIDRA||||END| -data/extensions/rust/unix32/try_fixup.xml||GHIDRA||||END| -data/extensions/rust/unix64/cc.xml||GHIDRA||||END| -data/extensions/rust/unix64/probe_fixup.xml||GHIDRA||||END| -data/extensions/rust/unix64/try_fixup.xml||GHIDRA||||END| -data/extensions/rust/windows32/probe_fixup.xml||GHIDRA||||END| -data/extensions/rust/windows32/try_fixup.xml||GHIDRA||||END| -data/extensions/rust/windows64/probe_fixup.xml||GHIDRA||||END| -data/extensions/rust/windows64/try_fixup.xml||GHIDRA||||END| data/languages/adx.sinc||GHIDRA||||END| data/languages/avx.sinc||GHIDRA||||END| data/languages/avx2.sinc||GHIDRA||||END| @@ -75,7 +65,6 @@ data/languages/x86-64-compat32.pspec||GHIDRA||||END| data/languages/x86-64-gcc.cspec||GHIDRA||||END| data/languages/x86-64-golang.cspec||GHIDRA||||END| data/languages/x86-64-golang.register.info||GHIDRA||||END| -data/languages/x86-64-swift.cspec||GHIDRA||||END| data/languages/x86-64-win.cspec||GHIDRA||||END| data/languages/x86-64.dwarf||GHIDRA||||END| data/languages/x86-64.pspec||GHIDRA||||END| diff --git a/Ghidra/Processors/x86/data/languages/x86-64-swift.cspec b/Ghidra/Processors/x86/data/languages/x86-64-swift.cspec deleted file mode 100644 index 71bfa360ec..0000000000 --- a/Ghidra/Processors/x86/data/languages/x86-64-swift.cspec +++ /dev/null @@ -1,263 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Ghidra/Processors/x86/data/languages/x86.ldefs b/Ghidra/Processors/x86/data/languages/x86.ldefs index 43b1ecf864..a6ed12666d 100644 --- a/Ghidra/Processors/x86/data/languages/x86.ldefs +++ b/Ghidra/Processors/x86/data/languages/x86.ldefs @@ -95,7 +95,6 @@ - diff --git a/Ghidra/Processors/x86/data/languages/x86.opinion b/Ghidra/Processors/x86/data/languages/x86.opinion index 4e5fc7a331..e9b887ece0 100644 --- a/Ghidra/Processors/x86/data/languages/x86.opinion +++ b/Ghidra/Processors/x86/data/languages/x86.opinion @@ -27,9 +27,6 @@ - - - @@ -42,9 +39,6 @@ - - - @@ -65,9 +59,6 @@ - - -