Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zlib support #4

Closed
6 tasks done
pgaskin opened this issue Jun 22, 2018 · 6 comments
Closed
6 tasks done

Zlib support #4

pgaskin opened this issue Jun 22, 2018 · 6 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@pgaskin
Copy link
Owner

pgaskin commented Jun 22, 2018

  • Figure out issues with headers (see below)
  • Test zlib extraction and replacement
  • Implement zlib in patchlib
  • Decide on zlib replacement instructions
  • Test with existing patches
  • Figure out cgo cross-compiling (probably something like what I did with seriesmeta), biggest issue will be for macOS (will need to compile osxcross)
@pgaskin pgaskin self-assigned this Jun 22, 2018
@pgaskin
Copy link
Owner Author

pgaskin commented Jun 22, 2018

The hard part about this is figuring out a consistent and concise way to read and patch the zlib strings.

@pgaskin
Copy link
Owner Author

pgaskin commented Jun 23, 2018

So far, I have this: https://gist.github.com/geek1011/55ca3c4e750aa1bcd497cf296ceb8cf0 , which works for extracting the css. The biggest issue is that when recompressing it, the go zlib library uses a different dict (0x8c instead of 0x8d). Once I can get it to use the proper dict, I'll be able to add it to kobopatch and implement find_zlib, replace_zlib and replace_css instructions.

@pgaskin pgaskin added enhancement New feature or request help wanted Extra attention is needed labels Jun 23, 2018
@pgaskin
Copy link
Owner Author

pgaskin commented Jul 5, 2018

Some notes I've made for myself:

kobo      : 1111000 10011100 10001101 10010100 1011111 1101111
            78      9c       8d       94       5f      6f
czlib (go): 1111000 10011100 10001100 10010100 1011111 1101111
            78      9c       8c       94       5f      6f
go stdlib is completely wrong, so I'm using the czlib library instead.
            CMF---- FLG----- DICTID --------------------------

CMF:
 - Deflate compression

FLG:
 - Uses FDICT
 - Default compression (level 6)

DICTID:
 - TODO: figure out what the dictionary is (inconsistent between czlib and kobo).
         if it comes to it, I might just fork out to python, which uses the correct dict

References:
 - https://stackoverflow.com/questions/9050260/what-does-a-zlib-header-look-like
 - https://tools.ietf.org/html/rfc1950

@pgaskin
Copy link
Owner Author

pgaskin commented Jul 9, 2018

I think I might just end up embedding (if I can get it to cross-compile to a static binary or execing python (at least for now). Figuring out the compression issue is getting to be a bit too much work. The other alternative might be to use cgo to run a c program which calls zlib.

@pgaskin
Copy link
Owner Author

pgaskin commented Jul 9, 2018

Nevermind, 😠 I missed something obvious again (just like path chars in kepubify)!

Internally, python uses zlib.compressobj for zlib.compress. This uses deflateInit2. When I used czlib, I used czlib.NewWriterLevel, which internally uses deflateInit, which is different. To fix this, all I had to do was call czlib.Compress instead.

Now, I just need to do some more testing, then this feature should be ready!

@pgaskin
Copy link
Owner Author

pgaskin commented Jul 9, 2018

@pgaskin pgaskin closed this as completed in bff48b7 Jul 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant