Пример #1
0
        private static void DoRunWithLEProfile(string path, LEProfile profile)
        {
            try
            {
                if (profile.RunAsAdmin && !SystemHelper.IsAdministrator())
                {
                    ElevateProcess();

                    return;
                }

                if (profile.RunWithSuspend)
                {
                    if (DialogResult.No ==
                        MessageBox.Show(
                            "You are running a exectuable with CREATE_SUSPENDED flag.\r\n" +
                            "\r\n" +
                            "The exectuable will be executed after you click the \"Yes\" button, " +
                            "But as a background process which has no notfications at all." +
                            "You can attach it by using OllyDbg, or stop it with Task Manager.\r\n",
                            "Locale Emulator Debug Mode Warning",
                            MessageBoxButtons.YesNo,
                            MessageBoxIcon.Information
                            ))
                    {
                        return;
                    }
                }

                var applicationName = string.Empty;
                var commandLine     = string.Empty;

                if (Path.GetExtension(path).ToLower() == ".exe")
                {
                    applicationName = path;

                    commandLine = path.StartsWith("\"")
                                      ? string.Format("{0} ", path)
                                      : String.Format("\"{0}\" ", path);

                    commandLine += profile.Parameter;
                }
                else
                {
                    var jb = AssociationReader.GetAssociatedProgram(Path.GetExtension(path));

                    if (jb == null)
                    {
                        return;
                    }

                    applicationName = jb[0];

                    commandLine = jb[0].StartsWith("\"")
                                      ? string.Format("{0} ", jb[0])
                                      : String.Format("\"{0}\" ", jb[0]);
                    commandLine += jb[1].Replace("%1", path).Replace("%*", profile.Parameter);
                }

                var currentDirectory = Path.GetDirectoryName(path);
                var debugMode        = profile.RunWithSuspend;
                var ansiCodePage     = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.ANSICodePage;
                var oemCodePage      = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.OEMCodePage;
                var localeID         = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.LCID;
                var defaultCharset   = (uint)
                                       GetCharsetFromANSICodepage(CultureInfo.GetCultureInfo(profile.Location)
                                                                  .TextInfo.ANSICodePage);

                var tzi          = TimeZoneInfo.FindSystemTimeZoneById(profile.Timezone);
                var timezoneBias = (int)-tzi.BaseUtcOffset.TotalMinutes;

                var adjustmentRules = tzi.GetAdjustmentRules();
                TimeZoneInfo.AdjustmentRule adjustmentRule = null;
                if (adjustmentRules.Length > 0)
                {
                    // Find the single record that encompasses today's date. If none exists, sets adjustmentRule to null.
                    adjustmentRule =
                        adjustmentRules.SingleOrDefault(ar => ar.DateStart <= DateTime.Now && DateTime.Now <= ar.DateEnd);
                }
                var timezoneDaylightBias = adjustmentRule == null ? 0 : (int)-adjustmentRule.DaylightDelta.TotalMinutes;

                var timezoneStandardName = tzi.StandardName;

                var timezoneDaylightName = tzi.DaylightName;

                var registries = profile.RedirectRegistry
                                     ? new LERegistry().GetRegistryEntries()
                                     : new LERegistryEntry[0];

                var l = new LoaderWrapper
                {
                    ApplicationName      = applicationName,
                    CommandLine          = commandLine,
                    CurrentDirectory     = currentDirectory,
                    AnsiCodePage         = ansiCodePage,
                    OemCodePage          = oemCodePage,
                    LocaleID             = localeID,
                    DefaultCharset       = defaultCharset,
                    TimezoneBias         = timezoneBias,
                    TimezoneDaylightBias = timezoneDaylightBias,
                    TimezoneStandardName = timezoneStandardName,
                    TimezoneDaylightName = timezoneDaylightName,
                    NumberOfRegistryRedirectionEntries = registries.Length,
                    DebugMode = debugMode
                };

                registries.ToList()
                .ForEach(
                    item =>
                    l.AddRegistryRedirectEntry(item.Root, item.Key, item.Name, item.Type, item.Data));

                uint ret;
                if ((ret = l.Start()) != 0)
                {
                    if (SystemHelper.IsAdministrator())
                    {
                        GlobalHelper.ShowErrorDebugMessageBox(commandLine, ret);
                    }
                    else
                    {
                        ElevateProcess();
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Пример #2
0
        private static void DoRunWithLEProfile(string path, LEProfile profile)
        {
            try
            {
                if (profile.RunAsAdmin && !SystemHelper.IsAdministrator())
                {
                    ElevateProcess();

                    return;
                }

                if (profile.RunWithSuspend)
                {
                    if (DialogResult.No ==
                        MessageBox.Show(
                                        "You are running a exectuable with CREATE_SUSPENDED flag.\r\n" +
                                        "\r\n" +
                                        "The exectuable will be executed after you click the \"Yes\" button, " +
                                        "But as a background process which has no notfications at all." +
                                        "You can attach it by using OllyDbg, or stop it with Task Manager.\r\n",
                                        "Locale Emulator Debug Mode Warning",
                                        MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Information
                            ))
                        return;
                }

                string applicationName = string.Empty;
                string commandLine = string.Empty;

                if (Path.GetExtension(path).ToLower() == ".exe")
                {
                    applicationName = path;

                    commandLine = path.StartsWith("\"")
                                      ? string.Format("{0} ", path)
                                      : String.Format("\"{0}\" ", path);

                    commandLine += profile.Parameter;
                }
                else
                {
                    string[] jb = AssociationReader.GetAssociatedProgram(Path.GetExtension(path));

                    if (jb == null)
                        return;

                    applicationName = jb[0];

                    commandLine = jb[0].StartsWith("\"")
                                      ? string.Format("{0} ", jb[0])
                                      : String.Format("\"{0}\" ", jb[0]);
                    commandLine += jb[1].Replace("%1", path).Replace("%*", profile.Parameter);
                }

                string currentDirectory = Path.GetDirectoryName(path);
                bool debugMode = profile.RunWithSuspend;
                var ansiCodePage = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.ANSICodePage;
                var oemCodePage = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.OEMCodePage;
                var localeID = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.LCID;
                var defaultCharset = (uint)
                                     GetCharsetFromANSICodepage(CultureInfo.GetCultureInfo(profile.Location)
                                                                           .TextInfo.ANSICodePage);

                TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(profile.Timezone);
                var timezoneBias = (int)-tzi.BaseUtcOffset.TotalMinutes;

                TimeZoneInfo.AdjustmentRule[] adjustmentRules = tzi.GetAdjustmentRules();
                TimeZoneInfo.AdjustmentRule adjustmentRule = null;
                if (adjustmentRules.Length > 0)
                {
                    // Find the single record that encompasses today's date. If none exists, sets adjustmentRule to null.
                    adjustmentRule =
                        adjustmentRules.SingleOrDefault(ar => ar.DateStart <= DateTime.Now && DateTime.Now <= ar.DateEnd);
                }
                int timezoneDaylightBias = adjustmentRule == null ? 0 : (int)-adjustmentRule.DaylightDelta.TotalMinutes;

                string timezoneStandardName = tzi.StandardName;

                string timezoneDaylightName = tzi.DaylightName;

                LERegistryEntry[] registries = profile.RedirectRegistry
                                                   ? new LERegistry().GetRegistryEntries()
                                                   : new LERegistryEntry[0];

                var l = new LoaderWrapper
                        {
                            ApplicationName = applicationName,
                            CommandLine = commandLine,
                            CurrentDirectory = currentDirectory,
                            AnsiCodePage = ansiCodePage,
                            OemCodePage = oemCodePage,
                            LocaleID = localeID,
                            DefaultCharset = defaultCharset,
                            TimezoneBias = timezoneBias,
                            TimezoneDaylightBias = timezoneDaylightBias,
                            TimezoneStandardName = timezoneStandardName,
                            TimezoneDaylightName = timezoneDaylightName,
                            NumberOfRegistryRedirectionEntries = registries.Length,
                            DebugMode = debugMode,
                        };

                registries.ToList()
                          .ForEach(
                                   item =>
                                   l.AddRegistryRedirectEntry(item.Root, item.Key, item.Name, item.Type, item.Data));

                uint ret;
                if ((ret = l.Start()) != 0)
                {
                    if (SystemHelper.IsAdministrator())
                    {
                        MessageBox.Show(String.Format(
                                                      "Launch failed.\r\n" +
                                                      "\r\n" +
                                                      "Commands: {0}\r\n" +
                                                      "Error Number: {1}\r\n" +
                                                      "Administrator: {2}\r\n" +
                                                      "\r\n" +
                                                      "If you have any antivirus software running, please turn it off and try again.\r\n"
                                                      +
                                                      "If you think this error is related to LE itself, feel free to submit an issue at\r\n"
                                                      +
                                                      "https://github.com/xupefei/Locale-Emulator/issues.\r\n" +
                                                      "\r\n" +
                                                      "\r\n" +
                                                      "You can press CTRL+C to copy this message to your clipboard.\r\n",
                                                      commandLine,
                                                      Convert.ToString(ret, 16).ToUpper(),
                                                      SystemHelper.IsAdministrator()
                                            ),
                                        "Locale Emulator Version " + GlobalHelper.GetLEVersion());
                    }
                    else
                    {
                        ElevateProcess();
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Пример #3
0
        private static void DoRunWithLEProfile(string path, int argumentsStart, LEProfile profile)
        {
            try
            {
                if (profile.RunAsAdmin && !SystemHelper.IsAdministrator())
                {
                    ElevateProcess();

                    return;
                }

                if (profile.RunWithSuspend)
                {
                    if (DialogResult.No ==
                        MessageBox.Show(
                                        "You are running a exectuable with CREATE_SUSPENDED flag.\r\n" +
                                        "\r\n" +
                                        "The exectuable will be executed after you click the \"Yes\" button, " +
                                        "but as a background process which has no notifications at all." +
                                        "You can attach it by using OllyDbg, or stop it with Task Manager.\r\n",
                                        "Locale Emulator Debug Mode Warning",
                                        MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Information
                            ))
                        return;
                }

                var applicationName = string.Empty;
                var commandLine = string.Empty;

                if (Path.GetExtension(path).ToLower() == ".exe")
                {
                    applicationName = path;

                    commandLine = path.StartsWith("\"")
                                      ? $"{path} "
                                      : $"\"{path}\" ";

                    // use arguments in le.config, prior to command line arguments
                    commandLine += string.IsNullOrEmpty(profile.Parameter) && Args.Skip(argumentsStart).Any()
                                       ? Args.Skip(argumentsStart).Aggregate((a, b) => $"{a} {b}")
                                       : profile.Parameter;
                }
                else
                {
                    var jb = AssociationReader.GetAssociatedProgram(Path.GetExtension(path));

                    if (jb == null)
                        return;

                    applicationName = jb[0];

                    commandLine = jb[0].StartsWith("\"")
                                      ? $"{jb[0]} "
                                      : $"\"{jb[0]}\" ";
                    commandLine += jb[1].Replace("%1", path).Replace("%*", profile.Parameter);
                }

                var currentDirectory = Path.GetDirectoryName(path);
                var ansiCodePage = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.ANSICodePage;
                var oemCodePage = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.OEMCodePage;
                var localeID = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.LCID;
                var defaultCharset = (uint)
                                     GetCharsetFromANSICodepage(CultureInfo.GetCultureInfo(profile.Location)
                                                                           .TextInfo.ANSICodePage);

                var registries = profile.RedirectRegistry
                                     ? new RegistryEntriesLoader().GetRegistryEntries(profile.IsAdvancedRedirection)
                                     : null;

                var l = new LoaderWrapper
                        {
                            ApplicationName = applicationName,
                            CommandLine = commandLine,
                            CurrentDirectory = currentDirectory,
                            AnsiCodePage = ansiCodePage,
                            OemCodePage = oemCodePage,
                            LocaleID = localeID,
                            DefaultCharset = defaultCharset,
                            HookUILanguageAPI = profile.IsAdvancedRedirection ? (uint)1 : 0,
                            Timezone = profile.Timezone,
                            NumberOfRegistryRedirectionEntries = registries?.Length ?? 0,
                            DebugMode = profile.RunWithSuspend
                };

                registries?.ToList()
                           .ForEach(
                                    item =>
                                    l.AddRegistryRedirectEntry(item.Root,
                                                               item.Key,
                                                               item.Name,
                                                               item.Type,
                                                               item.GetValue(CultureInfo.GetCultureInfo(profile.Location))));

                uint ret;
                if ((ret = l.Start()) != 0)
                {
                    if (SystemHelper.IsAdministrator())
                    {
                        GlobalHelper.ShowErrorDebugMessageBox(commandLine, ret);
                    }
                    else
                    {
                        ElevateProcess();
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Пример #4
0
        private static void DoRunWithLEProfile(string absPath, int argumentsStart, LEProfile profile)
        {
            try
            {
                if (profile.RunAsAdmin && !SystemHelper.IsAdministrator())
                {
                    ElevateProcess();

                    return;
                }

                if (profile.RunWithSuspend)
                {
                    if (DialogResult.No ==
                        MessageBox.Show(
                            "You are running a exectuable with CREATE_SUSPENDED flag.\r\n" +
                            "\r\n" +
                            "The exectuable will be executed after you click the \"Yes\" button, " +
                            "but as a background process which has no notifications at all." +
                            "You can attach it by using OllyDbg, or stop it with Task Manager.\r\n",
                            "Locale Emulator Debug Mode Warning",
                            MessageBoxButtons.YesNo,
                            MessageBoxIcon.Information
                            ))
                    {
                        return;
                    }
                }

                var applicationName = string.Empty;
                var commandLine     = string.Empty;

                if (Path.GetExtension(absPath).ToLower() == ".exe")
                {
                    applicationName = absPath;

                    commandLine = absPath.StartsWith("\"")
                        ? $"{absPath} "
                        : $"\"{absPath}\" ";

                    // use arguments in le.config, prior to command line arguments
                    commandLine += string.IsNullOrEmpty(profile.Parameter) && Args.Skip(argumentsStart).Any()
                        ? Args.Skip(argumentsStart).Aggregate((a, b) => $"{a} {b}")
                        : profile.Parameter;
                }
                else
                {
                    var jb = AssociationReader.GetAssociatedProgram(Path.GetExtension(absPath));

                    if (jb == null)
                    {
                        return;
                    }

                    applicationName = jb[0];

                    commandLine = jb[0].StartsWith("\"")
                        ? $"{jb[0]} "
                        : $"\"{jb[0]}\" ";
                    commandLine += jb[1].Replace("%1", absPath).Replace("%*", profile.Parameter);
                }

                var currentDirectory = Path.GetDirectoryName(absPath);
                var ansiCodePage     = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.ANSICodePage;
                var oemCodePage      = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.OEMCodePage;
                var localeID         = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.LCID;
                var defaultCharset   = (uint)
                                       GetCharsetFromANSICodepage(CultureInfo.GetCultureInfo(profile.Location)
                                                                  .TextInfo.ANSICodePage);

                var registries = profile.RedirectRegistry
                    ? RegistryEntriesLoader.GetRegistryEntries(profile.IsAdvancedRedirection)
                    : null;

                var l = new LoaderWrapper
                {
                    ApplicationName   = applicationName,
                    CommandLine       = commandLine,
                    CurrentDirectory  = currentDirectory,
                    AnsiCodePage      = ansiCodePage,
                    OemCodePage       = oemCodePage,
                    LocaleID          = localeID,
                    DefaultCharset    = defaultCharset,
                    HookUILanguageAPI = profile.IsAdvancedRedirection ? (uint)1 : 0,
                    Timezone          = profile.Timezone,
                    NumberOfRegistryRedirectionEntries = registries?.Length ?? 0,
                    DebugMode = profile.RunWithSuspend
                };

                registries?.ToList()
                .ForEach(
                    item =>
                    l.AddRegistryRedirectEntry(item.Root,
                                               item.Key,
                                               item.Name,
                                               item.Type,
                                               item.GetValue(CultureInfo.GetCultureInfo(profile.Location))));

                uint ret;
                if ((ret = l.Start()) != 0)
                {
                    if (SystemHelper.IsAdministrator())
                    {
                        GlobalHelper.ShowErrorDebugMessageBox(commandLine, ret);
                    }
                    else
                    {
                        ElevateProcess();
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Пример #5
0
        private static void DoRunWithLEProfile(string path, LEProfile profile)
        {
            try
            {
                if (profile.RunAsAdmin && !SystemHelper.IsAdministrator())
                {
                    ElevateProcess();

                    return;
                }

                if (profile.RunWithSuspend)
                {
                    if (DialogResult.No ==
                        MessageBox.Show(
                            "You are running a exectuable with CREATE_SUSPENDED flag.\r\n" +
                            "\r\n" +
                            "The exectuable will be executed after you click the \"Yes\" button, " +
                            "But as a background process which has no notfications at all." +
                            "You can attach it by using OllyDbg, or stop it with Task Manager.\r\n",
                            "Locale Emulator Debug Mode Warning",
                            MessageBoxButtons.YesNo,
                            MessageBoxIcon.Information
                            ))
                    {
                        return;
                    }
                }

                string applicationName = string.Empty;
                string commandLine     = string.Empty;

                if (Path.GetExtension(path).ToLower() == ".exe")
                {
                    applicationName = path;

                    commandLine = path.StartsWith("\"")
                                      ? string.Format("{0} ", path)
                                      : String.Format("\"{0}\" ", path);

                    commandLine += profile.Parameter;
                }
                else
                {
                    string[] jb = AssociationReader.GetAssociatedProgram(Path.GetExtension(path));

                    if (jb == null)
                    {
                        return;
                    }

                    applicationName = jb[0];

                    commandLine = jb[0].StartsWith("\"")
                                      ? string.Format("{0} ", jb[0])
                                      : String.Format("\"{0}\" ", jb[0]);
                    commandLine += jb[1].Replace("%1", path).Replace("%*", profile.Parameter);
                }

                string currentDirectory = Path.GetDirectoryName(path);
                bool   debugMode        = profile.RunWithSuspend;
                var    ansiCodePage     = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.ANSICodePage;
                var    oemCodePage      = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.OEMCodePage;
                var    localeID         = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.LCID;
                var    defaultCharset   = (uint)
                                          GetCharsetFromANSICodepage(CultureInfo.GetCultureInfo(profile.Location)
                                                                     .TextInfo.ANSICodePage);

                TimeZoneInfo tzi          = TimeZoneInfo.FindSystemTimeZoneById(profile.Timezone);
                var          timezoneBias = (int)-tzi.BaseUtcOffset.TotalMinutes;

                TimeZoneInfo.AdjustmentRule[] adjustmentRules = tzi.GetAdjustmentRules();
                TimeZoneInfo.AdjustmentRule   adjustmentRule  = null;
                if (adjustmentRules.Length > 0)
                {
                    // Find the single record that encompasses today's date. If none exists, sets adjustmentRule to null.
                    adjustmentRule =
                        adjustmentRules.SingleOrDefault(ar => ar.DateStart <= DateTime.Now && DateTime.Now <= ar.DateEnd);
                }
                int timezoneDaylightBias = adjustmentRule == null ? 0 : (int)-adjustmentRule.DaylightDelta.TotalMinutes;

                string timezoneStandardName = tzi.StandardName;

                string timezoneDaylightName = tzi.DaylightName;

                LERegistryEntry[] registries = profile.RedirectRegistry
                                                   ? new LERegistry().GetRegistryEntries()
                                                   : new LERegistryEntry[0];

                var l = new LoaderWrapper
                {
                    ApplicationName      = applicationName,
                    CommandLine          = commandLine,
                    CurrentDirectory     = currentDirectory,
                    AnsiCodePage         = ansiCodePage,
                    OemCodePage          = oemCodePage,
                    LocaleID             = localeID,
                    DefaultCharset       = defaultCharset,
                    TimezoneBias         = timezoneBias,
                    TimezoneDaylightBias = timezoneDaylightBias,
                    TimezoneStandardName = timezoneStandardName,
                    TimezoneDaylightName = timezoneDaylightName,
                    NumberOfRegistryRedirectionEntries = registries.Length,
                    DebugMode = debugMode,
                };

                registries.ToList()
                .ForEach(
                    item =>
                    l.AddRegistryRedirectEntry(item.Root, item.Key, item.Name, item.Type, item.Data));

                uint ret;
                if ((ret = l.Start()) != 0)
                {
                    if (SystemHelper.IsAdministrator())
                    {
                        MessageBox.Show(String.Format(
                                            "Launch failed.\r\n" +
                                            "\r\n" +
                                            "Commands: {0}\r\n" +
                                            "Error Number: {1}\r\n" +
                                            "Administrator: {2}\r\n" +
                                            "\r\n" +
                                            "If you have any antivirus software running, please turn it off and try again.\r\n"
                                            +
                                            "If you think this error is related to LE itself, feel free to submit an issue at\r\n"
                                            +
                                            "https://github.com/xupefei/Locale-Emulator/issues.\r\n" +
                                            "\r\n" +
                                            "\r\n" +
                                            "You can press CTRL+C to copy this message to your clipboard.\r\n",
                                            commandLine,
                                            Convert.ToString(ret, 16).ToUpper(),
                                            SystemHelper.IsAdministrator()
                                            ),
                                        "Locale Emulator Version " + GlobalHelper.GetLEVersion());
                    }
                    else
                    {
                        ElevateProcess();
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Пример #6
0
        private static void DoRunWithLEProfile(string path, LEProfile profile)
        {
            try
            {
                if (profile.RunAsAdmin && !SystemHelper.IsAdministrator())
                {
                    ElevateProcess();

                    return;
                }

                if (profile.RunWithSuspend)
                {
                    if (DialogResult.No ==
                        MessageBox.Show(
                                        "You are running a exectuable with CREATE_SUSPENDED flag.\r\n" +
                                        "\r\n" +
                                        "The exectuable will be executed after you click the \"Yes\" button, " +
                                        "But as a background process which has no notfications at all." +
                                        "You can attach it by using OllyDbg, or stop it with Task Manager.\r\n",
                                        "Locale Emulator Debug Mode Warning",
                                        MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Information
                            ))
                        return;
                }

                var applicationName = string.Empty;
                var commandLine = string.Empty;

                if (Path.GetExtension(path).ToLower() == ".exe")
                {
                    applicationName = path;

                    commandLine = path.StartsWith("\"")
                                      ? string.Format("{0} ", path)
                                      : String.Format("\"{0}\" ", path);

                    commandLine += profile.Parameter;
                }
                else
                {
                    var jb = AssociationReader.GetAssociatedProgram(Path.GetExtension(path));

                    if (jb == null)
                        return;

                    applicationName = jb[0];

                    commandLine = jb[0].StartsWith("\"")
                                      ? string.Format("{0} ", jb[0])
                                      : String.Format("\"{0}\" ", jb[0]);
                    commandLine += jb[1].Replace("%1", path).Replace("%*", profile.Parameter);
                }

                var currentDirectory = Path.GetDirectoryName(path);
                var debugMode = profile.RunWithSuspend;
                var ansiCodePage = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.ANSICodePage;
                var oemCodePage = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.OEMCodePage;
                var localeID = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.LCID;
                var defaultCharset = (uint)
                                     GetCharsetFromANSICodepage(CultureInfo.GetCultureInfo(profile.Location)
                                                                           .TextInfo.ANSICodePage);

                var tzi = TimeZoneInfo.FindSystemTimeZoneById(profile.Timezone);
                var timezoneBias = (int)-tzi.BaseUtcOffset.TotalMinutes;

                var adjustmentRules = tzi.GetAdjustmentRules();
                TimeZoneInfo.AdjustmentRule adjustmentRule = null;
                if (adjustmentRules.Length > 0)
                {
                    // Find the single record that encompasses today's date. If none exists, sets adjustmentRule to null.
                    adjustmentRule =
                        adjustmentRules.SingleOrDefault(ar => ar.DateStart <= DateTime.Now && DateTime.Now <= ar.DateEnd);
                }
                var timezoneDaylightBias = adjustmentRule == null ? 0 : (int)-adjustmentRule.DaylightDelta.TotalMinutes;

                var timezoneStandardName = tzi.StandardName;

                var timezoneDaylightName = tzi.DaylightName;

                var registries = profile.RedirectRegistry
                                     ? new LERegistry().GetRegistryEntries()
                                     : new LERegistryEntry[0];

                var l = new LoaderWrapper
                        {
                            ApplicationName = applicationName,
                            CommandLine = commandLine,
                            CurrentDirectory = currentDirectory,
                            AnsiCodePage = ansiCodePage,
                            OemCodePage = oemCodePage,
                            LocaleID = localeID,
                            DefaultCharset = defaultCharset,
                            TimezoneBias = timezoneBias,
                            TimezoneDaylightBias = timezoneDaylightBias,
                            TimezoneStandardName = timezoneStandardName,
                            TimezoneDaylightName = timezoneDaylightName,
                            NumberOfRegistryRedirectionEntries = registries.Length,
                            DebugMode = debugMode
                        };

                registries.ToList()
                          .ForEach(
                                   item =>
                                   l.AddRegistryRedirectEntry(item.Root, item.Key, item.Name, item.Type, item.Data));

                uint ret;
                if ((ret = l.Start()) != 0)
                {
                    if (SystemHelper.IsAdministrator())
                    {
                        GlobalHelper.ShowErrorDebugMessageBox(commandLine, ret);
                    }
                    else
                    {
                        ElevateProcess();
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Пример #7
0
        private static void DoRunWithLEProfile(string path, LEProfile profile)
        {
            try
            {
                if (profile.RunWithSuspend)
                {
                    if (DialogResult.No ==
                        MessageBox.Show(
                            "You are running a process with CREATE_SUSPEND flag.\r\nIs this really what you want?",
                            "Locale Emulator Debug Mode Warning", MessageBoxButtons.YesNo)) return;
                }

                string applicationName = string.Empty;
                string commandLine = string.Empty;

                if (Path.GetExtension(path).ToLower() == ".exe")
                {
                    applicationName = path;

                    commandLine = path.StartsWith("\"")
                                      ? string.Format("{0} ", path)
                                      : String.Format("\"{0}\" ", path);

                    commandLine += profile.Parameter;
                }
                else
                {
                    string[] jb = AssociationReader.GetAssociatedProgram(Path.GetExtension(path));

                    if (jb == null)
                        return;

                    applicationName = jb[0];

                    commandLine = jb[0].StartsWith("\"")
                                      ? string.Format("{0} ", jb[0])
                                      : String.Format("\"{0}\" ", jb[0]);
                    commandLine += jb[1].Replace("%1", path).Replace("%*", profile.Parameter);
                }

                string currentDirectory = Path.GetDirectoryName(path);
                bool debugMode = profile.RunWithSuspend;
                var ansiCodePage = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.ANSICodePage;
                var oemCodePage = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.OEMCodePage;
                var localeID = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.LCID;
                var defaultCharset = (uint)
                                     GetCharsetFromANSICodepage(
                                         CultureInfo.GetCultureInfo(profile.Location).TextInfo.ANSICodePage);
                string defaultFaceName = profile.DefaultFont;

                TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(profile.Timezone);
                var timezoneBias = (int)-tzi.BaseUtcOffset.TotalMinutes;

                TimeZoneInfo.AdjustmentRule[] adjustmentRules = tzi.GetAdjustmentRules();
                TimeZoneInfo.AdjustmentRule adjustmentRule = null;
                if (adjustmentRules.Length > 0)
                {
                    // Find the single record that encompasses today's date. If none exists, sets adjustmentRule to null.
                    adjustmentRule =
                        adjustmentRules.SingleOrDefault(ar => ar.DateStart <= DateTime.Now && DateTime.Now <= ar.DateEnd);
                }
                int timezoneDaylightBias = adjustmentRule == null ? 0 : (int)-adjustmentRule.DaylightDelta.TotalMinutes;

                string timezoneStandardName = tzi.StandardName;

                string timezoneDaylightName = tzi.DaylightName;

                var l = new LoaderWrapper
                    {
                        ApplicationName = applicationName,
                        CommandLine = commandLine,
                        CurrentDirectory = currentDirectory,
                        AnsiCodePage = ansiCodePage,
                        OemCodePage = oemCodePage,
                        LocaleID = localeID,
                        DefaultCharset = defaultCharset,
                        DefaultFaceName = defaultFaceName,
                        TimezoneBias = timezoneBias,
                        TimezoneDaylightBias = timezoneDaylightBias,
                        TimezoneStandardName = timezoneStandardName,
                        TimezoneDaylightName = timezoneDaylightName,
                        DebugMode = debugMode,
                    };

                uint ret;
                if ((ret = l.Start()) != 0)
                {
                    if (IsAdministrator())
                    {
                        MessageBox.Show(
                            String.Format(
                                "Error number {0} detected.\r\n\r\nThis may because the target executable is a 64-bit binary which is not supported by the current version of Locale Emulator.",
                                Convert.ToString(ret, 16).ToUpper()),
                            "Locale Emulator");
                    }
                    else
                    {
                        RunWithElevatedProcess(Args);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Пример #8
0
        private static void Main(string[] args)
        {
            if (!(DLLExists("LoaderDll.dll") && DLLExists("LocaleEmulator.dll")))
            {
                MessageBox.Show(
                    "Some of the core Dlls are missing.\r\n" +
                    "\r\n" +
                    "These Dlls are:\r\n" +
                    "LoaderDll.dll\r\n" +
                    "LocaleEmulator.dll",
                    "LEProc",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                Environment.Exit(1);
            }

            if (args.Length == 0)
            {
                MessageBox.Show("Usage: LEProc.exe path [args]", "LEProc");
                Environment.Exit(1);
            }

            var path = EnsureValidPath(args[0]);

            if (path == null)
            {
                MessageBox.Show(args[0] + ": No such file or directory",
                                "LEProc",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                Environment.Exit(1);
            }

            string commandLine = "\"" + path + "\"";

            if (args.Length > 1)
            {
                args[0]     = commandLine;
                commandLine = String.Join(" ", args);
            }

            // var cultureInfo = CultureInfo.GetCultureInfo("ja-JP");
            // var textInfo = cultureInfo.TextInfo;

            var registries = new[]
            {
                new string[] { "HKEY_LOCAL_MACHINE", @"System\CurrentControlSet\Control\Nls\CodePage", "InstallLanguage", "REG_SZ", "1041" },
                new string[] { "HKEY_LOCAL_MACHINE", @"System\CurrentControlSet\Control\Nls\CodePage", "Default", "REG_SZ", "1041" },
                new string[] { "HKEY_LOCAL_MACHINE", @"System\CurrentControlSet\Control\Nls\CodePage", "OEMCP", "REG_SZ", "932" },
                new string[] { "HKEY_LOCAL_MACHINE", @"System\CurrentControlSet\Control\Nls\CodePage", "ACP", "REG_SZ", "932" }
#if ADVANCED_REDIRECTION
                ,
                new string[] { "HKEY_CURRENT_USER", @"Control Panel\International", "Locale", "REG_SZ", "00000411" },
                new string[] { "HKEY_CURRENT_USER", @"Control Panel\International", "LocaleName", "REG_SZ", "ja-JP" },
                new string[] { "HKEY_CURRENT_USER", @"Control Panel\Desktop", "PreferredUILanguages", "REG_MULTI_SZ", "ja-JP" },
                new string[] { "HKEY_CURRENT_USER", @"Control Panel\Desktop\MuiCached", "MachinePreferredUILanguages", "REG_MULTI_SZ", "ja-JP" }
#endif
            };

            // Use default value
            var l = new LoaderWrapper(path, commandLine, Environment.CurrentDirectory)
            {
                // AnsiCodePage = (uint)textInfo.ANSICodePage,
                // OemCodePage = (uint)textInfo.OEMCodePage,
                // LocaleID = (uint)textInfo.LCID,
                // DefaultCharset = 128,  // SHIFT-JIS
#if ADVANCED_REDIRECTION
                HookUILanguageAPI = 1,
#else
                // HookUILanguageAPI = 0,
#endif
                // Timezone = "Tokyo Standard Time",
                NumberOfRegistryRedirectionEntries = registries.Length,
                DebugMode = false
            };

            foreach (var item in registries)
            {
                l.AddRegistryRedirectEntry(
                    item[0],
                    item[1],
                    item[2],
                    item[3],
                    item[4]);
            }

            uint ret = l.Start();

            if (ret != 0)
            {
                MessageBox.Show(
                    $"Error: 0x{ret:X8}\r\n" +
                    "Command: " + commandLine,
                    "LEProc");
                Environment.Exit((int)ret);
            }
        }
Пример #9
0
        private static void DoRunWithLEProfile(string path, LEProfile profile)
        {
            try
            {
                if (profile.RunWithSuspend)
                {
                    if (DialogResult.No ==
                        MessageBox.Show(
                            "You are running a process with CREATE_SUSPEND flag.\r\nIs this really what you want?",
                            "Locale Emulator Debug Mode Warning", MessageBoxButtons.YesNo)) return;
                }

                string applicationName = string.Empty;
                string commandLine = string.Empty;

                if (Path.GetExtension(path).ToLower() == ".exe")
                {
                    applicationName = path;

                    commandLine = path.StartsWith("\"")
                                      ? string.Format("{0} ", path)
                                      : String.Format("\"{0}\" ", path);

                    commandLine += profile.Parameter;
                }
                else
                {
                    string[] jb = AssociationReader.GetAssociatedProgram(Path.GetExtension(path));

                    if (jb == null)
                        return;

                    applicationName = jb[0];

                    commandLine = jb[0].StartsWith("\"")
                                      ? string.Format("{0} ", jb[0])
                                      : String.Format("\"{0}\" ", jb[0]);
                    commandLine += jb[1].Replace("%1", path).Replace("%*", profile.Parameter);
                }

                string currentDirectory = Path.GetDirectoryName(path);
                bool debugMode = profile.RunWithSuspend;
                var ansiCodePage = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.ANSICodePage;
                var oemCodePage = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.OEMCodePage;
                var localeID = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.LCID;
                var defaultCharset = (uint)
                                     GetCharsetFromANSICodepage(
                                         CultureInfo.GetCultureInfo(profile.Location).TextInfo.ANSICodePage);
                string defaultFaceName = profile.DefaultFont;

                TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(profile.Timezone);
                var timezoneBias = (int)-tzi.BaseUtcOffset.TotalMinutes;

                TimeZoneInfo.AdjustmentRule[] adjustmentRules = tzi.GetAdjustmentRules();
                TimeZoneInfo.AdjustmentRule adjustmentRule = null;
                if (adjustmentRules.Length > 0)
                {
                    // Find the single record that encompasses today's date. If none exists, sets adjustmentRule to null.
                    adjustmentRule =
                        adjustmentRules.SingleOrDefault(ar => ar.DateStart <= DateTime.Now && DateTime.Now <= ar.DateEnd);
                }
                int timezoneDaylightBias = adjustmentRule == null ? 0 : (int)-adjustmentRule.DaylightDelta.TotalMinutes;

                string timezoneStandardName = tzi.StandardName;

                string timezoneDaylightName = tzi.DaylightName;

                var l = new LoaderWrapper
                    {
                        ApplicationName = applicationName,
                        CommandLine = commandLine,
                        CurrentDirectory = currentDirectory,
                        AnsiCodePage = ansiCodePage,
                        OemCodePage = oemCodePage,
                        LocaleID = localeID,
                        DefaultCharset = defaultCharset,
                        DefaultFaceName = defaultFaceName,
                        TimezoneBias = timezoneBias,
                        TimezoneDaylightBias = timezoneDaylightBias,
                        TimezoneStandardName = timezoneStandardName,
                        TimezoneDaylightName = timezoneDaylightName,
                        DebugMode = debugMode,
                    };

                uint ret;
                if ((ret = l.Start()) != 0)
                {
                    if (IsAdministrator())
                    {
                        MessageBox.Show(
                            String.Format(
                                "Error number {0} detected.\r\n\r\nThis may because the target executable is a 64-bit binary which is not supported by the current version of Locale Emulator.",
                                Convert.ToString(ret, 16).ToUpper()),
                            "Locale Emulator");
                    }
                    else
                    {
                        RunWithElevatedProcess(Args);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }