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

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,360 @@
<!DOCTYPE html>
<meta charset="utf8" http-equiv="X-UA-Compatible" content="IE=Edge">
<title>Ghidra Advanced Development</title>
<div id="present">
<iframe></iframe>
</div>
<div id="future">
<iframe></iframe>
</div>
<div id="slideidx" onclick="Dz.setCursor(prompt('Go to slide...','1'));">?</div>
<div id="nextslideidx">?</div>
<div id="notes">
<p id="content"></p>
</div>
<div id="slidecount">?</div>
<button id="popup-button" onclick="Dz.popup()">Pop-up</button>
<div id="time">
<span id="hours">00</span>:<span id="minutes">00</span>:<span id="seconds">00</span>
</div>
<style>
html, body {
height: 100%;
color: white;
}
body {
font-family: sans-serif;
overflow: hidden;
}
#present, #future {
bottom: 234px;
position: absolute;
top: 0;
z-index: 5;
}
#present {
left: 0;
right: 50%;
border-right: 4px solid #555;
}
#future {
left: 50%;
right: 0;
border-left: 4px solid #555;
}
#notes {
background: #EEE;
border-top: 8px solid #555;
bottom: 0;
color: #444;
font-size: 20px;
height: 226px;
left: 0;
padding: 0 250px 0 20px;
position: absolute;
right: 0;
overflow: auto;
}
#time {
background: #888;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
bottom: 0;
font-size: 40px;
font-weight: bold;
height: 52px;
line-height: 52px;
right: 30px;
position: absolute;
text-align: center;
width: 200px;
}
iframe {
border: none;
height: 100%;
pointer-events: none;
width: 100%;
}
#slideidx,
#nextslideidx,
#slidecount {
background: #888;
font-size: 40px;
font-weight: bold;
height: 52px;
line-height: 52px;
margin: 0;
position: absolute;
text-align: center;
z-index: 10;
}
#slideidx,
#nextslideidx {
border-bottom: 4px solid #555;
bottom: 230px;
padding: 0 10px;
}
#slideidx {
border-right: 4px solid #555;
border-top-left-radius: 10px;
cursor: pointer;
right: 50%;
}
#nextslideidx {
border-left: 4px solid #555;
border-top-right-radius: 10px;
left: 50%;
}
#slidecount {
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
border-top: 4px solid #555;
bottom: 174px;
width: 200px;
right: 30px;
}
#popup-button {
bottom: 88px;
background: #888;
border: none;
border-radius: 10px;
color: #FFF;
cursor: pointer;
height: 52px;
font-size: 30px;
font-weight: bold;
position: absolute;
right: 30px;
width: 200px;
z-index: 10;
}
</style>
<script>
var Dz = {
views: {},
notes: null,
url: null,
idx: 1
};
Dz.init = function() {
this.startClock();
this.loadIframes();
}
Dz.onkeydown = function(aEvent) {
// Don't intercept keyboard shortcuts
if (aEvent.altKey
|| aEvent.ctrlKey
|| aEvent.metaKey
|| aEvent.shiftKey) {
return;
}
if ( aEvent.keyCode == 37 // left arrow
|| aEvent.keyCode == 38 // up arrow
|| aEvent.keyCode == 33 // page up
) {
aEvent.preventDefault();
this.back();
}
if ( aEvent.keyCode == 39 // right arrow
|| aEvent.keyCode == 40 // down arrow
|| aEvent.keyCode == 34 // page down
) {
aEvent.preventDefault();
this.forward();
}
if (aEvent.keyCode == 35) { // end
aEvent.preventDefault();
this.goEnd();
}
if (aEvent.keyCode == 36) { // home
aEvent.preventDefault();
this.goStart();
}
if (aEvent.keyCode == 32) { // space
aEvent.preventDefault();
this.toggleContent();
}
}
Dz.onmessage = function(aEvent) {
var argv = aEvent.data.split(" "), argc = argv.length;
argv.forEach(function(e, i, a) { a[i] = decodeURIComponent(e) });
if (argv[0] === "CURSOR" && argc === 2) {
if (aEvent.source === this.views.present) {
var cursor = argv[1].split(".");
this.postMsg(this.views.present, "GET_NOTES");
this.idx = ~~cursor[0];
this.step = ~~cursor[1];
$("#slideidx").innerHTML = argv[1];
this.postMsg(this.views.future, "SET_CURSOR", this.idx + "." + (this.step + 1));
if (this.views.remote)
this.postMsg(this.views.remote, "SET_CURSOR", argv[1]);
} else {
$("#nextslideidx").innerHTML = +argv[1] < 0 ? "END" : argv[1];
}
}
if (aEvent.source === this.views.present) {
if (argv[0] === "NOTES" && argc === 2)
$("#notes > #content").innerHTML = this.notes = argv[1];
if (argv[0] === "REGISTERED" && argc === 3)
$("#slidecount").innerHTML = argv[2];
}
}
/* Get url from hash or prompt and store it */
Dz.getUrl = function() {
var u = window.location.hash.split("#")[1];
if (!u) {
u = window.prompt("What is the URL of the slides?");
if (u) {
window.location.hash = u.split("#")[0];
return u;
}
u = "<style>body{background-color:white;color:black}</style>";
u += "<strong>ERROR:</strong> No URL specified.<br>";
u += "Try<em>: " + document.location + "#yourslides.html</em>";
u = "data:text/html," + encodeURIComponent(u);
}
return u;
}
Dz.loadIframes = function() {
var present = $("#present iframe");
var future = $("#future iframe");
/*this.url = this.getUrl();*/
window.location.hash = "#GhidraAdvancedDevelopment.html";
this.url = "GhidraAdvancedDevelopment.html";
present.src = future.src = this.url + '?autoplay=0';
present.onload = future.onload = function() {
var id = this.parentNode.id;
Dz.views[id] = this.contentWindow;
if (Dz.views.present && Dz.views.future) {
Dz.postMsg(Dz.views.present, "REGISTER");
Dz.postMsg(Dz.views.future, "REGISTER");
}
}
}
Dz.toggleContent = function() {
if (this.views.remote)
this.postMsg(this.views.remote, "TOGGLE_CONTENT");
}
Dz.onhashchange = function() {
this.loadIframe();
}
Dz.back = function() {
this.postMsg(this.views.present, "BACK");
}
Dz.forward = function() {
this.postMsg(this.views.present, "FORWARD");
}
Dz.goStart = function() {
this.postMsg(this.views.present, "START");
}
Dz.goEnd = function() {
this.postMsg(this.views.present, "END");
}
Dz.setCursor = function(aCursor) {
this.postMsg(this.views.present, "SET_CURSOR", aCursor);
}
Dz.popup = function() {
this.views.remote = window.open(this.url + "#" + this.idx, 'slides', 'width=800,height=600,personalbar=0,toolbar=0,scrollbars=1,resizable=1');
}
Dz.postMsg = function(aWin, aMsg) { // [arg0, [arg1...]]
aMsg = [aMsg];
for (var i = 2; i < arguments.length; i++)
aMsg.push(encodeURIComponent(arguments[i]));
aWin.postMessage(aMsg.join(" "), "*");
}
Dz.startClock = function() {
var addZero = function(num) {
return num < 10 ? '0' + num : num;
}
setInterval(function() {
var now = new Date();
$("#hours").innerHTML = addZero(now.getHours());
$("#minutes").innerHTML = addZero(now.getMinutes());
$("#seconds").innerHTML = addZero(now.getSeconds());
}, 1000);
}
function init() {
Dz.init();
window.onkeydown = Dz.onkeydown.bind(Dz);
window.onhashchange = Dz.loadIframes.bind(Dz);
window.onmessage = Dz.onmessage.bind(Dz);
}
window.onload = init;
</script>
<script> // Helpers
if (!Function.prototype.bind) {
Function.prototype.bind = function (oThis) {
// closest thing possible to the ECMAScript 5 internal IsCallable
// function
if (typeof this !== "function")
throw new TypeError(
"Function.prototype.bind - what is trying to be fBound is not callable"
);
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function () {},
fBound = function () {
return fToBind.apply( this instanceof fNOP ? this : oThis || window,
aArgs.concat(Array.prototype.slice.call(arguments)));
};
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();
return fBound;
};
}
var $ = (HTMLElement.prototype.$ = function(aQuery) {
return this.querySelector(aQuery);
}).bind(document);
var $$ = (HTMLElement.prototype.$$ = function(aQuery) {
return this.querySelectorAll(aQuery);
}).bind(document);
</script>

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 143 KiB

View file

@ -0,0 +1,30 @@
/* ###
* 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.
*/
//It prints "Hello class" to the console.
//@category Category A.Category B
//@keybinding alt shift 6
//@menupath Script.My Class Script
//@toolbar Info.png
import ghidra.app.script.GhidraScript;
public class Lab3Script extends GhidraScript {
@Override
public void run() throws Exception {
println("Hello class");
}
}

View file

@ -0,0 +1,34 @@
/* ###
* 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.
*/
//Ask for an integer and print the current
//program?s name that many times to the console
//@category GADC
import ghidra.app.script.GhidraScript;
public class Lab4Script extends GhidraScript {
@Override
public void run() throws Exception {
int n = askInt("How Many Times?", "N");
for (int i = 0; i < n; ++i) {
if (monitor.isCancelled()) {
break;
}
println(i + ". " + currentProgram.getName());
Thread.sleep(1000);
}
}
}

View file

@ -0,0 +1,57 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//This script searches through all instructions that are
//moving a scalar into a register
//and sets an EOL comment in the form "[register] = [value]"
//@category GADC
import ghidra.app.script.GhidraScript;
import ghidra.program.model.lang.Register;
import ghidra.program.model.listing.Instruction;
import ghidra.program.model.scalar.Scalar;
public class Lab5Script extends GhidraScript {
@Override
public void run() throws Exception {
Instruction instruction = getFirstInstruction();
while (instruction != null) {
if (monitor.isCancelled()) {
break;
}
if (instruction.getNumOperands() != 2) {
continue;
}
Object[] opObjects0 = instruction.getOpObjects(0);
if (opObjects0.length != 1 || !(opObjects0[0] instanceof Register)) {
continue;
}
Object[] opObjects1 = instruction.getOpObjects(1);
if (opObjects1.length != 1 || !(opObjects1[0] instanceof Scalar)) {
continue;
}
Register register = (Register) opObjects0[0];
Scalar scalar = (Scalar) opObjects1[0];
String comment =
"[" + register.getName() + "]=[" + scalar.toString(16, false, false, "", "") + "]";
setEOLComment(instruction.getMinAddress(), comment);
instruction = getNextInstruction();
}
}
}

View file

@ -0,0 +1,36 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* 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.
*/
#include <stdio.h>
static unsigned int alpha = 0xfeedbabe;
int foo( int bar )
{
return bar * bar / bar + bar - bar % bar;
}
int main ( int argc, const char ** argv )
{
alpha *= 8;
printf( "Hello Ghidra!\n" );
int foobar = foo( 0x12345678 );
printf( "foobar = %x \n", foobar * alpha );
return 0;
}

View file

@ -0,0 +1,65 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* 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.
*/
//
// ghidra.h
// GHIDRA
//
#ifndef GHIDRA_ghidra_h
#define GHIDRA_ghidra_h
#define G_CPU_TYPE_X86 0x1 // x86 32-bit little endian
#define G_CPU_TYPE_PPC 0x2 // ppc 32-bit little endian
#define G_CPU_TYPE_ARM 0x4 // arm 32-bit little endian
#define G_MAGIC "ghidra"
#define G_OBJECT_FILE 0x1 // relocatable object file
#define G_EXECUTABLE_FILE 0x2 // demand paged executable file
#define G_LIBRARY_FILE 0x3 // fixed VM shared library file
#define G_KERNEL_OBJECT 0x4 // core file
struct ghidra_header {
char magic[ 6 ]; // magic number identifier
unsigned char cputype; // cpu specifier
unsigned short nsections; // number of sections
unsigned short nsymbols; // number of symbols
unsigned int flags; // flags
};
#define G_SECTION_READ 0x1
#define G_SECTION_WRITE 0x2
#define G_SECTION_EXECUTE 0x4
struct ghidra_section { // for 32-bit architectures
char name[ 16 ]; // name of this section
unsigned int addr; // memory address of this section
unsigned int size; // size in bytes of this section
unsigned int offset; // file offset of this section
unsigned int flags; // flags (section type and attributes
};
#define G_SYMBOL_TYPE_ENTRY_POINT 0x1
#define G_SYMBOL_TYPE_DATA 0x2
struct ghidra_symbol { // for 32-bit architectures
char name[ 25 ]; //name of this symbol
unsigned int addr; // memory address of this symbol
unsigned short type; // type of this symbol
};
#endif

View file

@ -0,0 +1,30 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* 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.
*/
//
// main.c
// GHIDRA
#include <stdio.h>
int main (int argc, const char * argv[])
{
// insert code here...
printf("Hello, World!\n");
return 0;
}