Advertisement
tinyevil

Untitled

Jul 29th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. struct DLLFunc{
  2.     private{
  3.         field funchandle:i32;
  4.         field dllhandle:i32;
  5.     }
  6.    
  7.     function load(dllname:string, funcname:string):Bar{
  8.         let dllhandle = load_dll(dllname);
  9.         return Bar {
  10.             dllhandle = dllhandle,
  11.             funchandle = get_proc_by_addr(dllhandle, funcname)
  12.         };
  13.     }
  14.    
  15.     method invoke(self:ref DLLFunc, data:ref[] u8){
  16.         dll_invoke(self->dllhandle, self->funchandle, data);
  17.     }
  18. }
  19.  
  20. instance Drop DLLFunc {
  21.     function drop(val:in Bar){
  22.         close_handle(val->funchandle);
  23.         close_dll(val->dllhandle);
  24.     }
  25. }
  26.  
  27. instance Copy DLLFunc {
  28.     function copy(target:out Bar, source:ref Bar){
  29.         target->dllhandle = dup_dll(source->dllhandle);
  30.         log("DLL Handle duped");
  31.         target->funchandle = dup_funchandle(
  32.             source->dllhandle,
  33.             source->funchandle,
  34.             target->dllhandle
  35.         );
  36.         log("Func Handle duped");
  37.     }
  38. }
  39.  
  40. global var logfunc:DLLFunc = DLLFunc::load("stdio", "_print");
  41.  
  42. function log(message:string){
  43.     logfunc->invoke(message.get_data());
  44. }
  45.  
  46. function update_logger(func:ref DLLFunc){
  47.     logfunc = *func;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement