X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=CheatServer.m;h=04cbdd92fc877d5cef0c5ff2ff25a77036d1560e;hb=e8d51183acdd2410a38dcf8f0efbf7c30cd6c581;hp=2a8ed8ca899879aeac5835398396c425bacffc03;hpb=42cf7bbe564d70233a0d73baee613f209eb00eb6;p=chaz%2Fthecheat diff --git a/CheatServer.m b/CheatServer.m index 2a8ed8c..04cbdd9 100644 --- a/CheatServer.m +++ b/CheatServer.m @@ -12,13 +12,18 @@ #import "SearchResults.h" +// for comparing floats +#import + #include #include +#include // Internal Functions -BOOL inline compare_float( float a, float b ); -BOOL inline compare_double( double a, double b ); +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 ); @implementation CheatServer @@ -88,7 +93,7 @@ BOOL inline compare_double( double a, double b ); if ( getpeername( sockfd, &identifier, &addrLen ) == -1 ) { - NSLog( @"ERROR: getpeername() failed" ); + CMLog( @"ERROR: getpeername() failed" ); } if ( identifier.sa_family == AF_INET ) @@ -99,12 +104,12 @@ BOOL inline compare_double( double a, double b ); 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]; @@ -117,10 +122,10 @@ BOOL inline compare_double( double a, double b ); 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"]; } @@ -151,7 +156,7 @@ BOOL inline compare_double( double a, double b ); numfds = sockfd + 1; - NSLog( @"SERVER start" ); + CMLog( @"SERVER start" ); for (;;) { @@ -168,26 +173,26 @@ BOOL inline compare_double( double a, double b ); 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 ) { @@ -234,7 +239,7 @@ BOOL inline compare_double( double a, double b ); close( sockfd ); - NSLog( @"SERVER close" ); + CMLog( @"SERVER close" ); [rootProxy serverDisconnected:self]; } @@ -273,15 +278,13 @@ BOOL inline compare_double( double a, double b ); 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; } @@ -293,28 +296,32 @@ BOOL inline compare_double( double a, double b ); 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 ); @@ -326,7 +333,7 @@ BOOL inline compare_double( double a, double b ); 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 @@ -351,7 +358,7 @@ BOOL inline compare_double( double a, double b ); { if ( result != KERN_INVALID_ADDRESS ) { - NSLog( @"vm_region returned error: %i", result ); + CMLog( @"vm_region returned error: %i", result ); } break; } @@ -363,7 +370,7 @@ BOOL inline compare_double( double a, double b ); 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; } @@ -374,7 +381,7 @@ BOOL inline compare_double( double a, double b ); if ( (results = (TCaddress *)realloc( results, TCAddressSize*resultsAmount + TCAddressSize*dataLength )) == NULL ) { - NSLog( @"ERROR: could not expand buffer" ); + CMLog( @"ERROR: could not expand buffer" ); exit(0); } @@ -396,7 +403,7 @@ BOOL inline compare_double( double a, double b ); 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 @@ -421,7 +428,7 @@ BOOL inline compare_double( double a, double b ); { if ( result != KERN_INVALID_ADDRESS ) { - NSLog( @"vm_region returned error: %i", result ); + CMLog( @"vm_region returned error: %i", result ); } break; } @@ -433,7 +440,7 @@ BOOL inline compare_double( double a, double b ); 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; } @@ -444,7 +451,7 @@ BOOL inline compare_double( double a, double b ); if ( (results = (TCaddress *)realloc( results, TCAddressSize*resultsAmount + 2*dataLength )) == NULL ) { - NSLog( @"ERROR: could not expand buffer" ); + CMLog( @"ERROR: could not expand buffer" ); exit(0); } @@ -466,7 +473,7 @@ BOOL inline compare_double( double a, double b ); 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 @@ -485,25 +492,25 @@ BOOL inline compare_double( double a, double b ); 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 (;;) { @@ -511,7 +518,7 @@ BOOL inline compare_double( double a, double b ); { if ( result != KERN_INVALID_ADDRESS ) { - NSLog( @"vm_region returned error: %i", result ); + CMLog( @"vm_region returned error: %i", result ); } break; } @@ -521,11 +528,11 @@ BOOL inline compare_double( double a, double b ); 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; } @@ -536,10 +543,10 @@ BOOL inline compare_double( double a, double b ); 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 ) @@ -558,10 +565,9 @@ BOOL inline compare_double( double a, double b ); 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; @@ -584,7 +590,7 @@ BOOL inline compare_double( double a, double b ); { if ( result != KERN_INVALID_ADDRESS ) { - NSLog( @"vm_region returned error: %i", result ); + CMLog( @"vm_region returned error: %i", result ); } break; } @@ -596,7 +602,7 @@ BOOL inline compare_double( double a, double b ); 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; } @@ -607,13 +613,13 @@ BOOL inline compare_double( double a, double b ); 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 ( compare_float( *(data+i), value ) ) + if ( CMCompareFloatsWithEpsilon( *(data+i), value, 0.1f ) == 0 ) { results[resultsAmount++] = (TCaddress)address + i * sizeof(value); } @@ -629,7 +635,7 @@ BOOL inline compare_double( double a, double b ); 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 @@ -648,7 +654,7 @@ BOOL inline compare_double( double a, double b ); TCaddress *results = NULL; int resultsAmount = 0; - NSLog( @"float search" ); + CMLog( @"float search" ); for (;;) { @@ -656,7 +662,7 @@ BOOL inline compare_double( double a, double b ); { if ( result != KERN_INVALID_ADDRESS ) { - NSLog( @"vm_region returned error: %i", result ); + CMLog( @"vm_region returned error: %i", result ); } break; } @@ -668,7 +674,7 @@ BOOL inline compare_double( double a, double b ); 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; } @@ -679,13 +685,13 @@ BOOL inline compare_double( double a, double b ); 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 ( compare_double( *(data+i), value ) ) + if ( CMCompareDoublesWithEpsilon( *(data+i), value, 0.1 ) == 0 ) { results[resultsAmount++] = (TCaddress)address + i * sizeof(value); } @@ -701,7 +707,7 @@ BOOL inline compare_double( double a, double b ); 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 ); } @@ -709,7 +715,7 @@ BOOL inline compare_double( double a, double b ); { kern_return_t result; - int8_t data; + char *data; vm_size_t dataLength; TCaddress *results; @@ -725,11 +731,20 @@ BOOL inline compare_double( double a, double b ); 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; } @@ -737,11 +752,11 @@ BOOL inline compare_double( double a, double b ); { 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; } @@ -750,7 +765,7 @@ BOOL inline compare_double( double a, double b ); { if ( result != KERN_PROTECTION_FAILURE ) { - NSLog( @"vm_read_overwrite returned error: %i", result ); + CMLog( @"vm_read_overwrite returned error: %i", result ); break; } } @@ -759,7 +774,9 @@ BOOL inline compare_double( double a, double b ); 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 @@ -784,7 +801,7 @@ BOOL inline compare_double( double a, double b ); 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; @@ -807,7 +824,7 @@ BOOL inline compare_double( double a, double b ); { if ( result != KERN_PROTECTION_FAILURE ) { - NSLog( @"vm_read_overwrite returned error: %i", result ); + CMLog( @"vm_read_overwrite returned error: %i", result ); break; } } @@ -816,7 +833,7 @@ BOOL inline compare_double( double a, double b ); 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 @@ -841,7 +858,7 @@ BOOL inline compare_double( double a, double b ); 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; @@ -864,7 +881,7 @@ BOOL inline compare_double( double a, double b ); { if ( result != KERN_PROTECTION_FAILURE ) { - NSLog( @"vm_read_overwrite returned error: %i", result ); + CMLog( @"vm_read_overwrite returned error: %i", result ); break; } } @@ -873,7 +890,7 @@ BOOL inline compare_double( double a, double b ); 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 @@ -898,7 +915,7 @@ BOOL inline compare_double( double a, double b ); 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; @@ -921,7 +938,7 @@ BOOL inline compare_double( double a, double b ); { if ( result != KERN_PROTECTION_FAILURE ) { - NSLog( @"vm_read_overwrite returned error: %i", result ); + CMLog( @"vm_read_overwrite returned error: %i", result ); break; } } @@ -930,7 +947,7 @@ BOOL inline compare_double( double a, double b ); 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 @@ -955,7 +972,7 @@ BOOL inline compare_double( double a, double b ); 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; @@ -969,7 +986,7 @@ BOOL inline compare_double( double a, double b ); if ( (result = vm_read_overwrite( processTask, address, sizeof(data), (vm_address_t)(&data), &dataLength )) == KERN_SUCCESS ) { - if ( compare_float( data, value ) ) + if ( CMCompareFloatsWithEpsilon( data, value, 0.1f ) == 0 ) { results[resultsAmount++] = address; } @@ -978,7 +995,7 @@ BOOL inline compare_double( double a, double b ); { if ( result != KERN_PROTECTION_FAILURE ) { - NSLog( @"vm_read_overwrite returned error: %i", result ); + CMLog( @"vm_read_overwrite returned error: %i", result ); break; } } @@ -987,7 +1004,7 @@ BOOL inline compare_double( double a, double b ); 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 @@ -1012,7 +1029,7 @@ BOOL inline compare_double( double a, double b ); 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; @@ -1026,7 +1043,7 @@ BOOL inline compare_double( double a, double b ); if ( (result = vm_read_overwrite( processTask, address, sizeof(data), (vm_address_t)(&data), &dataLength )) == KERN_SUCCESS ) { - if ( compare_double( data, value ) ) + if ( CMCompareDoublesWithEpsilon( data, value, 0.1 ) == 0 ) { results[resultsAmount++] = address; } @@ -1035,7 +1052,7 @@ BOOL inline compare_double( double a, double b ); { if ( result != KERN_PROTECTION_FAILURE ) { - NSLog( @"vm_read_overwrite returned error: %i", result ); + CMLog( @"vm_read_overwrite returned error: %i", result ); break; } } @@ -1044,7 +1061,7 @@ BOOL inline compare_double( double a, double b ); 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 ); } @@ -1053,8 +1070,6 @@ BOOL inline compare_double( double a, double b ); 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 ) @@ -1203,7 +1218,7 @@ BOOL inline compare_double( double a, double b ); if ( (buffer = (char *)malloc( length ))==NULL ) { - NSLog( @"sendProcessList failed" ); + CMLog( @"sendProcessList failed" ); return; } @@ -1225,7 +1240,7 @@ BOOL inline compare_double( double a, double b ); if ( SendBuffer( sockfd, buffer, &lengthAfter ) == -1 || lengthAfter != length ) { - NSLog( @"sendProcessList failed" ); + CMLog( @"sendProcessList failed" ); } free( buffer ); @@ -1243,7 +1258,7 @@ BOOL inline compare_double( double a, double b ); if ( SendBuffer( sockfd, (char *)(&header), &length ) == -1 || length != sizeof(header) ) { - NSLog( @"sendSearchFinished failed" ); + CMLog( @"sendSearchFinished failed" ); } } @@ -1252,19 +1267,21 @@ BOOL inline compare_double( double a, double b ); 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; } @@ -1272,14 +1289,17 @@ BOOL inline compare_double( double a, double b ); 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 @@ -1293,7 +1313,7 @@ BOOL inline compare_double( double a, double b ); if ( SendBuffer( sockfd, (char *)(&header), &length ) == -1 || length != sizeof(header) ) { - NSLog( @"sendChangeFinished failed" ); + CMLog( @"sendChangeFinished failed" ); } } @@ -1316,7 +1336,7 @@ BOOL inline compare_double( double a, double b ); if ( (buffer = (char *)malloc( length )) == NULL ) { - NSLog( @"sendError:fatal: failed" ); + CMLog( @"sendError:fatal: failed" ); return; } @@ -1328,7 +1348,7 @@ BOOL inline compare_double( double a, double b ); if ( SendBuffer( sockfd, buffer, &length ) == -1 || lengthAfter != length ) { - NSLog( @"sendError:fatal: failed" ); + CMLog( @"sendError:fatal: failed" ); } free( buffer ); @@ -1350,7 +1370,7 @@ BOOL inline compare_double( double a, double b ); if ( SendBuffer( sockfd, (char *)(&header), &length ) == -1 || length != sizeof(header) ) { - NSLog( @"sendUndoFinished failed" ); + CMLog( @"sendUndoFinished failed" ); } } @@ -1365,7 +1385,7 @@ BOOL inline compare_double( double a, double b ); if ( SendBuffer( sockfd, (char *)(&header), &length ) == -1 || length != sizeof(header) ) { - NSLog( @"sendRedoFinished failed" ); + CMLog( @"sendRedoFinished failed" ); } } @@ -1388,7 +1408,7 @@ BOOL inline compare_double( double a, double b ); if ( (buffer = (char *)malloc( length )) == NULL ) { - NSLog( @"sendSetTargetPID: failed" ); + CMLog( @"sendSetTargetPID: failed" ); } ptr = buffer; @@ -1399,7 +1419,7 @@ BOOL inline compare_double( double a, double b ); if ( SendBuffer( sockfd, buffer, &lengthAfter ) == -1 || lengthAfter != length ) { - NSLog( @"sendUndoRedoStatus: failed" ); + CMLog( @"sendUndoRedoStatus: failed" ); } free( buffer ); @@ -1429,7 +1449,7 @@ BOOL inline compare_double( double a, double b ); if ( (buffer = (char *)malloc( length ))==NULL ) { - NSLog( @"sendAppLaunched: failed" ); + CMLog( @"sendAppLaunched: failed" ); return; } @@ -1444,7 +1464,7 @@ BOOL inline compare_double( double a, double b ); if ( SendBuffer( sockfd, buffer, &lengthAfter ) == -1 || lengthAfter != length ) { - NSLog( @"sendAppLaunched: failed" ); + CMLog( @"sendAppLaunched: failed" ); } free( buffer ); @@ -1474,7 +1494,7 @@ BOOL inline compare_double( double a, double b ); if ( (buffer = (char *)malloc( length ))==NULL ) { - NSLog( @"sendAppQuit: failed" ); + CMLog( @"sendAppQuit: failed" ); return; } @@ -1488,7 +1508,7 @@ BOOL inline compare_double( double a, double b ); if ( SendBuffer( sockfd, buffer, &lengthAfter ) == -1 || lengthAfter != length ) { - NSLog( @"sendAppQuit: failed" ); + CMLog( @"sendAppQuit: failed" ); } free( buffer ); @@ -1505,7 +1525,7 @@ BOOL inline compare_double( double a, double b ); if ( SendBuffer( sockfd, (char *)(&header), &length ) == -1 || length != sizeof(header) ) { - NSLog( @"sendTargetAppQuit failed" ); + CMLog( @"sendTargetAppQuit failed" ); } } @@ -1528,7 +1548,7 @@ BOOL inline compare_double( double a, double b ); if ( (buffer = (char *)malloc( length ))==NULL ) { - NSLog( @"sendPauseFinished: failed" ); + CMLog( @"sendPauseFinished: failed" ); return; } @@ -1542,7 +1562,7 @@ BOOL inline compare_double( double a, double b ); if ( SendBuffer( sockfd, buffer, &lengthAfter ) == -1 || lengthAfter != length ) { - NSLog( @"sendPauseFinished: failed" ); + CMLog( @"sendPauseFinished: failed" ); } free( buffer ); @@ -1568,6 +1588,9 @@ BOOL inline compare_double( double a, double b ); 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] ) { @@ -1579,7 +1602,7 @@ BOOL inline compare_double( double a, double b ); { case SIZE_8_BIT: { - [self firstSearchString8bit:ptr size:(dataSize - (ptr - data))]; + [self firstSearchString8bit:ptr size:(dataSize - (ptr - data) - 1)]; } break; } @@ -1844,35 +1867,66 @@ BOOL inline compare_double( double a, double b ); { int wait_status; - if ( ptrace( PT_ATTACH, processID, 0, 0 ) != -1 ) + NS_DURING { - if ( waitpid( processID, &wait_status, WUNTRACED ) == processID ) + if ( ptrace( PT_ATTACH, processID, 0, 0 ) != -1 ) { - if ( WIFSTOPPED(wait_status) ) + if ( waitpid( processID, &wait_status, WUNTRACED ) == processID ) { - processPaused = YES; - [self sendPauseFinished:YES]; + if ( WIFSTOPPED(wait_status) ) + { + processPaused = YES; + [self sendPauseFinished:YES]; + } + else + { + 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:@"Process couldn't be paused." fatal: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:@"Process couldn't be paused." fatal:NO]; + + switch ( errno ) + { + case ESRCH: + [self sendError:@"Could not pause target because there is no valid target to pause." fatal:NO]; + break; + + case EINVAL: + [self sendError:@"Could not pause target because a process cannot pause itself." fatal:NO]; + break; + + case EBUSY: + [self sendError:@"Could not pause target because the target is being controlled by another instance or application." fatal:NO]; + break; + + case EPERM: + [self sendError:@"Could not pause target because this type of application cannot be paused." fatal:NO]; + break; + + default: + [self sendError:@"Could not pause target because of an unknown error." fatal:NO]; + break; + } } } - else + NS_HANDLER { - NSLog( @"ERROR: process couldn't be paused" ); [self sendPauseFinished:NO]; - [self sendError:@"Process couldn't be paused." fatal:NO]; + [self sendError:[NSString stringWithFormat:@"Could not pause target because an exception (%@) was raised: %@", [localException name], [localException reason]] fatal:NO]; } + NS_ENDHANDLER } else { @@ -1961,7 +2015,7 @@ BOOL inline compare_double( double a, double b ); 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 ); } } @@ -2020,6 +2074,27 @@ BOOL inline compare_double( double a, double b ); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ +#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=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 ) { float const feps = 0.0001f; @@ -2032,4 +2107,4 @@ BOOL compare_double( double a, double b ) double const deps = 0.0000001; return deps > fabs( a - b ); -} \ No newline at end of file +}*/ \ No newline at end of file