0

I made a simple Windows batch file to decode JARs and APKs, and it worked:

@ECHO off
 SETLOCAL ENABLEDELAYEDEXPANSION
 SET listejar=:core.jar:core-junit.jar:bouncycastle.jar:ext.jar:framework.jar:framework2.jar:android.policy.jar:services.jar:apache-xml.jar:filterfw.jar:java.awt.jar:svc.jar:am.jar:android.test.runner.jar:bmgr.jar:bu.jar:com.android.future.usb.accessory.jar:com.android.location.provider.jar:com.google.android.maps.jar:com.google.android.media.effects.jar:com.google.widevine.software.drm.jar:com.samsung.device.jar:com.yamaha.android.media.jar:twframework.jar:send_bug.jar:GlobalConfig.jar:ime.jar:input.jar:javax.obex.jar:libvtmanagerjar.jar:minimode.jar:monkey.jar:pm.jar:seccamera.jar:secframework.jar:sechardware.jar:secmediarecorder.jar:sec_feature.jar
 SET baksmali=c:\DO\baksmali.jar
 SET smali=c:\do\smali.jar
 SET BTP1=c:\do
 SET BTP2=c:\do\framework

FOR %%F IN ("*.odex") DO (
        @echo.
        @echo.
        @echo.
        ECHO Decompiling %%F
        java -Xmx1024m -jar %baksmali% -a 15 -d %btp1% -d %btp2% -c %listejar% -x "%%F" -o "%%~nF"
        ECHO Compiling %%~nF classses.dex
        md "%%~dpnF"_o
        java -Xmx1024m -jar %smali% -a 15 %%~nF -o "%%~dpnF"_o\classes.dex
        RD /s/q "%%~dpnF"

        C:\DO\7z.exe u "%%~dpnF".jar %%~dpnF"_o\classes.dex >NUL
        RD /s/q %%~dpnF"_o
        DEL %%~dpnxF
        ECHO %%~nF is Deodexed
    )
cd..

CD app
FOR %%F IN ("*.odex") DO (
        @echo:
        @echo:
        @echo:
        ECHO Decompiling %%F
        java -Xmx1024m -jar %baksmali% -a 15 -d %btp1% -d %btp2% -c %listejar% -x "%%F" -o "%%~nF"
        ECHO Compiling %%~nF classses.dex
        md "%%~dpnF"_o
        java -Xmx1024m -jar %smali% -a 15 %%~nF -o "%%~dpnF"_o\classes.dex
        RD /s/q "%%~dpnF"
        C:\DO\7z.exe u "%%~dpnF".apk %%~dpnF"_o\classes.dex >NUL
        RD /s/q %%~dpnF"_o
        DEL %%~dpnxF
        ECHO %%~nF is Deodexed
    )
echo ALL DONE press any key to exit
pause >NUL
exit

But then I tried to make it a bit better, and I don't know what i did wrong. It now exits right away. Help on the matter will be really appreciated.

This is what I tried to do in the revised version:

@ECHO off
 SETLOCAL ENABLEDELAYEDEXPANSION
 SET listejar=:core.jar:core-junit.jar:bouncycastle.jar:ext.jar:framework.jar:framework2.jar:android.policy.jar:services.jar:apache-xml.jar:filterfw.jar:java.awt.jar:svc.jar:am.jar:android.test.runner.jar:bmgr.jar:bu.jar:com.android.future.usb.accessory.jar:com.android.location.provider.jar:com.google.android.maps.jar:com.google.android.media.effects.jar:com.google.widevine.software.drm.jar:com.samsung.device.jar:com.yamaha.android.media.jar:twframework.jar:send_bug.jar:GlobalConfig.jar:ime.jar:input.jar:javax.obex.jar:libvtmanagerjar.jar:minimode.jar:monkey.jar:pm.jar:seccamera.jar:secframework.jar:sechardware.jar:secmediarecorder.jar:sec_feature.jar
 SET baksmali=c:\DO\baksmali.jar
 SET smali=c:\do\smali.jar
 SET BTP1=c:\do
 SET BTP2=c:\do\framework

