如何使用proguard来混淆带有依赖项的jar文件(how to obfuscate jar file with dependencies by using proguard)
我在Idea IDE中构建了一个与maven有两个依赖关系(fastjson和volley)的jar,现在我想混淆我的jar但没有混淆两个依赖jar,我试过在proguardgui中做这个,我的proguard.pro内容如下:
-injars android_video_tv_sdk_player-1.0.0-SNAPSHOT-shaded.jar -outjars android_video_tv_sdk_player-1.0.0-SNAPSHOT-proguard.jar -libraryjars 'C:\Users\hangl\IDE\sdk\platforms\android-16\android.jar' -libraryjars 'C:\Users\hangl\IDE\sdk\extras\android\support\v4\android-support-v4.jar' -dontoptimize -dontusemixedcaseclassnames -dontpreverify -verbose -dontwarn com.alibaba.**,com.android.volley.** -keep class com.ifeng.exception.InvalidParamsException -keep class com.ifeng.media.** { <fields>; <methods>; } -keep class com.alibaba.** { <fields>; <methods>; } -keep class com.android.volley.** { <fields>; <methods>; } # Keep - Applications. Keep all application classes, along with their 'main' # methods. -keepclasseswithmembers public class * { public static void main(java.lang.String[]); } # Also keep - Enumerations. Keep the special static methods that are required in # enumeration classes. -keepclassmembers enum PlayState { public static **[] values(); public static ** valueOf(java.lang.String); } # Keep names - Native method names. Keep all native class/method names. -keepclasseswithmembers,allowshrinking class * { native <methods>; } # Remove - System method calls. Remove all invocations of System # methods without side effects whose return values are not used. -assumenosideeffects public class java.lang.System { public static long currentTimeMillis(); static java.lang.Class getCallerClass(); public static int identityHashCode(java.lang.Object); public static java.lang.SecurityManager getSecurityManager(); public static java.util.Properties getProperties(); public static java.lang.String getProperty(java.lang.String); public static java.lang.String getenv(java.lang.String); public static java.lang.String mapLibraryName(java.lang.String); public static java.lang.String getProperty(java.lang.String,java.lang.String); }
我的超级jar的主要包是com.ifeng.media,我想在这个包下保持类,并在其他包中混淆其他类,但在我处理混淆了我的jar之后,我发现混淆类中的大多数方法和文件都消失了! 这是一个例子,我定义了类LogUtils.java,这里是代码:
/** * Created by hangl on 2014/9/19. */ public class LogUtils { private static boolean isDebug = true; public static void d(String tag, String msg) { if (isDebug) { Log.d(tag, msg); } } public static void v(String tag, String msg) { if (isDebug) { Log.v(tag, msg); } } public static void i(String tag, String msg) { if (isDebug) { Log.i(tag, msg); } } public static void e(String tag, String msg) { if (isDebug) { Log.e(tag, msg); } } public static void w(String tag, String msg) { if (isDebug) { Log.w(tag, msg); } } }
在混淆之后,它变成了类a.class,现在它的代码变成你现在看到的:
import android.util.Log; public class a { private static boolean a = true; public static void a(String paramString1, String paramString2) { if (a) { Log.d(paramString1, paramString2); } } public static void b(String paramString1, String paramString2) { if (a) { Log.e(paramString1, paramString2); } } }
我不知道为什么,其他类中也存在同样的情况,我的proguard.pro文件有问题吗? 谁能告诉我我需要做什么? 如果你有其他方法来达到目标,比如在maven pom.xml中安装插件来混淆maven mudule(我已经尝试了这个,但我遇到同样的问题),请告诉我你的方式。 谢谢!
I'm build a jar which has two dependencies(fastjson and volley) with maven in Idea IDE, now I want to obfuscate my jar but without obfuscate two dependencies jars, I've tried to do this in proguardgui, my proguard.pro content as follow:
-injars android_video_tv_sdk_player-1.0.0-SNAPSHOT-shaded.jar -outjars android_video_tv_sdk_player-1.0.0-SNAPSHOT-proguard.jar -libraryjars 'C:\Users\hangl\IDE\sdk\platforms\android-16\android.jar' -libraryjars 'C:\Users\hangl\IDE\sdk\extras\android\support\v4\android-support-v4.jar' -dontoptimize -dontusemixedcaseclassnames -dontpreverify -verbose -dontwarn com.alibaba.**,com.android.volley.** -keep class com.ifeng.exception.InvalidParamsException -keep class com.ifeng.media.** { <fields>; <methods>; } -keep class com.alibaba.** { <fields>; <methods>; } -keep class com.android.volley.** { <fields>; <methods>; } # Keep - Applications. Keep all application classes, along with their 'main' # methods. -keepclasseswithmembers public class * { public static void main(java.lang.String[]); } # Also keep - Enumerations. Keep the special static methods that are required in # enumeration classes. -keepclassmembers enum PlayState { public static **[] values(); public static ** valueOf(java.lang.String); } # Keep names - Native method names. Keep all native class/method names. -keepclasseswithmembers,allowshrinking class * { native <methods>; } # Remove - System method calls. Remove all invocations of System # methods without side effects whose return values are not used. -assumenosideeffects public class java.lang.System { public static long currentTimeMillis(); static java.lang.Class getCallerClass(); public static int identityHashCode(java.lang.Object); public static java.lang.SecurityManager getSecurityManager(); public static java.util.Properties getProperties(); public static java.lang.String getProperty(java.lang.String); public static java.lang.String getenv(java.lang.String); public static java.lang.String mapLibraryName(java.lang.String); public static java.lang.String getProperty(java.lang.String,java.lang.String); }
my uber jar's main package is com.ifeng.media, I want keep class under this package and obfuscate other classes in other packages, but after I process obfuscate my jar, I found most methods and fileds in obfuscated class just gone! Here's an example, I define class LogUtils.java, here's the code:
/** * Created by hangl on 2014/9/19. */ public class LogUtils { private static boolean isDebug = true; public static void d(String tag, String msg) { if (isDebug) { Log.d(tag, msg); } } public static void v(String tag, String msg) { if (isDebug) { Log.v(tag, msg); } } public static void i(String tag, String msg) { if (isDebug) { Log.i(tag, msg); } } public static void e(String tag, String msg) { if (isDebug) { Log.e(tag, msg); } } public static void w(String tag, String msg) { if (isDebug) { Log.w(tag, msg); } } }
after obfuscate,it became class a.class, now its code became what you see now:
import android.util.Log; public class a { private static boolean a = true; public static void a(String paramString1, String paramString2) { if (a) { Log.d(paramString1, paramString2); } } public static void b(String paramString1, String paramString2) { if (a) { Log.e(paramString1, paramString2); } } }
I don't know why,same situation exist in other classes, Is there something wrong with my proguard.pro file? can anyone tell me what I need to do? If you have other method to reach the goal, like install plugins in maven pom.xml to obfuscate maven mudule(I've already tried this but I face same problem), please show me your way. Thanks!
原文:https://stackoverflow.com/questions/25995733
最满意答案
试图解决同样的问题时偶然发现了这个问题。
安德鲁从2010年开始的答案是正确的,但自那时起,新的Internet Explorers(10和11)不会在注册表值“版本”中显示其真实版本号。 相反,它记录在注册表值中:'svcVersion'。
Stumbled across this while trying to solve the same problem.
Andrew's answer from 2010 is correct, but since then, newer Internet Explorers (10 and 11) do not show their true version number in the registry value: 'Version'. Instead, it is recorded in the registry value: 'svcVersion'.
相关问答
更多-
您需要检查此密钥以获取计算机上已安装实例的列表: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL 这将列出所有可用的实例。 这些也是注册表项的名称,因此如果您找到SQLEXPRESS的键,它将具有字符串值 - 在我的情况下,它是MSSQL12.SQLEXPRESS 。 使用该值,再次在注册表中查找: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQ ...
-
如何从Windows注册表获取IE版本号?(How to get the IE version number from the Windows registry? [duplicate])[2023-01-02]
试图解决同样的问题时偶然发现了这个问题。 安德鲁从2010年开始的答案是正确的,但自那时起,新的Internet Explorers(10和11)不会在注册表值“版本”中显示其真实版本号。 相反,它记录在注册表值中:'svcVersion'。 Stumbled across this while trying to solve the same problem. Andrew's answer from 2010 is correct, but since then, newer Internet Expl ... -
主要使用两个标准应用程序来处理批处理文件中的Windows注册表: REG.EXE REGEDIT.EXE 在Windows x64上,它们都存在为32位和64位应用程序,其中32位版本访问注册表,如32位应用程序,这意味着注册表重定向器处于活动状态,64位应用程序的注册表项对于32位不可见REG和REGEDIT 。 通常最好使用REG而不是REGEDIT来获取(读访问)或设置(写访问)批处理文件中的几个键或值。 自Windows Vista起, REGEDIT的使用始终需要管理员权限,即使只是用于将密钥导 ...
-
Environment.OSVersion像其他人所说的是正确的路要走。 但是,如果有人想通过注册表获得它,可以使用 - using (Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine .OpenSubKey(@"SOFTWARE\Microsoft\WindowsNT\CurrentVersion")) { var osVersion = key.GetVal ...
-
根据你的描述,我认为你真正需要的是ApiInformation类 。 通过此类,您可以检测是否存在指定的成员,类型或API合同,以便您可以安全地在各种设备上进行API调用。 因此,我们不需要获取当前的操作系统版本,以查看设备是否支持某些内容。 这里的关键点是检测功能,而不是操作系统或设备 。 自适应应用程序背后的基本思想是您的应用程序检查它所需的功能(或功能),并且仅在可用时使用它。 执行此操作的传统方法是检查操作系统版本,然后使用这些API。 使用Windows 10,您的应用程序可以在运行时检查当前操作 ...
-
可能是你的谷歌浏览器的安装有点搞砸了。 我有这个注册表项,它包含两个值与当前版本号。 另一种方法虽然不通过注册表,但检查用户/ [用户名] / AppData /本地/谷歌/ Chrome /应用程序中的文件夹。 我有一个最新版本号的文件夹。 (以及旧版本的文件夹)。 我在注册表中找到了一些可能也适用于每个客户端的东西:HKEY_CLASSES_ROOT \ Wow6432Node \ CLSID {5C65F4B0-3651-4514-B207-D10CB699B14B} \ LocalServer32其 ...
-
您看到的问题是因为要在InnoSetup的主要部分中调用函数作为参数,您需要使用{code:}构造。 这是一个对我有用的例子: [Registry] Root: HKCU; Subkey: "Software\MyCompany\Product"; ValueType: DWORD ; ValueName: "Version" ; ValueData: {code:GetVersion|{#MyAppVersion}}; Flags: uninsdeletekey; The problem you ...
-
在安装期间,Windows Installer版本存储在VersionMsi属性中。 请注意,版本3.1存储为3.01,4.5存储为4.05。 如果要确定计算机上的Windows Installer版本,只需检查C:\Windows\system32文件夹中的msi.dll文件。 During install, the Windows Installer version is stored in VersionMsi property. Please note that version 3.1 is sto ...
-
使用这些程序的一组程序是R批处理文件 这些程序通过(1)检查环境变量(R_HOME,R_MIKTEX,R_TOOLS)或(2)(如果未设置它们在注册表中查找)来设置R(以及R Tools和miktex的版本)的版本。 Major edit: It looks like those registry entries are primarily there for use by external applications. Here's why I think that. grep'ing HKEY_LOCAL ...
-
NSIS:无法从Windows 7 64位注册表中获取JRE版本(NSIS: Unable to get JRE version from registry in Windows 7 64 bit)[2023-04-17]
在NSIS中,您可以使用SetRegView设置注册表“模式” In NSIS, you can set the registry "mode" with SetRegView