guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Executing Arbitrary Machine Code in Guile


From: Jan Wedekind
Subject: Re: Executing Arbitrary Machine Code in Guile
Date: Sat, 22 Aug 2015 09:08:59 +0100
User-agent: K-9 Mail for Android

Executing machine code basically just requires a call to mmap to make the data 
executable. The calling code can be generated on the fly using ffi:
http://github.com/wedesoft/aiscm

On August 22, 2015 12:31:56 AM GMT+01:00, Elzair <address@hidden> wrote:
>The other day I came across a page on Rosetta Code showing how to
>directly execute x86 instructions across several languages:
>http://rosettacode.org/wiki/Machine_code
>
>For example, here is the code for Racket.
>#lang racket/base
> 
>(require ffi/unsafe)
> 
>; set up access to racket internals
>(define scheme-malloc-code
>(get-ffi-obj 'scheme_malloc_code #f (_fun (len : _intptr) ->
>_pointer)))
>(define scheme-free-code
>(get-ffi-obj 'scheme_free_code #f (_fun _pointer -> _void)))
> 
>(define opcodes '(139 68 36 4 3 68 36 8 195))
> 
>(define code (scheme-malloc-code 64))
> 
>(for ([byte opcodes]
>[i (in-naturals)])
>(ptr-set! code _ubyte i byte))
> 
>(define function (cast code _pointer (_fun _ubyte _ubyte -> _ubyte)))
> 
>(function 7 12)
> 
>(scheme-free-code code)
>
>Is this possible in Guile (with, say, the FFI)?

-- 
Jan Wedekind
http://www.wedesoft.de/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]