]> Dogcows Code - chaz/thecheat/blobdiff - CheatServer.m
The Cheat 1.1.2
[chaz/thecheat] / CheatServer.m
index ba4ca6e48b791350c1c3f88bb6e6c55306752231..04cbdd92fc877d5cef0c5ff2ff25a77036d1560e 100644 (file)
@@ -12,7 +12,8 @@
 
 #import "SearchResults.h"
 
-#include "chaz.h"
+// for comparing floats
+#import <Chaz/Misc.h>
 
 #include <string.h>
 #include <math.h>
@@ -20,6 +21,7 @@
 
 
 // Internal Functions
+int bmsearch( char *pat, int m, char *text, int n, void *base, void *loc[] );
 //BOOL inline compare_float( float a, float b );
 //BOOL inline compare_double( double a, double b );
 
@@ -91,7 +93,7 @@
 
        if ( getpeername( sockfd, &identifier, &addrLen ) == -1 )
        {
-               NSLog( @"ERROR: getpeername() failed" );
+               CMLog( @"ERROR: getpeername() failed" );
        }
 
        if ( identifier.sa_family == AF_INET )
 
                if ( getpeername( sockfd, (struct sockaddr *)(&addr), &addrLen ) == -1 )
                {
-                       NSLog( @"ERROR: getpeername() failed" );
+                       CMLog( @"ERROR: getpeername() failed" );
                }
 
                if ( (addressCString = inet_ntoa( addr.sin_addr )) == NULL )
                {
-                       NSLog( @"ERROR: inet_ntoa() failed" );
+                       CMLog( @"ERROR: inet_ntoa() failed" );
                }
 
                address = [NSString stringWithCString:addressCString];
 
                if ( getpeername( sockfd, (struct sockaddr *)(&addr), &addrLen ) == -1 )
                {
-                       NSLog( @"ERROR: getpeername() failed" );
+                       CMLog( @"ERROR: getpeername() failed" );
                }
 
-               NSLog( @"client connection: %s", addr.sun_path );
+               CMLog( @"client connection: %s", addr.sun_path );
                
                address = [NSString stringWithString:@"127.0.0.1"];
        }
 
        numfds = sockfd + 1;
 
