public static CGCompParameters SetDefaults()
        {
            CGCompParameters Params = new CGCompParameters();

            NativeCode.GComp_SetDefaults(ref Params);
            return(Params);
        }
示例#2
0
 internal MethodCompiled(MethodBase method, MethodContext?context, CorInfo.MethodInfo corMethodInfo, CorJitResult result, IntPtr nativeAddress, int size)
 {
     NativeCode    = new NativeCode(nativeAddress, size);
     Method        = method;
     Context       = context;
     Result        = result;
     CorMethodInfo = corMethodInfo;
 }
 public static void SaveSettings(ref CGCompParameters Params)
 {
     try
     {
         NativeCode.GComp_SaveSettings(ref Params);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
示例#4
0
 internal Credential(NativeCode.NativeCredential ncred)
 {
     CredentialBlobSize = ncred.CredentialBlobSize;
     CredentialBlob = Marshal.PtrToStringUni (ncred.CredentialBlob,
      (int) ncred.CredentialBlobSize / 2);
     UserName = Marshal.PtrToStringUni (ncred.UserName);
     TargetName = Marshal.PtrToStringUni (ncred.TargetName);
     TargetAlias = Marshal.PtrToStringUni (ncred.TargetAlias);
     Type = ncred.Type;
     Flags = ncred.Flags;
     Persist = (NativeCode.Persistance) ncred.Persist;
     LastWritten = DateTime.FromFileTime ((long) ( (ulong) ncred.LastWritten.dwHighDateTime << 32 | (ulong) ncred.LastWritten.dwLowDateTime ));
 }
示例#5
0
        public override string ToString()
        {
            string ress = "Evaluation: { ";

            ress += " Result = " + Type.ToString() + ": \"" + Result + "\"";
            if (!IsOK)
            {
                ress += ", OK = Failure: { ErrorCode = " + NativeCode.ToString() + " }";
            }
            else
            {
                ress += ", OK = Success";
            }
            ress += " }";
            return(ress);
        }
        void Test()
        {
            try {
                var utils = new StringUtilities();
                var up    = upper.Caption;
                var down  = lower.Caption;

                up   = NativeCode.TestUpperCase(utils, up);
                down = NativeCode.TestLowerCase(utils, down);

                lower.Caption = down;
                upper.Caption = up;
                dvc.ReloadData();
            } catch (Exception ex) {
                upper.Caption = "Failed to test managed interop";
                lower.Caption = ex.Message;
            }
        }
示例#7
0
        protected override void Execute(MethodDef method)
        {
            var encodedBytes = IcedHelpers.ReadNativeMethodBodyBytes(method);
            var is32Bit      = !method.Module.IsAMD64;

            var block = new NativeCodeBlock(NativeCodeBlockKind.Code, (uint)method.NativeBody.RVA, new ArraySegment <byte>(encodedBytes), null);
            var vars  = new NativeVariableInfo[method.Parameters.Count];

            for (var i = 0; i < method.Parameters.Count; i++)
            {
                vars[i] = new NativeVariableInfo(false, i, method.Parameters[i].Name);
            }

            var native = new NativeCode(is32Bit ? NativeCodeKind.X86_32 : NativeCodeKind.X86_64,
                                        NativeCodeOptimization.Unknown, new[] { block }, null, vars,
                                        method.FullName, IdentifierEscaper.Escape(method.Name), method.Module.Name);

            var contentProvider = fac.Create(native, DisassemblyContentFormatterOptions.None, null, null);

            disassemblyViewerService.Value.Show(contentProvider, true);
        }
 public static bool Compile(ref CGCompParameters Params)
 {
     NativeCode.GComp_Compile(ref Params);
     return(true);
 }
 public static bool Decompile(ref CGCompParameters Params)
 {
     return(NativeCode.GComp_Decompile(ref Params) == 1);
 }
示例#10
0
 public static void ReadSettings(ref CGCompParameters Params)
 {
     NativeCode.GComp_ReadSettings(ref Params);
 }
示例#11
0
 //Wrapper
 public static string GetVersion()
 {
     return(Marshal.PtrToStringAnsi(NativeCode.GComp_GetVersion()));
 }
        private static bool PromptForCredentials(string target, NativeCode.CredentialUIInfo credUI, ref bool save, out string user, out string password, out string domain)
        {
            user = String.Empty;
            password = String.Empty;
            domain = String.Empty;



            // Setup the flags and variables
            credUI.cbSize = Marshal.SizeOf (credUI);
            int errorcode = 0;
            uint dialogReturn;
            uint authPackage = 0;

            IntPtr outCredBuffer = new IntPtr ();
            uint outCredSize;
            var flags = NativeCode.PromptForWindowsCredentialsFlags.GenericCredentials | NativeCode.PromptForWindowsCredentialsFlags.EnumerateCurrentUser;
            flags = save ? flags | NativeCode.PromptForWindowsCredentialsFlags.ShowCheckbox : flags;

            // Setup the flags and variables
            int result = NativeCode.CredUIPromptForWindowsCredentials (ref credUI,
                errorcode,
                ref authPackage,
                IntPtr.Zero,
                0,
                out outCredBuffer,
                out outCredSize,
                ref save,
                flags);

            var usernameBuf = new StringBuilder (100);
            var passwordBuf = new StringBuilder (100);
            var domainBuf = new StringBuilder (100);

            int maxUserName = 100;
            int maxDomain = 100;
            int maxPassword = 100;
            if ( result == 0 )
            {
                if ( NativeCode.CredUnPackAuthenticationBuffer (0, outCredBuffer, outCredSize, usernameBuf, ref maxUserName,
                                                   domainBuf, ref maxDomain, passwordBuf, ref maxPassword) )
                {
                    user = usernameBuf.ToString ();
                    password = passwordBuf.ToString ();
                    domain = domainBuf.ToString ();
                    if ( String.IsNullOrWhiteSpace (domain) )
                    {
                        Debug.WriteLine ("Domain null");
                        if ( !ParseUserName (usernameBuf.ToString (), maxUserName, maxDomain, out user, out password) )
                            user = usernameBuf.ToString ();
                    }
                }

                //mimic SecureZeroMem function to make sure buffer is zeroed out. SecureZeroMem is not an exported function, neither is RtlSecureZeroMemory
                var zeroBytes = new byte[outCredSize];
                Marshal.Copy (zeroBytes, 0, outCredBuffer, (int) outCredSize);

                //clear the memory allocated by CredUIPromptForWindowsCredentials 
                NativeCode.CoTaskMemFree (outCredBuffer);
                return true;
            }

            user = null;
            domain = null;
            return false;
        }
 /// <summary>
 /// Creates a <see cref="DisassemblyContentProvider"/> that can be passed to <see cref="DisassemblyViewerService.Show(DisassemblyContentProvider, string)"/>
 /// </summary>
 /// <param name="code">Native code</param>
 /// <param name="formatterOptions">Options</param>
 /// <param name="symbolResolver">Symbol resolver or null</param>
 /// <param name="header">Header comment added at the top of the document or null. This can contain multiple lines</param>
 /// <returns></returns>
 public abstract DisassemblyContentProvider Create(NativeCode code, DisassemblyContentFormatterOptions formatterOptions, ISymbolResolver symbolResolver, string header);
示例#14
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="code">Native code</param>
 /// <param name="symbolResolver">Symbol resolver or null</param>
 /// <param name="header">Header or null</param>
 public GetNativeCodeResult(NativeCode code, ISymbolResolver symbolResolver, string header)
 {
     Code           = code;
     SymbolResolver = symbolResolver;
     Header         = header;
 }
示例#15
0
        public static void Main()
        {
            Console.WriteLine("=========== Swig Default Test ===========");

            int result = NativeCode.Fact(10);

            Console.WriteLine("fact : " + result);

            int result1 = NativeCode.MyMod(2, 5);

            Console.WriteLine("my_mode : " + result1);

            Console.WriteLine("=========== Swig Array Test ===========");
            int[] source = { 1, 2, 3 };
            int[] target = new int[source.Length];

            NativeCode.MyArrayCopy(source, target, target.Length);
            Console.WriteLine("Contents of copy target array using default marshaling");
            PrintArray(target);

            target = new int[source.Length];
            NativeCode.myArrayCopyUsingFixedArrays(source, target, target.Length);
            Console.WriteLine("Contents of copy target array using fixed arrays");
            PrintArray(target);

            target = new int[] { 4, 5, 6 };
            NativeCode.MyArraySwap(source, target, target.Length);
            Console.WriteLine("Contents of arrays after swapping using default marshaling");
            PrintArray(source);
            PrintArray(target);

            source = new int[] { 1, 2, 3 };
            target = new int[] { 4, 5, 6 };

            NativeCode.myArraySwapUsingFixedArrays(source, target, target.Length);
            Console.WriteLine("Contents of arrays after swapping using fixed arrays");
            PrintArray(source);
            PrintArray(target);

            Console.WriteLine("=========== Swig Struct Test ===========");

            TestInfo info = new TestInfo();

            info.BuildingName = "shinagawa";
            info.OfficeName   = "jr office";
            info.PersionName  = "joso";

            TextClient textClient = new TextClient("http://google.com", "english", info, TestType.TESTTYPEOK);
            string     urlStr     = NativeCode.GetTestString(textClient);

            Console.WriteLine("url string : " + urlStr);
            string language = NativeCode.GetTestLang(textClient);

            Console.WriteLine("language : " + language);

            Console.WriteLine("=========== Swig function pointer ===========");
            FuncPtCallback callback = new FuncPtCallback(CallbackTest);

            NativeCode.TestExec("Called C Function pointer??", callback);

            FuncPtCallback callback1 = new FuncPtCallback(CallbackTest1);

            NativeCode.TestExec("No Problem Callback", callback1);

            FuncPtIntCallback intCallback = new FuncPtIntCallback(IntCallbackTest);

            NativeCode.SetCallback(intCallback);

            Console.WriteLine("=========== Swig struct with function pointer ===========");
            FuncPtrStructTest structPtrFuncTest = new FuncPtrStructTest();

            structPtrFuncTest.Func1       = Func1CallbackTest;
            structPtrFuncTest.Func2       = Func2CallbackTest;
            structPtrFuncTest.Func3       = Func3CallbackTest;
            structPtrFuncTest.GetFuncData = GetFuncDataCallbackTest;

            NativeCode.RegistFuncPtrStruct(structPtrFuncTest);

            NativeCode.CallStructFunc1();
            NativeCode.CallStructFunc2();
            NativeCode.CallStructFunc3();
            NativeCode.CallStructGetFuncData();

            FuncPtrTest funcPtrTest = new FuncPtrTest();

            funcPtrTest.SetFuncPtrStructTest = SetFuncPtrStructTestCallback;

            NativeCode.RegistAndCallFuncPtrs(funcPtrTest);

            Console.WriteLine("=========== Int Array Struct Test ===========");
            IntArrayStructTest intArrayStructTest = new IntArrayStructTest();

            intArrayStructTest.Test1 = new int[] { 3, 5, 7, 8, 9, 10, 14, 25, 30 };
            intArrayStructTest.Test2 = new int[] { 10, 35, 67, 89, 100 };

            Console.WriteLine("intArrayStructTest Test1 : {0}", string.Join(",", intArrayStructTest.Test1));
            Console.WriteLine("intArrayStructTest Test2 : {0}", string.Join(",", intArrayStructTest.Test2));

            Console.WriteLine("intArrayStructTest Test1[3] : {0}", intArrayStructTest.Test1[3]);
            Console.WriteLine("intArrayStructTest Test2[4] : {0}", intArrayStructTest.Test2[4]);

            string[] names = new string[] { "james", "micle", "jonson" };
            NativeCode.StringArrayTest(names, names.Length);
            Console.WriteLine("=========== Swig Test End ===========");
        }