]> Dogcows Code - chaz/thecheat/blobdiff - AppController.m
The Cheat 1.0b3
[chaz/thecheat] / AppController.m
index d5de59e1cb629da7427245be8dfa1e982f0870d9..c8750c03b8ceec35d47e654dc9f716b8d61ef1f1 100644 (file)
 
 #import "AppController.h"
 
-#include <mach/vm_map.h>
-#include <mach/mach_traps.h>
+#include "cheat_shared.h"
 
+#import "AboutBoxController.h"
+#import "PreferenceController.h"
+#import "NetTrafficController.h"
 
-// defines
-#define PID_SELECTED   [[[processList objectAtIndex:[processPopup indexOfSelectedItem]] objectForKey:@"NSApplicationProcessIdentifier"] intValue]
-#define TYPE_SELECTED  [typePopup indexOfSelectedItem]
-#define SIZE_SELECTED  [sizePopup indexOfSelectedItem]
+#import "CheatListener.h"
+#import "CheatServer.h"
+
+#import "ServerHolder.h"
 
 
 @implementation AppController
 
++ (void)initialize
+{
+       NSMutableDictionary             *defaults = [NSMutableDictionary dictionary];
+       char                                    temp[104];
+       
+       // change the socket path to reside in the home directory of the current user
+       strncpy( temp, [NSHomeDirectory() lossyCString], 103 );
+       strncat( temp, TCDefaultListenPath, 103 - strlen(TCDefaultListenPath) );
+       strncpy( TCDefaultListenPath, temp, 103 );
+
+       [defaults setObject:[NSNumber numberWithBool:TCGlobalPlaySounds] forKey:TCPlaySoundsPref];
+       [defaults setObject:[NSNumber numberWithBool:TCGlobalWindowsOnTop] forKey:TCWindowsOnTopPref];
+       [defaults setObject:[NSNumber numberWithBool:TCGlobalAllowRemote] forKey:TCAllowRemotePref];
+       [defaults setObject:[NSNumber numberWithInt:TCGlobalListenPort] forKey:TCListenPortPref];
+       [defaults setObject:[NSString stringWithFormat:@"%@'s Computer", NSFullUserName()] forKey:TCBroadcastNamePref];
+
+       [[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
+
+       TCGlobalPlaySounds = [[NSUserDefaults standardUserDefaults] integerForKey:TCPlaySoundsPref];
+       TCGlobalWindowsOnTop = [[NSUserDefaults standardUserDefaults] integerForKey:TCWindowsOnTopPref];
+       TCGlobalListenPort = [[NSUserDefaults standardUserDefaults] integerForKey:TCListenPortPref];
+       TCGlobalAllowRemote = [[NSUserDefaults standardUserDefaults] boolForKey:TCAllowRemotePref];
+}
+
 - (id)init
 {
        if ( self = [super init] )
        {
+               servers = [[NSMutableArray alloc] init];
                
+               [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willQuit:) name:@"NSApplicationWillTerminateNotification" object:nil];
+
+               [self listenOnPort:TCGlobalListenPort remote:TCGlobalAllowRemote];
+               [self broadcastWithName:TCGlobalBroadcastName];
        }
 
        return self;
 }
 
-- (void)awakeFromNib
-{
-       NSNotificationCenter    *nc = [[NSWorkspace sharedWorkspace] notificationCenter];
 
-       [self rebuildProcessList];
-       [self updateProcessPopup];
-       [self updateTypePopup];
-       [self updateSizePopup];
-       [self updateChangeButton];
-       [self updateStatusText];
+- (void)listenOnPort:(int)port remote:(BOOL)remote
+{
+       if ( connection )
+       {
+               [self stopListener];
 
-       [nc addObserver:self selector:@selector(processListChanged:) name:@"NSWorkspaceDidLaunchApplicationNotification" object:nil];
-       [nc addObserver:self selector:@selector(processListChanged:) name:@"NSWorkspaceDidTerminateApplicationNotification" object:nil];
-       
-       [self reset];
+               waitingToListen = YES;
+               connectionPort = port;
+               connectionRemote = remote;
+       }
+       else
+       {
+               connection = [[CheatListener listenerWithDelegate:self port:port remote:remote] retain];
+               connectionPort = port;
+               connectionRemote = remote;
+       }
 }
 
-
-- (void)reset
+- (void)stopListener
 {
-       if ( cheating )
+       if ( connection )
        {
-               cheating = NO;
-
-               [addressList release], addressList = nil;
-
-               // update the interface
-               [typePopup setEnabled:YES];
-               [sizePopup setEnabled:YES];
-               [searchTextField setStringValue:@""];
-               [changeTextField setStringValue:@""];
-               [addressTable reloadData];
+               close( sockfd );
+               [connection release], connection = nil;
        }
 }
 
 
-- (void)firstSearch:(id)nothing
+- (void)broadcastWithName:(NSString *)name
 {
-       NSAutoreleasePool                       *pool = [[NSAutoreleasePool alloc] init];
-       
-       pid_t                                           pid = (pid_t)PID_SELECTED;
-       vm_map_t                                        task;
-
-       kern_return_t                           result;
-
-       vm_address_t                            address = 0x0;
-       vm_size_t                                       size = 0;
-       vm_region_basic_info_data_t     info;
-       mach_msg_type_number_t          infoCnt = 8;
-       mach_port_t                                     object_name = 0;
-
-       char unsigned                           *data;
-       vm_size_t                                       dataCnt;
+       if ( TCGlobalAllowRemote )
+       {
+               [self stopBroadcast];
+               
+               service = [[NSNetService alloc] initWithDomain:@"local." type:@"_cheat._tcp." name:name port:TCGlobalListenPort];
+               [service setDelegate:self];
+               [service publish];
+       }
+}
 
-       char unsigned                           *string8bit = (char unsigned *)[[searchTextField stringValue] lossyCString];
-       long unsigned                           stringSize = strlen( string8bit );
-       char                                            integer8bit = (char)[searchTextField intValue];
-       short                                           integer16bit = (short)[searchTextField intValue];
-       long                                            integer32bit = (long)[searchTextField intValue];
-       long long                                       integer64bit = (long long)[searchTextField intValue];
-       float                                           float32bit = (float)[searchTextField floatValue];
-       double                                          float64bit = (double)[searchTextField doubleValue];
+- (void)stopBroadcast
+{
+       oldService = service;
+       [oldService stop], service = nil;
+}
 
-       BOOL                                            done = NO;
 
-       if ( (result = task_for_pid( current_task(), pid, &task)) != KERN_SUCCESS )
+- (IBAction)showAboutBoxWindow:(id)sender
+{
+       if ( !aboutBoxController )
        {
-               NSLog( @"task_for_pid returned error: %i", result );
-               return;
+               aboutBoxController = [[AboutBoxController alloc] init];
        }
+       
+       [aboutBoxController showWindow:self];
+}
 
-       addressList = [[NSMutableArray alloc] init];
-
-       while ( !done )
+- (IBAction)showPreferenceWindow:(id)sender
+{
+       if ( !preferenceController )
        {
-               if ( (result = vm_region( task, &address, &size, VM_REGION_BASIC_INFO, (vm_region_info_t)(&info), &infoCnt, &object_name )) != KERN_SUCCESS )
-               {
-                       if ( result != KERN_INVALID_ADDRESS )
-                       {
-                               NSLog( @"vm_region returned error: %i", result );
-                       }
+               preferenceController = [[PreferenceController alloc] initWithDelegate:self];
+       }
 
-                       done = YES;
-               }
+       [preferenceController showWindow:self];
+}
 
-               //NSLog( @"address: %X, size: %i", address, size );
+- (IBAction)showNetTrafficWindow:(id)sender
+{
+       if ( !netTrafficController )
+       {
+               netTrafficController = [[NetTrafficController alloc] initWithDelegate:self];
+       }
 
-               if ( (info.protection & VM_PROT_READ) && ((info.protection & VM_PROT_WRITE) >> 1) )
-               {
-                       data = (char unsigned *)malloc( size );
-                       dataCnt = size;
-
-                       if ( (result = vm_read_overwrite( task, address, size, (vm_address_t)data, &dataCnt )) != KERN_SUCCESS && result != KERN_PROTECTION_FAILURE )
-                       {
-                               NSLog( @"vm_read_overwrite returned error: %i", result );
-                               free( data );
-                               done = YES;
-                       }
-
-                       if ( result == KERN_SUCCESS )
-                       {
-                               long unsigned   i, max = (long unsigned)dataCnt;
-
-                               //NSLog( @"data: %X, size: %i", (vm_address_t)data, dataCnt );
-
-                               switch ( TYPE_SELECTED )
-                               {
-                                       case TYPE_STRING:
-                                               switch ( SIZE_SELECTED )
-                                               {
-                                                       case SIZE_8_BIT:
-                                                       {
-                                                               long unsigned   maxString = max - stringSize;
-
-                                                               for ( i = 0; i < maxString; i += sizeof(char unsigned) )
-                                                               {
-                                                                       if ( strncmp( string8bit, data+i, stringSize ) == 0 )
-                                                                       {
-                                                                               [addressList addObject:[NSNumber numberWithUnsignedLong:(long unsigned)address + i]];
-                                                                       }
-                                                               }
-                                                       }
-                                                               break;
-                                               }
-                                               break;
-
-                                       case TYPE_INTEGER:
-                                               switch ( SIZE_SELECTED )
-                                               {
-                                                       case SIZE_8_BIT:
-                                                       {
-                                                               for ( i = 0; i < max; i += sizeof(char) )
-                                                               {
-                                                                       if ( integer8bit == *((char *)(data+i)) )
-                                                                       {
-                                                                               [addressList addObject:[NSNumber numberWithUnsignedLong:(long unsigned)address + i]];
-                                                                       }
-                                                               }
-                                                       }
-                                                               break;
-
-                                                       case SIZE_16_BIT:
-                                                       {
-                                                               for ( i = 0; i < max; i += sizeof(short) )
-                                                               {
-                                                                       if ( integer16bit == *((short *)(data+i)) )
-                                                                       {
-                                                                               [addressList addObject:[NSNumber numberWithUnsignedLong:(long unsigned)address + i]];
-                                                                       }
-                                                               }
-                                                       }
-                                                               break;
-
-                                                       case SIZE_32_BIT:
-                                                       {
-                                                               for ( i = 0; i < max; i += sizeof(long) )
-                                                               {
-                                                                       if ( integer32bit == *((long *)(data+i)) )
-                                                                       {
-                                                                               [addressList addObject:[NSNumber numberWithUnsignedLong:(long unsigned)address + i]];
-                                                                       }
-                                                               }
-                                                       }
-                                                               break;
-
-                                                       case SIZE_64_BIT:
-                                                       {
-                                                               for ( i = 0; i < max; i += sizeof(long long) )
-                                                               {
-                                                                       if ( integer64bit == *((long long *)(data+i)) )
-                                                                       {
-                                                                               [addressList addObject:[NSNumber numberWithUnsignedLong:(long unsigned)address + i]];
-                                                                       }
-                                                               }
-                                                       }
-                                                               break;
-                                               }
-                                               break;
-
-                                       case TYPE_FLOAT:
-                                               switch ( SIZE_SELECTED+2 )
-                                               {
-                                                       case SIZE_32_BIT:
-                                                       {
-                                                               for ( i = 0; i < max; i += sizeof(float) )
-                                                               {
-                                                                       if ( float32bit == *((float *)(data+i)) )
-                                                                       {
-                                                                               [addressList addObject:[NSNumber numberWithUnsignedLong:(long unsigned)address + i]];
-                                                                       }
-                                                               }
-                                                       }
-                                                               break;
-
-                                                       case SIZE_64_BIT:
-                                                       {
-                                                               for ( i = 0; i < max; i += sizeof(double) )
-                                                               {
-                                                                       if ( float64bit == *((double *)(data+i)) )
-                                                                       {
-                                                                               [addressList addObject:[NSNumber numberWithUnsignedLong:(long unsigned)address + i]];
-                                                                       }
-                                                               }
-                                                       }
-                                                               break;
-                                               }
-                                               break;
-                               }
-                       }
-
-                       free( data );
-               }
+       [netTrafficController showWindow:self];
+}
 
-               address += size;
-       }
 
-       searching = NO;
+- (IBAction)launchHelpFile:(id)sender
+{
+       //[[NSWorkspace sharedWorkspace] openFile:[[NSBundle mainBundle] pathForResource:@"Read Me" ofType:@"html"] withApplication:@"Safari"];
+       [[NSWorkspace sharedWorkspace] openURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Read Me" ofType:@"pdf"]]];
+}
 
-       // update the interface
-       [statusBar stopAnimation:self];
-       [self updateProcessPopup];
-       [self updateSearchButton];
-       [self updateTypePopup];
-       [self updateSizePopup];
-       [self updateChangeButton];
-       [self updateStatusText];
-       [addressTable reloadData];
+- (IBAction)launchWebsiteMenu:(id)sender
+{
+       LaunchWebsite();
+}
 
-       [pool release];
+- (IBAction)launchDebugEmailMenu:(id)sender
+{
+       [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"mailto:thecheat@brokenzipper.com"]];
 }
 
-- (void)search:(id)nothing
+
+- (void)dealloc
 {
-       NSAutoreleasePool                       *pool = [[NSAutoreleasePool alloc] init];
-       
-       pid_t                                           pid = (pid_t)PID_SELECTED;
-       vm_map_t                                        task;
+       [[NSNotificationCenter defaultCenter] removeObserver:self];
 
-       kern_return_t                           result;
+       [self stopListener];
+       [self stopBroadcast];
 
-       vm_address_t                            address = 0x0;
-       vm_size_t                                       size = 0;
-       vm_region_basic_info_data_t     info;
-       mach_msg_type_number_t          infoCnt = 8;
-       mach_port_t                                     object_name = 0;
+       [servers release];
 
-       char unsigned                           *data;
-       vm_size_t                                       dataCnt;
+       [super dealloc];
+}
 
-       char unsigned                           *string8bit = (char unsigned *)[[searchTextField stringValue] lossyCString];
-       long unsigned                           stringSize = strlen( string8bit );
-       char                                            integer8bit = (char)[searchTextField intValue];
-       short                                           integer16bit = (short)[searchTextField intValue];
-       long                                            integer32bit = (long)[searchTextField intValue];
-       long long                                       integer64bit = (long long)[searchTextField intValue];
-       float                                           float32bit = (float)[searchTextField floatValue];
-       double                                          float64bit = (double)[searchTextField doubleValue];
 
-       long unsigned                           j, max = [addressList count];
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%   PreferenceControlling
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-       NSMutableArray                          *newList = [[NSMutableArray alloc] init];
 
-       if ( (result = task_for_pid( current_task(), pid, &task)) != KERN_SUCCESS )
+- (void)preferenceAllowRemoteChanged:(BOOL)allow
+{
+       [self listenOnPort:TCGlobalListenPort remote:allow];
+       
+       if ( allow )
        {
-               NSLog( @"task_for_pid returned error: %i", result );
-               return;
+               [self broadcastWithName:TCGlobalBroadcastName];
        }
-
-       for ( j = 0; j < max; j++ )
+       else
        {
-               long unsigned           item = [[addressList objectAtIndex:j] unsignedLongValue];
+               [self stopBroadcast];
+       }
 
-               address = (vm_address_t)item;
+       [netTrafficController allowRemoteChanged:allow];
+}
 
-               if ( (result = vm_region( task, &address, &size, VM_REGION_BASIC_INFO, (vm_region_info_t)(&info), &infoCnt, &object_name )) != KERN_SUCCESS )
-               {
-                       if ( result != KERN_INVALID_ADDRESS )
-                       {
-                               NSLog( @"vm_region returned error: %i", result );
-                       }
+- (void)preferenceListenPortChanged:(int)port
+{
+       [self listenOnPort:port remote:TCGlobalAllowRemote];
+       [self broadcastWithName:TCGlobalBroadcastName];
 
-                       break;
-               }
+       [netTrafficController listenPortChanged:port];
+}
 
-               //NSLog( @"address: %X, size: %i", address, size );
+- (void)preferenceBroadcastNameChanged:(NSString *)name
+{
+       [self broadcastWithName:name];
 
-               if ( (info.protection & VM_PROT_READ) && ((info.protection & VM_PROT_WRITE) >> 1) )
-               {
-                       data = (char unsigned *)malloc( size );
-                       dataCnt = size;
-
-                       if ( (result = vm_read_overwrite( task, address, size, (vm_address_t)data, &dataCnt )) != KERN_SUCCESS && result != KERN_PROTECTION_FAILURE )
-                       {
-                               NSLog( @"vm_read_overwrite returned error: %i", result );
-                               free( data );
-                               break;
-                       }
-
-                       if ( result == KERN_SUCCESS )
-                       {
-                               long unsigned   i = item - (long unsigned)address;
-
-                               if ( i < (long unsigned)dataCnt )
-                               {
-                                       //NSLog( @"data: %X, size: %i", (vm_address_t)data, dataCnt );
-
-                                       switch ( TYPE_SELECTED )
-                                       {
-                                               case TYPE_STRING:
-                                                       switch ( SIZE_SELECTED )
-                                                       {
-                                                               case SIZE_8_BIT:
-                                                               {
-                                                                       if ( strncmp( string8bit, data+i, stringSize ) == 0 )
-                                                                       {
-                                                                               [newList addObject:[NSNumber numberWithUnsignedLong:(long unsigned)address + i]];
-                                                                       }
-                                                               }
-                                                                       break;
-                                                       }
-                                                       break;
-
-                                               case TYPE_INTEGER:
-                                                       switch ( SIZE_SELECTED )
-                                                       {
-                                                               case SIZE_8_BIT:
-                                                               {
-                                                                       if ( integer8bit == *((char *)(data+i)) )
-                                                                       {
-                                                                               [newList addObject:[NSNumber numberWithUnsignedLong:(long unsigned)address + i]];
-                                                                       }
-                                                               }
-                                                                       break;
-
-                                                               case SIZE_16_BIT:
-                                                               {
-                                                                       if ( integer16bit == *((short *)(data+i)) )
-                                                                       {
-                                                                               [newList addObject:[NSNumber numberWithUnsignedLong:(long unsigned)address + i]];
-                                                                       }
-                                                               }
-                                                                       break;
-
-                                                               case SIZE_32_BIT:
-                                                               {
-                                                                       if ( integer32bit == *((long *)(data+i)) )
-                                                                       {
-                                                                               [newList addObject:[NSNumber numberWithUnsignedLong:(long unsigned)address + i]];
-                                                                       }
-                                                               }
-                                                                       break;
-
-                                                               case SIZE_64_BIT:
-                                                               {
-                                                                       if ( integer64bit == *((long long *)(data+i)) )
-                                                                       {
-                                                                               [newList addObject:[NSNumber numberWithUnsignedLong:(long unsigned)address + i]];
-                                                                       }
-                                                               }
-                                                                       break;
-                                                       }
-                                                       break;
-
-                                               case TYPE_FLOAT:
-                                                       switch ( SIZE_SELECTED+2 )
-                                                       {
-                                                               case SIZE_32_BIT:
-                                                               {
-                                                                       if ( float32bit == *((float *)(data+i)) )
-                                                                       {
-                                                                               [newList addObject:[NSNumber numberWithUnsignedLong:(long unsigned)address + i]];
-                                                                       }
-                                                               }
-                                                                       break;
-
-                                                               case SIZE_64_BIT:
-                                                               {
-                                                                       if ( float64bit == *((double *)(data+i)) )
-                                                                       {
-                                                                               [newList addObject:[NSNumber numberWithUnsignedLong:(long unsigned)address + i]];
-                                                                       }
-                                                               }
-                                                                       break;
-                                                       }
-                                                       break;
-                                       }
-                               }
-                       }
-
-                       free( data );
-               }
-       }
+       [netTrafficController broadcastNameChanged:name];
+}
 
-       [addressList release];
-       addressList = newList;
 
-       searching = NO;
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%   NetTrafficControlling
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-       // update the interface
-       [statusBar stopAnimation:self];
-       [self updateProcessPopup];
-       [self updateSearchButton];
-       [self updateTypePopup];
-       [self updateSizePopup];
-       [self updateChangeButton];
-       [self updateStatusText];
-       [addressTable reloadData];
 
-       [pool release];
+- (int)netTrafficConnectionCount
+{
+       return [servers count];
 }
 
-
-- (void)change
+- (NSArray *)netTrafficConnectionList
 {
-       pid_t                                           pid = (pid_t)PID_SELECTED;
-       vm_map_t                                        task;
+       return servers;
+}
 
-       kern_return_t                           result;
+- (void)netTrafficKillConnection:(int)index
+{
+       NSLog( @"kill connection" );
 
-       char unsigned                           *string8bit = (char unsigned *)[[changeTextField stringValue] lossyCString];
-       long unsigned                           stringSize = strlen( string8bit );
-       char                                            integer8bit = (char)[changeTextField intValue];
-       short                                           integer16bit = (short)[changeTextField intValue];
-       long                                            integer32bit = (long)[changeTextField intValue];
-       long long                                       integer64bit = (long long)[changeTextField intValue];
-       float                                           float32bit = (float)[changeTextField floatValue];
-       double                                          float64bit = (double)[changeTextField doubleValue];
+       close( [[servers objectAtIndex:index] sockfd] );
+}
 
