burrowers / garble

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

Effect of reflection on obfuscation #860

Open Haif-07 opened 6 days ago

Haif-07 commented 6 days ago

I have no idea about the effect of reflection on obfuscation. My code is as follows. I would like to know whether the use of reflection will affect the program. I am trying to find out why my program cannot run normally.



func archive(object interface{}, objects []interface{}) ([]interface{}, plist.UID) {
    if object, ok := isPrimitiveObject(object); ok {
        index := len(objects)
        objects = append(objects, object)
        return objects, plist.UID(index)
    }

    if v, ok := object.([]interface{}); ok {
        return serializeArray(v, objects)
    }

    if v, ok := object.(map[string]interface{}); ok {
        return serializeMap(v, objects, buildClassDict("NSDictionary", "NSObject"))
    }
    typeOf := reflect.TypeOf(object)
    name := typeOf.Name()
    // seems like Name() can be empty for pointer types
    if name == "" {
        name = typeOf.String()
    }

    if encoderFunc, ok := encodableClasses[name]; ok {
        return encoderFunc(object, objects)
    }

    panic(fmt.Errorf("NSKeyedArchiver Unsupported object: '%s' of type:%s", object, typeOf))
}
lu4p commented 6 days ago

Any types that are passed directly to this function as the "object" parameter will not be obfuscated in order to not break reflection.

This may still break on complex types or parameters passed via multiple layers of function calls.

Can you provide a concrete error message and type for which this breaks?

Haif-07 commented 6 days ago

There is no error message when compiling, but when opening the executable program, some functions are completely unavailable

Haif-07 commented 5 days ago

I used this repository https://github.com/danielpaulus/go-ios to make the simplest call. The code is as follows. I wonder if you can test it. I really don't know where the specific problem is.

package main

import (
    "fmt"

    "github.com/danielpaulus/go-ios/ios"
)

func main() {
    // Connect to the first available device
    devices, err := ios.ListDevices()
    if err != nil {
        fmt.Println("Error listing devices: ", err)
        return
    }
    fmt.Println("Found devices: ", devices)

}
  1. This repository has a file with a nested structure. I modified it manually. There are not many, you need to modify it slightly before it can run.
  2. You need to use mac or install itunes on windows to use it
  3. The result is that the one built with go build can be used normally. The one built with garble build cannot be used normally.