Commit 66f8ca41 by Takumi Imai

ビルドテストコミット

parent 7ea8588b
#ParseMaster (July 25 2005)
# Based on "ParseMaster.js" by Dean Edwards <http://dean.edwards.name/>
# Ported to Perl by Rob Seiler, ELR Software Pty Ltd <http://www.elr.com.au>
# Copyright 2005. License <http://creativecommons.org/licenses/LGPL/2.1/>
package ParseMaster;
use strict;
use Data::Dumper;
# Package wide variable declarations
use vars qw/$VERSION
@_X_escaped @_X_patterns
/;
$VERSION = '017';
# constants
my $X_EXPRESSION = 0;
my $X_REPLACEMENT = 1;
my $X_LENGTH = 2;
# re's used to determine nesting levels
my $X_GROUPS = qr/\(/o; # NB: Requires g modifier!
my $X_SUB_REPLACE = qr/\$\d/o;
my $X_INDEXED = qr/^\$\d+$/o;
my $XX_ESCAPE = qr/\\./o; # NB: Requires g modifier!
my $XX_DELETED = qr/\001[^\001]*\001/o; # NB: Requires g modifier!
my $DIGIT = qr/[^\D]/o; # Yep - this is a digit - contains no non-digits
# Constructor
sub new {
my $class = shift;
my $self = {};
@_X_escaped = (); # Re-initialize global for each instance
@_X_patterns = (); # Re-initialize global for each instance
# Instance variables - access by similarly named set/get functions
$self->{_ignoreCase_} = 0;
$self->{_escapeChar_} = '';
bless ($self, $class);
return $self;
}
sub ignoreCase {
my ($self, $value) = @_;
if (defined($value)) {
$self->{_ignoreCase_} = $value;
}
return $self->{_ignoreCase_};
}
sub escapeChar{
my ($self, $value) = @_;
if (defined($value)) {
$self->{_escapeChar_} = $value;
}
return $self->{_escapeChar_};
}
#######################
# Public Parsemaster functions
my $X_DELETE = sub(@$) {
my $X_offset = pop;
my @X_match = @_;
return (chr(001) . $X_match[$X_offset] . chr(001));
}; # NB semicolon required for closure!
# create and add a new pattern to the patterns collection
sub add {
my ($self, $expression, $X_replacement) = @_;
if (!$X_replacement) {$X_replacement = $X_DELETE};
# count the number of sub-expressions
my $temp = &_X_internalEscape($expression);
my $length = 1; # Always at least one because each pattern is itself a sub-expression
$length += $temp =~ s/$X_GROUPS//g; # One way to count the left capturing parentheses in the regexp string
# does the pattern deal with sub-expressions?
if ((ref($X_replacement) ne "CODE") && ($X_replacement =~ m/$X_SUB_REPLACE/)) {
if ($X_replacement =~ m/$X_INDEXED/) { # a simple lookup? (eg "$2")
# store the index (used for fast retrieval of matched strings)
$X_replacement = substr($X_replacement,1) - 1;
}
else { # a complicated lookup (eg "Hello $2 $1")
my $i = $length;
while ($i) { # Had difficulty getting Perl to do Dean's splitting and joining of strings containing $'s
my $str = '$a[$o+' . ($i-1) . ']'; # eg $a[$o+1]
$X_replacement =~ s/\$$i/$str/; # eg $2 $3 -> $a[$o+1] $a[$o+2]
$i--;
}
# build a function to do the lookup - returns interpolated string of array lookups
$X_replacement = eval('sub {my $o=pop; my @a=@_; return "' . $X_replacement . '"};');
}
}
else {}
# pass the modified arguments
&_X_add($expression || q/^$/, $X_replacement, $length);
}
# execute the global replacement
sub exec {
#print Dumper(@_X_patterns);
my ($self, $X_string) = @_;
my $escChar = $self->escapeChar();
my $ignoreCase = $self->ignoreCase();
my ($regexp,$captures) = &_getPatterns(); # Concatenated and parenthesized regexp eg '(regex1)|(regex2)|(regex3)' etc
$X_string = &_X_escape($X_string, $escChar);
if ($ignoreCase) {$X_string =~ s/$regexp/{&_X_replacement(&_matchVars($captures,\$X_string))}/gie} # Pass $X_String as a
else {$X_string =~ s/$regexp/{&_X_replacement(&_matchVars($captures,\$X_string))}/ge} # reference for speed
$X_string = &_X_unescape($X_string, $escChar);
$X_string =~ s/$XX_DELETED//g;
return $X_string;
}
sub _X_add {
push (@_X_patterns, [@_]); # Save each argument set as is into an array of arrays
}
# this is the global replace function (it's quite complicated)
sub _X_replacement {
my (@arguments) = @_;
#print Dumper (@arguments);
if ($arguments[0] le '') {return ''}
# Dereference last index (source String) here - faster than in _matchVars (maybe not needed at all?)
$arguments[$#arguments] = ${$arguments[$#arguments]};
my $i = 1;
# loop through the patterns
for (my $j=0; $j<scalar(@_X_patterns); $j++) { # Loop through global all @_X_patterns
my @X_pattern = @{$_X_patterns[$j]};
# do we have a result? NB: "if ($arguments[$i])" as in Dean's Javascript is false for the value 0!!!
if ((defined $arguments[$i]) && ($arguments[$i] gt '')) {
my $X_replacement = $X_pattern[$X_REPLACEMENT];
# switch on type of $replacement
if (ref($X_replacement) eq "CODE") { # function
return &$X_replacement(@arguments,$i);
}
elsif ($X_replacement =~ m/$DIGIT/) { # number (contains no non-digits)
return $arguments[$X_replacement + $i];
}
else { # default
return $X_replacement; # default
}
} # skip over references to sub-expressions
else {$i += $X_pattern[$X_LENGTH]}
}
}
#######################
# Private functions
#######################
# encode escaped characters
sub _X_escape {
my ($X_string, $X_escapeChar) = @_;
if ($X_escapeChar) {
my $re = '\\'.$X_escapeChar.'(.)';
$X_string =~ s/$re/{push(@_X_escaped,$1); $X_escapeChar}/ge;
}
return $X_string;
}
# decode escaped characters
sub _X_unescape {
my ($X_string, $X_escapeChar) = @_;
if ($X_escapeChar) { # We'll only do this if there is an $X_escapeChar!
my $re = '\\'.$X_escapeChar;
$X_string =~ s/$re/{$X_escapeChar . (shift(@_X_escaped))}/ge; # Don't use Dean Edwards as below 'or' here - because zero will return ''!
# $X_string =~ s/$re/{$X_escapeChar . (shift(@_X_escaped) || '')}/ge;
}
return $X_string;
}
sub _X_internalEscape {
my ($string) = shift;
$string =~ s/$XX_ESCAPE//g;
return $string;
}
# Builds an array of match variables to (approximately) emulate that available in Javascript String.replace()
sub _matchVars {
my ($m,$sref) = @_;
my @args = (1..$m); # establish the number potential memory variables
my @mv = map {eval("\$$_")} @args; # matchvarv[1..m] = the memory variables $1 .. $m
unshift (@mv, $&); # matchvar[0] = the substring that matched
push (@mv, length($`)); # matchvar[m+1] = offset within the source string where the match occurred (= length of prematch string)
push (@mv, $sref); # matchvar[m+2] = reference to full source string (dereference in caller if/when needed)
#print Dumper (@mv);
return @mv;
}
sub _getPatterns {
my @Patterns = ();
my $lcp = 0;
for (my $i=0; $i<scalar(@_X_patterns); $i++) { # Loop through global all @_patterns
push (@Patterns, $_X_patterns[$i][$X_EXPRESSION]); # accumulate the expressions
$lcp += $_X_patterns[$i][$X_LENGTH]; # sum the left capturing parenthesis counts
}
my $str = "(" . join(')|(',@Patterns). ")"; # enclose each pattern in () separated by "|"
return ($str, $lcp);
}
##################
# END #
##################
1; # ParseMaster #
##################
#!/usr/bin/env perl
#jsPacker (July 2005)
#
use strict;
use Pack;
use vars qw($PROGNAME $VERSION
$opt_h $opt_q $opt_v $opt_i $opt_o $opt_e $opt_f $opt_s);
use Getopt::Std;
$PROGNAME = $0;
$VERSION = '1.00b';
my $Description = 'A JavaScript Compressor/Obfuscator';
my $Version = "v$VERSION\[p$Pack::VERSION-pm$Pack::PM_VERSION\]";
# "English" versions of settings
my %ENCODINGS = (0=>'None', 10=>'Decimal', 36=>'Normal', 62=>'Normal', 95=>'High-ascii');
my %SETTINGS = (0=>'No', 1=>'Yes');
exit(0) if &main();
exit(1);
################
# Sub-routines #
################
# Main program
sub main {
# Get command line options
&getopts('hqvfsi:o:e:');
$opt_h ||= 0; # $opt_h shows usage and exits
$opt_q ||= 0; # $opt_q sets quiet mode (no stdout output)
$opt_v ||= 0; # $opt_v shows version and exits
$opt_i ||= ''; # $opt_i is input file. Required!
$opt_o ||= ''; # $opt_o is output file. If not set, use standard output
$opt_e ||= 0; # $opt_e encoding level (0,10,36,62,95)
$opt_f ||= 0; # $opt_f use fast decoding
$opt_s ||= 0; # $opt_x use special characters
# Display help or version if requested
if ($opt_h) {&usage("help")}
if ($opt_v) {&usage("version")}
# Constrain encoding level, fastdecoding and specialcharacters to allowed limits
$opt_e = ($opt_e > 0) ? ($opt_e > 10) ? ($opt_e > 36) ? ($opt_e > 62) ? 95 : 62 : 36 : 10 : 0;
$opt_f = ($opt_f) ? 1 : 0;
$opt_s = ($opt_s) ? 1 : 0;
# Do the job if an input file is specified
if ($opt_i) {
# Read the source script
my $script = &readInputFile($opt_i);
# Pack the source script
my $packedscript = &Pack::pack($script,$opt_e, $opt_f, $opt_s);
# Show what happened (if not in quiet mode)
if (!$opt_q) {showJobDetails($opt_i, $opt_o, $opt_e, $opt_f,$opt_s,\$script,\$packedscript)}
# Output the packed script
if ($opt_o) {&writeOutputFile($opt_o,\$packedscript)} # to output file if specifed
else {print "$packedscript"} # otherwise to STDOUT
}
else { # If no input file is specified, display help
&usage();
}
return(1);
}
######################
sub showJobDetails { #
######################
# Show details of input/output files, settings and compression ratio
my ($inputfile, $outputfile,
$encoding, $fastdecode, $specialchars,
$instringref, $outstringref) = @_;
print "$PROGNAME $Version\n";
print "\tSource file : ";
print "\"$inputfile\"\n";
print (($outputfile) ? ("\tOutput file : \"$outputfile\"\n") : ''); # Print only if output is going to a file
print "\tSettings : encoding=$ENCODINGS{$encoding} fastdecode=$SETTINGS{$fastdecode} specialchars=$SETTINGS{$specialchars}\n";
print "\tCompression : " . &compressionRatio($instringref, $outstringref). "\n\n";
}
#####################
sub readInputFile { #
#####################
# Read content (source script) from input file
my $filename = shift;
open(FH, $filename) || die "Error!!! Problem opening input file \"$filename\"!\n";
my @content = <FH>;
close(FH);
return join('',@content);
}
#######################
sub writeOutputFile { #
#######################
# Write content (packed script) to output file
my ($filename,$refcontent) = @_;
open(FH, ">$filename") || die "Error!!! Problem opening output file \"$filename\"\n";
print(FH $$refcontent);
close(FH);
}
########################
sub compressionRatio { #
########################
# Calculate the ratio of output string to input string
my ($sref1,$sref2) = @_;
my $ratio = (length($$sref2) / (length($$sref1)||1));
$ratio = sprintf "%.2f", $ratio;
return $ratio;
}
#############
sub usage { #
#############
# Inform user about usage, version and exit
my $showusage = 0;
my $showversion = 0;
my $params = shift;
if (defined $params) {
if ($params eq "help") {$showusage = 1;}
elsif ($params eq "version") {$showversion = 1;}
else {$showusage = 1;}
}
else {$showversion = 1;}
if ($showversion) {
print<<EOT;
$PROGNAME $Version
$Description
\tBased on "Packer.js" by Dean Edwards <http://dean.edwards.name/>
\tPorted to Perl by Rob Seiler, ELR Software Pty Ltd <http://www.elr.com.au>
\tCopyright 2005. License <http://creativecommons.org/licenses/LGPL/2.1/>
Use "$PROGNAME -h" for options
EOT
exit(1);
}
if ($showusage) {
print<<EOT;
$PROGNAME $Version
$Description
Usage:
\t$PROGNAME -i inputfile [-o outputfile] [-eX] [-f] [-s] [-qvh]\n
\t-i <inputfile> (eg -i myscript.js)
\t-o <outputfile> (eg -o myscript-p.js)
\t-eN <encoding> [0=None 10=Numeric 62=Normal(alphanumeric) 95=High-ascii]
\t-f <fast decode>
\t-s <special characters>
\t-q quiet mode
\t-v version
\t-h help
Examples:
\t$PROGNAME -i myscript.js
\t$PROGNAME -i myscript.js -o packed.js
\t$PROGNAME -i myscript.js -o packed.js -e10 -f -s
\t$PROGNAME -i myscript.js -e95 -fsq > packed.js
EOT
exit(1);
}
}
#!/bin/sh
DIR=`dirname $0`/..
TARGET0=""
TARGET1=""
TARGET2=""
if [ $# -eq 1 ]; then
TARGET0=$1
else
TARGET0="abvw"
fi
# abvw/js/*
if [ "$TARGET0" = "abvw" ]; then
TARGET1='Limit_Access_Content.js bookmark.js contentsearch.js contentview.js contentview_3d.js contentview_Anket.js contentview_CallApi.js contentview_ContentTypeNone.js contentview_CreateObjects.js contentview_Events.js contentview_General.js contentview_GetData.js contentview_Gomu.js contentview_ImagePreview.js contentview_InitObjects.js contentview_Maker.js contentview_Marking.js contentview_Memo.js contentview_Paint.js contentview_Pen.js contentview_PopupText.js detail.js header.js history.js home.js login.js settings.js share.js stview.js contentview_Streaming.js contentview_Getits.js'
else
TARGET1='contentview.js contentview_3d.js contentview_Anket.js contentview_CallApi.js contentview_ContentTypeNone.js contentview_CreateObjects.js contentview_Events.js contentview_General.js contentview_GetData.js contentview_ImagePreview.js contentview_InitObjects.js contentview_PopupText.js contentview_initDefautValue.js'
fi
# abvw/common/js
if [ "$TARGET0" = "abvw" ]; then
TARGET2='avweb.js common.js i18n.js screenLock.js script.js tab.js textObject.js zoomDetector.js'
else
TARGET2='avweb.js common.js i18n.js script.js textObject.js zoomDetector.js'
fi
OBFUSCATE_EXECUTABLE="$DIR/packer/jsPacker.pl -e10"
for f in $TARGET1
do
ORG=$DIR/$TARGET0/js/$f
TARGET=$DIR/ob/abvw/js/$f
$OBFUSCATE_EXECUTABLE -i $ORG -o $TARGET
done
for f in $TARGET2
do
ORG=$DIR/$TARGET0/common/js/$f
TARGET=$DIR/ob/abvw/common/js/$f
$OBFUSCATE_EXECUTABLE -i $ORG -o $TARGET
done
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment