Skip to content

Commit

Permalink
Modify components to support ghidra-10.4
Browse files Browse the repository at this point in the history
  • Loading branch information
john0x1a committed Oct 16, 2023
1 parent 4c8495a commit 78449d4
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 24 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'
- uses: actions/cache@v3
id: cache
Expand All @@ -27,7 +27,7 @@ jobs:
uses: er28-0652/[email protected]
if: steps.cache.outputs.cache-hit != 'true'
with:
version: '10.1.2'
version: '10.4'
- name: Download Z3
uses: pavpanchekha/[email protected]
if: steps.cache.outputs.cache-hit != 'true'
Expand All @@ -39,7 +39,7 @@ jobs:
if: steps.cache.outputs.cache-hit == 'true'
run: |
echo "CPATH=/opt/hostedtoolcache/z3/4.8.15/x64/z3-4.8.15-x64-glibc-2.31/include" >> $GITHUB_ENV
echo "GHIDRA_INSTALL_DIR=/opt/hostedtoolcache/ghidra/10.1.2/x64" >> $GITHUB_ENV
echo "GHIDRA_INSTALL_DIR=/opt/hostedtoolcache/ghidra/10.4/x64" >> $GITHUB_ENV
- name: Setup Z3
run: |
cp $CPATH/../bin/com.microsoft.z3.jar $GITHUB_WORKSPACE/lib/com.microsoft.z3.jar
Expand All @@ -52,5 +52,5 @@ jobs:
- name: Integration test
uses: gradle/gradle-build-action@0d13054264b0bb894ded474f08ebb30921341cee
with:
gradle-version: current
gradle-version: 7.4
arguments: integrationTest
10 changes: 5 additions & 5 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'
- uses: actions/cache@v3
id: cache
Expand All @@ -27,7 +27,7 @@ jobs:
uses: er28-0652/[email protected]
if: steps.cache.outputs.cache-hit != 'true'
with:
version: '10.1.2'
version: '10.4'
- name: Download Z3
uses: pavpanchekha/[email protected]
if: steps.cache.outputs.cache-hit != 'true'
Expand All @@ -39,13 +39,13 @@ jobs:
if: steps.cache.outputs.cache-hit == 'true'
run: |
echo "CPATH=/opt/hostedtoolcache/z3/4.8.15/x64/z3-4.8.15-x64-glibc-2.31/include" >> $GITHUB_ENV
echo "GHIDRA_INSTALL_DIR=/opt/hostedtoolcache/ghidra/10.1.2/x64" >> $GITHUB_ENV
echo "GHIDRA_INSTALL_DIR=/opt/hostedtoolcache/ghidra/10.4/x64" >> $GITHUB_ENV
- name: Setup Z3
run: |
cp $CPATH/../bin/com.microsoft.z3.jar $GITHUB_WORKSPACE/lib/com.microsoft.z3.jar
sudo cp $CPATH/../bin/*.so /lib
- name: Unit test
uses: gradle/gradle-build-action@0d13054264b0bb894ded474f08ebb30921341cee
with:
gradle-version: current
gradle-version: 7.4
arguments: test
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ARG UBUNTU_MIRROR=mirrors.tuna.tsinghua.edu.cn

FROM gradle:7-jdk11
FROM gradle:7-jdk17

ARG UBUNTU_MIRROR
# Non-interactive installation requirements
Expand All @@ -22,9 +22,9 @@ RUN apt-get update -qq && apt-get install -y \

# Ghidra installation

ARG GHIDRA_RELEASE_TAG=Ghidra_10.1.2_build
ARG GHIDRA_VERSION=ghidra_10.1.2_PUBLIC
ARG GHIDRA_BUILD=${GHIDRA_VERSION}_20220125
ARG GHIDRA_RELEASE_TAG=Ghidra_10.4_build
ARG GHIDRA_VERSION=ghidra_10.4_PUBLIC
ARG GHIDRA_BUILD=${GHIDRA_VERSION}_20230928

RUN wget https://github.com/NationalSecurityAgency/ghidra/releases/download/${GHIDRA_RELEASE_TAG}/${GHIDRA_BUILD}.zip && \
unzip -d ghidra ${GHIDRA_BUILD}.zip && \
Expand Down
1 change: 0 additions & 1 deletion ghidra_scripts/BinAbsInspector.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.bai.checkers.CheckerManager;
import com.bai.env.funcs.FunctionModelManager;
import com.bai.util.Config.HeadlessParser;
import generic.continues.RethrowContinuesFactory;
import ghidra.app.util.bin.MemoryByteProvider;
import ghidra.app.util.bin.format.elf.ElfException;
import ghidra.app.util.bin.format.elf.ElfHeader;
Expand Down
6 changes: 4 additions & 2 deletions src/integration/java/IntegrationTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ghidra.app.plugin.core.analysis.AutoAnalysisManager;
import ghidra.app.util.importer.AutoImporter;
import ghidra.app.util.importer.MessageLog;
import ghidra.app.util.opinion.LoadResults;
import ghidra.program.flatapi.FlatProgramAPI;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Function;
Expand Down Expand Up @@ -32,14 +33,15 @@ public static void initEnv() {

protected Program prepareProgram(File file) throws Exception {
GlobalState.reset();
Program program = AutoImporter.importByUsingBestGuess(file, null, this, new MessageLog(),
LoadResults<Program> loadResults = AutoImporter.importByUsingBestGuess(file, null, null, this, new MessageLog(),
TaskMonitorAdapter.DUMMY);
Program program = loadResults.getPrimaryDomainObject();
AutoAnalysisManager analysisManager = AutoAnalysisManager.getAnalysisManager(program);
analysisManager.initializeOptions();
final int tid = program.startTransaction("analysis");
GlobalState.currentProgram = program;
GlobalState.flatAPI = new FlatProgramAPI(program);
if (!program.getOptions(Program.PROGRAM_INFO).getBoolean(Program.ANALYZED, false)) {
if (!program.getOptions(Program.PROGRAM_INFO).getBoolean(Program.ANALYZED_OPTION_NAME, false)) {
GlobalState.flatAPI.analyzeAll(program);
}
program.endTransaction(tid, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import ghidra.program.model.data.DataTypeManager;
import ghidra.program.model.data.FunctionDefinition;
import ghidra.program.model.data.FunctionDefinitionDataType;
import ghidra.program.model.data.GenericCallingConvention;
import ghidra.program.model.data.IntegerDataType;
import ghidra.program.model.data.ParameterDefinition;
import ghidra.program.model.data.ParameterDefinitionImpl;
Expand Down Expand Up @@ -67,7 +68,7 @@ private static void writeSignature(Function function, Address callsite, Function

ParameterDefinition[] params = sig.getArguments();
FunctionDefinitionDataType fsig = new FunctionDefinitionDataType("tmpname");
fsig.setGenericCallingConvention(sig.getGenericCallingConvention());
fsig.setGenericCallingConvention(GenericCallingConvention.getGenericCallingConvention(sig.getCallingConventionName()));

Check warning on line 71 in src/main/java/com/bai/env/funcs/externalfuncs/VarArgsFunctionBase.java

View workflow job for this annotation

GitHub Actions / build

[reviewdog] reported by reviewdog 🐶 Line is longer than 120 characters (found 127). Raw Output: /github/workspace/./src/main/java/com/bai/env/funcs/externalfuncs/VarArgsFunctionBase.java:71:0: warning: Line is longer than 120 characters (found 127). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
fsig.setArguments(params);
fsig.setReturnType(sig.getReturnType());
fsig.setVarArgs(sig.hasVarArgs());
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/com/bai/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.bai.env.funcs.FunctionModelManager;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import generic.continues.RethrowContinuesFactory;
import ghidra.app.cmd.function.ApplyFunctionSignatureCmd;
import ghidra.app.util.bin.MemoryByteProvider;
import ghidra.app.util.bin.format.elf.ElfException;
Expand Down Expand Up @@ -350,14 +349,13 @@ public static List<Reference> getReferences(List<String> symbolNames) {
public static Function getEntryFunction() {
try {
MemoryByteProvider provider = new MemoryByteProvider(GlobalState.currentProgram.getMemory(),
GlobalState.currentProgram.getMinAddress());

GlobalState.currentProgram.getMinAddress(), true);
Address entryAddress;
String executableFormat = GlobalState.currentProgram.getExecutableFormat();

switch (executableFormat) {
case ElfLoader.ELF_NAME: {
ElfHeader header = ElfHeader.createElfHeader(RethrowContinuesFactory.INSTANCE, provider);
ElfHeader header = new ElfHeader(provider, null);
entryAddress = GlobalState.flatAPI.toAddr(header.e_entry());
if (entryAddress.subtract(GlobalState.currentProgram.getImageBase()) < 0) {
// handle PIE ELF with non-zero base address
Expand All @@ -367,8 +365,7 @@ public static Function getEntryFunction() {
break;

case PeLoader.PE_NAME: {
PortableExecutable pe = PortableExecutable.createPortableExecutable(
RethrowContinuesFactory.INSTANCE, provider, PortableExecutable.SectionLayout.MEMORY);
PortableExecutable pe = new PortableExecutable(provider, PortableExecutable.SectionLayout.MEMORY);
OptionalHeader header = pe.getNTHeader().getOptionalHeader();
entryAddress = GlobalState.flatAPI.toAddr(header.getAddressOfEntryPoint());
entryAddress = entryAddress.add(GlobalState.currentProgram.getImageBase().getOffset());
Expand Down

0 comments on commit 78449d4

Please sign in to comment.