| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Some updates: I've gotten arbitrary function argument passing to work on a test, I still am figuring out return type inference however. use std::ffi::c_void;
use std::path::Path;
use libffi::middle as libffi;
use libloading::Symbol;
type FP = unsafe extern "C" fn ();
fn main() {
let path = "C:\\Windows\\System32\\kernel32.dll";
let path = Path::new(path);
let lib = unsafe { libloading::Library::new(path) }.unwrap();
let function_bytes = b"Sleep\0";
let function: Symbol<FP> = unsafe { lib.get(function_bytes) }.unwrap();
let function = *function;
let args = vec![libffi::Type::u32()];
let cif = libffi::Cif::new(args.into_iter(), libffi::Type::void());
let ms_wait: u32 = 5000;
println!("Calling function");
let now = std::time::Instant::now();
let _res: *const c_void = unsafe { cif.call(libffi::CodePtr(function as *mut _), &[libffi::arg(&ms_wait)]) };
println!("Function returned in {}ms", now.elapsed().as_millis());
println!("Function called");
}Calling function Function returned in 5001ms Function called |
Sorry, something went wrong.
|
Nevermind, it seems like return type needs to be manually specified and the default is cint |
Sorry, something went wrong.
|
Ready for review. (this is from the extra test) libc = cdll.msvcrt
print("rand", libc.rand())/cc @youknowone |
Sorry, something went wrong.
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
There was a problem hiding this comment.
Looks good, thank you so much!
Please check if the extra indent is intended or not.
Sorry, something went wrong.
|
Done. |
Sorry, something went wrong.
There was a problem hiding this comment.
👍
Sorry, something went wrong.
Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
| Back | FazBrowse Home | New Git URL |
Here comes the meat of the code and the hardest part implementation-wise.
The main goal is to implement (atleast partially) CFuncPtr. By partially, I mean that not supporting arguments to functions is probably fine. At any rate the cpython implementation can be used as a reference since they use libffi. The main challenge is determining the return type of the loaded function from the cvoid it'll return (unless we don't have to do that for some reason).
The next pr can probably just do some cleanup on this and get the basics for struct and union return types working.
Known issues