X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=Variable.m;h=536d94f9f4af29b54c81994fea11cfdfe86ae357;hb=refs%2Fheads%2Fmaster;hp=bb3c59e90542e0da750acdbba8649277b36f7bf7;hpb=d27548f80fe411fda2ee69c74a24eab4292267e9;p=chaz%2Fthecheat diff --git a/Variable.m b/Variable.m index bb3c59e..536d94f 100644 --- a/Variable.m +++ b/Variable.m @@ -1,26 +1,16 @@ -// ********************************************************************** -// 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 "Variable.h" - @interface Variable ( PrivateAPI ) - (void)_setType:(TCVariableType)type; @@ -53,6 +43,27 @@ return self; } +- (void)setProcess:(Process *)newProcess +{ + if (process != newProcess && [newProcess pid] > 0) + { + _isEmulated = [newProcess isEmulated]; + + [newProcess retain]; + [process release]; + process = newProcess; + } +} + +- (Process *)process +{ + return process; +} + +- (BOOL)isEmulated +{ + return _isEmulated; +} - (void)dealloc { @@ -73,7 +84,48 @@ [coder decodeValueOfObjCType:@encode(TCVariableType) at:&_type]; [coder decodeValueOfObjCType:@encode(TCIntegerSign) at:&_integerSign]; [coder decodeValueOfObjCType:@encode(TCAddress) at:&_address]; - [self setValue:[coder decodeBytesWithReturnedLength:&_size]]; + + void *value = [coder decodeBytesWithReturnedLength:&_size]; + + if (_type == TCString || _type == TCInt8) + { + [self setValue:value]; + } + else if (_type == TCInt16) + { + int16_t newVariable = CFSwapInt16BigToHost(*((int16_t *)value)); + [self setValue:&newVariable]; + } + else if (_type == TCInt32) + { + int32_t newVariable = CFSwapInt32BigToHost(*((int32_t *)value)); + [self setValue:&newVariable]; + } + else if (_type == TCInt64) + { + int64_t newVariable = CFSwapInt64BigToHost(*((int64_t *)value)); + [self setValue:&newVariable]; + } + else if (_type == TCFloat) + { +#ifdef __LITTLE_ENDIAN__ + CFSwappedFloat32 newVariable = CFConvertFloat32HostToSwapped(*((float *)value)); + [self setValue:&(newVariable.v)]; + +#else + [self setValue:value]; +#endif + } + else if (_type == TCDouble) + { +#ifdef __LITTLE_ENDIAN__ + CFSwappedFloat64 newVariable = CFConvertDoubleHostToSwapped(*((double *)value)); + [self setValue:&(newVariable.v)]; +#else + [self setValue:value]; +#endif + } + [coder decodeValueOfObjCType:@encode(BOOL) at:&_isValueValid]; [coder decodeValueOfObjCType:@encode(BOOL) at:&_enabled]; [coder decodeValueOfObjCType:@encode(int) at:&_tag]; @@ -86,7 +138,45 @@ [coder encodeValueOfObjCType:@encode(TCVariableType) at:&_type]; [coder encodeValueOfObjCType:@encode(TCIntegerSign) at:&_integerSign]; [coder encodeValueOfObjCType:@encode(TCAddress) at:&_address]; - [coder encodeBytes:_value length:_size]; + + if (_type == TCString || _type == TCInt8) + { + [coder encodeBytes:_value length:_size]; + } + else if (_type == TCInt16) + { + int16_t newVariable = CFSwapInt16HostToBig(*((int16_t *)_value)); + [coder encodeBytes:&newVariable length:_size]; + } + else if (_type == TCInt32) + { + int32_t newVariable = CFSwapInt32HostToBig(*((int32_t *)_value)); + [coder encodeBytes:&newVariable length:_size]; + } + else if (_type == TCInt64) + { + int64_t newVariable = CFSwapInt64HostToBig(*((int64_t *)_value)); + [coder encodeBytes:&newVariable length:_size]; + } + else if (_type == TCFloat) + { +#ifdef __LITTLE_ENDIAN__ + CFSwappedFloat32 newVariable = CFConvertFloat32HostToSwapped(*((float *)_value)); + [coder encodeBytes:&newVariable length:_size]; +#else + [coder encodeBytes:&_value length:_size]; +#endif + } + else if (_type == TCDouble) + { +#ifdef __LITTLE_ENDIAN__ + CFSwappedFloat64 newVariable = CFConvertDoubleHostToSwapped(*((double *)_value)); + [coder encodeBytes:&newVariable length:_size]; +#else + [coder encodeBytes:_value length:_size]; +#endif + } + [coder encodeValueOfObjCType:@encode(BOOL) at:&_isValueValid]; [coder encodeValueOfObjCType:@encode(BOOL) at:&_enabled]; [coder encodeValueOfObjCType:@encode(int) at:&_tag]; @@ -175,7 +265,8 @@ - (NSString *)addressString { - return [NSString stringWithFormat:@"%0.8X", _address]; +// return [NSString stringWithFormat:@"%0.8X", _address]; + return [NSString stringWithFormat:(_address & 0xffffffff00000000ULL) ? @"%0.16qX": @"%0.8X", _address]; } - (BOOL)setAddressString:(NSString *)string @@ -183,7 +274,11 @@ NSScanner *scanner = [NSScanner scannerWithString:string]; TCAddress address; +#if MAC_OS_X_VERSION_10_5 <= MAC_OS_X_VERSION_MAX_ALLOWED + if ( [scanner scanHexLongLong:(unsigned long long *)(&address)] ) { +#else if ( [scanner scanHexInt:(unsigned *)(&address)] ) { +#endif [self setAddress:address]; return YES; } @@ -269,7 +364,10 @@ case TCInt32: { SInt32 value; - if ( [scanner scanInt:(int *)(&value)] ) { +// if ( [scanner scanInt:(int *)(&value)] ) { + int integer; + if ( [scanner scanInt:&integer] ) { + value = integer; [self setValue:&value]; } break; @@ -321,6 +419,39 @@ return [self isValueValid]; } +// this only converts the byte order of the value at buffer if the process is running under rosetta on an intel mac +// floats and double's byte ordering should not be changed when searching for values because they may be swapped to '0.0' +void bigEndianValue(void *buffer, Variable *variable) +{ + if (variable->_isEmulated) + { + if (variable->_type == TCInt16) + { + int16_t newValue = CFSwapInt16HostToBig(*((int16_t *)buffer)); + memcpy(buffer, &newValue, sizeof(int16_t)); + } + else if (variable->_type == TCInt32) + { + int32_t newValue = CFSwapInt32HostToBig(*((int32_t *)buffer)); + memcpy(buffer, &newValue, sizeof(int32_t)); + } + else if (variable->_type == TCInt64) + { + int64_t newValue = CFSwapInt64HostToBig(*((int64_t *)buffer)); + memcpy(buffer, &newValue, sizeof(int64_t)); + } + else if (variable->_type == TCFloat) + { + CFSwappedFloat32 newValue = CFConvertFloat32HostToSwapped(*((float *)buffer)); + memcpy(buffer, &(newValue.v), sizeof(float)); + } + else if (variable->_type == TCDouble) + { + CFSwappedFloat64 newValue = CFConvertDoubleHostToSwapped(*((double *)buffer)); + memcpy(buffer, &(newValue.v), sizeof(double)); + } + } +} - (unsigned)valueSize { @@ -344,12 +475,20 @@ } +#if MAC_OS_X_VERSION_10_5 <= MAC_OS_X_VERSION_MAX_ALLOWED +- (NSInteger)tag +#else - (int)tag +#endif { return _tag; } +#if MAC_OS_X_VERSION_10_5 <= MAC_OS_X_VERSION_MAX_ALLOWED +- (void)setTag:(NSInteger)tag +#else - (void)setTag:(int)tag +#endif { _tag = tag; }