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

关于5.1以后版本修改的一些发现及问题 #6

Open
xinghui233 opened this issue Dec 10, 2021 · 22 comments
Open

关于5.1以后版本修改的一些发现及问题 #6

xinghui233 opened this issue Dec 10, 2021 · 22 comments

Comments

@xinghui233
Copy link

在阅读了https://github.com/kovidgoyal/calibre 中的几个关键提交

  • fe478a2ceedb8b7111517c80d39d064c0d438717 Use the new bypy freezing code for windows build
  • 2938e2c2037e1a47a4536bf373f9e72e7e5a8037 New bypy freezing framework for Linux builds
    https://github.com/kovidgoyal/bypy中的
  • cbe8e76783bcadc1df1d49a8c9b99c249a8a56bc Get the freeze module building on Windows
  • 63bef79da4d045c52c5c748e48d95247b535c3d8 Basic freezing support
    后 在 bypy/freeze/init.py中发现了关键函数
def freeze_python(base, dest_dir, include_dir):
    files = collect_files_for_internment(base)
    frozen_file = os.path.join(dest_dir, 'python-lib.bypy.frozen')
    index_data = {}
    with open(frozen_file, 'wb') as frozen_file:
        for name, path in files.items():
            raw = open(path, 'rb').read()
            index_data[name] = frozen_file.tell(), len(raw)
            frozen_file.write(raw)
    if len(index_data) > 9999:
        raise ValueError(
            'Too many files in python-lib have to switch'
            ' hash function to IntSaltHash and change C'
            ' template accordingly.')
    perfect_hash, code_to_get_index = get_c_code(index_data)
    values = []
    for k in sorted(index_data.keys(), key=perfect_hash):
        v = index_data[k]
        values.append(f'{{ {v[0]}u, {v[1]}u }}')
    vals = ','.join(values)
    tree = '\n'.join(bin_to_c(as_tree(index_data.keys())))
    header = code_to_get_index + f'''
static void
get_value_for_hash_index(int index, unsigned long *offset, unsigned long *size)
{{
    typedef struct {{ unsigned long offset, size; }} Item;
    static const Item values[{len(values)}] = {{ {vals} }};
    if (index >= 0 && index < {len(values)}) {{
       *offset = values[index].offset; *size = values[index].size;
    }} else {{
    *offset = 0; *size = 0;
    }}
}}
static const char filesystem_tree[] = {{ {tree} }};
'''
    with open(os.path.join(include_dir, 'bypy-data-index.h'), 'w') as f:
        f.write(header)

它看起来是抛弃了旧版本将pyc压缩成压缩包的方法 而是直接将pyc文件已二进制依次存入 \bin\python-lib.bypy.frozen 中
在我以16进制打开该文件后 也找到了 对应的方法名
但现在的问题是 我不知道如何寻找并修改frozen文件以取消核心函数(通过python3.9编译的原代码和修改后的代码均和存档存在细微差异 以至于我很难寻找到二进制文件准确修改位置(或许是python版本的问题

想问问作者有什么办法来解决

@xinghui233
Copy link
Author

甚至在我注释和删除 对应的4行 后所编译的pyc也有着大量的不同

@xinghui233 xinghui233 changed the title 关于5.3版本修改的一下问题 关于5.1以后版本修改的一些发现及问题 Dec 10, 2021
@xinghui233
Copy link
Author

calibre在载入二进制文件时是通过marshal.loads()去加载的

@snomiao
Copy link
Owner

snomiao commented Dec 13, 2021

我现在有点想就是给官方分支提 issue+pr 好好描述一下unicode的需求…然后让作者去Merge

@xinghui233
Copy link
Author

我现在有点想就是给官方分支提 issue+pr 好好描述一下unicode的需求…然后让作者去Merge

似乎有文章说作者认为用户不应该去操作文件系统 所以不考虑这个功能
我去论坛问了 作者说现在windows只能重新构建 或者设置环境变量

@UltramarineSky
Copy link

看来要先用旧版顶下了,因为会用其他软件进行阅读批注的原因对中文名需求还是比较大的

@kevinlae
Copy link

在阅读了https://github.com/kovidgoyal/calibre 中的几个关键提交

  • fe478a2ceedb8b7111517c80d39d064c0d438717 Use the new bypy freezing code for windows build
  • 2938e2c2037e1a47a4536bf373f9e72e7e5a8037 New bypy freezing framework for Linux builds
    https://github.com/kovidgoyal/bypy中的
  • cbe8e76783bcadc1df1d49a8c9b99c249a8a56bc Get the freeze module building on Windows
  • 63bef79da4d045c52c5c748e48d95247b535c3d8 Basic freezing support
    后 在 bypy/freeze/init.py中发现了关键函数
def freeze_python(base, dest_dir, include_dir):
    files = collect_files_for_internment(base)
    frozen_file = os.path.join(dest_dir, 'python-lib.bypy.frozen')
    index_data = {}
    with open(frozen_file, 'wb') as frozen_file:
        for name, path in files.items():
            raw = open(path, 'rb').read()
            index_data[name] = frozen_file.tell(), len(raw)
            frozen_file.write(raw)
    if len(index_data) > 9999:
        raise ValueError(
            'Too many files in python-lib have to switch'
            ' hash function to IntSaltHash and change C'
            ' template accordingly.')
    perfect_hash, code_to_get_index = get_c_code(index_data)
    values = []
    for k in sorted(index_data.keys(), key=perfect_hash):
        v = index_data[k]
        values.append(f'{{ {v[0]}u, {v[1]}u }}')
    vals = ','.join(values)
    tree = '\n'.join(bin_to_c(as_tree(index_data.keys())))
    header = code_to_get_index + f'''
static void
get_value_for_hash_index(int index, unsigned long *offset, unsigned long *size)
{{
    typedef struct {{ unsigned long offset, size; }} Item;
    static const Item values[{len(values)}] = {{ {vals} }};
    if (index >= 0 && index < {len(values)}) {{
       *offset = values[index].offset; *size = values[index].size;
    }} else {{
    *offset = 0; *size = 0;
    }}
}}
static const char filesystem_tree[] = {{ {tree} }};
'''
    with open(os.path.join(include_dir, 'bypy-data-index.h'), 'w') as f:
        f.write(header)

它看起来是抛弃了旧版本将pyc压缩成压缩包的方法 而是直接将pyc文件已二进制依次存入 \bin\python-lib.bypy.frozen 中 在我以16进制打开该文件后 也找到了 对应的方法名 但现在的问题是 我不知道如何寻找并修改frozen文件以取消核心函数(通过python3.9编译的原代码和修改后的代码均和存档存在细微差异 以至于我很难寻找到二进制文件准确修改位置(或许是python版本的问题

想问问作者有什么办法来解决

能否把python-lib.bypy.frozen 解包后,混入修改的pyc重新打包 python-lib.bypy.frozen

@actforjason
Copy link

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


[Brute force Calibre Chinese Catalog](https://hsuan9522.medium.com/%E6%9A%B4%E5%8A%9B%E7%A0%B4%E8%A7%A3-calibre-%E4%B8% AD%E6%96%87%E7%9B%AE%E9%8C%84-2b124f92f54)

@kurikomoe
Copy link

暴力破解 Calibre 中文目錄

https://github.com/kurikomoe/calibre-utf8-path

把相应的修改方法打包了一下。同时编译了一个 Linux 的版本

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


[Brute force cracking Caliber Chinese catalog](https://hsuan9522.medium.com/%E6%9A%B4%E5%8A%9B%E7%A0%B4%E8%A7%A3-calibre-%E4%B8 %AD%E6%96%87%E7%9B%AE%E9%8C%84-2b124f92f54)

https://github.com/kurikomoe/calibre-utf8-path

Packaged the corresponding modification method. Also compiled a version for Linux

@xiaopdown
Copy link

暴力破解Calibre 中文目录

https://github.com/kurikomoe/calibre-utf8-path

把相应的修改方法打包了一下。同时编译了一个 Linux 的版本

感谢您的修改,现在保存为中文目录,方便多了,简直造福人类!就是有个小问题:在calibre主目录,点击阅读图书的时候,epub等格式的图书没法直接点开,需要打开所在目录,然后点击该文件才能阅读, 稍微有点不方便!不知道是否有解决办法?

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


[Brute force cracking Caliber Chinese catalog](https://hsuan9522.medium.com/%E6%9A%B4%E5%8A%9B%E7%A0%B4%E8%A7%A3-calibre-%E4% B8%AD%E6%96%87%E7%9B%AE%E9%8C%84-2b124f92f54)

https://github.com/kurikomoe/calibre-utf8-path

Package the corresponding modification method. Also compiled a version for Linux

Thank you for your modification, now it is saved as a Chinese catalog, which is much more convenient and benefits mankind! There is just a small problem: when you click to read a book in the caliber main directory, you cannot directly click to open a book in epub format. You need to open the directory where it is located, and then click on the file to read it, which is a bit inconvenient! Not sure if there is a solution?

@kurikomoe
Copy link

kurikomoe commented Feb 8, 2023

暴力破解 Calibre 中文目录

https://github.com/kurikomoe/calibre-utf8-path
把相应的修改方法打包了一下。同时编译了一个 Linux 的版本

感谢您的修改,现在保存为中文目录,方便多了,简直造福人类!就是有个小问题:在 calibre 主目录,点击阅读图书的时候,epub 等格式的图书没法直接点开,需要打开所在目录,然后点击该文件才能阅读, 稍微有点不方便!不知道是否有解决办法?

实际上是 dev 模式下,viewer 的源代码需要被 jit 编译后使用,Linux 上能直接编译后启动,Windows 可能缺乏 python 环境导致编译失败。
在我的机子上大概要 10s 才能显示界面。我倒是可以改成直接显示 viewer 的模式,你可以测试一下。(在 windows 虚拟机里似乎没问题)

测试:https://github.com/kurikomoe/calibre-utf8-path/releases/tag/v6.10.2

另外建议其他和我的 patch 相关的 issue 提在 https://github.com/kurikomoe/calibre-utf8-path 里,不要污染本 issue。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


[Brute force cracking Caliber Chinese catalog](https://hsuan9522.medium.com/%E6%9A%B4%E5%8A%9B%E7%A0%B4%E8%A7%A3-calibre-%E4 %B8%AD%E6%96%87%E7%9B%AE%E9%8C%84-2b124f92f54)

https://github.com/kurikomoe/calibre-utf8-path
Package the corresponding modification method. Also compiled a version for Linux

Thank you for your modification, now it is saved as a Chinese catalog, which is much more convenient and benefits mankind! There is just a small problem: in the caliber main directory, when you click to read books, you cannot directly click to open books in epub and other formats. You need to open the directory where you are, and then click on the file to read, which is a bit inconvenient! Not sure if there is a solution?

In fact, in dev mode, the source code of the viewer needs to be compiled by jit to be used. On Linux, it can be compiled directly and then started. Windows may lack a python environment and cause the compilation to fail.
It takes about 10s on my machine to display the interface. I can change it to directly display the viewer mode, you can test it. (It seems to be ok in windows virtual machine)

Tested: https://github.com/kurikomoe/calibre-utf8-path/releases/tag/v6.10.2

@xiaopdown
Copy link

暴力破解 Calibre 中文目录

https://github.com/kurikomoe/calibre-utf8-path
把相应的修改方法打包了一下。同时编译了一个 Linux 的版本

感谢您的修改,现在保存为中文目录,方便多了,简直造福人类!就是有个小问题:在 calibre 主目录,点击阅读图书的时候,epub 等格式的图书没法直接点开,需要打开所在目录,然后点击该文件才能阅读, 稍微有点不方便!不知道是否有解决办法?

实际上是 dev 模式下,viewer 的源代码需要被 jit 编译后使用,Linux 上能直接编译后启动,Windows 可能缺乏 python 环境导致编译失败。 在我的机子上大概要 10s 才能显示界面。我倒是可以改成直接显示 viewer 的模式,你可以测试一下。(在 windows 虚拟机里似乎没问题)

测试: https://github.com/kurikomoe/calibre-utf8-path/releases/tag/v6.10.2

**另外建议其他和我的 patch 相关的 issue 提在 https://github.com/kurikomoe/calibre-utf8-path 里,不要污染本 issue。 **

非常感谢,已经可以打开了(虽然慢了一点),不过比不能打开强太多了,再次感谢!!

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


[Brute Force Crack Caliber Chinese Catalog](https://hsuan9522.medium.com/%E6%9A%B4%E5%8A%9B%E7%A0%B4%E8%A7%A3-calibre-% E4%B8%AD%E6%96%87%E7%9B%AE%E9%8C%84-2b124f92f54)

https://github.com/kurikomoe/calibre-utf8-path
Package the corresponding modification method. Also compiled a version for Linux

Thank you for your modification. It is now saved as a Chinese catalog, which is much more convenient and benefits mankind! There is just a small problem: in the caliber main directory, when you click to read books, you cannot directly click to open books in epub and other formats. You need to open the directory where you are, and then click on the file to read, which is a bit inconvenient! Not sure if there is a solution?

In fact, in dev mode, the source code of the viewer needs to be compiled by jit to be used. On Linux, it can be compiled directly and then started. Windows may lack a python environment and cause the compilation to fail. It takes about 10s on my machine to display the interface. I can change it to directly display the viewer mode, you can test it. (It seems to be ok in windows virtual machine)

Tested: [https://github.com/kurikomoe/calibre-utf8-path/releases/tag/v6.10.2](https://github.com/kurikomoe/calibre-utf8-path/releases/tag/v6 .10.2)

**It is also suggested that other issues related to my patch should be mentioned in https://github.com/kurikomoe/calibre-utf8-path , don't pollute this issue. **

Thank you very much, it can be opened already (although it is a bit slow), but it is much better than not being able to open it, thanks again! !

@Cirn09
Copy link

Cirn09 commented Mar 22, 2023

开个坑,这个问题可解,但是依赖软件逆向分析工具(可能有取巧绕过的方法

[可能]需要解决的问题:

  • 确定新的 Patch 方案
    • 手动验证可行性
    • 完成自动 Patch 脚本
    • 实现不依赖逆向分析工具的 Patch 方案
  • 检查此项目的 Patch 是否依然有效
  • 确定 Calibre 的 Python 版本(现在的 6.14.1 使用的是 Python 3.10.1150.1013,如果没记错的话,3.10 对上就行)
  • 找到方便的触发 Github Action + Release 的方法,可以的话后续每次 Calibre 发布新版本,我就开一次 Action,创建 Patch 文件,并自动 Release

问题:

    target = target.replace(
        'author = ascii_filename(author)[:l]',
        'author = re.sub(r"[\\/\\\\\\:\\*\\?\\"\\<\\>\\|]", "_", author.strip())[:l]'
    )

r"[\/\\\:\*\?\"\<\>\|]" 这是在干什么?

啊我知道了,是替换掉 Windows 不能用作路径的字符

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Open a hole, this problem can be solved, but rely on software reverse analysis tools (there may be tricky ways to bypass

[Possible] Issues that need to be addressed:

  • Reverse analysis, complete automatic patch script
    • Find a Patch solution that does not rely on reverse analysis tools
  • Check whether the Patch of this project is still valid
  • Determine the Python version of Caliber (the current 6.14.1 uses Python 3.10.1150.1013, if I remember correctly, 3.10 is fine)
  • Find a convenient way to trigger Github Action + Release. If possible, every time Caliber releases a new version, I will open an Action, create a Patch file, and release automatically

@Cirn09
Copy link

Cirn09 commented Mar 22, 2023

image

它工作

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


image

it works

@Cirn09
Copy link

Cirn09 commented Mar 28, 2023

新版的 Patch 方案:
https://github.com/Cirn09/calibre-do-not-translate-my-path

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


The new version of the Patch scheme:
https://github.com/Cirn09/calibre-do-not-translate-my-path

Repository owner deleted a comment Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants