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

@ -5,39 +5,9 @@ import (
"os"
)
type Type struct {
Type string `json:"type"`
Name string `json:"name"`
ArraySize int32 `json:"arrsize,omitempty"`
}
type StructMemberType struct {
Type string `json:"type"`
Name string `json:"name"`
ArraySize int32 `json:"arrsize,omitempty"`
Offset int32 `json:"offset,omitempty"`
}
type StructType struct {
Name string `json:"name"`
Members []StructMemberType `json:"members,omitempty"`
}
type UnionType struct {
Name string `json:"name"`
Members []Type `json:"members,omitempty"`
}
type FunctionType struct {
ReturnType string `json:"rettype"`
CallConvention string `json:"callconv"`
NoReturn bool `json:"noreturn"`
Name string `json:"name"`
Arguments []Type `json:"arguments,omitempty"`
}
// Describes the format of an x64dbg type information file
type Types struct {
Types []Type `json:"types,omitempty"`
Types []AliasType `json:"types,omitempty"`
Structs []StructType `json:"structs,omitempty"`
Unions []UnionType `json:"unions,omitempty"`
Functions []FunctionType `json:"functions,omitempty"`
@ -59,3 +29,21 @@ func SaveTypes(name string, types *Types) (err error) {
err = file.Close()
return
}
func LoadTypes(name string) (types *Types, err error) {
var file *os.File
file, err = os.Open(name)
if err != nil {
return
}
types = new(Types)
e := json.NewDecoder(file)
if err = e.Decode(types); err != nil {
return
}
err = file.Close()
return
}