For the Compleat Fan
pjot
Posts: 733 Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:
Post
by pjot » Mon Mar 13, 2006 2:20 pm
Hi,
Trying the code shown here:
http://www.newlisp.org/index.cgi?page=Embedded_Binary
...with newLisp 8.8 delivers errors....? However, I got it running with the following change:
1) the line
Code: Select all
(cpymem (pack "ld" 265) (first (dump foo)) 4)
changed into
Code: Select all
(cpymem (pack "ld" 264) (first (dump foo)) 4)
2) The resume at the end is incomplete, the line changing the type is missing.
6. Putting it all together
; set code
(set 'bindata (pack "ccccccccccc"
0x55 0x8B 0xEC 0x8B 0x45 0x08 0x03 0x45 0x0C 0x5D 0xC3))
; get function template
(set 'foo print)
; change type
(cpymem (pack "ld" 264) (first (dump foo)) 4)
; set code pointer
(cpymem (pack "ld" (address bindata)) (+ (first (dump foo)) 12) 4)
; execute
(foo 3 4) => 7
Regards
Peter
Lutz
Posts: 5289 Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:
Post
by Lutz » Mon Mar 13, 2006 4:13 pm
If you use 264 or 265 depends on the x86 platform you are using. On Win32 it is 265 (stdcall DLL format) on LINUX/UNIX it is 264 (cdecl lib format).
I will add this info and the missing line to the page on the site.
Lutz
pjot
Posts: 733 Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:
Post
by pjot » Mon Mar 13, 2006 8:18 pm
Thanks for the clarifications!
I was trying to get more speed with some assembly code, especially on the calculations and binary rotations, but I found it does not matter much. Which is good, of course :-)
Peter