Skip to content

Commit

Permalink
- Some litle cleaning in tsocks.
Browse files Browse the repository at this point in the history
- Fix SLProcess parenting check method.
- Fix message.
  • Loading branch information
javerous committed Mar 4, 2016
1 parent 814a687 commit d8d42ee
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 116 deletions.
6 changes: 3 additions & 3 deletions TorProxifier/TorProxifier/TPProcess.m
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ - (BOOL)parentOfPID:(pid_t)pid

while (1)
{
pid_t ppid = [[self class] PPIDForPID:pid];
pid = [[self class] PPIDForPID:pid];

if (ppid < 0)
if (pid <= 0)
return NO;

if (ppid == rpid)
if (pid == rpid)
return YES;
}

Expand Down
6 changes: 3 additions & 3 deletions TorProxifier/TorProxifier/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
"process_launching" = "Process is launching (%lu%%).";
"process_launched" = "Process is tunneled through Tor.";

"process_err_tor_socket" = "Can't verify that sockets are well redirected to Tor network. Launch of the process is stopped.";
"process_err_tor_nsurlconnection" = "Can't verify that NSURLConnection are well redirected to Tor network. Launch of the process is stopped.";
"process_err_tor_nsurlsession" = "Can't verify that NSURLSession are well redirected to Tor network. Launch of the process is stopped.";
"process_err_tor_socket" = "Can't verify that sockets are well redirected to Tor network. Launch of the process is suspended.";
"process_err_tor_nsurlconnection" = "Can't verify that NSURLConnection are well redirected to Tor network. Launch of the process is suspended.";
"process_err_tor_nsurlsession" = "Can't verify that NSURLSession are well redirected to Tor network. Launch of the process is suspended.";

/* Drop */
"drop_app" = "Drop application here";
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ __strong dispatch_block_t __concat(_exitBlock_, __LINE__) __attribute__((cleanup
return nil;
}


// Resolve host.
struct addrinfo hints, *res, *res0 = NULL;
int s = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
E8A78E4B1C5AB92E00D3C999 /* tsocks.h in Headers */ = {isa = PBXBuildFile; fileRef = E8A78E421C5AB92E00D3C999 /* tsocks.h */; };
E8A78E4E1C5ABA6A00D3C999 /* parser.c in Sources */ = {isa = PBXBuildFile; fileRef = E8A78E4C1C5ABA6A00D3C999 /* parser.c */; };
E8A78E4F1C5ABA6A00D3C999 /* parser.h in Headers */ = {isa = PBXBuildFile; fileRef = E8A78E4D1C5ABA6A00D3C999 /* parser.h */; };
E8B39B1A1C89BC5E007B7280 /* libresolv.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = E8B39B191C89BC5E007B7280 /* libresolv.tbd */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -31,13 +32,15 @@
E8A78E421C5AB92E00D3C999 /* tsocks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tsocks.h; sourceTree = "<group>"; };
E8A78E4C1C5ABA6A00D3C999 /* parser.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = parser.c; sourceTree = "<group>"; };
E8A78E4D1C5ABA6A00D3C999 /* parser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = parser.h; sourceTree = "<group>"; };
E8B39B191C89BC5E007B7280 /* libresolv.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libresolv.tbd; path = usr/lib/libresolv.tbd; sourceTree = SDKROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
E8A78DF71C5AAE5B00D3C999 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
E8B39B1A1C89BC5E007B7280 /* libresolv.tbd in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -49,6 +52,7 @@
children = (
E851B7831C7BD26F0083D155 /* TPControlHelper.h */,
E8A78DFC1C5AAE5B00D3C999 /* tsocks */,
E8B39B1B1C89BC65007B7280 /* Libs */,
E8A78DFB1C5AAE5B00D3C999 /* Products */,
);
sourceTree = "<group>";
Expand Down Expand Up @@ -77,6 +81,14 @@
path = tsocks;
sourceTree = "<group>";
};
E8B39B1B1C89BC65007B7280 /* Libs */ = {
isa = PBXGroup;
children = (
E8B39B191C89BC5E007B7280 /* libresolv.tbd */,
);
name = Libs;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down
12 changes: 1 addition & 11 deletions TorProxifier/TorProxifier/libtsocks/tsocks/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,9 @@ location */
/* Use _GNU_SOURCE to define RTLD_NEXT, mostly for RH7 systems */
/* #undef USE_GNU_SOURCE */

/* dlopen() the old libc to get connect() instead of RTLD_NEXT,
hopefully shouldn't be needed */
/* #undef USE_OLD_DLSYM */

/* path to library containing connect(), needed if USE_OLD_DLSYM is enabled */
/* #undef LIBCONNECT */

/* path to libc, needed if USE_OLD_DLSYM is enabled */
/* #undef LIBC */

/* Configure the system resolver to use TCP queries on startup, this
allows socksified DNS */
/* #undef USE_SOCKS_DNS */
#define USE_SOCKS_DNS 1

/* Prototype and function header for connect function */
#define CONNECT_SIGNATURE int __fd, const struct sockaddr * __addr, socklen_t __len
Expand Down
142 changes: 44 additions & 98 deletions TorProxifier/TorProxifier/libtsocks/tsocks/tsocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,39 +58,18 @@ char *progname = "libtsocks"; /* Name used in err msgs */
#include "dead_pool.h"



// --JP/
#include "TPControlHelper.h"

static void __attribute((constructor)) tp_constructor()
{
fprintf(stderr, "****** tsocks loaded ******\n");
}
// --JP!

/* Global Declarations */
#ifdef USE_SOCKS_DNS
static int (*realresinit)(void);
#endif
#ifdef USE_TOR_DNS
static dead_pool *pool = NULL;
//static struct hostent *(*realgethostbyname)(GETHOSTBYNAME_SIGNATURE);
//int (*realgetaddrinfo)(GETADDRINFO_SIGNATURE);
//static struct hostent *(*realgetipnodebyname)(GETIPNODEBYNAME_SIGNATURE);
#endif
//int (*realconnect)(CONNECT_SIGNATURE);
//static int (*realselect)(SELECT_SIGNATURE);
//static int (*realpoll)(POLL_SIGNATURE);
//int (*realclose)(CLOSE_SIGNATURE);
//static int (*realgetpeername)(GETPEERNAME_SIGNATURE);

static struct parsedfile *config;
static struct connreq *requests = NULL;
static int suid = 0;
static char *conffile = NULL;
static char *confdata = NULL;

/* Exported Function Prototypes */
void _init(void);
int connect(CONNECT_SIGNATURE);
int select(SELECT_SIGNATURE);
int poll(POLL_SIGNATURE);
Expand All @@ -106,6 +85,7 @@ struct hostent *getipnodebyname(GETIPNODEBYNAME_SIGNATURE);
#endif

/* Private Function Prototypes */
static void _init(void);
static int get_config();
static int get_environment();
static int connect_server(struct connreq *conn);
Expand All @@ -132,11 +112,25 @@ static int deadpool_init();
static int send_socksv4a_request(struct connreq *conn, const char *onion_host);
#endif


// --JP/
struct hostent *p_gethostbyname(GETHOSTBYNAME_SIGNATURE);
int p_getaddrinfo(GETADDRINFO_SIGNATURE);
struct hostent *p_getipnodebyname(GETIPNODEBYNAME_SIGNATURE);
#include "TPControlHelper.h"

static void __attribute((constructor)) tp_constructor()
{
fprintf(stderr, "****** tsocks loaded ******\n");

_init();
}
// --JP!

#ifdef USE_SOCKS_DNS
int p_res_init(void);
#endif
#if defined(USE_TOR_DNS) && USE_TOR_DNS
struct hostent * p_gethostbyname(GETHOSTBYNAME_SIGNATURE);
int p_getaddrinfo(GETADDRINFO_SIGNATURE);
struct hostent * p_getipnodebyname(GETIPNODEBYNAME_SIGNATURE);
#endif

int p_connect(CONNECT_SIGNATURE);

Expand All @@ -145,71 +139,46 @@ int p_poll(POLL_SIGNATURE);
int p_close(CLOSE_SIGNATURE);
int p_getpeername(GETPEERNAME_SIGNATURE);


// From 'OS X Internal'
typedef struct interpose_s {
void *new_func;
void *origin_func;
} interpose_t;

__attribute__((used)) static const interpose_t interposers[] __attribute__((section("__DATA,__interpose"))) = {
{ (void *)p_gethostbyname, (void *)gethostbyname },
{ (void *)p_getaddrinfo, (void *)getaddrinfo },
{ (void *)p_getipnodebyname, (void *)getipnodebyname },

{ (void *)p_connect, (void *)connect },
{ (void *)p_select, (void *)select },
{ (void *)p_poll, (void *)poll },
{ (void *)p_close, (void *)close },
{ (void *)p_getpeername, (void *)getpeername },

#if defined(USE_SOCKS_DNS) && USE_SOCKS_DNS
{ (void *)p_res_init, (void *)res_init },
#endif

#if defined(USE_TOR_DNS) && USE_TOR_DNS
{ (void *)p_gethostbyname, (void *)gethostbyname },
{ (void *)p_getaddrinfo, (void *)getaddrinfo },
{ (void *)p_getipnodebyname, (void *)getipnodebyname },
#endif

{ (void *)p_connect, (void *)connect },
{ (void *)p_select, (void *)select },
{ (void *)p_poll, (void *)poll },
{ (void *)p_close, (void *)close },
{ (void *)p_getpeername, (void *)getpeername },
};
// --JP!


void _init(void) {
#ifdef USE_OLD_DLSYM
void *lib;
#endif
static void _init(void) {

/* We could do all our initialization here, but to be honest */
/* most programs that are run won't use our services, so */
/* we do our general initialization on first call */

/* Determine the logging level */
suid = (getuid() != geteuid());

#ifndef USE_OLD_DLSYM
//realconnect = dlsym(RTLD_NEXT, "connect");
//realselect = dlsym(RTLD_NEXT, "select");
//realpoll = dlsym(RTLD_NEXT, "poll");
//realclose = dlsym(RTLD_NEXT, "close");
//realgetpeername = dlsym(RTLD_NEXT, "getpeername");
#ifdef USE_SOCKS_DNS
realresinit = dlsym(RTLD_NEXT, "res_init");
#endif
#ifdef USE_TOR_DNS
//realgethostbyname = dlsym(RTLD_NEXT, "gethostbyname");
//realgetaddrinfo = dlsym(RTLD_NEXT, "getaddrinfo");
//realgetipnodebyname = dlsym(RTLD_NEXT, "getipnodebyname");
#endif
#else
lib = dlopen(LIBCONNECT, RTLD_LAZY);
realconnect = dlsym(lib, "connect");
realselect = dlsym(lib, "select");
realpoll = dlsym(lib, "poll");
realgetpeername = dlsym(lib, "getpeername");
#ifdef USE_SOCKS_DNS
realresinit = dlsym(lib, "res_init");
#endif
#ifdef USE_TOR_DNS
realgethostbyname = dlsym(lib, "gethostbyname");
realgetaddrinfo = dlsym(lib, "getaddrinfo");
realgetipnodebyname = dlsym(RTLD_NEXT, "getipnodebyname");
#endif
dlclose(lib);
lib = dlopen(LIBC, RTLD_LAZY);
realclose = dlsym(lib, "close");
dlclose(lib);
#endif

get_environment();
get_config();

#ifdef USE_TOR_DNS
/* Unfortunately, we can't do this lazily because otherwise our mmap'd
area won't be shared across fork()s. */
Expand Down Expand Up @@ -317,13 +286,6 @@ int p_connect(CONNECT_SIGNATURE) {
struct connreq *newconn;

get_environment();

/* If the real connect doesn't exist, we're stuffed */
//if (realconnect == NULL) {
// show_msg(MSGERR, "Unresolved symbol: connect\n");
// return(-1);
//}


char *ipstr;

Expand Down Expand Up @@ -812,11 +774,6 @@ int p_close(CLOSE_SIGNATURE) {
int rc;
struct connreq *conn;

//if (realclose == NULL) {
// show_msg(MSGERR, "Unresolved symbol: close\n");
// return(-1);
//}

show_msg(MSGDEBUG, "Call to close(%d)\n", fd);

rc = close(fd);
Expand Down Expand Up @@ -852,14 +809,8 @@ int p_getpeername(GETPEERNAME_SIGNATURE) {
struct connreq *conn;
int rc;

//if (realgetpeername == NULL) {
// show_msg(MSGERR, "Unresolved symbol: getpeername\n");
// return(-1);
//}

show_msg(MSGDEBUG, "Call to getpeername for fd %d\n", __fd);


rc = getpeername(__fd, __name, __namelen);
if (rc == -1)
return rc;
Expand Down Expand Up @@ -1424,16 +1375,11 @@ static int read_socksv4_req(struct connreq *conn) {
}

#ifdef USE_SOCKS_DNS
int res_init(void) {
int p_res_init(void) {
int rc;

if (realresinit == NULL) {
show_msg(MSGERR, "Unresolved symbol: res_init\n");
return(-1);
}

/* Call normal res_init */
rc = realresinit();
rc = res_init();

/* Force using TCP protocol for DNS queries */
_res.options |= RES_USEVC;
Expand Down

0 comments on commit d8d42ee

Please sign in to comment.