private ArrayList DeObfuscateSingleFile(int index, RenameDatabase RenameStore) { TClassFile ClassFile = (TClassFile)FClassFiles[index]; if (ClassFile == null) return null; // add the class name to the head of the changelist FChangeList = new ArrayList(); FChangeList.Add(ClassFile.ThisClassName); string OriginalClassName = ClassFile.ThisClassName; string OriginalClassAndType = ClassFile.ThisClassName + " : " + ClassFile.SuperClassName; // rename the class and add the new class name to the changelist at [1] if (FRenameClasses && RenameStore.GetNewClassNameOnly(OriginalClassAndType) != null) { // check if we need to use a user-supplied class name first string NewClassName = RenameStore.GetNewClassNameOnly(OriginalClassAndType); while (ClassNameExists(NewClassName)) { NewClassName += "_"; } FChangeList.Add(ClassFile.ChangeClassName(NewClassName)); } else if (FRenameClasses && DoRename(OriginalClassName)) { string NewClassName; NewClassName = ClassFile.FileName; // test if the filename we are changing to hasnt already been used! while (ClassNameExists(NewClassName)) { NewClassName += "_"; } FChangeList.Add(ClassFile.ChangeClassName(NewClassName)); } else FChangeList.Add(OriginalClassName); // process the Methods for (int i = 0; i < ClassFile.Methods.Items.Count; i++) { MethodInfo mi = (MethodInfo)ClassFile.Methods.Items[i]; RenameData rd = RenameStore.GetNewMethodInfo(OriginalClassAndType, mi.Descriptor, mi.Name.Value); // this is the rule for renaming if (DoRename(mi.Name.Value) || rd != null) { // clone the original method TMethodChangeRecord mcr = new TMethodChangeRecord(mi); // rename all of the functions something meaningful string NewName; // user supplied names take precedence if (rd != null) { NewName = rd.FieldName; } else { NewName = mi.Name.Value; } // change the method name ClassFile.ChangeMethodName(i, NewName); // set the mcr.ChangedTo(mi); FChangeList.Add(mcr); } // fix the descriptor regardless ClassFile.ChangeMethodParam(i, OriginalClassName, ClassFile.ThisClassName); } // process the Fields for (int i = 0; i < ClassFile.Fields.Items.Count; i++) { FieldInfo fi = (FieldInfo)ClassFile.Fields.Items[i]; RenameData rd = RenameStore.GetNewFieldInfo(OriginalClassAndType, fi.Descriptor, fi.Name.Value); if (DoRename(fi.Name.Value) || rd != null) { // clone the original method TFieldChangeRecord fcr = new TFieldChangeRecord(fi); // rename all of the fields something meaningful string NewName; /*if (FThoroughMode) { int j = 0; while (ClassFile.Methods.FieldNameExists(NewName)) { // rename the field NewName = NewName + "_" + j; j++; } }*/ if (rd != null) { NewName = rd.FieldName; } else { NewName = fi.Name.Value; } ClassFile.ChangeFieldName(i, NewName); fcr.ChangedTo(fi); FChangeList.Add(fcr); } // fix the descriptor regardless ClassFile.ChangeFieldType(i, OriginalClassName, ClassFile.ThisClassName); } return FChangeList; }
private ArrayList DeObfuscateSingleFile(int index, RenameDatabase RenameStore) { TClassFile ClassFile = (TClassFile)FClassFiles[index]; if (ClassFile == null) return null; // add the class name to the head of the changelist FChangeList = new ArrayList(); FChangeList.Add(ClassFile.ThisClassName); string OriginalClassName = ClassFile.ThisClassName; string OriginalClassAndType = ClassFile.ThisClassName + " : " + ClassFile.SuperClassName; // rename the class and add the new class name to the changelist at [1] if (FRenameClasses && RenameStore.GetNewClassNameOnly(OriginalClassAndType) != null) { // check if we need to use a user-supplied class name first string NewClassName = RenameStore.GetNewClassNameOnly(OriginalClassAndType); while (ClassNameExists(NewClassName)) { NewClassName += "_"; } FChangeList.Add(ClassFile.ChangeClassName(NewClassName)); } else if (FRenameClasses && DoRename(OriginalClassName)) { string NewClassName; if (UseUniqueNums) { string format = "{0:D" + (FClassFiles.Count.ToString().Length + 2) + "}"; string uniqueNum = string.Format(format, Convert.ToInt64(ClassFile.ThisClassCode.ToString() + index.ToString())); NewClassName = String.Format("Class_{0}_{1}", Common.GetClassName(OriginalClassName), uniqueNum); } else NewClassName = String.Format("Class_{0}", Common.GetClassName(OriginalClassName)); // test if the filename we are changing to hasnt already been used! while (ClassNameExists(NewClassName)) { NewClassName += "_"; } FChangeList.Add(ClassFile.ChangeClassName(NewClassName)); } else FChangeList.Add(OriginalClassName); // process the Methods for (int i = 0; i < ClassFile.Methods.Items.Count; i++) { MethodInfo mi = (MethodInfo)ClassFile.Methods.Items[i]; RenameData rd = RenameStore.GetNewMethodInfo(OriginalClassAndType, mi.Descriptor, mi.Name.Value); // this is the rule for renaming if (DoRename(mi.Name.Value) || rd != null) { // clone the original method TMethodChangeRecord mcr = new TMethodChangeRecord(mi); // rename all of the functions something meaningful string NewName; // if the offset is zero, it probably means its an abstract method if (ClassFile.AccessFlags == AccessFlags.ACC_INTERFACE) NewName = String.Format("sub_iface_{0:x}", i); else if (mi.Offset != 0) NewName = String.Format("sub_{0:x}", mi.Offset); else NewName = String.Format("sub_null_{0:x}", i); /*if (FThoroughMode) { int j = 0; while (ClassFile.Methods.MethodNameExists(NewName)) { // rename the method NewName = NewName + "_" + j; j++; } }*/ // user supplied names take precedence if (rd != null) { NewName = rd.FieldName; } // change the method name ClassFile.ChangeMethodName(i, NewName); // set the mcr.ChangedTo(mi); FChangeList.Add(mcr); } // fix the descriptor regardless ClassFile.ChangeMethodParam(i, OriginalClassName, ClassFile.ThisClassName); } // process the Fields for (int i = 0; i < ClassFile.Fields.Items.Count; i++) { FieldInfo fi = (FieldInfo)ClassFile.Fields.Items[i]; RenameData rd = RenameStore.GetNewFieldInfo(OriginalClassAndType, fi.Descriptor, fi.Name.Value); if (DoRename(fi.Name.Value) || rd != null) { // clone the original method TFieldChangeRecord fcr = new TFieldChangeRecord(fi); // rename all of the fields something meaningful string NewName; // if the offset is zero, it probably means its a null/abstract method if (fi.Offset != 0) NewName = String.Format("var_{0:x}", fi.Offset); else NewName = String.Format("var_null_{0:x}", fi.Offset); /*if (FThoroughMode) { int j = 0; while (ClassFile.Methods.FieldNameExists(NewName)) { // rename the field NewName = NewName + "_" + j; j++; } }*/ if (rd != null) { NewName = rd.FieldName; } ClassFile.ChangeFieldName(i, NewName); fcr.ChangedTo(fi); FChangeList.Add(fcr); } // fix the descriptor regardless ClassFile.ChangeFieldType(i, OriginalClassName, ClassFile.ThisClassName); } return FChangeList; }