3 * The Cheat - The legendary universal game trainer for Mac OS X.
4 * http://www.dogcows.com/chaz/wiki/TheCheat
6 * Copyright (c) 2003-2010, Charles McGarvey et al.
8 * Distributable under the terms and conditions of the 2-clause BSD
9 * license; see the file COPYING for the legal text of the license.
13 #import <Cocoa/Cocoa.h>
16 #import "CheaterTypes.h"
22 #define TC_BUFFER_SIZE (8192)
23 // used when buffers are expanded; use a multiple for 4096 because
24 // the virtual memory system uses those sizes for optimization.
26 #define TC_EPSILON (0.1)
27 // defines the accuracy for floating point comparisons
30 @interface SearchContext
: NSObject
33 * So here's the big, bad, rather ugly search context class.
34 * There is quite a bit to keep track of, as you can see.
37 TCVariableType _variableType
;
38 TCIntegerSign _integerSign
;
39 TCSearchOperator _operator
;
40 TCSearchType _searchType
;
42 // for fast access while iterating through the task loop.
45 pid_t process
; // the pid of the process being searched
46 unsigned regionCount
; // estimation of the # of regions used for progress reporting
47 VMRegion lastRegion
; // used to find the next region to search
49 Variable
*value
; // the value to compare against (TCGivenValue searches)
50 BOOL (*compareFunc
)(void const *, void const*); // comparison function
52 TCArray addresses
; // array to store hit addresses
53 TCArray values
; // parallel array to store hit values
54 TCArray regions
; // array of addresses, one for each region which contains a hit
55 TCArray perRegion
; // number of variables found for each region
56 unsigned numberOfResults
; // actual number of hits so far
58 TCArray lastAddresses
; // the addresses of variables to check
59 TCArray lastValues
; // the values to compare against (TCLastValue searches)
60 TCArray lastRegions
; // optimizes "again" searches
61 TCArray lastPerRegion
; // parallels lastRegions
63 void *buffer
; // the working buffer for reading in memory from the other app
64 unsigned bufferSize
; // size of the working buffer
67 void *valuePtr
, *lastValuePtr
;
68 TCAddress
*addressPtr
, *lastAddressPtr
;
69 TCAddress
*lastRegionPtr
;
70 unsigned *lastPerRegionPtr
;
72 int progress
; // 0-100
77 // this initializer must be used to create a context for a first-time search
78 - (id
)initWithPID
:(pid_t
)pid searchOperator
:(TCSearchOperator
)op value
:(Variable
*)val
;
79 // these initializers take data from the last search that was performed
80 - (id
)initWithLastContext
:(SearchContext
*)context searchOperator
:(TCSearchOperator
)op
;
81 - (id
)initWithLastContext
:(SearchContext
*)context searchOperator
:(TCSearchOperator
)op value
:(Variable
*)val
;
85 - (TCVariableType
)variableType
;
86 - (TCIntegerSign
)integerSign
;
87 - (TCSearchOperator
)searchOperator
;
89 - (BOOL (*)(void const *, void const *))compareFunction
;
90 - (int (*)(id
, unsigned))iterationFunction
;