-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcplugin.cpp
214 lines (184 loc) · 4.55 KB
/
cplugin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
//setlocale//
#ifdef _MSC_VER
#if _MSC_VER >= 1400
#pragma setlocale("japanese")
#endif
#endif
//setlocale end//
/*
* csaori.cpp
*
* written by Ukiya http://ukiya.sakura.ne.jp/
* based by Mr.EBISAWA "gethwnd.dll"
*/
#ifdef _MSC_VER
#pragma warning( disable : 4786 )
#pragma warning( disable : 4996 )
#endif
#include "cplugin.h"
//////////WINDOWS DEFINE///////////////////////////
#ifdef _WINDOWS
#ifdef _DEBUG
#include <crtdbg.h>
#define new new( _NORMAL_BLOCK, __FILE__, __LINE__)
#endif
#endif
///////////////////////////////////////////////////
const string_t& CPLUGIN::s_saori_version(void) const
{
static string_t s = L"PLUGIN/2.0";
return s;
}
const string_t& CPLUGIN::s_saori_def(void) const
{
static string_t s = L" PLUGIN/";
return s;
}
const string_t& CPLUGIN::s_saori_argument(void) const
{
static string_t s = L"Reference";
return s;
}
const string_t& CPLUGIN::s_saori_value(void) const
{
static string_t s = L"Reference";
return s;
}
const string_t& CPLUGIN::s_saori_result(void) const
{
static string_t s = L"Script";
return s;
}
void CPLUGIN::exec_before(const CSAORIInput& in,CSAORIOutput& out)
{
//----------変数群初期化----------
script.erase();
script_option.erase();
event.erase();
event_option.erase();
target.erase();
marker.erase();
security_level.erase();
language.erase();
map_strpair::const_iterator itr = in.opts.find(L"Language");
if ( itr != in.opts.end() ) {
language = itr->second;
}
sender.erase();
itr = in.opts.find(L"Sender");
if ( itr != in.opts.end() ) {
sender = itr->second;
}
//----------ゴーストリスト更新----------
if ( in.args.size() >= 5 ) {
if ( wcsicmp(in.id.c_str(),L"OnGhostBoot") == 0 || wcsicmp(in.id.c_str(),L"OnGhostInfoUpdate") == 0 ) {
string_t path = in.args[4];
ghost_map_type::iterator itr = ghost_map.find(path);
SAORI_FUNC::CCriticalSectionLock lock(sstp_thread_lock);
CGhostInfo *pGI;
if ( itr != ghost_map.end() ) {
pGI = &(itr->second);
}
else {
pGI = &(ghost_map[path]);
}
pGI->hwnd = reinterpret_cast<void*>(wcstoul(in.args[0].c_str(),NULL,10));
pGI->name = in.args[1];
pGI->shell_name = in.args[2];
pGI->id = in.args[3];
pGI->path = path;
if ( in.args.size() >= 6 ) {
pGI->shell_path = in.args[5];
}
else {
pGI->shell_path.erase();
}
}
else if ( wcsicmp(in.id.c_str(),L"OnGhostExit") == 0 ) {
string_t path = in.args[4];
SAORI_FUNC::CCriticalSectionLock lock(sstp_thread_lock);
ghost_map_type::iterator itr = ghost_map.find(path);
if ( itr != ghost_map.end() ) {
ghost_map.erase(itr);
}
}
}
}
void CPLUGIN::exec_after(const CSAORIInput& in,CSAORIOutput& out)
{
//----------変数群をヘッダに適用----------
if ( script.length() ) {
out.result = script;
}
if ( script_option.length() ) {
out.opts[L"ScriptOption"] = script_option;
}
if ( event.length() ) {
out.opts[L"Event"] = event;
}
if ( event_option.length() ) {
out.opts[L"EventOption"] = event_option;
}
if ( target.length() ) {
out.opts[L"Target"] = target;
}
if ( marker.length() ) {
out.opts[L"Marker"] = marker;
}
if ( security_level.length() ) {
out.opts[L"SecurityLevel"] = security_level;
}
}
void CPLUGIN::send_sstp(const std::string &str,void* hwnd)
{
if ( ! hwnd ) {
SAORI_FUNC::CCriticalSectionLock lock(sstp_thread_lock);
DWORD result;
COPYDATASTRUCT c;
c.dwData = 9801;
c.cbData = str.size();
c.lpData = const_cast<char*>(str.c_str());
for ( ghost_map_type::iterator itr = ghost_map.begin() ;
itr != ghost_map.end() ; ++itr ) {
hwnd = itr->second.hwnd;
::SendMessageTimeout(reinterpret_cast<HWND>(hwnd),
WM_COPYDATA,
reinterpret_cast<WPARAM>(hwnd),
reinterpret_cast<LPARAM>(&c),
SMTO_ABORTIFHUNG,1000,&result);
}
}
else {
DWORD result;
COPYDATASTRUCT c;
c.dwData = 9801;
c.cbData = str.size();
c.lpData = const_cast<char*>(str.c_str());
::SendMessageTimeout(reinterpret_cast<HWND>(hwnd),
WM_COPYDATA,
reinterpret_cast<WPARAM>(hwnd),
reinterpret_cast<LPARAM>(&c),
SMTO_ABORTIFHUNG,1000,&result);
}
}
bool CPLUGIN::load()
{
return true; //NOOP
}
bool CPLUGIN::unload()
{
return true; //NOOP
}
void CPLUGIN::exec(const CSAORIInput &in, CSAORIOutput &out)
{
return; //NOOP
}
//CreateInstanceはそれぞれが定義してください。
/*
#ifndef CUSTOM_CREATE_INSTANCE
CSAORIBase* CreateInstance(void)
{
return new CPLUGIN();
}
#endif //CUSTOM_CREATE_INSTANCE
*/