Skip to content

Commit

Permalink
bind sdk fix decode bit start index
Browse files Browse the repository at this point in the history
  • Loading branch information
ddkwork committed Jun 19, 2024
1 parent 787388f commit 1727232
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 53 deletions.
4 changes: 1 addition & 3 deletions bin/debug/SDK/Headers/BasicTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
// Basic Datatypes //
//////////////////////////////////////////////////

//#include <wchar.h>
#include <windows.h>

#include <wchar.h>

typedef unsigned long long QWORD;
typedef unsigned __int64 UINT64, *PUINT64;
Expand Down
21 changes: 0 additions & 21 deletions gengo/bind/sdkMerge/bug/bug.go

This file was deleted.

39 changes: 20 additions & 19 deletions gengo/bind/sdkMerge/bug/bug.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
//#include <windows.h>
typedef unsigned __int64 UINT64, *PUINT64;

#define X86_FLAGS_RESERVED_BITS 0xffc38028
#define X86_FLAGS_FIXED 0x00000002

#define IOCTL_PREACTIVATE_FUNCTIONALITY \
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x820, METHOD_BUFFERED, FILE_ANY_ACCESS)

// typedef struct _CR3_TYPE
// {
// union
// {
// UINT64 Flags;
//
// struct
// {
// UINT64 Pcid : 12;
// UINT64 PageFrameNumber : 36;
// UINT64 Reserved1 : 12;
// UINT64 Reserved_2 : 3;
// UINT64 PcidInvalidate : 1;
// } Fields;
// };
// } CR3_TYPE, *PCR3_TYPE;
typedef struct _CR3_TYPE
{
union
{
UINT64 Flags;

struct
{
UINT64 Pcid : 12;
UINT64 PageFrameNumber : 36;
UINT64 Reserved1 : 12;
UINT64 Reserved_2 : 3;
UINT64 PcidInvalidate : 1;
} Fields;
};
} CR3_TYPE, *PCR3_TYPE;

//typedef union
//{
Expand Down Expand Up @@ -80,10 +81,10 @@


// typedef struct xed_immdis_s {
//// union xed_immdis_values_t value;
// union xed_immdis_values_t value;
// unsigned int currently_used_space :4; // current number of assigned bytes
// unsigned int max_allocated_space :4; // max allocation, 4 or 8
// int present : 1;
// int immediate_is_unsigned : 1;
// bool present : 1;
// bool immediate_is_unsigned : 1;
// } xed_immdis_t;
//
2 changes: 1 addition & 1 deletion gengo/bind/sdkMerge/bug/bug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ func TestDemoDll(t *testing.T) {
AdditionalParams: []string{},
}),
)
mylog.Check(pkg.WriteToDir("."))
mylog.Check(pkg.WriteToDir("./tmp"))
}
17 changes: 11 additions & 6 deletions gengo/clang/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,36 @@ func (o *Options) ClangCommand(opt ...string) ([]byte, error) {
mylog.CheckIgnore(cmd.Run())
println(Stderr.String())
stream.WriteTruncate("astError.log", Stderr)
stream.WriteAppend("ast.log", Stdout)
stream.WriteTruncate("ast.log", Stdout)
return Stdout.Bytes(), nil
}

func CreateAST(opt *Options) ([]byte, error) {
return opt.ClangCommand(
"-fsyntax-only",
"-E",
"-dM",
//"-fsyntax-only",
"-nobuiltininc",
"-Xclang",
"-ast-dump=json",
"-Xclang",
"-fmacro-backtrace-limit=0",
//"-Xclang",
//"-fmacro-backtrace-limit=0",
)
}

func CreateLayoutMap(opt *Options) ([]byte, error) {
return opt.ClangCommand(
//"-E",
//"-dM",
"-fsyntax-only",
"-nobuiltininc",
"-emit-llvm",
"-Xclang",
"-fdump-record-layouts",
"-Xclang",
"-fdump-record-layouts-complete",
"-Xclang",
"-fmacro-backtrace-limit=0",
//"-Xclang",
//"-fmacro-backtrace-limit=0",
)
}

Expand All @@ -81,6 +85,7 @@ func Parse(opt *Options) (ast Node, layout *LayoutMap, err error) {
})
errg.Go(func() error {
res, e := CreateLayoutMap(opt)
stream.WriteTruncate("astLayout.log", res)
if e != nil {
return e
}
Expand Down
14 changes: 11 additions & 3 deletions gengo/clang/layout_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ type RecordLayout struct {
func (r *RecordLayout) UnmarshalString(data string) error {
// mylog.Check(errors.New("improperly terminated layout"))
first := true
offset := 0

for _, line := range strings.Split(data, "\n") {
before, after, found := strings.Cut(line, "|")
if !found {
Expand All @@ -83,11 +85,17 @@ func (r *RecordLayout) UnmarshalString(data string) error {
if strings.Contains(before, ":") && strings.Contains(before, "-") {
mylog.Todo("bitset bug")
//continue
split := strings.Split(before, ":")
bitRange := strings.Split(split[1], "-")
start, end := mylog.Check2(strconv.Atoi(bitRange[0])), mylog.Check2(strconv.Atoi(bitRange[1]))
println(offset)
offset += end - start + 1
//offset = mylog.Check2(strconv.Atoi(bitRange[0]))
} else {
// Parse offset
offset = mylog.Check2Ignore(strconv.Atoi(strings.TrimSpace(before)))
}

// Parse offset
offset := mylog.Check2Ignore(strconv.Atoi(strings.TrimSpace(before)))

// Determine indentation level
indent := len(after)
after = strings.TrimLeft(after, " \t")
Expand Down

0 comments on commit 1727232

Please sign in to comment.