Created
September 14, 2014 16:08
-
-
Save mrsasha/9f24e129ced1b1db791b to your computer and use it in GitHub Desktop.
.jar and .dex method count helpers for Windows. dx from build-tools in the Android SDK has to be in your PATH. Just call methodcount.bat "filename"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
IF "%1"=="" GOTO MissingFileNameError | |
IF EXIST "%1" (GOTO ContinueProcessing) ELSE (GOTO FileDoesntExist) | |
:ContinueProcessing | |
set FileNameToProcess=%1 | |
set FileNameForDx=%~n1.dex | |
IF "%~x1"==".dex" GOTO ProcessWithPowerShell | |
REM preprocess Jar with dx | |
IF "%~x1"==".jar" ( | |
ECHO Processing Jar %FileNameToProcess% with DX! | |
CALL dx --dex --output=%FileNameForDx% %FileNameToProcess% | |
set FileNameToProcess=%FileNameForDx% | |
IF ERRORLEVEL 1 GOTO DxProcessingError | |
) | |
:ProcessWithPowerShell | |
ECHO Counting methods in DEX file %FileNameToProcess% | |
CALL powershell -noexit -executionpolicy bypass "& ".\printhex.ps1" %FileNameToProcess% | |
GOTO End | |
:MissingFileNameError | |
@ECHO Missing filename for processing | |
GOTO End | |
:DxProcessingError | |
@ECHO Error processing file %1% with dx! | |
GOTO End | |
:FileDoesntExist | |
@ECHO File %1% doesn't exist! | |
GOTO End | |
:End |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Outputs the number of methods in a dex file. | |
.PARAMETER Path | |
Specifies the path to a file. Wildcards are not permitted. | |
#> | |
param( | |
[parameter(Position=0,Mandatory=$TRUE)] | |
[String] $Path | |
) | |
if ( -not (test-path -literalpath $Path) ) { | |
write-error "Path '$Path' not found." -category ObjectNotFound | |
exit | |
} | |
$item = get-item -literalpath $Path -force | |
if ( -not ($? -and ($item -is [System.IO.FileInfo])) ) { | |
write-error "'$Path' is not a file in the file system." -category InvalidType | |
exit | |
} | |
if ( $item.Length -gt [UInt32]::MaxValue ) { | |
write-error "'$Path' is too large." -category OpenError | |
exit | |
} | |
$stream = [System.IO.File]::OpenRead($item.FullName) | |
$buffer = new-object Byte[] 2 | |
$stream.Position = 88 | |
$bytesread = $stream.Read($buffer, 0, 2) | |
$output = $buffer[0..1] | |
#("{1:X2} {0:X2}") -f $output | |
$outputdec = $buffer[1]*256 + $buffer[0] | |
"Number of methods is " + $outputdec | |
$stream.Close() |
use the suggested batch-name methodcount.bat
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have set dx.bat file path on PATH variable but still i am getting "dx' is not recognize as internal or external command".