怪异的行为而混淆使用ProGuard一个JAR [英] Weird behaviour while obfuscating a JAR with proguard

查看:519
本文介绍了怪异的行为而混淆使用ProGuard一个JAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图混淆使用Proguard的一个Android JAR(4.7,但4.6有问题也是如此)。我可以分解问题转化为一个简单的示例项目。

I'm trying to obfuscate an Android JAR using Proguard (4.7, but 4.6 problematic too). I could break down the problem into a simple sample project.

问题:对于部分的功能(目前还不清楚是什么原因)的公开的函数的参数名都将丢失,有时是炒(真的)。我想着重就丢失部分首先,因为炒的是更奇怪...

The problem: For some functions (unclear for what reasons) the argument names of exposed functions are lost, sometimes "scrambled" (really). I would like to focus on the "lost" part first, because the scrambled thing is much more weird...

1)我创建Eclipse的一个库项目。 Android的SDK是2.1更新1因为某些原因 该项目被标记为图书馆计划,并只有一个类MyJarEntry.java和一个输出函数foo

1) I created a library project in Eclipse. Android SDK is 2.1-update 1 for some reasons The project is marked as "Library Project" and has just one class MyJarEntry.java and one exported function foo

package com.decades.myjar;

import android.location.LocationListener;

public class MyJarEntry {

    public void foo(String provider, long minTime, float minDistance, LocationListener listener) {
    }
}

2)我的项目有一个子目录ProGuard的包含最新proguard.jar加上proguard.cfg,它看起来像这样

2) My project has a subdir "proguard" containing the latest proguard.jar plus the proguard.cfg, which looks like this

-printmapping out.map

-keepparameternames
-renamesourcefileattribute SourceFile
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
            SourceFile,LineNumberTable,*Annotation*,EnclosingMethod

-keep public class * {
    public protected *;
}

3)我在build.xml有目标,构建JAR和优化像这样,所以建筑的lib在Eclipse后,我做的蚁族罐子和优化的一个终端。这是的build.xml

3) My Build.xml has targets for building the JAR and optimizing it like this, so after building the lib in Eclipse I do "ant jar" and "and optimize" in a terminal. This is build.xml

<project name="MyJar" default="jar" basedir=".">
<description>
  Lib JAR builder
</description>

<!-- set global properties for this build -->
<property name="res" location="res" />
<property name="bin" location="bin" />

<!-- Output directories -->
<property name="out.dir" value="bin" />
<property name="out.absolute.dir" location="${out.dir}" />
<property name="out.classes.dir" value="${out.absolute.dir}/com" />
<property name="out.classes.absolute.dir" location="${out.classes.dir}" />


<!-- Pack the jar -->
<target name="jar">
    <jar destfile="MyJar.jar" basedir="bin/">
        <!-- replace 'com' by what ever you are using -->
        <!-- as first part of the package name -->
        <!-- e.g. de, org, ... -->
        <!-- the ** is important to include the directory recursively -->
        <include name="com/**" />
    </jar>
</target>

<!-- Obfuscation with ProGuard -->

<property name="version" value="0.0.1"/>            <!-- change this occasionally -->

<property name="proguard-dir" value="proguard"/>
<property name="unoptimized" value="MyJar.jar"/>
<property name="optimized" value="MyJar_${version}.jar"/>


<target name="optimize" unless="nooptimize">

    <!-- Run obfuscator -->
    <java jar="${proguard-dir}/proguard.jar" fork="true" failonerror="true">
        <jvmarg value="-Dmaximum.inlined.code.length=16"/>
        <arg value="@${proguard-dir}/proguard.cfg"/>      
        <arg value="-injars ${unoptimized}"/>
        <arg value="-outjars ${optimized}"/>
        <arg value="-libraryjars /Users/decades/android-sdk-mac_x86/platforms/android-7/android.jar"/>
    </java>     
</target>   

建立和模糊处理是好的,但在导入产生MyJar_0.0.1.jar到测试项目后,code完成后不显示正确的参数名称,而不是foo是psented为

Build and obfuscation is fine, but after importing the resulting MyJar_0.0.1.jar into a test project the code completion does not show up the right parameter names, instead foo is presented as

FOO(字符串为arg0,长ARG1,浮ARG2,LocationListener的ARG3)

foo(String arg0, long arg1, float arg2, LocationListener arg3)

虽然keepparameternames中指定。

although "keepparameternames" is specified.

我已经花了几个小时,不能使它发挥作用。一切都很好,如果我导入是非模糊的JAR。包中的其他一些功能也确实有其正确的参数名称显示出来......

I have spent hours and hours and couldn't make it work. All is fine if I import the unobfuscated JAR. Some other functions in the package do also show up with their correct parameter names...

由于没有线索,你呢?

问候

推荐答案

ProGuard的4.7(及以上)出现删除未使用的参数的名称。我现在已经解决了这个问题在今后的版本。你可以解决它通过关闭优化(-dontoptimize)。

ProGuard 4.7 (and older) appears to remove the names of unused parameters. I've now fixed this for future releases. You can work around it by switching off optimization (-dontoptimize).

请注意,您可以随时报告的ProGuard的bug追踪系统

Note that you can always report bugs on ProGuard's bug tracker.

这篇关于怪异的行为而混淆使用ProGuard一个JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