unixpickle / gobfuscate

Obfuscate Go binaries and packages
BSD 2-Clause "Simplified" License
1.45k stars 157 forks source link

Struct methods won't be obfuscated if method's receiver is a struct pointer #6

Closed XiaoMouR closed 5 years ago

XiaoMouR commented 6 years ago

It seems the struct's methods like follows won't be obfuscated.

type AStruct struct {
  field1 string
  field2 int 
}
func (a *AStruct) MethodA(){}
func (a *BStruct) MethodB(){}

I found that in methodRenames, type assert rev.Type.(fmt.Stringer) returns false

XiaoMouR commented 6 years ago

In this case, rev.Type is *ast.StarExpr, which makes type assert failed.

ghost commented 6 years ago

I met the same problem.But it can be solved by replacing the corresponding codes with codes below. It is truly a fatal bug because of the plenty use of starExpr. for _, rec := range d.Recv.List { 156 s, ok := rec.Type.(fmt.Stringer) 157 if !ok { 158 if se,ok:=rec.Type.(*ast.StarExpr);ok{ 159 s,ok=se.X.(fmt.Stringer) 160 if !ok { 161 fmt.Println("NOstringer",rec.Type,reflect.TypeOf(se.X)) 162 continue 163 } 164 }else{ 165 fmt.Println("NOstringer",rec.Type,reflect.TypeOf(rec.Type)) 166 continue 167 } 168 169 }