-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInput.cs
executable file
·101 lines (89 loc) · 3.58 KB
/
Input.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using System.Text;
using Mono.Cecil.Cil;
using Mono.Cecil;
namespace Escan.Engine
{
public class Input : ICilNode
{
private void InitializeInput(string sClassName, MethodDefinition method, Instruction inst) {
this.sClassName = sClassName;
this.oMethod = method;
this.oInstr = inst;
}
/* Se le pasa una instruccion que esta llamando a un metodo con una de nuestras inputs
* y devuelve una instancia de MethodDefinition para poder trabajar dentro del nuevo
* metodo */
internal Input(Instruction inst, MethodDefinition method)
{
if (!OpCode.IsACallInstruction(inst) || !(inst.Operand is MethodReference))
{
throw new NotSupportedException("This case is not supported");
}
this.InitializeInput(((MethodReference)inst.Operand).DeclaringType.Name, method, inst);
}
protected Instruction oInstr;
protected MethodDefinition oMethod;
protected string sClassName;
public Instruction Instr
{
get { return this.oInstr; }
set { this.oInstr = value; }
}
public MethodDefinition Method
{
get { return this.oMethod; }
set { this.oMethod = value; }
}
public string ClassName
{
get { return this.sClassName; }
set { this.sClassName = value; }
}
//internal Input(string sClassName, MethodDefinition method, Instruction inst) {
//}
//Se le pasa un methoddefinition y un opcode y devuelve las instrucciones donde se guardan
public List<Instruction> callBy(MethodDefinition method)
{
List<Instruction> aCallers = new List<Instruction>();
if (Engine.getVar(this.Instr).OpCode.Name == "stloc.s")
{
string V_ = Convert.ToString(Engine.getVar(this.Instr).Operand);
aCallers = Engine.getldlocS(V_, method);
}
if (OpCode.IsALdargInstruction(this.Instr))
{
foreach (Instruction instruccion in method.Body.Instructions)
{
if (instruccion.OpCode == this.Instr.OpCode)
{
Console.WriteLine("Se llama desde " + Engine.detectCaller(instruccion).Operand.ToString() + " a " + Engine.getVar(this.Instr).OpCode.Name);
aCallers.Add(Engine.detectCaller(instruccion));
return aCallers;
}
}
}
else
{
foreach (Instruction instruccion in method.Body.Instructions)
{
try
{
if (instruccion.OpCode.Name == Engine.stTold(Engine.getVar(this.Instr).OpCode.Name))
{
Console.WriteLine("Se llama desde " + Engine.detectCaller(instruccion).Operand.ToString() + " a " + Engine.getVar(this.Instr).OpCode.Name);
//isNative(detectCaller(instruccion));
aCallers.Add(Engine.detectCaller(instruccion));
}
}
catch (Exception e)
{
return null;
}
}
}
return aCallers;
}
}
}