-// **********************************************************************
-// The Cheat - A universal game cheater for Mac OS X
-// (C) 2003-2005 Chaz McGarvey (BrokenZipper)
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 1, or (at your option)
-// any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-//
+/*
+ * The Cheat - The legendary universal game trainer for Mac OS X.
+ * http://www.brokenzipper.com/trac/wiki/TheCheat
+ *
+ * Copyright (c) 2003-2011, Charles McGarvey et al.
+ *
+ * Distributable under the terms and conditions of the 2-clause BSD
+ * license; see the file COPYING for the legal text of the license.
+ */
#import "LocalCheater.h"
- (void)getProcessList
{
NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
- NSArray *launchedApps = [workspace launchedApplications];
- unsigned i, len = [launchedApps count];
+// NSArray *launchedApps = [workspace launchedApplications];
+// unsigned i, len = [launchedApps count];
+ ProcessSerialNumber psn = {0, kNoProcess};
if ( !_processes ) {
- _processes = [[NSMutableArray alloc] initWithCapacity:len];
+ //_processes = [[NSMutableArray alloc] initWithCapacity:len];
+ _processes = [[NSMutableArray alloc] initWithCapacity:1];
}
// compile process array
- for ( i = 0; i < len; i++ ) {
- NSDictionary *application = [launchedApps objectAtIndex:i];
+// for ( i = 0; i < len; i++ ) {
+ while(/*procNotFound != */!GetNextProcess(&psn)) {
+// NSDictionary *application = [launchedApps objectAtIndex:i];
+ NSDictionary *application = (NSDictionary *)ProcessInformationCopyDictionary(&psn, kProcessDictionaryIncludeAllInformationMask);
+ void *bundlePath = [application objectForKey:@"BundlePath"];
// don't allow The Cheat to be cheated
- if ( [[application objectForKey:@"NSApplicationBundleIdentifier"] isEqualToString:[[NSBundle mainBundle] bundleIdentifier]] ) {
+// if ( [[application objectForKey:@"NSApplicationBundleIdentifier"] isEqualToString:[[NSBundle mainBundle] bundleIdentifier]] ) {
+ if ( [[application objectForKey:(NSString *)kCFBundleIdentifierKey] isEqualToString:[[NSBundle mainBundle] bundleIdentifier]] ) {
continue;
}
- Process *process = [[Process alloc] initWithName:[application objectForKey:@"NSApplicationName"]
+ /*Process *process = [[Process alloc] initWithName:[application objectForKey:@"NSApplicationName"]]
version:ApplicationVersion( [application objectForKey:@"NSApplicationPath"] )
icon:[workspace iconForFile:[application objectForKey:@"NSApplicationPath"]]
- pid:[[application objectForKey:@"NSApplicationProcessIdentifier"] intValue]];
+ pid:[[application objectForKey:@"NSApplicationProcessIdentifier"] intValue]];*/
+ Process *process = [[Process alloc] initWithName:[application objectForKey:(NSString *)kCFBundleNameKey]
+ version:ApplicationVersion( bundlePath ? bundlePath: [application objectForKey:(NSString *)kCFBundleExecutableKey] )
+ icon:[workspace iconForFile:bundlePath ? bundlePath: [application objectForKey:(NSString *)kCFBundleExecutableKey]]
+ pid:[[application objectForKey:@"pid"] intValue]];
[_processes addObject:process];
[process release];
}
-
+
// return process list
[_delegate cheater:self didFindProcesses:[NSArray arrayWithArray:_processes]];
}
}
function = [context iterationFunction];
- if ( function ) {
+ if ( function ) {
+ SearchContext *searchContext = context;
+ if (searchContext->value->_type != TCFloat && searchContext->value->_type != TCDouble)
+ {
+ bigEndianValue(searchContext->value->_value, searchContext->value);
+ }
+
_searchTask = [[ThreadedTask alloc] initWithFunction:function
context:context
delegate:self];
top = index + count;
for ( i = index; i < top; i++ ) {
Variable *var = [[Variable alloc] initWithType:[context variableType] integerSign:[context integerSign]];
+ [var setProcess:_target];
[var setAddress:*(TCAddress *)TCArrayElementAtIndex( addresses, i )];
- [var setValue:TCArrayElementAtIndex( values, i ) size:TCArrayElementSize(values)];
+ [var setValue:TCArrayElementAtIndex(values, i) size:TCArrayElementSize(values)];
[vars addObject:var];
[var release];
}
for ( i = 0; i < top; i++ ) {
Variable *variable = [variables objectAtIndex:i];
- if ( VMWriteBytes( [_target pid], [variable address], [variable value], [variable valueSize] ) ) {
+ if ([[variable process] pid] != [_target pid])
+ {
+ [variable setProcess:_target];
+ }
+
+ char buffer[variable->_size];
+ memcpy(buffer, variable->_value, variable->_size);
+ bigEndianValue(buffer, variable);
+
+ if ( VMWriteBytes( [_target pid], [variable address], buffer, [variable valueSize] ) )
+ {
successes++;
}
}
{
unsigned i, top;
char value[TC_MAX_VAR_SIZE];
- vm_size_t size;
+ mach_vm_size_t size;
top = [_watchVariables count];
for ( i = 0; i < top; i++ ) {
size = [variable valueSize];
if ( VMReadBytes( [_target pid], [variable address], value, &size ) ) {
+ bigEndianValue(value, variable);
+
// check if memory changed
- if ( memcmp( value, [variable value], size ) != 0 ) {
+ if (memcmp(value, variable->_value, size) != 0)
+ {
[variable setValue:value];
// inform delegate of the change
[_delegate cheater:self variableAtIndex:_watchRange.location+i didChangeTo:variable];