Thread: K5 JBPatch
View Single Post
Old 10-14-2012, 05:52 AM   #835
arikfunke
Enthusiast
arikfunke is an enigma wrapped up in a mystery.arikfunke is an enigma wrapped up in a mystery.arikfunke is an enigma wrapped up in a mystery.arikfunke is an enigma wrapped up in a mystery.arikfunke is an enigma wrapped up in a mystery.arikfunke is an enigma wrapped up in a mystery.arikfunke is an enigma wrapped up in a mystery.arikfunke is an enigma wrapped up in a mystery.arikfunke is an enigma wrapped up in a mystery.arikfunke is an enigma wrapped up in a mystery.arikfunke is an enigma wrapped up in a mystery.
 
Posts: 32
Karma: 41848
Join Date: Mar 2011
Device: iRex
JBPatch works on K3

Good news for those who have been waiting for JBPatch on K3: after writing a small dummy patch I can confirm that JBPatch appears to work perfectly on K3. (Obviously less the UI component.)

Rough recipe for compiling JBPatch for K3:
  1. Delete the "ui" directories from the JBPatch source tree. That is in its base directory and in the "conf" directory.
  2. Delete the line "public abstract SettingPanel getPanel(SettingChangeListener listener);" from "conf/ConfigurableSetting.java"
  3. Delete "bootstrap/Stage1.java" from the source tree.
  4. Delete the patch source files from the source tree.
  5. Add the new startup script for the K3 from this post.
  6. Compile and pack in a JAR

Note: the deletions were necessary in my case due to missing dependencies. If you have them, it should not be necessary to delete anything from the source three.

Copy the JAR to the kindle as described by ixtab in his post.

I have also created a dummy patch that prefixes "abcXYZ" to any search string entered in the browser's URL bar for Google searches:

Code:
package com.mobileread.arikfunke.patch;

import java.util.Map;

import serp.bytecode.BCClass;
import serp.bytecode.lowlevel.Entry;
import serp.bytecode.lowlevel.UTF8Entry;

import com.mobileread.ixtab.jbpatch.Patch;
import com.mobileread.ixtab.jbpatch.PatchMetadata;
import com.mobileread.ixtab.jbpatch.PatchMetadata.PatchableClass;

public class K3BrowserGoogleMobileSearchPatch extends Patch {

	private static final String CLASS = "com.amazon.ebook.booklet.browser.resources.BrowserResources";
	private static final String MD5_BEFORE = "6c8c6e226e2f60e134fa7ccec784c4ce";
	private static final String MD5_AFTER = "96d802f5b0cef88cdf54a2407e263af8";

	private final String[] ORIGINAL = new String[] { "search.internet.url.pattern", "http://www.google.com/search?q={0}" };
	private final String[] REPLACEMENT = new String[] { "search.internet.url.pattern", "http://www.google.com/search?q=abcXYZ{0}" };
	
	public int getVersion() {
		return 20121013;
	}

	protected void initLocalization(String locale, Map map) {
		if (RESOURCE_ID_ENGLISH.equals(locale)) {
			map.put(I18N_JBPATCH_NAME, "Use Google Mobile Search in Browser");
			map.put(I18N_JBPATCH_DESCRIPTION, "This is a proof of concept patch. It changes the browser's search-bar behaviour. abcXYZ is prefixed to any search string.");
		}
	}

	public PatchMetadata getMetadata() {
		PatchableClass pc = new PatchableClass(CLASS).withChecksums(MD5_BEFORE,
				MD5_AFTER);
		return new PatchMetadata(this).withClass(pc);
	}

	public String perform(String md5, BCClass clazz) throws Throwable {
		if (md5.equals(MD5_BEFORE)) {
			patchBrowserResources(clazz);
			return null;
		}
		return "unsupported MD5: "+md5;
	}

	private void patchBrowserResources(BCClass clazz) {
		String[] replacement = REPLACEMENT;
		
		Entry[] entries = clazz.getPool().getEntries();
		for (int e=0; e < entries.length; ++e) {
			if (entries[e] instanceof UTF8Entry) {
				UTF8Entry entry = (UTF8Entry) entries[e];
				for (int r = 0; r < ORIGINAL.length; ++r) {
					if (ORIGINAL[r].equals(entry.getValue())) {
						entry.setValue(replacement[r]);
						break;
					}
				}
			}
		}
	}

}
To try the patch, compile into a class file and rename to "com.mobileread.arikfunke.patch.K3BrowserGoogleMob ileSearchPatch.class". Copy to "/mnt/us/opt/jbpatch/" on the K3 (or simply "/opt/jbpatch/" when plugged in as USB drive).

Restart the framework with the modifications described in this post by ixtab. (Note: due to changes in the naming of the classes you need to use "app=com.mobileread.ixtab.jbpatch.bootstrap.K3Star tup" rather than "app=com.mobileread.ixtab.jbpatch.bootstrap.Startu p" .)

Hope this is useful to somebody. Many thanks to ixtab for the great work with JBPatch!
Attached Files
File Type: zip jbpatchK3.zip (204.0 KB, 236 views)

Last edited by arikfunke; 10-14-2012 at 06:02 AM.
arikfunke is offline   Reply With Quote