-
Notifications
You must be signed in to change notification settings - Fork 4
/
files-state.rb
executable file
·103 lines (95 loc) · 2.01 KB
/
files-state.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/local/bin/ruby -w
# $Id$
# (c) 2005, Dirk Meyer, Im Grund 4, 34317 Habichtswald
#
# Updates on:
# http://anime.dinoex.net/xdcc/tools/
#
require 'getoptlong'
def usage(msg, options)
print msg, "\nUsage: #{File.basename($0)} statefile [statefile ...]\n\n"
print msg, "export iroffer statefile to text.\n"
options.each { |o|
print " " + o[1] + ", " + o[0] + " " +
(o[2] == GetoptLong::REQUIRED_ARGUMENT ? 'ARGUMENT' : '') + "\n"
}
exit 64
end
def get_long(string)
return string.unpack('N')[ 0 ]
end
def get_xlong(string)
ll = string.unpack('NN')
l = ll[ 0 ] * ( 2 ** 32 )
l += ll[ 1 ]
return l
end
def get_text(string)
l = string.unpack('C')[ 0 ]
l -= 1
return string[1, l]
end
def parse_buffer(buffer, bsize)
fsize = bsize - 16;
ipos = 8
while ipos < fsize
tag = get_long( buffer[ipos, 4] )
len = get_long( buffer[ipos + 4, 4] )
if ( len <= 8 )
printf( ":tag=%d<br>\n", tag )
printf( ":len=%d<br>\n", len )
printf( "Warning: parsing statfile aborted\n" )
ipos = fsize
break
end
case tag
when 3072 # XDCCS
chunkdata = buffer[ipos, len]
jpos = 8
while jpos < len
jtag = get_long( chunkdata[jpos, 4] )
jlen = get_long( chunkdata[jpos + 4, 4] )
if ( len <= 8 )
printf( ":xtag=%d<br>\n", jtag )
printf( ":xlen=%d<br>\n", jlen )
printf( "Warning: parsing statfile aborted\n" )
jpos = len
break
end
case jtag
when 0
jpos = len
when 3073 # FILE
text = chunkdata[jpos + 7, jlen - 8]
printf( "%s\n", get_text( text ) )
end
jpos += jlen
r = jlen % 4
if ( r > 0 )
jpos += 4 - r
end
end
end
ipos += len;
r = len % 4;
if ( r > 0 )
ipos += 4 - r;
end
end
end
if ARGV.size > 0 then
ARGV.each { |filename|
File.stat(filename).file? or next
bsize = File.size(filename)
begin
buffer = File.open(filename, 'r').read
parse_buffer( buffer, bsize )
rescue
$stderr.print "Failure at #{filename}: #{$!} => Skipping!\n"
end
}
else
usage('State-file not given!', options)
end
exit 0
#