代碼難讀化
「 | 」 |
噉嘅工作。
概論
代碼難讀化係軟件工程同相關工作上成日要做嘅一段工序。想像家陣有班軟件工程師,佢哋寫好咗隻新軟件嘅原始碼,而且測試都做好嗮,隻軟件可以出街攞去賣。但喺呢個時候,佢哋又要閉翳一樣嘢:啲人有可能會攞佢哋隻軟件嘅原始碼去複製,用嚟整翻版;為咗保障佢哋嘅知識產權,班軟件工程師就會想要有啲方法,防止啲人隨便複雜隻軟件嘅原始碼[2];除此之外,啲原始碼易改又表示,正當嘅用家可能會貪玩亂咁改啲碼,改改吓搞軭隻軟件。
因為呢啲噉嘅緣故,軟件工程師好多時會想使用代碼難讀化:佢哋會攞住隻軟件段原始碼或者(轉化好嘅)機械碼,將段碼執吓佢,令到段碼變到對人類同電腦嚟講難理解。代碼難讀化做好咗之後,佢哋先會畀隻軟件出街。舉個簡單例子,好似下面嘅 C 例子碼噉,就做咗難讀化[3]:
int i;main(){for(i=0;i["]<i;++i){--i;}"];
read('-'-'-',i+++"hell\
o,world!\n",'/'/'/'));}read(j,i,p){
write(j/p+p,i---j,i/i);}
而一段比較整齊易讀嘅 C 碼望落比較似係噉嘅:
int i;
void write_char(char ch)
{
printf("%c", ch);
}
int main()
{
for (i = 0; i < 15; i++) {
write_char("hello, world!\n"[i]);
}
return 0;
}
目標
代碼難讀化目的係要達致[3]:
技巧
代碼難讀化有好多技巧可以用,比較簡單嘅有:
- 死碼(dead code):指一段碼永遠唔會行得到(例如係行嘅條件永遠唔會有可能達到)或者就算行咗段碼,段碼嘅 output 唔會有畀個程式嘅任何部份攞嚟用;做代碼難讀化嘅人,有陣時會加少少死碼,嚟擾亂嘗試解讀段碼嘅人[4]。
- 最佳化(optimize):做最佳化嘅過程,成日都會搞到段碼變得冇咁易睇;數學上最有效率嘅演算法,往往唔多合乎人腦直覺嘅諗嘢方式。
- 將啲碼嘅次序掉轉,甚至加啲 goto 落去令到段碼行起上嚟會「跳嚟跳去」,同時一路 kip1 住個程式嘅行為唔變。
... 呀噉。
睇埋
攷
- ↑ What is code obfuscation?. ASEE.
- ↑ Balakrishnan, A., & Schulze, C. (2005). Code obfuscation literature survey (PDF). CS701 Construction of compilers, 19, 31.
- ↑ 3.0 3.1 What is Obfuscation?. GeeksForGeeks.
- ↑ Barría, C., Cordero, D., Cubillos, C., & Osses, R. (2016, May). Obfuscation procedure based in dead code insertion into crypter. In 2016 6th International Conference on Computers Communications and Control (ICCCC) (pp. 23-29). IEEE.
- ↑ Karthik, J., Amritha, P. P., & Sethumadhavan, M. (2020, July). Video Game DRM: Analysis and Paradigm Solution. In 2020 11th International Conference on Computing, Communication and Networking Technologies (ICCCNT) (pp. 1-4). IEEE.
- ↑ You, I., & Yim, K. (2010, November). Malware obfuscation techniques: A brief survey. In 2010 International conference on broadband, wireless computing, communication and applications (pp. 297-300). IEEE.