Thread: Any code to create another executable?

  1. #31
    Disagreeably Disagreeable
    Join Date
    Aug 2001
    Well, you could (for the characters that aren't "friendly") just work with the ASCII numbers.

    But, as far as actual text (and not numbers) goes, I can't think of anything right now. I'm pretty tired (it's 3 AM here), so I'm not thinking very well.

  2. #32
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    There is a very simple way for an EXE to delete itself after running. Most programs will call DOS function 4C00 to terminate the program. Prior to running your program, hook int 21h, function 4c00h. Now when the program calls it you will know which program did by looking at either the command line or looking at the PSP/Environment block - I forget which holds the program name or you could compare that to the caller's address/segment (could be called from diff segment, though not likely since will be the end of the program) - which will be on the stack. Then you can search through the FAT, find the cluster number of the file that matches the name, trace the chain marking each cluster as empty( 00h) and placing character 0x229 in the first letter of the directory entry. If you are in DOS 6.20+ you will have to unlock the volume if it is a hard drive or DOS will not allow you to access the hard drive via int 13h. It's possible to delete directories, files, partitions, or restore/create directories, partitions, files, etc. Unfortunately there is not RESTREE command to restore directories in DOS, even though it is possible.

    If you are interested I have code that will extract the boot sector off a disk and save it as a binary file. You can also replace the boot sector by specifying a new binary file. Note that this code can destroy your boot sector on your hard drive. Easy way to fix this is to FDISK /MBR which re-writes the bootsector code to the disk. All of the file is in hex like you have been talking about. Each of those hex values corresponds to opcodes and operands, strings, constants, etc. To explain all of it would take lots of time and you would need to be well-versed in assembly language.

    But , it is possible to write assembly code in hex and execute it. If you look at the old days of BASIC programming many people did this to write small assembly language functions for their BASIC programs. You just place the values in memory and jump to the start of the code or perform a call to the address of the start of the code.

    For instance the opcode for a short jump to a 16 bit offset:segment pair is EA. This would appear in a text file as ASCII 234 which would display some odd character. The actual encodings of the opcodes/operands/SIB byte/MOD r/m byte are extremely complex - thus CISC, but debuggers interpret this data and display it as assembly mneumonics so that we the programmers can read it.

  3. #33
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    ahh i think the stuff above is a bit complicated for me. However if u show me the binary for the retrieving the boot sector that'll be nice. But i guess there'll be no easy way to a file to delete itself? DOesn't matter.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Create EAN code in c#
    By Limpan in forum C# Programming
    Replies: 3
    Last Post: 05-18-2009, 05:37 AM
  2. how to properly call an executable from C code?
    By remy06 in forum C Programming
    Replies: 3
    Last Post: 05-14-2009, 03:48 AM
  3. Replies: 23
    Last Post: 04-20-2009, 07:35 AM
  4. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  5. Replies: 4
    Last Post: 01-16-2002, 12:04 AM