Guest User

Untitled

a guest
Jun 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. //
  2. // MHProxyFactory.m
  3. // MineHelmet
  4. //
  5. // Created by Dylan Lukes on 10/22/10.
  6. // Copyright 2010 Dylan Lukes. All rights reserved.
  7. //
  8.  
  9. #import "MHProxyManager.h"
  10. #import "APELite.h"
  11.  
  12. #include <netinet/in.h>
  13. #include <arpa/inet.h>
  14. #include <netdb.h>
  15.  
  16. @interface MHProxyManager (PrivateMethods)
  17.  
  18. - (int)handleConnectAttempt:(int)socket addr:(const struct sockaddr *)addr addrlen:(socklen_t)addrlen;
  19. - (void)proxyCreateThread:(NSValue *)saObj;
  20. - (void)startWorkerThreadRunLoop;
  21.  
  22. @end
  23.  
  24. static MHProxyManager *instance_pointer;
  25. static int connect_override(int socket, const struct sockaddr *address, socklen_t addrlen){
  26. return [instance_pointer handleConnectAttempt:socket addr:address addrlen:addrlen];
  27. }
  28.  
  29. @implementation MHProxyManager
  30.  
  31. + (id)sharedInstance {
  32. static dispatch_once_t pred;
  33. static MHProxyManager *instance = nil;
  34.  
  35. dispatch_once(&pred, ^{ instance = [[self alloc] init]; });
  36. return instance;
  37. }
  38.  
  39. - (id)init {
  40. if (self = [super init]) {
  41. connectReentry = APEPatchCreate(connect, connect_override);
  42. instance_pointer = self;
  43. // Instantiate a thread object
  44. proxyThread = [[NSThread alloc] init];
  45. }
  46. return self;
  47. }
  48.  
  49. - (int)handleConnectAttempt:(int)socket addr:(const struct sockaddr *)addr addrlen:(socklen_t)addrlen {
  50. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  51. if (addr->sa_family == AF_INET6) {
  52. struct sockaddr_in6 *sa = (struct sockaddr_in6 *)addr;
  53. in_port_t port = ntohs(sa->sin6_port);
  54. if(!(port > 50000 || port == 80)) {
  55. /* HIDDEN CODE :O */
  56. }
  57. }
  58. [pool drain];
  59. return connectReentry(socket, addr, addrlen);
  60. }
  61.  
  62. - (void)proxyCreateThread:(NSValue *)saObj {
  63. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  64. proxy = [[MHProxy alloc] initWithDestAddress:NULL];
  65. [pool drain];
  66. }
  67.  
  68. - (void)startWorkerThreadRunLoop {
  69. [[NSRunLoop currentRunLoop] run];
  70. }
  71.  
  72. @end
Add Comment
Please, Sign In to add comment