2012-03-15 96 views
0

全部,从混淆JS文件中提取URL

我想提取所有在混淆的JS文件中提到的URL。到目前为止,该脚本只提取一个URL。由于混淆,所有URL都包含在一行中。 下面是一段代码,我使用的URL提取:

while(my $line = <$info>) { 
      chomp ($line); #removing the unwanted new line character 
      my ($uri)= $line =~ /$RE{URI}{HTTP}{-scheme=>'https?'}{-keep}/ ; 
      $uri=~s/[,\']//g; 
      print "$uri\n" if ($uri); 
} 

我怎么能在这一段代码改进,使其正确提取所有网址吗?这段代码很好地与普通的JS文件一起工作。

回答

1

试试这个。在正则表达式末尾的/g允许它在连续的调用中从匹配跳转到匹配,跟踪它在字符串中的位置。请参阅Perl RegExpt教程中的“perldoc perlretut”中的“全局匹配”。

我在($re)附近添加的括号捕获匹配结果并将其分配给$1。请参阅“perldoc perlretut”中的“提取匹配”;

while(my $line = <DATA>) { 
      chomp ($line); #removing the unwanted new line character 
      my $re = $RE{URI}{HTTP}{-scheme=>'https?'}{-keep}; 
      while ($line =~ /($re)/g){ 
       my $uri = $1; 
       $uri=~s/[,\']//g; 
       print "$uri\n" if ($uri); 
      } 
} 
+0

就像一个魅力!谢谢@凯文 – smokinguns 2012-03-15 19:02:02

0
while(my $line = <$info>) { 
    chomp ($line); #removing the unwanted new line character 
    my @uris = $line =~ /($RE{URI}{HTTP}{-scheme=>'https?'}{-keep})/g; 
    foreach my $uri (@uris) { 
    $uri=~s/[,\']//g; 
    print "$uri\n" if ($uri); 
    } 
}