Beispiel #1
0
 public override int GetHashCode()
 {
     return(NativeClass.GetHashCode());
 }
 public Window(Rect rect, WindowStyle stylemask, BackingStoreType backingstore, bool defer)
 {
     NativeObject = (IntPtr)ObjCMessaging.objc_msgSend(NativeClass.ToIntPtr(), "alloc", typeof(IntPtr));
     NativeObject = (IntPtr)ObjCMessaging.objc_msgSend(NativeObject, "initWithContentRect:styleMask:backing:defer:", typeof(IntPtr), typeof(Rect), rect, typeof(int), stylemask, typeof(int), backingstore, typeof(bool), defer);
 }
Beispiel #3
0
        public static string IL2String(IReadOnlyList <ILBuffer> buffers)
        {
            StringBuilder strb = new StringBuilder(1024);

            IEnumerator <ILBuffer> iter = buffers.GetEnumerator();

            while (iter.MoveNext())
            {
                ILBuffer il = iter.Current;

                OpCode code = il.code;
                strb.Append($"IL_{il.offset:X4}: {code}");
                switch (code.OperandType)
                {
                case OperandType.InlineBrTarget:
                case OperandType.ShortInlineBrTarget:
                    strb.Append($" IL_{FindILBuffer(buffers, NativeClass.ReadMemoryValue_unsafe<int>(il.operand, 0)).offset:X4}");
                    break;

                case OperandType.InlineField:
                {
                    FieldInfo info = (FieldInfo)il.operand;
                    strb.Append($" {info.FieldType.Name.ToLower()} {info.DeclaringType.Name}::{info.Name}");
                }
                break;

                case OperandType.InlineMethod:
                {
                    if (il.operand is MethodInfo temp)
                    {
                        if (temp.IsStatic == false)
                        {
                            strb.Append($" instance");
                        }
                        strb.Append($" {temp.ReturnType.Name.ToLower()} {temp.DeclaringType.Name}::{temp.Name}()");
                    }
                    else
                    {
                        ConstructorInfo info = (ConstructorInfo)il.operand;
                        if (info.IsStatic == false)
                        {
                            strb.Append($" instance");
                        }
                        strb.Append($" void {info.DeclaringType.Name}::.ctor()");
                    }
                }
                break;

                case OperandType.InlineSig:
                {
                    if (il.operand is SignatureHelper temp)
                    {
                        strb.Append($" {temp}");
                    }
                    else
                    {
                        strb.Append($" meta_{(int)il.operand:X4}");
                    }
                }
                break;

                case OperandType.InlineString:
                    strb.Append($" \"{(string)il.operand}\"");
                    break;

                case OperandType.InlineSwitch:
                    strb.Append($" <inlineSwitch>");
                    break;

                case OperandType.InlineTok:
                {
                    if (il.operand is Type temp)
                    {
                        strb.Append($" {temp.FullName}");
                    }
                    else
                    {
                        strb.Append($" 0x{(int)il.operand:X4}");
                    }
                }
                break;

                case OperandType.InlineType:
                    strb.Append($" {((Type)il.operand).FullName}");
                    break;

                case OperandType.InlineI:
                case OperandType.InlineI8:
                case OperandType.InlineR:
                case OperandType.InlineVar:
                case OperandType.ShortInlineI:
                case OperandType.ShortInlineR:
                case OperandType.ShortInlineVar:
                    strb.Append($" {il.operand}");
                    break;

                default:
                    break;
                }
                strb.AppendLine();
            }
            iter.Dispose();

            return(strb.ToString());
        }
Beispiel #4
0
        public static void Main(string[] args)
        {
            // introduction
            Console.WriteLine(" === SuperComicLib.LowLevel === ");
            Console.WriteLine(" =========== Sample =========== ");
            Console.WriteLine(Environment.NewLine);

            // prepare
            DynamicMethod dm = new DynamicMethod(string.Empty, typeof(void), new[] { typeof(int).MakeByRefType() });
            ILGenerator   il = dm.GetILGenerator();

            // do something
            il.Emit(OpCodes.Ldarga_S, (byte)0);
            il.Emit(OpCodes.Ldind_I4, 400);
            il.Emit(OpCodes.Ret);

            Console.WriteLine(" === Before === ");

            // read memory
            BinaryStructureInfo bsi_bf = new BinaryStructureInfo(NativeClass.ReadMemory(ref il));

            {
                // read field memory
                ILGenerator2 il2_bf = bsi_bf.Read <ILGenerator2>(0);

                // check Before
                Console.WriteLine(il2_bf.ToString());

                /*
                 *  m_ILStream           : 0F 00 4A 90 01 00 00 2A
                 *  m_Length             : 8
                 *  m_MaxStackSize       : 1
                 */

                // overwrite
                il2_bf.ilstream     = new byte[32];
                il2_bf.maxStackSize = 32;
                il2_bf.length       = 1;

                // apply
                NativeClass.RefMemory(ref il, temp =>
                {
                    byte[] arr       = NativeClass.ReadMemory(ref il2_bf);
                    fixed(byte *optr = arr)
                    {
                        NativeClass.Memcpy(optr, (uint)IntPtr.Size, temp, (uint)IntPtr.Size, (uint)(arr.Length - IntPtr.Size));
                    }
                });
            }
            // dispose
            bsi_bf.Dispose();

            Console.WriteLine(Environment.NewLine);
            Console.WriteLine(" === After === ");

            // read memory
            using (BinaryStructureInfo bsi_af = new BinaryStructureInfo(NativeClass.ReadMemory(ref il)))
            {
                // read field memory
                ILGenerator2 il2_af = bsi_af.Read <ILGenerator2>(0);

                // check After
                Console.WriteLine(il2_af.ToString());

                /*
                 *  m_ILStream           : 00
                 *  m_Length             : 1
                 *  m_MaxStackSize       : 32
                 */
            } // dispose

            // wait
            Console.ReadLine();
        }
Beispiel #5
0
 public NSNumber(int initialValue)
 {
     NativeObject = ( IntPtr )ObjCMessaging.objc_msgSend(NativeClass.ToIntPtr(), "numberWithInt:", typeof(IntPtr), typeof(int), initialValue);
 }
Beispiel #6
0
 public Image(string filename)
 {
     NativeObject = (IntPtr)ObjCMessaging.objc_msgSend(NativeClass.ToIntPtr(), "alloc", typeof(IntPtr));
     NativeObject = (IntPtr)ObjCMessaging.objc_msgSend(NativeObject, "initByReferencingFile:", typeof(IntPtr), typeof(IntPtr), new Cocoa.String(filename).NativeObject);
 }
 public override bool GreatOrEquals(T left, T right) => NativeClass.ReferenceCompare(left, right) >= 0;
Beispiel #8
0
 public NativeClassDrop(NativeClass @class, object extra)
 {
     class_ = @class;
     Extra  = extra;
 }
 public override bool LessOrEquals(T left, T right) => NativeClass.CompareTo(ref left, ref right) <= 0;
 public override bool Greater(T left, T right) => NativeClass.ReferenceCompare(left, right) > 0;
 public override bool Lesser(T left, T right) => NativeClass.CompareTo(ref left, ref right) < 0;
 public override bool GreatOrEquals(T left, T right) => NativeClass.CompareTo(ref left, ref right) >= 0;
 public override bool Greater(T left, T right) => NativeClass.CompareTo(ref left, ref right) > 0;
Beispiel #14
0
 /**
  * 네이티브 라이브러리에 클래스를 추가한다.
  *
  * @param	nativeClass
  */
 public void addClass(NativeClass nativeClass)
 {
     classes.Add(nativeClass);
 }
 public override bool Lesser(T left, T right) => NativeClass.ReferenceCompare(left, right) < 0;
Beispiel #16
0
        public void initialize()
        {/*
          * if (initialized) return;
          * initialized = true;*/
            classes   = new List <NativeClass>();
            functions = new List <NativeFunction>();
            List <NativeFunction> temp = new List <NativeFunction>();
            NativeClass           number = new NativeClass("number", temp);
            NativeClass           _string = new NativeClass("string", temp);
            NativeClass           boolean = new NativeClass("bool", temp);
            NativeClass           array = new NativeClass("array", temp);
            NativeClass           _void = new NativeClass("void", temp);
            List <string>         None = new List <string>(), One = new List <string>(), Two = new List <string>();

            One.Add("number");
            Two.Add("number");
            Two.Add("number");
            List <string> temp2 = new List <string>();

            temp2.Add("*");

            NativeFunction print = new NativeFunction("print", temp2, "void");

            print.write("IVK 1");

            NativeFunction read = new NativeFunction("read", None, "string");

            read.write("IVK 2");

            NativeFunction exit = new NativeFunction("exit", None, "void");

            exit.write("END");

            NativeFunction info = new NativeFunction("info", None, "void");

            info.write("IVK 3");

            NativeFunction abs = new NativeFunction("abs", One, "number");

            abs.write("IVK 4");

            NativeFunction acos = new NativeFunction("acos", One, "number");

            acos.write("IVK 5");

            NativeFunction asin = new NativeFunction("asin", One, "number");

            asin.write("IVK 6");

            NativeFunction atan = new NativeFunction("atan", One, "number");

            atan.write("IVK 7");

            NativeFunction atan2 = new NativeFunction("atan2", Two, "number");

            atan2.write("IVK 8");

            NativeFunction ceil = new NativeFunction("ceil", One, "number");

            ceil.write("IVK 9");

            NativeFunction floor = new NativeFunction("floor", One, "number");

            floor.write("IVK 10");

            NativeFunction round = new NativeFunction("round", One, "number");

            round.write("IVK 11");

            NativeFunction cos = new NativeFunction("cos", One, "number");

            cos.write("IVK 12");

            NativeFunction sin = new NativeFunction("sin", One, "number");

            sin.write("IVK 13");

            NativeFunction tan = new NativeFunction("tan", One, "number");

            tan.write("IVK 14");

            NativeFunction log = new NativeFunction("log", One, "number");

            log.write("IVK 15");

            NativeFunction sqrt = new NativeFunction("sqrt", One, "number");

            sqrt.write("IVK 16");

            NativeFunction pow = new NativeFunction("pow", Two, "number");

            pow.write("IVK 17");

            NativeFunction random = new NativeFunction("random", None, "number");

            random.write("IVK 18");

            addClass(number);
            addClass(_string);
            addClass(array);
            addClass(boolean);
            addClass(_void);

            addFunction(print);
            addFunction(read);
            addFunction(info);
            addFunction(exit);
            addFunction(abs);
            addFunction(asin);
            addFunction(acos);
            addFunction(atan);
            addFunction(atan2);
            addFunction(ceil);
            addFunction(floor);
            addFunction(round);
            addFunction(cos);
            addFunction(sin);
            addFunction(tan);
            addFunction(log);
            addFunction(sqrt);
            addFunction(pow);
            addFunction(random);
        }
 public override bool LessOrEquals(T left, T right) => NativeClass.ReferenceCompare(left, right) <= 0;
        public Dictionary(string key, Object native_object) : base()
        {
            String s = new String(key);

            NativeObject = (IntPtr)ObjCMessaging.objc_msgSend(NativeClass.ToIntPtr(), "dictionaryWithObject:forKey:", typeof(IntPtr), typeof(IntPtr), native_object.NativeObject, typeof(IntPtr), s.NativeObject);
        }
 public override bool Greater(T?left, T?right) =>
 left.HasValue
     ? right.HasValue && NativeClass.CompareTo(left.Value, right.Value) > 0
     : right.HasValue == false;
Beispiel #20
0
 public int hash()
 {
     return(( int )ObjCMessaging.objc_msgSend(NativeClass.ToIntPtr(), "hash", typeof(int)));
 }
 public override bool LessOrEquals(T?left, T?right) =>
 left.HasValue
     ? right.HasValue && NativeClass.CompareTo(left.Value, right.Value) <= 0
     : right.HasValue == false;
 public static void Start()
 {
     NativeClass.DoSomething();
 }
 public override bool EqualsAB(T left, T right) => NativeClass.CompareTo(ref left, ref right) == 0;
Beispiel #24
0
        public override object Evaluate(Context context)
        {
            if (this.qname != null)
            {
                Type type = TypeUtilities.AsType(this.qname);

                if (type != null)
                {
                    return(type);
                }
            }

            IList <object> values = new List <object>();
            var            result = this.expression.Evaluate(context);

            if (!(result is DynamicObject))
            {
                NativeClass nclass = (NativeClass)context.GetValue("Fixnum");
                nclass = (NativeClass)nclass.MethodClass(result, null);
                Func <object, IList <object>, object> nmethod = null;

                if (nclass != null)
                {
                    nmethod = nclass.GetInstanceMethod(this.name);
                }

                if (this.arguments != null)
                {
                    foreach (var argument in this.arguments)
                    {
                        values.Add(argument.Evaluate(context));
                    }
                }

                if (nmethod == null)
                {
                    if (result is Type && this.name == "new")
                    {
                        return(Activator.CreateInstance((Type)result, values.ToArray()));
                    }

                    if (result is Type)
                    {
                        return(TypeUtilities.InvokeTypeMember((Type)result, this.name, values));
                    }

                    return(ObjectUtilities.GetValue(result, this.name, values));
                }

                return(nmethod(result, values));
            }

            var obj = (DynamicObject)result;

            foreach (var argument in this.arguments)
            {
                values.Add(argument.Evaluate(context));
            }

            var method = obj.GetMethod(this.name);

            if (method == null)
            {
                if (Predicates.IsConstantName(this.name))
                {
                    try
                    {
                        return(ObjectUtilities.GetNativeValue(obj, this.name, values));
                    }
                    catch
                    {
                    }
                }

                throw new NoMethodError(this.name);
            }

            return(method.Apply(obj, context, values));
        }
Beispiel #25
0
 public String(string init)
 {
     NativeObject = (IntPtr)ObjCMessaging.objc_msgSend(NativeClass.ToIntPtr(), "stringWithUTF8String:", typeof(IntPtr), typeof(string), init);
 }