Re: [問題] 如何寫出符合安全的C/C++ code
※ 引述《Schottky (順風相送)》之銘言:
: ※ 引述《Clangpp (Clang++)》之銘言:
: : 另外還看到很多新手居然把重要參數寫在 #define (preprocessor)中...
: : (同事的說法 因為編成binary後還是明碼
: : 甚至可以直接開檔改 所以建議重要參數不要放在 preprocessor)
: 突然想到一個方便的小實驗可以驗證上面這個說法,
: 寫這樣一段小程式:
: #include <stdio.h>
: const char *password = "CrystalBall";
: int main(void) {
: printf("Password = %s\n", password);
: return 0;
: }
: 和
: #include <stdio.h>
: #define PASSWORD "CrystalBall"
: int main(void) {
: printf("Password = %s\n", PASSWORD);
: return 0;
: }
要比較放不放preprocessor #define應該是用
#include <stdio.h>
#define SUPER_SECRET_PASSWORD "CrystalBall"
const char *password = SUPER_SECRET_PASSWORD ;
int main(void) {
printf("Password = %s\n", password);
return 0;
}
吧?
: 把他們 compile 成執行檔(假設叫 a.out),然後用這指令:
: strings a.out | grep 'CrystalBall'
: 試試看不同的方法,哪一種可以讓簡單的文字搜尋指令搜尋不到...
: 這樣不用反組譯也可以快快樂樂看見密碼~~~
: 如果你有 binary editor (vim -b 就辦得到) 也可以用 editor 開啟檔案搜尋。
--
『我思故我在』怎樣從法文變成拉丁文的:
je pense, donc je suis --- René Descartes, Discours de la Méthode (1637)
ego sum, ego existo --- ____, Meditationes de Prima Philosophia (1641)
ego cogito, ergo sum --- ____, Principia Philosophiae (1644)
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.112.101.8
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1460008135.A.C50.html
→
04/07 18:55, , 1F
04/07 18:55, 1F
推
04/07 20:47, , 2F
04/07 20:47, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):