| 1 |
#!/usr/bin/perl |
#!/usr/bin/perl |
| 2 |
|
|
| 3 |
# fluscate.pl 0.04 - The Flash Obfuscator |
# fluscate - The Flash Obfuscator |
| 4 |
|
|
| 5 |
# $Id$ |
# $Id$ |
| 6 |
# $Log$ |
# $Log$ |
| 7 |
|
# Revision 1.6 2004/08/03 00:24:15 joko |
| 8 |
|
# restructured code (procedures) |
| 9 |
|
# command-line arguments |
| 10 |
|
# new feature: pollute |
| 11 |
|
# |
| 12 |
# Revision 1.5 2004/07/26 16:11:58 joko |
# Revision 1.5 2004/07/26 16:11:58 joko |
| 13 |
# updated pod |
# updated pod |
| 14 |
# included more complete list of flash event-handlers |
# included more complete list of flash event-handlers |
| 29 |
|
|
| 30 |
=pod |
=pod |
| 31 |
|
|
| 32 |
|
fluscate - The Flash Obfuscator |
| 33 |
|
|
| 34 |
This software is Copyright (C) 2004 Andreas Motl |
This software is Copyright (C) 2004 Andreas Motl |
| 35 |
Ideas and future AppleScript integration by Holger Marseille. |
Ideas and MacOS X Application by Holger Marseille |
| 36 |
|
|
| 37 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
| 38 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
| 65 |
|
|
| 66 |
fluscate handles two different styles of function declarations: |
fluscate handles two different styles of function declarations: |
| 67 |
|
|
| 68 |
1. "Normal" ones |
1. "Normal" ones, e.g. |
| 69 |
function mp3Player ('arg1', 'arg2') |
function mp3Player ('arg1', 'arg2') |
| 70 |
|
|
| 71 |
2. There may be "stacked" function declarations |
2. There may be "stacked" function declarations, e.g. |
| 72 |
push 'mp3Player' |
push 'mp3Player' |
| 73 |
function () |
function () |
| 74 |
|
|
| 75 |
|
=head2 Pollute |
| 76 |
|
|
| 77 |
|
Some flash-disassemblers might croak when inserting the following code |
| 78 |
|
after a/each "constants"-declaration: |
| 79 |
|
|
| 80 |
|
push 0 |
| 81 |
|
ls: |
| 82 |
|
dup |
| 83 |
|
trace |
| 84 |
|
branchIfTrue ls" |
| 85 |
|
|
| 86 |
|
|
| 87 |
=head1 Dependencies |
=head1 Dependencies |
| 88 |
|
|
| 92 |
|
|
| 93 |
=head1 Usage |
=head1 Usage |
| 94 |
|
|
| 95 |
|
=head2 General |
| 96 |
|
|
| 97 |
|
Please type "fluscate --help" to get more information about command-line parameters. |
| 98 |
|
|
| 99 |
=head2 win32 |
=head2 win32 |
| 100 |
|
|
| 101 |
#> flasm.exe -d puzzle.swf > puzzle.flm |
#> flasm.exe -d puzzle.swf > puzzle.flm |
| 121 |
zufallsprinip (-21,-3,-89)? (->random) |
zufallsprinip (-21,-3,-89)? (->random) |
| 122 |
- evtl. constants nach abfrage ersetzen ? leider sehr aufwendig, bei vielen constants (->ask) |
- evtl. constants nach abfrage ersetzen ? leider sehr aufwendig, bei vielen constants (->ask) |
| 123 |
- rausgeben des arrays mit den "neuen" werten um evtl die obfuscation rückgängig zu machen (->undo) |
- rausgeben des arrays mit den "neuen" werten um evtl die obfuscation rückgängig zu machen (->undo) |
|
- " push 0 |
|
|
ls: |
|
|
dup |
|
|
trace |
|
|
branchIfTrue ls" |
|
|
... after each "constants" declaration (->pollute) |
|
| 124 |
- what about other symbols beside "function"s? (e.g. variables) (->mode) |
- what about other symbols beside "function"s? (e.g. variables) (->mode) |
| 125 |
- include list of ->keywords from: |
- include list of ->keywords from: |
| 126 |
http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/ |
http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/ |
| 173 |
Password Busting / SWF Protections: http://www.searchlores.org/cinix_fla.htm |
Password Busting / SWF Protections: http://www.searchlores.org/cinix_fla.htm |
| 174 |
|
|
| 175 |
=head2 Off-Topic |
=head2 Off-Topic |
| 176 |
|
|
| 177 |
|
=head3 XML |
| 178 |
|
|
| 179 |
XPath for Actionscript and other stuff: http://www.xfactorstudio.com/Actionscript/ |
XPath for Actionscript and other stuff: http://www.xfactorstudio.com/Actionscript/ |
| 180 |
|
XMLRPC Flash Libraries for ActionScript 2.0: http://xmlrpcflash.sourceforge.net/ |
| 181 |
|
|
| 182 |
|
=head3 Marshalling / AMF (Flash Remoting protocol) |
| 183 |
|
|
| 184 |
|
AMFPHP - Flash Remoting for PHP: http://www.amfphp.org/ |
| 185 |
|
AMF::Perl - Flash Remoting in Perl and Python: http://simonf.com/amfperl/ |
| 186 |
SerializerClass: http://sourceforge.net/projects/serializerclass/ |
SerializerClass: http://sourceforge.net/projects/serializerclass/ |
| 187 |
AMF::Perl - Flash Remoting in Perl and Python - using Flash Remoting protocol (AMF): |
|
| 188 |
http://simonf.com/amfperl/ |
=head3 Misc |
| 189 |
|
|
| 190 |
PEAR::SWF - Read and write SWF head tag: http://www.sephiroth.it/test/php/SWF/ |
PEAR::SWF - Read and write SWF head tag: http://www.sephiroth.it/test/php/SWF/ |
| 191 |
AMFPHP - Flash Remoting for PHP: http://www.amfphp.org/ |
Convert videos to flv: |
| 192 |
|
http://ffmpeg.sourceforge.net/ |
| 193 |
|
http://www.videohelp.com/tools?tool=263 |
| 194 |
|
Flash-CMS: http://www.lachoseinteractive.net/fr/produits/alahup/ |
| 195 |
|
|
| 196 |
=cut |
=cut |
| 197 |
|
|
| 199 |
use strict; |
use strict; |
| 200 |
use warnings; |
use warnings; |
| 201 |
|
|
| 202 |
|
use Getopt::Long; |
| 203 |
|
use Storable; |
| 204 |
|
use Data::Dumper; |
| 205 |
|
|
| 206 |
|
my $VERSION = "0.10"; |
| 207 |
|
|
| 208 |
my $regex = { |
my $regex = { |
| 209 |
'function' => 'function(?:2|)\s(.+?)\s\(.*?\)', |
'function' => 'function(?:2|)\s(.+?)\s\(.*?\)', |
| 210 |
'constants' => 'constants', |
'constants' => 'constants', |
| 212 |
'function_stacked' => 'function(?:2|)\s\s\(.*?\)', |
'function_stacked' => 'function(?:2|)\s\s\(.*?\)', |
| 213 |
'push' => 'push\s\'(.+?)\'', |
'push' => 'push\s\'(.+?)\'', |
| 214 |
}; |
}; |
|
my @symbols_events = qw( |
|
|
onDragOut |
|
|
onDragOver |
|
|
onKeyUp |
|
|
onKeyDown |
|
|
onKillFocus |
|
|
onPress |
|
|
onRelease |
|
|
onReleaseOutside |
|
|
onRollOut |
|
|
onRollOver |
|
|
onSetFocus |
|
|
onActivity |
|
|
onStatus |
|
|
onSelect |
|
|
onData |
|
|
onLoad |
|
|
allowDomain |
|
|
allowInsecureDomain |
|
|
onMouseDown |
|
|
onMouseMove |
|
|
onMouseUp |
|
|
onMouseWheel |
|
|
onEnterFrame |
|
|
onUnload |
|
|
onLoadComplete |
|
|
onLoadError |
|
|
onLoadInit |
|
|
onLoadProgress |
|
|
onLoadStart |
|
|
onID3 |
|
|
onSoundComplete |
|
|
onResize |
|
|
onChanged |
|
|
onScroller |
|
|
); |
|
| 215 |
my @symbols; |
my @symbols; |
| 216 |
|
my @lines; |
| 217 |
|
my $options; |
| 218 |
|
|
| 219 |
# 1. read flasm code from STDIN |
sub read_options { |
| 220 |
my @lines = <STDIN>; |
GetOptions( |
| 221 |
|
"pollute" => \$options->{pollute}, |
| 222 |
|
"help" => \$options->{help}, |
| 223 |
|
"version" => \$options->{version} |
| 224 |
|
); |
| 225 |
|
} |
| 226 |
|
|
| 227 |
my $counter = 0; |
sub scan_symbols { |
| 228 |
foreach (@lines) { |
my @symbols_events = qw( |
| 229 |
|
onDragOut |
| 230 |
# trim newlines |
onDragOver |
| 231 |
#chomp; |
onKeyUp |
| 232 |
my $symbol; |
onKeyDown |
| 233 |
|
onKillFocus |
| 234 |
|
onPress |
| 235 |
|
onRelease |
| 236 |
|
onReleaseOutside |
| 237 |
|
onRollOut |
| 238 |
|
onRollOver |
| 239 |
|
onSetFocus |
| 240 |
|
onActivity |
| 241 |
|
onStatus |
| 242 |
|
onSelect |
| 243 |
|
onData |
| 244 |
|
onLoad |
| 245 |
|
allowDomain |
| 246 |
|
allowInsecureDomain |
| 247 |
|
onMouseDown |
| 248 |
|
onMouseMove |
| 249 |
|
onMouseUp |
| 250 |
|
onMouseWheel |
| 251 |
|
onEnterFrame |
| 252 |
|
onUnload |
| 253 |
|
onLoadComplete |
| 254 |
|
onLoadError |
| 255 |
|
onLoadInit |
| 256 |
|
onLoadProgress |
| 257 |
|
onLoadStart |
| 258 |
|
onID3 |
| 259 |
|
onSoundComplete |
| 260 |
|
onResize |
| 261 |
|
onChanged |
| 262 |
|
onScroller |
| 263 |
|
); |
| 264 |
|
|
| 265 |
# check for all "function" / "function2" symbols and ... |
my $counter = 0; |
| 266 |
if (m/$regex->{function}/) { |
foreach (@lines) { |
| 267 |
# ... remember them |
|
| 268 |
$symbol = $1; |
# trim newlines |
| 269 |
|
#chomp; |
| 270 |
|
my $symbol; |
| 271 |
} elsif (m/$regex->{function_stacked}/) { |
|
| 272 |
if ($lines[$counter - 1] =~ m/$regex->{push}/) { |
# check for all "function" / "function2" symbols and ... |
| 273 |
|
if (m/$regex->{function}/) { |
| 274 |
|
# ... remember them |
| 275 |
$symbol = $1; |
$symbol = $1; |
| 276 |
|
|
| 277 |
|
|
| 278 |
|
} elsif (m/$regex->{function_stacked}/) { |
| 279 |
|
if ($lines[$counter - 1] =~ m/$regex->{push}/) { |
| 280 |
|
$symbol = $1; |
| 281 |
|
} |
| 282 |
} |
} |
| 283 |
|
|
| 284 |
|
if ($symbol and not grep(/$symbol/, @symbols_events)) { |
| 285 |
|
push @symbols, $symbol; |
| 286 |
|
} |
| 287 |
|
|
| 288 |
|
$counter++; |
| 289 |
|
|
| 290 |
} |
} |
| 291 |
|
|
|
if ($symbol and not grep(/$symbol/, @symbols_events)) { |
|
|
push @symbols, $symbol; |
|
|
} |
|
|
|
|
|
$counter++; |
|
|
|
|
| 292 |
} |
} |
| 293 |
|
|
| 294 |
#print join("\n", @symbols); exit; |
#print join("\n", @symbols); exit; |
| 295 |
|
|
| 296 |
# 2. step through all symbols found and replace them |
# 2. step through all symbols found and replace them |
| 297 |
my $symbol_counter = -1; |
sub obfuscate { |
|
foreach my $symbol (@symbols) { |
|
|
my $line_counter = 0; |
|
|
foreach (@lines) { |
|
|
|
|
|
# function declarations; single quotes might not be there! |
|
|
if (m/$regex->{function}/) { |
|
|
s/\s'*$symbol'*\s/ '$symbol_counter' /i; |
|
|
|
|
|
# "constants"-line at begin of each block; single quotes should already be there |
|
|
} elsif (m/$regex->{constants}/) { |
|
|
s/'$symbol'/'$symbol_counter'/i; |
|
|
|
|
|
# function calls; replace inside predecessor line of calling-lines |
|
|
} elsif (m/$regex->{call}/) { |
|
|
$lines[$line_counter - 1] =~ s/'$symbol'/'$symbol_counter'/i; |
|
| 298 |
|
|
| 299 |
# function declarations; name of function is pushed on stack one line before! |
# 1st stage: symbol replacement |
| 300 |
} elsif (m/$regex->{function_stacked}/) { |
my $symbol_counter = -1; |
| 301 |
$lines[$line_counter - 1] =~ s/'$symbol'/'$symbol_counter'/i; |
foreach my $symbol (@symbols) { |
| 302 |
|
my $line_counter = 0; |
| 303 |
|
foreach (@lines) { |
| 304 |
|
|
| 305 |
|
# function declarations; single quotes might not be there! |
| 306 |
|
if (m/$regex->{function}/) { |
| 307 |
|
s/\s'*$symbol'*\s/ '$symbol_counter' /i; |
| 308 |
|
|
| 309 |
|
# "constants"-line at begin of each block; single quotes should already be there |
| 310 |
|
} elsif (m/$regex->{constants}/) { |
| 311 |
|
s/'$symbol'/'$symbol_counter'/i; |
| 312 |
|
|
| 313 |
|
# function calls; replace inside predecessor line of calling-lines |
| 314 |
|
} elsif (m/$regex->{call}/) { |
| 315 |
|
$lines[$line_counter - 1] =~ s/'$symbol'/'$symbol_counter'/i; |
| 316 |
|
|
| 317 |
|
# function declarations; name of function is pushed on stack one line before! |
| 318 |
|
} elsif (m/$regex->{function_stacked}/) { |
| 319 |
|
$lines[$line_counter - 1] =~ s/'$symbol'/'$symbol_counter'/i; |
| 320 |
|
} |
| 321 |
|
|
| 322 |
|
$line_counter++; |
| 323 |
|
|
| 324 |
} |
} |
| 325 |
|
$symbol_counter--; |
| 326 |
|
} |
| 327 |
|
|
| 328 |
$line_counter++; |
# 2nd stage: pollute & Co. |
| 329 |
|
if ($options->{pollute}) { |
| 330 |
|
foreach (@lines) { |
| 331 |
|
if (m/$regex->{constants}/) { |
| 332 |
|
my $inject = qq( |
| 333 |
|
push 0 |
| 334 |
|
ls: |
| 335 |
|
dup |
| 336 |
|
trace |
| 337 |
|
branchIfTrue ls |
| 338 |
|
|
| 339 |
|
); |
| 340 |
|
$_ .= $inject; |
| 341 |
|
} |
| 342 |
|
} |
| 343 |
} |
} |
| 344 |
$symbol_counter--; |
|
| 345 |
|
} |
| 346 |
|
|
| 347 |
|
sub usage { |
| 348 |
|
print "fluscate - The Flash Obfuscator (v$VERSION)", "\n"; |
| 349 |
|
if (not $options->{version}) { |
| 350 |
|
print <<USAGE; |
| 351 |
|
[-p|--pollute] Pollute code by inserting snippet making life harder for disassemblers |
| 352 |
|
[-h|--help] This text |
| 353 |
|
[-v|--version] Show version information only |
| 354 |
|
USAGE |
| 355 |
|
}; |
| 356 |
} |
} |
| 357 |
|
|
| 358 |
# write all stuff to STDOUT |
sub main { |
| 359 |
print STDOUT @lines; |
read_options(); |
| 360 |
|
#print Dumper($options); |
| 361 |
|
if ($options->{help} || $options->{version}) { |
| 362 |
|
usage(); |
| 363 |
|
exit; |
| 364 |
|
} |
| 365 |
|
# read flasm code from STDIN |
| 366 |
|
@lines = <STDIN>; |
| 367 |
|
scan_symbols(); |
| 368 |
|
obfuscate(); |
| 369 |
|
# write all stuff to STDOUT |
| 370 |
|
print STDOUT @lines; |
| 371 |
|
} |
| 372 |
|
|
| 373 |
|
main(); |
| 374 |
|
|
| 375 |
|
1; |
| 376 |
|
__END__ |