Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@
/src/.theos
/src/theos
/src/packages
/.theos
/src/CocoaTop/CocoaTop.xcodeproj/xcuserdata
/src/CocoaTop/CocoaTop.xcodeproj/project.xcworkspace/xcuserdata
/packages
/src/CocoaTop-helper/bin
666 changes: 0 additions & 666 deletions CocoaTop.xcodeproj/project.pbxproj

This file was deleted.

This file was deleted.

23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ARCHS = arm64
TARGET = iphone:clang:18.4:12.0
APPLICATION_NAME = CocoaTop

.PHONY: build-subprojects

#DEBUG = 0
#FINALPACKAGE = 1
#PACKAGE_VERSION = $(THEOS_PACKAGE_BASE_VERSION)

include $(THEOS)/makefiles/common.mk
SUBPROJECTS += src/CocoaTop
include $(THEOS_MAKE_PATH)/aggregate.mk

build-subprojects:
@$(MAKE) -C src/CocoaTop-helper all

ipa: build-subprojects package
@mkdir -p .theos/_tmp/build/Payload
@cp -r .theos/_/Applications/* .theos/_tmp/build/Payload
@cd .theos/_tmp/build/ && zip -r ../../../packages/$(APPLICATION_NAME).tipa Payload
@cd ../../../..
@echo "[+] Done! IPA created"
12 changes: 12 additions & 0 deletions layout/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Package: ru.domo.cocoatop64
Name: CocoatopTS
Version: 3.0.0
Architecture: iphoneos-arm
Description: Process Viewer for iOS GUI, updated for iOS 13 by SXX.
Depends: firmware (>= 12.0) | org.swift.libswift
Conflicts: ru.domo.cocoatop
Replaces: ru.domo.cocoatop
Breaks: ru.domo.cocoatop
Author: Domo, SXX
Maintainer: AlvinHV
Section: Applications
48 changes: 48 additions & 0 deletions src/CocoaTop-helper/Ent.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.private.security.storage.AppDataContainers</key>
<true/>
<key>com.apple.private.security.no-sandbox</key>
<true/>
<key>com.apple.private.security.sandbox.debug-mode</key>
<true/>
<key>com.apple.private.persona-mgmt</key>
<true/>
<key>platform-application</key>
<true/>
<key>get-task-allow</key>
<true/>
<key>proc_info-allow</key>
<true/>
<key>task_for_pid-allow</key>
<true/>
<key>com.apple.private.network.statistics</key>
<true/>
<key>com.apple.security.temporary-exception.sbpl</key>
<array>
<string>(allow signal)</string>
<string>(allow ipc-posix-sem)</string>
<string>(allow ipc-posix-shm)</string>
<string>(allow process-info-listpids)</string>
<string>(allow process-info*)</string>
</array>
<key>com.apple.security.exception.process-info</key>
<array/>
<key>com.apple.system-task-ports</key>
<true/>
<key>com.apple.managedconfiguration.profiled-access</key>
<true/>
<key>com.apple.private.logging.diagnostic</key>
<true/>
<key>com.apple.private.memorystatus</key>
<true/>
<key>com.apple.private.thread-set-state</key>
<true/>
<key>com.apple.private.set-exception-port</key>
<true/>
<key>com.apple.private.sysdiagnose</key>
<true/>
</dict>
</plist>
27 changes: 27 additions & 0 deletions src/CocoaTop-helper/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
TARGET = CocoaTop-helper
OUTDIR ?= bin

CC = xcrun -sdk iphoneos cc -arch arm64
LDID = ldid
CFLAGS = -Wall

.PHONY: clean all

all: clean $(OUTDIR)/$(TARGET)

DEBUG ?= 0
ifeq ($(DEBUG), 1)
CFLAGS +=
else
CFLAGS += -O2
endif

$(OUTDIR):
mkdir -p $(OUTDIR)

$(OUTDIR)/$(TARGET): RootWrapper.c | $(OUTDIR)
$(CC) -o $@ $^ $(CFLAGS)
$(LDID) -SEnt.plist $@

clean:
rm -f $(OUTDIR)/$(TARGET)
89 changes: 89 additions & 0 deletions src/CocoaTop-helper/RootWrapper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/sysctl.h>
#include <sys/types.h>
#include <signal.h>

// Comparator to sort kinfo_proc by PID
static int sort_procs_by_pid(const void *a, const void *b) {
const struct kinfo_proc *p1 = a;
const struct kinfo_proc *p2 = b;
if (p1->kp_proc.p_pid < p2->kp_proc.p_pid) return -1;
if (p1->kp_proc.p_pid > p2->kp_proc.p_pid) return 1;
return 0;
}

// Fill the shared buffer with process info, return count or -1 on error
static ssize_t get_process_list(struct kinfo_proc *kp, size_t bufSize) {
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0 };
size_t size = bufSize;
if (sysctl(mib, 4, kp, &size, NULL, 0) < 0) {
return -1;
}
ssize_t count = size / sizeof(struct kinfo_proc);
qsort(kp, count, sizeof(struct kinfo_proc), sort_procs_by_pid);
return count;
}

int main(int argc, char *argv[]) {
if (argc < 2) {
fprintf(stderr, "Usage: %s <buf_size>\n", argv[0]);
return EXIT_FAILURE;
}

char shm_name[50];
int parent_pid = getppid();
snprintf(shm_name, sizeof(shm_name), "/cocoatop_%d", parent_pid);

int shm_fd = shm_open(shm_name, O_RDWR , S_IRUSR | S_IWUSR);
if (shm_fd < 0) {
perror("helper: shm_open");
return 1;
}

size_t bufSize = (size_t)strtoull(argv[1], NULL, 10);

// mmap the shared memory region
struct kinfo_proc *kp = mmap(NULL, bufSize,
PROT_READ | PROT_WRITE,
MAP_SHARED, shm_fd, 0);
if (kp == MAP_FAILED) {
perror("mmap");
return EXIT_FAILURE;
}

char line[128];
while (fgets(line, sizeof(line), stdin)) {
// Strip newline
size_t len = strlen(line);
if (len > 0 && line[len-1] == '\n') {
line[len-1] = '\0';
}

if (strcmp(line, "getprocs") == 0) {
ssize_t count = get_process_list(kp, bufSize);
if (count < 0) {
fprintf(stderr, "Failed to get process list: %s\n", strerror(errno));
printf("-1\n");
} else {
printf("%zd\n", count);
}
fflush(stdout);
}
else if (strcmp(line, "quit") == 0) {
break;
}
else {
fprintf(stderr, "Unknown command: %s\n", line);
fflush(stderr);
}
}

munmap(kp, bufSize);
return EXIT_SUCCESS;
}
Loading