Skip to content
This repository has been archived by the owner on Oct 12, 2024. It is now read-only.

Make PyGoRE Python 2 compatible #15

Closed
wants to merge 1 commit into from
Closed

Make PyGoRE Python 2 compatible #15

wants to merge 1 commit into from

Conversation

0xThiebaut
Copy link

This PR introduces Python 2 compatibility by adding minor statements implicitly covered by Python 3's syntax sugar.

Why support the end-of-life Python 2?

Supporting Python 2 enables PyGoRE to be used in Java-based projects through Jython. This PR is the first step in integrating GoRE into Ghidra. 🎉

@0xThiebaut
Copy link
Author

A small mention that leveraging Python 2 to integrate GoRE into Ghidra through the Java Python interpreter (Jython) is not possible. As so, this PR might be closed if Python 2 support is not something that interests the maintainers.


The PyGoRE bindings cannot be used as Ghidra’s Java Python interpreter (Jython) does not support non-scalar C types in C structures. One of such examples is the following code from PyGoRE’s internal.py.

class _CompilerVersion(Structure):
    _fields_ = [('name', c_char_p),
                ('sha', c_char_p),
                ('timestamp', c_char_p)]

The c_char_p type is defined as follow in Jython’s ctypes.

class c_char_p(jffi.StringCData, _CData):
    _type_ = 'z'
    _jffi_type = jffi.Type.STRING

However, adding fields to a struct does not support non-scalar values as can be seen in Jython’s ctypes.

    def add_field(self, f):
        if not issubclass(f[1], _ScalarCData):
            raise RuntimeError("non-scalar fields not supported")

Integrating GoRE in Ghidra will have to be done through native Java.

@TcM1911
Copy link
Member

TcM1911 commented Nov 5, 2020

Thank you for contributing. I'm a bit hesitant to add support for an EOL version of a language. Would it be possible to integrate support with Ghidra by using the c-library shim?

@0xThiebaut
Copy link
Author

Not exactly as Java can't call C libraries if they haven't been build explicitly for Java using the JNI specification (See JNIEXPORT and JNICALL macros).

Anyway, as Python is off the table anyway, I'll close this PR.

@0xThiebaut 0xThiebaut closed this Nov 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants