2018-06-30 17:01:23 -06:00
|
|
|
#!/usr/bin/perl
|
2021-06-18 16:21:23 -06:00
|
|
|
|
2024-10-18 00:41:59 -06:00
|
|
|
# Copyright (C) 2005-2024 Giorgio Maone <https://maone.net>
|
2021-06-18 16:21:23 -06:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2018-06-30 17:01:23 -06:00
|
|
|
use strict;
|
|
|
|
|
|
|
|
require LWP::UserAgent;
|
|
|
|
use LWP::Simple;
|
2018-10-13 02:34:18 -06:00
|
|
|
use Regexp::List;
|
2018-06-30 17:01:23 -06:00
|
|
|
use File::stat;
|
|
|
|
use File::Basename;
|
|
|
|
use List::MoreUtils qw(uniq);
|
|
|
|
|
2018-08-18 03:38:39 -06:00
|
|
|
my $HTML_ATOMS_URL = "https://hg.mozilla.org/mozilla-central/raw-file/tip/xpcom/ds/StaticAtoms.py";
|
2018-06-30 17:01:23 -06:00
|
|
|
|
|
|
|
my $HERE = dirname($0);
|
2018-07-03 09:36:36 -06:00
|
|
|
my $SOURCE_FILE = "$HERE/../src/xss/InjectionChecker.js";
|
2018-06-30 17:01:23 -06:00
|
|
|
|
|
|
|
sub create_re
|
|
|
|
{
|
|
|
|
my $cache = "$HERE/html5_events.re";
|
2018-08-18 03:38:39 -06:00
|
|
|
my $archive = "$HERE/html5_events_archive.txt";
|
2018-10-13 02:34:18 -06:00
|
|
|
|
2018-06-30 17:01:23 -06:00
|
|
|
my $sb = stat($cache);
|
|
|
|
|
|
|
|
if ($sb && time() - $sb->mtime < 86400)
|
|
|
|
{
|
|
|
|
open IN, "<$cache";
|
|
|
|
my @content = <IN>;
|
|
|
|
close IN;
|
|
|
|
return $content[0];
|
|
|
|
}
|
2018-10-13 02:34:18 -06:00
|
|
|
|
2018-06-30 17:01:23 -06:00
|
|
|
sub fetch_url
|
|
|
|
{
|
|
|
|
my $url = shift(@_);
|
|
|
|
my $ua = LWP::UserAgent->new;
|
2022-02-25 01:46:54 -07:00
|
|
|
$ua->timeout(5);
|
2018-06-30 17:01:23 -06:00
|
|
|
$ua->agent('Mozilla/5.0');
|
2022-02-25 01:46:54 -07:00
|
|
|
$ua->ssl_opts('verify_hostname' => 0);
|
2018-06-30 17:01:23 -06:00
|
|
|
my $res = $ua->get($url);
|
|
|
|
if ($res->is_success)
|
|
|
|
{
|
|
|
|
return $res->decoded_content;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
my $err = $res->content;
|
|
|
|
my $ca_file = $ua->ssl_opts('SSL_ca_file');
|
|
|
|
die ("Could not fetch $url: $err\n$ca_file");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-18 03:38:39 -06:00
|
|
|
my $content = fetch_url($HTML_ATOMS_URL);
|
2018-06-30 17:01:23 -06:00
|
|
|
|
2018-08-18 03:38:39 -06:00
|
|
|
$content = join("\n", grep(/^\s*Atom\("on\w+"/, split(/[\n\r]/, $content)));
|
2018-06-30 17:01:23 -06:00
|
|
|
|
|
|
|
$content =~ s/.*"(on\w+)".*/$1 /g;
|
2018-10-13 02:34:18 -06:00
|
|
|
|
2018-08-18 03:38:39 -06:00
|
|
|
open IN, "<$archive";
|
|
|
|
my @archived = <IN>;
|
|
|
|
close IN;
|
2018-06-30 17:01:23 -06:00
|
|
|
|
2018-08-18 03:38:39 -06:00
|
|
|
$content .= join("\n", @archived);
|
2018-10-13 02:34:18 -06:00
|
|
|
|
2018-08-18 03:38:39 -06:00
|
|
|
$content =~ s/\s+/\n/g;
|
|
|
|
$content =~ s/^\s+|\s+$//g;
|
2018-10-13 02:34:18 -06:00
|
|
|
|
2018-08-18 03:38:39 -06:00
|
|
|
my @all_events = grep(!/^only$/, uniq(split("\n", $content)));
|
2018-10-13 02:34:18 -06:00
|
|
|
|
2018-08-18 03:38:39 -06:00
|
|
|
open (OUT, ">$archive");
|
|
|
|
print OUT join("\n", @all_events);
|
|
|
|
close OUT;
|
2018-10-13 02:34:18 -06:00
|
|
|
|
2018-06-30 17:01:23 -06:00
|
|
|
my $l = Regexp::List->new;
|
2018-08-18 03:38:39 -06:00
|
|
|
my $re = $l->list2re(@all_events);
|
2018-06-30 17:01:23 -06:00
|
|
|
$re =~ s/\(\?[-^]\w+:(.*)\)/$1/;
|
2018-10-13 02:34:18 -06:00
|
|
|
|
2018-06-30 17:01:23 -06:00
|
|
|
open (OUT, ">$cache");
|
|
|
|
print OUT $re;
|
|
|
|
close OUT;
|
2018-10-13 02:34:18 -06:00
|
|
|
|
2018-06-30 17:01:23 -06:00
|
|
|
$re;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub patch
|
|
|
|
{
|
|
|
|
my $src = shift;
|
|
|
|
my $dst = "$src.tmp";
|
|
|
|
my $re = create_re();
|
|
|
|
my $must_replace = 0;
|
|
|
|
print "Patching $src...\n";
|
|
|
|
open IN, "<$src" or die ("Can't open $src!");
|
|
|
|
open OUT, ">$dst" or die ("Can't open $dst!");
|
|
|
|
|
|
|
|
while (<IN>)
|
|
|
|
{
|
|
|
|
my $line = $_;
|
|
|
|
$must_replace = $line ne $_ if s/^(\s*const IC_EVENT_PATTERN\s*=\s*")([^"]+)/$1$re/;
|
|
|
|
|
|
|
|
print OUT $_;
|
|
|
|
}
|
|
|
|
close IN;
|
|
|
|
close OUT;
|
|
|
|
|
|
|
|
if ($must_replace) {
|
|
|
|
rename $dst, $src;
|
|
|
|
print "Patched.\n";
|
2020-08-28 13:00:01 -06:00
|
|
|
return 0;
|
2018-06-30 17:01:23 -06:00
|
|
|
}
|
2020-08-28 13:00:01 -06:00
|
|
|
|
|
|
|
unlink $dst;
|
|
|
|
print "Nothing to do.\n";
|
|
|
|
return 1;
|
2018-06-30 17:01:23 -06:00
|
|
|
}
|
|
|
|
|
2020-08-28 13:00:01 -06:00
|
|
|
exit(patch($SOURCE_FILE));
|