Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NSArray description #478

Merged
merged 19 commits into from
May 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix addresses and refactor
GLinnik21 committed May 16, 2024
commit a390753b1beb5511eb73eae0686da4325e1dfc1e
30 changes: 16 additions & 14 deletions Sources/KSCrashRecordingCore/KSObjC.c
Original file line number Diff line number Diff line change
@@ -1575,43 +1575,45 @@ static inline int nsarrayCount(const void* const arrayPtr)
return 0;
}

static int nsarrayContents(const void* const arrayPtr, uintptr_t* contents, int count)
static int nsarrayContents(const void *const arrayPtr, uintptr_t *contents, int count)
{
int actualCount = nsarrayCount(arrayPtr);
const char* const className = ksobjc_objectClassName(arrayPtr);
const char *const className = ksobjc_objectClassName(arrayPtr);

if(actualCount < (CFIndex)count)
if (actualCount < count)
{
if(actualCount <= 0)
if (actualCount <= 0)
{
return 0;
}
count = actualCount;
}
// TODO: implement this (requires bit-field unpacking) in ksobj_ivarValue
if(nsarrayIsMutable(arrayPtr))

if (nsarrayIsMutable(arrayPtr))
{
return 0;
}

id entry = NULL;

// https://github.com/apple/llvm-project/blob/29180d27e709b76965cc02c338188e37f2df9e7f/lldb/source/Plugins/Language/ObjC/NSArray.cpp#L772-L787
const uintptr_t *entry = NULL;

if (strcmp(className, "__NSSingleObjectArrayI") == 0)
{
const NSArrayDescriptor *arrayI = (const NSArrayDescriptor *)arrayPtr;
entry = (id)arrayI->_data;
// Using a temp variable to handle aligment of NSArrayDescriptor
uintptr_t temp_data = arrayI->_data;
entry = &temp_data;
}
else
{
const struct NSArray* array = arrayPtr;
entry = array->basic.firstEntry;
const struct NSArray *array = (const struct NSArray *)arrayPtr;
entry = (const uintptr_t *)&array->basic.firstEntry;
}
if(!ksmem_copySafely(&entry, contents, (int)sizeof(*contents) * count))

if (!ksmem_copySafely(entry, contents, sizeof(*contents) * count))
{
return 0;
}

return count;
}