Advertisement
P22DX

test.php

Aug 4th, 2020
1,358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.57 KB | None | 0 0
  1. <?php
  2.  
  3. $headerName = 'stdio.h';
  4. $libName = 'libc.so';
  5.  
  6. try {
  7.     $libc = FFI::load($headerName);
  8.     var_dump($libc);
  9. } catch(FFI\Exception $e)
  10. {
  11.     fprintf(STDERR, '%s on line %s%s', $e->getMessage(),$e->getLine(), PHP_EOL);
  12.     $headerContent = sprintf('#define FFI_LIB "%s"%s', $libName, PHP_EOL);
  13.     $headerContent .= sprintf('#define FFI_SCOPE "_%s"%s', strtoupper($libName), PHP_EOL);
  14.  
  15.     if(file_put_contents($headerName, $headerContent)) {
  16.         echo exec(sprintf('cpp -P -C -D"__attribute__(ARGS)="$(find $PREFIX -type f -name %s)>>%s', $headerName, $headerName));
  17.     }
  18. }
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement