Revision | 797f1f0836139bf851fe3191321ebc0e54809f90 (tree) |
---|---|
Time | 2012-03-24 23:52:21 |
Author | qwerty2501 <qwerty2501@user...> |
Commiter | qwerty2501 |
ファイアフォックスクッキー取得処理実装
@@ -81,7 +81,16 @@ UInt FormatTime(NString &str,const NString &format,tm* timeptr){ | ||
81 | 81 | |
82 | 82 | |
83 | 83 | |
84 | +Int ReadIni(const NString &path,const NString §ion,const NString &key,NString &val){ | |
84 | 85 | |
86 | + std::array<NChar,_MAX_PATH> buf; | |
87 | + Int result = GetPrivateProfileString(section.c_str(),key.c_str(),_T(""),buf.data(),buf.size(),path.c_str()); | |
88 | + | |
89 | + val = buf.data(); | |
90 | + | |
91 | + return result; | |
92 | + | |
93 | +} | |
85 | 94 | |
86 | 95 | |
87 | 96 |
@@ -34,6 +34,11 @@ extern Void GetnliteUserId(NString &id); | ||
34 | 34 | |
35 | 35 | |
36 | 36 | /// |
37 | +///iniファイル読み込み | |
38 | +/// | |
39 | +extern Int ReadIni(const NString &path,const NString §ion,const NString &key,NString &val); | |
40 | + | |
41 | +/// | |
37 | 42 | ///特定バイト列検索 |
38 | 43 | /// |
39 | 44 | template<typename T> |
@@ -320,12 +320,13 @@ Bool NDeleteFile(const NString &fileName){ | ||
320 | 320 | } |
321 | 321 | |
322 | 322 | |
323 | + | |
323 | 324 | static Bool GetGetFolderPath(Int dil,NString &dir){ |
324 | 325 | |
325 | 326 | NChar buffer[_MAX_PATH]; |
326 | - BOOL result = SHGetFolderPath(0,dil,0,SHGFP_TYPE_CURRENT,buffer); | |
327 | + CHResult result = SHGetFolderPath(0,dil,0,SHGFP_TYPE_CURRENT,buffer); | |
327 | 328 | dir = buffer; |
328 | - return result != FALSE ? true :false; | |
329 | + return result.IsS_OK(); | |
329 | 330 | |
330 | 331 | } |
331 | 332 |
@@ -334,6 +335,10 @@ Bool GetAppLocalDataDirectry(NString &dir){ | ||
334 | 335 | return GetGetFolderPath(CSIDL_LOCAL_APPDATA,dir); |
335 | 336 | |
336 | 337 | } |
338 | +Bool GetAppDataDirectry(NString &dir){ | |
339 | + | |
340 | + return GetGetFolderPath(CSIDL_APPDATA,dir); | |
341 | +} | |
337 | 342 | |
338 | 343 | Bool GetTempDirectry(NString &dir){ |
339 | 344 |
@@ -45,6 +45,7 @@ static_assert(sizeof(CHResult) <= 4,"CHResult size error"); | ||
45 | 45 | |
46 | 46 | |
47 | 47 | |
48 | + | |
48 | 49 | /// |
49 | 50 | ///OSバージョン取得 |
50 | 51 | /// |
@@ -62,6 +63,7 @@ extern Bool NDeleteFile(const NString &fileName); | ||
62 | 63 | /// |
63 | 64 | extern Bool GetAppLocalDataDirectry(NString &dir); |
64 | 65 | |
66 | +extern Bool GetAppDataDirectry(NString &dir); | |
65 | 67 | |
66 | 68 | extern Bool GetTempDirectry(NString &dir); |
67 | 69 |
@@ -2,10 +2,13 @@ | ||
2 | 2 | #include "firefoxcookiegetter.h" |
3 | 3 | |
4 | 4 | |
5 | + | |
5 | 6 | #include "namespace_start.h" |
6 | 7 | |
8 | +browsertype::BrowserType CFireFoxCookieGetter::BT = browsertype::FIREFOX; | |
9 | + | |
7 | 10 | CFireFoxCookieGetter::CFireFoxCookieGetter(): |
8 | -SQLiteCookieGetterT<CFireFoxCookieGetter>(_T("SELECT a.name, a.value FROM moz_cookies a WHERE a.name = '%1%' AND a.baseDomain = '%2%' "),CreateCookiePath()) | |
11 | +SQLiteCookieGetterT<CFireFoxCookieGetter>(_T("SELECT a.value FROM moz_cookies a WHERE a.name = '%1%' AND a.baseDomain = '%2%' "),CreateCookiePath()) | |
9 | 12 | { |
10 | 13 | |
11 | 14 | } |
@@ -28,7 +31,59 @@ Bool CFireFoxCookieGetter::GetCookieInternal(const NString &domein,const NString | ||
28 | 31 | return result; |
29 | 32 | } |
30 | 33 | |
31 | -Bool Fancta(const Byte * data,ULong dataSize,const NString & domein,const NString &name,CCookie &cookie){ | |
34 | + | |
35 | + | |
36 | +NString CFireFoxCookieGetter::CreateCookiePath(){ | |
37 | + | |
38 | + NString appdataPath; | |
39 | + NString iniDir(_T("\\Mozilla\\Firefox\\")); | |
40 | + NString cookieFileName(_T("cookies.sqlite")); | |
41 | + NString val; | |
42 | + if(GetAppDataDirectry(appdataPath)){ | |
43 | + | |
44 | + NString iniPath = appdataPath + iniDir + _T("profiles.ini"); | |
45 | + NString cookiePathtmp; | |
46 | + ReadIni(iniPath,_T("Profile0"),_T("Path"),cookiePathtmp); | |
47 | + | |
48 | + nregex reg(_T("/")); | |
49 | + cookiePathtmp = std::regex_replace(cookiePathtmp,reg,NString(_T("\\"))); | |
50 | + NString val2; | |
51 | + ReadIni(iniPath,_T("Profile0"),_T("IsRelative"),val2); | |
52 | + Int patern = boost::lexical_cast<Int>(val2); | |
53 | + | |
54 | + switch(patern){ | |
55 | + | |
56 | + case 0: | |
57 | + val = cookiePathtmp + cookieFileName; | |
58 | + break; | |
59 | + | |
60 | + | |
61 | + case 1: | |
62 | + val = appdataPath + iniDir + cookiePathtmp + _T("\\") + cookieFileName; | |
63 | + break; | |
64 | + }; | |
65 | + } | |
66 | + | |
67 | + return val; | |
68 | +} | |
69 | +Bool CFireFoxCookieGetter::Fancta(const Byte * data,ULong dataSize,const NString & domein,const NString &name,CCookie &cookie){ | |
70 | + | |
71 | + | |
72 | + MString mdomein; | |
73 | + MString startdomeinname; | |
74 | + | |
75 | + ToUTF8(mdomein,_T(".") + domein); | |
76 | + ToUTF8(startdomeinname,domein+name); | |
77 | + | |
78 | + const Byte * startPointer = memmem(data,dataSize,startdomeinname.c_str(),startdomeinname.size())+ startdomeinname.size(); | |
79 | + | |
80 | + if(startPointer != nullptr){ | |
81 | + U16String cookieValue; | |
82 | + UTF8ToUTF16(cookieValue,startPointer,strstr(startPointer,mdomein.c_str()) - startPointer); | |
83 | + cookie.SetCookieValue(cookieValue); | |
84 | + return true; | |
85 | + } | |
86 | + | |
32 | 87 | |
33 | 88 | return false; |
34 | 89 | } |
@@ -17,4 +17,5 @@ | ||
17 | 17 | #include <regex> |
18 | 18 | #include <boost\test\unit_test.hpp> |
19 | 19 | #include <boost/format.hpp> |
20 | +#include <boost\lexical_cast.hpp> | |
20 | 21 | #include <atlfile.h> |
\ No newline at end of file |
@@ -86,8 +86,8 @@ Void UnitTest(){ | ||
86 | 86 | exceptionflag = true; |
87 | 87 | } |
88 | 88 | |
89 | - BOOST_CHECK_MESSAGE(exceptionflag == false,"chromeのクッキー検索中に例外が発生しました"); | |
90 | - BOOST_CHECK_MESSAGE(result == true,"chromeのクッキーが見つかりませんでした"); | |
89 | + BOOST_CHECK_MESSAGE(exceptionflag == false,"クッキー検索中に例外が発生しました"); | |
90 | + BOOST_CHECK_MESSAGE(result == true,"クッキーが見つかりませんでした"); | |
91 | 91 | |
92 | 92 | exceptionflag = true; |
93 | 93 | Bool result2 = false; |
@@ -101,15 +101,15 @@ Void UnitTest(){ | ||
101 | 101 | exceptionflag = true; |
102 | 102 | } |
103 | 103 | |
104 | - BOOST_CHECK_MESSAGE(result2 == true,"強制検索でchromeのクッキーが見つかりませんでした"); | |
104 | + BOOST_CHECK_MESSAGE(result2 == true,"クッキーが見つかりませんでした"); | |
105 | 105 | |
106 | 106 | if(result && result2){ |
107 | 107 | BOOST_CHECK_MESSAGE(cookie.GetCookieValue() == cookie2.GetCookieValue(),"正規の方法で取得したクッキーと強制検索で取得したクッキーが違います"); |
108 | 108 | } |
109 | 109 | } |
110 | - /* | |
110 | + | |
111 | 111 | { |
112 | - BOOST_CHECK_MESSAGE(!CFireFoxCookieGetter::CreateCookiePath().empty(),"クロームのクッキーパス取得に失敗しました"); | |
112 | + BOOST_CHECK_MESSAGE(!CFireFoxCookieGetter::CreateCookiePath().empty(),"クッキーパス取得に失敗しました"); | |
113 | 113 | CFireFoxCookieGetter firefoxcookiegetter; |
114 | 114 | Bool result; |
115 | 115 | exceptionflag = false; |
@@ -124,14 +124,14 @@ Void UnitTest(){ | ||
124 | 124 | exceptionflag = true; |
125 | 125 | } |
126 | 126 | |
127 | - BOOST_CHECK_MESSAGE(exceptionflag == false,"chromeのクッキー検索中に例外が発生しました"); | |
128 | - BOOST_CHECK_MESSAGE(result == true,"chromeのクッキーが見つかりませんでした"); | |
127 | + BOOST_CHECK_MESSAGE(exceptionflag == false,"クッキー検索中に例外が発生しました"); | |
128 | + BOOST_CHECK_MESSAGE(result == true,"クッキーが見つかりませんでした"); | |
129 | 129 | |
130 | 130 | exceptionflag = true; |
131 | 131 | Bool result2 = false; |
132 | 132 | CCookie cookie2; |
133 | 133 | try{ |
134 | - result2 = ForceSearch(firefoxcookiegetter.cookieFilePath,domein,name,cookie2,CChromeCookieGetter::Fancta); | |
134 | + result2 = ForceSearch(firefoxcookiegetter.cookieFilePath,domein,name,cookie2,CFireFoxCookieGetter::Fancta); | |
135 | 135 | |
136 | 136 | |
137 | 137 | } catch(Exception &e3){ |
@@ -139,13 +139,13 @@ Void UnitTest(){ | ||
139 | 139 | exceptionflag = true; |
140 | 140 | } |
141 | 141 | |
142 | - BOOST_CHECK_MESSAGE(result2 == true,"強制検索でchromeのクッキーが見つかりませんでした"); | |
142 | + BOOST_CHECK_MESSAGE(result2 == true,"クッキーが見つかりませんでした"); | |
143 | 143 | |
144 | 144 | if(result && result2){ |
145 | 145 | BOOST_CHECK_MESSAGE(cookie.GetCookieValue() == cookie2.GetCookieValue(),"正規の方法で取得したクッキーと強制検索で取得したクッキーが違います"); |
146 | 146 | } |
147 | 147 | } |
148 | - */ | |
148 | + | |
149 | 149 | return; |
150 | 150 | |
151 | 151 | } |