-       NSEnumerator                            *enumerator = [addressTable selectedRowEnumerator];
-       NSNumber                                        *row;
 
-       if ( (result = task_for_pid( current_task(), pid, &task)) != KERN_SUCCESS )
-       {
-               NSLog( @"task_for_pid returned error: %i", result );
-               return;
-       }
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%   ListenerDelegate
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-       while ( row = [enumerator nextObject] )
-       {
-               long unsigned           item = [[addressList objectAtIndex:[row intValue]] unsignedLongValue];
 
-               //NSLog( @"address: %X", item );
+- (void)listenerListeningWithSocket:(int)sock
+{
+       sockfd = sock;
 
-               switch ( TYPE_SELECTED )
-               {
-                       case TYPE_STRING:
-                               switch ( SIZE_SELECTED )
-                               {
-                                       case SIZE_8_BIT:
-                                       {
-                                               result = vm_write( task, (vm_address_t)item, (vm_offset_t)string8bit, (mach_msg_type_number_t)stringSize );
-                                       }
-                                               break;
-                               }
-                               break;
-
-                       case TYPE_INTEGER:
-                               switch ( SIZE_SELECTED )
-                               {
-                                       case SIZE_8_BIT:
-                                       {
-                                               result = vm_write( task, (vm_address_t)item, (vm_offset_t)(&integer8bit), sizeof(char) );
-                                       }
-                                               break;
-
-                                       case SIZE_16_BIT:
-                                       {
-                                               result = vm_write( task, (vm_address_t)item, (vm_offset_t)(&integer16bit), sizeof(short) );
-                                       }
-                                               break;
-
-                                       case SIZE_32_BIT:
-                                       {
-                                               result = vm_write( task, (vm_address_t)item, (vm_offset_t)(&integer32bit), sizeof(long) );
-                                       }
-                                               break;
-
-                                       case SIZE_64_BIT:
-                                       {
-                                               result = vm_write( task, (vm_address_t)item, (vm_offset_t)(&integer64bit), sizeof(long long) );
-                                       }
-                                               break;
-                               }
-                               break;
-
-                       case TYPE_FLOAT:
-                               switch ( SIZE_SELECTED+2 )
-                               {
-                                       case SIZE_32_BIT:
-                                       {
-                                               result = vm_write( task, (vm_address_t)item, (vm_offset_t)(&float32bit), sizeof(float) );
-                                       }
-                                               break;
-
-                                       case SIZE_64_BIT:
-                                       {
-                                               result = vm_write( task, (vm_address_t)item, (vm_offset_t)(&float64bit), sizeof(double) );
-                                       }
-                                               break;
-                               }
-                               break;
-               }
-       }
+       TCGlobalListening = YES;
+       [[NSNotificationCenter defaultCenter] postNotificationName:@"TCListenerStarted" object:nil];
 }
 
-
-- (void)updateProcessPopup
+- (void)listenerDisconnected
 {
-       if ( searching )
+       if ( waitingToListen )
        {
-               [processPopup setEnabled:NO];
+               waitingToListen = NO;
+               connection = [[CheatListener listenerWithDelegate:self port:connectionPort remote:connectionRemote] retain];
        }
        else
        {
-               [processPopup setEnabled:YES];
+               [self stopListener];
        }
+
+       TCGlobalListening = NO;
+       [[NSNotificationCenter defaultCenter] postNotificationName:@"TCListenerStopped" object:nil];
 }
 
-- (void)updateTypePopup
+- (void)listenerError:(NSString *)error message:(NSString *)message
 {
-       if ( cheating || searching )
-       {
-               [typePopup setEnabled:NO];
-       }
-       else
-       {
-               int                     selected = [typePopup indexOfSelectedItem];
-               
-               [typePopup setEnabled:YES];
-               
-               [typePopup removeAllItems];
-
-               [typePopup addItemWithTitle:@"String"];
-               [typePopup addItemWithTitle:@"Integer"];
-               [typePopup addItemWithTitle:@"Float"];
+       NSRunCriticalAlertPanel( error, message, @"OK", nil, nil );
+}
 
-               [typePopup selectItemAtIndex:selected];
-       }
+- (void)listenerReceivedNewConnection:(int)sock
+{
+       [servers addObject:[ServerHolder holderWithConnection:[CheatServer serverWithDelegate:self socket:sock] socket:sock]];
 }
 
