qq_842316758 2018-04-27 02:19 采纳率: 0%
浏览 1250
已结题

java修改安卓模拟器的IMEI?

用java代码随即修改安卓模拟器的IMEI,原本都是00000000000000,实了一些方法都没该成功,求解答

  • 写回答

2条回答 默认 最新

  • dy18049352903 2018-04-27 03:32
    关注

    该程序实现一下功能,

    1,修改android模拟器的imei,

    2,自动启动android模拟器

    3,运行开机启动程序,ps:这个开机启动程序apk就没放出来了。

    4,停止android模拟器;

    重复1,2,3过程

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;

    public class Test {

    /**

    • @param args
      */
      public static void main(String[] args) {
      try {
      while(true){//

       eidtEmulator();//修改imei
      
       Runtime rt = Runtime.getRuntime();  
       String command = "C:\\Program Files\\Android\\android-sdk\\tools\\emulator -avd AVD-10";    
       rt.exec(command);  // 运行android模拟器
       System.out.println("success run");
      
       Thread.sleep(2*60*1000);//  等待2分钟后,停止android模拟器
       if(findRunningWindowsProcess("emulator-arm.exe")){
             killRunningWindowsProcess("emulator-arm.exe");
      }
      

      }
      } catch (IOException e) {
      e.printStackTrace();
      } catch (Exception e) {
      e.printStackTrace();
      }

      }

      public static void eidtEmulator() throws Exception{
      String oldFilePath = "C:\Program Files\Android\android-sdk\tools\emulator-arm.exe ";
      String newFilePath = "C:\Program Files\Android\android-sdk\tools\emulator-arm1.exe";
      FileInputStream in = new FileInputStream(oldFilePath);
      FileOutputStream out = new FileOutputStream(newFilePath);
      byte bytes[] = new byte[1];
      byte gsnbytes[] = new byte[3];
      byte imeiBytes[] = new byte[15];
      int count;
      while ((count = in.read(bytes)) != -1) {
      out.write(bytes);
      if (bytes[0] == 0x43) {// if is char 'C'
      count = in.read(gsnbytes);
      if (count == -1) {
      break;
      }
      out.write(gsnbytes);
      if (gsnbytes[0] == 0x47 && gsnbytes[1] == 0x53 && gsnbytes[2] == 0x4E) {//if is char 'GSN'
      count = in.read(bytes);//read char '.'
      if (count == -1) {
      break;
      }
      out.write(bytes);
      count = in.read(imeiBytes);//read old imei
      if (count == -1) {
      break;
      }
      byte[] imeis = getIMEIBytes();
      out.write(imeis);//write new imei;
      }
      }

      }
      

      in.close();
      out.close();
      File oldFile = new File(oldFilePath);
      oldFile.delete();
      File newFile = new File(newFilePath);
      newFile.renameTo(oldFile);

      }

      public static byte[] getIMEIBytes() {//随即生成15位imei号
      StringBuffer bff = new StringBuffer();
      byte imeiBytes[] = new byte[15];
      for(int i=0;i<imeiBytes.length;i++){
      int num = (int) Math.round(Math.random()*8);
      bff.append(num);
      imeiBytes[i] = Byte.parseByte("3"+num, 16);
      }
      // printArray(imeiBytes);
      System.err.println("start imei: "+bff.toString());
      return imeiBytes;
      }

      public static void printArray(byte bytes[]) {
      StringBuffer buff = new StringBuffer();
      for (byte b : bytes) {
      buff.append(String.format("%02X", b) + " ");
      }
      System.out.println(buff.toString());
      }

      public static boolean killRunningWindowsProcess(String processName){

      try {

      Runtime.getRuntime().exec("taskkill /IM " + processName);

      System.out.println("kill process successful");

      // System.out.println("Process " + processName + " was killed. Mission completed.");

      return true;

      } catch (Exception ex) {

      ex.printStackTrace();

      System.out.println("kill process fail");

      System.out.println("Misson failed.");

      return false;

      }

      }

      public static boolean findRunningWindowsProcess(String processName) {

      BufferedReader bufferedReader = null;

      Process proc = null;

      try {

      proc = Runtime.getRuntime().exec("tasklist /FI \"IMAGENAME eq " + processName + "\"");

      bufferedReader = new BufferedReader(new InputStreamReader(proc.getInputStream()));

      String line;

      while ((line = bufferedReader.readLine()) != null) {

      if (line.contains(processName)) {

      return true;

      }

      }

      return false;

      } catch (Exception ex) {

      ex.printStackTrace();

      return false;

      } finally {

      if (bufferedReader != null) {

      try {

      bufferedReader.close();

      } catch (Exception ex) {

      }

      }

      if (proc != null) {

      try {

      proc.destroy();

      } catch (Exception ex) {

      }

      }

      }

      }

    }

    评论

报告相同问题?

悬赏问题

  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置