| 1 |
/* |
| 2 |
* Copyright (C) 2010 Ryszard Wiśniewski <[email protected]> |
| 3 |
* Copyright (C) 2010 Connor Tumbleson <[email protected]> |
| 4 |
* |
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
* you may not use this file except in compliance with the License. |
| 7 |
* You may obtain a copy of the License at |
| 8 |
* |
| 9 |
* https://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
* |
| 11 |
* Unless required by applicable law or agreed to in writing, software |
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
* See the License for the specific language governing permissions and |
| 15 |
* limitations under the License. |
| 16 |
*/ |
| 17 |
package brut.androlib; |
| 18 |
|
| 19 |
import java.io.IOException; |
| 20 |
import java.io.InputStream; |
| 21 |
import java.util.Properties; |
| 22 |
import java.util.logging.Logger; |
| 23 |
|
| 24 |
public class ApktoolProperties { |
| 25 |
public static String get(String key) { |
| 26 |
return get().getProperty(key); |
| 27 |
} |
| 28 |
|
| 29 |
public static Properties get() { |
| 30 |
if (sProps == null) { |
| 31 |
loadProps(); |
| 32 |
} |
| 33 |
return sProps; |
| 34 |
} |
| 35 |
|
| 36 |
private static void loadProps() { |
| 37 |
InputStream in = ApktoolProperties.class.getResourceAsStream("/properties/apktool.properties"); |
| 38 |
sProps = new Properties(); |
| 39 |
try { |
| 40 |
sProps.load(in); |
| 41 |
in.close(); |
| 42 |
} catch (IOException ex) { |
| 43 |
LOGGER.warning("Can't load properties."); |
| 44 |
} |
| 45 |
|
| 46 |
InputStream templateStream = null; |
| 47 |
try { |
| 48 |
templateStream = org.jf.baksmali.Main.class.getClassLoader().getResourceAsStream("baksmali.properties"); |
| 49 |
} catch(NoClassDefFoundError ex) { |
| 50 |
LOGGER.warning("Can't load baksmali properties."); |
| 51 |
} |
| 52 |
Properties properties = new Properties(); |
| 53 |
String version = "(unknown)"; |
| 54 |
|
| 55 |
if (templateStream != null) { |
| 56 |
try { |
| 57 |
properties.load(templateStream); |
| 58 |
version = properties.getProperty("application.version"); |
| 59 |
templateStream.close(); |
| 60 |
} catch (IOException ignored) { } |
| 61 |
} |
| 62 |
sProps.put("baksmaliVersion", version); |
| 63 |
|
| 64 |
templateStream = null; |
| 65 |
try { |
| 66 |
templateStream = org.jf.smali.Main.class.getClassLoader().getResourceAsStream("smali.properties"); |
| 67 |
} catch(NoClassDefFoundError ex) { |
| 68 |
LOGGER.warning("Can't load smali properties."); |
| 69 |
} |
| 70 |
properties = new Properties(); |
| 71 |
version = "(unknown)"; |
| 72 |
|
| 73 |
if (templateStream != null) { |
| 74 |
try { |
| 75 |
properties.load(templateStream); |
| 76 |
version = properties.getProperty("application.version"); |
| 77 |
templateStream.close(); |
| 78 |
} catch (IOException ignored) { } |
| 79 |
} |
| 80 |
sProps.put("smaliVersion", version); |
| 81 |
} |
| 82 |
|
| 83 |
private static Properties sProps; |
| 84 |
|
| 85 |
private static final Logger LOGGER = Logger.getLogger(ApktoolProperties.class.getName()); |
| 86 |
} |