Skip to content

Correctly rename InvokeDynamic method references during obfuscation#156

Open
ShortyDev wants to merge 2 commits intoGuardsquare:masterfrom
ShortyDev:feat
Open

Correctly rename InvokeDynamic method references during obfuscation#156
ShortyDev wants to merge 2 commits intoGuardsquare:masterfrom
ShortyDev:feat

Conversation

@ShortyDev
Copy link
Copy Markdown

@ShortyDev ShortyDev commented Dec 16, 2025

This PR enables ProGuard to track and update the method name in invokedynamic instructions (Lambdas) when the target Functional Interface method is renamed. Previously, only the descriptor type was updated, leading to a mismatch between the instruction name and the actual interface method.

Changes:

  • InvokeDynamicConstant: Added referencedClass and referencedMember fields to store the resolved Functional Interface method.
  • LambdaReferenceInitializer: Introduced a new visitor that links invokedynamic constants to their corresponding interface members.
  • MemberReferenceFixer: Added logic to detect if the linked member has been renamed and update the NameAndType constant in the pool accordingly.

Relevant issue:
Guardsquare/proguard#512

*
* @author ShortyDev
*/
public class LambdaReferenceInitializer implements ClassVisitor, ConstantVisitor {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this class is completely unused outside of javadoc, what is the purpose?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what you actually want to do is modify the visitInvokeDynamicConstant implementation of the ClassReferenceInitializer, and drop the new class.

*
* <p>The class hierarchy must be initialized before using this visitor.
*
* @author ShortyDev
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove author tag

@piazzesiNiccolo-GS
Copy link
Copy Markdown
Contributor

Please make sure to add a reproducing test that justifies this code :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants