Esempio n. 1
0
        public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
        {
            context.Asm("mov ebx, 0");
            context.Asm("call _" + Utils.MD5(instruction.Operand.ToString()));


            if (instruction.Operand is MethodDef md)
            {
                int size = !md.IsStatic ? 4 : 0; // non static always get the 'this' value are arg 0

                foreach (var parameter in md.Parameters)
                {
                    size += 4;
                    // context.Asm("pop ebx");
                }

                context.Asm("add esp, " + size);
                if (!md.ReturnType.FullName.Contains("Void"))
                {
                    context.Asm("push eax");
                }
            }
            else if (instruction.Operand is MemberRef mr)
            {
                if (!mr.ReturnType.FullName.Contains("Void"))
                {
                    context.Asm("push eax");
                }
            }
        }
Esempio n. 2
0
        public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
        {
            //fml time for vmt shit crap
            context.Asm("mov ebx, 1");
            context.Asm("call _" + Utils.MD5(instruction.Operand.ToString()));

            if (instruction.Operand is MemberRef mr)
            {
                var argsc = mr.FullName.Split('(').Last().TrimEnd(')').Split(',').Length;
                var size  = (argsc * 4);


                context.Asm("add esp, " + size);
                if (!mr.ReturnType.FullName.Contains("Void"))
                {
                    context.Asm("push eax");
                }
            }
            else if (instruction.Operand is MethodDef md)
            {
                int size = !md.IsStatic ? 4 : 0; // non static always get the 'this' value are arg 0

                foreach (var parameter in md.Parameters)
                {
                    size += 4;
                    // context.Asm("pop ebx");
                }

                context.Asm("add esp, " + size);
                if (!md.ReturnType.FullName.Contains("Void"))
                {
                    context.Asm("push eax");
                }
            }
        }
Esempio n. 3
0
 public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
 {
     context.Asm($"pop eax");      // the array
     context.Asm($"pop ebx");      // the index
     context.Asm($"add eax, ebx"); // the index
     context.Asm($"push eax");     // the index
 }
Esempio n. 4
0
        private void EmmitGlobals(IRAssembly assembly, UskrContext context)
        {
            foreach (var member in assembly.Members)
            {
                if (member.IsField && member.Static)
                {
                    context.Asm($"global _{Utils.MD5(member.Namespace)}");

                    var s = "";

                    if (member.InitValue == null)
                    {
                        context.Asm($"_{Utils.MD5(member.Namespace)}: db 0,0,0,0 ;{member.Namespace}");
                    }
                    else
                    {
                        foreach (var val in member.InitValue)
                        {
                            s += val + ",";
                        }

                        context.Asm($"{Utils.MD5(member.Namespace)} db {s.Trim().TrimEnd(',')}");
                    }
                }
            }
        }
Esempio n. 5
0
File: Add.cs Progetto: djlw78/Uskr
 public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
 {
     context.Asm("pop eax");
     context.Asm("pop ebx");
     context.Asm("add ebx, eax");
     context.Asm("push ebx");
 }
Esempio n. 6
0
 public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
 {
     context.Asm("pop ecx");             //bits
     context.Asm("pop ebx");             //val
     context.Asm($"shr ebx, cl");
     context.Asm("push ebx");
 }
Esempio n. 7
0
        public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
        {
                                    context.Asm("pop eax"); //value
                        context.Asm("pop ebx"); //adress
                        context.Asm("mov [ebx],  eax");

        }
Esempio n. 8
0
File: Div.cs Progetto: djlw78/Uskr
 public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
 {
     context.Asm("mov edx, 0");
     context.Asm("pop eax");
     context.Asm("pop ecx");
     context.Asm("div ecx");
     context.Asm("push eax");
 }
Esempio n. 9
0
 public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
 {
     //@Incomplete need to do overflow cheack
     context.Asm("pop eax");
     context.Asm("pop ebx");
     context.Asm("add ebx, eax");
     context.Asm("push ebx");
 }
Esempio n. 10
0
File: Bgt_S.cs Progetto: djlw78/Uskr
 public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
 {
     context.Asm("pop eax");
     context.Asm("pop ebx");
     context.Asm($"cmp eax, ebx");
     context.Asm(
         $"jg _{Utils.MD5(meth.Namespace)}_{(instruction.Operand as Instruction).Offset}");
 }
Esempio n. 11
0
        public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
        {
            if (meth.IsFunc)
            {
                context.Asm("pop eax");
            }

            context.Asm("leave");
            context.Asm("ret");
        }
Esempio n. 12
0
File: Stfld.cs Progetto: djlw78/Uskr
        public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
        {
            context.Asm($"pop eax"); // value
            context.Asm($"pop ebx"); // object pointer

            if (instruction.Operand is FieldDef fd)
            {
                context.Asm($"add ebx, {4 + fd.DeclaringType.Fields.IndexOf(fd) * 4}");
                context.Asm($"mov [ebx], eax");
            }
        }
Esempio n. 13
0
        public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
        {
            context.Asm($"pop eax");    //index
            context.Asm($"pop ecx");    //array
            context.Asm($"add ecx, 4"); //array

            context.Asm($"mov edx, 4"); //array

            context.Asm($"mul edx");
            context.Asm($"add ecx, eax");
            context.Asm($"mov ebx, [ecx]"); //array
            context.Asm("push ebx");
        }
Esempio n. 14
0
        public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
        {
            if (instruction.Operand is MethodDef md)
            {
                context.Asm($"push {4 + CalcMaxFields(md.DeclaringType) * 4}");
                context.Asm($"call _1EC80A85A7C365C7432628F0BD1DC116 ; call to kmalloc");
                context.Asm($"add esp, 4");
                context.Asm($"mov [eax], dword {context.VirtualTypes.IndexOf(md.DeclaringType)}"); //store in instance number
                context.Asm($"push eax");

                context.Asm($"call _{Utils.MD5(md.FullName)}");
                //dont add to esp here because we need to dup it any way`
            }
        }
Esempio n. 15
0
File: Ceq.cs Progetto: djlw78/Uskr
 public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
 {
     context.Asm("pop eax");
     context.Asm("pop ebx");
     context.Asm($"cmp eax, ebx");
     context.Asm(
         $"je _{Utils.MD5(meth.Namespace)}_{instruction.Offset}_f");
     context.Asm("push 0");
     context.Asm($"jmp _{Utils.MD5(meth.Namespace)}_{instruction.Offset}_t");
     context.Asm(
         $"_{Utils.MD5(meth.Namespace)}_{instruction.Offset}_f:");
     context.Asm("push 1");
     context.Asm(
         $"_{Utils.MD5(meth.Namespace)}_{instruction.Offset}_t:");
 }
Esempio n. 16
0
        public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
        {
            long size = 0;

            if (instruction.Operand is TypeDef td)
            {
                foreach (var field in td.Fields)
                {
                    size += field.GetFieldSize();
                }
            }


            context.Asm($"push {size}");
        }
Esempio n. 17
0
        public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
        {
            var nexti = meth.Body.Instructions.IndexOf(instruction);
            var next  = meth.Body.Instructions[nexti + 1];
            var val   = instruction.GetLdcI4Value();

            switch (next.OpCode.Code)
            {
            case Code.Conv_U:
                context.Asm($"push {(uint) val}");
                break;

            default:
                context.Asm($"push {val}");
                break;
            }
        }
Esempio n. 18
0
        public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
        {
            context.Asm($"pop edi");      // count of elements
            context.Asm($"mov eax, edi"); // count of elements


            context.Asm("mov edx, 0");
            context.Asm($"mov ecx, 4");
            context.Asm("mul ecx");
            context.Asm($"add eax, 4"); // add padding of 4 to store leng
            context.Asm("push eax");


            context.Asm($"call _1EC80A85A7C365C7432628F0BD1DC116");
            context.Asm($"sub esp, 4");
            context.Asm($"mov [eax], edi");
            context.Asm($"push eax");
        }
Esempio n. 19
0
        private void EmmitStaticIL(IRAssembly assembly, IRMethod meth, UskrContext context)
        {
            foreach (var instruction in meth.Body.Instructions)
            {
                context.Comment();
                context.Comment(instruction.ToString());

                context.Asm($"_{Utils.MD5(meth.Namespace)}_{instruction.Offset}: ");

                if (Handlers.ContainsKey(instruction.OpCode.Code))
                {
                    Handlers[instruction.OpCode.Code].Handel(assembly, meth, context, instruction);
                }
                else
                {
                    Logger.Error($"Missing Opcode Handler: {instruction}");
                }
            }
        }
Esempio n. 20
0
        public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
        {
            var bytes = "";

            foreach (var c in instruction.Operand.ToString())
            {
                bytes += ((byte)c) + ",";
            }

            bytes = bytes.Trim().TrimEnd(',');

            var key  = "_" + Utils.MD5(instruction.Operand.ToString());
            var bits = BitConverter.GetBytes(instruction.Operand.ToString().Length);

            if (!context.GlobalsExtra.ContainsKey(key))
            {
                context.GlobalsExtra.Add(key,
                                         $"{bits[0]},{bits[1]},{bits[2]},{bits[3]}" + "," +
                                         bytes);
            }
            context.Asm($"push _{Utils.MD5(instruction.Operand.ToString())}");
        }
Esempio n. 21
0
 public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
 {
     context.Asm("push 2");
 }
Esempio n. 22
0
 public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
 {
     Logger.Debug($"Not Implemented: {instruction.OpCode.Code}");
     //64nit
 }
Esempio n. 23
0
 public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
 {
     context.Asm($"pop eax");
     context.Asm($"mov [_{Utils.MD5((instruction.Operand as FieldDef).FullName)}], eax");
 }
Esempio n. 24
0
 public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
 {
     throw new Exception();                         //@need an test case to see wtf
 }
Esempio n. 25
0
 public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
 {
     context.Asm($"mov eax, [ebp-{4 + (4 * (instruction.Operand as Local).Index)}]");
     context.Asm("push eax");
 }
Esempio n. 26
0
 public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
 {
     context.Asm($"mov eax, [ebp-{4 * 2}]");
     context.Asm("push eax");
 }
Esempio n. 27
0
 public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
 {
     context.Asm("pop eax");
     context.Asm("mov [ebp-4], eax");
 }
Esempio n. 28
0
 public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
 {
     context.Asm($"push {instruction.Operand.ToString()}");
 }
Esempio n. 29
0
 public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
 {
     context.Asm($"mov eax, ebp");
     context.Asm($"sub eax, {4 * ((instruction.Operand as Local).Index + 1)}");
     context.Asm($"push eax");
 }
Esempio n. 30
0
        public void Handel(IRAssembly assembly, IRMethod meth, UskrContext context, Instruction instruction)
        {
                                    context.Asm($"mov eax, [ebp+{(meth.ParamsCount * 4) - (4 * 2) + 4}]");
                        context.Asm("push eax");

        }