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

expects import "golang.org/x/sys/unix" #10

Open
CaledoniaProject opened this issue Mar 9, 2019 · 9 comments
Open

expects import "golang.org/x/sys/unix" #10

CaledoniaProject opened this issue Mar 9, 2019 · 9 comments

Comments

@CaledoniaProject
Copy link

I got the following error with gobfuscate:

2019/03/09 03:55:25 Obfuscating symbols...
Renamed 2 occurrences in 2 files in 1 package.
Renamed 1 occurrence in 1 file in 1 package.
Renamed 1 occurrence in 1 file in 1 package.
Renamed 1 occurrence in 1 file in 1 package.
Renamed 1 occurrence in 1 file in 1 package.
Renamed 1 occurrence in 1 file in 1 package.
Renamed 2 occurrences in 2 files in 2 packages.
Renamed 2 occurrences in 2 files in 2 packages.
/tmp/613618656/src/ehincglpolcljoeojneb/args.go:4:2: code in directory /tmp/613618656/src/afnacmagbfmgjmnmffin/ikihhbconjooebdgogkp/cmmkiannaflaadabloef/unix expects import "golang.org/x/sys/unix"
Failed to compile: exit status 1

How can I debug this?

@CaledoniaProject
Copy link
Author

I have removed the relevant code, but still got issues

2019/03/09 04:14:58 Obfuscating strings...
2019/03/09 04:14:58 Obfuscating symbols...
Renamed 1 occurrence in 1 file in 1 package.
Renamed 2 occurrences in 2 files in 2 packages.
Renamed 2 occurrences in 2 files in 2 packages.
Renamed 2 occurrences in 2 files in 1 package.
Renamed 1 occurrence in 1 file in 1 package.
Renamed 1 occurrence in 1 file in 1 package.
Renamed 1 occurrence in 1 file in 1 package.
Renamed 1 occurrence in 1 file in 1 package.
build cache is required, but could not be located: GOCACHE is not defined and neither $XDG_CACHE_HOME nor $HOME are defined
Failed to compile: exit status 1

@unixpickle
Copy link
Owner

Try the latest master branch, which sets GOCACHE.

@CaledoniaProject
Copy link
Author

New errors:

Failed to obfuscate symbols: top-level renames: /tmp/026921609/src/xxxxx/doc.go:10:1: expected declaration, found available

Source code:

// Package pty provides functions for working with Unix terminals.
package pty

import (
	"errors"
	"os"
)

// ErrUnsupported is returned if a function is not
// available on the current platform.
var ErrUnsupported = errors.New("unsupported")

@unixpickle
Copy link
Owner

Interesting. I'm guessing some other stage of the obfuscation pipeline corrupted the doc.go file somehow. To find out, try adding the -outdir flag so you can keep the obfuscated GOPATH after the obfuscation fails. Then you can look at the exact doc.go file that gorename is complaining about.

@CaledoniaProject
Copy link
Author

CaledoniaProject commented Jun 17, 2019

I've deleted all previous comments and merged the bug report into one:

Problem 1

Unable to process multiple // comments

// ErrUnsupported is returned if a function is not
// available on the current platform.
var ErrUnsupported = errors.New("unsupported")

became

     9	// ErrUnsupported is returned if a function is not
    10	available on the current platform.
    11	m.
    12	var ErrUnsupported = errors.New((func() string {
    13	mask := []byte("\x2e\xe5\xd4\xcd\x26\x50\xa8\x1c\xce\xe3\x55")
    14	maskedStr := []byte("\x5b\x8b\xa7\xb8\x56\x20\xc7\x6e\xba\x86\x31")

Problem 2

Unable to process /**/ style comments:

/* ErrUnsupported is returned if a function is not
   available on the current platform. */

became

/*  ErrUnsupported is returned if a function is not
   available on the current platform.
/

Problem 3

Did not process comments after package keyword.

package unix // import "golang.org/x/sys/unix"

This will throw an error if package name is unexpected:

src/XXX/args.go:4:2: code in directory /XXXX/src/XXX/XXX/jidgeindacgiemcpihnp/unix expects import "golang.org/x/sys/unix"

@CaledoniaProject
Copy link
Author

I've patched removeDoNotEdit and append only comments that contains the keyword // +build, it finally worked.

@unixpickle
Copy link
Owner

By the way, removeDoNotEdit had a bug for a brief while (a few hours) before I fixed it. Is the comment problem still happening on the latest master branch? The latest master should also respect build tags (added yesterday)

@CaledoniaProject
Copy link
Author

Yes, it is the master branch. The last commit is 18 hours ago.

@unixpickle
Copy link
Owner

Problem 3 is an interesting one, as it seems to reveal deeper problems with some Go build tools. For example, my IDE complains about the comment example you provided, and it simply relies on existing Go source code analysis tools. I think we should create a separate issue for problem 3.

To check the other two problems, I created a directory in my GOPATH with the package name github.com/unixpickle/testme and made a main.go file:

package main

import (
	"errors"
	"fmt"
)

// ErrUnsupported is returned if a function is not
// available on the current platform.
var ErrUnsupported = errors.New("unsupported")

// Foo is a cool structure
// with a doc comment.
type Foo struct {
}

/* Ignored checks something
   that it shouldn't? */
func (f *Foo) Ignored() {
}

func main() {
	fmt.Println("hi")
}

Gobfuscate correctly obfuscates it with this output:

package main

import (
	"errors"
	"fmt"
)

// Mkcdnleioandomamdfam is returned if a function is not
// available on the current platform.
var Mkcdnleioandomamdfam = errors.New((func() string {
	mask := []byte("\x21\x0f\xc7\xbb\x81\x86\x39\xac\x48\xa4\xc6")
	maskedStr := []byte("\x54\x61\xb4\xce\xf1\xf6\x56\xde\x3c\xc1\xa2")
	res := make([]byte, 11)
	for i, m := range mask {
		res[i] = m ^ maskedStr[i]
	}
	return string(res)
}()))

// Ogfkflibbhjhjmmgjajd is a cool structure
// with a doc comment.
type Ogfkflibbhjhjmmgjajd struct {
}

/* Ignored checks something
   that it shouldn't? */
func (f *Ogfkflibbhjhjmmgjajd) Cdlckjmaedannakkmjko() {
}

func main() {
	fmt.Println((func() string {
		mask := []byte("\xaf\xa2")
		maskedStr := []byte("\xc7\xcb")
		res := make([]byte, 2)
		for i, m := range mask {
			res[i] = m ^ maskedStr[i]
		}
		return string(res)
	}()))
}

On commit a109102, I see problems 1 and 2 as you described. But not on master.

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

No branches or pull requests

2 participants