Skip to content

Commit

Permalink
fix: array decoding (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
t0rr3sp3dr0 committed Jun 2, 2024
1 parent b5c7468 commit 00b2be9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
14 changes: 9 additions & 5 deletions types/objc/type_encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,17 +366,21 @@ func decodeType(encType string) string {
}

func decodeArray(arrayType string) string {
numIdx := strings.LastIndexAny(arrayType, "0123456789")
if len(arrayType) == 1 {
return fmt.Sprintf("x[%s]", arrayType)
typIdx := 0
for _, c := range arrayType {
if c < '0' || c > '9' {
break
}

typIdx++
}

decType := decodeType(arrayType[numIdx+1:])
decType := decodeType(arrayType[typIdx:])
if !strings.HasSuffix(decType, "*") {
decType += " "
}

return fmt.Sprintf("%sx[%s]", decType, arrayType[:numIdx+1])
return fmt.Sprintf("%sx[%s]", decType, arrayType[:typIdx])
}

func decodeStructure(structure string) string {
Expand Down
9 changes: 8 additions & 1 deletion types/objc/type_encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ func Test_decodeType(t *testing.T) {
want: "struct OutterStruct { union InnerUnion { long long x0; struct InnerStruct { int x0; int x1; } x1; } x0; unsigned int x1:1; unsigned int x2:2; unsigned int x3:10; unsigned int x4:1; long long x5; void *x6[2]; signed char *x7 __attribute__((aligned(8), vector_size(4))); _Atomic unsigned long long x8; } *",
},
{
name: "Test array",
name: "Test array 0",
args: args{
encType: "[2^v]",
},
want: "void *x[2]",
},
{
name: "Test array 1",
args: args{
encType: "[20{IDSGlobalLinkAttribute=\"type\"S\"len\"S\"value\"(?=\"ss\"{sockaddr_storage=\"ss_len\"C\"ss_family\"C\"__ss_pad1\"[6c]\"__ss_align\"q\"__ss_pad2\"[112c]}\"u16\"S\"u32\"I\"u64\"Q\"binaryData\"{IDSGLAttrBinaryData_=\"len\"i\"data\"[1024C]})}]",
},
want: "struct IDSGlobalLinkAttribute { unsigned short type; unsigned short len; union { struct sockaddr_storage { unsigned char ss_len; unsigned char ss_family; signed char __ss_pad1[6]; long long __ss_align; signed char __ss_pad2[112]; } ss; unsigned short u16; unsigned int u32; unsigned long long u64; struct IDSGLAttrBinaryData_ { int len; unsigned char data[1024]; } binaryData; } value; } x[20]",
},
{
name: "Test bitfield",
args: args{
Expand Down

0 comments on commit 00b2be9

Please sign in to comment.