home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_08_08
/
8n08139a
< prev
next >
Wrap
Text File
|
1990-07-18
|
843b
|
44 lines
#include <stdio.h>
/* re: "Executable Strings" by James A. Kuzdrall in the May 1990 issue.
* It is possible to execute stings in any 80x86 memory model by
* casting the string to a far function pointer.
*
* Yours Truly,
*
* Rick Shide
* Moore Data Management
* S Hwy 100
* Minneapolis, MN 55416-1519
*/
/* asm equivalent of executable string setting return value to 5
*
* mov ax,5 ; B8 05 00
* ret ; CB
*/
typedef int (far *FPFI)(); // pointer to far function returning int
/* demonstrate executable strings
*/
main()
{
int i;
char *str;
/* immediate form
*/
i = ((FPFI)"\xb8\x05\x00\xcb")();
printf("%d\n", i); // will print "5"
/* string ptr form
*/
str = "\xb8\x34\x12\xcb";
i = ((FPFI)str)();
printf("0X%x\n", i); // will print "0X1234"
}