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

Unable to debug .NET application that uses P/Invoke from compiled CFFI library #651

Closed
yoghurtbot opened this issue Dec 23, 2021 · 1 comment
Assignees

Comments

@yoghurtbot
Copy link

yoghurtbot commented Dec 23, 2021

I'm trying to use Helheim (a pyarmor protected package) in a CFFI compiled C-Shared library in a .NET application using P/Invoke.

I've compiled a DLL with the following FFI builder code. I've tried Python 3.7, 3.8 and 3.9. I'm compiling everything on x64

Python Code

from helheim_cffi import ffi

sys.path.append(os.getcwd())
import helheim << pyarmor protected package

@ffi.def_extern()
def auth(apiKey, discover):
    helheim.auth(getString(apiKey), discover=discover)

    return responseWrapper({
        'sessionID': 0,
        'response': 'authenticated'
    })

FFI Builder Code

ffibuilder = cffi.FFI()

ffibuilder.embedding_api(
    """
    char *auth(char apiKey[], int discover);
    """
)

libraryPath = sysconfig.get_config_vars('LIBDIR')
if libraryPath and libraryPath[0]:
    ffibuilder.set_source("helheim_cffi", "", library_dirs=libraryPath)
else:
    ffibuilder.set_source("helheim_cffi", "")

with open('template.tpl', 'r') as code:
    ffibuilder.embedding_init_code(code.read())


ffibuilder.compile(
    target=f"../helheim_cffi.{extensionMap[platform.system()]}",
    verbose=True
)

I'm able to use the DLL in .NET by doing the following:

    public static class External
    {
        [DllImport("helheim_cffi.dll")]
        private static extern IntPtr auth(string apiKey, bool discover);
        .....

However, when I debug the .NET code in Visual Studio 2022, my .NET application forcefully closes without error or exception. When I run the application outside of VS, the program executes as desired.

Is pyarmor's anti-debugger stopping me from debugging my .NET code when a pyarmor protected package is compiled into a C-Shared library?

@jondy
Copy link
Contributor

jondy commented Dec 23, 2021

pyarmor anti-debug will disable some system debug features, If .Net debugger use these feature, it may not work.

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

2 participants