source: trunk/Cocoa/F-Script Anywhere/Source/SCPatch/SCPatchController/SCPatchContext.cpp@ 593

Last change on this file since 593 was 153, checked in by Nicholas Riley, 21 years ago

Integrates SCPatch and mach_inject; unfinished, buggy.

File size: 2.9 KB
RevLine 
[153]1#include "SCPatchContext.h"
2
3/* -------------------------------------------------------------------------------- */
4bool operator< (const MacPSN& x, const MacPSN& y)
5{
6 if(x.psn.highLongOfPSN < y.psn.highLongOfPSN)
7 return true;
8 else if(x.psn.highLongOfPSN == y.psn.highLongOfPSN)
9 return (x.psn.lowLongOfPSN < y.psn.lowLongOfPSN);
10 else
11 return false;
12}
13
14/* -------------------------------------------------------------------------------- */
15bool operator==(const MacPSN& x, const MacPSN& y)
16{
17 return (x.psn.highLongOfPSN == y.psn.highLongOfPSN &&
18 x.psn.lowLongOfPSN == y.psn.lowLongOfPSN);
19}
20
21/* -------------------------------------------------------------------------------- */
22SCPatchContext::SCPatchContext(ProcessSerialNumber *inPSN, SInt32 inPID, OSType inCreator)
23{
24 psn = *inPSN;
25 pid = inPID;
26 path = NULL;
27 name = NULL;
28 creator = inCreator;
29 flags = 0;
30}
31
32/* -------------------------------------------------------------------------------- */
33SCPatchContext::SCPatchContext(const SCPatchContext &toCopy)
34{
35 psn = toCopy.psn;
36 pid = toCopy.pid;
37 flags = toCopy.flags;
38 creator = toCopy.creator;
39 if((path = toCopy.path) != NULL)
40 CFRetain(path);
41 if((name = toCopy.name) != NULL)
42 CFRetain(name);
43}
44
45/* -------------------------------------------------------------------------------- */
46/* -------------------------------------------------------------------------------- */
47SCPatchContextList::SCPatchContextList(void) : contexts()
48{
49}
50
51/* -------------------------------------------------------------------------------- */
52SCPatchContextList::~SCPatchContextList(void)
53{
54}
55
56/* -------------------------------------------------------------------------------- */
57SCPatchContextRef SCPatchContextList::NewContext(ProcessSerialNumber *inPSN,
58 SInt32 inPID, OSType inCreator)
59{
60 SCPatchContextRef zeroResult = { 0 };
61 SCPatchContextRef result;
62
63 try
64 {
65 MacPSN macPSN(inPSN);
66 SCPatchContext patchContext(inPSN, inPID, inCreator);
67 SCPatchContextPair newContext(macPSN, patchContext);
68
69 contexts.insert(newContext);
70 result = *inPSN;
71 }
72 catch(...)
73 {
74 result = zeroResult;
75 }
76 return result;
77}
78
79/* -------------------------------------------------------------------------------- */
80SCPatchContext *SCPatchContextList::GetContext(ProcessSerialNumber *inPSN)
81{
82 SCPatchContextIterator iter;
83
84 iter = contexts.find(MacPSN(inPSN));
85 if(iter != contexts.end())
86 return &(*iter).second;
87 else
88 return NULL;
89}
90
91/* -------------------------------------------------------------------------------- */
92SCPatchContext *SCPatchContextList::GetContext(OSType inCreator)
93{
94 SCPatchContextIterator iter;
95
96 for(iter = contexts.begin(); iter != contexts.end(); iter++)
97 if(iter->second.creator == inCreator)
98 return &(*iter).second;
99 return NULL;
100}
101
102/* -------------------------------------------------------------------------------- */
103void SCPatchContextList::DeleteContext(ProcessSerialNumber *inPSN)
104{
105 contexts.erase(MacPSN(inPSN));
106}
Note: See TracBrowser for help on using the repository browser.