-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Big refactor incl Ghidra 11.1 support (#78)
* Big Refactor (MVP, but not cleaned up yet) * Use extra method for checking credentials instead of relying on health endpoint * Use dedicated endpoint for checking validity of credentials * Implement binary uploading * Make health check more resilient * Cleanup, minor fixes and support for Ghidra 11.1 * Use Ghidra 11.1 in CI --------- Co-authored-by: Florian Magin <fmagin@users.noreply.github.com>
- Loading branch information
Showing
55 changed files
with
2,187 additions
and
1,674 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import ai.reveng.toolkit.ghidra.core.services.api.GhidraRevengService; | ||
import ai.reveng.toolkit.ghidra.core.services.api.types.AnalysisStatus; | ||
import ai.reveng.toolkit.ghidra.core.services.api.types.ApiInfo; | ||
import ai.reveng.toolkit.ghidra.core.services.api.types.BinaryID; | ||
import ghidra.app.script.GhidraScript; | ||
import ghidra.program.model.listing.CircularDependencyException; | ||
import ghidra.program.model.symbol.Namespace; | ||
import ghidra.program.model.symbol.SourceType; | ||
import ghidra.util.exception.DuplicateNameException; | ||
import ghidra.util.exception.InvalidInputException; | ||
|
||
public class RevEngAutoRenamePostScript extends GhidraScript { | ||
@Override | ||
protected void run() throws Exception { | ||
// Services are not available in headless mode, so we have to instantiate it ourself | ||
var ghidraRevengService = new GhidraRevengService(ApiInfo.fromConfig()); | ||
ghidraRevengService.upload(currentProgram); | ||
var binID = ghidraRevengService.analyse(currentProgram); | ||
// Wait for analysis to finish | ||
waitForAnalysis(ghidraRevengService, binID); | ||
|
||
var revengMatchNamespace = currentProgram.getSymbolTable().getOrCreateNameSpace( | ||
currentProgram.getGlobalNamespace(), | ||
"RevEng", | ||
SourceType.ANALYSIS | ||
); | ||
// Fetch Function matches | ||
ghidraRevengService.getSimilarFunctions(currentProgram, 1, 0.05).forEach( | ||
(function, matches) -> { | ||
var bestMatch = matches.get(0); | ||
Namespace libraryNamespace = null; | ||
try { | ||
libraryNamespace = currentProgram.getSymbolTable().getOrCreateNameSpace( | ||
revengMatchNamespace, | ||
bestMatch.nearest_neighbor_binary_name(), | ||
SourceType.ANALYSIS); | ||
} catch (DuplicateNameException e) { | ||
throw new RuntimeException(e); | ||
} catch (InvalidInputException e) { | ||
throw new RuntimeException(e); | ||
} | ||
try { | ||
function.getSymbol().setNameAndNamespace( | ||
bestMatch.nearest_neighbor_function_name(), | ||
libraryNamespace, | ||
SourceType.ANALYSIS | ||
); | ||
println("Renamed " + function.getName() + " to " + bestMatch.nearest_neighbor_function_name() + " from " + bestMatch.nearest_neighbor_binary_name() + " with confidence " + bestMatch.confidence()); | ||
} catch (DuplicateNameException e) { | ||
throw new RuntimeException(e); | ||
} catch (InvalidInputException e) { | ||
throw new RuntimeException(e); | ||
} catch (CircularDependencyException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
} | ||
|
||
); | ||
|
||
|
||
} | ||
|
||
|
||
private void waitForAnalysis(GhidraRevengService ghidraRevengService, BinaryID binID) throws InterruptedException { | ||
var analysisComplete = false; | ||
while (!analysisComplete) { | ||
Thread.sleep(5000); | ||
switch (ghidraRevengService.status(binID)) { | ||
case Complete: | ||
println("Analysis finished successfully"); | ||
analysisComplete = true; | ||
break; | ||
case Error: | ||
println("Analysis failed"); | ||
analysisComplete = true; | ||
break; | ||
case Processing: | ||
println("Analysis still running"); | ||
break; | ||
case Queued: | ||
println("Analysis queued"); | ||
break; | ||
default: | ||
println("Unknown status"); | ||
break; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.