Closed 0sm1les closed 1 month ago
this issue was marked as to little info so i made a small example.
main.go
package main
import (
"encoding/json"
"fmt"
"garbe-test/models"
"os"
)
func main() {
var test models.Garble_test
test_string := `{
"Field1":"test1",
"Field2":"test2",
"Field3":3
}`
err := json.Unmarshal([]byte(test_string), &test)
if err != nil {
fmt.Println(err)
os.Exit(0)
}
fmt.Println(test)
}
models.go
package models
type Garble_test struct {
Field1 string
Field2 string
Field3 int
}
running with go build
$ go build main.go && ./main
{test1 test2 3}
running with garble build -seed="random"
$ /home/user/go/bin/garble -seed="random" build
$ ./main
{ 0}
i also tried reading from a file because maybe this string was being messed up but it was not the case. Still did not work with garble and worked with go build.
When i move the struct out of my models package and into the main package it works, although this is unoptimal and should be fixed
package main
import (
"encoding/json"
"fmt"
"os"
)
type Garble_test struct {
Field1 string
Field2 string
Field3 int
}
func main() {
var test Garble_test
test_string := `{
"Field1":"test1",
"Field2":"test2",
"Field3":3
}`
err := json.Unmarshal([]byte(test_string), &test)
if err != nil {
fmt.Println(err)
os.Exit(0)
}
fmt.Println(test)
}
$ garble -seed="random" build
-seed chosen at random: wXOTnV9OlJLgRx1jWBDQEA
$ ./main
{test1 test2 3}
tried "solution" in bigger program and does not work
because json.unmarshal is not throwing any errors, I think this problem is to do with obfuscating the struct. if you change the names of the fields and your raw json still uses the original field names it wont be able to match the values.
case in point, I tried to use json.marshal to serialize some directory info and this is the result, its technically working but this is not workable:
Gr1jjyGHsVeT: 7
SlLV5YxVF: false
U5vyWJ: "Lrwxrwxrwx"
VG4aj5: "bin"
as you can see the original field names have been replaced.
I think the solution to this is to have an option where you can choose to not obfuscate structs for this reason.
my temporary solution is to use maps, but i imagine this will be a common issue for a lot of software.
@0sm1les see https://github.com/burrowers/garble?tab=readme-ov-file#caveats, in particular the second point there. This is a known limitation and not one that can be fixed without making builds extremely slow.
What version of Garble and Go are you using?
What environment are you running Garble on?
xubuntu
go env
OutputWhat did you do?
json unmarshal does not work, when I unmarshal into a struct and check the struct it is empty even though unmarshel returned no errors. the code works as intended when just using go build.
What did you expect to see?
a struct filled with my info.
What did you see instead?
an empty struct.