Skip to content

Commit

Permalink
jetsamctl way.
Browse files Browse the repository at this point in the history
  • Loading branch information
PoomSmart committed Mar 20, 2019
1 parent 4cf19c0 commit 9a0826b
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion LetMeBlock.plist
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ Filter = { Executables = ( "mDNSResponder" ); }; }
{ Filter = { Executables = ( "mDNSResponder", "mDNSResponderHelper" ); }; }
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PACKAGE_VERSION = 0.0.4.4
PACKAGE_VERSION = 0.0.5

TARGET = iphone:latest:9.0

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# LetMeBlock
Makes mDNSResponder care about `/etc/hosts` on iOS 12, and load **all** entries on iOS 9+

In order to load all entries on iOS 9+, the memory limits defined in `Version4 > Daemon > Override > com.apple.mDNSResponder.reloaded` of the jetsam properties plist **must be increased**.
In order to load all entries on iOS 9+, the memory limits defined in `Version4 > Daemon > Override > com.apple.mDNSResponder.reloaded` of the jetsam properties plist **must be increased**. This can be done either by manually editing the plist or using jetsamctl's API, see [here](https://github.com/conradev/jetsamctl).

If in any cases the tweak does not seem to work, you either
* Reinstall LetMeBlock from Cydia
* Run the command `killall -9 mDNSResponder` as root
* Run the command `killall -9 mDNSResponder; killall -9 mDNSResponderHelper` as root
42 changes: 40 additions & 2 deletions Tweak.xm
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
#import <substrate.h>

#include <stdlib.h>
#include <errno.h>
#include <sys/sysctl.h>
#include <sys/kern_memorystatus.h>

#define DEFAULT_HOSTS_PATH "/etc/hosts"
#define NEW_HOSTS_PATH "/etc/hosts.lmb"

unsigned int *_mDNS_StatusCallback_allocated = NULL;

// Allow /etc/hosts to be read on iOS 12
%hookf(bool, "_os_variant_has_internal_diagnostics", const char *subsystem) {
if (subsystem && strcmp(subsystem, "com.apple.mDNSResponder") == 0)
return 1;
return %orig;
}

// Reset the memory counter every time it is increased
%hookf(void, "_mDNS_StatusCallback", void *arg1, int arg2) {
if (_mDNS_StatusCallback_allocated)
*_mDNS_StatusCallback_allocated = 0;
%orig;
}

// The new UHB will place all the blocked addresses to NEW_HOSTS_PATH so we won't mess up with the original file
// Open UHB's hosts instead of /etc/hosts
// This new UHB will place all the blocked addresses to NEW_HOSTS_PATH so we won't mess up with the original file
// If in any cases NEW_HOSTS_PATH got corrupted, we fallback to the original one (DEFAULT_HOSTS_PATH)
%hookf(int, "_open", const char *path, int oflag, ...) {
int result = 0;
Expand Down Expand Up @@ -54,5 +62,35 @@ hook:
%ctor {
_mDNS_StatusCallback_allocated = (unsigned int *)MSFindSymbol(NULL, "_mDNS_StatusCallback.allocated");
HBLogDebug(@"Found _mDNS_StatusCallback_allocated: %d", _mDNS_StatusCallback_allocated != NULL);
%init;
if (_mDNS_StatusCallback_allocated) {
// mDNSResponder (_mDNSResponder)
%init;
} else {
// mDNSResponderHelper (root)
pid_t pid = 0;
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0};
size_t size;
if (sysctl(mib, 4, NULL, &size, NULL, 0) == -1)
HBLogError(@"LetMeBlock-jetsamctl: error: %s", strerror(errno));
else {
struct kinfo_proc *processes = (struct kinfo_proc *)malloc(size);
if (processes == NULL)
HBLogError(@"LetMeBlock-jetsamctl: error: %s", strerror(errno));
else if (sysctl(mib, 4, processes, &size, NULL, 0) == -1)
HBLogError(@"LetMeBlock-jetsamctl: error: %s", strerror(errno));
else {
for (unsigned long i = 0; i < size / sizeof(struct kinfo_proc); i++) {
if (strcmp(processes[i].kp_proc.p_comm, "mDNSResponder") == 0) {
pid = processes[i].kp_proc.p_pid;
break;
}
}
free(processes);
if (pid == 0)
HBLogError(@"LetMeBlock-jetsamctl: error: %s", strerror(ESRCH));
else if (memorystatus_control(MEMORYSTATUS_CMD_SET_JETSAM_TASK_LIMIT, pid, 384, NULL, 0) == -1)
HBLogError(@"LetMeBlock-jetsamctl: error: %s", strerror(errno));
}
}
}
}
2 changes: 1 addition & 1 deletion control
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: com.ps.letmeblock
Name: LetMeBlock
Depends: mobilesubstrate, firmware (>= 9.0), com.bingner.plutil
Depends: mobilesubstrate, firmware (>= 9.0)
Version: 0.0.1
Architecture: iphoneos-arm
Description: Make mDNSResponder care more about /etc/hosts
Expand Down
1 change: 1 addition & 0 deletions layout/DEBIAN/extrainst_
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ if [[ $1 == install ]];then
finish reboot
elif [[ $1 == upgrade ]];then
killall -9 mDNSResponder || true
killall -9 mDNSResponderHelper || true
fi
23 changes: 0 additions & 23 deletions layout/DEBIAN/postinst

This file was deleted.

15 changes: 1 addition & 14 deletions layout/DEBIAN/postrm
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
#!/bin/sh

model=$(uname -i)
model=${model/AP/}

jetsam_orig_plist="/System/Library/LaunchDaemons/com.apple.jetsamproperties.${model}.plist.bak"
jetsam_plist="/System/Library/LaunchDaemons/com.apple.jetsamproperties.${model}.plist"

if [[ ! -f "${jetsam_orig_plist}" ]];then
echo "Error: Couldn't find the original jetsam properties plist (${jetsam_orig_plist})"
exit 1
fi

mv "${jetsam_orig_plist}" "${jetsam_plist}"
echo "Restored the backup file"

function finish() {
f="${1}"
[[ -z "${f}" || -z "${CYDIA}" ]] && return
Expand All @@ -27,4 +13,5 @@ if [[ "$1" == "remove" || "$1" == "abort-install" ]];then
finish reboot
fi
killall -9 mDNSResponder || true
killall -9 mDNSResponderHelper || true
fi
3 changes: 0 additions & 3 deletions make.sh

This file was deleted.

Binary file removed packages/com.ps.letmeblock_0.0.4.4_iphoneos-arm.deb
Binary file not shown.
Binary file added packages/com.ps.letmeblock_0.0.5_iphoneos-arm.deb
Binary file not shown.

0 comments on commit 9a0826b

Please sign in to comment.