Home | History | Annotate | Download | only in dexter
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #pragma once
     18 
     19 #include "dissasembler.h"
     20 #include "slicer/dex_ir.h"
     21 
     22 #include <stdlib.h>
     23 #include <memory>
     24 #include <vector>
     25 
     26 // Encapsulates the state (command line switches, stats, ...) and
     27 // the interface of the command line .dex manipulation tool.
     28 class Dexter {
     29   static constexpr const char* VERSION = "v1.1";
     30 
     31  public:
     32   Dexter(int argc, char* argv[]) : argc_(argc), argv_(argv) {}
     33 
     34   Dexter(const Dexter&) = delete;
     35   Dexter& operator=(const Dexter&) = delete;
     36 
     37   // main entry point, returns an appropriate proces exit code
     38   int Run();
     39 
     40  private:
     41   int ProcessDex();
     42   void PrintHelp();
     43   bool CreateNewImage(std::shared_ptr<ir::DexFile> dex_ir);
     44 
     45  private:
     46   // command line
     47   int argc_ = 0;
     48   char** argv_ = nullptr;
     49 
     50   // parsed options
     51   const char* extract_class_ = nullptr;
     52   bool stats_ = false;
     53   bool verbose_ = false;
     54   bool list_classes_ = false;
     55   const char* out_dex_filename_ = nullptr;
     56   const char* dex_filename_ = nullptr;
     57   bool dissasemble_ = false;
     58   bool print_map_ = false;
     59   std::vector<const char*> experiments_;
     60   DexDissasembler::CfgType cfg_type_ = DexDissasembler::CfgType::None;
     61 
     62   // basic timing stats
     63   double reader_time_ = 0;
     64   double writer_time_ = 0;
     65   double experiments_time_ = 0;
     66 };
     67