Skip to content

Commit

Permalink
Rename Swift meta class to SwiftABI
Browse files Browse the repository at this point in the history
  • Loading branch information
YungRaj committed Dec 12, 2024
1 parent e606445 commit 43d8556
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 36 deletions.
2 changes: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ genrule(

cc_library(
name = "DarwinKit_kext_library",
srcs = glob(["kernel/*.c"]),
srcs = glob(["kernel/*.c"] + ["darwinkit/*.c"]),
hdrs = glob(["kernel/*.h"]) + glob(["darwinkit/*.h"]),
includes = [
"kernel",
Expand Down
2 changes: 1 addition & 1 deletion arm64/disassembler_arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ bool registerAccess(cs_insn* insn, cs_regs regs_read, uint8_t* nread, cs_regs re
return cs_regs_access(handle_arm64, insn, regs_read, nread, regs_write, nwrite) == 0;
}

xnu::mach::VmAddress disassembleNthBranchLink(xnu::mach::VmAddress address, size_t num,
xnu::mach::VmAddress DisassembleNthBranchLink(xnu::mach::VmAddress address, size_t num,
size_t lookup_size) {
cs_insn* result = nullptr;

Expand Down
2 changes: 1 addition & 1 deletion kernel/kernel_darwin_kit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ bool IOKernelDarwinKitService::start(IOService* provider) {
ret = darwinkit_start(this, kernel, &darwinkitKext);

if (ret == kIOReturnSuccess) {
darwinkit = mac_darwinkit_get_darwinkit();
darwinkit = darwinkit_get_darwinkit();
}

registerService();
Expand Down
2 changes: 1 addition & 1 deletion kernel/kernel_darwin_kit.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extern kern_return_t darwinkit_start(IOKernelDarwinKitService* service, xnu::Ker
extern kern_return_t darwinkit_stop(IOKernelDarwinKitService* service, xnu::Kernel* kernel,
xnu::Kext** kext);

extern darwin::DarwinKit* mac_darwinkit_get_darwinkit();
extern darwin::DarwinKit* darwinkit_get_darwinkit();

class IOKernelDarwinKitService : public IOService {
OSDeclareDefaultStructors(IOKernelDarwinKitService)
Expand Down
20 changes: 8 additions & 12 deletions user/dyld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@

#include <mach/mach.h>

static int EndsWith(const char* str, const char* suffix) {
namespace darwin {
namespace dyld {

char* Dyld::Contains(char* str, const char* substr) {
return strstr(str, substr);
}

int Dyld::EndsWith(const char* str, const char* suffix) {
if (!str || !suffix)
return 0;

Expand All @@ -39,17 +46,6 @@ static int EndsWith(const char* str, const char* suffix) {
return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0;
}

static char* Contains(char* str, const char* substr) {
return strstr(str, substr);
}

namespace darwin {
namespace dyld {

Dyld::Dyld(xnu::Kernel* kernel, xnu::Task* task) : kernel(kernel), task(task) {
IterateAllImages();
}

void Dyld::IterateAllImages() {
bool found_main_image = false;

Expand Down
9 changes: 8 additions & 1 deletion user/dyld.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ using ImageInfo = struct dyld_image_info;

class Dyld {
public:
explicit Dyld(xnu::Kernel* kernel, xnu::Task* task);
explicit Dyld(xnu::Kernel* kernel, xnu::Task* task)
: kernel(kernel), task(task) {
IterateAllImages();
}

~Dyld() = default;

Expand Down Expand Up @@ -87,6 +90,10 @@ class Dyld {
return slide;
}

char* Contains(char* str, const char* substr);

int EndsWith(const char* str, const char* suffix);

void GetImageInfos();

void IterateAllImages();
Expand Down
2 changes: 1 addition & 1 deletion user/macho_userspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class MachOUserspace : public MachO {
darwin::CodeSignature* codeSignature;

objc::ObjCData* objc;
swift::SwiftMetadata* swift;
swift::SwiftABI* swift;

char* file_path;

Expand Down
4 changes: 1 addition & 3 deletions user/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
#include "dwarf.h"
#include "dyld.h"
#include "kernel.h"
#include "macho_userspace.h"
#include "pac.h"
#include "task.h"
#include "macho_userspace.h"

#include <arm64/patch_finder_arm64.h>

Expand Down Expand Up @@ -391,7 +391,6 @@ int injectLibrary(char* dylib) {
libSystemPthread->GetAslrSlide();

printf("dlopen = 0x%llx\n", dlopen);

printf("pthread_create_from_mach_thread = 0x%llx\n", pthread_create_from_mach_thread);

if ((kr = thread_create(task->GetTaskPort(), &remote_thread)) != KERN_SUCCESS) {
Expand Down Expand Up @@ -551,7 +550,6 @@ void print_usage() {

int main(int argc, char** argv) {
// fuzzer::Harness *harness = new fuzzer::Harness(new xnu::Kernel());

int err;

char* wait_for_process_name = nullptr;
Expand Down
18 changes: 9 additions & 9 deletions user/swift.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ static char kSwift5Protos[] = "__swift5_protos";
static char kSwift5Capture[] = "__swift5_capture";
static char kSwift5Mpenum[] = "__swift5_mpenum";

SwiftMetadata* ParseSwift(darwin::MachOUserspace* macho) {
return macho->GetObjCMetadata() ? new SwiftMetadata(macho, macho->GetObjCMetadata()) : nullptr;
SwiftABI* ParseSwift(darwin::MachOUserspace* macho) {
return macho->GetObjCMetadata() ? new SwiftABI(macho, macho->GetObjCMetadata()) : nullptr;
}

void SwiftMetadata::PopulateSections() {
void SwiftABI::PopulateSections() {
if (!text) {
text = macho->GetSegment(kTextSegment);
}
Expand All @@ -71,11 +71,11 @@ void SwiftMetadata::PopulateSections() {
mpenum = macho->GetSection(kTextSegment, kSwift5Mpenum);
}

void SwiftMetadata::ParseSwift() {
void SwiftABI::ParseSwift() {
EnumerateTypes();
}

void SwiftMetadata::EnumerateTypes() {
void SwiftABI::EnumerateTypes() {
Section* types = GetTypes();

UInt8* swift_types_begin = (*macho)[types->GetOffset()];
Expand Down Expand Up @@ -103,7 +103,7 @@ void SwiftMetadata::EnumerateTypes() {
}
}

struct Type* SwiftMetadata::ParseTypeDescriptor(struct TypeDescriptor* typeDescriptor) {
struct Type* SwiftABI::ParseTypeDescriptor(struct TypeDescriptor* typeDescriptor) {
struct Type* type;

struct TypeDescriptor* descriptor;
Expand Down Expand Up @@ -188,7 +188,7 @@ struct Type* SwiftMetadata::ParseTypeDescriptor(struct TypeDescriptor* typeDescr
return type;
}

UInt64 SwiftMetadata::GetTypeMetadata(struct TypeDescriptor* typeDescriptor) {
UInt64 SwiftABI::GetTypeMetadata(struct TypeDescriptor* typeDescriptor) {
UInt64 typeMetadata;

UInt64 accessFunction = typeDescriptor->access_function;
Expand Down Expand Up @@ -226,7 +226,7 @@ UInt64 SwiftMetadata::GetTypeMetadata(struct TypeDescriptor* typeDescriptor) {
#endif
}

void SwiftMetadata::ParseFieldDescriptor(struct Type* type,
void SwiftABI::ParseFieldDescriptor(struct Type* type,
struct FieldDescriptor* fieldDescriptor) {
struct Fields* fields = new Fields;

Expand All @@ -250,6 +250,6 @@ void SwiftMetadata::ParseFieldDescriptor(struct Type* type,
}
}

void SwiftMetadata::ParseClassMetadata(Class* cls) {}
void SwiftABI::ParseClassMetadata(Class* cls) {}

} // namespace swift
8 changes: 4 additions & 4 deletions user/swift.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,13 @@ struct CaptureDescriptor {

#pragma options align = reset

class SwiftMetadata {
class SwiftABI {
public:
explicit SwiftMetadata(MachO* macho, objc::ObjCData* objc) : macho(macho), objc(objc) {
explicit SwiftABI(MachO* macho, objc::ObjCData* objc) : macho(macho), objc(objc) {
PopulateSections();
ParseSwift();
}
explicit SwiftMetadata(MachO* macho, objc::ObjCData* objc, Segment* text)
explicit SwiftABI(MachO* macho, objc::ObjCData* objc, Segment* text)
: macho(macho), objc(objc), text(text) {
PopulateSections();
ParseSwift();
Expand Down Expand Up @@ -414,5 +414,5 @@ class SwiftMetadata {
Section* mpenum;
};

SwiftMetadata* ParseSwift(darwin::MachOUserspace* macho);
SwiftABI* ParseSwift(darwin::MachOUserspace* macho);
}; // namespace swift
4 changes: 2 additions & 2 deletions x86_64/disassembler_x86_64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ mach_vm_address_t DisassembleNthCall(mach_vm_address_t address, size_t num, size
return 0;
}

mach_vm_address_t disassembleNthJmp(mach_vm_address_t address, size_t num, size_t lookup_size) {
mach_vm_address_t DisassembleNthJmp(mach_vm_address_t address, size_t num, size_t lookup_size) {
cs_insn* result = nullptr;

size_t disasm_size = arch::x86_64::disassembler::Disassemble(address, lookup_size, &result);
Expand Down Expand Up @@ -215,7 +215,7 @@ mach_vm_address_t disassembleNthJmp(mach_vm_address_t address, size_t num, size_
return 0;
}

mach_vm_address_t disassembleNthInstruction(mach_vm_address_t address, x86_insn insn, size_t num,
mach_vm_address_t DisassembleNthInstruction(mach_vm_address_t address, x86_insn insn, size_t num,
size_t lookup_size) {
cs_insn* result = nullptr;

Expand Down

0 comments on commit 43d8556

Please sign in to comment.