-       NSLog( @"SERVER start" );
+       CMLog( @"SERVER start" );
 
        for (;;)
        {
 
                        if ( !VerifyChecksum( header.checksum ) )
                        {
-                               NSLog( @"checksum failed" );
+                               CMLog( @"checksum failed" );
                        }
 
                        if ( header.size != 0 )
                        {
                                if ( (data = (char *)malloc( header.size )) == NULL )
                                {
-                                       NSLog( @"failed to allocate buffer for reading a network packet" );
+                                       CMLog( @"failed to allocate buffer for reading a network packet" );
                                        break;
                                }
 
                                if ( (result = ReadBuffer( sockfd, data, header.size )) != header.size )
                                {
-                                       NSLog( @"failed to read the data of a network packet" );
+                                       CMLog( @"failed to read the data of a network packet" );
                                        free( data );
                                        break;
                                }
                        }
 
-                       NSLog( @"SERVER message %i/%i/%i", header.checksum, header.function, header.size );
+                       //CMLog( @"SERVER message %i/%i/%i", header.checksum, header.function, header.size );
 
                        switch ( header.function )
                        {
 
        close( sockfd );
 
-       NSLog( @"SERVER close" );
+       CMLog( @"SERVER close" );
 
        [rootProxy serverDisconnected:self];
 }
        TCaddress                                       *results = NULL;
        int                                                     resultsAmount = 0;
        
-       NSLog( @"string search: %s", value );
-       
        for (;;)
        {
                if ( (result = vm_region( processTask, &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 );
+                               CMLog( @"vm_region returned error: %i", result );
                        }
                        break;
                }
                        
                        if ( (result = vm_read_overwrite( processTask, address, size, (vm_address_t)data, &dataLength )) != KERN_SUCCESS && result != KERN_PROTECTION_FAILURE )
                        {
-                               NSLog( @"vm_read_overwrite returned error: %i", result );
+                               CMLog( @"vm_read_overwrite returned error: %i", result );
                                free( data );
                                break;
                        }
                        
                        if ( result == KERN_SUCCESS )
                        {
-                               int                             i, top = dataLength - vsize;
+                               //int                           i, top = dataLength - vsize;
                                
                                if ( (results = realloc( results, TCAddressSize*resultsAmount + dataLength )) == NULL )
                                {
-                                       NSLog( @"ERROR: could not expand buffer" );
+                                       CMLog( @"ERROR: could not expand buffer" );
                                        exit(0);
                                }
                                
-                               for ( i = 0; i < top; i++ )
+                               resultsAmount += bmsearch( (char *)value, vsize, (char *)data, dataLength, (void *)address, (void **)((char *)results+TCAddressSize*resultsAmount) );
+                               //resultsAmount += TBM( (char *)value, vsize, data, dataLength, (void **)((char *)results+TCAddressSize*resultsAmount) );
+                               //resultsAmount += SMITH( data, dataLength, (char *)value, vsize, (void **)((char *)results+TCAddressSize*resultsAmount) );
+                               
+                               /*for ( i = 0; i < top; i++ )
                                {
                                        if ( strncmp( value, data+i, vsize ) == 0 )
                                        {
                                                results[resultsAmount++] = (TCaddress)address + i;
                                        }
-                               }
+                               }*/
                        }
                        
                        free( data );
        realloc( results, TCAddressSize*resultsAmount );
        [searchResults addObject:[SearchResults resultsWithType:TYPE_INTEGER size:SIZE_8_BIT data:results amount:resultsAmount]];
        
-       NSLog( @"found %i of %i", resultsAmount, value );
+       CMLog( @"found %i of %i", resultsAmount, value );
 }
 
 - (void)firstSearchIntegerChar:(int8_t)value
                {
                        if ( result != KERN_INVALID_ADDRESS )
                        {
-                               NSLog( @"vm_region returned error: %i", result );
+                               CMLog( @"vm_region returned error: %i", result );
                        }
                        break;
                }
                        
                        if ( (result = vm_read_overwrite( processTask, address, size, (vm_address_t)data, &dataLength )) != KERN_SUCCESS && result != KERN_PROTECTION_FAILURE )
                        {
-                               NSLog( @"vm_read_overwrite returned error: %i", result );
+                               CMLog( @"vm_read_overwrite returned error: %i", result );
                                free( data );
                                break;
                        }
                                
                                if ( (results = (TCaddress *)realloc( results, TCAddressSize*resultsAmount + TCAddressSize*dataLength )) == NULL )
                                {
-                                       NSLog( @"ERROR: could not expand buffer" );
+                                       CMLog( @"ERROR: could not expand buffer" );
                                        exit(0);
                                }
                                
        realloc( results, TCAddressSize*resultsAmount );
        [searchResults addObject:[SearchResults resultsWithType:TYPE_INTEGER size:SIZE_8_BIT data:results amount:resultsAmount]];
        
-       NSLog( @"found %i of %i", resultsAmount, value );
+       CMLog( @"found %i of %i", resultsAmount, value );
 }
 
 - (void)firstSearchIntegerShort:(int16_t)value
                {
                        if ( result != KERN_INVALID_ADDRESS )
                        {
-                               NSLog( @"vm_region returned error: %i", result );
+                               CMLog( @"vm_region returned error: %i", result );
                        }
                        break;
                }
                        
                        if ( (result = vm_read_overwrite( processTask, address, size, (vm_address_t)data, &dataLength )) != KERN_SUCCESS && result != KERN_PROTECTION_FAILURE )
                        {
-                               NSLog( @"vm_read_overwrite returned error: %i", result );
+                               CMLog( @"vm_read_overwrite returned error: %i", result );
                                free( data );
                                break;
                        }
                                
                                if ( (results = (TCaddress *)realloc( results, TCAddressSize*resultsAmount + 2*dataLength )) == NULL )
                                {
-                                       NSLog( @"ERROR: could not expand buffer" );
+                                       CMLog( @"ERROR: could not expand buffer" );
                                        exit(0);
                                }
                                
        realloc( results, TCAddressSize*resultsAmount );
        [searchResults addObject:[SearchResults resultsWithType:TYPE_INTEGER size:SIZE_16_BIT data:results amount:resultsAmount]];
        
-       NSLog( @"found %i of %i", resultsAmount, value );
+       CMLog( @"found %i of %i", resultsAmount, value );
 }
 
 - (void)firstSearchIntegerLong:(int32_t)value
        TCaddress                                       *results = NULL;
        int                                                     resultsAmount = 0;
        
-       unsigned                                        zone_count = 10;
+       /*unsigned                                      zone_count = 10;
        vm_address_t                            *zones = (vm_address_t *)malloc( zone_count * sizeof(vm_address_t) );
        //memory_reader_t                               reader;
        
        if ( (result = malloc_get_all_zones( processTask, NULL, &zones, &zone_count )) != KERN_SUCCESS )
        {
-               NSLog( @"malloc_get_all_zones error: %i", result );
+               CMLog( @"malloc_get_all_zones error: %i", result );
        }
        else
        {
                //address = zones[0];
                
-               /*int                   i;
+               int                     i;
                
                for ( i = 0; i < 10; i++ )
                {
-                       NSLog( @"malloc_get_all_zones[%i] = %X", i, (vm_address_t)zones[i] );
-               }*/
-       }
+                       CMLog( @"malloc_get_all_zones[%i] = %X", i, (vm_address_t)zones[i] );
+               }
+       }*/
        
        for (;;)
        {
                {
                        if ( result != KERN_INVALID_ADDRESS )
                        {
-                               NSLog( @"vm_region returned error: %i", result );
+                               CMLog( @"vm_region returned error: %i", result );
                        }
                        break;
                }
                        data = (int32_t *)malloc( size );
                        dataLength = size;
                        
-                       NSLog( @"address: %.8X size: %i", address, size );
+                       //CMLog( @"address: %.8X size: %i", address, size );
                        
                        if ( (result = vm_read_overwrite( processTask, address, size, (vm_address_t)data, &dataLength )) != KERN_SUCCESS && result != KERN_PROTECTION_FAILURE )
                        {
-                               NSLog( @"vm_read_overwrite returned error: %i", result );
+                               CMLog( @"vm_read_overwrite returned error: %i", result );
                                free( data );
                                break;
                        }
                                
                                if ( (results = (TCaddress *)realloc( results, TCAddressSize*resultsAmount + dataLength )) == NULL )
                                {
-                                       NSLog( @"ERROR: could not expand buffer" );
+                                       CMLog( @"ERROR: could not expand buffer" );
                                        exit(0);
                                }
-                               
+
                                for ( i = 0; i < top; i++ )
                                {
                                        if ( *(data+i) == value )
        realloc( results, TCAddressSize*resultsAmount );
        [searchResults addObject:[SearchResults resultsWithType:TYPE_INTEGER size:SIZE_32_BIT data:results amount:resultsAmount]];
        
-       NSLog( @"found %i of %i", resultsAmount, value );
+       CMLog( @"found %i of %i", resultsAmount, value );
 }
 
-
 - (void)firstSearchDecimalFloat:(float)value
 {
        kern_return_t                           result;
                {
                        if ( result != KERN_INVALID_ADDRESS )
                        {
-                               NSLog( @"vm_region returned error: %i", result );
+                               CMLog( @"vm_region returned error: %i", result );
                        }
                        break;
                }
                        
                        if ( (result = vm_read_overwrite( processTask, address, size, (vm_address_t)data, &dataLength )) != KERN_SUCCESS && result != KERN_PROTECTION_FAILURE )
                        {
-                               NSLog( @"vm_read_overwrite returned error: %i", result );
+                               CMLog( @"vm_read_overwrite returned error: %i", result );
                                free( data );
                                break;
                        }
                                
                                if ( (results = realloc( results, TCAddressSize*resultsAmount + dataLength )) == NULL )
                                {
-                                       NSLog( @"ERROR: could not expand buffer" );
+                                       CMLog( @"ERROR: could not expand buffer" );
                                        exit(0);
                                }
                                
                                for ( i = 0; i < top; i++ )
                                {
-                                       if ( cl_compare_float_eps( *(data+i), value, 0.1f ) == 0 )
+                                       if ( CMCompareFloatsWithEpsilon( *(data+i), value, 0.1f ) == 0 )
                                        {
                                                results[resultsAmount++] = (TCaddress)address + i * sizeof(value);
                                        }
        realloc( results, TCAddressSize*resultsAmount );
        [searchResults addObject:[SearchResults resultsWithType:TYPE_DECIMAL size:SIZE_32_BIT data:results amount:resultsAmount]];
        
-       NSLog( @"found %i of %i", resultsAmount, value );
+       CMLog( @"found %i of %i", resultsAmount, value );
 }
 
 - (void)firstSearchDecimalDouble:(double)value
        TCaddress                                       *results = NULL;
        int                                                     resultsAmount = 0;
        
-       NSLog( @"float search" );
+       CMLog( @"float search" );
        
        for (;;)
        {
                {
                        if ( result != KERN_INVALID_ADDRESS )
                        {
-                               NSLog( @"vm_region returned error: %i", result );
+                               CMLog( @"vm_region returned error: %i", result );
                        }
                        break;
                }
                        
                        if ( (result = vm_read_overwrite( processTask, address, size, (vm_address_t)data, &dataLength )) != KERN_SUCCESS && result != KERN_PROTECTION_FAILURE )
                        {
-                               NSLog( @"vm_read_overwrite returned error: %i", result );
+                               CMLog( @"vm_read_overwrite returned error: %i", result );
                                free( data );
                                break;
                        }
                                
                                if ( (results = realloc( results, TCAddressSize*resultsAmount + dataLength )) == NULL )
                                {
-                                       NSLog( @"ERROR: could not expand buffer" );
+                                       CMLog( @"ERROR: could not expand buffer" );
                                        exit(0);
                                }
                                
                                for ( i = 0; i < top; i++ )
                                {
-                                       if ( cl_compare_double_eps( *(data+i), value, 0.1 ) == 0 )
+                                       if ( CMCompareDoublesWithEpsilon( *(data+i), value, 0.1 ) == 0 )
                                        {
                                                results[resultsAmount++] = (TCaddress)address + i * sizeof(value);
                                        }
        realloc( results, TCAddressSize*resultsAmount );
        [searchResults addObject:[SearchResults resultsWithType:TYPE_DECIMAL size:SIZE_64_BIT data:results amount:resultsAmount]];
        
-       NSLog( @"found %i of %i", resultsAmount, value );
+       CMLog( @"found %i of %i", resultsAmount, value );
 }
 
 
 {
        kern_return_t                           result;
        
-       int8_t                                          data;
+       char                                            *data;
        vm_size_t                                       dataLength;
        
        TCaddress                                       *results;
                return;
        }
        
+       if ( (data = (char *)malloc( vsize )) == NULL )
+       {
+               CMLog( @"ERROR: could not create buffer" );
+               
+               [self sendError:@"The server cancelled the search because it ran out of memory." fatal:NO];
+               return;
+       }
+       
        if ( (results = (TCaddress *)malloc( TCAddressSize*lastResultsAmount )) == NULL )
        {
-               NSLog( @"ERROR: could not create buffer" );
+               CMLog( @"ERROR: could not create buffer" );
                
                [self sendError:@"The server cancelled the search because it ran out of memory." fatal:NO];
+               free( data );
                return;
        }
        
        {
                TCaddress               address = lastResultsData[i];
                
-               dataLength = sizeof(data);
+               //dataLength = sizeof(data);
                
-               if ( (result = vm_read_overwrite( processTask, address, sizeof(data), (vm_address_t)(&data), &dataLength )) == KERN_SUCCESS )
+               if ( (result = vm_read_overwrite( processTask, address, vsize, (vm_address_t)(data), &dataLength )) == KERN_SUCCESS )
                {
-                       if ( data == value[0] )
+                       if ( memcmp( data, value, dataLength ) == 0 )
                        {
                                results[resultsAmount++] = address;
                        }
                {
                        if ( result != KERN_PROTECTION_FAILURE )
                        {
-                               NSLog( @"vm_read_overwrite returned error: %i", result );
+                               CMLog( @"vm_read_overwrite returned error: %i", result );
                                break;
                        }
                }
        realloc( results, TCAddressSize*resultsAmount );
        [searchResults addObject:[SearchResults resultsWithType:TYPE_INTEGER size:SIZE_8_BIT data:results amount:resultsAmount]];
        
-       NSLog( @"found %i of %i", resultsAmount, value );
+       free( data );
+       
+       CMLog( @"found %i of %i", resultsAmount, value );
 }
 
 - (void)searchIntegerChar:(int8_t)value
        
        if ( (results = (TCaddress *)malloc( TCAddressSize*lastResultsAmount )) == NULL )
        {
-               NSLog( @"ERROR: could not create buffer" );
+               CMLog( @"ERROR: could not create buffer" );
                
                [self sendError:@"The server cancelled the search because it ran out of memory." fatal:NO];
                return;
                {
                        if ( result != KERN_PROTECTION_FAILURE )
                        {
-                               NSLog( @"vm_read_overwrite returned error: %i", result );
+                               CMLog( @"vm_read_overwrite returned error: %i", result );
                                break;
                        }
                }
        realloc( results, TCAddressSize*resultsAmount );
        [searchResults addObject:[SearchResults resultsWithType:TYPE_INTEGER size:SIZE_8_BIT data:results amount:resultsAmount]];
        
-       NSLog( @"found %i of %i", resultsAmount, value );
+       CMLog( @"found %i of %i", resultsAmount, value );
 }
 
 - (void)searchIntegerShort:(int16_t)value
        
        if ( (results = (TCaddress *)malloc( TCAddressSize*lastResultsAmount )) == NULL )
        {
-               NSLog( @"ERROR: could not create buffer" );
+               CMLog( @"ERROR: could not create buffer" );
                
                [self sendError:@"The server cancelled the search because it ran out of memory." fatal:NO];
                return;
                {
                        if ( result != KERN_PROTECTION_FAILURE )
                        {
-                               NSLog( @"vm_read_overwrite returned error: %i", result );
+                               CMLog( @"vm_read_overwrite returned error: %i", result );
                                break;
                        }
                }
        realloc( results, TCAddressSize*resultsAmount );
        [searchResults addObject:[SearchResults resultsWithType:TYPE_INTEGER size:SIZE_16_BIT data:results amount:resultsAmount]];
        
-       NSLog( @"found %i of %i", resultsAmount, value );
+       CMLog( @"found %i of %i", resultsAmount, value );
 }
 
 - (void)searchIntegerLong:(int32_t)value
        
        if ( (results = (TCaddress *)malloc( TCAddressSize*lastResultsAmount )) == NULL )
        {
-               NSLog( @"ERROR: could not create buffer" );
+               CMLog( @"ERROR: could not create buffer" );
                
                [self sendError:@"The server cancelled the search because it ran out of memory." fatal:NO];
                return;
                {
                        if ( result != KERN_PROTECTION_FAILURE )
                        {
-                               NSLog( @"vm_read_overwrite returned error: %i", result );
+                               CMLog( @"vm_read_overwrite returned error: %i", result );
                                break;
                        }
                }
        realloc( results, TCAddressSize*resultsAmount );
        [searchResults addObject:[SearchResults resultsWithType:TYPE_INTEGER size:SIZE_32_BIT data:results amount:resultsAmount]];
        
-       NSLog( @"found %i of %i", resultsAmount, value );
+       CMLog( @"found %i of %i", resultsAmount, value );
 }
 
 - (void)searchDecimalFloat:(float)value
        
        if ( (results = (TCaddress *)malloc( TCAddressSize*lastResultsAmount )) == NULL )
        {
-               NSLog( @"ERROR: could not create buffer" );
+               CMLog( @"ERROR: could not create buffer" );
                
                [self sendError:@"The server cancelled the search because it ran out of memory." fatal:NO];
                return;
                
                if ( (result = vm_read_overwrite( processTask, address, sizeof(data), (vm_address_t)(&data), &dataLength )) == KERN_SUCCESS )
                {
-                       if ( cl_compare_float_eps( data, value, 0.1f ) == 0 )
+                       if ( CMCompareFloatsWithEpsilon( data, value, 0.1f ) == 0 )
                        {
                                results[resultsAmount++] = address;
                        }
                {
                        if ( result != KERN_PROTECTION_FAILURE )
                        {
-                               NSLog( @"vm_read_overwrite returned error: %i", result );
+                               CMLog( @"vm_read_overwrite returned error: %i", result );
                                break;
                        }
                }
        realloc( results, TCAddressSize*resultsAmount );
        [searchResults addObject:[SearchResults resultsWithType:TYPE_DECIMAL size:SIZE_32_BIT data:results amount:resultsAmount]];
        
-       NSLog( @"found %i of %i", resultsAmount, value );
+       CMLog( @"found %i of %i", resultsAmount, value );
 }
 
 - (void)searchDecimalDouble:(double)value
        
        if ( (results = (TCaddress *)malloc( TCAddressSize*lastResultsAmount )) == NULL )
        {
-               NSLog( @"ERROR: could not create buffer" );
+               CMLog( @"ERROR: could not create buffer" );
                
                [self sendError:@"The server cancelled the search because it ran out of memory." fatal:NO];
                return;
                
                if ( (result = vm_read_overwrite( processTask, address, sizeof(data), (vm_address_t)(&data), &dataLength )) == KERN_SUCCESS )
                {
-                       if ( cl_compare_double_eps( data, value, 0.1 ) == 0 )
+                       if ( CMCompareDoublesWithEpsilon( data, value, 0.1 ) == 0 )
                        {
                                results[resultsAmount++] = address;
                        }
                {
                        if ( result != KERN_PROTECTION_FAILURE )
                        {
-                               NSLog( @"vm_read_overwrite returned error: %i", result );
+                               CMLog( @"vm_read_overwrite returned error: %i", result );
                                break;
                        }
                }
        realloc( results, TCAddressSize*resultsAmount );
        [searchResults addObject:[SearchResults resultsWithType:TYPE_DECIMAL size:SIZE_64_BIT data:results amount:resultsAmount]];
        
-       NSLog( @"found %i of %i", resultsAmount, value );
+       CMLog( @"found %i of %i", resultsAmount, value );
 }
 
 
        int                                     failCount = 0;
        int                                     i;
        
-       NSLog( @"change string: %s", value );
-       
        for ( i = 0; i < count; i++ )
        {
                if ( vm_write( processTask, (vm_address_t)addresses[i], (vm_offset_t)value, vsize ) != KERN_SUCCESS )
 
        if ( (buffer = (char *)malloc( length ))==NULL )
        {
-               NSLog( @"sendProcessList failed" );
+               CMLog( @"sendProcessList failed" );
                return;
        }
 
 
        if ( SendBuffer( sockfd, buffer, &lengthAfter ) == -1 || lengthAfter != length )
        {
-               NSLog( @"sendProcessList failed" );
+               CMLog( @"sendProcessList failed" );
        }
 
        free( buffer );
 
        if ( SendBuffer( sockfd, (char *)(&header), &length ) == -1 || length != sizeof(header) )
        {
-               NSLog( @"sendSearchFinished failed" );
+               CMLog( @"sendSearchFinished failed" );
        }
 }
 
        PacketHeader    header;
        int                             length;
        int                             lengthAfter;
+       int                             displayAmount = ( searchResultsAmountDisplayed > amount )? amount : searchResultsAmountDisplayed;
+       int                             resultsLength = TCAddressSize * displayAmount;
 
        char                    *buffer, *ptr;
 
        header.checksum = RandomChecksum();
        header.function = 7;
-       header.size = sizeof(amount) + TCAddressSize*amount;
-       //            AMOUNT           DATA
+       header.size = sizeof(amount) + sizeof(displayAmount) + resultsLength;
+       //            AMOUNT           DISPLAY AMOUNT          DATA
 
        lengthAfter = length = header.size + sizeof(header);
 
        if ( (buffer = (char *)malloc( length )) == NULL )
        {
-               NSLog( @"sendVariableList:amount: failed" );
+               CMLog( @"sendVariableList:amount: failed" );
                return;
        }
 
 
        COPY_TO_BUFFER( ptr, &header, sizeof(header) );
        COPY_TO_BUFFER( ptr, &amount, sizeof(amount) );
-       COPY_TO_BUFFER( ptr, data, TCAddressSize*amount );
+       COPY_TO_BUFFER( ptr, &displayAmount, sizeof(displayAmount) );
+       COPY_TO_BUFFER( ptr, data, resultsLength );
 
        if ( SendBuffer( sockfd, buffer, &length ) == -1 || lengthAfter != length )
        {
-               NSLog( @"sendVariableList:amount: failed" );
+               CMLog( @"sendVariableList:amount: failed" );
        }
 
        free( buffer );
+       
+       CMLog( @"SERVER sending %i out of %i results", displayAmount, amount );
 }
 
 - (void)sendChangeFinished
 
        if ( SendBuffer( sockfd, (char *)(&header), &length ) == -1 || length != sizeof(header) )
        {
-               NSLog( @"sendChangeFinished failed" );
+               CMLog( @"sendChangeFinished failed" );
        }
 }
 
 
        if ( (buffer = (char *)malloc( length )) == NULL )
        {
-               NSLog( @"sendError:fatal: failed" );
+               CMLog( @"sendError:fatal: failed" );
                return;
        }
 
 
        if ( SendBuffer( sockfd, buffer, &length ) == -1 || lengthAfter != length )
        {
-               NSLog( @"sendError:fatal: failed" );
+               CMLog( @"sendError:fatal: failed" );
        }
 
        free( buffer );
 
        if ( SendBuffer( sockfd, (char *)(&header), &length ) == -1 || length != sizeof(header) )
        {
-               NSLog( @"sendUndoFinished failed" );
+               CMLog( @"sendUndoFinished failed" );
        }
 }
 
 
        if ( SendBuffer( sockfd, (char *)(&header), &length ) == -1 || length != sizeof(header) )
        {
-               NSLog( @"sendRedoFinished failed" );
+               CMLog( @"sendRedoFinished failed" );
        }
 }
 
        
        if ( (buffer = (char *)malloc( length )) == NULL )
        {
-               NSLog( @"sendSetTargetPID: failed" );
+               CMLog( @"sendSetTargetPID: failed" );
        }
        
        ptr = buffer;
        
        if ( SendBuffer( sockfd, buffer, &lengthAfter ) == -1 || lengthAfter != length )
        {
-               NSLog( @"sendUndoRedoStatus: failed" );
+               CMLog( @"sendUndoRedoStatus: failed" );
        }
        
        free( buffer );
 
        if ( (buffer = (char *)malloc( length ))==NULL )
        {
-               NSLog( @"sendAppLaunched: failed" );
+               CMLog( @"sendAppLaunched: failed" );
 
                return;
        }
 
        if ( SendBuffer( sockfd, buffer, &lengthAfter ) == -1 || lengthAfter != length )
        {
-               NSLog( @"sendAppLaunched: failed" );
+               CMLog( @"sendAppLaunched: failed" );
        }
 
        free( buffer );
 
        if ( (buffer = (char *)malloc( length ))==NULL )
        {
-               NSLog( @"sendAppQuit: failed" );
+               CMLog( @"sendAppQuit: failed" );
 
                return;
        }
 
        if ( SendBuffer( sockfd, buffer, &lengthAfter ) == -1 || lengthAfter != length )
        {
-               NSLog( @"sendAppQuit: failed" );
+               CMLog( @"sendAppQuit: failed" );
        }
 
        free( buffer );
 
        if ( SendBuffer( sockfd, (char *)(&header), &length ) == -1 || length != sizeof(header) )
        {
-               NSLog( @"sendTargetAppQuit failed" );
+               CMLog( @"sendTargetAppQuit failed" );
        }
 }
 
 
        if ( (buffer = (char *)malloc( length ))==NULL )
        {
-               NSLog( @"sendPauseFinished: failed" );
+               CMLog( @"sendPauseFinished: failed" );
 
                return;
        }
 
        if ( SendBuffer( sockfd, buffer, &lengthAfter ) == -1 || lengthAfter != length )
        {
-               NSLog( @"sendPauseFinished: failed" );
+               CMLog( @"sendPauseFinished: failed" );
        }
 
        free( buffer );
 
        COPY_FROM_BUFFER( &type, ptr, sizeof(type) );
        COPY_FROM_BUFFER( &size, ptr, sizeof(size) );
+       
+       // receive the amount of results to return
+       COPY_FROM_BUFFER( &searchResultsAmountDisplayed, ptr, sizeof(searchResultsAmountDisplayed) );
 
        if ( ![searchResults lastObject] )
        {
                                {
                                        case SIZE_8_BIT:
                                        {
-                                               [self firstSearchString8bit:ptr size:(dataSize - (ptr - data))];
+                                               [self firstSearchString8bit:ptr size:(dataSize - (ptr - data) - 1)];
                                        }
                                                break;
                                }
                                        }
                                        else
                                        {
-                                               NSLog( @"ERROR: process couldn't be paused" );
+                                               CMLog( @"ERROR: process couldn't be paused" );
                                                [self sendPauseFinished:NO];
                                                [self sendError:@"Could not pause target because of an unknown error." fatal:NO];
                                        }
                                }
                                else
                                {
-                                       NSLog( @"ERROR: process couldn't be paused" );
+                                       CMLog( @"ERROR: process couldn't be paused" );
                                        [self sendPauseFinished:NO];
                                        [self sendError:@"Could not pause target because of an unknown error." fatal:NO];
                                }
                        }
                        else
                        {
-                               NSLog( @"ERROR: process couldn't be paused" );
+                               CMLog( @"ERROR: process couldn't be paused" );
                                [self sendPauseFinished:NO];
                                
                                switch ( errno )
 
        if ( (result = task_for_pid( current_task(), processID, &processTask)) != KERN_SUCCESS )
        {
-               NSLog( @"task_for_pid returned error: %i", result );
+               CMLog( @"task_for_pid returned error: %i", result );
        }
 }
 
 %%%%%%%%%%%%%%%%%%%%%%   Internal Functions
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
+
+#define ASIZE 256
+int bmsearch( char *pat, int m, char *text, int n, void *base, void *loc[] )
+{
+       int count = 0;
+       int i, j, k, skip[ASIZE];
+       
+       if( m==0 ) return 0;
+       for( k=0; k<ASIZE; k++ ) skip[k] = m;
+       for( k=0; k<m-1; k++ ) skip[(int)pat[k]] = m-k-1;
+       
+       for( k=m-1; k < n; k += skip[(int)text[k] & (ASIZE-1)] ) {
+               for( j=m-1, i=k; j>=0 && text[i] == pat[j]; j-- ) i--;
+               if( j == (-1) )
+                       /* SAVE LOCATION */
+                       loc[count++] = (void *)( base+i+1 );
+                       //return( text+i+1 );
+       }
+       return count;
+}
+
 /*
 BOOL compare_float( float a, float b )
 {
This page took 0.055048 seconds and 4 git commands to generate.