namespace DexerPOC
{
enum State: int
{
ERROR_CONTACTING_SERVER = 0x101,
ERROR_INVALID_PACKAGE_NAME = 0x102,
ERROR_NON_MATCHING_UID = 0x103,
ERROR_NOT_MARKET_MANAGED = 0x3,
ERROR_SERVER_FAILURE = 0x4,
ERROR_OVER_QUOTA = 0x5,
LICENSED = 0x0,
LICENSED_OLD_KEY = 0x2,
NOT_LICENSED = 0x1
}
class Program
{
static void Main(string[] args)
{
Dex dex = Dex.Read("classes.dex");
Console.WriteLine("Dexer Licensing POC - Scanning instructions...");
foreach (ClassDefinition cdef in dex.Classes)
foreach (MethodDefinition mdef in cdef.Methods)
if (mdef.Body != null)
foreach (Instruction ins in mdef.Body.Instructions)
if (ins.OpCode == OpCodes.Sparse_switch)
{
SparseSwitchData data = ins.Operand as SparseSwitchData;
if (data.Targets.Keys.All(key => Enum.IsDefined(typeof(State), key) ))
{
Console.WriteLine("SparseSwitch found! - {0}", mdef);
data.Targets[(int) State.NOT_LICENSED] = data.Targets[(int) State.LICENSED];
}
}
Console.WriteLine("Done!");
dex.Write("output.dex");
}
}
}