From 1475238074676bae74bdbf2fc8e756ca129f7fe5 Mon Sep 17 00:00:00 2001 From: Dhruv Maroo Date: Tue, 11 Apr 2023 23:06:09 +0530 Subject: [PATCH] Initial extension set up * Extension help can be found in the "Help" section in Ghidra * Extension build script, LICENSE and README added --- .gitignore | 21 ++++ LICENSE | 7 ++ Module.manifest | 0 README.md | 27 +++++ build.gradle | 33 ++++++ build.sh | 102 +++++++++++++++++++ certification.manifest | 6 ++ extension.properties | 5 + src/main/help/help/TOC_Source.xml | 54 ++++++++++ src/main/help/help/shared/Frontpage.css | 58 +++++++++++ src/main/help/help/topics/GhidRust/help.html | 19 ++++ 11 files changed, 332 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Module.manifest create mode 100644 README.md create mode 100644 build.gradle create mode 100755 build.sh create mode 100644 certification.manifest create mode 100644 extension.properties create mode 100644 src/main/help/help/TOC_Source.xml create mode 100644 src/main/help/help/shared/Frontpage.css create mode 100644 src/main/help/help/topics/GhidRust/help.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fc6ed3f --- /dev/null +++ b/.gitignore @@ -0,0 +1,21 @@ +# temp files +tmp/ + +# editor config files +.idea/ +.vscode/ +.settings/ + +# build directories +bin/ +build/ +dist/ + +# gradle files +.gradle/ +gradle/ +gradlew +gradlew.bat + +# misc +.DS_Store diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ca3a23b --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2023 Dhruv Maroo + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Module.manifest b/Module.manifest new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md new file mode 100644 index 0000000..d5b24cf --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# GhidRust: Rust binary analysis extension + +## Building + +There is a build script provided (`build.sh`) which can build and install the extension. + +``` +$ ./build.sh -h +GhidRust install script +Usage: build.sh [-i | --install] -g GHIDRA_PATH + + -i | --install Install the extension + -g | --ghidra Path to Ghidra installation (usually /opt/ghidra) + -h | --help Show usage/help +``` + +You can build the extension using the following command. + +``` +$ ./build.sh -g +``` + +You can install it using the install flag as follows. + +``` +./build.sh -ig +``` diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..e827d99 --- /dev/null +++ b/build.gradle @@ -0,0 +1,33 @@ +// Builds a Ghidra Extension for a given Ghidra installation. +// +// An absolute path to the Ghidra installation directory must be supplied either by setting the +// GHIDRA_INSTALL_DIR environment variable or Gradle project property: +// +// > export GHIDRA_INSTALL_DIR= +// > gradle +// +// or +// +// > gradle -PGHIDRA_INSTALL_DIR= +// +// Gradle should be invoked from the directory of the project to build. Please see the +// application.gradle.version property in /Ghidra/application.properties +// for the correction version of Gradle to use for the Ghidra installation you specify. + +//----------------------START "DO NOT MODIFY" SECTION------------------------------ +def ghidraInstallDir + +if (System.env.GHIDRA_INSTALL_DIR) { + ghidraInstallDir = System.env.GHIDRA_INSTALL_DIR +} +else if (project.hasProperty("GHIDRA_INSTALL_DIR")) { + ghidraInstallDir = project.getProperty("GHIDRA_INSTALL_DIR") +} + +if (ghidraInstallDir) { + apply from: new File(ghidraInstallDir).getCanonicalPath() + "/support/buildExtension.gradle" +} +else { + throw new GradleException("GHIDRA_INSTALL_DIR is not defined!") +} +//----------------------END "DO NOT MODIFY" SECTION------------------------------- diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..c06f531 --- /dev/null +++ b/build.sh @@ -0,0 +1,102 @@ +#!/bin/bash + +success() { + echo -e "\033[32;1m[+]\033[0m" "$1" +} + +status() { + echo -e "\033[33;1m[-]\033[0m" "$1" +} + +failure() { + echo -e "\033[31;1m[!]\033[0m" "$1" +} + +usage() { + echo -e "Usage: $(basename $0) [-i | --install] -g GHIDRA_PATH" + echo -e "" + echo -e "\t-i | --install\t\t Install the extension" + echo -e "\t-g | --ghidra\t\t Path to Ghidra installation (usually /opt/ghidra)" + echo -e "\t-h | --help\t\t Show usage/help" +} + +VALID_ARGS=$(getopt -o ig:h --long install,ghidra:,help -- "$@") + +if [[ $? -ne 0 ]]; then + failure "Invalid arguments provided" + exit 1; +fi + +eval set -- "$VALID_ARGS" + +INSTALL=0 +GHIDRA="" + +while [ : ]; do + case "$1" in + -i | --install) + INSTALL=1 + shift + ;; + -g | --ghidra) + GHIDRA="$2" + shift 2 + ;; + -h | --help) + echo -e "GhidRust install script" + usage + exit 0 + ;; + ?) + failure "Invalid arguments provided" + echo -e "" + usage + exit 1 + ;; + --) shift; + break + ;; + esac +done + +if [ -z "$GHIDRA" ] +then + failure "Required arguments not provided" + echo -e "" + usage + exit 1 +fi + +status "Building GhidRust" + +gradle -PGHIDRA_INSTALL_DIR="$GHIDRA" + +if [[ $? -ne 0 ]]; then + failure "Build command failed" + exit 1; +fi + +success "Build successful" + +if [ "$INSTALL" -eq "0" ] +then + exit 0 +fi + +status "Installing GhidRust" + +sudo cp dist/* "$GHIDRA"/Extensions/Ghidra + +if [[ $? -ne 0 ]]; then + failure "Installation failed" + exit 1; +fi + +success "Installation successful" + +status "Next steps" + +echo -e "\t 1. Open Ghidra" +echo -e "\t 2. Go to File -> Install Extensions" +echo -e "\t 3. Tick the checkbox beside GhidRust" +echo -e "\t 4. Restart Ghidra" diff --git a/certification.manifest b/certification.manifest new file mode 100644 index 0000000..3d29014 --- /dev/null +++ b/certification.manifest @@ -0,0 +1,6 @@ +##VERSION: 1.0 +##MODULE IP: MIT +Module.manifest||GHIDRA||||END| +extension.properties||GHIDRA||||END| +src/main/help/help/TOC_Source.xml||GHIDRA||||END| +src/main/help/help/topics/GhidRust/help.html||GHIDRA||||END| diff --git a/extension.properties b/extension.properties new file mode 100644 index 0000000..5ed0402 --- /dev/null +++ b/extension.properties @@ -0,0 +1,5 @@ +name=@extname@ +description=Helps in analyzing and decompiling Rust binaries. +author=DMaroo +createdOn=4/11/2023 +version=@extversion@ diff --git a/src/main/help/help/TOC_Source.xml b/src/main/help/help/TOC_Source.xml new file mode 100644 index 0000000..18f2fd1 --- /dev/null +++ b/src/main/help/help/TOC_Source.xml @@ -0,0 +1,54 @@ + + + + + + + + diff --git a/src/main/help/help/shared/Frontpage.css b/src/main/help/help/shared/Frontpage.css new file mode 100644 index 0000000..452bf6e --- /dev/null +++ b/src/main/help/help/shared/Frontpage.css @@ -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; } diff --git a/src/main/help/help/topics/GhidRust/help.html b/src/main/help/help/topics/GhidRust/help.html new file mode 100644 index 0000000..1549421 --- /dev/null +++ b/src/main/help/help/topics/GhidRust/help.html @@ -0,0 +1,19 @@ + + + + + + + + + GhidRust + + + + +

GhidRust: Rust binary analysis extension

+ +

// TODO documentation

+ + +