Skip to content
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

support fetching original package names and import paths via reflection #904

Merged
merged 5 commits into from
Jan 12, 2025

Conversation

mvdan
Copy link
Member

@mvdan mvdan commented Jan 4, 2025

(see commit messages - please do not squash)

Updates #849.

mvdan added 4 commits January 4, 2025 22:23
This function returns obfuscated names, so use that as its name.
Moreover, some of the callers still called the result "objStr",
which misled me into thinking the string was a unique object path.

Leave a TODO behind about using go/types/objectpath too.
Our own recordedObjectString is sort of similar, but not as principled.
Only two callers did pass nil, and there's no reason for them to do so.
They should be the ones to check that typeToObj did not return nil.
There's no need to reach for sharedCache.ListedPackages
when the caller is computePkgCache, which already has the lpkg value.

While here, compare *go/types.Package pointers directly
rather than via their import path strings.
Reflection can show package names alone via reflect.Type.String,
and I'm sure they are available in other ways.
We were obfuscating "package p" exactly like the import path "foo.com/p"
which worked OK for the most part, but not for reflection.

This is also a slight improvement to the quality of the obfuscation,
given that package names and import paths will no longer be aligned
when obfuscated.
Copy link
Member

@lu4p lu4p left a comment

Choose a reason for hiding this comment

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

I think this PR is too aggressive at including import paths.

In your last commit message explain that we're doing this to support "wails" builds or things like it.

reflect.go Outdated Show resolved Hide resolved
reflect.go Show resolved Hide resolved
reflect.go Show resolved Hide resolved
reflect.go Show resolved Hide resolved
testdata/script/reflect.txtar Outdated Show resolved Hide resolved
obfuscatedImportPath already handled ToObfuscate, so the callers
don't have to do that as well. Handle main packages too, whose logic
was sprinkled and repeated throughout the project.
@mvdan
Copy link
Member Author

mvdan commented Jan 12, 2025

Given that we don't agree on this, and that the approach as written doesn't fix Wails anyway, I'll need to give this a second attempt in a separate PR.

For now, I have updated the PR to remove package name and path deobfuscation, and fixed a failing test as well. All of the changes leading up to the original reflect change are still valuable in my opinion, and should be merged.

@lu4p lu4p merged commit 3c742da into burrowers:master Jan 12, 2025
4 checks passed
@mvdan mvdan deleted the reflect-pkgpath branch January 12, 2025 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants