Esempio n. 1
0
        public static ResourceLayout LoadSettings(string path)
        {
            var ret = new ResourceLayout();

            using (var ipModule = new RemoteDesktop_CSLibrary.Handle_Wrapper(LoadLibraryEx(path, IntPtr.Zero, LoadLibraryFlags.LOAD_LIBRARY_AS_DATAFILE)))
            {
                if (ipModule.Handle == IntPtr.Zero)
                {
                    throw new Exception("LoadLibraryEx error " + Marshal.GetLastWin32Error());
                }

                var ipResInfo = FindResource(ipModule.Handle, "#8", "#6");//Why 8 here? I dont know, it was the only RT_STRING type listed in the exe. 6 is RT_STRING type
                if (ipResInfo == IntPtr.Zero)
                {
                    throw new Exception("FindResource error " + Marshal.GetLastWin32Error());
                }

                var hResLoad = LoadResource(ipModule.Handle, ipResInfo);
                if (hResLoad == IntPtr.Zero)
                {
                    throw new Exception("LoadResource error " + Marshal.GetLastWin32Error());
                }
                var lpResLock = LockResource(hResLoad);
                if (lpResLock == IntPtr.Zero)
                {
                    throw new Exception("LockResource error " + Marshal.GetLastWin32Error());
                }
                var    dwsize = SizeofResource(ipModule.Handle, ipResInfo);
                byte[] y      = new byte[dwsize];

                Marshal.Copy(lpResLock, y, 0, (int)dwsize);

                var splits = Split(y);
                int offset = 0;

                ret.IDS_STRINGSERVICE_NAME              = splits[offset++];
                ret.IDS_STRINGSERVICE_DISPLAY_NAME      = splits[offset++];
                ret.IDS_STRINGDEFAULTPORT               = splits[offset++];
                ret.IDS_STRINGDEFAULTGATEWAY            = splits[offset++];
                ret.IDS_STRINGDEFAULTPROXYGETSESSIONURL = splits[offset++];

                ret.IDS_STRINGDISCLAIMERMESSAGE = splits[offset++];
                ret.IDS_STRINGUNIQUE_ID         = splits[offset++];
            }
            return(ret);
        }
Esempio n. 2
0
        public static byte[] Update(string path, ResourceLayout newsettings)
        {
            var tmp = Path.GetTempPath() + Path.GetFileName(path);

            File.Copy(path, tmp, true);
            var hUpdateRes = BeginUpdateResource(tmp, false);

            if (hUpdateRes == IntPtr.Zero)
            {
                throw new Exception("BeginUpdateResource error " + Marshal.GetLastWin32Error());
            }

            var ms = new MemoryStream();

            ms.Write(System.Text.Encoding.Unicode.GetBytes("\0"), 0, 2);

            Append(ms, newsettings.IDS_STRINGSERVICE_NAME);
            Append(ms, newsettings.IDS_STRINGSERVICE_DISPLAY_NAME);
            Append(ms, newsettings.IDS_STRINGDEFAULTPORT);
            Append(ms, newsettings.IDS_STRINGDEFAULTGATEWAY);
            Append(ms, newsettings.IDS_STRINGDEFAULTPROXYGETSESSIONURL);
            Append(ms, newsettings.IDS_STRINGDISCLAIMERMESSAGE);
            Append(ms, newsettings.IDS_STRINGUNIQUE_ID);


            var    b      = ms.ToArray();
            var    ciInfo = new CultureInfo("en-US");
            ushort uLcid  = (ushort)ciInfo.LCID;

            if (!UpdateResource(hUpdateRes, 6, 8, uLcid, b, (uint)b.Length))
            {
                throw new Exception("UpdateResource error " + Marshal.GetLastWin32Error());
            }
            if (!EndUpdateResource(hUpdateRes, false))
            {
                throw new Exception("EndUpdateResource error " + Marshal.GetLastWin32Error());
            }


            var data = File.ReadAllBytes(tmp);

            File.Delete(tmp);
            return(data);
        }
