-
Notifications
You must be signed in to change notification settings - Fork 0
/
contentplugin.cpp
226 lines (184 loc) · 5.16 KB
/
contentplugin.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
215
216
217
218
219
220
221
222
223
224
225
226
//==========================================================================
// contentplugin.h: C++ish TC/WDX plugin API implementations
//==========================================================================
// (C) 2022 Raziel Anarki, based on the official WDX guide 2.12
//--------------------------------------------------------------------------
#include "stdafx.h"
#include "dllmain.h"
#include "strutils.h"
#include "contentplugin.h"
//==========================================================================
PUBLIC
VOID PLUGINAPI ContentGetDetectString
(
LPSTR DetectString,
UINT MaxSize
)
{
StringCchCopyA(DetectString, MaxSize, ""); // return dummpy empty string
}
PUBLIC
VOID PLUGINAPI ContentSetDefaultParams
(
LPCONTENTDEFAULTPARAMS Params
)
{
if( Params->DefaultParamsSize >= sizeof ( CONTENTDEFAULTPARAMS ) )
StringCchCopyA ( DataPath, MAX_PATH, Params->DefaultIniName );
PluginInit (); // init on load
}
PUBLIC
VOID PLUGINAPI ContentPluginUnloading ()
{
PluginDone(); // unload
}
//==========================================================================
PUBLIC
VOID PLUGINAPI ContentSendStateInformation
(
StateChange StateChange,
LPSTR CurrentPath
)
{
PluginInit(); // refresh on reload
}
PUBLIC
VOID PLUGINAPI ContentSendStateInformationW
(
StateChange ChangeState,
LPWSTR CurrentPathW
)
{
PluginInit(); // refresh on reload
}
//==========================================================================
PUBLIC
FieldType PLUGINAPI ContentGetSupportedField
(
UINT FieldIndex,
LPSTR FieldName,
LPSTR FieldUnits,
UINT MaxSize
)
{
UINT32 capture_count;
pcre2_pattern_info_8 ( code, PCRE2_INFO_CAPTURECOUNT, &capture_count );
StringCchCopyA ( FieldUnits, MaxSize, "" );
if( capture_count < FieldIndex )
{
StringCchCopyA ( FieldName, MaxSize, "" );
return FieldType::None;
}
AUTOSTR(group_id, 20);
snprintf(group_id, 20, "$%d", FieldIndex);
LPSTR group_name = group_id;
UINT32 name_count, name_length;
pcre2_pattern_info_8 (code, PCRE2_INFO_NAMECOUNT, &name_count);
pcre2_pattern_info_8 (code, PCRE2_INFO_NAMEENTRYSIZE, &name_length);
PCRE2_SPTR8 name_table;
pcre2_pattern_info_8 (code, PCRE2_INFO_NAMETABLE, &name_table);
PCRE2_SPTR8 name_entry = name_table;
for( UINT32 i = 0; i < name_count; i++ )
{
INT capture_group_index = (name_entry[0] << 8) | name_entry[1];
if (capture_group_index == FieldIndex)
{
group_name = (LPSTR)(name_entry + 2);
break;
}
name_entry += name_length;
}
StringCchCopyA(FieldName, MaxSize, group_name);
return FieldType::String;
}
//==========================================================================
PUBLIC
FieldType PLUGINAPI ContentGetValue
(
LPSTR FileName,
UINT FieldIndex,
UINT UnitIndex,
LPVOID FieldData,
UINT MaxSize,
UINT Flags
)
{
LPSTR const FieldValue = (LPSTR) FieldData;
PCRE2_SIZE bufsize = MaxSize;
pcre2_match_data_8* match_data = pcre2_match_data_create_from_pattern_8 ( code, NULL );
nonstd::scope_exit ( [&] { pcre2_match_data_free_8 ( match_data ); } );
INT match_result = pcre2_match_8
(
code,
(PCRE2_SPTR8) FileName,
PCRE2_ZERO_TERMINATED,
0,
PCRE2_NO_UTF_CHECK,
match_data,
NULL
);
if( match_result < 0 )
{
if( FieldIndex == 0 )
{
pcre2_get_error_message_8 ( match_result, (PCRE2_UCHAR8*) FieldValue, bufsize );
return FieldType::Error;
}
StringCchCopyA ( FieldValue, MaxSize, "" );
return FieldType::None;
}
if (pcre2_substring_length_bynumber_8 (match_data, FieldIndex, NULL) < 0)
return FieldType::Empty;
FieldValue[0] = 0;
pcre2_substring_copy_bynumber_8 ( match_data, FieldIndex, (PCRE2_UCHAR8*) FieldValue, &bufsize );
FieldValue[bufsize] = 0;
return FieldType::String;
}
PUBLIC
VOID PLUGINAPI ContentStopGetValue
(
LPSTR FileName
)
{
return; // dummy
}
//==========================================================================
PUBLIC
FieldType PLUGINAPI ContentGetValueW
(
LPWSTR FileNameW,
UINT FieldIndex,
UINT UnitIndex,
LPVOID FieldData,
UINT MaxSize,
UINT Flags
)
{
LPWSTR const FieldValueW = (LPWSTR) FieldData;
AUTOSTR(FileName, MaxSize);
AUTOSTR(FieldValue, MaxSize);
FieldType Result = ContentGetValue
(
Narrow ( FileNameW, MaxSize, FileName ),
FieldIndex,
UnitIndex,
FieldValue,
MaxSize,
Flags
);
if (Result == FieldType::String)
{
Widen (FieldValue, MaxSize, FieldValueW);
Result = FieldType::WString;
}
return Result;
}
PUBLIC
VOID PLUGINAPI ContentStopGetValueW
(
LPWSTR FileNameW
)
{
return; // dummy
}
//==========================================================================