line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Tools::License; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
12908662
|
use strict; |
|
6
|
|
|
|
|
20
|
|
|
6
|
|
|
|
|
226
|
|
4
|
6
|
|
|
6
|
|
49
|
use warnings; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
327
|
|
5
|
6
|
|
|
6
|
|
32
|
use base 'Exporter'; |
|
6
|
|
|
|
|
142
|
|
|
6
|
|
|
|
|
873
|
|
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
794
|
use English qw(-no_match_vars); |
|
6
|
|
|
|
|
4518
|
|
|
6
|
|
|
|
|
79
|
|
8
|
|
|
|
|
|
|
|
9
|
6
|
|
|
6
|
|
6125
|
use FusionInventory::Agent::Tools; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
5667
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT = qw( |
12
|
|
|
|
|
|
|
getAdobeLicenses |
13
|
|
|
|
|
|
|
decodeMicrosoftKey |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Thanks to Brandon Mulcahy |
17
|
|
|
|
|
|
|
# http://www.a1vbcode.com/snippet-4796.asp |
18
|
|
|
|
|
|
|
sub _decodeAdobeKey { |
19
|
2
|
|
|
2
|
|
5
|
my ($encrypted_key) = @_; |
20
|
|
|
|
|
|
|
|
21
|
2
|
|
|
|
|
15
|
my @cipher_key = qw/ |
22
|
|
|
|
|
|
|
0000000001 5038647192 1456053789 2604371895 |
23
|
|
|
|
|
|
|
4753896210 8145962073 0319728564 7901235846 |
24
|
|
|
|
|
|
|
7901235846 0319728564 8145962073 4753896210 |
25
|
|
|
|
|
|
|
2604371895 1426053789 5038647192 3267408951 |
26
|
|
|
|
|
|
|
5038647192 2604371895 8145962073 7901235846 |
27
|
|
|
|
|
|
|
3267408951 1426053789 4753896210 0319728564/; |
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
|
|
4
|
my @decrypted_key_chars; |
30
|
2
|
|
|
|
|
10
|
foreach my $char (split(//, $encrypted_key)) { |
31
|
48
|
|
|
|
|
54
|
my $sub_cipher_key = shift @cipher_key; |
32
|
48
|
|
|
|
|
179
|
push @decrypted_key_chars, (split(//, $sub_cipher_key))[$char]; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
2
|
|
|
|
|
18
|
return sprintf |
36
|
|
|
|
|
|
|
'%s%s%s%s-%s%s%s%s-%s%s%s%s-%s%s%s%s-%s%s%s%s-%s%s%s%s', |
37
|
|
|
|
|
|
|
@decrypted_key_chars; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub getAdobeLicenses { |
41
|
1
|
|
|
1
|
1
|
191
|
my (%params) = @_; |
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
|
|
23
|
my $handle = getFileHandle(%params); |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
2
|
my @licenses; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my %data; |
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
15
|
while (my $line = <$handle>) { |
50
|
229
|
|
|
|
|
270
|
chomp($line); |
51
|
|
|
|
|
|
|
|
52
|
229
|
|
|
|
|
591
|
my @f = split(/ <> /, $line); |
53
|
|
|
|
|
|
|
|
54
|
229
|
100
|
|
|
|
530
|
next unless $f[3]; |
55
|
|
|
|
|
|
|
|
56
|
207
|
|
|
|
|
528
|
$f[1] =~ s/\{\|\}.*//; |
57
|
207
|
|
|
|
|
331
|
$f[2] =~ s/\{\|\}.*//; |
58
|
207
|
|
|
|
|
266
|
$f[3] =~ s/\{\|\}.*//; |
59
|
|
|
|
|
|
|
|
60
|
207
|
100
|
|
|
|
735
|
if ($f[2] eq 'FLMap') { |
|
|
100
|
|
|
|
|
|
61
|
9
|
|
|
|
|
10
|
push @{$data{$f[3]}{with}}, $f[1]; |
|
9
|
|
|
|
|
46
|
|
62
|
|
|
|
|
|
|
} elsif ($f[3] ne "unlicensed") { |
63
|
135
|
|
|
|
|
763
|
$data{$f[1]}{$f[2]} = $f[3]; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
1
|
|
|
|
|
5
|
foreach my $key (keys %data) { |
68
|
11
|
50
|
66
|
|
|
42
|
next unless $data{$key}{SN} || $data{$key}{with}; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
push @licenses, { |
71
|
|
|
|
|
|
|
NAME => $key, |
72
|
|
|
|
|
|
|
FULLNAME => $data{$key}{ALM_LicInfo_EpicAppName}, |
73
|
|
|
|
|
|
|
KEY => _decodeAdobeKey($data{$key}{SN}), |
74
|
2
|
|
|
|
|
7
|
COMPONENTS => join('/', @{$data{$key}{with}}) |
|
2
|
|
|
|
|
14
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
1
|
|
|
|
|
35
|
return @licenses; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# inspired by http://poshcode.org/4363 |
82
|
|
|
|
|
|
|
sub decodeMicrosoftKey { |
83
|
7
|
|
|
7
|
1
|
23809
|
my ($raw) = @_; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
## no critic (ProhibitBitwise) |
86
|
|
|
|
|
|
|
|
87
|
7
|
50
|
|
|
|
25
|
return unless $raw; |
88
|
|
|
|
|
|
|
|
89
|
7
|
|
|
|
|
537
|
my @key_bytes = unpack 'C*', $raw; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# select correct bytes range: |
92
|
|
|
|
|
|
|
# - 808 to 822 for new style keys (Office 2010 and later) |
93
|
|
|
|
|
|
|
# - 52 to 66 for old style keys |
94
|
7
|
100
|
|
|
|
132
|
my $first_byte = defined $key_bytes[808] ? 808 : 52; |
95
|
7
|
|
|
|
|
13
|
my $last_byte = $first_byte + 14; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# check for Windows 8/Office 2013 style key (can contains the letter "N") |
98
|
7
|
|
|
|
|
18
|
my $containsN = ($key_bytes[$last_byte] >> 3) & 1; |
99
|
7
|
|
|
|
|
11
|
$key_bytes[$last_byte] = $key_bytes[$last_byte] & 0xF7; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# length of product key, in chars |
102
|
7
|
|
|
|
|
11
|
my $chars_length = 25; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# length of product key, in bytes |
105
|
7
|
|
|
|
|
8
|
my $bytes_length = 15; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# product key available characters |
108
|
7
|
|
|
|
|
37
|
my @letters = qw(B C D F G H J K M P Q R T V W X Y 2 3 4 6 7 8 9); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# extract relevant bytes |
111
|
7
|
|
|
|
|
29
|
my @bytes = @key_bytes[$first_byte .. $last_byte]; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# return immediatly for null keys |
114
|
7
|
100
|
|
49
|
|
59
|
return if all { $_ == 00 } @bytes; |
|
49
|
|
|
|
|
225
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# decoded product key |
117
|
4
|
|
|
|
|
15
|
my @chars; |
118
|
|
|
|
|
|
|
|
119
|
4
|
|
|
|
|
18
|
for (my $i = $chars_length - 1; $i >= 0; $i--) { |
120
|
100
|
|
|
|
|
113
|
my $index = 0; |
121
|
100
|
|
|
|
|
250
|
for (my $j = $bytes_length - 1; $j >= 0; $j--) { |
122
|
1500
|
|
|
|
|
2032
|
my $value = ($index << 8) | $bytes[$j]; |
123
|
1500
|
|
|
|
|
2048
|
$bytes[$j] = $value / scalar @letters; |
124
|
1500
|
|
|
|
|
3387
|
$index = $value % (scalar @letters); |
125
|
|
|
|
|
|
|
} |
126
|
100
|
|
|
|
|
245
|
$chars[$i] = $letters[$index]; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
4
|
100
|
|
|
|
15
|
if ($containsN != 0) { |
130
|
2
|
|
|
|
|
3
|
my $first_char = shift @chars; |
131
|
2
|
|
|
|
|
3
|
my $first_char_index = 0; |
132
|
2
|
|
|
|
|
8
|
for (my $index = 0; $index < scalar @letters; $index++) { |
133
|
2
|
50
|
|
|
|
5
|
next if $first_char ne $letters[$index]; |
134
|
2
|
|
|
|
|
2
|
$first_char_index = $index; |
135
|
2
|
|
|
|
|
3
|
last; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
2
|
|
|
|
|
6
|
splice @chars, $first_char_index, 0, 'N'; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
4
|
|
|
|
|
138
|
return sprintf |
142
|
|
|
|
|
|
|
'%s%s%s%s%s-%s%s%s%s%s-%s%s%s%s%s-%s%s%s%s%s-%s%s%s%s%s', @chars; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |
146
|
|
|
|
|
|
|
__END__ |