# $Id: CryptIt 11659 2010-07-12 14:08:09Z sparky $
# Link::CryptIt - Link decrypter plugin for rsget.pl
#
# 2009-2010 (c) Przemysław Iskra <sparky@pld-linux.org>
#		This program is free software,
# you may distribute it under GPL v2 or newer.

name: CryptIt
short: L:CryptIt
web: "http://crypt-it.com/"
uri: qr{crypt-it\.com/}
slots: max
status: OK 2010-07-12

pre:
	# from jdownloader
	my $key = pack "C*", (
		0x73, 0x6f, 0x35, 0x73,  0x78, 0x4e, 0x73, 0x50,
		0x4b, 0x66, 0x4e, 0x53,  0x44, 0x44, 0x5a, 0x48,
		0x61, 0x79, 0x72, 0x33,  0x32, 0x35, 0x32, 0x30	);
	my $post_header = pack "C*", (
		0x00, 0x00, 0x00, 0x00,  0x00, 0x01, 0x00, 0x11,
		0x63, 0x72, 0x79, 0x70,  0x74, 0x69, 0x74, 0x32,
		0x2e, 0x67, 0x65, 0x74,  0x46, 0x69, 0x6c, 0x65,
		0x73, 0x00, 0x02, 0x2f,  0x31, 0x00, 0x00, 0x00,
		0x11, 0x0a, 0x00, 0x00,  0x00, 0x02, 0x02, 0x00,
		0x06);
	my $post_separator = pack "C*", ( 0x02, 0x00 );

	use Crypt::Rijndael;
	my $cipher = new Crypt::Rijndael $key;

unify:
	return "http://crypt-it.com/$1/$2"
		if m{^http://crypt-it\.com/(.*?)/(.*?)(/.*)?$};

start:
	GET( $-{_uri} );
	ERROR( "links not found" )
		unless $-{_referer} =~ m{^http://crypt-it\.com/(.*?)/(.*?)$};
	$-{dir} = $2;

	my $pass = $-{_opts}->{pass} || "";
	my $post = $post_header . $-{dir} . $post_separator . ( chr length $pass ) . $pass;

	ERROR( "password required" )
		if />Acces denied! Password required</ and not $pass;

	GET( "http://crypt-it.com/engine/",
		post => $post,
		headers => [ "Content-Type: application/x-amf" ],
	);

	my @links;
	my @cr = /url.*?([0-9a-fA-F]+).*?size/g;
	foreach ( @cr ) {
		my $cr = join "", map chr hex, /(..)/g;

		my $l = $cipher->decrypt( $cr );
		$l =~ s/\0+//g;
		push @links, $l;
	}

	LINK( @links );

# vim: filetype=perl:ts=4:sw=4
