Beispiel #1
0
        public void resize(int newsize)
        {
            switch (type)
            {
            case etype.DW:
                dw   = Helper.resize(dw, newsize);
                size = newsize;
                break;

            case etype.STR:
                if (newsize < size)
                {
                    if (IsBuf)
                    {
                        str = '#' + ToHexString().Substring(0, newsize * 2) + '#';
                    }
                    else
                    {
                        str.Remove(newsize);
                    }
                    size = newsize;
                }
                break;
            }
        }
Beispiel #2
0
        public static rulong str2rul(string str, uint @base)
        {
            rulong num = 0;
            rulong charnum;

            if (@base < 2 || @base > 32)
            {
                return(0);
            }

            for (int i = 0; i < str.Length; i++)
            {
                charnum = char2rul(str[i]);
                if (charnum < 0 || charnum >= @base)
                {
                    break;
                }

                num *= @base;
                num += charnum;
            }
            return(num);

            /*
             #ifdef _WIN64
             *  return _strtoui64(string.c_str(), NULL, Base);
             #else
             *  return strtoul(string.c_str(), NULL, Base);
             #endif
             */
        }
Beispiel #3
0
        public static string rul2str(rulong x, uint @base, uint fill = 0)
        {
            StringBuilder @out = new StringBuilder();
            uint          i    = 0;

            if (@base < 2 || @base > 32)
            {
                return("");
            }
            do
            {
                @out.Insert(0, digits[(int)(x % @base)]);
                x /= @base;
                i++;
            }while (x != 0 || i < fill);

            return(@out.ToString());

            /*
             #ifdef _WIN64
             * _ui64toa(x, buffer, Base);
             #else
             * _ultoa(x, buffer, Base);
             #endif
             * string @out = buffer;
             * if(fill > @out.size())
             *  @out.insert(0, [email protected](), '0');
             * return @out;
             */
        }
Beispiel #4
0
 /// <summary>
 /// Masks off the high part of the given value.
 /// </summary>
 public static rulong resize(rulong dw, int size)
 {
     if (0 <= size && size < sizeof(ulong))
     {
         dw &= Bits.Mask(0, size * 8);
     }
     return(dw);
 }
Beispiel #5
0
 private void emu_BeforeStart(object sender, EventArgs e)
 {
     scriptInterpreter.Reset();
     scriptInterpreter.debuggee_running = false;
     OldIP = 0;
     scriptInterpreter.InitGlobalVariables();
     ScripterResume();
 }
Beispiel #6
0
 /// <summary>
 /// Masks off the high part of the given value.
 /// </summary>
 public static rulong resize(rulong dw, int byteSize)
 {
     if (0 <= byteSize && byteSize < sizeof(ulong))
     {
         dw &= Bits.Mask(0, 8 * byteSize);
     }
     return(dw);
 }
Beispiel #7
0
 public void SetBPX(rulong addr, byte type, Action SoftwareCallback)
 {
     if (type == Ue.UE_BREAKPOINT)
     {
         emu.SetBreakpoint((uint)addr, SoftwareCallback);
         return;
     }
     throw new NotImplementedException();
 }
Beispiel #8
0
        // Number manipulation

        public static rulong reverse(rulong dw)
        {
            throw new NotImplementedException();
#if LATER
            byte [] pdw = (byte *)&dw;
            reverse(pdw, pdw + sizeof(dw));
            return(dw);
#endif
        }
Beispiel #9
0
 public void SetBPX(rulong addr, byte type, Action SoftwareCallback)
 {
     if (type == Ue.UE_BREAKPOINT)
     {
         emu.SetBreakpoint((uint)addr, SoftwareCallback);
         return;
     }
     throw new NotImplementedException();
 }
Beispiel #10
0
        public static rulong round_up(rulong dw, rulong val)
        {
            rulong mod = dw % val;

            if (mod != 0)
            {
                dw += (val - mod);
            }
            return(dw);
        }
Beispiel #11
0
 public virtual Var reverse()
 {
     switch (type)
     {
     case etype.DW:
         dw = Helper.reverse(dw);
         break;
     }
     return(this);
 }
Beispiel #12
0
        public virtual Var Add(rulong rhs)
        {
            switch (type)
            {
            case etype.DW: return(Create(this.dw + rhs));

            case etype.FLT: return(Create(this.flt + rhs));
            }
            return(this);
        }
Beispiel #13
0
 public override Var Add(rulong rhs)
 {
     if (this.IsBuf) // buf + rulong -> buf
     {
         return(Var.Create("#" + this.to_bytes() + Helper.rul2hexstr(Helper.reverse(rhs), sizeof(rulong) * 2) + '#'));
     }
     else // str + rulong -> str
     {
         return(Var.Create(this.str + Helper.toupper(Helper.rul2hexstr(rhs))));
     }
 }
Beispiel #14
0
 public bool SetContextData(eContextData reg, rulong value)
 {
     switch (reg)
     {
     case eContextData.UE_EIP:
         var cAddr = Constant.Create(arch.PointerType, value);
         emu.InstructionPointer = arch.MakeAddressFromConstant(cAddr, true);
         return(true);
     }
     throw new NotImplementedException();
 }
Beispiel #15
0
        public static rulong resize(rulong dw, int size)
        {
            throw new NotImplementedException();
#if LATER
            if (size > 0 && size < sizeof(dw))
            {
                dw &= ((1 << (size * 8)) - 1);
            }
            return(dw);
#endif
        }
Beispiel #16
0
 public override Var Add(rulong rhs)
 {
     if (this.IsBuf) // buf + rulong -> buf
     {
         return(Var.Create("#" + this.ToHexString() + Helper.rul2hexstr(Helper.reverse(rhs), sizeof(rulong) * 2) + '#'));
     }
     else // str + rulong -> str
     {
         return(Var.Create(this.str + Helper.rul2hexstr(rhs).ToUpperInvariant()));
     }
 }
Beispiel #17
0
        /*
         * Design:
         *
         * ScripterResume MUST be called from within the debug loop
         * - BP callback
         * - or via plugin interface:
         + Call to ScripterAutoDebug which loads exe and calls DebugLoop and calls ScripterResume on EP
         + it will immediately return, this is needed for returning to the debug loop
         + and executing until a breakpoint/exception occurs:
         +
         + / + DebugLoop()
         + ^   + OnBP/OnException callback
         |     + OllyLang::Step()
         | ^	  [do commands until return to loop is required (RUN, STI, etc.)]
         |     -
         | ^   -
         \ -
         \
         \ When done, call FinishedCallback
         \ (if script loaded inside debug loop and not via ScripterExecuteScript)
         \ or return
         */

        // TitanEngine plugin callbacks
        void TitanDebuggingCallBack(DEBUG_EVENT debugEvent, int CallReason)
        {
            switch (CallReason)
            {
            case Ue.UE_PLUGIN_CALL_REASON_POSTDEBUG:
                break;

            case Ue.UE_PLUGIN_CALL_REASON_EXCEPTION:
                switch (debugEvent.dwDebugEventCode)
                {
                case DEBUG_EVENT.CREATE_PROCESS_DEBUG_EVENT:
                    scriptInterpreter.InitGlobalVariables();
                    break;

                case DEBUG_EVENT.EXCEPTION_DEBUG_EVENT:
                    if (scriptInterpreter.script_running)
                    {
                        rulong NewIP = debugger.GetContextData(eContextData.UE_CIP);
                        //if(debugEvent.u.Exception.ExceptionRecord.ExceptionCode == 1) // EXCEPTION_BREAKPOINT)
                        NewIP--;

                        //DBG_LOG("Exception debug event @ " + Helper.rul2hexstr(NewIP));   //$LATER

                        if (NewIP != OldIP)
                        {
                            scriptInterpreter.debuggee_running = false;
                        }

                        //$LATER
                        //if(!debugEvent.u.Exception.dwFirstChance)
                        //    ollylang.OnException();

                        OldIP = NewIP;
                    }
                    break;
                }
                break;
            }
        }
Beispiel #18
0
 public static void SetHardwareBreakPoint(rulong addr, object o, eHWBPType type, byte size, Action callback)
 {
 }
Beispiel #19
0
 public bool SetMemoryBPXEx(rulong addr, rulong size, byte p1, bool p2, Action MemoryCallback)
 {
     throw new NotImplementedException();
 }
Beispiel #20
0
 public bool SetContextData(RegisterStorage reg, rulong value)
 {
     emu.WriteRegister(reg, value);
     return(true);
 }
Beispiel #21
0
 public bool SetMemoryBPXEx(Address addr, rulong size, byte p1, bool p2, Action MemoryCallback)
 {
     throw new NotImplementedException();
 }
Beispiel #22
0
 public static rulong round_down(rulong dw, rulong val)
 {
     return (dw - (dw % val));
 }
Beispiel #23
0
        public static rulong resize(rulong dw, int size)
        {
               throw new NotImplementedException();
#if LATER
            if (size > 0 && size < sizeof(dw))
            {
                dw &= ((1 << (size * 8)) - 1);
            }
            return dw;
#endif
        }
Beispiel #24
0
 public static string rul2decstr(rulong x, uint fill = 0)
 {
     return rul2str(x, 10, fill);
 }
Beispiel #25
0
 public override Var Add(rulong rhs)
 {
     if (this.IsBuf) // buf + rulong -> buf
     {
         return Var.Create("#" + this.to_bytes() + Helper.rul2hexstr(Helper.reverse(rhs), sizeof(rulong) * 2) + '#');
     }
     else // str + rulong -> str
     {
         return Var.Create(this.str + Helper.toupper(Helper.rul2hexstr(rhs)));
     }
 }
Beispiel #26
0
 public void DeleteBPX(rulong addr)
 {
     emu.DeleteBreakpoint((uint)addr);
 }
Beispiel #27
0
 public bool SetContextData(eContextData p1, rulong p2)
 {
     throw new NotImplementedException();
 }
Beispiel #28
0
 public bool SetContextData(eContextData p1, rulong p2)
 {
     throw new NotImplementedException();
 }
Beispiel #29
0
 public Var GetJumpDestination(object p, rulong addr)
 {
     throw new NotImplementedException();
 }
Beispiel #30
0
 public void DeleteBPX(rulong addr)
 {
     emu.DeleteBreakpoint((uint)addr);
 }
Beispiel #31
0
 public static Var Create(rulong rhs)
 {
     return(new Var {
         type = etype.DW, dw = (rhs), size = 4
     });
 }
Beispiel #32
0
 public static void SetHardwareBreakPoint(rulong addr, object o, eHWBPType type, byte size, Action callback)
 {
 }
Beispiel #33
0
 public virtual Var Add(rulong rhs)
 {
     switch (type)
     {
     case etype.DW: return Create(this.dw + rhs);  
     case etype.FLT: return Create(this.flt + rhs);
     }
     return this;
 }
Beispiel #34
0
        // Number manipulation

        public static rulong reverse(rulong dw)
        {
            throw new NotImplementedException();
#if LATER
            byte [] pdw = (byte*)&dw;
            reverse(pdw, pdw + sizeof(dw));
            return dw;
#endif
        }
Beispiel #35
0
 public void resize(int newsize)
 {
     switch (type)
     {
     case etype.DW:
         dw = Helper.resize(dw, newsize);
         size = newsize;
         break;
     case etype.STR:
         if (newsize < size)
         {
             if (IsBuf)
                 str = '#' + to_bytes().Substring(0, newsize * 2) + '#';
             else
                 str.Remove(newsize);
             size = newsize;
         }
         break;
     }
 }
Beispiel #36
0
 public static rulong round_up(rulong dw, rulong val)
 {
     rulong mod = dw % val;
     if (mod != 0)
         dw += (val - mod);
     return dw;
 }
Beispiel #37
0
 public virtual Var reverse()
 {
     switch (type)
     {
     case etype.DW:
         dw = Helper.reverse(dw);
         break;
     }
     return this;
 }
Beispiel #38
0
        public static string rul2str(rulong x, uint @base, uint fill = 0)
        {
            StringBuilder @out = new StringBuilder();
            uint i = 0;

            if (@base < 2 || @base > 32)
                return "";

            do
            {
                @out.Insert(0, digits[(int)(x % @base)]);
                x /= @base;
                i++;
            }
            while (x != 0 || i < fill);

            return @out.ToString();

            /*
        #ifdef _WIN64
            _ui64toa(x, buffer, Base);
        #else
            _ultoa(x, buffer, Base);
        #endif
            string @out = buffer;
            if(fill > @out.size())
                @out.insert(0, [email protected](), '0');
            return @out;
            */
        }
Beispiel #39
0
 public static string rul2hexstr(rulong x, uint fill = 0)
 {
     return(rul2str(x, 16, fill));
 }
Beispiel #40
0
 public void RemoveMemoryBPX(Address membpaddr, rulong membpsize)
 {
     throw new NotImplementedException();
 }
Beispiel #41
0
 public void DisableBPX(rulong addr)
 {
     throw new NotImplementedException();
 }
Beispiel #42
0
        private bool DoBPHWC(string[] args)
        {
            rulong addr;

            if (args.Length >= 0 && args.Length <= 1)
            {
                if (args.Length == 0)
                {
                    return DoBPHWCA(new string[0]);
                }
                else if (GetRulong(args[0], out addr))
                {
                    rulong[] DRX = new rulong[4];

                    DRX[0] = Debugger.GetContextData(eContextData.UE_DR0);
                    DRX[1] = Debugger.GetContextData(eContextData.UE_DR1);
                    DRX[2] = Debugger.GetContextData(eContextData.UE_DR2);
                    DRX[3] = Debugger.GetContextData(eContextData.UE_DR3);
                    for (int i = 0; i < DRX.Length; i++)
                    {
                        if (DRX[i] == addr)
                        {
                            Debugger.DeleteHardwareBreakPoint(i);
                        }
                    }
                    return true;
                }
            }
            return false;
        }
Beispiel #43
0
 public void DisableBPX(rulong addr)
 {
     throw new NotImplementedException();
 }
Beispiel #44
0
 public static string rul2decstr(rulong x, uint fill = 0)
 {
     return(rul2str(x, 10, fill));
 }
Beispiel #45
0
 private void emu_BeforeStart(object sender, EventArgs e)
 {
     scriptInterpreter.Reset();
     scriptInterpreter.debuggee_running = false;
     OldIP = 0;
     scriptInterpreter.InitGlobalVariables();
     ScripterResume();
 }
Beispiel #46
0
 public void RemoveMemoryBPX(rulong membpaddr, rulong membpsize)
 {
     throw new NotImplementedException();
 }
Beispiel #47
0
        /*
        Design:

        ScripterResume MUST be called from within the debug loop
         - BP callback
         - or via plugin interface:
           + Call to ScripterAutoDebug which loads exe and calls DebugLoop and calls ScripterResume on EP
        it will immediately return, this is needed for returning to the debug loop
        and executing until a breakpoint/exception occurs:

        / + DebugLoop()
        ^   + OnBP/OnException callback
        |     + OllyLang::Step()
        ^	  [do commands until return to loop is required (RUN, STI, etc.)]
        |     -
        ^   -
        \ -

        When done, call FinishedCallback
        (if script loaded inside debug loop and not via ScripterExecuteScript)
        or return
        */

        // TitanEngine plugin callbacks
        void TitanDebuggingCallBack(DEBUG_EVENT debugEvent, int CallReason)
        {
            switch (CallReason)
            {
            case Ue.UE_PLUGIN_CALL_REASON_POSTDEBUG:
                break;
            case Ue.UE_PLUGIN_CALL_REASON_EXCEPTION:
                switch (debugEvent.dwDebugEventCode)
                {
                case DEBUG_EVENT.CREATE_PROCESS_DEBUG_EVENT:
                    scriptInterpreter.InitGlobalVariables();
                    break;
                case DEBUG_EVENT.EXCEPTION_DEBUG_EVENT:
                    if (scriptInterpreter.script_running)
                    {
                        rulong NewIP = debugger.GetContextData(eContextData.UE_CIP);
                        //if(debugEvent.u.Exception.ExceptionRecord.ExceptionCode == 1) // EXCEPTION_BREAKPOINT)
                        NewIP--;

                        //DBG_LOG("Exception debug event @ " + Helper.rul2hexstr(NewIP));   //$LATER

                        if (NewIP != OldIP)
                            scriptInterpreter.debuggee_running = false;

                        //$LATER
                        //if(!debugEvent.u.Exception.dwFirstChance)
                        //    ollylang.OnException();

                        OldIP = NewIP;
                    }
                    break;
                }
                break;
            }
        }
Beispiel #48
0
 public static rulong round_down(rulong dw, rulong val)
 {
     return(dw - (dw % val));
 }
Beispiel #49
0
 public static string rul2hexstr(rulong x, uint fill = 0)
 {
     return rul2str(x, 16, fill);
 }
Beispiel #50
0
 public static Var Create(rulong rhs) { return new Var { type = etype.DW, dw = (rhs), size = 4 }; }
Beispiel #51
0
 public Var GetJumpDestination(object p, rulong addr)
 {
     throw new NotImplementedException();
 }