Embedded binary example does not work

Started by pjot, March 13, 2006, 06:20:00 AM

Previous topic - Next topic

pjot

Hi,



Trying the code shown here:



http://www.newlisp.org/index.cgi?page=Embedded_Binary">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

(cpymem (pack "ld" 265) (first (dump foo)) 4)

changed into

(cpymem (pack "ld" 264) (first (dump foo)) 4)


2) The resume at the end is incomplete, the line changing the type is missing.
Quote
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

#1
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

#2
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