PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.6.0
Defender Security – Malware Scanner, Login Security & Firewall v5.6.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / vendor / thecodingmachine / safe / lib / special_cases.php

special_cases.php in Defender Security – Malware Scanner, Login Security & Firewall 5.6.0, at vendor/thecodingmachine/safe/lib/special_cases.php

242 lines 8.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * This file contains all the functions that could not be dealt with automatically using the code generator.
4 * If you add a function in this list, do not forget to add it in the generator/config/specialCasesFunctions.php
5 *
6 */
7
8 namespace Safe;
9
10 use Safe\Exceptions\SocketsException;
11 use const PREG_NO_ERROR;
12 use Safe\Exceptions\ApcException;
13 use Safe\Exceptions\ApcuException;
14 use Safe\Exceptions\JsonException;
15 use Safe\Exceptions\OpensslException;
16 use Safe\Exceptions\PcreException;
17
18 /**
19 * Wrapper for json_decode that throws when an error occurs.
20 *
21 * @param string $json JSON data to parse
22 * @param bool $assoc When true, returned objects will be converted
23 * into associative arrays.
24 * @param int $depth User specified recursion depth.
25 * @param int $options Bitmask of JSON decode options.
26 *
27 * @return mixed
28 * @throws JsonException if the JSON cannot be decoded.
29 * @link http://www.php.net/manual/en/function.json-decode.php
30 */
31 function json_decode(string $json, bool $assoc = false, int $depth = 512, int $options = 0)
32 {
33 $data = \json_decode($json, $assoc, $depth, $options);
34 if (JSON_ERROR_NONE !== json_last_error()) {
35 throw JsonException::createFromPhpError();
36 }
37 return $data;
38 }
39
40
41 /**
42 * Fetchs a stored variable from the cache.
43 *
44 * @param mixed $key The key used to store the value (with
45 * apc_store). If an array is passed then each
46 * element is fetched and returned.
47 * @return mixed The stored variable or array of variables on success; FALSE on failure
48 * @throws ApcException
49 *
50 */
51 function apc_fetch($key)
52 {
53 error_clear_last();
54 $result = \apc_fetch($key, $success);
55 if ($success === false) {
56 throw ApcException::createFromPhpError();
57 }
58 return $result;
59 }
60
61 /**
62 * Fetchs an entry from the cache.
63 *
64 * @param string|string[] $key The key used to store the value (with
65 * apcu_store). If an array is passed then each
66 * element is fetched and returned.
67 * @return mixed The stored variable or array of variables on success
68 * @throws ApcuException
69 *
70 */
71 function apcu_fetch($key)
72 {
73 error_clear_last();
74 $result = \apcu_fetch($key, $success);
75 if ($success === false) {
76 throw ApcuException::createFromPhpError();
77 }
78 return $result;
79 }
80
81 /**
82 * Searches subject for matches to
83 * pattern and replaces them with
84 * replacement.
85 *
86 * @param mixed $pattern The pattern to search for. It can be either a string or an array with
87 * strings.
88 *
89 * Several PCRE modifiers
90 * are also available.
91 * @param mixed $replacement The string or an array with strings to replace. If this parameter is a
92 * string and the pattern parameter is an array,
93 * all patterns will be replaced by that string. If both
94 * pattern and replacement
95 * parameters are arrays, each pattern will be
96 * replaced by the replacement counterpart. If
97 * there are fewer elements in the replacement
98 * array than in the pattern array, any extra
99 * patterns will be replaced by an empty string.
100 *
101 * replacement may contain references of the form
102 * \\n or
103 * $n, with the latter form
104 * being the preferred one. Every such reference will be replaced by the text
105 * captured by the n'th parenthesized pattern.
106 * n can be from 0 to 99, and
107 * \\0 or $0 refers to the text matched
108 * by the whole pattern. Opening parentheses are counted from left to right
109 * (starting from 1) to obtain the number of the capturing subpattern.
110 * To use backslash in replacement, it must be doubled
111 * ("\\\\" PHP string).
112 *
113 * When working with a replacement pattern where a backreference is
114 * immediately followed by another number (i.e.: placing a literal number
115 * immediately after a matched pattern), you cannot use the familiar
116 * \\1 notation for your backreference.
117 * \\11, for example, would confuse
118 * preg_replace since it does not know whether you
119 * want the \\1 backreference followed by a literal
120 * 1, or the \\11 backreference
121 * followed by nothing. In this case the solution is to use
122 * ${1}1. This creates an isolated
123 * $1 backreference, leaving the 1
124 * as a literal.
125 *
126 * When using the deprecated e modifier, this function escapes
127 * some characters (namely ', ",
128 * \ and NULL) in the strings that replace the
129 * backreferences. This is done to ensure that no syntax errors arise
130 * from backreference usage with either single or double quotes (e.g.
131 * 'strlen(\'$1\')+strlen("$2")'). Make sure you are
132 * aware of PHP's string
133 * syntax to know exactly how the interpreted string will look.
134 * @param string|array|string[] $subject The string or an array with strings to search and replace.
135 *
136 * If subject is an array, then the search and
137 * replace is performed on every entry of subject,
138 * and the return value is an array as well.
139 * @param int $limit The maximum possible replacements for each pattern in each
140 * subject string. Defaults to
141 * -1 (no limit).
142 * @param int $count If specified, this variable will be filled with the number of
143 * replacements done.
144 * @return string|array|string[] preg_replace returns an array if the
145 * subject parameter is an array, or a string
146 * otherwise.
147 *
148 * If matches are found, the new subject will
149 * be returned, otherwise subject will be
150 * returned unchanged.
151 *
152 * @throws PcreException
153 *
154 */
155 function preg_replace($pattern, $replacement, $subject, int $limit = -1, int &$count = null)
156 {
157 error_clear_last();
158 $result = \preg_replace($pattern, $replacement, $subject, $limit, $count);
159 if (preg_last_error() !== PREG_NO_ERROR || $result === null) {
160 throw PcreException::createFromPhpError();
161 }
162 return $result;
163 }
164
165 /**
166 * @param resource|null $dir_handle
167 * @return string|false
168 * @deprecated
169 * This function is only in safe because the php documentation is wrong
170 */
171 function readdir($dir_handle = null)
172 {
173 if ($dir_handle !== null) {
174 $result = \readdir($dir_handle);
175 } else {
176 $result = \readdir();
177 }
178 return $result;
179 }
180
181 /**
182 * Encrypts given data with given method and key, returns a raw
183 * or base64 encoded string
184 *
185 * @param string $data The plaintext message data to be encrypted.
186 * @param string $method The cipher method. For a list of available cipher methods, use openssl_get_cipher_methods.
187 * @param string $key The key.
188 * @param int $options options is a bitwise disjunction of the flags
189 * OPENSSL_RAW_DATA and
190 * OPENSSL_ZERO_PADDING.
191 * @param string $iv A non-NULL Initialization Vector.
192 * @param string $tag The authentication tag passed by reference when using AEAD cipher mode (GCM or CCM).
193 * @param string $aad Additional authentication data.
194 * @param int $tag_length The length of the authentication tag. Its value can be between 4 and 16 for GCM mode.
195 * @return string Returns the encrypted string.
196 * @throws OpensslException
197 *
198 */
199 function openssl_encrypt(string $data, string $method, string $key, int $options = 0, string $iv = "", string &$tag = "", string $aad = "", int $tag_length = 16): string
200 {
201 error_clear_last();
202 // The $tag parameter is handled in a weird way by openssl_encrypt. It cannot be provided unless encoding is AEAD
203 if (func_num_args() <= 5) {
204 $result = \openssl_encrypt($data, $method, $key, $options, $iv);
205 } else {
206 $result = \openssl_encrypt($data, $method, $key, $options, $iv, $tag, $aad, $tag_length);
207 }
208 if ($result === false) {
209 throw OpensslException::createFromPhpError();
210 }
211 return $result;
212 }
213
214 /**
215 * The function socket_write writes to the
216 * socket from the given
217 * buffer.
218 *
219 * @param resource $socket
220 * @param string $buffer The buffer to be written.
221 * @param int $length The optional parameter length can specify an
222 * alternate length of bytes written to the socket. If this length is
223 * greater than the buffer length, it is silently truncated to the length
224 * of the buffer.
225 * @return int Returns the number of bytes successfully written to the socket.
226 * The error code can be retrieved with
227 * socket_last_error. This code may be passed to
228 * socket_strerror to get a textual explanation of the
229 * error.
230 * @throws SocketsException
231 *
232 */
233 function socket_write($socket, string $buffer, int $length = 0): int
234 {
235 error_clear_last();
236 $result = $length === 0 ? \socket_write($socket, $buffer) : \socket_write($socket, $buffer, $length);
237 if ($result === false) {
238 throw SocketsException::createFromPhpError();
239 }
240 return $result;
241 }
242