importing embedded dynamic lib

From: Vio (vmilitaru_at_sympatico.ca)
Date: 06/09/04


Date: Wed, 09 Jun 2004 08:23:39 -0400

I have a basic dynamic lib "noddy.so" which I want to
1- embed inside my executable
2- import by embedded python interpreter using an API call.

I have two questions:

1- what would be the recommended technique to embed a binary file inside
an executable?
My guess would be to add the binary "noddy.so" to the linking command,
but then
how do I get access to that chunk of code in my source file? My goal
would be to achieve something like

    int* noddy_so = <binary here> ... but then how do I include the
binary code, or make the source code aware of it?

Using "#include" doesn't feel right, as this is a binary file, not
ASCII. And loading the file at run-time isn't right either, I need to
load it at compile time. And is "int*" the appropriate data type for
binary data?

2- Let's imagine that I managed to load "noddy.so" into my source code
somehow, and now have a pointer to it.
Any hints as to the correct python API call to import a dynamic lib
from a memory buffer? Could someone
tell me for example if the following makes sense for my purpose?

------------------------------
char *modulename="noddy", *filename="no_real_file";
PyObject *tmp;

/*Here try to translate the binary lib into a PyObject*/
tmp = Py_CompileString(noddy_so, filename, Py_file_input);
if (tmp == NULL)
      error("Can't compile module [tmp]");

/*Import the "noddy" module*/
pmod = PyImport_ExecCodeModule(modulename, tmp);
if (pmod == NULL)
      error("Can't load module [pmod]");
------------------------------

Regards,
Vio



Relevant Pages

  • Re: Identifying call of copy of ((){ })();
    ... The code is effectively identical for both but API has a few subtle differences that I need to take into account. ... Is there a someway to tell if the public methods are called ... might expose that source code the work needed to extract the information would be a huge overhead. ... It would probably be simpler to wrap the fist object in a second that implemented an identical public interface and then you could know which was called based on the identity of the functions that made up the two interfaces. ...
    (comp.lang.javascript)
  • Re: CREATEPROCESS Question
    ... this isn't just a spurious recompile. ... source code changes should normally be needed except in rare special ... commercial applications. ... For an operating system API, it can be a pretty big one. ...
    (comp.lang.fortran)
  • Re: Windows API + Hotkey
    ... calls to the Windows API's. ... here's some websites that will help you figure out what the API ... Rob wrote: ... have to print off the source code when I go back to work Monday. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Identifying call of copy of ((){ })();
    ... The code is effectively identical for both but API has a few subtle differences that I need to take into account. ... Is there a someway to tell if the public methods are called ... might expose that source code the work needed to extract the information would be a huge overhead. ... It would probably be simpler to wrap the fist object in a second that implemented an identical public interface and then you could know which was called based on the identity of the functions that made up the two interfaces. ...
    (comp.lang.javascript)
  • RE: what is format spc object id in memory?
    ... By reading their source code, you'll find all the answers you need. ... "Anand Choubey" wrote: ... I am trying to understand code signing part of any binary. ... do not see any such string in signed binary file. ...
    (microsoft.public.platformsdk.security)