Swizzling low-level TCP methods on IOS - ios

I am trying to find a way to get information on all the TCP traffic to and from my IOS application. The application is very simple and composed of a single UIWebView object.
I tried to use swizzling on NSURLRequest but didn't have much luck with that - my version of requestWithURL: is called when I call it NSURLRequest manually, but it doesn't seem to ever be called when going to a page in UIWebView, so I guess its using a different object under the covers.
So I thought of trying to hook into CFSocket functions, but those are not part of a class so I'm not sure how to swizzle them (or if its even possible).
Are there any ways to hook into C functions on IOS, or any other APIs I can try to swizzle to access TCP (or even HTTP) traffic?
I also tried using NSURLCache, which works for most of the main .html pages, but as many people have found out the .cs files and some others don't seem to go through the cache.
Thanks!

Just set up an external proxy like Fiddler or Charles to monitor http traffic. Or more complicated, Wireshark for any tcp traffic. This will be much easier than what you're trying and more powerful.

Related

Network traffic from a iOS SDK

Let's say I want to build a SDK that communicates with a server. I don't want any one (not even the app that implements the SDK) to intercept and look at my requests/responses.
If I'd use a common lib like AFNetworking it would be possible to look at all requests i.e by registering a NSURLProtocol.
I'm assuming that this would be harder to do if I would use i.e CFNetworking to perform my request/response handling? Or am I missing something? Would it be possible to intercept that traffic as well?
Using non NSURLConnection based classes, especially C low level classes (because NSIn/OutStream can be swizzled) like CFNetwork's CFStream, would make life harder for a potential curious developer. However, it will never stop a determined one. Your framework could, for example, be decompiled, although that's not a trivial task, which means many will quit even before starting, if the information is not worthwhile.

HLS on iOS with custom buffer policy

I'm looking to use an existing video player library for iOS apps with HLS support so that I can implement a player with some very specific networking behavior, as opposed to letting Apple decide the size and timing of requests. It needs to be customizable enough to support new networking policies such that I can override the request sizes, change what files are requested, and read data from an existing local cache file. In short, I'm attempting to override the networking portion that actually calls out and fetches the segments such that I can feed in data from partial cache as well as make specific algorithmic changes to the timing and size of external HTTP requests.
I've tried AV Foundation's AVAssetResourceLoaderDelegate Protocol but, unless there is something I'm not seeing, there doesn't seem to be a way to override the outgoing requests and just feed bytes to the media player.
I've also looking into VLC but unfortunately my current project is incompatible with a GPL license.
Ideally, there would be a way to directly feed bytes or complete segments to MPMoviePlayerController, but I can't find any way of accomplishing this in the API. The only method I'm aware that works is using a local HTTP server, which I have been doing but it seems overly complicated when all I'm really trying to do is override some internal networking code.
Any suggestions of another way of doing this?

NSURLProtocol vs NSURLCache for JavaScript to Native iOS bridge

Subclassing NSURLProtocol and NSURLCache appear to be two established approaches to allowing JavaScript communication from a UIWebView to native iOS code.
Both allow you to intercept NSURLRequests made by a UIWebView and return arbitrary response data.
Both techniques have performance sufficient for my requirements.
So, performance time aside, is there any reason why I should prefer one approach over the other?
For reference an example using NSURLProtocol and an example using NSURLCache:
iOS WebView remote html with local image files
http://www.handcraftedsoftware.net/articles/how-to-pass-messages-between-native-ios-and-a-uiwebview-via-ajax-without-phonegap

Delphi internet hook

I want write a program in Delphi to watch the internet connection, and if a certain response received (in response to request from a program), send request again encoded to another server, get a new encoded response, decode it, and pass it as response to the program who sent the main request. But I don't now how to hook internet connection. I want to use this program to pass through filter my country governments made using a private program to avoid blocking it. Is there any idea?
Thanks for your answer.
Magenta Systems released a free set of Delphi components that let you see the network traffic on your computer and examine the content. If you see the response you are looking for, your monitoring program can send a request to another server.
Off the top of my head, I'm not sure if it will let you alter the content of the original packet. If not, then Marcus' suggestion of using a proxy might suit you better.
You can either try to hook stuff at the Winsock level (there's plenty of examples for that around), but I suggest you go one level deeper and use a Layered Service provider (LSP).
I have used Komodia's redirector from http://www.komodia.com. Commercial, but well worth it.
See also this post
Is it possible to intercept dns queries using LSP/SPI?

IOS And AsyncUDPSocket - Tutorial?

I am learning C and Objective-C so am still dependent on examples...
I found AsyncUDPSocket which has a lot of example code in the Google Code repository, but I'm not far enough along to understand it all yet.
I'm trying to build an iPhone app that uses UDP for communication to another device (Arduino). I have the device end working (testing with the UDP Tool app). I just need help with the iOS side of it...
An example with more explanation would really help (that is, a tutorial)... Is there one or what would some example code with good comments be?
https://github.com/robbiehanson/CocoaAsyncSocket
GCDAsyncUdpSocket and AsyncUdpSocket are UDP/IP socket networking libraries. Here are the key features available in both:
Native objective-c, fully self-contained in one class. No need to
muck around with low-level sockets. This class handles everything for
you.
Full delegate support.
Errors, send completions, receive completions, and disconnections all result in a call to your delegate method.
Queued non-blocking send and receive operations, with optional
timeouts.
You tell it what to send or receive, and it handles everything for you. Queueing, buffering, waiting and checking errno - all
handled for you automatically.
Support for IPv4 and IPv6.
Automatically send/recv using IPv4 and/or IPv6. No more worrying about multiple sockets.

Resources