- disassembly - Python Script to get disassembled output of an EXE file - Reverse Engineering Stack Exchange
- GitHub - VDOO-Connected-Trust/ghidra-pyi-generator: Generates `.pyi` type stubs for the entire Ghidra API
- GitHub - TorgoTorgo/ghidra-findcrypt: Ghidra analysis plugin to locate cryptographic constants
- GitHub - garyttierney/intellij-ghidra: An IntelliJ IDEA plugin for working on Ghidra Extensions.
- GitHub - HackOvert/GhidraSnippets: Python snippets for Ghidra's Program and Decompiler APIs
Tools > Function ID > Populate FidDb from programs- GitHub - NWMonster/ApplySig: Apply IDA FLIRT signatures for Ghidra
- https://github.com/NationalSecurityAgency/ghidra/blob/master/Ghidra/Features/FunctionID/data/building_fid.txt
- https://github.com/NationalSecurityAgency/ghidra-data/blob/master/FunctionID/FID.md
- https://blog.threatrack.de/2019/09/20/ghidra-fid-generator/
- https://raw-data.gitlab.io/post/ghidra_fid/
- Enable FunctionID plugin
- Create new empty database
- Populate database with program (I get 6783 results added to the database)
- When I load in another binary (using the same functions), I use Set Active databases
- I turned on "Always apply FID Label" in the analyzer's settings
In my code browser when i go to File -> Configure... I do not see an option for Function ID (there are only sections Ghidra Core, Debugger, Miscellaneous, Developer, and Experimental), and under the experimental plugins there's no option for FidDebugPlugin. However, Function ID is availble under Tools -> Function ID. What could cause that? I found it, they moved it to developer
- Window > Symbol Table > [Select lines and open context menu] > Export to CSV...
- Window > Script Manager > ImportSymbolScript.py
- File > Load PDB File...
- Config > Add https://msdl.microsoft.com/download/symbols/
- For ntoskrnl: ntkrnlmp.pdb
- On linux: createPdbXmlFiles.bat
Apply function symbols as debugger comments with script Funcs2MameComs:
GHIDRA_INSTALL_DIR=$HOME/opt/ghidra_12.0.4_PUBLIC/
GHIDRA_PROJECT_DIR=$HOME/code/ghidra/
GHIDRA_PROJECT_NAME=fooPrj
"$GHIDRA_INSTALL_DIR/support/analyzeHeadless" "$GHIDRA_PROJECT_DIR/" "$GHIDRA_PROJECT_NAME/fooDir" \
-process fooPrg \
-noanalysis \
-scriptPath ~/ghidra_scripts/ \
-postScript Funcs2MameComs.java
mame -debugscript foo.mame.txt# extension
gradle -PGHIDRA_INSTALL_DIR=$HOME/opt/ghidra_12.0.4_PUBLIC buildExtension && mv dist/ghidra_12.0.4_PUBLIC_*.zip ~/opt/ghidra_12.0.4_PUBLIC/Extensions/Ghidra/
# processor
ant -Dghidra.install.dir=$HOME/opt/ghidra_12.0.4_PUBLIC -f buildLanguage.xml && rsync --delete-excluded --exclude=.git --exclude=.gradle -uva ./foo/ ~/opt/ghidra_12.0.4_PUBLIC/Ghidra/Processors/foo/
# dist
# - replace `assert(ip != null)` with `if` in gradle/support/ip.gradle (https://github.com/NationalSecurityAgency/ghidra/issues/661)
gradle -I gradle/support/fetchDependencies.gradle
gradle yajswDevUnpack
gradle buildGhidra
mv build/dist/*.zip ~/opt/ && ( cd ~/opt && find . -maxdepth 1 -type f -iregex '.*\.zip' -exec sh -c 'atool -x "{}" && rm -f "{}"' \; )
# parser/decompiler
gradle generateGrammarSource Decompiler:buildNatives
# test
gradle :Emulation:test --tests "ghidra.pcode.exec.SleighProgramCompilerTest.testGoto64BitOffset" -x buildHelp -x sleighCompile
gradle unitTestReport
gradle integrationTest- File > Import... > Existing project
- GhidraDev > Link Ghidra...
- If "Multiple modules collided with same name", then remove installed extension || temporarily move from ~/.ghidra/
- Run > Debug Configrations... > Classpath
- Bootstrap Entries || User Entries > Add project...
- Debug (Ghidra instance is launched from Eclipse)
If attaching from IDE:
diff --git a/gradle/javaTestProject.gradle b/gradle/javaTestProject.gradle
index 5e3614963e..c9ab46999d 100644
--- a/gradle/javaTestProject.gradle
+++ b/gradle/javaTestProject.gradle
@@ -198,7 +198,7 @@ def initTestJVM(Task task, String rootDirName) {
'-Duser.language=en',
'-Djdk.attach.allowAttachSelf',
'-XX:TieredStopAtLevel=1',
- '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=' + debugPort,
+ //'-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=' + debugPort,
// Allow illegal reflective accesses
'--add-opens=java.base/java.util.concurrent=ALL-UNNAMED',- Script Manager
- Pick: ResolveX86orX64LinuxSyscallsScript
- CodeBrowser > Edit > Tool Options > Decompiler > Analysis
- Unpick: Eliminate unreachable code
- CodeBrowser > Function Call Trees (Incoming + Outgoing Calls)
- Select instructions > Clear Code Block
- Select bytes (starting at expected offset) > Disassemble
./analyzeHeadless $ghidra_database/ $database_name -process '*' -recursiveListing > Edit the Listing fields > Instruction Data > Add Field > Stack Depth
- File > Export Program > Export As C/C++
typedef unsigned char undefined;
typedef unsigned char byte;
typedef unsigned int dword;
typedef unsigned int uint;
typedef unsigned char uint3[3];
typedef unsigned char undefined1;
typedef unsigned short undefined2;
typedef unsigned int undefined4;
typedef unsigned long long undefined8;
typedef unsigned short ushort;
typedef unsigned short word;- https://ghidra.re/ghidra_docs/api/ghidra/program/flatapi/FlatProgramAPI.html
- https://ghidra.re/ghidra_docs/api/ghidra/program/model/address/Address.html
0x41
||
|+-> bits 3..0
+--> bits 7..4
- https://www.riverloopsecurity.com/blog/2019/05/pcode/
- https://swarm.ptsecurity.com/guide-to-p-code-injection/
- GitHub - Nalen98/GhidraEmu: Native Pcode emulator
- First Look: Ghidra 10.3 Emulator
Probably the best use case so far has been pcodetest which takes C code that tries to create junit tests for SLEIGH processor module validation. They gave an introduction at RECON 2019. The difficulty here is one size fits all: it's one C source base and you can't guarantee the coverage of asm produced from ISA to ISA with the compiler. It may not generate all the instructions or even whole classes of them. It may not generate enough variety in register usage, which for register based languages like SLEIGH, that is important to test. Some of the more interesting instructions, and typically the harder ones to implement in SLEIGH, sometimes don't even have a C counterpart.
# Compile SLEIGH specifications
cd ~/code/ghidra_workspace/foo/data
ant -f buildLanguage.xml-
Creating a Ghidra processor module in SLEIGH using V8 bytecode as an example - PT SWARM
-
Implementing a brainfuck CPU in Ghidra - part 1: Setup and disassembly | Spinsel
-
~/code/doc/reversing/Implementing\ a\ New\ CPU\ Architecture\ for\ Ghidra.pdf
-
https://github.com/NationalSecurityAgency/ghidra/tree/master/Ghidra/Features/Decompiler/src/main/doc
-
https://github.com/NationalSecurityAgency/ghidra/tree/master/Ghidra/Processors
- GitHub - oberoisecurity/ghidra-processor-module-generator: A step towards automating the creation of Ghidra processor modules
- ghidra_i960 - scrape.py
-
ghidra/Ghidra/Extensions/SleighDevTools/pcodetest at master · NationalSecurityAgency/ghidra · GitHub
-
What is pcodeTest · Issue #833 · NationalSecurityAgency/ghidra · GitHub
These tests have a corresponding compiled pcodetest binary which must be created before the tests can be run. We did not want to compile and store these test binaries within the repository. The C source which must be built separately for each test can be found within the Ghidra SleighDevTools extension module. This extension must be installed/unpacked to access the source which also include python build scripts. You will need to obtain the appropriate cross-build toolchain and adjust the build scripts for your environment before building the pcodetest binary. There is a README file but as you will see it is rather involved and not well documented.
- Select bytes
- Open: Context menu > Data > String
- Open: Context menu > Data > Settings > Charset
- File > Add to program
- Memory Map > Add Memory Block
- Length: file size
- Overlay: check
- File Bytes: added file
- File Offset: 0
- Load PDB symbols (if available)
- Export... > Binary BinExport (v2) for BinDiff
- bindiff primary.BinExport secondary.BinExport, take primary_vs_secondary.BinDiff
- bindiff --ui
- Diffs > Add Existing Diff...