注册 登录
自由的生活_软路由 返回首页

心想事成的个人空间 https://bbs.routerclub.com/?681 [收藏] [复制] [分享] [RSS]

日志

在linux下获取ts流Crypt8的工具

已有 2795 次阅读2019-3-3 22:48

来自:http://www.sat-universe.com/showthread.php?t=307112
#!/usr/bin/perl
use strict;
use warnings;


my $num_args = $#ARGV + 1;
if ($num_args != 3) {
    print "\nUsage: getC8.pl file pid payloadsize\n";
    print "Set pid to 'all' for all pids.\n";
    print "Set payloadsize to 'all' for all payloadsizes.\n";
    print "----------------------------------------------\n";
    print "getC8.pl v0.5 02/09/2018\n";
    exit;
}

my $file=$ARGV[0];
my $pid=$ARGV[1];
my $payload=$ARGV[2];
my $low=1;
my $high=23;


if ($payload ne "all") {
$payload=oct($payload) if $payload=~ /^0/;
$low=int($payload/8);
$high=int($payload/8);

if ($payload % 8 != 0) {
print"\nError: The payloadsize must be a multiple of 8!\n";
exit;
}
if ($payload > 184) {
print"\nError: The payloadsize may not be greater than 184!\n";
exit;
}
if ($payload < 8) {
print"\nError: The payloadsize may not be smaller than 8!\n";
exit;
}
}

if ($pid ne "all") {
$pid=oct($pid) if $pid=~ /^0/;
if ($pid > 0x1FFF) {
print"\nError: The pid may not be greater than 0x1FFF!\n";
exit;
}
if ($pid < 0x0020) {
print"\nError: The pid may not be smaller than 0x0020!\n";
exit;
}
}

print "getC8.pl v0.5 02/09/2018\n";
print "------------------------\n";

my %even_c8=();
my %odd_c8=();

open (my $FH, '<:raw', $file) or die "Can't open '$file' for read: $!";

while (read $FH, my $packet, 188){
my $header_2=unpack("x1 C",$packet);
my $header_3=unpack("x2 C",$packet);
my $header_4=unpack("x3 C",$packet);
#printf ("0x%02x\n",$header_4);
my $tmp_pid = (($header_2 & 0x1F) << 8) | ($header_3);
my $scrambled = ($header_4 >> 6); #10=even; 11=odd; 
my $af = ($header_4 >> 4) & 0x3; #01=no af; 11=af and payload
my $offset=4;
my $tmp_pls=0;
#print "$pid $scrambled $tmp_pid $af\n";
#if (($tmp_pid == $pid) && ($scrambled > 1)){
if (($tmp_pid < 0x1FFF) && ($tmp_pid >0x001F) && ($scrambled > 1)){
if ($af == 0x1) {
$tmp_pls=184;
$offset=4;
} elsif ($af == 0x3) {
$tmp_pls=184-unpack("x4 C",$packet)-1;
$offset=unpack("x4 C",$packet)+1+4;
}
$tmp_pls=int($tmp_pls/8)*8;
#printf "$offset\n";
if ($offset>180) {$offset=4};
my $c8=unpack("x$offset H16",$packet);
#printf "$c8\n";
if ($scrambled==2) { #even
if (!(defined $even_c8{$tmp_pls}{$tmp_pid}{$c8})) {
$even_c8{$tmp_pls}{$tmp_pid}{$c8}=0;
}
$even_c8{$tmp_pls}{$tmp_pid}{$c8}++;
} elsif ($scrambled ==3) { #odd
if (!(defined $odd_c8{$tmp_pls}{$tmp_pid}{$c8})) {
$odd_c8{$tmp_pls}{$tmp_pid}{$c8}=0;
}
$odd_c8{$tmp_pls}{$tmp_pid}{$c8}++;
}
}
}
close $FH or die "Cannot close $file: $!";

for (my $i=$low; $i<=$high; $i++){
my $tmp_pls=$i*8;
printf "Using payload size: %s\n",$tmp_pls;
foreach my $tmp_pid (sort keys %{$even_c8{$tmp_pls}}){
my $counter=0;
foreach my $c8 (sort {$even_c8{$tmp_pls}{$tmp_pid}{$b} <=> $even_c8{$tmp_pls}{$tmp_pid}{$a}} keys %{$even_c8{$tmp_pls}{$tmp_pid}}){
if (($even_c8{$tmp_pls}{$tmp_pid}{$c8}>1) && ($counter<11)){ 
if (($pid eq "all") || ($pid == $tmp_pid)){
printf "PID %0Xh %0Xh-Crypt8: %s [E] Count:%s\n",$tmp_pid,$tmp_pls,$c8,$even_c8{$tmp_pls}{$tmp_pid}{$c8};
$counter++;
}
}
}
if ($counter>0) {print "\n";}
}

foreach my $tmp_pid (sort keys %{$odd_c8{$tmp_pls}}){
my $counter=0;
foreach my $c8 (sort {$odd_c8{$tmp_pls}{$tmp_pid}{$b} <=> $odd_c8{$tmp_pls}{$tmp_pid}{$a}} keys %{$odd_c8{$tmp_pls}{$tmp_pid}}){
if (($odd_c8{$tmp_pls}{$tmp_pid}{$c8}>1) && ($counter<11)){ 
if (($pid eq "all") || ($pid == $tmp_pid)){
printf "PID %0Xh %0Xh-Crypt8: %s [O] Count:%s\n",$tmp_pid,$tmp_pls,$c8,$odd_c8{$tmp_pls}{$tmp_pid}{$c8};
$counter++;
}
}
}
if ($counter>0) {print "\n";}
}
}


路过

雷人

握手

鲜花

鸡蛋

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

QQ|Archiver|手机版|小黑屋|软路由 ( 渝ICP备15001194号-1|渝公网安备 50011602500124号 )

GMT+8, 2024-4-17 04:51 , Processed in 0.036927 second(s), 5 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2023 Discuz! Team.

返回顶部