• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision797f1f0836139bf851fe3191321ebc0e54809f90 (tree)
Zeit2012-03-24 23:52:21
Autorqwerty2501 <qwerty2501@user...>
Commiterqwerty2501

Log Message

ファイアフォックスクッキー取得処理実装

Ändern Zusammenfassung

Diff

Binary files a/nlite.suo and b/nlite.suo differ
--- a/nlite_common/function.cpp
+++ b/nlite_common/function.cpp
@@ -81,7 +81,16 @@ UInt FormatTime(NString &str,const NString &format,tm* timeptr){
8181
8282
8383
84+Int ReadIni(const NString &path,const NString &section,const NString &key,NString &val){
8485
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+}
8594
8695
8796
--- a/nlite_common/function.h
+++ b/nlite_common/function.h
@@ -34,6 +34,11 @@ extern Void GetnliteUserId(NString &id);
3434
3535
3636 ///
37+///iniファイル読み込み
38+///
39+extern Int ReadIni(const NString &path,const NString &section,const NString &key,NString &val);
40+
41+///
3742 ///特定バイト列検索
3843 ///
3944 template<typename T>
--- a/nlite_common/windowsAPI.cpp
+++ b/nlite_common/windowsAPI.cpp
@@ -320,12 +320,13 @@ Bool NDeleteFile(const NString &fileName){
320320 }
321321
322322
323+
323324 static Bool GetGetFolderPath(Int dil,NString &dir){
324325
325326 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);
327328 dir = buffer;
328- return result != FALSE ? true :false;
329+ return result.IsS_OK();
329330
330331 }
331332
@@ -334,6 +335,10 @@ Bool GetAppLocalDataDirectry(NString &dir){
334335 return GetGetFolderPath(CSIDL_LOCAL_APPDATA,dir);
335336
336337 }
338+Bool GetAppDataDirectry(NString &dir){
339+
340+ return GetGetFolderPath(CSIDL_APPDATA,dir);
341+}
337342
338343 Bool GetTempDirectry(NString &dir){
339344
--- a/nlite_common/windowsAPI.h
+++ b/nlite_common/windowsAPI.h
@@ -45,6 +45,7 @@ static_assert(sizeof(CHResult) <= 4,"CHResult size error");
4545
4646
4747
48+
4849 ///
4950 ///OSバージョン取得
5051 ///
@@ -62,6 +63,7 @@ extern Bool NDeleteFile(const NString &fileName);
6263 ///
6364 extern Bool GetAppLocalDataDirectry(NString &dir);
6465
66+extern Bool GetAppDataDirectry(NString &dir);
6567
6668 extern Bool GetTempDirectry(NString &dir);
6769
--- a/nlite_cookie/firefoxcookiegetter.cpp
+++ b/nlite_cookie/firefoxcookiegetter.cpp
@@ -2,10 +2,13 @@
22 #include "firefoxcookiegetter.h"
33
44
5+
56 #include "namespace_start.h"
67
8+browsertype::BrowserType CFireFoxCookieGetter::BT = browsertype::FIREFOX;
9+
710 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())
912 {
1013
1114 }
@@ -28,7 +31,59 @@ Bool CFireFoxCookieGetter::GetCookieInternal(const NString &domein,const NString
2831 return result;
2932 }
3033
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+
3287
3388 return false;
3489 }
--- a/nlite_cookie/stdafx.h
+++ b/nlite_cookie/stdafx.h
@@ -17,4 +17,5 @@
1717 #include <regex>
1818 #include <boost\test\unit_test.hpp>
1919 #include <boost/format.hpp>
20+#include <boost\lexical_cast.hpp>
2021 #include <atlfile.h>
\ No newline at end of file
--- a/nlite_cookie/unit_test.cpp
+++ b/nlite_cookie/unit_test.cpp
@@ -86,8 +86,8 @@ Void UnitTest(){
8686 exceptionflag = true;
8787 }
8888
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,"クッキーが見つかりませんでした");
9191
9292 exceptionflag = true;
9393 Bool result2 = false;
@@ -101,15 +101,15 @@ Void UnitTest(){
101101 exceptionflag = true;
102102 }
103103
104- BOOST_CHECK_MESSAGE(result2 == true,"強制検索でchromeのクッキーが見つかりませんでした");
104+ BOOST_CHECK_MESSAGE(result2 == true,"クッキーが見つかりませんでした");
105105
106106 if(result && result2){
107107 BOOST_CHECK_MESSAGE(cookie.GetCookieValue() == cookie2.GetCookieValue(),"正規の方法で取得したクッキーと強制検索で取得したクッキーが違います");
108108 }
109109 }
110- /*
110+
111111 {
112- BOOST_CHECK_MESSAGE(!CFireFoxCookieGetter::CreateCookiePath().empty(),"クロームのクッキーパス取得に失敗しました");
112+ BOOST_CHECK_MESSAGE(!CFireFoxCookieGetter::CreateCookiePath().empty(),"クッキーパス取得に失敗しました");
113113 CFireFoxCookieGetter firefoxcookiegetter;
114114 Bool result;
115115 exceptionflag = false;
@@ -124,14 +124,14 @@ Void UnitTest(){
124124 exceptionflag = true;
125125 }
126126
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,"クッキーが見つかりませんでした");
129129
130130 exceptionflag = true;
131131 Bool result2 = false;
132132 CCookie cookie2;
133133 try{
134- result2 = ForceSearch(firefoxcookiegetter.cookieFilePath,domein,name,cookie2,CChromeCookieGetter::Fancta);
134+ result2 = ForceSearch(firefoxcookiegetter.cookieFilePath,domein,name,cookie2,CFireFoxCookieGetter::Fancta);
135135
136136
137137 } catch(Exception &e3){
@@ -139,13 +139,13 @@ Void UnitTest(){
139139 exceptionflag = true;
140140 }
141141
142- BOOST_CHECK_MESSAGE(result2 == true,"強制検索でchromeのクッキーが見つかりませんでした");
142+ BOOST_CHECK_MESSAGE(result2 == true,"クッキーが見つかりませんでした");
143143
144144 if(result && result2){
145145 BOOST_CHECK_MESSAGE(cookie.GetCookieValue() == cookie2.GetCookieValue(),"正規の方法で取得したクッキーと強制検索で取得したクッキーが違います");
146146 }
147147 }
148- */
148+
149149 return;
150150
151151 }