• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

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

Commit MetaInfo

Revisiónf7ffbeb6b8f90a1cb17fbcc0f22718cf41cd827c (tree)
Tiempo2012-03-25 17:21:44
Autorqwerty2501 <qwerty2501@user...>
Commiterqwerty2501

Log Message

IEクッキー取得実装途中

Cambiar Resumen

Diferencia incremental

Binary files a/nlite.suo and b/nlite.suo differ
--- a/nlite_common/define.h
+++ b/nlite_common/define.h
@@ -15,7 +15,7 @@ typedef void Void;
1515
1616 typedef char Char;
1717
18-typedef char Byte;
18+typedef unsigned char Byte;
1919
2020 typedef unsigned char UChar;
2121
--- a/nlite_common/nexception.h
+++ b/nlite_common/nexception.h
@@ -1,7 +1,7 @@
11 #pragma once
22
33
4-#include <stdexcept>
4+
55 #include "define.h"
66 #include "windowsAPI.h"
77 #include "bugreport.h"
--- a/nlite_common/raii.h
+++ b/nlite_common/raii.h
@@ -1,7 +1,7 @@
11 #pragma once
22
3-#include "nexception.h"
4-#include <boost\utility.hpp>
3+
4+
55 #include "namespace_start.h"
66 template<typename T,typename H>
77 class RAIIT:public boost::noncopyable{
@@ -45,12 +45,6 @@ public:
4545
4646 }
4747
48- Void Dispose(){
49-
50- THROW_EXCEPTION(Exception,_T("RAIIが実装されていません"));
51-
52- }
53-
5448
5549
5650 };
--- a/nlite_common/stdafx.h
+++ b/nlite_common/stdafx.h
@@ -23,4 +23,6 @@
2323 #include <regex>
2424 #include <array>
2525 #include <boost\test\unit_test.hpp>
26-#include <boost\lexical_cast.hpp>
\ No newline at end of file
26+#include <boost\lexical_cast.hpp>
27+#include <boost\utility.hpp>
28+#include <stdexcept>
\ No newline at end of file
--- a/nlite_common/windowsAPI.cpp
+++ b/nlite_common/windowsAPI.cpp
@@ -256,6 +256,10 @@ const NString &GetWindowsVersion(){
256256
257257
258258
259+
260+//
261+//HRESULT 管理クラス
262+///////////////////////////////////////////////////////////////////
259263 CHResult::CHResult(){}
260264
261265 CHResult::CHResult(HRESULT hResult):m_hResult(hResult){}
@@ -294,6 +298,83 @@ Bool operator==(const CHResult &result,HRESULT hResult){
294298 return hResult == result.m_hResult;
295299 }
296300
301+
302+ //
303+ //HKEY管理クラス
304+ ///////////////////////////////////////////////////
305+
306+ Void CRegistryKey::Dispose(){
307+
308+ RegCloseKey( m_handle);
309+ m_handle = nullptr;
310+ }
311+
312+ CHResult CRegistryKey::OpenKey(HKEY hkey,const NString &subKeystr,DWORD options,REGSAM samDesired){
313+
314+ return RegOpenKeyEx(hkey,subKeystr.c_str(),options,samDesired,&m_handle);
315+ }
316+
317+ CHResult CRegistryKey::QueryValue(const NString &valueName,NString &val,LPDWORD lpType,LPDWORD lpReserved){
318+
319+ ValueList valList;
320+ CHResult hresult = QueryValue(valueName,valList);
321+
322+ val = reinterpret_cast<const NChar*>(*valList.data());
323+
324+ return hresult;
325+
326+
327+ }
328+
329+CHResult CRegistryKey::QueryValue(const NString &valueName,Int &val,LPDWORD lpType,LPDWORD lpReserved){
330+
331+ ValueList valList;
332+ CHResult hresult = QueryValue(valueName,valList);
333+
334+ val = *reinterpret_cast<const Int*>(valList.data());
335+
336+ return hresult;
337+}
338+
339+ CHResult CRegistryKey::QueryValue(const NString &valueName,ValueList &valueList,LPDWORD lpType,LPDWORD lpReserved){
340+
341+ DWORD data;
342+ RegQueryValueEx(m_handle,valueName.c_str(),lpReserved,lpType,nullptr,&data);
343+
344+
345+
346+ valueList.resize(data);
347+
348+
349+ return RegQueryValueEx(m_handle,valueName.c_str(),lpReserved,lpType,&valueList[0],&data);
350+ }
351+
352+ CRegistryKey::operator HKEY(){
353+
354+ return m_handle;
355+
356+ }
357+
358+
359+ Void CFindFirstFile::Dispose(){
360+
361+ FindClose(m_handle);
362+ m_handle = nullptr;
363+ }
364+
365+ Bool CFindFirstFile::NextFile(WIN32_FIND_DATA &findData){
366+
367+ return FindNextFile(m_handle,&findData);
368+ }
369+
370+HANDLE CFindFirstFile::Find(const NString &fileName,WIN32_FIND_DATA &findData){
371+
372+
373+ m_handle = FindFirstFile(fileName.c_str(),&findData);
374+
375+ return m_handle;
376+}
377+
297378 Void GetWindowsErrorMessage(NString &buf,DWORD lastErrorCode){
298379
299380 NChar *lpMsgBuf;
@@ -321,7 +402,7 @@ Bool NDeleteFile(const NString &fileName){
321402
322403
323404
324-static Bool GetGetFolderPath(Int dil,NString &dir){
405+static Bool GetFolderPath(Int dil,NString &dir){
325406
326407 NChar buffer[_MAX_PATH];
327408 CHResult result = SHGetFolderPath(0,dil,0,SHGFP_TYPE_CURRENT,buffer);
@@ -332,17 +413,22 @@ static Bool GetGetFolderPath(Int dil,NString &dir){
332413
333414 Bool GetAppLocalDataDirectry(NString &dir){
334415
335- return GetGetFolderPath(CSIDL_LOCAL_APPDATA,dir);
416+ return GetFolderPath(CSIDL_LOCAL_APPDATA,dir);
336417
337418 }
338419 Bool GetAppDataDirectry(NString &dir){
339420
340- return GetGetFolderPath(CSIDL_APPDATA,dir);
421+ return GetFolderPath(CSIDL_APPDATA,dir);
422+}
423+
424+Bool GetCookieDirectry(NString &dir){
425+
426+ return GetFolderPath(CSIDL_COOKIES,dir);
341427 }
342428
343429 Bool GetTempDirectry(NString &dir){
344430
345- return GetGetFolderPath(CSIDL_TEMPLATES,dir);
431+ return GetFolderPath(CSIDL_TEMPLATES,dir);
346432 }
347433
348434
--- a/nlite_common/windowsAPI.h
+++ b/nlite_common/windowsAPI.h
@@ -3,7 +3,7 @@
33 #include <Windows.h>
44 #include "unit_test.h"
55 #include "define.h"
6-
6+#include "raii.h"
77
88 #include "namespace_start.h"
99
@@ -44,6 +44,47 @@ static_assert(sizeof(CHResult) <= 4,"CHResult size error");
4444
4545
4646
47+///
48+///レジストリキークラス
49+///
50+class CRegistryKey:public RAIIT<CRegistryKey,HKEY>{
51+
52+public:
53+ typedef std::vector<Byte> ValueList;
54+ Void Dispose();
55+
56+ CHResult OpenKey(HKEY hkey,const NString &subKeystr,DWORD options = 0,REGSAM samDesired = KEY_READ);
57+
58+
59+ CHResult QueryValue(const NString &valueName,NString &val,LPDWORD lpType = nullptr,LPDWORD lpReserved = nullptr);
60+
61+ CHResult QueryValue(const NString &valueName,Int &val,LPDWORD lpType = nullptr,LPDWORD lpReserved = nullptr);
62+private:
63+
64+ CHResult QueryValue(const NString &valueName,ValueList &valueList,LPDWORD lpType = nullptr,LPDWORD lpReserved = nullptr);
65+
66+
67+ operator HKEY();
68+
69+};
70+
71+
72+
73+///
74+///ファインドファーストファイル
75+///
76+class CFindFirstFile:public RAIIT<CFindFirstFile,HANDLE>{
77+
78+
79+public:
80+ Void Dispose();
81+
82+ Bool NextFile(WIN32_FIND_DATA &findData);
83+
84+ HANDLE Find(const NString &fileName,WIN32_FIND_DATA &findData);
85+
86+
87+};
4788
4889
4990 ///
@@ -65,6 +106,8 @@ extern Bool GetAppLocalDataDirectry(NString &dir);
65106
66107 extern Bool GetAppDataDirectry(NString &dir);
67108
109+extern Bool GetCookieDirectry(NString &dir);
110+
68111 extern Bool GetTempDirectry(NString &dir);
69112
70113
--- a/nlite_cookie/chromecookiegetter.cpp
+++ b/nlite_cookie/chromecookiegetter.cpp
@@ -54,7 +54,7 @@ Bool CChromeCookieGetter::Fancta(const Byte * data,ULong dataSize,const NString
5454
5555 MString searchString;
5656 ToUTF8(searchString,domein+name);
57- const Byte *startPointer = memmem(data,dataSize,searchString.c_str(),searchString.size()) +searchString.size() ;
57+ const Char *startPointer = reinterpret_cast<const Char*>(memmem(data,dataSize,searchString.c_str(),searchString.size()) +searchString.size()) ;
5858
5959 U16String cookieValue;
6060 UTF8ToUTF16(cookieValue,startPointer,strstr(startPointer,"/") - startPointer);
--- a/nlite_cookie/cookieGetter.h
+++ b/nlite_cookie/cookieGetter.h
@@ -91,4 +91,8 @@ Bool ForceSearch(const NString &fileName,const NString &domein,const NString &na
9191 return result;
9292 }
9393
94+
95+
96+
97+
9498 #include "namespace_end.h"
\ No newline at end of file
--- a/nlite_cookie/define.h
+++ b/nlite_cookie/define.h
@@ -22,6 +22,8 @@ namespace resultcode{
2222 enum ResultCode:Byte{
2323 OK = 0,
2424 ERR_SQLITE = 1,
25+ ERR_IEAPI = 2,
26+ ERR_IEAPI_SEC = 3,
2527 UNDEFINED = 127
2628 };
2729 }
--- a/nlite_cookie/firefoxcookiegetter.cpp
+++ b/nlite_cookie/firefoxcookiegetter.cpp
@@ -75,7 +75,7 @@ Bool CFireFoxCookieGetter::Fancta(const Byte * data,ULong dataSize,const NString
7575 ToUTF8(mdomein,_T(".") + domein);
7676 ToUTF8(startdomeinname,domein+name);
7777
78- const Byte * startPointer = memmem(data,dataSize,startdomeinname.c_str(),startdomeinname.size())+ startdomeinname.size();
78+ const Char * startPointer = reinterpret_cast<const Char*>(memmem(data,dataSize,startdomeinname.c_str(),startdomeinname.size())+ startdomeinname.size());
7979
8080 if(startPointer != nullptr){
8181 U16String cookieValue;
--- /dev/null
+++ b/nlite_cookie/ieapicookiegetter.h
@@ -0,0 +1,121 @@
1+#pragma once
2+
3+#include <nlite_common\define.h>
4+#include <nlite_common\windowsAPI.h>
5+#include <iepmapi.h>
6+#include <WinInet.h>
7+#include "cookieGetter.h"
8+
9+
10+#include "namespace_start.h"
11+template<typename T>
12+class CIEAPICookieGetterT:public CCookieGetterT<T>{
13+
14+protected :
15+ NString normalDirectry;
16+
17+public:
18+
19+ CIEAPICookieGetterT(){
20+
21+ GetCookieDirectry(normalDirectry);
22+
23+ }
24+
25+protected:
26+
27+
28+ CCookieGetResult GetCookieIEAPI(const NString &domein,const NString &name,CCookie &cookie,Bool securytyFlag,DWORD flags = 0){
29+
30+ std::vector<NChar> buf;
31+ buf.resize(4096);
32+ CCookieGetResult result(BT);
33+ DWORD dwCookieBufSize = buf.size();
34+ CHResult hresult;
35+ NString url = _T("http://") + domein;
36+ if(securytyFlag){
37+
38+ hresult = IEGetProtectedModeCookie(url.c_str(),name.c_str(),&buf[0],&dwCookieBufSize,flags);
39+
40+ } else if(InternetGetCookie(url.c_str(),name.c_str(),&buf[0],&dwCookieBufSize)){
41+
42+ hresult = S_OK;
43+
44+ } else {
45+
46+ hresult = GetLastError();
47+
48+ }
49+
50+
51+ if(hresult.IsSucceded()){
52+
53+ cookie.SetCookieValue(buf.data());
54+ result.SetFindFlag(true);
55+ } else {
56+
57+
58+ result.SetResultCode(securytyFlag ? resultcode::ERR_IEAPI_SEC : resultcode::ERR_IEAPI);
59+ result.SetHResult(hresult);
60+
61+
62+ }
63+
64+ return result;
65+
66+ }
67+
68+protected:
69+
70+ static Bool Fancta(const Byte * data,ULong dataSize,const NString & domein,const NString &name,CCookie &cookie){
71+
72+
73+ return false;
74+ }
75+
76+ template<typename F>
77+ CCookieGetResult ForceSearchFiles(const NString &cookieDir,const NString &domein,const NString &name,CCookie &cookie,F func){
78+
79+ CCookieGetResult result(BT);
80+ CFindFirstFile findfirst;
81+ NString searchFiles = cookieDir + _T("\\?*.txt");
82+ NString targetFileName;
83+ WIN32_FIND_DATA findData;
84+
85+
86+
87+ do{
88+ if(findfirst.Find(searchFiles,findData) != INVALID_HANDLE_VALUE)break;
89+
90+ if((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == false){
91+
92+ targetFileName = (cookieDir + _T("\\")) + findData.cFileName;
93+
94+ if(ForceSearch(targetFileName,domein,name,cookie,func)){
95+
96+ result.SetFindFlag(true);
97+ }
98+ }
99+
100+ }while(findfirst.NextFile(findData));
101+
102+
103+
104+
105+ return result;
106+ }
107+
108+
109+
110+
111+
112+
113+
114+
115+};
116+
117+#include "namespace_end.h"
118+
119+
120+#pragma comment(lib,"WinInet.lib")
121+#pragma comment(lib,"iepmapi.lib")
\ No newline at end of file
--- /dev/null
+++ b/nlite_cookie/iecookiegetter.cpp
@@ -0,0 +1,56 @@
1+#include "stdafx.h"
2+#include "iecookiegetter.h"
3+
4+#include "namespace_start.h"
5+
6+browsertype::BrowserType CIECookieGetter::BT = browsertype::IE;
7+
8+
9+CIECookieGetter::CIECookieGetter(){
10+
11+ securityCookiedir = this->normalDirectry + _T("\\Low");
12+}
13+
14+Bool CIECookieGetter::GetCookieInternal(const NString &domein,const NString &name,CCookie &cookie){
15+
16+ NString url = _T("http://") + domein;
17+ Bool secFlag = IEIsSecurityMode();
18+ CCookieGetResult result = this->GetCookieIEAPI(url,name,cookie,secFlag);
19+
20+ if(result.GetResultCode() != resultcode::OK){
21+
22+ resultList.push_back(result);
23+
24+ }
25+
26+
27+ if(!result.IsFound()){
28+
29+ CIECookieGetter::ForceSearchFiles(secFlag ? this->securityCookiedir : this->normalDirectry,domein,name,cookie,CIECookieGetter::Fancta);
30+ }
31+
32+ return result.IsFound();
33+}
34+
35+Bool CIECookieGetter::IEIsSecurityMode(){
36+
37+ CRegistryKey regkey;
38+ if(!regkey.OpenKey(HKEY_CURRENT_USER,_T("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3")).IsS_OK()){
39+
40+ THROW_EXCEPTION(Exception,_T("レジストリキーが開けませんでした"));
41+ }
42+
43+ Int securityMode;
44+ if(!regkey.QueryValue(_T("2500"),securityMode).IsS_OK()){
45+
46+ return false;
47+ }
48+
49+
50+
51+ return securityMode == 0;
52+}
53+
54+
55+
56+#include "namespace_end.h"
\ No newline at end of file
--- /dev/null
+++ b/nlite_cookie/iecookiegetter.h
@@ -0,0 +1,28 @@
1+#pragma once
2+
3+#include "ieapicookiegetter.h"
4+
5+#include "namespace_start.h"
6+class CIECookieGetter:public CIEAPICookieGetterT<CIECookieGetter>{
7+ friend Void UnitTest();
8+
9+private:
10+ NString securityCookiedir;
11+
12+public:
13+
14+ CIECookieGetter();
15+
16+
17+ Bool GetCookieInternal(const NString &domein,const NString &name,CCookie &cookie);
18+
19+
20+
21+
22+private:
23+
24+ static Bool IEIsSecurityMode();
25+
26+
27+};
28+#include "namespace_end.h"
\ No newline at end of file
--- a/nlite_cookie/nlite_cookie.vcxproj
+++ b/nlite_cookie/nlite_cookie.vcxproj
@@ -110,6 +110,8 @@
110110 <ClInclude Include="define.h" />
111111 <ClInclude Include="filecookiegetter.h" />
112112 <ClInclude Include="firefoxcookiegetter.h" />
113+ <ClInclude Include="ieapicookiegetter.h" />
114+ <ClInclude Include="iecookiegetter.h" />
113115 <ClInclude Include="namespace_end.h" />
114116 <ClInclude Include="namespace_start.h" />
115117 <ClInclude Include="sqlitecookiegetter.h" />
@@ -122,6 +124,7 @@
122124 <ClCompile Include="cookie.cpp" />
123125 <ClCompile Include="cookieGetResult.cpp" />
124126 <ClCompile Include="firefoxcookiegetter.cpp" />
127+ <ClCompile Include="iecookiegetter.cpp" />
125128 <ClCompile Include="stdafx.cpp">
126129 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
127130 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='UnitTest|Win32'">Create</PrecompiledHeader>
--- a/nlite_cookie/nlite_cookie.vcxproj.filters
+++ b/nlite_cookie/nlite_cookie.vcxproj.filters
@@ -60,6 +60,12 @@
6060 <ClInclude Include="firefoxcookiegetter.h">
6161 <Filter>ヘッダー ファイル</Filter>
6262 </ClInclude>
63+ <ClInclude Include="ieapicookiegetter.h">
64+ <Filter>ヘッダー ファイル</Filter>
65+ </ClInclude>
66+ <ClInclude Include="iecookiegetter.h">
67+ <Filter>ヘッダー ファイル</Filter>
68+ </ClInclude>
6369 </ItemGroup>
6470 <ItemGroup>
6571 <ClCompile Include="stdafx.cpp">
@@ -80,5 +86,8 @@
8086 <ClCompile Include="firefoxcookiegetter.cpp">
8187 <Filter>ソース ファイル</Filter>
8288 </ClCompile>
89+ <ClCompile Include="iecookiegetter.cpp">
90+ <Filter>ソース ファイル</Filter>
91+ </ClCompile>
8392 </ItemGroup>
8493 </Project>
\ No newline at end of file
--- a/nlite_cookie/stdafx.h
+++ b/nlite_cookie/stdafx.h
@@ -18,4 +18,4 @@
1818 #include <boost\test\unit_test.hpp>
1919 #include <boost/format.hpp>
2020 #include <boost\lexical_cast.hpp>
21-#include <atlfile.h>
\ No newline at end of file
21+#include <atlfile.h>
--- a/nlite_cookie/unit_test.cpp
+++ b/nlite_cookie/unit_test.cpp
@@ -5,6 +5,7 @@
55 #include "cookie.h"
66 #include "chromecookiegetter.h"
77 #include "firefoxcookiegetter.h"
8+#include "iecookiegetter.h"
89 #include "cookieGetter.h"
910 #include "unit_test.h"
1011
@@ -146,6 +147,47 @@ Void UnitTest(){
146147 }
147148 }
148149
150+ {
151+
152+ CIECookieGetter::IEIsSecurityMode();
153+
154+
155+ CIECookieGetter cookieGetters;
156+ Bool result;
157+ exceptionflag = false;
158+ NString domein = _T("nicovideo.jp");
159+ NString name = _T("user_session");
160+ try{
161+
162+ result = cookieGetters.GetCookie(domein,name,cookie);
163+
164+ } catch(Exception &e3){
165+ e3;
166+ exceptionflag = true;
167+ }
168+
169+ BOOST_CHECK_MESSAGE(exceptionflag == false,"クッキー検索中に例外が発生しました");
170+ BOOST_CHECK_MESSAGE(result == true,"クッキーが見つかりませんでした");
171+
172+ exceptionflag = true;
173+ Bool result2 = false;
174+ CCookie cookie2;
175+ try{
176+ // result2 = ForceSearch(firefoxcookiegetter.cookieFilePath,domein,name,cookie2,CFireFoxCookieGetter::Fancta);
177+
178+
179+ } catch(Exception &e3){
180+ e3;
181+ exceptionflag = true;
182+ }
183+
184+ BOOST_CHECK_MESSAGE(result2 == true,"クッキーが見つかりませんでした");
185+
186+ if(result && result2){
187+ BOOST_CHECK_MESSAGE(cookie.GetCookieValue() == cookie2.GetCookieValue(),"正規の方法で取得したクッキーと強制検索で取得したクッキーが違います");
188+ }
189+
190+ }
149191 return;
150192
151193 }
--- a/sqlite3/sqlitemanage.cpp
+++ b/sqlite3/sqlitemanage.cpp
@@ -1,3 +1,5 @@
1+#include <Windows.h>
2+#include <boost\utility.hpp>
13 #include "sqlitemanage.h"
24 #include <iostream>
35 #include <nlite_common\function.h>