feat(go): x64dbg can't parse types correctly without being in the correct order, but we can use Kahn topological sorting to avoid issues

This commit is contained in:
phaneron 2024-08-01 01:19:29 -04:00
parent df04015c59
commit b6fb39c844
12 changed files with 475 additions and 35 deletions

View file

@ -40,4 +40,5 @@ func init() {
x64dbg_gen.Flags().StringP("base-address", "b", "00400000", "the base address of the module")
rootCmd.AddCommand(x64dbg_gen)
rootCmd.AddCommand(x64dbg_typesort)
}

View file

@ -0,0 +1,32 @@
package cmd
import (
"encoding/json"
"os"
"github.com/spf13/cobra"
"github.com/thunderbrewhq/binana/go/x64dbg"
)
var x64dbg_typesort = &cobra.Command{
Use: "x64dbg-typesort [types.json file]",
Short: "sort a x64dbg types file",
Run: x64dbg_typesort_func,
}
func x64dbg_typesort_func(cmd *cobra.Command, args []string) {
types, err := x64dbg.LoadTypes(args[0])
if err != nil {
panic(err)
}
if err = x64dbg.SortTypes(types); err != nil {
panic(err)
}
encoder := json.NewEncoder(os.Stdout)
encoder.SetIndent("", " ")
if err = encoder.Encode(types); err != nil {
panic(err)
}
}