Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

One potential method to reveal a statically generated C string at compile time using FFI is to define a function in the C code that returns a pointer to the string, and then use FFI to call that function from within the target language. For example, in C code you could define a function like this:

const char* getMyString() {
    return "This is my string";
}

Then, in a target language like Python, you could use FFI to call this function and retrieve the string:

import ctypes

mylib = ctypes.CDLL('./mylib.so')
c_string = mylib.getMyString()
print(ctypes.string_at(c_string))

This would output:

b'This is my string'

Here, ctypes.CDLL loads the compiled C library, and mylib.getMyString() calls the function defined in the C code to retrieve the C string. The ctypes.string_at function is then used to convert the C string into a Python string that can be printed or manipulated in other ways.