Question

This is my first time experience of decompiling an apk to java code. The following code is of a local TVApp launcher which is ofcourse android based. To my surprise, I found out that the decompilers do not do a complete conversion to the source code. Hence, it messes up a thing or two. I have tried to work around with what I had, and made functions out of labels. Although I got it to work, but I suppose I missed out on some things..

Can someone guide me how to get this to work correctly? Do I have to do a manual refactoring of the code or is there a tool available for this?

public void run()
    {
      EN_INPUT_SOURCE_TYPE localEN_INPUT_SOURCE_TYPE;
      int i;
      ITvServiceServer localITvServiceServer;
      for (;;)
      {
        if (LauncherActivity.this.bExitThread.booleanValue()) {
          return;
        }
        synchronized (LauncherActivity.this.bSync)
        {
          localEN_INPUT_SOURCE_TYPE = LauncherActivity.this.toChangeInputSource;
          LauncherActivity.this.toChangeInputSource = EN_INPUT_SOURCE_TYPE.E_INPUT_SOURCE_NONE;
          i = LauncherActivity.this.fullScale;
          LauncherActivity.this.fullScale = 0;
          if (localEN_INPUT_SOURCE_TYPE != EN_INPUT_SOURCE_TYPE.E_INPUT_SOURCE_NONE)
          {
            localITvServiceServer = ITvServiceServer.Stub.asInterface(ServiceManager.checkService("tv_services"));
            if (localITvServiceServer == null) {
              Log.w("LauncherActivity", "Unable to find ITvService interface.");
            }
          }
          else
          {
            if (i != 2) {
              break label345;
            }
            LauncherActivity.this.setPipscale();
            try
            {
              label104:
              Thread.sleep(100L);
            }
            catch (InterruptedException localInterruptedException)
            {
              localInterruptedException.printStackTrace();
            }
          }
        }
      }
      for (;;)
      {
        for (;;)
        {
          ITvServiceServerCommon localITvServiceServerCommon;
          try
          {
            localITvServiceServerCommon = localITvServiceServer.getCommonManager();
            if (localEN_INPUT_SOURCE_TYPE != EN_INPUT_SOURCE_TYPE.E_INPUT_SOURCE_ATV) {
              break label324;
            }
            if (!localITvServiceServerCommon.GetCurrentInputSource().equals(EN_INPUT_SOURCE_TYPE.E_INPUT_SOURCE_STORAGE)) {
              break;
            }
            if (LauncherActivity.this.minidatabase != null) {
              break label275;
            }
            j = 0;
            if ((j < 0) || (j > EN_INPUT_SOURCE_TYPE.E_INPUT_SOURCE_NONE.ordinal())) {
              break;
            }
            localITvServiceServerCommon.SetInputSource(EN_INPUT_SOURCE_TYPE.values()[j]);
            if (EN_INPUT_SOURCE_TYPE.values()[j] != EN_INPUT_SOURCE_TYPE.E_INPUT_SOURCE_ATV) {
              break label290;
            }
            k = localITvServiceServer.getChannelManager().getCurrentChannelNumber();
            if ((k < 0) || (k > 255)) {
              break label361;
            }
            localITvServiceServer.getChannelManager().programSel(k, EN_MEMBER_SERVICE_TYPE.E_SERVICETYPE_ATV);
          }
          catch (RemoteException localRemoteException1)
          {
            localRemoteException1.printStackTrace();
          }
          break;
          label275:
          int j = LauncherActivity.this.minidatabase.queryCurInputSrc();
          continue;
          label290:
          if (EN_INPUT_SOURCE_TYPE.values()[j] != EN_INPUT_SOURCE_TYPE.E_INPUT_SOURCE_DTV) {
            break;
          }
          localITvServiceServer.getChannelManager().changeToFirstService(EN_FIRST_SERVICE_INPUT_TYPE.E_FIRST_SERVICE_DTV, EN_FIRST_SERVICE_TYPE.E_DEFAULT);
          break;
          try
          {
            label324:
            localITvServiceServerCommon.SetInputSource(localEN_INPUT_SOURCE_TYPE);
          }
          catch (RemoteException localRemoteException2)
          {
            localRemoteException2.printStackTrace();
          }
        }
        break;
        label345:
        if (i != 1) {
          break label104;
        }
        LauncherActivity.this.setFullscale();
        break label104;
        label361:
        int k = 0;
      }
    }
Was it helpful?

Solution

Do I have to do a manual refactoring of the code? YES.
The only thing you can do (in Eclipse) is pressing ALT+R on a selected label and change all its occurrences.

OTHER TIPS

Decompiling is not 100% complete/accurate, due to how the process works, I suggest you read: http://en.wikipedia.org/wiki/Decompiler to understand more on the process.

It is fairly accurate though on some virtual machines like Java, as its bytecode includes extensive metadata. That's why you got a 'nice' result.

You will have to do a lot of manual refactoring anyway.

And bear in mind the legality of what you are doing, check licenses and copyright.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top