CD framework
 IF EXIST *.odex ( GOTO STARTFW ) ELSE ( ECHO Odex Not Found && GOTO FINISHEDFW )

 :STARTFW
 FOR %%F IN ("*.odex") DO (
 @echo.
 @echo.
 @echo.
 ECHO Decompiling %%~nxF
 java -Xmx1024m -jar %baksmali% -a 15 -d %btp1% -d %btp2% -c %listejar% -x "%%F" -o "%%~nF"
 ECHO Compiling %%~nF classses.dex
 MD "%%~dpnF"_o
 java -Xmx1024m -jar %smali% -a 15 %%~nF -o "%%~dpnF"_o\classes.dex
 RD /s/q "%%~dpnF"
 IF EXIST "%%~dpnF"_o\classes.dex (GOTO CONTINIUEFW) ELSE (GOTO CHECKFW)

 :CHECKFFW
 IF NOT EXIST C:\DO\Framework\ERORR ( MD C:\Framework\Error )
 MOVE /Y "%%~dpnF".* C:\Framework\Error
 ECHO Error With %%~nxF & %%~nF.jar
 ECHO Moved To Error Folder
 GOTO SKIPFW

 :CONTINIUEFW
 ECHO Injecting classes.dex to "%%~nF".jar
 C:\DO\7z.exe u "%%~dpnF".jar %%~dpnF"_o\classes.dex >NUL
 RD /s/q %%~dpnF"_o
 DEL %%~dpnxF
 ECHO %%~nF.jar is Deodexed
 IF EXIST *.odex ( 
  GOTO STARTFW
  ) ELSE ( 
  ECHO Odex Not Found
  GOTO FINISHEDFW
  )

 :SKIPFW
 )

:FINISHEDFW
CD..
CD app

 IF EXIST *.odex ( 
  GOTO STARTAPP 
  ) ELSE ( 
   ECHO Odex Not Found
   GOTO FINISHEDAPP
 )
:STARTAPP
 FOR %%F IN ("*.odex") DO (
 @echo.
 @echo.
 @echo.
 ECHO Decompiling %%~nxF
 java -Xmx1024m -jar %baksmali% -a 15 -d %btp1% -d %btp2% -c %listejar% -x "%%F" -o "%%~nF"
 ECHO Compiling %%~nF classses.dex
 MD "%%~dpnF"_o
 java -Xmx1024m -jar %smali% -a 15 %%~nF -o "%%~dpnF"_o\classes.dex
 RD /s/q "%%~dpnF"
 IF EXIST "%%~dpnF"_o\classes.dex ( GOTO CONTINIUEAPP ) ELSE ( GOTO CHECKAPP )

 :CHECKFAPP
 IF NOT EXIST C:\DO\app\ERORR ( MD C:\app\Error )
 MOVE /Y "%%~dpnF".* C:\app\Error
 ECHO Error With %%~nxF & %%~nF.apk
 ECHO Moved To Error Folder
 GOTO SKIPAPP

 :CONTINIUEAPP
 ECHO Injecting classes.dex to "%%~nF".apk
 C:\DO\7z.exe u "%%~dpnF".apk %%~dpnF"_o\classes.dex >NUL
 RD /s/q %%~dpnF"_o
 DEL %%~dpnxF
 ECHO %%~nF.apk is Deodexed
 IF EXIST *.odex ( 
  GOTO STARTAPP
  ) ELSE ( 
  ECHO Odex Not Found
  GOTO FINISHEDAPP
 )

 :SKIPAPP

 )

echo ALL DONE press any key to exit
pause >NUL
exit 
  • There's a lot of script code here; it might help if you specifically included only the bits that you changed (before and after). Additionally, you might consider sprinkling the script with various different `echo` calls to see how far the script is getting before exiting. I've found that to be a useful way to debug CMD scripts... – reuben Jul 07 '12 at 18:34
  • after `cd framework` when its at `IF EXIST *.odex ( GOTO STARTFW ) ELSE ( ECHO Odex Not Found && GOTO FINISHEDFW )` it shows this in cmd: `C:\DO\framework>IF EXIST *.odex (GOTO STARTFW ) ELSE (ECHO Odex Not Found && GOTO FINISHEDFW )` `) was unexpected at this time.` `C:\DO\framework> )` then it exits – user1509093 Jul 07 '12 at 19:07
  • What's the stray `)` after `SKIPFW`? – reuben Jul 07 '12 at 19:17
  • just to save jumping around, I would do `IF NOT EXIST Filename GOTO NextBit`, then the else stuff is not required, and less places to get errors – SeanC Jul 07 '12 at 20:31

1 Answers1

1

I haven't traced your code to see why you are getting the syntax error. But I see a serious problem - You are attempting to use GOTO within a loop and branch to a label within the same loop. That simply will not work the way you want it to work. The moment you use GOTO, the loop is broken. The GOTO finds the label OK, but the script no longer knows anything about the loop. Your results are bound to be other than what you intend unless you are really clever and want to obfuscate your code.

Generally you should never GOTO a label within a parenthesized block of code. This is true for both FOR loops and IF statements. See (Windows batch) Goto within if block behaves very strangely for a similar problem within an IF/ELSE block.

Community
  • 1
  • 1
dbenham
  • 127,446
  • 28
  • 251
  • 390