Diff
8 years ago
dashboard
7 years ago
rest-api
7 years ago
.htaccess
7 years ago
Diff.php
14 years ago
GeoLite2-Country.mmdb
7 years ago
IPTraf.php
8 years ago
IPTrafList.php
7 years ago
WFLSPHP52Compatability.php
7 years ago
compat.php
8 years ago
conntest.php
7 years ago
cronview.php
8 years ago
dbview.php
8 years ago
diffResult.php
8 years ago
email_genericAlert.php
7 years ago
email_newIssues.php
7 years ago
email_unlockRequest.php
8 years ago
email_unsubscribeRequest.php
7 years ago
flags.php
7 years ago
live_activity.php
8 years ago
menu_dashboard.php
7 years ago
menu_dashboard_options.php
7 years ago
menu_firewall.php
7 years ago
menu_firewall_blocking.php
7 years ago
menu_firewall_blocking_options.php
8 years ago
menu_firewall_waf.php
7 years ago
menu_firewall_waf_options.php
7 years ago
menu_options.php
7 years ago
menu_scanner.php
7 years ago
menu_scanner_credentials.php
8 years ago
menu_scanner_options.php
8 years ago
menu_support.php
7 years ago
menu_tools.php
7 years ago
menu_tools_diagnostic.php
7 years ago
menu_tools_importExport.php
7 years ago
menu_tools_livetraffic.php
7 years ago
menu_tools_twoFactor.php
7 years ago
menu_tools_whois.php
8 years ago
menu_wordfence_central.php
7 years ago
noc1.key
7 years ago
sysinfo.php
8 years ago
unknownFiles.php
8 years ago
viewFullActivityLog.php
8 years ago
wf503.php
7 years ago
wfAPI.php
7 years ago
wfActivityReport.php
7 years ago
wfAdminNoticeQueue.php
8 years ago
wfArray.php
7 years ago
wfBrowscap.php
8 years ago
wfBrowscapCache.php
7 years ago
wfBulkCountries.php
7 years ago
wfCache.php
9 years ago
wfCentralAPI.php
7 years ago
wfConfig.php
7 years ago
wfCrawl.php
8 years ago
wfCredentialsController.php
7 years ago
wfCrypt.php
7 years ago
wfDB.php
7 years ago
wfDashboard.php
7 years ago
wfDateLocalization.php
8 years ago
wfDiagnostic.php
7 years ago
wfDict.php
8 years ago
wfDirectoryIterator.php
7 years ago
wfHelperBin.php
11 years ago
wfHelperString.php
11 years ago
wfIPWhitelist.php
7 years ago
wfImportExportController.php
7 years ago
wfIssues.php
7 years ago
wfJWT.php
7 years ago
wfLockedOut.php
7 years ago
wfLog.php
7 years ago
wfMD5BloomFilter.php
8 years ago
wfModuleController.php
7 years ago
wfNotification.php
8 years ago
wfOnboardingController.php
7 years ago
wfPersistenceController.php
8 years ago
wfRESTAPI.php
7 years ago
wfScan.php
7 years ago
wfScanEngine.php
7 years ago
wfSchema.php
7 years ago
wfStyle.php
7 years ago
wfSupportController.php
7 years ago
wfUnlockMsg.php
7 years ago
wfUpdateCheck.php
8 years ago
wfUtils.php
7 years ago
wfVersionCheckController.php
8 years ago
wfView.php
10 years ago
wfViewResult.php
8 years ago
wordfenceClass.php
7 years ago
wordfenceConstants.php
7 years ago
wordfenceHash.php
7 years ago
wordfenceScanner.php
7 years ago
wordfenceURLHoover.php
7 years ago
wfHelperBin.php
78 lines
| 1 | <?php |
| 2 | |
| 3 | class wfHelperBin { |
| 4 | |
| 5 | /** |
| 6 | * @param string $bin1 |
| 7 | * @param string $bin2 |
| 8 | * @return mixed |
| 9 | */ |
| 10 | public static function addbin2bin($bin1, $bin2) { |
| 11 | if (strlen($bin1) % 4 != 0) { |
| 12 | $bin1 = str_repeat("\0", 4 - (strlen($bin1) % 4)) . $bin1; |
| 13 | } |
| 14 | if (strlen($bin2) % 4 != 0) { |
| 15 | $bin2 = str_repeat("\0", 4 - (strlen($bin2) % 4)) . $bin2; |
| 16 | } |
| 17 | |
| 18 | $bin1_ints = array_reverse(array_values(unpack('N*', $bin1))); |
| 19 | $bin2_ints = array_reverse(array_values(unpack('N*', $bin2))); |
| 20 | $return = array(); |
| 21 | $carries = 0; |
| 22 | for ($i=0; $i < max(count($bin1_ints), count($bin2_ints)); $i++) { |
| 23 | $int1 = array_key_exists($i, $bin1_ints) ? $bin1_ints[$i] : 0; |
| 24 | $int2 = array_key_exists($i, $bin2_ints) ? $bin2_ints[$i] : 0; |
| 25 | $val = $int1 + $int2 + $carries; |
| 26 | if ($carries > 0) { |
| 27 | $carries = 0; |
| 28 | } |
| 29 | if ($val >= 0x100000000) { |
| 30 | $val -= 0x100000000; |
| 31 | $carries++; |
| 32 | } |
| 33 | $return[] = $val; |
| 34 | } |
| 35 | if ($carries) { |
| 36 | $return[] += $carries; |
| 37 | } |
| 38 | $return = array_reverse($return); |
| 39 | array_unshift($return, 'N*'); |
| 40 | $return = call_user_func_array('pack', $return); |
| 41 | $return = ltrim($return, "\x00"); |
| 42 | return strlen($return) == 0 ? "\x00" : $return; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Convert binary string to the 10101's representation. |
| 47 | * |
| 48 | * @param string $string |
| 49 | * @return string |
| 50 | */ |
| 51 | public static function bin2str($string) { |
| 52 | $return = ''; |
| 53 | for ($i = 0; $i < strlen($string); $i++) { |
| 54 | $return .= str_pad(decbin(ord($string[$i])), 8, '0', STR_PAD_LEFT); |
| 55 | } |
| 56 | $return = ltrim($return, '0'); |
| 57 | return strlen($return) == 0 ? '0' : $return; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Convert 10101's representation back to the binary data. |
| 62 | * |
| 63 | * @param string $string |
| 64 | * @return string |
| 65 | */ |
| 66 | public static function str2bin($string) { |
| 67 | if (strlen($string) % 32 > 0) { |
| 68 | $string = str_repeat('0', 32 - (strlen($string) % 32)) . $string; |
| 69 | } |
| 70 | $ints = str_split($string, 32); |
| 71 | $return = ''; |
| 72 | foreach ($ints as $int) { |
| 73 | $return .= pack('N', bindec($int)); |
| 74 | } |
| 75 | $return = ltrim($return, "\0"); |
| 76 | return strlen($return) == 0 ? "\0" : $return; |
| 77 | } |
| 78 | } |