NationalSecurityAgency / ghidra

Ghidra is a software reverse engineering (SRE) framework
https://www.nsa.gov/ghidra
Apache License 2.0
51.12k stars 5.82k forks source link

Extending from HeadlessScript in Python #1306

Closed daqo closed 4 years ago

daqo commented 4 years ago

I'm interested in calculating Analysis Time in Ghidra. I was going to log the start_time at the end of my preprocessor script (storing it temporarily using the storeHeadlessValue method). Later, I was going to get the current time at the beginning of my postprocessor function and do a simple endTime - beginningTime.

A couple of questions:

  1. Is there a better way to get the analysis time?
  2. Is there a way to inherit from HeadlessScript in python? My understanding is that I need to extend from that to be able to use storeHeadlessValue.
astrelsky commented 4 years ago

Technically you can inherit any java class in jython as long as it's visible, but I'm not sure this would be helpful.

Analysis time is calculated and logged automatically even in headless mode. It may be found in the application.log file. If you wish to fetch that information you may retrieve it as a pre-formatted string by the following:

AutoAnalysisManager mgr = AutoAnalysisManager.getAnalysisManager(currentProgram);
String result = mgr.getTaskTimesString();

of course making modifications as necessary for python.

The AutoAnalysisManager class is not documented but it is public and located in the package ghidra.app.plugin.core.analysis

Here is as example of the timing output from the log.

-----------------------------------------------------
    ASCII Strings                              1.029 secs
    Apply Data Archives                        0.857 secs
    Call Convention Identification             0.200 secs
    Call-Fixup Installer                       0.031 secs
    Create Address Tables                      0.070 secs
    Create Address Tables - One Time           0.160 secs
    Create Function                            0.028 secs
    DWARF                                      0.183 secs
    Data Reference                             0.155 secs
    Decompiler Switch Analysis                 0.140 secs
    Decompiler Switch Analysis - One Time      0.338 secs
    Demangler                                  0.309 secs
    Disassemble Entry Points                   0.511 secs
    ELF Scalar Operand References              0.120 secs
    Embedded Media                             0.220 secs
    External Entry References                  0.000 secs
    Function Start Search                      0.221 secs
    Function Start Search After Code           0.019 secs
    Function Start Search After Data           0.020 secs
    GCC C++ Class Analyzer                     3.880 secs
    GCC Exception Handlers                     2.739 secs
    GCC RTTI Analyzer                          2.230 secs
    Non-Returning Functions - Discovered       0.414 secs
    Non-Returning Functions - Known            0.016 secs
    Reference                                  0.226 secs
    Shared Return Calls                        0.078 secs
    Stack                                      1.829 secs
    Subroutine References                      0.057 secs
    Subroutine References - One Time           0.000 secs
    x86 Constant Reference Analyzer            1.781 secs
-----------------------------------------------------
     Total Time   17 secs
-----------------------------------------------------
daqo commented 4 years ago

Thank you for your quick response. Closing the ticket.