bnicovideo 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bnicovideo/os_detector.rb +35 -0
- data/lib/bnicovideo/user_session/linux.rb +43 -0
- data/lib/bnicovideo/user_session/mac_os_x.rb +107 -0
- data/lib/bnicovideo/user_session/win95.rb +54 -0
- data/lib/bnicovideo/user_session/win_vista.rb +110 -0
- data/lib/bnicovideo/user_session/win_xp.rb +60 -0
- data/lib/bnicovideo/user_session.rb +29 -81
- data/lib/bnicovideo/version.rb +1 -1
- data/lib/bnicovideo/windows_detector.rb +23 -0
- data/lib/bnicovideo.rb +2 -0
- metadata +10 -3
@@ -0,0 +1,35 @@
|
|
1
|
+
# To change this template, choose Tools | Templates
|
2
|
+
# and open the template in the editor.
|
3
|
+
|
4
|
+
module Bnicovideo
|
5
|
+
module OsDetector
|
6
|
+
def self.detect
|
7
|
+
if /mswin(?!ce)|mingw|cygwin|bccwin/ =~ RUBY_PLATFORM
|
8
|
+
# Windows
|
9
|
+
return Bnicovideo::WindowsDetector.check
|
10
|
+
elsif /darwin/ =~ RUBY_PLATFORM
|
11
|
+
return 'macosx'
|
12
|
+
elsif /java/ =~ RUBY_PLATFORM
|
13
|
+
# JRuby
|
14
|
+
os_name = Java::JavaLang::System.getProperty('os.name')
|
15
|
+
if /Windows/ =~ os_name
|
16
|
+
os_version = Java::JavaLang::System.getProperty('os.version')
|
17
|
+
mj = os_version.split('.')[0]
|
18
|
+
if mj == '6'
|
19
|
+
return 'winvista'
|
20
|
+
elsif mj == '5'
|
21
|
+
return 'winxp'
|
22
|
+
else
|
23
|
+
return 'win95'
|
24
|
+
end
|
25
|
+
elsif /Mac OS X/ =~ os_name
|
26
|
+
return 'macosx'
|
27
|
+
else
|
28
|
+
return 'unix'
|
29
|
+
end
|
30
|
+
else
|
31
|
+
return 'unix'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# To change this template, choose Tools | Templates
|
2
|
+
# and open the template in the editor.
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'sqlite3'
|
6
|
+
require 'inifile'
|
7
|
+
|
8
|
+
module Bnicovideo
|
9
|
+
class UserSession
|
10
|
+
module Linux
|
11
|
+
def self.init_from_firefox
|
12
|
+
base_path = File.join(ENV['HOME'], '.mozilla', 'firefox')
|
13
|
+
ini_path = File.join(base_path, 'profiles.ini')
|
14
|
+
ini_hash = IniFile.load(ini_path).to_h
|
15
|
+
profile_path = nil
|
16
|
+
ini_hash.each do |k, v|
|
17
|
+
next unless v['Name'] == 'default'
|
18
|
+
relative = (v['IsRelative'] != '0')
|
19
|
+
input_path = v['Path']
|
20
|
+
if relative
|
21
|
+
profile_path = File.join(base_path, input_path)
|
22
|
+
else
|
23
|
+
profile_path = input_path
|
24
|
+
end
|
25
|
+
sql_path = File.join(profile_path, 'cookies.sqlite')
|
26
|
+
conn = SQLite3::Database.new(sql_path)
|
27
|
+
val = conn.get_first_value("select value from moz_cookies" +
|
28
|
+
" where host='.nicovideo.jp' AND name='user_session'")
|
29
|
+
return val
|
30
|
+
end
|
31
|
+
return nil
|
32
|
+
end
|
33
|
+
def self.init_from_chrome
|
34
|
+
sql_path = File.join(ENV['HOME'], '.config', 'google-chrome', 'Default', 'Cookies')
|
35
|
+
conn = SQLite3::Database.new(sql_path)
|
36
|
+
val = conn.get_first_value("select value from cookies" +
|
37
|
+
" where host_key='.nicovideo.jp' AND name='user_session'")
|
38
|
+
conn.close
|
39
|
+
return val
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# To change this template, choose Tools | Templates
|
2
|
+
# and open the template in the editor.
|
3
|
+
|
4
|
+
require 'rexml/document'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'sqlite3'
|
7
|
+
require 'inifile'
|
8
|
+
|
9
|
+
module Bnicovideo
|
10
|
+
class UserSession
|
11
|
+
module MacOsX
|
12
|
+
def self.init_from_firefox
|
13
|
+
base_path = File.join(ENV['HOME'], 'Library', 'Application Support', 'Firefox')
|
14
|
+
ini_path = File.join(base_path, 'profiles.ini')
|
15
|
+
ini_hash = IniFile.load(ini_path).to_h
|
16
|
+
profile_path = nil
|
17
|
+
ini_hash.each do |k, v|
|
18
|
+
next unless v['Name'] == 'default'
|
19
|
+
relative = (v['IsRelative'] != '0')
|
20
|
+
input_path = v['Path']
|
21
|
+
if relative
|
22
|
+
profile_path = File.join(base_path, input_path)
|
23
|
+
else
|
24
|
+
profile_path = input_path
|
25
|
+
end
|
26
|
+
sql_path = File.join(profile_path, 'cookies.sqlite')
|
27
|
+
conn = SQLite3::Database.new(sql_path)
|
28
|
+
val = conn.get_first_value("select value from moz_cookies" +
|
29
|
+
" where host='.nicovideo.jp' AND name='user_session'")
|
30
|
+
return val
|
31
|
+
end
|
32
|
+
return nil
|
33
|
+
end
|
34
|
+
def self.init_from_chrome
|
35
|
+
sql_path = File.join(ENV['HOME'], 'Library', 'Application Support',
|
36
|
+
'Google', 'Chrome', 'Default', 'Cookies')
|
37
|
+
conn = SQLite3::Database.new(sql_path)
|
38
|
+
val = conn.get_first_value("select value from cookies" +
|
39
|
+
" where host_key='.nicovideo.jp' AND name='user_session'")
|
40
|
+
conn.close
|
41
|
+
return val
|
42
|
+
end
|
43
|
+
def self.init_from_safari
|
44
|
+
cookie_base_path = File.join(ENV['HOME'], 'Library', 'Cookies')
|
45
|
+
bcpath = File.join(cookie_base_path, 'Cookies.binarycookies')
|
46
|
+
if File.exist?(bcpath)
|
47
|
+
cookie_path = bcpath
|
48
|
+
bin = nil
|
49
|
+
File.open(cookie_path, 'rb') do |file|
|
50
|
+
bin = file.read
|
51
|
+
end
|
52
|
+
raise 'Invalid Cookie file' unless bin[0..3] == 'cook'
|
53
|
+
page_num = bin[4..7].unpack('N')[0]
|
54
|
+
pages_length = []
|
55
|
+
page_num.times do |i|
|
56
|
+
page_length = bin[(8 + i * 4)..(11 + i * 4)].unpack('N')[0]
|
57
|
+
pages_length.push(page_length)
|
58
|
+
end
|
59
|
+
read_ptr = 8 + page_num * 4
|
60
|
+
pages_length.each do |pgl|
|
61
|
+
page = bin[read_ptr..(read_ptr + pgl - 1)]
|
62
|
+
cookies_num = page[4..7].unpack('V')[0]
|
63
|
+
nread_ptr = read_ptr
|
64
|
+
cookies_offset = []
|
65
|
+
cookies_num.length.times do |i|
|
66
|
+
cookie_offset = page[(8 + i * 4)..(11 + i * 4)].unpack('V')[0]
|
67
|
+
cookies_offset.push(cookie_offset)
|
68
|
+
end
|
69
|
+
nread_ptr += 12 + cookies_num * 4
|
70
|
+
read_ptr += pgl
|
71
|
+
cookies_offset.each do |cof|
|
72
|
+
cookie_length = page[cof..(cof + 3)].unpack('V')[0]
|
73
|
+
cookie_bin = page[cof..(cof + cookie_length - 1)]
|
74
|
+
offset_url = page[(cof + 16)..(cof + 19)].unpack('V')[0]
|
75
|
+
offset_name = page[(cof + 20)..(cof + 23)].unpack('V')[0]
|
76
|
+
offset_path = page[(cof + 24)..(cof + 27)].unpack('V')[0]
|
77
|
+
offset_value = page[(cof + 28)..(cof + 31)].unpack('V')[0]
|
78
|
+
url_end = (/\x00/ =~ cookie_bin[offset_url..-1])
|
79
|
+
url = cookie_bin[offset_url, url_end]
|
80
|
+
name_end = (/\x00/ =~ cookie_bin[offset_name..-1])
|
81
|
+
name = cookie_bin[offset_name, name_end]
|
82
|
+
path_end = (/\x00/ =~ cookie_bin[offset_path..-1])
|
83
|
+
path = cookie_bin[offset_path, path_end]
|
84
|
+
value_end = (/\x00/ =~ cookie_bin[offset_value..-1])
|
85
|
+
value = cookie_bin[offset_value, value_end]
|
86
|
+
return value if (/nicovideo\.jp$/ =~ url) && (name == 'user_session')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
return nil
|
90
|
+
else
|
91
|
+
xml = REXML::Document.new(File.read(File.join(cookie_base_path, 'Cookies.plist')))
|
92
|
+
xml.root.elements.each('array/dict') do |elem|
|
93
|
+
if elem.elements['key[text()="Domain"]'] &&
|
94
|
+
elem.elements['key[text()="Domain"]'].next_element &&
|
95
|
+
elem.elements['key[text()="Domain"]'].next_element.text == '.nicovideo.jp' &&
|
96
|
+
elem.elements['key[text()="Name"]'] &&
|
97
|
+
elem.elements['key[text()="Name"]'].next_element &&
|
98
|
+
elem.elements['key[text()="Name"]'].next_element.text == 'user_session'
|
99
|
+
return elem.elements['key[text()="Value"]'].next_element.text
|
100
|
+
end
|
101
|
+
end
|
102
|
+
return nil
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# To change this template, choose Tools | Templates
|
2
|
+
# and open the template in the editor.
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'sqlite3'
|
6
|
+
require 'inifile'
|
7
|
+
|
8
|
+
module Bnicovideo
|
9
|
+
class UserSession
|
10
|
+
# Windows 95 and NT 4.x
|
11
|
+
module Win95
|
12
|
+
def self.init_from_firefox
|
13
|
+
# Single user only
|
14
|
+
base_path = File.join(ENV['windir'], 'Application Data', 'Mozilla', 'Firefox')
|
15
|
+
ini_path = File.join(base_path, 'profiles.ini')
|
16
|
+
ini_hash = IniFile.load(ini_path).to_h
|
17
|
+
profile_path = nil
|
18
|
+
ini_hash.each do |k, v|
|
19
|
+
next unless v['Name'] == 'default'
|
20
|
+
relative = (v['IsRelative'] != '0')
|
21
|
+
input_path = v['Path']
|
22
|
+
if relative
|
23
|
+
profile_path = File.join(base_path, input_path)
|
24
|
+
else
|
25
|
+
profile_path = input_path
|
26
|
+
end
|
27
|
+
sql_path = File.join(profile_path, 'cookies.sqlite')
|
28
|
+
conn = SQLite3::Database.new(sql_path)
|
29
|
+
val = conn.get_first_value("select value from moz_cookies" +
|
30
|
+
" where host='.nicovideo.jp' AND name='user_session'")
|
31
|
+
return val
|
32
|
+
end
|
33
|
+
return nil
|
34
|
+
end
|
35
|
+
def self.init_from_ie
|
36
|
+
cookies_path = File.join(ENV['windir'], 'Cookie')
|
37
|
+
Dir.open(cookies_path) do |dir|
|
38
|
+
dir.each do |fn|
|
39
|
+
next unless (/.*@nicovideo.*/ =~ fn)
|
40
|
+
File.open(fn) do |f|
|
41
|
+
cb = f.read
|
42
|
+
cs = cb.split(/\*\n/)
|
43
|
+
cs.each do |c|
|
44
|
+
ca = c.split(/\n/)
|
45
|
+
return ca[1] if ca[0] == 'user_session'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
return nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# To change this template, choose Tools | Templates
|
2
|
+
# and open the template in the editor.
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'sqlite3'
|
6
|
+
require 'inifile'
|
7
|
+
|
8
|
+
module Bnicovideo
|
9
|
+
class UserSession
|
10
|
+
# Windows Vista and 7
|
11
|
+
module WinVista
|
12
|
+
# Get user session from Firefox(3.0 or later)
|
13
|
+
def self.init_from_firefox
|
14
|
+
ini_path = File.join(ENV['APPDATA'], 'Mozilla', 'Firefox', 'profiles.ini')
|
15
|
+
ini_hash = IniFile.load(ini_path).to_h
|
16
|
+
profile_path = nil
|
17
|
+
ini_hash.each do |k, v|
|
18
|
+
next unless v['Name'] == 'default'
|
19
|
+
relative = (v['IsRelative'] != '0')
|
20
|
+
input_path = v['Path']
|
21
|
+
if relative
|
22
|
+
profile_path = File.join(ENV['APPDATA'], 'Mozilla', 'Firefox', input_path)
|
23
|
+
else
|
24
|
+
profile_path = input_path
|
25
|
+
end
|
26
|
+
sql_path = File.join(profile_path, 'cookies.sqlite')
|
27
|
+
conn = SQLite3::Database.new(sql_path)
|
28
|
+
val = conn.get_first_value("select value from moz_cookies" +
|
29
|
+
" where host='.nicovideo.jp' AND name='user_session'")
|
30
|
+
return val
|
31
|
+
end
|
32
|
+
return nil
|
33
|
+
end
|
34
|
+
# Get user session from Google Chrome
|
35
|
+
def self.init_from_chrome
|
36
|
+
sql_path = File.join(ENV['LOCALAPPDATA'], 'Google','Chrome', 'User Data', 'Default', 'Cookies')
|
37
|
+
conn = SQLite3::Database.new(sql_path)
|
38
|
+
val = conn.get_first_value("select value from cookies" +
|
39
|
+
" where host_key='.nicovideo.jp' AND name='user_session'")
|
40
|
+
conn.close
|
41
|
+
return val
|
42
|
+
end
|
43
|
+
# Get user session from Internet Explorer
|
44
|
+
def self.init_from_ie
|
45
|
+
cookies_path = File.join(ENV['APPDATA'], 'Microsoft', 'Windows', 'Cookies', 'Low')
|
46
|
+
Dir.open(cookies_path) do |dir|
|
47
|
+
dir.each do |fn|
|
48
|
+
next unless (/.*@nicovideo.*/ =~ fn)
|
49
|
+
File.open(fn) do |f|
|
50
|
+
cb = f.read
|
51
|
+
cs = cb.split(/\*\n/)
|
52
|
+
cs.each do |c|
|
53
|
+
ca = c.split(/\n/)
|
54
|
+
return ca[1] if ca[0] == 'user_session'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
return nil
|
60
|
+
end
|
61
|
+
# Get user session from Safari
|
62
|
+
def self.init_from_safari
|
63
|
+
cookie_path = File.join(ENV['APPDATA'], 'Apple Computer', 'Safari',
|
64
|
+
'Cookies', 'Cookies.binarycookies')
|
65
|
+
bin = nil
|
66
|
+
File.open(cookie_path, 'rb') do |file|
|
67
|
+
bin = file.read
|
68
|
+
end
|
69
|
+
raise 'Invalid Cookie file' unless bin[0..3] == 'cook'
|
70
|
+
page_num = bin[4..7].unpack('N')[0]
|
71
|
+
pages_length = []
|
72
|
+
page_num.times do |i|
|
73
|
+
page_length = bin[(8 + i * 4)..(11 + i * 4)].unpack('N')[0]
|
74
|
+
pages_length.push(page_length)
|
75
|
+
end
|
76
|
+
read_ptr = 8 + page_num * 4
|
77
|
+
pages_length.each do |pgl|
|
78
|
+
page = bin[read_ptr..(read_ptr + pgl - 1)]
|
79
|
+
cookies_num = page[4..7].unpack('V')[0]
|
80
|
+
nread_ptr = read_ptr
|
81
|
+
cookies_offset = []
|
82
|
+
cookies_num.times do |i|
|
83
|
+
cookie_offset = page[(8 + i * 4)..(11 + i * 4)].unpack('V')[0]
|
84
|
+
cookies_offset.push(cookie_offset)
|
85
|
+
end
|
86
|
+
nread_ptr += 12 + cookies_num * 4
|
87
|
+
read_ptr += pgl
|
88
|
+
cookies_offset.each do |cof|
|
89
|
+
cookie_length = page[cof..(cof + 3)].unpack('V')[0]
|
90
|
+
cookie_bin = page[cof..(cof + cookie_length - 1)]
|
91
|
+
offset_url = page[(cof + 16)..(cof + 19)].unpack('V')[0]
|
92
|
+
offset_name = page[(cof + 20)..(cof + 23)].unpack('V')[0]
|
93
|
+
offset_path = page[(cof + 24)..(cof + 27)].unpack('V')[0]
|
94
|
+
offset_value = page[(cof + 28)..(cof + 31)].unpack('V')[0]
|
95
|
+
url_end = (/\x00/ =~ cookie_bin[offset_url..-1])
|
96
|
+
url = cookie_bin[offset_url, url_end]
|
97
|
+
name_end = (/\x00/ =~ cookie_bin[offset_name..-1])
|
98
|
+
name = cookie_bin[offset_name, name_end]
|
99
|
+
path_end = (/\x00/ =~ cookie_bin[offset_path..-1])
|
100
|
+
path = cookie_bin[offset_path, path_end]
|
101
|
+
value_end = (/\x00/ =~ cookie_bin[offset_value..-1])
|
102
|
+
value = cookie_bin[offset_value, value_end]
|
103
|
+
return value if (/nicovideo\.jp$/ =~ url) && (name == 'user_session')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
return nil
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# To change this template, choose Tools | Templates
|
2
|
+
# and open the template in the editor.
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'sqlite3'
|
6
|
+
require 'inifile'
|
7
|
+
|
8
|
+
module Bnicovideo
|
9
|
+
class UserSession
|
10
|
+
module WinXp
|
11
|
+
def self.init_from_firefox
|
12
|
+
base_path = File.join(ENV['APPDATA'], 'Mozilla', 'Firefox')
|
13
|
+
ini_path = File.join(base_path, 'profiles.ini')
|
14
|
+
ini_hash = IniFile.load(ini_path).to_h
|
15
|
+
profile_path = nil
|
16
|
+
ini_hash.each do |k, v|
|
17
|
+
next unless v['Name'] == 'default'
|
18
|
+
relative = (v['IsRelative'] != '0')
|
19
|
+
input_path = v['Path']
|
20
|
+
if relative
|
21
|
+
profile_path = File.join(base_path, input_path)
|
22
|
+
else
|
23
|
+
profile_path = input_path
|
24
|
+
end
|
25
|
+
sql_path = File.join(profile_path, 'cookies.sqlite')
|
26
|
+
conn = SQLite3::Database.new(sql_path)
|
27
|
+
val = conn.get_first_value("select value from moz_cookies" +
|
28
|
+
" where host='.nicovideo.jp' AND name='user_session'")
|
29
|
+
return val
|
30
|
+
end
|
31
|
+
return nil
|
32
|
+
end
|
33
|
+
def self.init_from_ie
|
34
|
+
cookies_path = File.join(ENV['USERPROFILE'], 'Cookie')
|
35
|
+
Dir.open(cookies_path) do |dir|
|
36
|
+
dir.each do |fn|
|
37
|
+
next unless (/.*@nicovideo.*/ =~ fn)
|
38
|
+
File.open(fn) do |f|
|
39
|
+
cb = f.read
|
40
|
+
cs = cb.split(/\*\n/)
|
41
|
+
cs.each do |c|
|
42
|
+
ca = c.split(/\n/)
|
43
|
+
return ca[1] if ca[0] == 'user_session'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
return nil
|
49
|
+
end
|
50
|
+
def self.init_from_chrome
|
51
|
+
sql_path = File.join(ENV['APPDATA'], 'Google', 'Chrome', 'User Data', 'Default', 'Cookies')
|
52
|
+
conn = SQLite3::Database.new(sql_path)
|
53
|
+
val = conn.get_first_value("select value from cookies" +
|
54
|
+
" where host_key='.nicovideo.jp' AND name='user_session'")
|
55
|
+
conn.close
|
56
|
+
return val
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -9,6 +9,14 @@ require 'inifile'
|
|
9
9
|
module Bnicovideo
|
10
10
|
# User session class
|
11
11
|
class UserSession
|
12
|
+
autoload :Win95, File.join(File.dirname(__FILE__), 'user_session', 'win95.rb')
|
13
|
+
autoload :WinXp, File.join(File.dirname(__FILE__), 'user_session', 'win_xp.rb')
|
14
|
+
autoload :WinVista, File.join(File.dirname(__FILE__), 'user_session', 'win_vista.rb')
|
15
|
+
autoload :MacOsX, File.join(File.dirname(__FILE__), 'user_session', 'mac_os_x.rb')
|
16
|
+
autoload :Linux, File.join(File.dirname(__FILE__), 'user_session', 'linux.rb')
|
17
|
+
OS_LIST = {'winvista' => WinVista, 'winxp' => WinXp, 'win95' => Win95,
|
18
|
+
'macosx' => MacOsX, 'unix' => Linux
|
19
|
+
}
|
12
20
|
# User session ID
|
13
21
|
attr_reader :session_id
|
14
22
|
def initialize(sid)
|
@@ -16,99 +24,39 @@ module Bnicovideo
|
|
16
24
|
end
|
17
25
|
# Get user session from Firefox(3.0 or later)
|
18
26
|
def self.init_from_firefox
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
relative = (v['IsRelative'] != '0')
|
25
|
-
input_path = v['Path']
|
26
|
-
if relative
|
27
|
-
profile_path = File.join(ENV['APPDATA'], 'Mozilla', 'Firefox', input_path)
|
28
|
-
else
|
29
|
-
profile_path = input_path
|
30
|
-
end
|
31
|
-
sql_path = File.join(profile_path, 'cookies.sqlite')
|
32
|
-
conn = SQLite3::Database.new(sql_path)
|
33
|
-
val = conn.get_first_value("select value from moz_cookies" +
|
34
|
-
" where host='.nicovideo.jp' AND name='user_session'")
|
35
|
-
return self.new(val)
|
27
|
+
sess = OS_LIST[Bnicovideo::OsDetector.detect].init_from_firefox
|
28
|
+
if sess
|
29
|
+
return self.new(sess)
|
30
|
+
else
|
31
|
+
return nil
|
36
32
|
end
|
37
|
-
return nil
|
38
33
|
end
|
39
34
|
# Get user session from Google Chrome
|
40
35
|
def self.init_from_chrome
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
36
|
+
sess = OS_LIST[Bnicovideo::OsDetector.detect].init_from_chrome
|
37
|
+
if sess
|
38
|
+
return self.new(sess)
|
39
|
+
else
|
40
|
+
return nil
|
41
|
+
end
|
47
42
|
end
|
48
43
|
# Get user session from Internet Explorer
|
49
44
|
def self.init_from_ie
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
cb = f.read
|
56
|
-
cs = cb.split(/\*\n/)
|
57
|
-
cs.each do |c|
|
58
|
-
ca = c.split(/\n/)
|
59
|
-
return self.new(ca[1]) if ca[0] == 'user_session'
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
45
|
+
sess = OS_LIST[Bnicovideo::OsDetector.detect].init_from_ie
|
46
|
+
if sess
|
47
|
+
return self.new(sess)
|
48
|
+
else
|
49
|
+
return nil
|
63
50
|
end
|
64
|
-
return nil
|
65
51
|
end
|
66
52
|
# Get user session from Safari
|
67
53
|
def self.init_from_safari
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
74
|
-
raise 'Invalid Cookie file' unless bin[0..3] == 'cook'
|
75
|
-
page_num = bin[4..7].unpack('N')[0]
|
76
|
-
pages_length = []
|
77
|
-
page_num.times do |i|
|
78
|
-
page_length = bin[(8 + i * 4)..(11 + i * 4)].unpack('N')[0]
|
79
|
-
pages_length.push(page_length)
|
80
|
-
end
|
81
|
-
read_ptr = 8 + page_num * 4
|
82
|
-
pages_length.each do |pgl|
|
83
|
-
page = bin[read_ptr..(read_ptr + pgl - 1)]
|
84
|
-
cookies_num = page[4..7].unpack('V')[0]
|
85
|
-
nread_ptr = read_ptr
|
86
|
-
cookies_offset = []
|
87
|
-
cookies_num.length.times do |i|
|
88
|
-
cookie_offset = page[(8 + i * 4)..(11 + i * 4)].unpack('V')[0]
|
89
|
-
cookies_offset.push(cookie_offset)
|
90
|
-
end
|
91
|
-
nread_ptr += 12 + cookies_num * 4
|
92
|
-
read_ptr += pgl
|
93
|
-
cookies_offset.each do |cof|
|
94
|
-
cookie_length = page[cof..(cof + 3)].unpack('V')[0]
|
95
|
-
cookie_bin = page[cof..(cof + cookie_length - 1)]
|
96
|
-
offset_url = page[(cof + 16)..(cof + 19)].unpack('V')[0]
|
97
|
-
offset_name = page[(cof + 20)..(cof + 23)].unpack('V')[0]
|
98
|
-
offset_path = page[(cof + 24)..(cof + 27)].unpack('V')[0]
|
99
|
-
offset_value = page[(cof + 28)..(cof + 31)].unpack('V')[0]
|
100
|
-
url_end = (/\x00/ =~ cookie_bin[offset_url..-1])
|
101
|
-
url = cookie_bin[offset_url, url_end]
|
102
|
-
name_end = (/\x00/ =~ cookie_bin[offset_name..-1])
|
103
|
-
name = cookie_bin[offset_name, name_end]
|
104
|
-
path_end = (/\x00/ =~ cookie_bin[offset_path..-1])
|
105
|
-
path = cookie_bin[offset_path, path_end]
|
106
|
-
value_end = (/\x00/ =~ cookie_bin[offset_value..-1])
|
107
|
-
value = cookie_bin[offset_value, value_end]
|
108
|
-
return self.new(value) if (/nicovideo\.jp$/ =~ url) && (name == 'user_session')
|
109
|
-
end
|
54
|
+
sess = OS_LIST[Bnicovideo::OsDetector.detect].init_from_safari
|
55
|
+
if sess
|
56
|
+
return self.new(sess)
|
57
|
+
else
|
58
|
+
return nil
|
110
59
|
end
|
111
|
-
return nil
|
112
60
|
end
|
113
61
|
end
|
114
62
|
end
|
data/lib/bnicovideo/version.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
# To change this template, choose Tools | Templates
|
2
|
+
# and open the template in the editor.
|
3
|
+
|
4
|
+
require 'Win32API'
|
5
|
+
|
6
|
+
module Bnicovideo
|
7
|
+
module WindowsDetector
|
8
|
+
def self.check
|
9
|
+
gvex = Win32API.new('kernel32','GetVersionEx','P','I')
|
10
|
+
buf = [148,0,0,0,0,"\0"*128].pack("LLLLLa128")
|
11
|
+
gvex.call(buf)
|
12
|
+
arr = buf[0,20].unpack("LLLLL")
|
13
|
+
osv = arr[1].to_s
|
14
|
+
if osv == '6'
|
15
|
+
return 'winvista'
|
16
|
+
elsif osv == '5'
|
17
|
+
return 'winxp'
|
18
|
+
else
|
19
|
+
return 'win95'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/bnicovideo.rb
CHANGED
@@ -6,4 +6,6 @@ module Bnicovideo
|
|
6
6
|
autoload :Tag, File.join(File.dirname(__FILE__), 'bnicovideo', 'tag.rb')
|
7
7
|
autoload :UserSession, File.join(File.dirname(__FILE__), 'bnicovideo', 'user_session.rb')
|
8
8
|
autoload :Video, File.join(File.dirname(__FILE__), 'bnicovideo', 'video.rb')
|
9
|
+
autoload :OsDetector, File.join(File.dirname(__FILE__), 'bnicovideo', 'os_detector.rb')
|
10
|
+
autoload :WindowsDetector, File.join(File.dirname(__FILE__), 'bnicovideo', 'windows_detector.rb')
|
9
11
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 0.0.2
|
9
|
+
version: 0.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- MH35
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-
|
17
|
+
date: 2012-04-16 00:00:00 +09:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -64,10 +64,17 @@ files:
|
|
64
64
|
- bnicovideo.gemspec
|
65
65
|
- lib/bnicovideo.rb
|
66
66
|
- lib/bnicovideo/mylist.rb
|
67
|
+
- lib/bnicovideo/os_detector.rb
|
67
68
|
- lib/bnicovideo/tag.rb
|
68
69
|
- lib/bnicovideo/user_session.rb
|
70
|
+
- lib/bnicovideo/user_session/linux.rb
|
71
|
+
- lib/bnicovideo/user_session/mac_os_x.rb
|
72
|
+
- lib/bnicovideo/user_session/win95.rb
|
73
|
+
- lib/bnicovideo/user_session/win_vista.rb
|
74
|
+
- lib/bnicovideo/user_session/win_xp.rb
|
69
75
|
- lib/bnicovideo/version.rb
|
70
76
|
- lib/bnicovideo/video.rb
|
77
|
+
- lib/bnicovideo/windows_detector.rb
|
71
78
|
- nbproject/project.properties
|
72
79
|
- nbproject/project.xml
|
73
80
|
has_rdoc: true
|