public CLabeledStatement(string codeString, CExpression caseExpression, CStatement labeledStatement) : base(caseExpression != null ? "case " + caseExpression.codeString : codeString, labeledStatement != null ? labeledStatement.nextStatement : null) { this.labeledStatement = labeledStatement; this.caseExpression = caseExpression; }
public CConditionalStatement parseIfStatement(Queue <CMatchedData> matchedData) { CToken[] currTokens = matchedData.Dequeue().getTokens(); CExpression conditionExpression; CStatement ifTrueStatement; if (currTokens[0].tokenType != CTokenType.IF) { throw new System.ArgumentException("matchedData should start with an if statement!", "matchedData"); } conditionExpression = new CExpression(getText(currTokens, 2, currTokens.Length - 1)); ifTrueStatement = parseStatement(matchedData); /* Check if next statement is ELSE */ if (ifTrueStatement.nextStatement is CConditionalStatement && ((CConditionalStatement)ifTrueStatement.nextStatement).condition == null) { CStatement elseStatement = ((CConditionalStatement)ifTrueStatement.nextStatement).ifTrueStatement; return(new CConditionalStatement(conditionExpression, ifTrueStatement, elseStatement, ifTrueStatement.nextStatement.nextStatement)); } return(new CConditionalStatement(conditionExpression, ifTrueStatement, ifTrueStatement.nextStatement)); }
public _Customer() { this.ID = 0; this.CusNo = string.Empty; this.CusType = string.Empty; this.IDCard = string.Empty; this.CorporationCode = string.Empty; this.Prefix = string.Empty; this.Name = string.Empty; this.Surname = string.Empty; this.Nickname = string.Empty; this.Sex = string.Empty; this.Birthday = DateTime.MinValue; this._Education = new _EducationList._Education(); this.Tel_Home = string.Empty; this.Tel_Mobile1 = string.Empty; this.Tel_Mobile2 = string.Empty; this.Tel_Work = string.Empty; this.Tel_Fax = string.Empty; this._AddressList = new _AddressList(); this._SentAddressList = new _AddressList(); this._Address = new _AddressList._Address(); this._Career = new _CareerList._Career(); this.Career_Other = string.Empty; this.Career_Remark = string.Empty; this._Income = new _IncomeList._Income(); this.Total_Member = 0; this.User_Add = 0; this._statement = new CStatement("Select_Customer", "INSERT", "UPDATE", "DELETE", System.Data.CommandType.StoredProcedure); this._statementMaxCusNo = new CStatement("Select_MaxCusNo", "INSERT", "UPDATE", "DELETE", System.Data.CommandType.StoredProcedure); }
public _Postel() { this.ID = 0; this._District = new _DistrictList._District(); this.Postel_Code = string.Empty; this._statement = new CStatement("Select_Postel", "INSERT", "UPDATE", "DELETE", System.Data.CommandType.StoredProcedure); }
public ProductList() { this._statememet = new CStatement("uspGetProduct", "uspAddProduct", "uspUpdateProduct", "uspDelProduct", System.Data.CommandType.StoredProcedure); this._statememetType = new CStatement("uspGetTypeProduct", "uspAddTypeProduct", "uspUpdateTypeProduct", "uspDelTypeProduct", System.Data.CommandType.StoredProcedure); this._statememetProduct = new CStatement("uspSelectProduct", "", "", "", System.Data.CommandType.StoredProcedure); this._searchProduct = new CStatement("uspSearchProduct", "", "", "", System.Data.CommandType.StoredProcedure); }
public CFor(CStatement initial, CStatement update, CExpression predicate, CBlock body) { Initial = initial; Update = update; Predicate = predicate; Body = body; }
public SearchMCNumber() { this._Customer = new _Customer(); this._Address = new _AddressList._Address(); this._Purchase = new _Purchase(); this._statement = new CStatement("Select_MCNumber", "INSERT", "UPDATE", "DELETE", System.Data.CommandType.StoredProcedure); this._statementChk = new CStatement("Select_CheckMCNumber", "INSERT", "UPDATE", "DELETE", System.Data.CommandType.StoredProcedure); }
public virtual void setNextStatement(CStatement nextStatement) { if (!this.nextStatementSet) { this.nextStatement = nextStatement; this.nextStatementSet = true; } }
public void VisitStatement(CStatement statement) { if (!(statement is CNewline)) { InstrumentNode(statement); } visitor.VisitStatement(statement); }
public void setLabeledStatement(CStatement labeledStatement) { if (!this.labeledStatementSet) { this.labeledStatement = labeledStatement; this.labeledStatementSet = true; } }
public CConditionalStatement(CExpression condition, CStatement trueStatement, CStatement nextStatement) : base(condition != null ? "if: " + condition.codeString : "", nextStatement) { this.condition = condition; this.ifTrueStatement = trueStatement; this.ifTrueStatement.setNextStatement(null); }
public RedCarPlate() { this.ID = 0; this.RedCarPlate_DATE = DateTime.MinValue; this.RedCarPlate_NO = string.Empty; this.RedCarPlate_PRICE = 0; this.RedCarPlate_NUM = string.Empty; this._statement = new CStatement("uspSelectRedCarPlate", "INSERT", "UPDATE", "DELETE", System.Data.CommandType.StoredProcedure); }
public override bool contains(CStatement statement) { if (statement == this) { return(true); } return(false); }
public _Invoice() { this._statememetInvoice = new CStatement("uspSelectInvoice", "uspInsertInvoice", "uspUpdatePurchase", "", System.Data.CommandType.StoredProcedure); _Invoice_Date = DateTime.MinValue; _GetInvoice_Date = DateTime.MinValue; _Transport_Date = DateTime.MinValue; _GetGuide = DateTime.MinValue; _GetBadge_Date = DateTime.MinValue; _NoteSet_Date = DateTime.MinValue; _GetNotSet_Date = DateTime.MinValue; _RemarkInvoice = String.Empty; }
public TreePetchList() { this._statememet_Count = new CStatement("uspSelectCount_Item", "uspImportExcelStock", "UPDATE", "DELECT", System.Data.CommandType.StoredProcedure); this._statememet_Total_Coast = new CStatement("uspSelectTotal_Coast", "uspImportExcelStock", "UPDATE", "DELECT", System.Data.CommandType.StoredProcedure); this._statememet_Sum_Amound = new CStatement("uspSelectSum_AmoundSold", "uspImportExcelStock", "UPDATE", "DELECT", System.Data.CommandType.StoredProcedure); this._statememet_Dis_Bath = new CStatement("uspSelectDif_Coast_Dis_Bath", "uspImportExcelStock", "UPDATE", "DELECT", System.Data.CommandType.StoredProcedure); this._statememet_Dis_EA = new CStatement("uspSelectDif_Coast_Dis_EA", "uspImportExcelStock", "UPDATE", "DELECT", System.Data.CommandType.StoredProcedure); this._statememet_Dis_List = new CStatement("uspSelectDif_Coast_Dis_List", "uspImportExcelStock", "UPDATE", "DELECT", System.Data.CommandType.StoredProcedure); this._statememet_Plus_Bath = new CStatement("uspSelectDif_Coast_Plus_Bath", "uspImportExcelStock", "UPDATE", "DELECT", System.Data.CommandType.StoredProcedure); this._statememet_Plus_EA = new CStatement("uspSelectDif_Coast_Plus_EA", "uspImportExcelStock", "UPDATE", "DELECT", System.Data.CommandType.StoredProcedure); this._statememet_Plus_List = new CStatement("uspSelectDif_Coast_Plus_List", "uspImportExcelStock", "UPDATE", "DELECT", System.Data.CommandType.StoredProcedure); }
public override bool contains(CStatement statement) { if (statement == this) { return(true); } if (this.switchStatement != null && this.switchStatement.contains(statement)) { return(true); } return(false); }
public CSwitchStatement(CExpression condition, CStatement switchStatement, CLabeledStatement[] jumpTargets, CStatement nextStatement) : base(condition != null ? "switch: " + condition.codeString : "", new CLabeledStatement("switch break target", null, nextStatement != null ? nextStatement : new CExpressionStatement(new CExpression(";"), null))) { this.condition = condition; this.switchStatement = switchStatement; this.switchStatement.setNextStatement(null); this.jumpTargets = (CLabeledStatement[])jumpTargets.Clone(); }
public Tb_User() { this.EmpID = 0; this.ID = 0; this.UserType = 0; this.TypeName = string.Empty; this.Username = string.Empty; this.Password = string.Empty; this.FullName = string.Empty; this.NickName = string.Empty; this.Company = string.Empty; this.Branch = string.Empty; this.Team = string.Empty; this._statement = new CStatement("Select_User", "INSERT", "UPDATE", "DELETE", System.Data.CommandType.StoredProcedure); }
public _BodyClass() { this.Body_Acc_ID = 0; this.Body_Company_ID = 0; this.Body_Acc_Name = string.Empty; this.Body_Model_ID = 0; this.Body_Model_price = 0; this.Mcode = string.Empty; this.Body_Option_ID = 0; this.Body_Option_Name = string.Empty; this.Body_Option_price = 0; this.finance = string.Empty; this._statement = new CStatement("Body_Select_Accessories", "INSERT", "UPDATE", "DELETE", System.Data.CommandType.StoredProcedure); this._statement1 = new CStatement("Body_Select_Option_price", "INSERT", "UPDATE", "DELETE", System.Data.CommandType.StoredProcedure); }
public CJumpStatement(string codeString, CStatement nextStatement) : base(codeString, nextStatement) { string[] parts = codeString.Split(' '); if (parts[0] == "goto" && parts.Length > 1) { this.targetIdentifier = parts[1]; } else { this.targetIdentifier = null; } this.returnedExpression = null; }
public CLabeledStatement parseLabeledStatement(Queue <CMatchedData> matchedData) { CToken[] currTokens = matchedData.Dequeue().getTokens(); string labelName = currTokens[0].tokenCode; CExpression caseExpression = null; CStatement labeled = parseStatement(matchedData); CLabeledStatement result; if (labelName == "case") { caseExpression = new CExpression(getText(currTokens, 1, currTokens.Length - 1)); } if (labeled == null) { throw new System.InvalidOperationException("error: label at end of compound statement!"); } result = new CLabeledStatement(labelName, caseExpression, labeled); if (labelName == "case" || labelName == "default") { this.caseLabels.Add(result); } else { int i; /* Match label with goto */ for (i = 0; i < this.gotoJumps.Count; i++) { if (this.gotoJumps[i].targetIdentifier == labelName) { this.gotoJumps[i].setTargetStatement(result); this.gotoJumps.RemoveAt(i); return(result); } } this.labels.Add(result); } return(result); }
public CCompoundStatement parseCompoundStatement(Queue <CMatchedData> matchedData) { List <CStatement> containedStatements = new List <CStatement>(); CToken[] currTokens = matchedData.Dequeue().getTokens(); Queue <CMatchedData> containedMatchedData = new Queue <CMatchedData>(matchCompoundStatementContents(currTokens)); CStatement currStatement = null; containedStatements.Add(currStatement = parseStatement(containedMatchedData)); while (currStatement != null) { containedStatements.Add(currStatement = currStatement.nextStatement); } return(new CCompoundStatement(containedStatements.ToArray(), parseStatement(matchedData))); }
public _BranchList() { this._statement = new CStatement("SELECT_Company", "INSERT", "UPDATE", "DELETE", System.Data.CommandType.StoredProcedure); this._statementB = new CStatement("SELECT_Branch", "INSERT", "UPDATE", "DELETE", System.Data.CommandType.StoredProcedure); }
public CStatement(string codeString, CStatement nextStatement) { this.codeString = codeString; this.nextStatement = nextStatement; }
static List<CStatement> Add_C(uint pc, uint instruction) { Instruction i = new Instruction(instruction); /* op1 + op2 */ CStatement stat = new CStatement(CStatement.Kinds.Addition, RegName(i.RA()), RegName(i.RB())); /* dest = expr */ CStatement ass = new CStatement(CStatement.Kinds.Assignment, RegName(i.RD()), stat); List<CStatement> stats = new List<CStatement>(); stats.Add(ass); if (i.OE()) MessageBox.Show("This instruction sets the O bit. I don't know how to translate it! Ignoring."); if (i.RC()) stats.Add(new CStatement(CStatement.Kinds.Assignment, "cr0", RegName(i.RD()))); return stats; }
static List<CStatement> Lbzx_C(uint pc, uint instruction) { Instruction i = new Instruction(instruction); CStatement stat = new CStatement(CStatement.Kinds.Assignment, RegName(i.RD())); stat.OperandSizes = CStatement.Sizes.Byte; if (i.RA() != 0) { if (i.RB() != 0) stat.Op2 = new CStatement.COperand(RegName(i.RA()), RegName(i.RB())); else stat.Op2 = new CStatement.COperand(RegName(i.RA()), 0); } else stat.Op2 = new CStatement.COperand(RegName(i.RB()), 0); List<CStatement> stats = new List<CStatement>(); stats.Add(stat); return stats; }
public CJumpStatement(CExpression returnedExpression, CStatement nextStatement) : base("return " + returnedExpression.codeString, nextStatement) { this.targetIdentifier = null; this.returnedExpression = returnedExpression; }
public BodyOptionExtraList() { this._statement = new CStatement("Body_Select_Option_price", "INSERT", "UPDATE", "DELETE", System.Data.CommandType.StoredProcedure); }
static List<CStatement> Srawi_C(uint pc, uint instruction) { Instruction i = new Instruction(instruction); CStatement shift = new CStatement(CStatement.Kinds.RightShift, RegName(i.RS()), i.SH()); shift.OperandSizes = CStatement.Sizes.Int; CStatement stat = new CStatement(CStatement.Kinds.Assignment, RegName(i.RA()), shift); stat.OperandSizes = CStatement.Sizes.Int; List<CStatement> stats = new List<CStatement>(); stats.Add(stat); if (i.RC()) stats.Add(new CStatement(CStatement.Kinds.Assignment, "cr0", RegName(i.RA()))); return stats; }
static List<CStatement> B_C(uint pc, uint instruction) { Instruction i = new Instruction(instruction); List<CStatement> stats = new List<CStatement>(); uint destination = (uint) SignExtend24(i.LI() << 2); if ((instruction & 2) != 2) destination += pc; Function f = decompiler.Functions.Find(delegate(Function fn) { return fn.Address == destination; }); String destName; if (f != null) destName = f.Name; else destName = "L" + destination.ToString("X8"); CStatement branch = new CStatement(); if (i.LK()) { if (f != null && decompiler.IgnoredCalls.Contains(f)) return new List<CStatement>(); if (f != null && f.Returns.Name == "void" && f.Returns.Kind == CType.TypeKind.ValueType) { branch.Kind = CStatement.Kinds.Call; branch.CallFuncName = destName; branch.CalledFunction = f; } else { branch.Kind = CStatement.Kinds.Assignment; branch.Op1 = new CStatement.COperand("r3"); CStatement realBranch = new CStatement(CStatement.Kinds.Call); realBranch.CallFuncName = destName; realBranch.CalledFunction = f; branch.Op2 = new CStatement.COperand(realBranch); } } else { if (f != null && decompiler.CallIsRet.Contains(f)) branch.Kind = CStatement.Kinds.Return; else { branch.Kind = CStatement.Kinds.Goto; branch.BranchDestination = destName; branch.BranchDestinationAddr = destination; } } stats.Add(branch); return stats; }
static List<CStatement> Twi_C(uint pc, uint instruction) { Instruction i = new Instruction(instruction); CStatement stat = new CStatement(CStatement.Kinds.Throw); if (i.TO() != 31) throw new Exception("Can't handle complex twi"); List<CStatement> stats = new List<CStatement>(); stats.Add(stat); return stats; }
static List<CStatement> Stw_C(uint pc, uint instruction) { Instruction i = new Instruction(instruction); CStatement stat = new CStatement(CStatement.Kinds.Assignment); stat.OperandSizes = CStatement.Sizes.Int; if (i.RS() == 0) stat.Op2 = new CStatement.COperand(0); else stat.Op2 = new CStatement.COperand(RegName(i.RS())); int ds = (int)i.SIMM(); if (i.RA() != 0) stat.Op1 = new CStatement.COperand(RegName(i.RA()), ds); else { stat.Op1 = new CStatement.COperand(); stat.Op1.Kind = CStatement.OperandKinds.AddressPointer; stat.Op1.Offset = ds; } List<CStatement> stats = new List<CStatement>(); stats.Add(stat); return stats; }
private void LoopPhase2(List<FunctionBlock> blocks, List<Loop> loops) { /* Take loops in reverse order (inner loops are processed before outer loops */ loops.Sort(LoopSortDesc); foreach (Loop loop in loops) { FunctionBlock lastBlock = loop.Blocks[loop.Blocks.Count - 1]; CStatement doWhile = new CStatement(); doWhile.Kind = CStatement.Kinds.DoWhile; doWhile.Condition = FindLastCondition(lastBlock.Statements); doWhile.SubBlocks = loop.Blocks; doWhile.BreakBlock = blocks[lastBlock.Id + 1]; doWhile.ContinueBlock = lastBlock; doWhile.ExpandBlocks(); if (doWhile.ContinueBlock.Statements.Count != 1) doWhile.ContinueBlock = null; else { CStatement stat = doWhile.ContinueBlock.Statements[0]; if (stat.Kind != CStatement.Kinds.Conditional) doWhile.ContinueBlock = null; else { if (stat.InnerBlock[0].BranchDestinationAddr != loop.Blocks[0].StartAddress) doWhile.ContinueBlock = null; } } /* Remove all blocks in the loop from the main block list. It is replaced by a single while block */ int firstIndex = blocks.IndexOf(loop.Blocks[0]); FunctionBlock firstBlock = blocks[firstIndex]; foreach (FunctionBlock b in loop.Blocks) blocks.Remove(b); FunctionBlock fake = new FunctionBlock(); fake.StartAddress = firstBlock.StartAddress; fake.InstrCount = 0; fake.Statements.Add(doWhile); loop.LoopBlock = fake; blocks.Insert(firstIndex, fake); StructureBreakContinue(doWhile, doWhile.ContinueBlock, doWhile.BreakBlock); } foreach (Loop loop in loops) { FunctionBlock precBlock = blocks.Find(delegate(FunctionBlock b) { return b.Id == loop.Blocks[0].Id - 1; }); uint precedingBlockStart = precBlock.StartAddress; uint lastInstruction = precedingBlockStart + (precBlock.InstrCount - 1) * 4; uint offset = state.Pe.Rva2Offset(lastInstruction - (uint)state.Pe.optHdr.ImageBase); uint instruction = state.Pe.ReadInstruction(offset); XenonInstructions.OpCodeInfo info = state.Instructions.GetInfo(instruction); if (info.Id == XenonInstructions.Mnemonics.PPC_OP_B) { uint bDest = (instruction & 0xFFFFFF) + lastInstruction; if (bDest == loop.Header.StartAddress) { loop.LoopBlock.Statements[0].Kind = CStatement.Kinds.While; precBlock.InstrCount--; precBlock.Statements.RemoveAt(precBlock.Statements.Count - 1); } } } foreach (Loop loop in loops) { int cnt = loop.LoopBlock.Statements[0].SubBlocks.Count; FunctionBlock last = loop.LoopBlock.Statements[0].SubBlocks[cnt - 1]; loop.LoopBlock.Statements[0].SubBlocks.RemoveAt(cnt - 1); last.Statements.RemoveAt(0); if (last.Statements.Count != 0) { blocks.Add(last); blocks.Sort(Function.FunctionBlockSorter); } /* This will have removed some statements, reexpand the blocks */ loop.LoopBlock.Statements[0].ExpandBlocks(); } }
static List<CStatement> Mtspr_C(uint pc, uint instruction) { Instruction i = new Instruction(instruction); CStatement stat = new CStatement(CStatement.Kinds.Assignment, null, RegName(i.RS())); stat.OperandSizes = CStatement.Sizes.Long; stat.Op1 = new CStatement.COperand(); stat.Op1.Kind = CStatement.OperandKinds.Variable; switch (i.SPR()) { case 32: stat.Op1.Name = "xer"; break; case 256: stat.Op1.Name = "lr"; break; case 288: stat.Op1.Name = "ctr"; break; default: stat.Op1.Name = "spr" + i.SPR(); break; } List<CStatement> stats = new List<CStatement>(); stats.Add(stat); return stats; }
static List<CStatement> Ori_C(uint pc, uint instruction) { Instruction i = new Instruction(instruction); /* NOP */ if (i.RA() == i.RS() && i.RS() == 0 && i.UIMM() == 0) return new List<CStatement>(); CStatement stat; if (i.RS() == 0) stat = new CStatement(CStatement.Kinds.Assignment, RegName(i.RA()), i.UIMM()); else if (i.UIMM() == 0) stat = new CStatement(CStatement.Kinds.Assignment, RegName(i.RA()), RegName(i.RS())); else { CStatement or = new CStatement(CStatement.Kinds.Or, RegName(i.RS()), i.UIMM()); or.OperandSizes = CStatement.Sizes.Long; stat = new CStatement(CStatement.Kinds.Assignment, RegName(i.RA()), or); } stat.OperandSizes = CStatement.Sizes.Long; List<CStatement> stats = new List<CStatement>(); stats.Add(stat); return stats; }
private static CStatement ConditionCheck(Instruction i) { CStatement CtrCondition = null; CStatement CrCondition = null; if ((i.BO() & 4) == 0) { CtrCondition = new CStatement(); } if ((i.BO() & 0x10) == 0) { CrCondition = new CStatement(); CrCondition.Kind = CStatement.Kinds.Comparison; uint cr = i.BI() / 4; uint fld = i.BI() % 4; CrCondition.Op1 = new CStatement.COperand("cr" + cr); CrCondition.Op2 = new CStatement.COperand(0); bool bo = ((i.BO() >> 3) & 1) == 1; switch (fld) { case 0: if (bo) CrCondition.ConditionSign = CStatement.Conditions.LessThan; else CrCondition.ConditionSign = CStatement.Conditions.GreaterEqualThan; break; case 1: if (bo) CrCondition.ConditionSign = CStatement.Conditions.GreaterThan; else CrCondition.ConditionSign = CStatement.Conditions.LessEqualThan; break; case 2: if (bo) CrCondition.ConditionSign = CStatement.Conditions.Equal; else CrCondition.ConditionSign = CStatement.Conditions.NotEqual; break; case 3: if (bo) CrCondition.ConditionSign = CStatement.Conditions.Overflow; else CrCondition.ConditionSign = CStatement.Conditions.NotOverflow; break; } } CStatement final = null; if (CrCondition != null) { if (CtrCondition != null) { CStatement composite = new CStatement(CStatement.Kinds.CompositeCondition, CrCondition, CtrCondition); composite.ConditionSign = CStatement.Conditions.And; final = new CStatement(); final.Kind = CStatement.Kinds.Conditional; final.Condition = composite; } else { final = new CStatement(); final.Kind = CStatement.Kinds.Conditional; final.Condition = CrCondition; } } else if (CtrCondition != null) { final = new CStatement(); final.Kind = CStatement.Kinds.Conditional; final.Condition = CtrCondition; } return final; }
static List<CStatement> Bclr_C(uint pc, uint instruction) { Instruction i = new Instruction(instruction); List<CStatement> stats = new List<CStatement>(); if ((i.BO() & 4) == 0) { CStatement ctrSub = new CStatement(CStatement.Kinds.Subtraction, "CTR", 1); CStatement ctrAss = new CStatement(CStatement.Kinds.Assignment, "CTR", ctrSub); stats.Add(ctrAss); } CStatement final = ConditionCheck(i); CStatement branch = new CStatement(); if (i.LK()) { branch.Kind = CStatement.Kinds.Assignment; branch.Op1 = new CStatement.COperand("r3"); CStatement realBranch = new CStatement(CStatement.Kinds.Call); realBranch.CallFuncName = "lr"; realBranch.BranchDestinationRegister = "lr"; branch.Op2 = new CStatement.COperand(realBranch); } else branch.Kind = CStatement.Kinds.Return; if (final == null) final = branch; else { final.InnerBlock = new List<CStatement>(); final.InnerBlock.Add(branch); } stats.Add(final); return stats; }
public abstract bool contains(CStatement statement);
static List<CStatement> Bc_C(uint pc, uint instruction) { Instruction i = new Instruction(instruction); List<CStatement> stats = new List<CStatement>(); if ((i.BO() & 4) == 0) { CStatement ctrSub = new CStatement(CStatement.Kinds.Subtraction, "CTR", 1); CStatement ctrAss = new CStatement(CStatement.Kinds.Assignment, "CTR", ctrSub); stats.Add(ctrAss); } CStatement final = ConditionCheck(i); uint destination = (uint)(int)(short)(i.BD() << 2); if ((instruction & 2) != 2) destination += pc; Function f = decompiler.Functions.Find(delegate(Function fn) { return fn.Address == destination; }); String destName; if (f != null) destName = f.Name; else destName = "L" + destination.ToString("X8"); CStatement branch = new CStatement(); if (i.LK()) { if (f != null && decompiler.IgnoredCalls.Contains(f)) return new List<CStatement>(); if (f != null && f.Returns.Name == "void" && f.Returns.Kind == CType.TypeKind.ValueType) { branch.Kind = CStatement.Kinds.Call; branch.CallFuncName = destName; branch.CalledFunction = f; } else { branch.Kind = CStatement.Kinds.Assignment; branch.Op1 = new CStatement.COperand("r3"); CStatement realBranch = new CStatement(CStatement.Kinds.Call); realBranch.CallFuncName = destName; realBranch.CalledFunction = f; branch.Op2 = new CStatement.COperand(realBranch); } } else { if (f != null && decompiler.CallIsRet.Contains(f)) branch.Kind = CStatement.Kinds.Return; else { branch.Kind = CStatement.Kinds.Goto; branch.BranchDestination = destName; branch.BranchDestinationAddr = destination; } } if (final == null) final = branch; else { final.InnerBlock = new List<CStatement>(); final.InnerBlock.Add(branch); } stats.Add(final); return stats; }
private void StructureBreakContinue(CStatement container, FunctionBlock continueBlock, FunctionBlock breakBlock) { foreach (CStatement stmt in container.InnerBlock) { switch (stmt.Kind) { case CStatement.Kinds.Goto: if (continueBlock != null && stmt.BranchDestinationAddr == continueBlock.StartAddress) stmt.Kind = CStatement.Kinds.Continue; else if (stmt.BranchDestinationAddr == breakBlock.StartAddress) stmt.Kind = CStatement.Kinds.Break; break; case CStatement.Kinds.Conditional: /* Recursion to subscopes */ StructureBreakContinue(stmt, continueBlock, breakBlock);; break; default: /* Do not recurse to do/while, while and for, since they have their own continue and break blocks! */ break; } } }
static List<CStatement> And_C(uint pc, uint instruction) { Instruction i = new Instruction(instruction); /* op1 & op2 */ CStatement stat = new CStatement(CStatement.Kinds.And, RegName(i.RS()), RegName(i.RB())); /* dest = expr */ CStatement ass = new CStatement(CStatement.Kinds.Assignment, RegName(i.RA()), stat); List<CStatement> stats = new List<CStatement>(); stats.Add(ass); if (i.RC()) stats.Add(new CStatement(CStatement.Kinds.Assignment, "cr0", RegName(i.RA()))); return stats; }
static List<CStatement> Cmp_C(uint pc, uint instruction) { Instruction i = new Instruction(instruction); CStatement stat = new CStatement(CStatement.Kinds.Subtraction, RegName(i.RA()), RegName(i.RB())); CStatement ass = new CStatement(CStatement.Kinds.Assignment, "cr" + i.CRFD(), stat); if (!i.CmpLong()) ass.OperandSizes = stat.OperandSizes = CStatement.Sizes.Int; List<CStatement> stats = new List<CStatement>(); stats.Add(ass); return stats; }
static List<CStatement> Rlwimi_C(uint pc, uint instruction) { List<CStatement> stats = new List<CStatement>(); Instruction i = new Instruction(instruction); uint m1 = 0xFFFFFFFF << (int)i.ME(); uint m2 = 0xFFFFFFFF << (int)i.MB(); uint mask = m1 ^ m2; CStatement lsh = new CStatement(CStatement.Kinds.LeftShift, RegName(i.RS()), 32 - i.SH()); CStatement rsh = new CStatement(CStatement.Kinds.RightShift, RegName(i.RS()), i.SH()); CStatement orRot = new CStatement(CStatement.Kinds.Or, rsh, lsh); CStatement notMask = new CStatement(CStatement.Kinds.BinaryNot, mask); CStatement and1 = new CStatement(CStatement.Kinds.And, orRot, mask); CStatement and2 = new CStatement(CStatement.Kinds.And, RegName(i.RA()), notMask); CStatement or = new CStatement(CStatement.Kinds.Or, and1, and2); CStatement ass = new CStatement(CStatement.Kinds.Assignment, RegName(i.RA()), or); stats.Add(ass); /* RA = (ROTL(RS, i.SH) & mask) | (RA & ~mask); */ if (i.RC()) stats.Add(new CStatement(CStatement.Kinds.Assignment, "cr0", RegName(i.RA()))); return stats; }
static List<CStatement> Stwu_C(uint pc, uint instruction) { Instruction i = new Instruction(instruction); List<CStatement> stats = Stw_C(pc, instruction); if (i.SIMM() == 0) return stats; CStatement add = new CStatement(CStatement.Kinds.Addition, RegName(i.RA()), (ulong)(long)i.SIMM()); CStatement stat = new CStatement(CStatement.Kinds.Assignment, RegName(i.RA()), add); stat.OperandSizes = CStatement.Sizes.Int; stats.Add(stat); return stats; }
public BodyClassList() { this._statement = new CStatement("Body_Select_Accessories", "INSERT", "UPDATE", "DELETE", System.Data.CommandType.StoredProcedure); }
static List<CStatement> Rlwinm_C(uint pc, uint instruction) { /** * Very complex instruction * RA = RotateLeft(RS, SH) & ((0xFFFFFFFF >> MB) ^ (0xFFFFFFFF >> ME)); * * Can be simplified: * if (MB == 0 && ME + SH == 31) * ShiftLeft (BigEndian) = ShiftRight (LittleEndian) * if (ME == 31 && SH + MB == 32) * ShiftRight (BigEndian) = ShiftLeft * if (SH == 0 && ME == 31) * ClearLeft = ClearRight * if (SH == 0 && MB == 0) * ClearRight = ClearLeft * if (MB == 0 && ME == 31) * Rotate * * extlwi rA,rS,n,b equivalent to rlwinm rA,rS,b,0,n – 1 * extrwi rA,rS,n,b equivalent to rlwinm rA,rS,b + n,32 – n,31 * clrlslwi rA,rS,b,n equivalent to rlwinm rA,rS,n,b – n,31 – n */ List<CStatement> stats = new List<CStatement>(); Instruction i = new Instruction(instruction); if (i.MB() == 0) { if (i.ME() == 31) { /* * Rotate left - Rotate right... * ((x >> n) | (x << (32 - n))) */ uint n = i.SH(); CStatement lsh = new CStatement(CStatement.Kinds.LeftShift, RegName(i.RS()), 32 - n); CStatement rsh = new CStatement(CStatement.Kinds.RightShift, RegName(i.RS()), n); CStatement or = new CStatement(CStatement.Kinds.Or, rsh, lsh); CStatement ass = new CStatement(CStatement.Kinds.Assignment, RegName(i.RA()), or); stats.Add(ass); } else if (i.ME() + i.SH() == 31) { /* ShiftLeft = ShiftRight */ uint n = i.SH(); CStatement rsh = new CStatement(CStatement.Kinds.RightShift, RegName(i.RS()), n); CStatement ass = new CStatement(CStatement.Kinds.Assignment, RegName(i.RA()), rsh); stats.Add(ass); } else if (i.SH() == 0) { /* ClearRight = ClearLeft */ uint n = 31 - i.ME(); uint mask = 0xFFFFFFFF << (int)n; CStatement and = new CStatement(CStatement.Kinds.And, RegName(i.RS()), mask); CStatement ass = new CStatement(CStatement.Kinds.Assignment, RegName(i.RA()), and); stats.Add(ass); } } else if (i.ME() == 31 && i.SH() + i.MB() == 32) { /* ShiftRight = ShiftLeft */ uint n = i.MB(); CStatement lsh = new CStatement(CStatement.Kinds.LeftShift, RegName(i.RS()), n); CStatement ass = new CStatement(CStatement.Kinds.Assignment, RegName(i.RA()), lsh); stats.Add(ass); } else if (i.SH() == 0) { if (i.ME() == 31) { /* ClearLeft = ClearRight */ uint n = i.MB(); uint mask = 0xFFFFFFFF ^ (0xFFFFFFFF << (int)n); CStatement and = new CStatement(CStatement.Kinds.And, RegName(i.RS()), mask); CStatement ass = new CStatement(CStatement.Kinds.Assignment, RegName(i.RA()), and); stats.Add(ass); } else { /* And without rotate */ uint m1 = 0xFFFFFFFF >> (int)(i.ME() + 1); uint m2 = 0xFFFFFFFF >> (int)i.MB(); uint mask = m1 ^ m2; CStatement and = new CStatement(CStatement.Kinds.And, RegName(i.RS()), mask); CStatement ass = new CStatement(CStatement.Kinds.Assignment, RegName(i.RA()), and); stats.Add(ass); } } else { /* Rotate, then and */ uint n = i.SH(); uint m1 = 0xFFFFFFFF << (int)i.MB(); uint m2 = 0xFFFFFFFF << (int)i.ME(); uint mask = m1 ^ m2; CStatement lsh = new CStatement(CStatement.Kinds.LeftShift, RegName(i.RS()), 32 - n); CStatement rsh = new CStatement(CStatement.Kinds.RightShift, RegName(i.RS()), n); CStatement or = new CStatement(CStatement.Kinds.Or, rsh, lsh); CStatement and = new CStatement(CStatement.Kinds.And, or, mask); CStatement ass = new CStatement(CStatement.Kinds.Assignment, RegName(i.RA()), and); stats.Add(ass); } if (i.RC()) stats.Add(new CStatement(CStatement.Kinds.Assignment, "cr0", RegName(i.RA()))); return stats; }
static List<CStatement> Ld_C(uint pc, uint instruction) { Instruction i = new Instruction(instruction); CStatement stat = new CStatement(CStatement.Kinds.Assignment, RegName(i.RD())); int ds = (int)i.DS() << 2; if (i.RA() != 0) stat.Op2 = new CStatement.COperand(RegName(i.RA()), ds); else { stat.Op2 = new CStatement.COperand(); stat.Op2.Kind = CStatement.OperandKinds.AddressPointer; stat.Op2.Offset = ds; } List<CStatement> stats = new List<CStatement>(); stats.Add(stat); return stats; }
public _BankList() { this._statement = new CStatement("SELECT_Bank", "INSERT", "UPDATE", "DELETE", System.Data.CommandType.StoredProcedure); }
static List<CStatement> Addi_C(uint pc, uint instruction) { Instruction i = new Instruction(instruction); CStatement stat = new CStatement(CStatement.Kinds.Assignment, RegName(i.RD())); if (i.RA() == 0) stat.Op2 = new CStatement.COperand((ulong)(long)i.SIMM()); else if (i.SIMM() == 0) stat.Op2 = new CStatement.COperand(RegName(i.RA())); else { CStatement add = new CStatement(CStatement.Kinds.Addition, RegName(i.RA()), (ulong)(long)i.SIMM()); long val = (long)add.Op2.Value; if (val < 0) { add.Kind = CStatement.Kinds.Subtraction; add.Op2.Value = (ulong)-val; } stat.Op2 = new CStatement.COperand(add); } List<CStatement> stats = new List<CStatement>(); stats.Add(stat); return stats; }
public _InvoiceList() { this._statememet = new CStatement("uspSelectInvoice", "uspInsertInvoice", "uspUpdatePurchase", "", System.Data.CommandType.StoredProcedure); this._statememet2 = new CStatement("", "", "uspUpdateCarInfo", "", System.Data.CommandType.StoredProcedure); }
private void DecompileFunction(object sender, RoutedEventArgs e) { ListViewFunction item = (ListViewFunction)FunctionsView.SelectedItem; Function f = item.Details; if (f.Size == 0xFFFFFFFF || f.Blocks == null) { f.FindSize(); FindDominators(f.Blocks); } f.Loops = FindLoops(f.Blocks); DecompileEasy(f); ComputeUseDefs(f.Blocks); // PropagateExpressions(f.Blocks); // NiceConditions(f.Blocks); // LoopPhase2(f.Blocks, f.Loops); // IfElse(f.Blocks); List<CStatement> statements = new List<CStatement>(); foreach (FunctionBlock b in f.Blocks) { CStatement label = new CStatement(CStatement.Kinds.Label); label.LabelName = "L" + b.StartAddress.ToString("X8"); statements.Add(label); statements.AddRange(b.Statements); } string csource = "void " + f.Name + "()\n{\n"; foreach (CStatement stat in statements) { if (stat.Kind != CStatement.Kinds.Label) csource += "\t"; csource += stat.ToString(1); if (stat.Kind != CStatement.Kinds.Conditional && stat.Kind != CStatement.Kinds.Label) csource += ";\n"; else csource += "\n"; } csource += "}"; CSource src = new CSource(csource); src.Show(); }
static List<CStatement> Or_C(uint pc, uint instruction) { Instruction i = new Instruction(instruction); CStatement stat; if (i.RS() == 0 && i.RB() != 0) stat = new CStatement(CStatement.Kinds.Assignment, RegName(i.RA()), RegName(i.RB())); else if (i.RB() == 0 && i.RS() != 0) stat = new CStatement(CStatement.Kinds.Assignment, RegName(i.RA()), RegName(i.RS())); else if (i.RS() == i.RB()) { if (i.RS() != 0) stat = new CStatement(CStatement.Kinds.Assignment, RegName(i.RA()), RegName(i.RS())); else stat = new CStatement(CStatement.Kinds.Assignment, RegName(i.RA()), 0); } else { CStatement or = new CStatement(CStatement.Kinds.Or, RegName(i.RS()), RegName(i.RB())); or.OperandSizes = CStatement.Sizes.Long; stat = new CStatement(CStatement.Kinds.Assignment, RegName(i.RA()), or); } stat.OperandSizes = CStatement.Sizes.Long; List<CStatement> stats = new List<CStatement>(); stats.Add(stat); if (i.RC()) stats.Add(new CStatement(CStatement.Kinds.Assignment, "cr0", RegName(i.RA()))); return stats; }