PHP代码加密技术 郭新华 PHPCON2018

1. PHPդᎱ‫ੂے‬ದ๞ —@swoole᮳ෛ܏
2. ‫ى‬ԭ౯ • peclਥො୏‫ݎ‬ᕟ౮ާ̶ • swoole-srcᶱፓ໐ஞ౮ާ̶ • ሿձ᫣᫪԰ᘶຝ຅૵̶ • php-cp̵swoole-mysql-proxy̵ swoole-serialize̵swoole-compiler ᒵᶱፓ֢ᘏ̶
3. ԅՋԍᥝ‫ੂے‬ • ी୩ଫአጱਞ‫ق‬௔ • ‫כ‬ಷᎣᦩԾ๦ • क़۱‫ݪل‬ጱ୊ᖅ௔ • etc…
4. Ӟӻᓌ‫ܔ‬ጱ‫ੂے‬ᔮᕹ ᖫᦲᴤྦྷ phpդᎱ ASTು᨝᧍ဩ໅ opcodes vmಗᤈ ᭋ‫ݻ‬ૡᑕ ဳ఺ᖫᦲ๗ᳵ੪Ꮯਧጱ‫ ؀‬ই PHP_OS opcodesਂ‫෈ک‬ կ᯾
5. ᭋ‫ৼֺݻ‬ ໐ஞ—ᴠྊᭋ‫ݻ‬
6. ӮኴӤဌํᏈᥴӧԧጱ᫫կ҅‫ݝ‬ ํӧ‫؀‬஑Ꮘᥴጱ᫫կ̶ • ൉ṛᭋ‫ݻ‬౮๜(੒ἓਮ) • ᭋ‫ݸݻ‬ӧ‫(᧛ݢ‬੒᧛ᘏ)
7. ᭋ‫ݸݻ‬ӧ‫ڼ—᧛ݢ‬ᴻဳ᯽ ᭋ‫ݸݻ‬ ‫ڍ‬හᖫᦲ‫ݸ‬ጱᕮ຅֛ • ဳ఺$reflection->getDocComment ()
8. ᭋ‫ݸݻ‬ӧ‫—᧛ݢ‬Ⴐႝੴ᮱‫ݒ‬ᰁ ᒧ‫ݩ‬ᤒ radius circum hash stack stack ᭋ‫ݸݻ‬ !0 => $radius !1 => $circum உग़አᒧ‫ݩ‬ᤒጱఘ‫٭‬ • $$var_name • compact̵extractᒵ‫ڍ‬හ • includeᬰ๶ጱ‫ݒ‬ᰁ • etc… Notice: Undefined variable: $_432345234
9. opcodes optimize separate vmಗᤈ ᭋ‫ݸݻ‬ӧ‫—᧛ݢ‬ᖫᦲս۸ pass /* CSE, STRING construction */ /* Constant conversion and jumps */ /* ++, +=, series of jumps */ /* INIT_FCALL_BY_NAME -> DO_FCALL */ /* CFG based optimization */ /* DFA based optimization */ /* CALL GRAPH optimization */ /* SCCP (constant propagation) */ ս۸ /* TMP VAR usage */ ๜ֺአ‫ک‬ /* NOP removal */ /* Merge equal constants */ /* Adjust used stack */ /* Remove unused variables */ /* DCE (dead code elimination) */ /* Collect constants */ /* Inline functions */ /* etc…*/ • ଉᰁփඎ • ଉᰁರ‫ݖ‬
10. ଉᰁփඎ ᖫᦲս۸-ֺৼ ଉᰁರ‫ݖ‬ • need to migrate from php72
11. ᭋ‫ݸݻ‬ӧ‫—᧛ݢ‬Ջԍฎٖᘶ ဳ‫ف‬೰ե(ٖᘶ)
12. ٖᘶ‫ڍ‬හྍṈ ྍṈ1ᬦᄁ • ‫ڍ‬හํᶉா‫ݒ‬ᰁ • ಘ઀ਫሿጱ‫ڍ‬හ • ᭓୭᧣አᛔ૩ • ‫ڍ‬හ֛ᬦय़ • ‫ڍ‬හग़ா • etc… ྍṈ2॒ቘ೰ե • recv̵send̵return init fcall̵do fcall • etc… ྍṈ3‫ݳ‬ଚ • copyਁᶎᰁ̵‫ݒ‬ᰁᒵ‫௳מ‬ • ‫ݳ‬ଚopcodes • etc… ྍṈ4᧣ෆ • ‫॔ץ‬jmp̵jmpz̵jmpnzᒵ೰եጱ؇ᑏᰁ • etc…
13. ๋ᕣጱᕮຎ ဳ‫ف‬೰ե(ٖᘶ) ս۸ դᎱ֛ᑌ‫ݒ‬य़ Ӷ०ञ຾ ‫ץ‬ද෈կᵱᥝ᯿ෛᖫᦲෆӻᶱፓ
14. ᭋ‫ݸݻ‬ӧ‫—᧛ݢ‬चԭllvmᖫᦲ౮bitcode೰ե opcode ᘉᦲ llvm IR llvm pass bitcode llvm୚ක
15. ‫——————‪ᕚ‬ۆړ‪——————-‬‬
16. ࣯࣍դᎱ ӧᚆॡग़
17. ಆଘ۸ഴ‫ګ‬ၞ if(a==1) echo 1 if(a==2) echo 2 if(a==3) echo 3 echo ‘end’
18. ಆଘ۸ഴ‫ګ‬ၞ switch next if(a==1) next =1; else next =2; echo 1; next = 6; if(a==2) next =3; else next =4; echo 2; next = 6; if(a==2) next =3; else next =4; echo 2; next = 6; if(a==3) next =5; else next =6; echo 3; next = 6; ӧᚆ෫ᚏ‫ے‬ ᵱᥝᕮ‫ٌݳ‬՜‫ੂے‬ echo ’end’; return;
19. ‫ץ‬දਁᶎᰁ ٖᗝ‫ڍ‬හ‫๊ݷ‬ഘ ‫ڍ‬හᤒ md5 _8739482343 hash ‫ץ‬ද‫ڍ‬හᤒ hash zif_md5 zif_md5 ᗌᅩғಸᲙञ຾᯾ᶎጱ‫ڍ‬හ‫ݷ‬ฎԤᎱ
20. ‫ڢ‬ᴻ/Ⴐႝopcode ‫כݝ‬ኸhandler opcode vmྒ஗ሾhandler handler ZEND_ECHO echo_handler ZEND_MUL ZEND_RETURN mul_handler return_handler ํԶopcodeӧᚆ‫ڢ‬ᴻ/Ⴐႝ c‫ڍ‬හ .....
21. ໑ഝhandler‫ݍ‬വopcode handlerጱc‫ڍ‬හ‫ݍ‬വ opcode handler opcode handler opcode handler opcode handler opcode handler ..... c‫ڍ‬හ
22. ᡦ೙๢‫כ‬ಷದ๞(vmp) my_vm my_opcode my_handler my_opcode my_handler my_opcode my_handler my_opcode my_handler my_opcode my_handler ..... • ളᓕzend_vm • ᛔਧԎ೰եᵞ • ᛔਧԎහഝᕮ຅ • ᛔ૩ਫሿ੒ଫጱhandler
23. ᜰ೰ե my_jmpz_handler
24. ‫ਁੂے‬ᶎᰁ ‫ੂے‬ ᬩᤈ෸ᥴੂ my_echo_handler ᬌ‫ڹڊ‬ᥴੂ ᬌ‫ੂےݸڊ‬ ӧᚆॡग़
25. ٌ՜ • ‫ᦶ᧣ݍ‬ • ᴠᓫද • ᶼᴠᏈᥴ • ‫ڣ‬ෙ೰ᰒฎ‫ᤩވ‬ೝ౼ • ‫ے‬ॎ
26. ௛ᕮ • ಸᲙ‫ੂے޾௳מ‬ᭌೠ‫ݸ‬ᘏ • ी‫ے‬Ꮘᥴᵙଶጱᑮᳵฎ෫ᴴጱ ๋ᵙጱฎ‫޾ੂے‬௔ᚆጱ๦ᤍ
27. swoole compilerਧ֖—----ଫአਞ‫ق‬ૡٍ դᎱ‫ੂے‬+හഝ‫ੂے‬+რᎱᄋ၏ಚൈ
28. ᵞ౮swoole compiler‫૲ݎک‬ᔮᕹ ‫ץ‬දphpդ Ꮁ ൉Իgitՙପ ᥶‫ݎ‬຅ୌ ᖫᦲphp(‫ੂے‬+ ਞ‫ق‬ಚൈ)ኞ౮ ᮱ᗟ۱ ᛔۖ۸ၥᦶ ᛔۖ۸᮱ᗟ
29. thanks
30. PHPCON ਥᗑғwww.phpconchina.com ‫ق‬᮱ PPT ӥ᫹ғhttps://github.com/ThinkDevelopers/PHPConChina ਥොQQᗭғ34449228̵135615537 ਥො‫ل‬ռ‫ݩ‬ғThinkInLAMP