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: Elzair
Subject: Re: Executing Arbitrary Machine Code in Guile
Date: Tue, 25 Aug 2015 19:47:32 -0400

Thank you very much everyone!
Looking at envy has been very helpful.



> On Aug 22, 2015, at 4:08 AM, Jan Wedekind <address@hidden> wrote:
> 
> 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]