2017年11月13日 星期一

[linux] c++filt


        一個簡單的linux命令, 確實不值得大費周折, 但是, 如果能與實際開發工作聯系起來, 解決實際開發中的困惑, 在生動的實際場景中學習命令, 那無疑是棒棒噠的感覺得意    
       最近剛好用c++filt解決了相關實際問題, 故而分享如下:

      我們知道, 在C++中, 是允許函數重載的, 也就引出了編譯器的name mangling機制, 今天我們要介紹的c++filt命令便與此有關。
      對於從事linux開發的人來說, 不可不知道c++filt命令的使用。

      在linux開發中, 如果要調用基礎模塊庫, 就要包含對應的頭文件, 並在makefile中指定頭文件路徑和對應的庫。
       之前我們說過了:
      1. 如果沒有指定對應的頭文件, 則編譯會報錯, 提示找不到頭文件。 
      2. 如果指定了庫路徑, 但實際沒有庫, 則會報找不錯庫文件的錯誤。 
      3. 如果沒有指定庫路徑(因各種原因啦), 則編譯不會報錯, 運行的時候才會報錯, 提示dlopen失敗。

      針對3中的問題, 我們之前也說過, 完全不用等到運行階段才去發現問題, 我們可以在編譯出so庫後, 用ldd -r命令來找出undefined的函數名(當然也可以用nm命令), 比如用ldd -r test.so查出缺少_ZNK4Json5ValueixEPKc(這就是name mangling後的函數名), 那怎麼知道這個name mangling後的名字的原函數名稱呢?  我們可以大致猜測, 但這並不靠譜, 怎麼辦呢?c++file命令就是專門干這個的, 如下:
[plain] view plain copy
[taoge@localhost test]$ c++filt _ZNK4Json5ValueixEPKc  
Json::Value::operator[](char const*) const  
      這樣, 就更清楚是哪個函數了。 然後就可以在工程中搜索了, 然後就可以找到對應的庫了, 然後就可以修改makefile來指定庫了, 醬紫就解決問題了

      就這樣。

      後記: 我之前一直想找到一個從name mangling後的名字來找原函數的方法, 沒想到c++filt命令早已實現。 遇上你, 真美麗羨慕羨慕羨慕





from:
http://blog.csdn.net/stpeace/article/details/51416297


2017年11月9日 星期四

[MFC] dumpbin,vcvarsall.bat,輸出def, Lib檔



1. 將DOS轉為 Visual Studio 的tools command prompt,執行:
cmd.exe ""C:\Program Files (x86)\Microsoft Visual Studio 11.0\VCvcvarsall.bat"" x86



或直接使用內建




2. 看DLL裡的function,執行
dumpbin DBAccess.dll /exports


3.duumpbin的所有指令 ,參考:
https://msdn.microsoft.com/zh-tw/library/756as972.aspx




5.將dll函式輸出成lib檔
lib /def:DBAccess.def /machine:x86 /out:DBAcess.lib
lib /def:DBAccess.def /machine:x64 /out:DBAcess.lib


[MFC] dumpbin,vcvarsall.bat



1. 將DOS轉為 Visual Studio 的tools command prompt,執行:
cmd.exe ""C:\Program Files (x86)\Microsoft Visual Studio 11.0\VCvcvarsall.bat"" x86


或直接使用內建




2. 看DLL裡的function,執行
dumpbin DBAccess.dll /exports


3.duumpbin的所有指令 ,參考:
https://msdn.microsoft.com/zh-tw/library/756as972.aspx


2017年11月8日 星期三

[MFC] Visual Studio 編譯參數

Visual Studio 編譯參數

VC建立項目時總會定義"Win32"。控制台程序會定義"_CONSOLE",否則會定義"_WINDOWS"。Debug版定義"_DEBUG",

Release版定義"NDEBUG"。

與MFC DLL有關的編譯常數包括:

_WINDLL 表示要做一個用到MFC的DLL

_USRDLL 表示做一個用戶DLL(相對MFC擴展DLL而言)

_AFXDLL 表示使用MFC動態鏈接庫

_AFXEXT 表示要做一個MFC擴展DLL

所以:

Regular, statically linked to MFC :_WINDLL,_USRDLL

Regular, using the shared MFC DLL: _WINDLL,_USRDLL,_AFXDLL

Extension DLL :_WINDLL,_AFXDLL,_AFXEXT

CL.EXE編譯所有源文件,LINK.EXE鏈接EXE和DLL,LIB.EXE產生靜態庫。


MFC Application:

MFC DLL :



2017年11月7日 星期二

[MFC]error LNK2001: unresolved external symbol __imp__GlobalMemoryStatusEx

Question:
S_USBPlugTestDlg.obj : error LNK2001: unresolved external symbol __imp__GlobalMemoryStatusEx@4
Dedug/3S_USBPlugTest.exe : fatal error LNK1120: 1 unresolved externals

[cid:image001.png@01D3587D.37DDB7B0]



Because:
too many versions of Kernel32.lib
[cid:image002.png@01D35880.07E4A700]


Solution:
1.Copy the correct version of lib ( from x86 folder) to source code
[cid:image003.png@01D35880.07E4A700]

2.Create Lib folder in souce code
[cid:image004.png@01D35880.655761C0]

3.add lib:
#pragma comment(lib, "Kernel32.lib")
[cid:image005.png@01D35880.7F4BAB40]


________________________________________ 3S CONFIDENTIALITY NOTICE: This message and all attachments may contain legally privileged and confidential information. Any unauthorized review, use or distribution by anyone other than the intended recipient is strictly prohibited. If you are not the intended recipient, please contact the sender immediately by replying to the message and delete all copies. Thank you.

Windows DACL(Discretionary Access Control List)(psgetsid.exe)

設定Windwos DACL (Discretionary Access Control List)
檔案->內容->安全性->進階->權限,設定
[cid:image003.png@01D357EB.614B4410]


查看DACL
電腦管理->事件檢視器->Windwos記錄->安全性->依工作類別排序(查看檔案系統類)
[cid:image001.png@01D357E9.B4303110]



[cid:image002.png@01D357E9.B4303110]


________________________________________ 3S CONFIDENTIALITY NOTICE: This message and all attachments may contain legally privileged and confidential information. Any unauthorized review, use or distribution by anyone other than the intended recipient is strictly prohibited. If you are not the intended recipient, please contact the sender immediately by replying to the message and delete all copies. Thank you.

2017年11月6日 星期一

[Windows] SID, whoami

[cid:image001.png@01D357AE.436DC630]
________________________________________ 3S CONFIDENTIALITY NOTICE: This message and all attachments may contain legally privileged and confidential information. Any unauthorized review, use or distribution by anyone other than the intended recipient is strictly prohibited. If you are not the intended recipient, please contact the sender immediately by replying to the message and delete all copies. Thank you.