-- (void)updateSizePopup
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%   ServerDelegate
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+
+- (void)server:(CheatServer *)server connectedWithSocket:(int)sock
 {
-       if ( cheating || searching )
-       {
-               [sizePopup setEnabled:NO];
-       }
-       else
-       {
-               [sizePopup setEnabled:YES];
-               
-               [sizePopup removeAllItems];
+       int                             i, top = [servers count];
 
-               switch ( TYPE_SELECTED )
+       for ( i = 0; i < top; i++ )
+       {
+               if ( [(ServerHolder *)[servers objectAtIndex:i] sockfd] == sock )
                {
-                       case TYPE_STRING:
-                               [sizePopup addItemWithTitle:@"  8-bit"];
-                               break;
-
-                       case TYPE_INTEGER:
-                               [sizePopup addItemWithTitle:@"  8-bit"];
-                               [sizePopup addItemWithTitle:@"16-bit"];
-                               [sizePopup addItemWithTitle:@"32-bit"];
-                               [sizePopup addItemWithTitle:@"64-bit"];
-                               break;
-
-                       case TYPE_FLOAT:
-                               [sizePopup addItemWithTitle:@"32-bit"];
-                               [sizePopup addItemWithTitle:@"64-bit"];
-                               break;
+                       [(ServerHolder *)[servers objectAtIndex:i] setServer:server];
+                       break;
                }
        }
-}
 
-- (void)updateSearchButton
-{
-       if ( searching )
-       {
-               [searchTextField setEnabled:NO];
-               [searchButton setEnabled:NO];
-       }
-       else
-       {
-               [searchTextField setEnabled:YES];
-               [searchButton setEnabled:YES];
-       }
+       [netTrafficController connectionListChanged];
 }
 
-- (void)updateChangeButton
+- (void)serverDisconnected:(CheatServer *)server
 {
-       if ( [addressTable selectedRow] == -1 || searching )
-       {
-               [changeTextField setEnabled:NO];
-               [changeButton setEnabled:NO];
-       }
-       else
-       {
-               [changeTextField setEnabled:YES];
-               [changeButton setEnabled:YES];
-       }
-}
+       int                             i, top = [servers count];
 
-- (void)updateStatusText
-{
-       if ( searching )
+       for ( i = 0; i < top; i++ )
        {
-               [statusText setStringValue:@"Searching..."];
-       }
-       else if ( !cheating )
-       {
-               [statusText setStringValue:[NSString stringWithFormat:@"PID: %i", PID_SELECTED]];
-       }
-       else // cheating
-       {
-               [statusText setStringValue:[NSString stringWithFormat:@"Found: %i", [addressList count]]];
+               if ( [(ServerHolder *)[servers objectAtIndex:i] server] == server )
+               {
+                       [servers removeObjectAtIndex:i];
+                       break;
+               }
        }
 
-       [statusText display];
+       [netTrafficController connectionListChanged];
 }
 
-
-- (void)processListChanged:(NSNotification *)note
+- (void)server:(CheatServer *)server changedAddress:(NSString *)address
 {
-       if ( cheating && [[note name] isEqualToString:@"NSWorkspaceDidTerminateApplicationNotification"] )
+       int                             i, top = [servers count];
+
+       for ( i = 0; i < top; i++ )
        {
-               int                     pid = PID_SELECTED;
-               int                     other = [[[note userInfo] objectForKey:@"NSApplicationProcessIdentifier"] intValue];
-               
-               // check to make sure the program we were cheating wasn't the one that quit
-               if ( pid == other )
+               if ( [(ServerHolder *)[servers objectAtIndex:i] server] == server )
                {
-                       // it was, so let's take care of it
-                       NSBeginAlertSheet( @"", @"OK", nil, nil, window, nil, nil, nil, 0, @"The application that was being cheated has quit." );
-                       
-                       [self reset];
+                       [(ServerHolder *)[servers objectAtIndex:i] setAddress:address];
+                       break;
                }
        }
 
-       [self rebuildProcessList];
-       [self updateProcessPopup];
-       [self updateStatusText];
+       [netTrafficController connectionListChanged];
 }
 
-
-- (void)rebuildProcessList
+- (void)server:(CheatServer *)server changedAction:(NSString *)action
 {
-       NSString                *selected = [[processPopup titleOfSelectedItem] retain];
-       int                             i, max;
-
-       [processList release];
-       processList = [[[NSWorkspace sharedWorkspace] launchedApplications] retain];
+       int                             i, top = [servers count];
 
-       max = [processList count];
-
-       [processPopup setImagePosition:NSImageOverlaps];
-
-       [processPopup removeAllItems];
-
-       for ( i = 0; i < max; i++ )
+       for ( i = 0; i < top; i++ )
        {
-               NSString        *name = [[processList objectAtIndex:i] objectForKey:@"NSApplicationName"];
-               NSString        *path = [[processList objectAtIndex:i] objectForKey:@"NSApplicationPath"];
-
-               NSImage         *image = [[NSWorkspace sharedWorkspace] iconForFile:path];
-
-               [processPopup addItemWithTitle:name];
-
-               [image setScalesWhenResized:YES];
-               [image setSize:NSMakeSize( 16.0, 16.0 )];
-
-               [[processPopup itemAtIndex:i] setImage:image];
-
-               if ( [selected isEqualToString:[processPopup itemTitleAtIndex:i]] )
+               if ( [(ServerHolder *)[servers objectAtIndex:i] server] == server )
                {
-                       [processPopup selectItemAtIndex:i];
+                       [(ServerHolder *)[servers objectAtIndex:i] setAction:action];
+                       break;
                }
        }
 
-       [selected release];
+       [netTrafficController connectionListChanged];
 }
 
-
-- (void)dealloc
+- (NSArray *)serverProcessList
 {
-       [self reset];
-       
-       [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
+       return [[NSWorkspace sharedWorkspace] launchedApplications];
+}
 
-       [processList release];
-       
-       [super dealloc];
+- (pid_t)serverFirstProcess
+{
+       return (pid_t)[[[[[NSWorkspace sharedWorkspace] launchedApplications] objectAtIndex:0] objectForKey:@"NSApplicationProcessIdentifier"] intValue];
 }
 
 
-- (IBAction)processPopup:(id)sender
-{
-       [self reset];
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%   NetService Delegate
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-       [self updateStatusText];
-}
 
-- (IBAction)typePopup:(id)sender
+- (void)netServiceWillPublish:(NSNetService *)sender
 {
-       [self updateSizePopup];
+       NSLog( @"service will publish" );
+       [sender resolve];
 }
 
-- (IBAction)searchButton:(id)sender
+- (void)netService:(NSNetService *)sender didNotPublish:(NSDictionary *)errorDict
 {
-       if ( [[searchTextField stringValue] isEqualToString:@""] )
-       {
-               NSBeep();
-               return;
-       }
-
-       searching = YES;
-
-       // update the interface
-       [statusBar startAnimation:self];
-       [self updateProcessPopup];
-       [self updateSearchButton];
-       [self updateTypePopup];
-       [self updateSizePopup];
-       [self updateChangeButton];
-       [self updateStatusText];
-
-       if ( !cheating )
+       NSLog( @"service did not publish" );
+       
+       if ( [[errorDict objectForKey:@"NSNetServicesErrorCode"] intValue] == NSNetServicesCollisionError )
        {
-               cheating = YES;
-
-               [NSThread detachNewThreadSelector:@selector(firstSearch:) toTarget:self withObject:nil];
+               [self broadcastWithName:[NSString stringWithFormat:@"%@ %i", TCGlobalBroadcastName, TCGlobalAlternateBroadcastNameCount++]];
        }
        else
        {
-               [NSThread detachNewThreadSelector:@selector(search:) toTarget:self withObject:nil];
+               NSRunCriticalAlertPanel( @"Network Error", @"Server couldn't broadcast.  Local can't be cheated by remote computers.", @"OK", nil, nil );
        }
-/*
-       {
-               pid_t                   pid = (pid_t)PID_SELECTED;
-               vm_map_t                task;
-
-               kern_return_t   result;
-               //int                           waitStatus;
-
-               addressList = [[NSMutableArray alloc] init];
-
-               result = task_for_pid( current_task(), pid, &task );
-
-               if ( result == KERN_SUCCESS )
-                       NSLog( @"KERN_SUCCESS" );
-               else if ( result == KERN_INVALID_ADDRESS )
-                       NSLog( @"KERN_INVALID_ADDRESS" );
-               else if ( result == KERN_INVALID_ARGUMENT )
-                       NSLog( @"KERN_INVALID_ARGUMENT" );
-               else if ( result == KERN_PROTECTION_FAILURE )
-                       NSLog( @"KERN_PROTECTION_FAILURE" );
-               else if ( result == KERN_NO_SPACE )
-                       NSLog( @"KERN_NO_SPACE" );
-
-               if ( ptrace( PT_ATTACH, pid, 0, 0 ) != -1 )
-               {
-                       if ( waitpid( pid, &waitStatus, WUNTRACED ) == pid )
-                       {
-                               if ( WIFSTOPPED(waitStatus) )
-                               {
-                                       NSLog( @"process stopped" );
-                               }
-                               else
-                               {
-                                       NSLog( @"process didn't stop" );
-                               }
-
-                               {
-                                       vm_address_t                            address = 0x1b000;
-                                       vm_size_t                                       size = 0;
-                                       vm_region_basic_info_data_t     info;
-                                       mach_msg_type_number_t          infoCnt = 8;
-                                       mach_port_t                                     object_name = 0;
-
-                                       BOOL                                            canRead, canWrite, canExecute;
-
-                                       char unsigned                           *data;
-                                       vm_size_t                                       dataCnt;
-
-                                       NSLog( @"pid: %i, task: %i", pid, task );
-                                       
-                                       result = vm_region( task, &address, &size, VM_REGION_BASIC_INFO, (vm_region_info_t)(&info), &infoCnt, &object_name );
-
-                                       NSLog( @"info count: %i", (int)infoCnt );
-
-                                       if ( result == KERN_SUCCESS )
-                                               NSLog( @"KERN_SUCCESS" );
-                                       else if ( result == KERN_INVALID_ADDRESS )
-                                               NSLog( @"KERN_INVALID_ADDRESS" );
-                                       else if ( result == KERN_INVALID_ARGUMENT )
-                                               NSLog( @"KERN_INVALID_ARGUMENT" );
-                                       else if ( result == KERN_PROTECTION_FAILURE )
-                                               NSLog( @"KERN_PROTECTION_FAILURE" );
-                                       else if ( result == KERN_NO_SPACE )
-                                               NSLog( @"KERN_NO_SPACE" );
-
-                                       NSLog( @"address: %X, size: %i", address, size );
-
-                                       canRead = info.protection & VM_PROT_READ;
-                                       canWrite = (info.protection & VM_PROT_WRITE) >> 1;
-                                       canExecute = (info.protection & VM_PROT_EXECUTE) >> 2;
-
-                                       if ( canRead )
-                                               NSLog( @"can read" );
-                                       if ( canWrite )
-                                               NSLog( @"can write" );
-                                       if ( canExecute )
-                                               NSLog( @"can execute" );
-
-                                       data = (char unsigned *)malloc( size );
-                                       dataCnt = size;
-
-                                       result = vm_read_overwrite( task, address, size, (vm_address_t)data, &dataCnt );
-
-                                       if ( result == KERN_SUCCESS )
-                                               NSLog( @"KERN_SUCCESS" );
-                                       else if ( result == KERN_INVALID_ADDRESS )
-                                               NSLog( @"KERN_INVALID_ADDRESS" );
-                                       else if ( result == KERN_INVALID_ARGUMENT )
-                                               NSLog( @"KERN_INVALID_ARGUMENT" );
-                                       else if ( result == KERN_PROTECTION_FAILURE )
-                                               NSLog( @"KERN_PROTECTION_FAILURE" );
-                                       else if ( result == KERN_NO_SPACE )
-                                               NSLog( @"KERN_NO_SPACE" );
-
-                                       NSLog( @"data: %X, size: %i", (vm_address_t)data, dataCnt );
-
-                                       free( data );
-                               }
-                       }
-                       else
-                       {
-                               NSLog( @"waitpid() failed" );
-                       }
-
-                       ptrace( PT_DETACH, pid, 0, 0 );
-               }
-               else
-               {
-                       NSLog( @"ptrace() failed" );
-               }
-       }*/
 }
 
-- (IBAction)changeButton:(id)sender
+- (void)netServiceDidStop:(NSNetService *)sender
 {
-       [self change];
+       NSLog( @"service stopped" );
+       [oldService release], oldService = nil;
 }
 
 
-- (int)numberOfRowsInTableView:(NSTableView *)table
-{
-       if ( cheating && !searching )
-               return [addressList count];
-
-       return 0;
-}
-
-- (id)tableView:(NSTableView *)table objectValueForTableColumn:(NSTableColumn *)column row:(int)row
-{
-       return [NSString stringWithFormat:@"%X", [[addressList objectAtIndex:row] unsignedLongValue]];
-}
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%   NSApplication Notification
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-- (void)tableView:(NSTableView *) setObjectValue:(id)object forTableColumn:(NSTableColumn *)column row:(int)row
-{
-       return;
-}
 
-- (void)tableViewSelectionDidChange:(NSNotification *)note
+- (void)willQuit:(NSNotification *)note
 {
-       [self updateChangeButton];
+       //[self listenPortTextField:self];
+       //[self broadcastNameTextField:self];
 }
 
 
This page took 0.041573 seconds and 4 git commands to generate.