Windows批处理文件错误

时间:2012-07-07 18:21:55

标签: windows batch-file cmd

我制作了一个简单的Windows批处理文件来解码JAR和APK,它起作用了:

@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

但后来我试着让它变得更好,而且我不知道自己做错了什么。它现在立即退出。对此事的帮助将非常感激。

这是我在修订版中尝试做的事情:

@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 

1 个答案:

答案 0 :(得分:1)

我没有跟踪您的代码,看看为什么会出现语法错误。但是我发现了一个严重的问题 - 你试图在一个循环中使用GOTO并在同一个循环中转移到一个标签。这根本不会按照您希望的方式工作。使用GOTO的那一刻,循环就被打破了。 GOTO找到标签OK,但脚本不再了解循环。你的结果必然不是你想要的,除非你真的很聪明,并且想要混淆你的代码。

通常,您不应该在带括号的代码块中使用GOTO标签。对于FOR循环和IF语句都是如此。有关IF / ELSE块中的类似问题,请参阅(Windows batch) Goto within if block behaves very strangely