5 // Created by Chaz McGarvey on 12/4/04.
6 // Copyright 2004 Chaz McGarvey. All rights reserved.
9 #import <Cocoa/Cocoa.h>
12 #import "CheaterTypes.h"
18 #define TC_BUFFER_SIZE (8192)
19 // used when buffers are expanded; use a multiple for 4096 because
20 // the virtual memory system uses those sizes for optimization.
22 #define TC_EPSILON (0.1)
23 // defines the accuracy for floating point comparisons
26 @interface SearchContext
: NSObject
29 * So here's the big, bad, rather ugly search context class.
30 * There is quite a bit to keep track of, as you can see.
33 TCVariableType _variableType
;
34 TCIntegerSign _integerSign
;
35 TCSearchOperator _operator
;
36 TCSearchType _searchType
;
38 // for fast access while iterating through the task loop.
41 pid_t process
; // the pid of the process being searched
42 unsigned regionCount
; // estimation of the # of regions used for progress reporting
43 VMRegion lastRegion
; // used to find the next region to search
45 Variable
*value
; // the value to compare against (TCGivenValue searches)
46 BOOL (*compareFunc
)(void const *, void const*); // comparison function
48 TCArray addresses
; // array to store hit addresses
49 TCArray values
; // parallel array to store hit values
50 TCArray regions
; // array of addresses, one for each region which contains a hit
51 TCArray perRegion
; // number of variables found for each region
52 unsigned numberOfResults
; // actual number of hits so far
54 TCArray lastAddresses
; // the addresses of variables to check
55 TCArray lastValues
; // the values to compare against (TCLastValue searches)
56 TCArray lastRegions
; // optimizes "again" searches
57 TCArray lastPerRegion
; // parallels lastRegions
59 void *buffer
; // the working buffer for reading in memory from the other app
60 unsigned bufferSize
; // size of the working buffer
63 void *valuePtr
, *lastValuePtr
;
64 TCAddress
*addressPtr
, *lastAddressPtr
;
65 TCAddress
*lastRegionPtr
;
66 unsigned *lastPerRegionPtr
;
68 int progress
; // 0-100
73 // this initializer must be used to create a context for a first-time search
74 - (id
)initWithPID
:(pid_t
)pid searchOperator
:(TCSearchOperator
)op value
:(Variable
*)val
;
75 // these initializers take data from the last search that was performed
76 - (id
)initWithLastContext
:(SearchContext
*)context searchOperator
:(TCSearchOperator
)op
;
77 - (id
)initWithLastContext
:(SearchContext
*)context searchOperator
:(TCSearchOperator
)op value
:(Variable
*)val
;
81 - (TCVariableType
)variableType
;
82 - (TCIntegerSign
)integerSign
;
83 - (TCSearchOperator
)searchOperator
;
85 - (BOOL (*)(void const *, void const *))compareFunction
;
86 - (int (*)(id
, unsigned))iterationFunction
;