Page 1 of 1

Embedded binary example does not work

Posted: Mon Mar 13, 2006 2:20 pm
by pjot
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

Posted: Mon Mar 13, 2006 4:13 pm
by Lutz
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

Posted: Mon Mar 13, 2006 8:18 pm
by pjot
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