Candidate release of source code.

This commit is contained in:
Dan 2019-03-26 13:45:32 -04:00
parent db81e6b3b0
commit 79d8f164f8
12449 changed files with 2800756 additions and 16 deletions

View file

@ -0,0 +1,57 @@
<?xml version='1.0' encoding='ISO-8859-1' ?>
<!--
This is an XML file intended to be parsed by the Ghidra help system. It is loosely based
upon the JavaHelp table of contents document format. The Ghidra help system uses a
TOC_Source.xml file to allow a module with help to define how its contents appear in the
Ghidra help viewer's table of contents. The main document (in the Base module)
defines a basic structure for the
Ghidra table of contents system. Other TOC_Source.xml files may use this structure to insert
their files directly into this structure (and optionally define a substructure).
In this document, a tag can be either a <tocdef> or a <tocref>. The former is a definition
of an XML item that may have a link and may contain other <tocdef> and <tocref> children.
<tocdef> items may be referred to in other documents by using a <tocref> tag with the
appropriate id attribute value. Using these two tags allows any module to define a place
in the table of contents system (<tocdef>), which also provides a place for
other TOC_Source.xml files to insert content (<tocref>).
During the help build time, all TOC_Source.xml files will be parsed and validated to ensure
that all <tocref> tags point to valid <tocdef> tags. From these files will be generated
<module name>_TOC.xml files, which are table of contents files written in the format
desired by the JavaHelp system. Additionally, the genated files will be merged together
as they are loaded by the JavaHelp system. In the end, when displaying help in the Ghidra
help GUI, there will be on table of contents that has been created from the definitions in
all of the modules' TOC_Source.xml files.
Tags and Attributes
<tocdef>
-id - the name of the definition (this must be unique across all TOC_Source.xml files)
-text - the display text of the node, as seen in the help GUI
-target** - the file to display when the node is clicked in the GUI
-sortgroup - this is a string that defines where a given node should appear under a given
parent. The string values will be sorted by the JavaHelp system using
a javax.text.RulesBasedCollator. If this attribute is not specified, then
the text of attribute will be used.
<tocref>
-id - The id of the <tocdef> that this reference points to
**The URL for the target is relative and should start with 'help/topics'. This text is
used by the Ghidra help system to provide a universal starting point for all links so that
they can be resolved at runtime, across modules.
-->
<tocroot>
<!-- Uncomment and adjust fields to add help topic to help system's Table of Contents
<tocref id="Ghidra Functionality">
<tocdef id="HelpAnchor" text="My Feature" target="help/topics/my_topic/help.html" />
</tocref>
-->
</tocroot>

View file

@ -0,0 +1,58 @@
/* ###
* 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.
*/
/*
WARNING!
This file is copied to all help directories. If you change this file, you must copy it
to each src/main/help/help/shared directory.
Java Help Note: JavaHelp does not accept sizes (like in 'margin-top') in anything but
px (pixel) or with no type marking.
*/
body { margin-bottom: 50px; margin-left: 10px; margin-right: 10px; margin-top: 10px; } /* some padding to improve readability */
li { font-family:times new roman; font-size:14pt; }
h1 { color:#000080; font-family:times new roman; font-size:36pt; font-style:italic; font-weight:bold; text-align:center; }
h2 { margin: 10px; margin-top: 20px; color:#984c4c; font-family:times new roman; font-size:18pt; font-weight:bold; }
h3 { margin-left: 10px; margin-top: 20px; color:#0000ff; font-family:times new roman; font-size:14pt; font-weight:bold; }
h4 { margin-left: 10px; margin-top: 20px; font-family:times new roman; font-size:14pt; font-style:italic; }
/*
P tag code. Most of the help files nest P tags inside of blockquote tags (the was the
way it had been done in the beginning). The net effect is that the text is indented. In
modern HTML we would use CSS to do this. We need to support the Ghidra P tags, nested in
blockquote tags, as well as naked P tags. The following two lines accomplish this. Note
that the 'blockquote p' definition will inherit from the first 'p' definition.
*/
p { margin-left: 40px; font-family:times new roman; font-size:14pt; }
blockquote p { margin-left: 10px; }
p.providedbyplugin { color:#7f7f7f; margin-left: 10px; font-size:14pt; margin-top:100px }
p.ProvidedByPlugin { color:#7f7f7f; margin-left: 10px; font-size:14pt; margin-top:100px }
p.relatedtopic { color:#800080; margin-left: 10px; font-size:14pt; }
p.RelatedTopic { color:#800080; margin-left: 10px; font-size:14pt; }
/*
We wish for a tables to have space between it and the preceding element, so that text
is not too close to the top of the table. Also, nest the table a bit so that it is clear
the table relates to the preceding text.
*/
table { margin-left: 20px; margin-top: 10px; width: 80%;}
td { font-family:times new roman; font-size:14pt; vertical-align: top; }
th { font-family:times new roman; font-size:14pt; font-weight:bold; background-color: #EDF3FE; }
code { color: black; font-family: courier new; font-size: 14pt; }

View file

@ -0,0 +1,23 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META name="generator" content=
"HTML Tidy for Java (vers. 2009-12-01), see jtidy.sourceforge.net">
<META http-equiv="Content-Language" content="en-us">
<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
<META name="GENERATOR" content="Microsoft FrontPage 4.0">
<META name="ProgId" content="FrontPage.Editor.Document">
<TITLE>Skeleton Help File for a Module</TITLE>
<LINK rel="stylesheet" type="text/css" href="../../shared/Frontpage.css">
</HEAD>
<BODY>
<H1><a name="HelpAnchor"></a>Skeleton Help File for a Module</H1>
<P>This is a simple skeleton help topic. For a better description of what should and should not
go in here, see the "sample" Ghidra extension in the Extensions/Ghidra directory, or see your
favorite help topic. In general, language modules do not have their own help topics.</P>
</BODY>
</HTML>

View file

@ -0,0 +1,74 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package skeleton;
import ghidra.app.services.AbstractAnalyzer;
import ghidra.app.services.AnalyzerType;
import ghidra.app.util.importer.MessageLog;
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;
/**
* TODO: Provide class-level documentation that describes what this analyzer does.
*/
public class SkeletonAnalyzer extends AbstractAnalyzer {
public SkeletonAnalyzer() {
// TODO: Name the analyzer and give it a description.
super("My Analyzer", "Analyzer description goes here", AnalyzerType.BYTE_ANALYZER);
}
@Override
public boolean getDefaultEnablement(Program program) {
// TODO: Return true if analyzer should be enabled by default
return false;
}
@Override
public boolean canAnalyze(Program program) {
// TODO: Examine 'program' to determine of this analyzer should analyze it. Return true
// if it can.
return false;
}
@Override
public void registerOptions(Options options, Program program) {
// TODO: If this analyzer has custom options, register them here
options.registerOption("Option name goes here", false, null,
"Option description goes here");
}
@Override
public boolean added(Program program, AddressSetView set, TaskMonitor monitor, MessageLog log)
throws CancelledException {
// TODO: Perform analysis when things get added to the 'program'. Return true if the
// analysis succeeded.
return false;
}
}

View file

@ -0,0 +1,69 @@
/* ###
* 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 skeleton;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import ghidra.app.util.*;
import ghidra.app.util.exporter.Exporter;
import ghidra.app.util.exporter.ExporterException;
import ghidra.framework.model.DomainObject;
import ghidra.program.model.address.AddressSetView;
import ghidra.util.task.TaskMonitor;
/**
* TODO: Provide class-level documentation that describes what this exporter does.
*/
public class SkeletonExporter extends Exporter {
/**
* Exporter constructor.
*/
public SkeletonExporter() {
// TODO: Name the exporter and associate a file extension with it
super("My Exporter", "exp", null);
}
@Override
public boolean export(File file, DomainObject domainObj, AddressSetView addrSet,
TaskMonitor monitor) throws ExporterException, IOException {
// TODO: Perform the export, and return true if it succeeded
return false;
}
@Override
public List<Option> getOptions(DomainObjectService domainObjectService) {
List<Option> list = new ArrayList<>();
// TODO: If this exporter has custom options, add them to 'list'
list.add(new Option("Option name goes here", "Default option value goes here"));
return list;
}
@Override
public void setOptions(List<Option> options) throws OptionException {
// TODO: If this exporter has custom options, assign their values to the exporter here
}
}

View file

@ -0,0 +1,184 @@
/* ###
* 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 skeleton;
import java.io.*;
import java.util.*;
import ghidra.app.util.bin.ByteProvider;
import ghidra.app.util.bin.ByteProviderInputStream;
import ghidra.formats.gfilesystem.*;
import ghidra.formats.gfilesystem.annotations.FileSystemInfo;
import ghidra.formats.gfilesystem.factory.GFileSystemFactoryFull;
import ghidra.formats.gfilesystem.factory.GFileSystemProbeFull;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor;
/**
* TODO: Provide class-level documentation that describes what this file system does.
*/
@FileSystemInfo(
type = "fstypegoeshere", // ([a-z0-9]+ only)
description = "File system description goes here",
factory = SkeletonFileSystem.MyFileSystemFactory.class)
public class SkeletonFileSystem implements GFileSystem {
private final FSRLRoot fsFSRL;
private FileSystemIndexHelper<MyMetadata> fsih;
private FileSystemRefManager refManager = new FileSystemRefManager(this);
private ByteProvider provider;
/**
* File system constructor.
*
* @param fsFSRL The root {@link FSRL} of the file system.
* @param provider The file system provider.
*/
public SkeletonFileSystem(FSRLRoot fsFSRL, ByteProvider provider) {
this.fsFSRL = fsFSRL;
this.provider = provider;
this.fsih = new FileSystemIndexHelper<>(this, fsFSRL);
}
/**
* Mounts (opens) the file system.
*
* @param monitor A cancellable task monitor.
*/
public void mount(TaskMonitor monitor) {
monitor.setMessage("Opening " + SkeletonFileSystem.class.getSimpleName() + "...");
// TODO: Customize how things in the file system are stored. The following should be
// treated as pseudo-code.
for (MyMetadata metadata : new MyMetadata[10]) {
if (monitor.isCancelled()) {
break;
}
fsih.storeFile(metadata.path, fsih.getFileCount(), false, metadata.size, metadata);
}
}
@Override
public void close() throws IOException {
refManager.onClose();
if (provider != null) {
provider.close();
provider = null;
}
fsih.clear();
}
@Override
public String getName() {
return fsFSRL.getContainer().getName();
}
@Override
public FSRLRoot getFSRL() {
return fsFSRL;
}
@Override
public boolean isClosed() {
return provider == null;
}
@Override
public int getFileCount() {
return fsih.getFileCount();
}
@Override
public FileSystemRefManager getRefManager() {
return refManager;
}
@Override
public GFile lookup(String path) throws IOException {
return fsih.lookup(path);
}
@Override
public InputStream getInputStream(GFile file, TaskMonitor monitor)
throws IOException, CancelledException {
// TODO: Get an input stream for a file. The following is an example of how the metadata
// might be used to get an input stream from a stored provider offset.
MyMetadata metadata = fsih.getMetadata(file);
return (metadata != null)
? new ByteProviderInputStream(provider, metadata.offset, metadata.size)
: null;
}
@Override
public List<GFile> getListing(GFile directory) throws IOException {
return fsih.getListing(directory);
}
@Override
public String getInfo(GFile file, TaskMonitor monitor) throws IOException {
MyMetadata metadata = fsih.getMetadata(file);
return (metadata == null) ? null : FSUtilities.infoMapToString(getInfoMap(metadata));
}
public Map<String, String> getInfoMap(MyMetadata metadata) {
Map<String, String> info = new LinkedHashMap<>();
// TODO: Customize information about a file system entry. The following is sample
// information that might be useful.
info.put("Name", metadata.name);
info.put("Size",
"" + Long.toString(metadata.size) + ", 0x" + Long.toHexString(metadata.size));
return info;
}
// TODO: Customize for the real file system.
public static class MyFileSystemFactory
implements GFileSystemFactoryFull<SkeletonFileSystem>, GFileSystemProbeFull {
@Override
public SkeletonFileSystem create(FSRL containerFSRL, FSRLRoot targetFSRL,
ByteProvider byteProvider, File containerFile, FileSystemService fsService,
TaskMonitor monitor) throws IOException, CancelledException {
SkeletonFileSystem fs = new SkeletonFileSystem(targetFSRL, byteProvider);
fs.mount(monitor);
return fs;
}
@Override
public boolean probe(FSRL containerFSRL, ByteProvider byteProvider, File containerFile,
FileSystemService fsService, TaskMonitor monitor)
throws IOException, CancelledException {
// TODO: Quickly and efficiently examine the bytes in 'byteProvider' to determine if
// it's a valid file system. If it is, return true.
return false;
}
}
// TODO: Customize with metadata from files in the real file system. This is just a stub.
// The elements of the file system will most likely be modeled by Java classes external to this
// file.
private static class MyMetadata {
private String name;
private String path;
private long offset;
private long size;
}
}

View file

@ -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 skeleton;
import java.io.IOException;
import java.util.*;
import ghidra.app.util.Option;
import ghidra.app.util.bin.ByteProvider;
import ghidra.app.util.importer.MemoryConflictHandler;
import ghidra.app.util.importer.MessageLog;
import ghidra.app.util.opinion.AbstractLibrarySupportLoader;
import ghidra.app.util.opinion.LoadSpec;
import ghidra.framework.model.DomainObject;
import ghidra.program.model.listing.Program;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor;
/**
* TODO: Provide class-level documentation that describes what this loader does.
*/
public class SkeletonLoader extends AbstractLibrarySupportLoader {
@Override
public String getName() {
// TODO: Name the loader. This name must match the name of the loader in the .opinion
// files.
return "My loader";
}
@Override
public Collection<LoadSpec> findSupportedLoadSpecs(ByteProvider provider) throws IOException {
List<LoadSpec> loadSpecs = new ArrayList<>();
// TODO: Examine the bytes in 'provider' to determine if this loader can load it. If it
// can load it, return the appropriate load specifications.
return loadSpecs;
}
@Override
protected void load(ByteProvider provider, LoadSpec loadSpec, List<Option> options,
Program program, MemoryConflictHandler handler, TaskMonitor monitor, MessageLog log)
throws CancelledException, IOException {
// TODO: Load the bytes from 'provider' into the 'program'.
}
@Override
public List<Option> getDefaultOptions(ByteProvider provider, LoadSpec loadSpec,
DomainObject domainObject, boolean isLoadIntoProgram) {
List<Option> list =
super.getDefaultOptions(provider, loadSpec, domainObject, isLoadIntoProgram);
// TODO: If this loader has custom options, add them to 'list'
list.add(new Option("Option name goes here", "Default option value goes here"));
return list;
}
@Override
public String validateOptions(ByteProvider provider, LoadSpec loadSpec, List<Option> options) {
// TODO: If this loader has custom options, validate them here. Not all options require
// validation.
return super.validateOptions(provider, loadSpec, options);
}
}

View file

@ -0,0 +1,116 @@
/* ###
* 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 skeleton;
import java.awt.BorderLayout;
import javax.swing.*;
import docking.ActionContext;
import docking.ComponentProvider;
import docking.action.DockingAction;
import docking.action.ToolBarData;
import ghidra.app.ExamplesPluginPackage;
import ghidra.app.plugin.PluginCategoryNames;
import ghidra.app.plugin.ProgramPlugin;
import ghidra.framework.plugintool.*;
import ghidra.framework.plugintool.util.PluginStatus;
import ghidra.util.HelpLocation;
import ghidra.util.Msg;
import resources.Icons;
/**
* TODO: Provide class-level documentation that describes what this plugin does.
*/
//@formatter:off
@PluginInfo(
status = PluginStatus.STABLE,
packageName = ExamplesPluginPackage.NAME,
category = PluginCategoryNames.EXAMPLES,
shortDescription = "Plugin short description goes here.",
description = "Plugin long description goes here."
)
//@formatter:on
public class SkeletonPlugin extends ProgramPlugin {
MyProvider provider;
/**
* Plugin constructor.
*
* @param tool The plugin tool that this plugin is added to.
*/
public SkeletonPlugin(PluginTool tool) {
super(tool, true, true);
// TODO: Customize provider (or remove if a provider is not desired)
String pluginName = getName();
provider = new MyProvider(this, pluginName);
// TODO: Customize help (or remove if help is not desired)
String topicName = this.getClass().getPackage().getName();
String anchorName = "HelpAnchor";
provider.setHelpLocation(new HelpLocation(topicName, anchorName));
}
@Override
public void init() {
super.init();
// TODO: Acquire services if necessary
}
// TODO: If provider is desired, it is recommended to move it to its own file
private static class MyProvider extends ComponentProvider {
private JPanel panel;
private DockingAction action;
public MyProvider(Plugin plugin, String owner) {
super(plugin.getTool(), owner, owner);
buildPanel();
createActions();
}
// Customize GUI
private void buildPanel() {
panel = new JPanel(new BorderLayout());
JTextArea textArea = new JTextArea(5, 25);
textArea.setEditable(false);
panel.add(new JScrollPane(textArea));
setVisible(true);
}
// TODO: Customize actions
private void createActions() {
action = new DockingAction("My Action", getName()) {
@Override
public void actionPerformed(ActionContext context) {
Msg.showInfo(getClass(), panel, "Custom Action", "Hello!");
}
};
action.setToolBarData(new ToolBarData(Icons.ADD_ICON, null));
action.setEnabled(true);
action.markHelpUnnecessary();
dockingTool.addLocalAction(this, action);
}
@Override
public JComponent getComponent() {
return panel;
}
}
}

View file

@ -0,0 +1,2 @@
The "src/resources/images" directory is intended to hold all image/icon files used by
this module.

View file

@ -0,0 +1,2 @@
The "test" directory is intended to hold unit test cases. The package structure within
this folder should correspond to that found in the "src" folder.