Created
October 11, 2020 15:54
-
-
Save abjurato/b6a2fe170e31a4173b71f38d31ad8213 to your computer and use it in GitHub Desktop.
lldb Amazon Kindle example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add breakpoint at the place when list of chapters becomes available | |
(lldb) expr -- void *$class1 = (void *)objc_getClass("ReaderViewController") | |
(lldb) expr -- void *$sel11=(void *)sel_getUid("didLoadBook") | |
(lldb) po (void*)class_getMethodImplementation($class1, $sel11) | |
0x0000000104d3d738 | |
(lldb) b 0x0000000104d3d738 | |
(lldb) с | |
// - OPEN THE BOOK, WAIT TILL THE PROCESS WILL BE STOPPED | |
// Get pointer to the list of chapters | |
(lldb) expr -- NSDictionary* $chapters = ((NSDictionary*)((KfxPagePreviewModel*)[((KfxDocViewController*)((ReaderViewController*)$arg1)->_documentSpecificViewController) pagePreviewModel])->_chapterPositions) | |
// Get pointer to the first chapter | |
(lldb) expr -- BookPositionRange* $firstChapter = [((BookPositionRange*)[BookPositionRange alloc]) initWithFirstPosition: ((BookPosition*)[$chapters objectForKey: @1]) lastPosition: ((BookPosition*)[$chapters objectForKey: @2])] | |
(lldb) c | |
// Add breakpoint at the place where text of a chunk is fetched for translator | |
(lldb) expr -- void *$class2 = (void *)objc_getClass("BookTextExtractor") | |
(lldb) expr -- void *$sel21=(void *)sel_getUid("textInfoForBookPositionRange:usingIterator:") | |
(lldb) po (void*)class_getMethodImplementation($class2, $sel21) | |
0x00000001027256dc | |
(lldb) b 0x00000001027256dc | |
(lldb) c | |
// TURN PAGE, WAIT TILL THE PROCESS WILL STOP | |
// Get pointer to the text of whole chapter | |
(lldb) expr -- NSString* $text = [((BookTextExtractorInfo*)[((BookTextExtractor*)$arg1) textInfoForBookPositionRange: $firstChapter usingIterator:((KfxWordIterator*)$arg4)]) text] | |
(lldb) po $text | |
// HERE WE’LL SEE THE TEXT | |
// Write NSString with the text of a chapter into a local file | |
(lldb) expr -- NSString* $firstPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"firstChapter.txt"] | |
(lldb) po [[NSFileManager defaultManager] createFileAtPath:$firstPath contents:[$text dataUsingEncoding:NSUTF8StringEncoding] attributes:nil]; | |
YES | |
// AND NOW FULL CHAPTER TEXT WILL BE WRITTEN TO A FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment