Thread: JBPatch
View Single Post
Old 01-02-2013, 09:28 AM   #1002
ixtab
(offline)
ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.
 
ixtab's Avatar
 
Posts: 2,907
Karma: 6736092
Join Date: Dec 2011
Device: K3, K4, K5, KPW, KPW2
Quote:
Originally Posted by ghudod View Post
ixtab, how about using grep and regex to search all source files for the margin-checking logic? (presumably X >= 50 or X < 50)

Something like:
grep -PHn '>=\s*?50|<\s*?50' *.java

That searches all Java files and displays filename and line number where "< 50" or ">= 50" is found (whitespace is accounted for). There will probably be some false positive, but it's certainly better than searching with eyeball.
Quote:
Originally Posted by knc1 View Post
Why?
Because Amazon did not ship us the source code.
All that is there is the *.class files.
OK, a little bit of progress on that front. I figured out that on each page turn, the left and right margins seem to be set to Math.max(topMargin, leftMargin) - so no hardcoded "50" anywhere, it's actually "40" (taken from the topMargin setting). I currently don't understand why it keeps using "40", even if topMargin is set to something lower - maybe yet another class needs to be patched somewhere. (Update: I found out why that is - for some reason, the implementation switches from the hacked resources file to the localized one at some point, and of course that file contains the original settings again... sigh).

To get an idea of what the code to be deciphered looks like, here is the method in question. This is already the "easy" part of it, as this method decompiles almost correctly - still, the disassembly has to be looked at to really understand what's going on (but other classes are far, far worse):

Spoiler:

Code:
    public void MR(int k)
    {
    //*   0    0:aload_0         
        L b = t.Rgc();
    //    1    1:dup             
    //    2    2:getfield        #5   <Field com.amazon.ebook.booklet.reader.impl.ReaderSDKImpl com.amazon.ebook.booklet.reader.impl.E.t>
    //    3    5:invokevirtual   #89  <Method com.amazon.ebook.booklet.reader.impl.L com.amazon.ebook.booklet.reader.impl.ReaderSDKImpl.Rgc()>
    //    4    8:astore          6
        if(!t.Qr().Mk()) goto _L2; else goto _L1
    //    5   10:getfield        #5   <Field com.amazon.ebook.booklet.reader.impl.ReaderSDKImpl com.amazon.ebook.booklet.reader.impl.E.t>
    //    6   13:invokevirtual   #90  <Method com.amazon.ebook.booklet.reader.sdk.content.Book com.amazon.ebook.booklet.reader.impl.ReaderSDKImpl.Qr()>
    //    7   16:invokeinterface #91  <Method boolean com.amazon.ebook.booklet.reader.sdk.content.Book.Mk()>
    //    8   21:ifeq            95
    //*   9   24:aload_0         
_L1:
        int i;
        int g;
        int e;
        int c;
        c = e = Math.max(b.lQB(), b.XPB());
    //   10   25:aload           6
    //   11   27:invokevirtual   #92  <Method int com.amazon.ebook.booklet.reader.impl.L.lQB()>
    //   12   30:aload           6
    //   13   32:invokevirtual   #93  <Method int com.amazon.ebook.booklet.reader.impl.L.XPB()>
    //   14   35:invokestatic    #94  <Method int java.lang.Math.max(int, int)>
    //   15   38:dup             
    //   16   39:istore          4
    //   17   41:istore          5
        i = ((Integer)p.getObject("reader.content.topMargin")).intValue();
    //   18   43:getfield        #2   <Field java.util.ResourceBundle com.amazon.ebook.booklet.reader.impl.E.p>
    //   19   46:ldc1            #95  <String "reader.content.topMargin">
    //   20   48:invokevirtual   #62  <Method java.lang.Object java.util.ResourceBundle.getObject(java.lang.String)>
    //   21   51:checkcast       #96  <Class java.lang.Integer>
    //   22   54:invokevirtual   #97  <Method int java.lang.Integer.intValue()>
    //   23   57:istore_2        
        g = ((Integer)p.getObject("reader.content.bottomMargin")).intValue() - ((Integer)p.getObject("reader.progressbar.footer.height")).intValue();
    //   24   58:aload_0         
    //   25   59:getfield        #2   <Field java.util.ResourceBundle com.amazon.ebook.booklet.reader.impl.E.p>
    //   26   62:ldc1            #98  <String "reader.content.bottomMargin">
    //   27   64:invokevirtual   #62  <Method java.lang.Object java.util.ResourceBundle.getObject(java.lang.String)>
    //   28   67:checkcast       #96  <Class java.lang.Integer>
    //   29   70:invokevirtual   #97  <Method int java.lang.Integer.intValue()>
    //   30   73:aload_0         
    //   31   74:getfield        #2   <Field java.util.ResourceBundle com.amazon.ebook.booklet.reader.impl.E.p>
    //   32   77:ldc1            #99  <String "reader.progressbar.footer.height">
    //   33   79:invokevirtual   #62  <Method java.lang.Object java.util.ResourceBundle.getObject(java.lang.String)>
    //   34   82:checkcast       #96  <Class java.lang.Integer>
    //   35   85:invokevirtual   #97  <Method int java.lang.Integer.intValue()>
    //   36   88:isub            
    //   37   89:istore_3        
        l;
    //   38   90:aload_0         
          goto _L3
    //*  39   91:goto            164
    //*  40   94:pop             
_L2:
        i = g = Math.max(b.lQB(), b.XPB());
    //   41   95:aload           6
    //   42   97:invokevirtual   #92  <Method int com.amazon.ebook.booklet.reader.impl.L.lQB()>
    //   43  100:aload           6
    //   44  102:invokevirtual   #93  <Method int com.amazon.ebook.booklet.reader.impl.L.XPB()>
    //   45  105:invokestatic    #94  <Method int java.lang.Math.max(int, int)>
    //   46  108:dup             
    //   47  109:istore_3        
    //   48  110:istore_2        
        g -= ((Integer)p.getObject("reader.progressbar.footer.height")).intValue();
    //   49  111:iload_3         
    //   50  112:aload_0         
    //   51  113:getfield        #2   <Field java.util.ResourceBundle com.amazon.ebook.booklet.reader.impl.E.p>
    //   52  116:ldc1            #99  <String "reader.progressbar.footer.height">
    //   53  118:invokevirtual   #62  <Method java.lang.Object java.util.ResourceBundle.getObject(java.lang.String)>
    //   54  121:checkcast       #96  <Class java.lang.Integer>
    //   55  124:invokevirtual   #97  <Method int java.lang.Integer.intValue()>
    //   56  127:isub            
    //   57  128:istore_3        
        c = ((Integer)p.getObject("reader.content.rightMargin")).intValue();
    //   58  129:aload_0         
    //   59  130:getfield        #2   <Field java.util.ResourceBundle com.amazon.ebook.booklet.reader.impl.E.p>
    //   60  133:ldc1            #100 <String "reader.content.rightMargin">
    //   61  135:invokevirtual   #62  <Method java.lang.Object java.util.ResourceBundle.getObject(java.lang.String)>
    //   62  138:checkcast       #96  <Class java.lang.Integer>
    //   63  141:invokevirtual   #97  <Method int java.lang.Integer.intValue()>
    //   64  144:istore          5
        e = ((Integer)p.getObject("reader.content.leftMargin")).intValue();
    //   65  146:aload_0         
    //   66  147:getfield        #2   <Field java.util.ResourceBundle com.amazon.ebook.booklet.reader.impl.E.p>
    //   67  150:ldc1            #101 <String "reader.content.leftMargin">
    //   68  152:invokevirtual   #62  <Method java.lang.Object java.util.ResourceBundle.getObject(java.lang.String)>
    //   69  155:checkcast       #96  <Class java.lang.Integer>
    //   70  158:invokevirtual   #97  <Method int java.lang.Integer.intValue()>
    //   71  161:istore          4
        l;
    //   72  163:aload_0         
_L3:
        t;
    //   73  164:getfield        #5   <Field com.amazon.ebook.booklet.reader.impl.ReaderSDKImpl com.amazon.ebook.booklet.reader.impl.E.t>
        AGc();
    //   74  167:invokevirtual   #102 <Method com.amazon.ebook.booklet.reader.impl.m com.amazon.ebook.booklet.reader.impl.ReaderSDKImpl.AGc()>
        WIc();
    //   75  170:invokevirtual   #103 <Method com.amazon.ebook.booklet.reader.sdk.content.util.d com.amazon.ebook.booklet.reader.impl.m.WIc()>
        "reader.state.preferences";
    //   76  173:ldc1            #104 <String "reader.state.preferences">
        FI();
    //   77  175:invokevirtual   #105 <Method com.amazon.ebook.booklet.reader.sdk.content.util.DataStoreObject com.amazon.ebook.booklet.reader.sdk.content.util.d.FI(java.lang.String)>
        (L);
    //   78  178:checkcast       #106 <Class com.amazon.ebook.booklet.reader.impl.L>
        JVM INSTR dup ;
    //   79  181:dup             
        L a;
        a;
    //   80  182:astore          7
        JVM INSTR ifnonnull 197;
    //   81  184:ifnonnull       197
           goto _L4 _L5
_L4:
        break MISSING_BLOCK_LABEL_187;
_L5:
        break MISSING_BLOCK_LABEL_197;
        v.J("Unable to get reader state data, so resetMargins failed");
    //   82  187:getstatic       #12  <Field com.amazon.ebook.util.log.d com.amazon.ebook.booklet.reader.impl.E.v>
    //   83  190:ldc1            #107 <String "Unable to get reader state data, so resetMargins failed">
    //   84  192:invokevirtual   #108 <Method void com.amazon.ebook.util.log.d.J(java.lang.String)>
        return;
    //   85  195:return          
    //*  86  196:iconst_0        
        a.ajc(e, c, i, g);
    //   87  197:aload           7
    //   88  199:iload           4
    //   89  201:iload           5
    //   90  203:iload_2         
    //   91  204:iload_3         
    //   92  205:invokevirtual   #109 <Method void com.amazon.ebook.booklet.reader.impl.L.ajc(int, int, int, int)>
        z.QDc();
    //   93  208:aload_0         
    //   94  209:getfield        #46  <Field com.amazon.ebook.booklet.reader.impl.GA com.amazon.ebook.booklet.reader.impl.E.z>
    //   95  212:invokevirtual   #110 <Method void com.amazon.ebook.booklet.reader.impl.GA.QDc()>
        return;
    //   96  215:return          
    }


So much for now. I now have to get my Paperwhite out of "your Kindle needs repair" mode.
ixtab is offline   Reply With Quote