- 
                Notifications
    
You must be signed in to change notification settings  - Fork 231
 
Auto-detect Ghidra protobuf version at build time #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Detect version from GHIDRA_INSTALL_DIR instead of hardcoding - Check gradle.properties for source builds - Scan for protobuf jars in release builds - Fallback to 3.21.8 if detection fails - Changed to compileOnly dependency to prevent bundling - Fixes VerifyError with mismatched protobuf versions
| extraLibs | ||
| // Detect protobuf version from Ghidra installation | ||
| // Allow manual override via -PghidraProtobufVersion=x.y.z | ||
| def detectGhidraProtobufVersion() { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow. This is pretty involved for "just linking protobuf" :)
        
          
                java/build.gradle
              
                Outdated
          
        
      | } | ||
| dependencies { | ||
| classpath 'com.google.protobuf:protobuf-gradle-plugin:0.9.5' | ||
| classpath 'com.google.protobuf:protobuf-gradle-plugin:0.9.4' | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason we're downgrading this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No particular reason, except for a typo ^^.
I just build and tested with a revision to "0.9.5" and it works just as well.
If you want I just add another commit on top reverting to "0.9.5"
| 
           Thank you! I was tearing my hair out the last time I looked at this. But the explanation makes perfect sense. I'll try and merge this soon-ish, but I'm travelling.  | 
    
          
 I'm not sure what the best course of action is here for now. Just my two cents: 
 So I guess that it's safe to keep  Thoughts?  | 
    
Summary
Auto-detect Ghidra's protobuf version from the installation directory to prevent runtime version mismatch errors.
Problem
BinExport previously hardcoded protobuf 4.31.0 and bundled it in the extension ZIP. This caused runtime errors when used with Ghidra releases that ship different protobuf versions:
When the extension bundled 4.31.0 ran on Ghidra 11.4.2, it caused, e.g. following error:
This happened because bundled protobuf 4.x (which uses
GeneratedMessageV3) replaced Ghidra's runtime protobuf 3.x classes (which useGeneratedMessage), creating binary-incompatible class hierarchies.Solution
Auto-detect protobuf version from
GHIDRA_INSTALL_DIR:ghidra.protobuf.java.versionfromgradle.propertiesprotobuf-java-*.jarin known locations (Ghidra/Debug/ProposedUtils/lib,Ghidra/Framework)-PghidraProtobufVersion=x.y.zfor edge casesChanged from
implementationtocompileOnlydependency. This prevents bundling protobuf in the extension.zip, but is provided by Ghidra itself it at runtime.Changes
Modified:
java/build.gradleAdded
detectGhidraProtobufVersion()functionRemoved
configurations { extraLibs }and bundling logicChanged dependency:
implementation→compileOnlyAdded
runtimeClasspathexclusion as safety netPreserved Eclipse IDE configuration and license headers
Testing
Environment:
OS: Ubuntu 22.04
Java: OpenJDK 21
Ghidra: 11.4.2 release (protobuf 3.21.8)
Build verification:
Runtime testing:
.BinExportfiles (optionally with additional IDA Pro CompatibilityValidation:
hello worldfiles)IllegalAccessError,or protobuf-related errorsNote:
Manual override example:
gradle -PghidraProtobufVersion=4.31.0 buildExtensionThe extension now adapts to the installed Ghidra version automatically, eliminating the need for manual build.gradle edits when switching between Ghidra versions.