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

Implement loading functions from static linked libraries #1

Open
playXE opened this Issue Dec 19, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@playXE
Copy link
Owner

playXE commented Dec 19, 2018

Example:

let func = Function::new(Name::External("printf");

@playXE playXE changed the title Implement calling function from static linked libraries Implement loading functions from static linked libraries Dec 19, 2018

@playXE playXE added the help wanted label Dec 19, 2018

@Nopey

This comment has been minimized.

Copy link

Nopey commented Dec 27, 2018

It sounds like you want to resolve a symbol at runtime, which is exactly what ld-linux.so does for linux, and windows api provides. Statically linked libraries are traditionally linked at compile time, and may not be available on the end-user's machine. (If it is linked at compile time, the symbols are often stripped)

This seems out of this project's scope, but could be a fairly simple crate.

If you want to search all loaded dynamic libs:

let func = Function::new(dynsym::load_sym("printf", dynsym::Search));
//on linux, maps pretty much to
   let func = Function::new(dlsym("printf", RTLD_DEFAULT))
//on windows, we emulate RTLD_DEFAULT by feeding the modules returned from EnumProcessModules through GetProcAddress, until we find "printf"

Or, if you know what library contains printf:

// LoadLibrary("msvcrt.dll") on win, dlopen("libc.so") on nix
let libc = dynsym::load_libc();
// GetProcAddress("printf", libc) on win, dlsym("printf", libc) on nix
let func = Function::new(dynsym::load_sym("printf", libc));
@playXE

This comment has been minimized.

Copy link
Owner

playXE commented Jan 6, 2019

@Nopey thank you for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment