2019-04-17 06:45:15 +00:00
|
|
|
package the.bytecode.club.bytecodeviewer.util;
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
|
|
|
|
* Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
import org.apache.commons.io.FilenameUtils;
|
2019-11-20 13:17:36 +00:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2019-04-17 06:45:15 +00:00
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Konloch
|
|
|
|
*/
|
|
|
|
public class LazyNameUtil
|
|
|
|
{
|
|
|
|
public static boolean SAME_NAME_JAR_WORKSPACE = false;
|
|
|
|
|
2019-11-20 13:17:36 +00:00
|
|
|
private static final HashMap<String, SeqAndCount> nameMap = new HashMap<>();
|
2019-04-17 06:45:15 +00:00
|
|
|
|
|
|
|
public static void reset()
|
|
|
|
{
|
|
|
|
nameMap.clear();
|
|
|
|
}
|
|
|
|
|
2019-11-20 13:17:36 +00:00
|
|
|
public static String applyNameChanges(String name) {
|
|
|
|
if (nameMap.containsKey(name)) {
|
|
|
|
if (!SAME_NAME_JAR_WORKSPACE) {
|
2019-04-17 06:45:15 +00:00
|
|
|
SAME_NAME_JAR_WORKSPACE = true;
|
2019-11-20 13:17:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SeqAndCount seqAndCount = nameMap.get(name);
|
|
|
|
nameMap.put(name, seqAndCount.incrSeqAndCount());
|
|
|
|
return FilenameUtils.removeExtension(name) + "#" + seqAndCount.getSeq() + "." + FilenameUtils.getExtension(name);
|
|
|
|
} else {
|
|
|
|
nameMap.put(name, SeqAndCount.init());
|
|
|
|
}
|
2019-04-17 06:45:15 +00:00
|
|
|
|
2019-11-20 13:17:36 +00:00
|
|
|
return name;
|
|
|
|
}
|
2019-04-17 06:45:15 +00:00
|
|
|
|
2019-11-20 13:17:36 +00:00
|
|
|
public static void removeName(String name) {
|
|
|
|
if (StringUtils.isBlank(name)) {
|
|
|
|
return;
|
2019-04-17 06:45:15 +00:00
|
|
|
}
|
2019-11-20 13:17:36 +00:00
|
|
|
|
|
|
|
if (name.contains("#")) {
|
|
|
|
name = name.substring(0, name.indexOf("#")) + name.substring(name.indexOf("."));
|
2019-04-17 06:45:15 +00:00
|
|
|
}
|
|
|
|
|
2019-11-20 13:17:36 +00:00
|
|
|
SeqAndCount seqAndCount = nameMap.get(name);
|
|
|
|
if (seqAndCount == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// sequence remain the same and decrease the count
|
|
|
|
// still the count become 1
|
|
|
|
if (seqAndCount.getCount() == 1) {
|
|
|
|
nameMap.remove(name);
|
|
|
|
} else {
|
|
|
|
nameMap.put(name, seqAndCount.decrCount());
|
|
|
|
}
|
2019-04-17 06:45:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-11-20 13:17:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SeqAndCount {
|
|
|
|
Integer seq;
|
|
|
|
Integer count;
|
|
|
|
|
|
|
|
public static SeqAndCount init() {
|
|
|
|
SeqAndCount seqAndCount = new SeqAndCount();
|
|
|
|
seqAndCount.setSeq(1);
|
|
|
|
seqAndCount.setCount(1);
|
|
|
|
return seqAndCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
public SeqAndCount incrSeq() {
|
|
|
|
seq = seq + 1;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public SeqAndCount incrCount() {
|
|
|
|
count = count + 1;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public SeqAndCount decrCount() {
|
|
|
|
count = count - 1;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public SeqAndCount incrSeqAndCount() {
|
|
|
|
seq = seq + 1;
|
|
|
|
count = count + 1;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Integer getSeq() {
|
|
|
|
return seq;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSeq(Integer seq) {
|
|
|
|
this.seq = seq;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Integer getCount() {
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCount(Integer count) {
|
|
|
|
this.count = count;
|
|
|
|
}
|
|
|
|
}
|