Esempio n. 3
0
        public static byte[] Update(string path, ResourceLayout newsettings)
        {
            var tmp = Path.GetTempPath() + Path.GetFileName(path);
            File.Copy(path, tmp, true);
            var hUpdateRes = BeginUpdateResource(tmp, false);
            if (hUpdateRes == IntPtr.Zero) throw new Exception("BeginUpdateResource error " + Marshal.GetLastWin32Error());

            var ms = new MemoryStream();
            ms.Write(System.Text.Encoding.Unicode.GetBytes("\0"), 0, 2);

            Append(ms, newsettings.IDS_STRINGSERVICE_NAME);
            Append(ms, newsettings.IDS_STRINGSERVICE_DISPLAY_NAME);
            Append(ms, newsettings.IDS_STRINGDEFAULTPORT);
            Append(ms, newsettings.IDS_STRINGDEFAULTGATEWAY);
            Append(ms, newsettings.IDS_STRINGDEFAULTPROXYGETSESSIONURL);
            Append(ms, newsettings.IDS_STRINGDISCLAIMERMESSAGE);
            Append(ms, newsettings.IDS_STRINGUNIQUE_ID);


            var b = ms.ToArray();
            var ciInfo = new CultureInfo("en-US");
            ushort uLcid = (ushort)ciInfo.LCID;
            if (!UpdateResource(hUpdateRes, 6, 8, uLcid, b, (uint)b.Length)) throw new Exception("UpdateResource error " + Marshal.GetLastWin32Error());
            if (!EndUpdateResource(hUpdateRes, false)) throw new Exception("EndUpdateResource error " + Marshal.GetLastWin32Error());


            var data = File.ReadAllBytes(tmp);
            File.Delete(tmp);
            return data;
        }
Esempio n. 4
0
        public static ResourceLayout LoadSettings(string path)
        {
            var ret = new ResourceLayout();
            using (var ipModule = new RemoteDesktop_CSLibrary.Handle_Wrapper(LoadLibraryEx(path, IntPtr.Zero, LoadLibraryFlags.LOAD_LIBRARY_AS_DATAFILE)))
            {
                if (ipModule.Handle == IntPtr.Zero) throw new Exception("LoadLibraryEx error " + Marshal.GetLastWin32Error());

                var ipResInfo = FindResource(ipModule.Handle, "#8", "#6");//Why 8 here? I dont know, it was the only RT_STRING type listed in the exe. 6 is RT_STRING type
                if (ipResInfo == IntPtr.Zero) throw new Exception("FindResource error " + Marshal.GetLastWin32Error());

                var hResLoad = LoadResource(ipModule.Handle, ipResInfo);
                if (hResLoad == IntPtr.Zero) throw new Exception("LoadResource error " + Marshal.GetLastWin32Error());
                var lpResLock = LockResource(hResLoad);
                if (lpResLock == IntPtr.Zero) throw new Exception("LockResource error " + Marshal.GetLastWin32Error());
                var dwsize = SizeofResource(ipModule.Handle, ipResInfo);
                byte[] y = new byte[dwsize];

                Marshal.Copy(lpResLock, y, 0, (int)dwsize);

                var splits = Split(y);
                int offset = 0;

                ret.IDS_STRINGSERVICE_NAME = splits[offset++];
                ret.IDS_STRINGSERVICE_DISPLAY_NAME = splits[offset++];
                ret.IDS_STRINGDEFAULTPORT = splits[offset++];
                ret.IDS_STRINGDEFAULTGATEWAY = splits[offset++];
                ret.IDS_STRINGDEFAULTPROXYGETSESSIONURL = splits[offset++];

                ret.IDS_STRINGDISCLAIMERMESSAGE = splits[offset++];
                ret.IDS_STRINGUNIQUE_ID = splits[offset++];
            }
            return ret;
        }