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 >
Text File  |  1990-07-18  |  843b  |  44 lines

  1. #include <stdio.h>
  2.  
  3. /* re: "Executable Strings" by James A. Kuzdrall in the May 1990 issue.
  4.  * It is possible to execute stings in any 80x86 memory model by
  5.  * casting the string to a far function pointer.
  6.  *
  7.  *    Yours Truly,
  8.  *
  9.  *    Rick Shide
  10.  *    Moore Data Management
  11.  *    S Hwy 100
  12.  *    Minneapolis, MN  55416-1519
  13.  */
  14.  
  15. /* asm equivalent of executable string setting return value to 5
  16.  *
  17.  *    mov    ax,5    ; B8 05 00    
  18.  *    ret            ; CB         
  19.  */
  20.  
  21. typedef int (far *FPFI)();        // pointer to far function returning int
  22.  
  23. /* demonstrate executable strings
  24.  */
  25. main()
  26. {
  27.     int        i;
  28.     char    *str;
  29.  
  30.     /* immediate form
  31.      */
  32.     i = ((FPFI)"\xb8\x05\x00\xcb")();
  33.     printf("%d\n", i);                    // will print "5"
  34.  
  35.     /* string ptr form
  36.      */
  37.     str = "\xb8\x34\x12\xcb";
  38.     i = ((FPFI)str)();
  39.     printf("0X%x\n", i);                 // will print "0X1234"
  40. }
  41.  
  42.  
  43.  
  44.