Share
Embed
Transcript
42 slides
-
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
Breaking KISS principle for the wine -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
Name: Petro Korienev Role: iOS Team Lead Company: Sigma Software Things I care about: -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
KISS stays for 1. Keep it short and simple 2. Keep it simple and straightforward 3. Keep it simple, stupid -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
Developers usually ignore it… KISS -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
enum Decision { case DontGiveAFuck() case Panic() case KeepItSimple() case Fuckup() } -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
switch (decision) { case .Fuckup(let ): // ... } -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
Given: UIWebView-based browser application for iOS When: Regression testing run Then: Found blocker issue: google accounts authentication (mail, drive etc.) is not persisted between app launches on iOS 9 Problem statement -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
(you as! Engineer). workWith(“UIWebView-based browser") == .Fuckup -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
“UIWebView-based browser" -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
• UIWebView stores cookies in .binarycookies format on disk • Somehow it’s started to fail to read written cookies • [[NSHTTPCookieStorage sharedCookieStorage] allCookies] is nil Investigation -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
• We’ve adopted on-the-fly proprietary disk encryption solution • “on-the-fly” means “magic” • We’ve broken cookies storing mechanism The root cause -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
func useMagic() -> Result { if !self.understandsMagic() { return .Fuckup } else { return .Win } } -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
With great power comes great responsibility -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
• Encryption library hooks UNIX file-system functions. • 200-line function with comparisons to string literals, magic numbers, system imports constants etc. • around 70-80 hooked unix implementations • And todo 17 Jan 2003 Deep investigation -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
Meanwhile, -2 debug days -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
• System calls atomic write to cookies file • File is written to temp • File is moved to original • Appropriate encryption applied • Hooked move is called on iOS 8 and not on iOS 9 Result -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
• AdHoc for encryption solution - ignore “_tmp_” pattern • Initial vector for encryption is the same for temp/original • Profit Solution -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
Code reviewers told - rewrite -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
func breakTheRules(principle: EngineeringPrinciples) -> Result { switch principle { case .SOLID: return rand() % 2 == 0 ? .Win : .Fuckup case .YAGNI: return rand() % 2 == 0 ? .Win : .Fuckup case .KISS : return .Fuckup } } -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
• Get the hook working on iOS 9 The next iteration -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
• XCode->Debug->Always show disassembly • symbolic breakpoints on UNIX-functions • debug symbol stubs • compare across different versions of iOS Tools -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
If you see a previous document, you are most-likely doing something wrong. -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
func RTFM(m: String) -> Result { if m.containsString("ARM Instruction set") { return .Fuckup } else { return .Win } } -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
Collective mind has given me a link -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
It didn’t work for this case neither. But trying it first i could save a time. And for sure I could find it myself. The library works exactly as the needed hook code -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
func useGoogle(use : Bool) -> Result { return use ? .Win : .Fuckup } -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
Ages of debugging on device, a week spent on implementing this for ARM architecture, offset calculations, reading Mach-O spec and i got the stubs working on iOS 9 I’ve written the solution -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
func testOn(target: TestTarget) -> Result { return target == .Device ? .Win : .Fuckup } -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
I was inspired by my awkward solution. I’ve reversed a big bunch of a format. I forgot about initial issue with login, cookies, etc... Once upon a time... -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
func tryWithoutDebugger(without: Bool) -> Result { return without ? .Win : .Fuckup } -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
(you as! Engineer).workWith("UIWebView-based browser") == .Fuckup (you as! Engineer).useMagic() == .Fuckup (you as! Engineer).breakTheRules(.KISS) == .Fuckup (you as! Engineer).RTFM("ARM Instruction set") == .Fuckup (you as! Engineer).useGoogle(false) == .Fuckup (you as! Engineer).testOn(.Simulator) == .Fuckup (you as! Engineer).tryWithoutDebugger(false) == .Fuckup Summary -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
Me: https://twitter.com/soxjke https://github.com/soxjke https://www.facebook.com/soxjke https://stackoverflow.com/users/2392973 -
DEV_AT_WORK Petro Korienev Breaking KISS principle for the win e
Thanks! Q & A TIME