[md5]. * @param Context $ctx Context. * @param string $kind plugin|theme (finding item prefix not needed; used in details). * @return bool Done. */ public static function run( array &$pkg, array $ref, Context $ctx, $kind ) { ksort( $ref, SORT_STRING ); $paths = array_keys( $ref ); $total = count( $paths ); $dir = trailingslashit( wp_normalize_path( $pkg['dir'] ) ); $item = $pkg['slug']; $base = array( 'kind' => $kind, 'name' => $pkg['name'], 'version' => $pkg['version'], ); if ( 'verify' === $pkg['phase'] ) { while ( $pkg['i'] < $total ) { $path = $paths[ $pkg['i'] ]; $pkg['i']++; $ctx->count( 'files' ); $file = $dir . $path; if ( ! is_file( $file ) ) { // A missing PHP file can break the plugin; other missing files (maps, licences) are minor. $ctx->add( 'missing', Files::is_executable( $path ) && ! in_array( $path, self::SOFT, true ) ? 'medium' : 'low', $item, $path, 'missing', $base ); $pkg['changed']++; } else { $md5 = Files::md5( $file ); if ( ! Files::matches( $file, $md5, (array) $ref[ $path ] ) ) { $soft = in_array( strtolower( $path ), self::SOFT, true ); $ctx->add( 'modified', $soft ? 'low' : Files::severity( $path ), $item, $path, $md5, $base ); if ( ! $soft ) { $pkg['changed']++; } } } if ( $ctx->out_of_time() ) { return false; } } $pkg['phase'] = $pkg['single'] ? 'done' : 'extra'; } if ( 'extra' === $pkg['phase'] ) { $extra_other = array(); foreach ( Files::walk( $dir ) as $path ) { if ( isset( $ref[ $path ] ) ) { continue; } if ( Files::is_executable( $path ) ) { $ctx->add( 'unexpected', 'high', $item, $path, Files::md5( $dir . $path ), $base ); } else { $extra_other[] = $path; } } if ( count( $extra_other ) > self::EXTRA_LIMIT ) { $ctx->add( 'unexpected-many', 'low', $item, '', (string) count( $extra_other ), $base + array( 'count' => count( $extra_other ) ) ); } else { foreach ( $extra_other as $path ) { $ctx->add( 'unexpected', Files::severity( $path ), $item, $path, Files::md5( $dir . $path ), $base ); } } $pkg['phase'] = 'done'; } // Collapse a package that is simply another build of the plugin (fork, development copy). if ( $pkg['changed'] > self::COLLAPSE_MIN && $pkg['changed'] > self::COLLAPSE_RATE * max( 1, $total ) ) { $count = Findings::count_types( $ctx->scan_id, $ctx->module, $item, array( 'modified', 'missing' ) ); Findings::remove_types( $ctx->scan_id, $ctx->module, $item, array( 'modified', 'missing' ) ); $ctx->add( 'mismatch-many', 'medium', $item, '', $pkg['version'] . ':' . $count, $base + array( 'count' => $count, 'total' => $total ) ); } return true; } }