|
In 1995 I try to experiment a new kind of programming technique: it is possible to have a program that make the same result if it is executed by the Dos batch process or directly from machine language? In other words, can a BAT file be executed like a COM file and produce the same results?
I find a solution that codify in a program that generate this file that I simple call Bat Com Equal (BCE). if you have a BCE file, you must rename it into BAT or COM extension, run it and obtain the same (99%) equal result.
How this is possible?
The solution is to divide the program into 3 part:
The first instruction we usually want that a BAT file performs is a disable of it's command output. This is done by
@echo offBut what happen if we execute the previous code using it like machine code?
ASCII HEX ASSEMBLY @ 40 inc ax e 65 arpl [bx+si+6F],bp c 63 h 68 o 6F 20 and [bx+66],eax o 6F f 66 f 66 ...How you can see the machine execution is not possible because we modify some memory locations that we don't know.
Well, we can try with the upper case mode:
ASCII HEX ASSEMBLY @ 40 inc ax E 45 inc bp C 43 inc bx H 48 dec ax O 4F dec di 20 and [bx+46],cl O 4F F 46 F 46 inc siThis is little better, but the use of the space give us an operation that modify memory location, so the space will be substituted.
ASCII HEX ASSEMBLY @ 40 inc ax E 45 inc bp C 43 inc bx H 48 dec ax O 4F dec di 0A or cl,[bx+46] O 4F F 46 F 46 inc si 0A or cl,[di] 0D 0A or al,[...] xx other line with ECHO of point 2 yyIn this version I use the change row key instead of the space, and a combination of change row, return, change row to finish the BAT instruction.
In point 2 we want a line that do nothing in BAT mode, but do something in COM mode. The instruction is so like this:
ECHO ..... >NULLIn fact this instruction in BAT mode produce a echo in the null file of it's body (the .....). So look at the machine code:
ASCII HEX ASSEMBLY E 45 inc bp C 43 inc bx H 48 dec ax O 4F dec di 0A or ah,[bx+si] 20 ..... 74 je xx+2 xx+2 75 jne xx xx > 3E N 4E U 55 L 6C 0D 0AHow you can see this is the form of the instruction we need: it is in the form we want for the BAT, and due to the 0Ah, 20h, we can put the COM body where there's the points. At the end of COM, I insert a jump to xx, the next instruction of point 2, so the 3 point is simple...
Due to the previous jump the instruction we need in this point is a normal BAT that is equals to the previous COM instruction.
End of Program
HEX ASSEMBLY CD int 20h 20Write a string
HEX ASSEMBLY E8 00 00 call $+1 5A pop dx 0E push cs 1F pop ds 83 C2 xx add dx,00xx 8B DA mov bx,dx 83 C3 yy add bx,yy C6 07 24 mov [bx],'$' B4 09 mov ah,09 CD 21 int 21hIn this case the string must not contains the $ char, and the address of string is taken from BAT instruction of point 3 (so only one string is needed).
Clear Screen
HEX ASSEMBLY B4 0F mov ah,0f CD 10 int 10h B4 00 mov al,00 CD 10 int 10hECHO %1
HEX ASSEMBLY B4 62 mov ah,62h CD 21 int 21h 53 push bx 1F pop ds BE 82 00 mov si,82h 3E 8A 14 yy: mov dl,ds:[si] 80 FA 20 cmp dl,20h 74 10 je xxxx FE CA dec dl 80 FA 0C cmp dl,0C 74 09 je xxxx FE C2 inc dl B4 02 mov ah,02 CD 21 int 21h 46 inc si EB E8 xx: jmp yyThe BCE generator is a C program containing the above coded instructions: all you need is to give it the call to the instructions you want to generate.
Download the BCE (2K) source package.
PC | Tognon Stefano programs |