Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

40
LINES

< > BotCompany Repo | #1004178 // loadDex - load & optionally run a dex on Android

JavaX fragment (include)

static synchronized S loadDex(byte[] dex, bool run) ctex {
  assertTrue("Not a dex file", isDex(dex));
  
  Class j = getJavaX();
  
  ClassLoader parentClassLoader = j.getClassLoader().getParent();
      
  File dexDir = (File) call(j, "TempDirMaker_make");
  File dexFile = new File(dexDir, "spontaneous.dex");
  //File dexFile = prepareProgramFile("spontaneous.dex");
  
  saveBinaryFile(dexFile, dex);
  print("dexFile: " + dexFile.getAbsolutePath());
  assertEquals((long) dex.length, dexFile.length());
  print("Dex size: " + dex.length);
  
  // For Android's optimized class data (must be an app-local dir)
  File dexOutputDir = makeAndroidTempDir();
 
  Class dcl = Class.forName("dalvik.system.DexClassLoader");
  O classLoader = dcl.getConstructors()[0].newInstance(dexFile.getAbsolutePath(), dexOutputDir.getAbsolutePath(), null,
    parentClassLoader);

  final Class<?> mainClass = (Class<?>) call(classLoader, "loadClass", "main");
  
  hotwire_copyOver(mainClass);
    
  final O paa = nuObject(_getClass(j, j.getName() + "$PaA"));
  S injectionID;
  set(paa, "injectionID", injectionID = randomID(8));
  set(paa, "mainClass", mainClass);
  call(j, "addInjection", paa);
  
  if (run)
    thread "Spontaneous DEX" {
      callMain(mainClass);
    }
  
  ret format("OK, injection id: *", injectionID);
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1004178
Snippet name: loadDex - load & optionally run a dex on Android
Eternal ID of this version: #1004178/1
Text MD5: 4940c9aff9b3cc9809fdf3fc190c8eaf
Author: stefan
Category: javax / android
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-11-15 15:06:15
Source code size: 1358 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 660 / 618
Referenced in: [show references]