Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
A few more Socket level stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Naville committed Aug 12, 2016
1 parent e0d637c commit f6fad3a
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ before_install:
- clear
- export THEOS=/opt/theos

script: "sudo python ./CIScripts/get-pip.py && ./Setup.sh && ./CIScripts/InstallTheos.sh &&./build.py DEBUG"
script: "sudo python ./CIScripts/get-pip.py && ./Setup.sh && ./CIScripts/InstallTheos.sh &&./build.py DEBUG && cat STDOUT.log && cat STDERR.log"
68 changes: 62 additions & 6 deletions Hooks/API/Socket.xm
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ int getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict)
int getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict)
__DARWIN_ALIAS(getsockname);
int getsockopt(int, int, int, void * __restrict, socklen_t * __restrict);
ssize_t
recvfrom(int socket, void *restrict buffer, size_t length, int flags,
struct sockaddr *restrict address, socklen_t *restrict address_len);
ssize_t
recvmsg(int socket, struct msghdr *message, int flags);
ssize_t
Expand Down Expand Up @@ -64,6 +59,23 @@ static NSString* get_ip_str(const struct sockaddr *sa)
}
}

static NSMutableDictionary* GetInfoFormsghdr(struct msghdr* message){
NSMutableDictionary* RetDict=[NSMutableDictionary dictionary];
if(message->msg_name!=NULL){
[RetDict setObject:get_ip_str((const struct sockaddr *)message->msg_name) forKey:@"MessageName"];
}
NSMutableArray* iovecArray=[[NSMutableArray array] autorelease];
if(message->msg_iov!=NULL && message->msg_iovlen>0){
for (int i = 0; i < message->msg_iovlen; i++) {
struct iovec currentIOVEC=message->msg_iov[i];
[iovecArray addObject:[NSData dataWithBytes:currentIOVEC.iov_base length:currentIOVEC.iov_len]];
}
}
[RetDict setObject:iovecArray forKey:@"IOVEC"];
[RetDict setObject:[NSData dataWithBytes:message->msg_control length:message->msg_controllen] forKey:@"Data"];
[RetDict setObject:[NSNumber numberWithInt:message->msg_flags] forKey:@"flags"];
return RetDict;
}

//Old Pointers
int (*old_socket)(int domain, int type, int protocol);
Expand All @@ -72,7 +84,8 @@ int (*old_bind)(int, struct sockaddr *, socklen_t);
int (*old_connect)(int, const struct sockaddr *, socklen_t);
int (*old_listen)(int, int);
ssize_t (*old_recv)(int socket, void *buffer, size_t length, int flags);

