Git Product home page Git Product logo

Comments (5)

pgaskin avatar pgaskin commented on May 24, 2024

This is partly by design (albeit with a cryptic error message). To replace bytes values, you need to use ReplaceBytes, and FindBaseAddressBytes. Try changing that (see the other patches for examples), and if it doesn't work, show me the whole patch.

from kobopatch.

taosxx avatar taosxx commented on May 24, 2024

Are you sure that there is a "FindBaseAddressBytes"?

I don't get it:
len("\x20") = 1 = len("\xBB")
len([]byte("\x20")) = 1 = len([]byte("\xBB"))

The default entry in libnickel.so.1.0.0.yaml (v10) looks like that:

Allow searches on Extra dictionaries:
  - Enabled: no
    ## To allow searches on Extra dictionaries change space character at end of
    ## "Extra: " to another char (ex: "Extra:_")
    ## The space char causes a non-desired "English - English" when searching on
    ## Extra dictionary from main menu.
  - FindBaseAddressString: "\0Extra:\x20"
  - ReplaceString: {Offset: 7, Find: "\x20", Replace: "_"}

If I replace the last two lines with - ReplaceBytes: {Offset: 0x00CC184F, FindH: 00 45 78 74 72 61 3A 20, ReplaceH: 00 45 78 74 72 61 3A BB} I get a libnickel.so.1.0.0 where the space \x20 is correctly replaced by "»" (\xBB). Not very convenient because I would have to use a hex editor to search for the correct offset with every firmware update.

If I use instead:

  - FindBaseAddressString: "\0Extra:\x20\0"
  - ReplaceString: {Offset: 7, Find: "\x20\0", Replace: "\xBB"}

For whatever reason, an additional character is inserted - the \x20\0 is replaced by "»" (\xC2\xBB). Why?

That means, in a hex editor, the interesting part looks like that:

00 45 78 74 72 61 3A 20 00 (unpatched libnickel)
00 45 78 74 72 61 3A BB 00 (correctly patched libnickel by replacing bytes)
00 45 78 74 72 61 3A C2 BB (incorrectly patched libnickel by replacing string)

from kobopatch.

pgaskin avatar pgaskin commented on May 24, 2024

Oops, I meant FindBaseAddressHex, not FindBaseAddressBytes.

What I would suggest is:

Allow searches on Extra dictionaries:
  - Enabled: no
    ## To allow searches on Extra dictionaries change space character at end of
    ## "Extra: " to another char (ex: "Extra:_")
    ## The space char causes a non-desired "English - English" when searching on
    ## Extra dictionary from main menu.
  - FindBaseAddressHex: 00 45 78 74 72 61 3A 20 # Hex of \0Extra:\x20\0
  - ReplaceBytes: {Offset: 7, FindH: 20, ReplaceH: BB}

This way, you don't have to update offsets, but it still works.

The issue is due to the way strings are encoded as binary in Go. Golang uses UTF-8, which is a two-byte encoding. \xBB is the ISO-8859-1 encoding of », and when trying to decode it as UTF-8, you get an invalid char. \xC2\xBB is the UTF-8 encoding, which is what Go uses.

from kobopatch.

pgaskin avatar pgaskin commented on May 24, 2024

Also, are you sure this displays properly on the Kobo? AFAIK, Qt uses the UTF-8 encoding by default.


EDIT: Yep, I checked. Replacing it with \xBB will not work (it will show a square box), as it needs \xC2\xBB (the UTF-8 encoding). So, the fact that it counts it as two bytes was correct from the start, as it is (due to the UTF-8 encoding). I've added this to the FAQ on the kobopatch thread.

Here is what you should use:

Allow searches on Extra dictionaries:
  - Enabled: no
    ## To allow searches on Extra dictionaries change space character at end of
    ## "Extra: " to another char (ex: "Extra:_")
    ## The space char causes a non-desired "English - English" when searching on
    ## Extra dictionary from main menu.
  - FindBaseAddressString: "\0Extra:\x20"
  - ReplaceString: {Offset: 7, Find: "\x20\0", Replace: "»"}

from kobopatch.

taosxx avatar taosxx commented on May 24, 2024

Thanks for the suggestion.

BTW, where do you see the squares in the GUI? I've attached two pictures that show how it looks like for me (20 replaced by BB: 00 45 78 74 72 61 3A BB 00 (no \xC2\xBB)). One picture is from the dictionary lookup, the other from the language settings.

img_7846
img_7847

I don't have to work around utf-8 in libnickel.so but in KoboReader.sqlite and Kobo eReader.conf.

from kobopatch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.