Source Code Cross Referenced for MappingKeeper.java in  » Development » proguard » proguard » obfuscate » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Development » proguard » proguard.obfuscate 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ProGuard -- shrinking, optimization, obfuscation, and preverification
003:         *             of Java bytecode.
004:         *
005:         * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
006:         *
007:         * This program is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU General Public License as published by the Free
009:         * Software Foundation; either version 2 of the License, or (at your option)
010:         * any later version.
011:         *
012:         * This program is distributed in the hope that it will be useful, but WITHOUT
013:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014:         * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
015:         * more details.
016:         *
017:         * You should have received a copy of the GNU General Public License along
018:         * with this program; if not, write to the Free Software Foundation, Inc.,
019:         * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020:         */
021:        package proguard.obfuscate;
022:
023:        import proguard.classfile.*;
024:        import proguard.classfile.util.*;
025:
026:        /**
027:         * This MappingKeeper applies the mappings that it receives to its class pool,
028:         * so these mappings are ensured in a subsequent obfuscation step.
029:         *
030:         * @author Eric Lafortune
031:         */
032:        public class MappingKeeper implements  MappingProcessor {
033:            private final ClassPool classPool;
034:            private final WarningPrinter warningPrinter;
035:
036:            // A field acting as a parameter.
037:            private Clazz clazz;
038:
039:            /**
040:             * Creates a new MappingKeeper.
041:             * @param classPool      the class pool in which class names and class
042:             *                       member names have to be mapped.
043:             * @param warningPrinter the optional warning printer to which warnings
044:             *                       can be printed.
045:             */
046:            public MappingKeeper(ClassPool classPool,
047:                    WarningPrinter warningPrinter) {
048:                this .classPool = classPool;
049:                this .warningPrinter = warningPrinter;
050:            }
051:
052:            // Implementations for MappingProcessor.
053:
054:            public boolean processClassMapping(String className,
055:                    String newClassName) {
056:                // Find the class.
057:                String name = ClassUtil.internalClassName(className);
058:
059:                clazz = classPool.getClass(name);
060:                if (clazz != null) {
061:                    String newName = ClassUtil.internalClassName(newClassName);
062:
063:                    // Print out a warning if the mapping conflicts with a name that
064:                    // was set before.
065:                    if (warningPrinter != null) {
066:                        String currentNewName = ClassObfuscator
067:                                .newClassName(clazz);
068:                        if (currentNewName != null
069:                                && !currentNewName.equals(newName)) {
070:                            warningPrinter.print("Warning: "
071:                                    + className
072:                                    + " is not being kept as '"
073:                                    + ClassUtil
074:                                            .externalClassName(currentNewName)
075:                                    + "', but remapped to '" + newClassName
076:                                    + "'");
077:                        }
078:                    }
079:
080:                    ClassObfuscator.setNewClassName(clazz, newName);
081:
082:                    // The class members have to be kept as well.
083:                    return true;
084:                }
085:
086:                return false;
087:            }
088:
089:            public void processFieldMapping(String className, String fieldType,
090:                    String fieldName, String newFieldName) {
091:                if (clazz != null) {
092:                    // Find the field.
093:                    String name = fieldName;
094:                    String descriptor = ClassUtil.internalType(fieldType);
095:
096:                    Field field = clazz.findField(name, descriptor);
097:                    if (field != null) {
098:                        // Print out a warning if the mapping conflicts with a name that
099:                        // was set before.
100:                        if (warningPrinter != null) {
101:                            String currentNewName = MemberObfuscator
102:                                    .newMemberName(field);
103:                            if (currentNewName != null
104:                                    && !currentNewName.equals(newFieldName)) {
105:                                warningPrinter.print("Warning: " + className
106:                                        + ": field '" + fieldType + " "
107:                                        + fieldName
108:                                        + "' is not being kept as '"
109:                                        + currentNewName
110:                                        + "', but remapped to '" + newFieldName
111:                                        + "'");
112:                            }
113:                        }
114:
115:                        // Make sure the mapping name will be kept.
116:                        MemberObfuscator.setFixedNewMemberName(field,
117:                                newFieldName);
118:                    }
119:                }
120:            }
121:
122:            public void processMethodMapping(String className,
123:                    int firstLineNumber, int lastLineNumber,
124:                    String methodReturnType, String methodNameAndArguments,
125:                    String newMethodName) {
126:                if (clazz != null) {
127:                    // Find the method.
128:                    String name = ClassUtil
129:                            .externalMethodName(methodNameAndArguments);
130:                    String descriptor = ClassUtil.internalMethodDescriptor(
131:                            methodReturnType, methodNameAndArguments);
132:
133:                    Method method = clazz.findMethod(name, descriptor);
134:                    if (method != null) {
135:                        // Print out a warning if the mapping conflicts with a name that
136:                        // was set before.
137:                        if (warningPrinter != null) {
138:                            String currentNewName = MemberObfuscator
139:                                    .newMemberName(method);
140:                            if (currentNewName != null
141:                                    && !currentNewName.equals(newMethodName)) {
142:                                warningPrinter.print("Warning: " + className
143:                                        + ": method '" + methodReturnType + " "
144:                                        + methodNameAndArguments
145:                                        + "' is not being kept as '"
146:                                        + currentNewName
147:                                        + "', but remapped to '"
148:                                        + newMethodName + "'");
149:                            }
150:                        }
151:
152:                        // Make sure the mapping name will be kept.
153:                        MemberObfuscator.setFixedNewMemberName(method,
154:                                newMethodName);
155:                    }
156:                }
157:            }
158:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.