ssize_t (*old_recvfrom)(int socket, void *buffer, size_t length,int flags,struct sockaddr *address,socklen_t * addresslen);
ssize_t (*old_recvmsg)(int socket, struct msghdr *message, int flags);
//New Functions
int new_socket(int domain, int type, int protocol){
int descriptor=old_socket(domain,type,protocol);
Expand Down Expand Up @@ -189,11 +202,54 @@ ssize_t new_recv(int socket, void *buffer, size_t length, int flags){
}
return retVal;
}
ssize_t new_recvfrom(int socket, void *buffer, size_t length, int flags,struct sockaddr *address, socklen_t *address_len){
ssize_t retVal=0;
if(WTShouldLog){
retVal=old_recvfrom(socket,buffer,length,flags,address,address_len);
WTInit(@"Socket",@"recvfrom");
WTAdd([NSNumber numberWithUnsignedInt:socket],@"SocketFileDescriptor");
WTAdd([NSData dataWithBytes:buffer length:length],@"Data");
WTAdd([NSNumber numberWithInt:flags],@"Flags");
WTAdd(get_ip_str(address),@"Address");
WTReturn([NSNumber numberWithLong:retVal]);
WTSave;
WTRelease;

}
else{
retVal=old_recvfrom(socket,buffer,length,flags,address,address_len);
}
return retVal;



}
ssize_t new_recvmsg(int socket, struct msghdr *message, int flags){
ssize_t retVal=0;
if(WTShouldLog){
retVal=old_recvmsg(socket,message,flags);
WTInit(@"Socket",@"recvmsg");
WTAdd([NSNumber numberWithUnsignedInt:socket],@"SocketFileDescriptor");

WTAdd([NSNumber numberWithInt:flags],@"Flags");
WTAdd(GetInfoFormsghdr(message),@"Address");
WTReturn([NSNumber numberWithLong:retVal]);
WTSave;
WTRelease;

}
else{
retVal=old_recvmsg(socket,message,flags);
}
return retVal;

}
extern void init_Socket_hook() {
WTHookFunction((void*)socket,(void*)new_socket, (void**)&old_socket);
WTHookFunction((void*)accept,(void*)new_accept, (void**)&old_accept);
WTHookFunction((void*)bind,(void*)new_bind, (void**)&old_bind);
WTHookFunction((void*)connect,(void*)new_connect, (void**)&old_connect);
WTHookFunction((void*)listen,(void*)new_listen, (void**)&old_listen);
WTHookFunction((void*)recv,(void*)new_recv, (void**)&old_recv);
WTHookFunction((void*)recvfrom,(void*)new_recvfrom, (void**)&old_recvfrom);
}
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export CFLAGS=-Wp,"-DWTFJHTWEAKNAME=@\"NH919IJFS93JT68\","-DWTFJHHostName=@\"NavRMBP\"
export CFLAGS=-Wp,"-DWTFJHTWEAKNAME=@\"SIY616KCGLYUR1L\","-DWTFJHHostName=@\"NavRMBP\"
include $(THEOS)/makefiles/common.mk
TWEAK_NAME = NH919IJFS93JT68
TWEAK_NAME = SIY616KCGLYUR1L
SUBSTRATE ?= yes
NH919IJFS93JT68_FILES = Tweak.xm CompileDefines.xm Hooks/API/AppleAccount.xm Hooks/API/CommonCryptor.xm Hooks/API/CommonDigest.xm Hooks/API/CommonHMAC.xm Hooks/API/CommonKeyDerivation.xm Hooks/API/CoreTelephony.xm Hooks/API/dlfcn.xm Hooks/API/Keychain.xm Hooks/API/libC.xm Hooks/API/libMobileGestalt.xm Hooks/API/LSApplication.xm Hooks/API/MachO.xm Hooks/API/Notification.xm Hooks/API/NSData.xm Hooks/API/NSFileHandle.xm Hooks/API/NSFileManager.xm Hooks/API/NSHTTPCookie.xm Hooks/API/NSInputStream.xm Hooks/API/NSKeyedArchiver.xm Hooks/API/NSKeyedUnarchiver.xm Hooks/API/NSOutputStream.xm Hooks/API/NSProcessInfo.xm Hooks/API/NSURLConnection.xm Hooks/API/NSURLCredential.xm Hooks/API/NSURLSession.xm Hooks/API/NSUserDefaults.xm Hooks/API/NSXMLParser.xm Hooks/API/ObjCRuntime.xm Hooks/API/Security.xm Hooks/API/Socket.xm Hooks/API/SSLKillSwitch.xm Hooks/API/sysctl.xm Hooks/API/UIPasteboard.xm Hooks/SDK/FclBlowfish.xm Hooks/SDK/JSPatch.xm Hooks/SDK/OpenSSLAES.xm Hooks/SDK/OpenSSLBlowFish.xm Hooks/SDK/OpenSSLMD5.xm Hooks/SDK/OpenSSLSHA1.xm Hooks/SDK/OpenSSLSHA512.xm Hooks/SDK/Reveal.xm Hooks/SDK/Wax.xm Hooks/Utils/CallStackInspector.m Hooks/Utils/CallTracer.m Hooks/Utils/DelegateProxies.m Hooks/Utils/NSURLConnectionDelegateProx.m Hooks/Utils/NSURLSessionDelegateProxy.m Hooks/Utils/PlistObjectConverter.m Hooks/Utils/RemoteLogSender.m Hooks/Utils/RuntimeUtils.m Hooks/Utils/SQLiteStorage.m Hooks/Utils/Utils.m Hooks/ThirdPartyTools/classdumpdyld.xm Hooks/ThirdPartyTools/dumpdecrypted.xm Hooks/ThirdPartyTools/InspectiveC.xm Hooks/Misc/Cycript.xm Hooks/Misc/fishhook.c Hooks/Misc/RemoveASLR.xm Hooks/Misc/SplitMachO.mm Hooks/Misc/WTSubstrate.mm
NH919IJFS93JT68_CCFLAGS = -Qunused-arguments -std=c++11
NH919IJFS93JT68_LDFLAGS = -Wl,-segalign,4000,-sectcreate,WTFJH,SIGDB,./SignatureDatabase.plist,-sectcreate,WTFJH,classdumpdyld,./classdumpdyld.dylib,-sectcreate,WTFJH,dumpdecrypted,./dumpdecrypted.dylib,-sectcreate,WTFJH,InspectiveC,./InspectiveC.dylib -lz -L. -v -force_load ./ExtraFWs/libcapstone.a -force_load ./ExtraFWs/libLiberation.a -force_load ./ExtraFWs/Reveal.framework/Reveal -force_load ./ExtraFWs/Cycript.framework/Cycript -F./ExtraFWs/ -Wno-unused-function
NH919IJFS93JT68_CFLAGS = -I/Volumes/PAGEZERO/WTFJH/Hooks/
NH919IJFS93JT68_LIBRARIES = sqlite3 substrate stdc++ c++
NH919IJFS93JT68_FRAMEWORKS = Foundation UIKit Security JavaScriptCore UIKit CoreGraphics CoreFoundation QuartzCore CFNetwork
SIY616KCGLYUR1L_FILES = Tweak.xm CompileDefines.xm Hooks/API/AppleAccount.xm Hooks/API/CommonCryptor.xm Hooks/API/CommonDigest.xm Hooks/API/CommonHMAC.xm Hooks/API/CommonKeyDerivation.xm Hooks/API/CoreTelephony.xm Hooks/API/dlfcn.xm Hooks/API/Keychain.xm Hooks/API/libC.xm Hooks/API/libMobileGestalt.xm Hooks/API/LSApplication.xm Hooks/API/MachO.xm Hooks/API/Notification.xm Hooks/API/NSData.xm Hooks/API/NSFileHandle.xm Hooks/API/NSFileManager.xm Hooks/API/NSHTTPCookie.xm Hooks/API/NSInputStream.xm Hooks/API/NSKeyedArchiver.xm Hooks/API/NSKeyedUnarchiver.xm Hooks/API/NSOutputStream.xm Hooks/API/NSProcessInfo.xm Hooks/API/NSURLConnection.xm Hooks/API/NSURLCredential.xm Hooks/API/NSURLSession.xm Hooks/API/NSUserDefaults.xm Hooks/API/NSXMLParser.xm Hooks/API/ObjCRuntime.xm Hooks/API/Security.xm Hooks/API/Socket.xm Hooks/API/SSLKillSwitch.xm Hooks/API/sysctl.xm Hooks/API/UIPasteboard.xm Hooks/SDK/FclBlowfish.xm Hooks/SDK/JSPatch.xm Hooks/SDK/OpenSSLAES.xm Hooks/SDK/OpenSSLBlowFish.xm Hooks/SDK/OpenSSLMD5.xm Hooks/SDK/OpenSSLSHA1.xm Hooks/SDK/OpenSSLSHA512.xm Hooks/SDK/Reveal.xm Hooks/SDK/Wax.xm Hooks/Utils/CallStackInspector.m Hooks/Utils/CallTracer.m Hooks/Utils/DelegateProxies.m Hooks/Utils/NSURLConnectionDelegateProx.m Hooks/Utils/NSURLSessionDelegateProxy.m Hooks/Utils/PlistObjectConverter.m Hooks/Utils/RemoteLogSender.m Hooks/Utils/RuntimeUtils.m Hooks/Utils/SQLiteStorage.m Hooks/Utils/Utils.m Hooks/ThirdPartyTools/classdumpdyld.xm Hooks/ThirdPartyTools/dumpdecrypted.xm Hooks/ThirdPartyTools/InspectiveC.xm Hooks/Misc/Cycript.xm Hooks/Misc/fishhook.c Hooks/Misc/RemoveASLR.xm Hooks/Misc/SplitMachO.mm Hooks/Misc/WTSubstrate.mm
SIY616KCGLYUR1L_CCFLAGS = -Qunused-arguments -std=c++11
SIY616KCGLYUR1L_LDFLAGS = -Wl,-segalign,4000,-sectcreate,WTFJH,SIGDB,./SignatureDatabase.plist,-sectcreate,WTFJH,classdumpdyld,./classdumpdyld.dylib,-sectcreate,WTFJH,dumpdecrypted,./dumpdecrypted.dylib,-sectcreate,WTFJH,InspectiveC,./InspectiveC.dylib -lz -L. -v -force_load ./ExtraFWs/libcapstone.a -force_load ./ExtraFWs/libLiberation.a -force_load ./ExtraFWs/Reveal.framework/Reveal -force_load ./ExtraFWs/Cycript.framework/Cycript -F./ExtraFWs/ -Wno-unused-function
SIY616KCGLYUR1L_CFLAGS = -I/Volumes/PAGEZERO/WTFJH/Hooks/
SIY616KCGLYUR1L_LIBRARIES = sqlite3 substrate stdc++ c++
SIY616KCGLYUR1L_FRAMEWORKS = Foundation UIKit Security JavaScriptCore UIKit CoreGraphics CoreFoundation QuartzCore CFNetwork

include $(THEOS_MAKE_PATH)/tweak.mk
after-install::
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
410
415
16 changes: 11 additions & 5 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def Exec(Command):
HostName=subprocess.check_output("hostname -s", shell=True).replace("\n","")
global AllowedSourceExtension
AllowedSourceExtension=[".cpp",".xm",".xmi",".mm",".c",".m",".x",".xi"]

global theospathmid
theospathmid="//"
def isSource(FileName):
for End in AllowedSourceExtension:
if FileName.upper().endswith(End.upper()):
Expand Down Expand Up @@ -340,8 +341,10 @@ def ParseArgs():
SkippedList.append(z)
if x.upper().startswith("HostName="):
HostName=str(x[9:])
if(DEBUG==False):
if(DEBUG==True):
buildCommand="make "
global theospathmid
theospathmid="/debug/"
def Obfuscation():
if OBFUSCATION==False:
print "No Obfuscation"
Expand All @@ -364,6 +367,8 @@ def BuildLoader(ModuleName):
f.write(Template)
f.close()
def buildThirdPartyComponents():
global theospathmid
global buildCommand
Exec("find . -type f -name .DS_Store -delete && xattr -cr *")
for x in Thirdbuildlistdir("ThirdPartyTools"):
os.chdir(InitialCWD)#Make Sure CWD We've changed in buildThirdPartyComponents() is set back
Expand All @@ -384,15 +389,15 @@ def buildThirdPartyComponents():
SubDirectoryPath="./ThirdPartyTools/"+x
origCH=os.getcwd()
os.chdir(SubDirectoryPath)
os.system("unlink theos&&rm obj&&rm -rf .theos&&ln -s $THEOS theos&&mkdir .theos && mkdir .theos/obj&&ln -s .theos/obj obj&& make&&"+"mv ./obj/debug/"+x+".dylib ../../")
os.system("unlink theos&&rm obj&&rm -rf .theos&&ln -s $THEOS theos&&mkdir .theos && mkdir .theos/obj&&ln -s .theos/obj obj&&"+buildCommand+"&&"+"mv ./obj/"+theospathmid+x+".dylib ../../")
os.chdir(origCH)
else:
Error=None
try:
SubDirectoryPath="./ThirdPartyTools/"+x
origCH=os.getcwd()
os.chdir(SubDirectoryPath)
Error=subprocess.check_call(["unlink theos&&rm obj&&rm -rf .theos&&ln -s $THEOS theos&&mkdir .theos && mkdir .theos/obj&&ln -s .theos/obj obj&& make &&"+"mv ./obj/debug/"+x+".dylib ../../"], stdout=STDOUT, stderr=STDERR, shell=True)
Error=subprocess.check_call(["unlink theos&&rm obj&&rm -rf .theos&&ln -s $THEOS theos&&mkdir .theos && mkdir .theos/obj&&ln -s .theos/obj obj&& "+buildCommand+"&&"+"mv ./obj/"+theospathmid+x+".dylib ../../"], stdout=STDOUT, stderr=STDERR, shell=True)
#sys.exit(0)
os.chdir(origCH)
except Exception as inst:
Expand Down Expand Up @@ -461,7 +466,8 @@ def main():
if buildSuccess==True:
os.system("mkdir -p ./layout/DEBIAN; cp ./control ./layout/DEBIAN/control")
FixControlFile("./layout/DEBIAN/control")
os.system("mkdir -p ./layout/Library/MobileSubstrate/DynamicLibraries; cp ./obj/debug/" + randomTweakName + ".dylib" + " ./layout/Library/MobileSubstrate/DynamicLibraries/")
global theospathmid
os.system("mkdir -p ./layout/Library/MobileSubstrate/DynamicLibraries; cp ./obj" +theospathmid+randomTweakName + ".dylib" + " ./layout/Library/MobileSubstrate/DynamicLibraries/")
os.system("cp ./WTFJH.plist" + " ./layout/Library/MobileSubstrate/DynamicLibraries/" + randomTweakName + ".plist")
# Cleaning finder caches, thanks to http://stackoverflow.com/questions/2016844/bash-recursively-remove-files
os.system("find . -type f -name .DS_Store -delete && xattr -cr *")
Expand Down

0 comments on commit f6fad3a

Please sign in to comment.