line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Helper::Encode; |
6
|
|
|
|
|
|
|
|
7
|
34
|
|
|
34
|
|
70215
|
use v5.12.5; |
|
34
|
|
|
|
|
160
|
|
8
|
34
|
|
|
34
|
|
231
|
use warnings; |
|
34
|
|
|
|
|
110
|
|
|
34
|
|
|
|
|
2015
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.2.3'; # TRIAL VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
require Exporter; |
13
|
34
|
|
|
34
|
|
264
|
use base qw(Exporter); |
|
34
|
|
|
|
|
192
|
|
|
34
|
|
|
|
|
3192
|
|
14
|
34
|
|
|
34
|
|
274
|
use vars qw(@EXPORT); |
|
34
|
|
|
|
|
102
|
|
|
34
|
|
|
|
|
11019
|
|
15
|
|
|
|
|
|
|
@EXPORT = qw(func_to_json); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my %escapes; |
18
|
|
|
|
|
|
|
for ( 0 .. 255 ) { |
19
|
|
|
|
|
|
|
$escapes{ chr($_) } = sprintf( "%%%02X", $_ ); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub url_encode { |
23
|
1
|
|
|
1
|
0
|
89
|
my ($txt) = @_; |
24
|
1
|
|
|
|
|
37
|
$txt =~ s/([^A-Za-z0-9_])/$escapes{$1}/g; |
25
|
1
|
|
|
|
|
7
|
return $txt; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub url_decode { |
29
|
0
|
|
|
0
|
0
|
|
my ($txt) = @_; |
30
|
0
|
|
|
|
|
|
$txt =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; |
|
0
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
return $txt; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub func_to_json { |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
0
|
0
|
|
return q| |
37
|
|
|
|
|
|
|
sub to_json { |
38
|
|
|
|
|
|
|
my ($ref) = @_; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $s = ""; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
if(ref $ref eq "ARRAY") { |
43
|
|
|
|
|
|
|
$s .= "["; |
44
|
|
|
|
|
|
|
for my $itm (@{ $ref }) { |
45
|
|
|
|
|
|
|
if(substr($s, -1) ne "[") { |
46
|
|
|
|
|
|
|
$s .= ","; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
$s .= to_json($itm); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
return $s . "]"; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
elsif(ref $ref eq "HASH") { |
53
|
|
|
|
|
|
|
$s .= "{"; |
54
|
|
|
|
|
|
|
for my $key (keys %{ $ref }) { |
55
|
|
|
|
|
|
|
if(substr($s, -1) ne "{") { |
56
|
|
|
|
|
|
|
$s .= ","; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
$s .= "\"$key\": " . to_json($ref->{$key}); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
return $s . "}"; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
else { |
63
|
|
|
|
|
|
|
if($ref =~ /^0\d+/) { |
64
|
|
|
|
|
|
|
return "\"$ref\""; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
elsif($ref =~ /^\d+$/) { |
67
|
|
|
|
|
|
|
return $ref; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else { |
70
|
|
|
|
|
|
|
$ref =~ s/'/\\\'/g; |
71
|
|
|
|
|
|
|
return "\"$ref\""; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |