Question

Here is a short batch program I made to call other batch files. The code is as below.

@echo off
setlocal EnableExtensions EnableDelayedExpansion
:choice
cls
@call makeline
echo Choose an action from below:
@call makeline
echo.
echo 1. Disassemble a suspect malware.
echo 2. Image a disk drive.
echo 3. Generate MD5 hash of a file.
echo 4. View Report.
echo 5. Exit Malverse 1.2
echo.
@call makeline

set "ch=%gch1%"
goto :chCheck
:chPrompt
echo Select by typing in the number [1-5] and hit the RETURN key.
set /p "ch=[1-5]: "
:chCheck
if not defined ch goto :chPrompt
echo %ch%
pause

if %ch% == 1 (
set ch=
GOTO disasm
)

if %ch% == 2 (
set ch=
GOTO image
)

if %ch% == 3 (
set ch=
GOTO hash
)

if %ch% == 4 (
set ch=
GOTO view
)

:hash
@call makeline
@call hasher

:disasm
@call makeline
@call disassembler

:image
@call makeline
@call imager

:view
@call makeline
@call report

pause
endlocal

This program should be giving output, say, if I enter 1 as the option from the menu, it should call the disassembler file.

Option: 1
Disassembler 2.2.

However, instead of doing that, it keeps calling the report file which is supposed to only be called by the option of 4. After running another test using 3 as the option, this time, it called the hasher file but then again also calling the report file later on.

Test Case: 1 results

Option: 1
Report viewer opened.

Test Case: 3 results

Option: 3
Hasher begins here.
Report viewer opened. 

Curious, I also checked the file names and it appeared to match exactly. I have checked some sites but to no avail. Also, I tried to sort of debug using @echo on at the top of the code but no error message was displayed. Please help.

Was it helpful?

Solution 2

Okay, I asked further around...external to this site and finally got the answer, thought I should share it here,

if %ch% == 4 (
set ch=
GOTO view
)
goto end

:disasm
@call makeline
@call disassembler
pause
goto end

I have to add

pause
goto end

in each of the function blocks and a goto end at the end of the final if block to make it work the way I want. Thanks for replies and views. Credits for the solution to Max Chu; a friend of mine.

OTHER TIPS

If you enter 1, it will GOTO disasm, but on reaching :disasm it will fall through to :image and then :view and hence call the report. Did you mean to include GOTO choice after each block?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top