public JumpInstruction(Instruction insJump) { Instruction = insJump; Targets = new List <Instruction>(); if (insJump.Operand is Instruction) { Instruction insTarget = (Instruction)insJump.Operand; while (DeobfUtils.IsDirectJumpInstruction(insTarget) || DeobfUtils.IsDirectLeaveInstruction(insTarget)) { insTarget = (Instruction)insTarget.Operand; } Targets.Add(insTarget); } else if (insJump.Operand is Instruction[]) { Instruction[] ops = (Instruction[])insJump.Operand; for (int i = 0; i < ops.Length; i++) { Instruction insTarget = ops[i]; if (insTarget == null) { continue; } while (DeobfUtils.IsDirectJumpInstruction(insTarget) || DeobfUtils.IsDirectLeaveInstruction(insTarget)) { insTarget = (Instruction)insTarget.Operand; } Targets.Add(insTarget); } } }
public static List <JumpInstruction> Find(MethodDefinition method, int insStart, int insEnd) { List <JumpInstruction> list = new List <JumpInstruction>(); Collection <Instruction> ic = method.Body.Instructions; if (insStart < 0) { insStart = 0; } if (insEnd < 0) { insEnd = ic.Count - 1; } InsUtils.ComputeIndexes(ic); for (int i = insStart; i <= insEnd; i++) { Instruction insTemp = ic[i]; if (DeobfUtils.IsJumpInstruction(insTemp)) { list.Add(new JumpInstruction(insTemp)); } } return(list); }
private bool Save() { int start = cboStart.SelectedIndex - 1; int end = cboEnd.SelectedIndex - 1; int to = cboTo.SelectedIndex - 1; if (start < 0 || end < 0 || start > end) { SimpleMessage.ShowError("Invalid instruction range."); return(false); } if (to < 0 || (_start <= to && to <= _end)) { SimpleMessage.ShowError("Invalid target instruction."); return(false); } if (to < start) { _displayStartIndex = to + 1; } else { _displayStartIndex = to - (end - start + 1) + 1; } if (rbBefore.Checked) { if (to > 0) { DeobfUtils.MoveBlock(_method.Body, to - 1, start, end); } else { DeobfUtils.MoveBlock(_method.Body, 0, start, end); DeobfUtils.MoveBlock(_method.Body, end - start + 1, 0, 0); } } else { DeobfUtils.MoveBlock(_method.Body, to, start, end); _displayStartIndex++; } _start = start; _end = end; return(true); }
public void ValidNameTest004() { string target; bool result; TestDeobfOptions options = new TestDeobfOptions(); target = "Aj4QrTN"; //TODO? result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); target = "AJLlWT"; //TODO? result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); target = "A05qgyfk1"; result = DeobfUtils.IsValidName(target, options); Assert.IsFalse(result, target); target = "auTALepob"; //TODO? result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); target = "Rb6hGgFem"; result = DeobfUtils.IsValidName(target, options); Assert.IsFalse(result, target); target = "t97Xh2M3j"; result = DeobfUtils.IsValidName(target, options); Assert.IsFalse(result, target); target = "LpHIjhc6t"; result = DeobfUtils.IsValidName(target, options); Assert.IsFalse(result, target); target = "GpQNp4q1a"; result = DeobfUtils.IsValidName(target, options); Assert.IsFalse(result, target); target = "WGlD8fXCb"; result = DeobfUtils.IsValidName(target, options); Assert.IsFalse(result, target); }
public void ValidNameTest003() { string target; bool result; TestDeobfOptions options = new TestDeobfOptions(); target = "O6Lu9fRJkae1mNEaZw"; result = DeobfUtils.IsValidName(target, options); Assert.IsFalse(result, target); target = "OvsG5kiWa2ig952vSH"; result = DeobfUtils.IsValidName(target, options); Assert.IsFalse(result, target); target = "NqVmlsUVgAvZE5umojm"; result = DeobfUtils.IsValidName(target, options); Assert.IsFalse(result, target); target = "AGEPbiSxbxaFCCuINB"; result = DeobfUtils.IsValidName(target, options); Assert.IsFalse(result, target); target = "PDbM101lmyWjObGHZX"; result = DeobfUtils.IsValidName(target, options); Assert.IsFalse(result, target); target = "uERBbksmWQHZojOlDO"; result = DeobfUtils.IsValidName(target, options); Assert.IsFalse(result, target); target = "mikr9QhOsU7eoLY2vO"; result = DeobfUtils.IsValidName(target, options); Assert.IsFalse(result, target); target = "x20fdba2900edec1d"; result = DeobfUtils.IsValidName(target, options); Assert.IsFalse(result, target); }
public void ValidNameTest002() { string target; bool result; TestDeobfOptions options = new TestDeobfOptions(); target = "MAX_LENGTH"; result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); target = "PDF417"; result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); target = "PDFGetFileName"; result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); target = "SBConfiguration"; result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); target = "ISBNumber"; result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); target = "get_ISBNumber"; result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); target = "GetISBNumber"; result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); target = "GetASPXCode"; result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); }
public override void DecompileObject(object decompileObject) { if (!(decompileObject is IMetadataTokenProvider)) { rtbText.Clear(); return; } string currentAssemblyFile; AssemblyDefinition ad; int index; FindCurrentAssembly(out currentAssemblyFile, out ad, out index); if (index < 0) { return; } IMetadataTokenProvider mtp = (IMetadataTokenProvider)decompileObject; object o = decompileObject; //use loaded assembly if (this.Assembly[index] != null && !(decompileObject is Mono.Cecil.AssemblyDefinition) && !(decompileObject is Mono.Cecil.ModuleDefinition) && !(decompileObject is Mono.Cecil.ModuleReference) && !(decompileObject is Mono.Cecil.AssemblyNameReference) ) { ad = (AssemblyDefinition)this.Assembly[index]; //LookupToken doesn't handle PropertyDefinition & EventDefinition? if (decompileObject is Mono.Cecil.PropertyDefinition) { PropertyDefinition property = (PropertyDefinition)decompileObject; TypeDefinition type = DeobfUtils.Resolve(property.DeclaringType, null, null); if (type != null) { foreach (PropertyDefinition pd in type.Properties) { if (pd.MetadataToken.ToInt32() == property.MetadataToken.ToInt32()) { o = pd; break; } } } } else if (decompileObject is Mono.Cecil.EventDefinition) { EventDefinition eventDef = (EventDefinition)decompileObject; TypeDefinition type = DeobfUtils.Resolve(eventDef.DeclaringType, null, null); if (type != null) { foreach (EventDefinition ed in type.Events) { if (ed.MetadataToken.ToInt32() == eventDef.MetadataToken.ToInt32()) { o = ed; break; } } } } else { //TODO: maybe search by name will be better? o = ad.MainModule.LookupToken(mtp.MetadataToken); } } if (o == null || decompileObject.ToString() != o.ToString()) { rtbText.Rtf = GetRtf("Cannot find matched Cecil object!", null); return; } bool resolveDirAdded = _form.Host.AddAssemblyResolveDir(_form.SourceDir); BaseAssemblyResolver bar = GlobalAssemblyResolver.Instance as BaseAssemblyResolver; bool savedRaiseResolveException = true; try { if (bar != null) { savedRaiseResolveException = bar.RaiseResolveException; bar.RaiseResolveException = false; } rtbText.Rtf = _ilSpy.Decompile(cboLanguage.SelectedItem as string, o); try { isHighlighting = true; //disable hightligh new RichTextFormatterHelper(rtbText).DetectLinks(); } finally { isHighlighting = false; } } finally { if (resolveDirAdded) { _form.Host.RemoveAssemblyResolveDir(_form.SourceDir); } if (bar != null) { bar.RaiseResolveException = savedRaiseResolveException; } } }
public static List <InstructionBlock> Find(MethodDefinition method) { List <InstructionBlock> list = new List <InstructionBlock>(); if (method == null || !method.HasBody) { return(list); } Collection <Instruction> ic = method.Body.Instructions; if (ic.Count < 1) { return(list); } int firstIndex = 0; int lastIndex = firstIndex; Instruction insLast = ic[lastIndex]; while (lastIndex < ic.Count) { if (DeobfUtils.IsBlockDelimiter(insLast) || lastIndex + 1 >= ic.Count) { InstructionBlock ib = new InstructionBlock(firstIndex, lastIndex); list.Add(ib); firstIndex = lastIndex + 1; lastIndex = firstIndex; } else { lastIndex++; } if (lastIndex >= ic.Count) { break; } insLast = ic[lastIndex]; } int insCount = 0; foreach (InstructionBlock ib in list) { insCount += ib.EndIndex - ib.StartIndex + 1; Instruction insTo = null; if (ic[ib.EndIndex].Operand is Instruction) { insTo = ic[ib.EndIndex].Operand as Instruction; } else { int prev = ib.EndIndex - 1; if (prev >= ib.StartIndex && ic[prev].Operand is Instruction) { insTo = ic[ib.EndIndex].Operand as Instruction; } } if (insTo != null) { int to = ic.IndexOf(insTo); foreach (InstructionBlock ib2 in list) { if (ib2.StartIndex == ib.StartIndex) { continue; } if (ib2.StartIndex <= to && to <= ib2.EndIndex) { ib.NextBlock = ib2; if (ib.StartIndex < ib2.StartIndex) { ib2.JumpDownRefCount++; } else { ib2.JumpUpRefCount++; } } } } } if (insCount != ic.Count) { throw new ApplicationException("internal error in InstructionBlock.Find."); } return(list); }
public void ValidNameTest001() { string target; bool result; TestDeobfOptions options = new TestDeobfOptions(); target = "delegate037"; result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); target = "m0000a5"; result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); target = "A4"; result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); target = "runMethod2"; result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); target = "get_AssemblyName"; result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); target = "CloseAllOpeningFiles"; result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); target = "UserCommentMaxLength"; result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); target = "get_RefersToR1C1"; result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); target = "CompareTo"; result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); target = "Superscript"; result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); target = "SyncRoot"; result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); target = "CheckLayout"; result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); target = "SW_MINIMIZE"; result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); target = "CreateAQF1Completed"; result = DeobfUtils.IsValidName(target, options); Assert.IsTrue(result, target); }