burrowers / garble

Obfuscate Go builds
BSD 3-Clause "New" or "Revised" License
3.73k stars 239 forks source link

reflection detection doesn't work for structs containing functions which return structs #817

Open lu4p opened 7 months ago

lu4p commented 7 months ago

While debugging #690 I found another case where reflection detection breaks down.

This is mostly a constructed esoteric case, however I want to save it for future reference.

This:

func closure() {
    type gobAlias struct {
        Security func() struct {
            Pad bool
        }
    }

    alias := gobAlias{}

    gob.NewEncoder(os.Stdout).Encode(alias)

    outer := func() func() struct{ Pad bool } {
        return func() struct{ Pad bool } {
            return struct{ Pad bool }{Pad: true}
        }
    }

    alias.Security = outer()
}

becomes:

func j4wwfVoxrQ3U() {
    type gobAlias struct {
        Security func() struct {
            CyKzfu_6PMml bool
        }
    }

    zHwfgoTGbS := gobAlias{}

     /*line pO5sQyOpjxG.go:1*/ gob.Z86VmnB5d5(os.E09Xl1y).Encode(zHwfgoTGbS)

    lSqYMFQpWJG := func() func() struct{ CyKzfu_6PMml bool } {
        return func() struct{ CyKzfu_6PMml bool } {
            return struct{ CyKzfu_6PMml bool }{CyKzfu_6PMml: true}
        }
    }

    zHwfgoTGbS.Security =  /*line FquOVyLxB.go:1*/ lSqYMFQpWJG()
}

In an ideal world the return type shouldn't be obfuscated anywhere.