protected override void GetBaseInfo()
        {
            LinkFile lnkfile = new LinkFile(this.Path);

            if (lnkfile.Available)
            {
                //填充名称
                if (string.IsNullOrEmpty(this.Name))
                {
                    this.Name = lnkfile.LnkInfo.Name;
                }

                //填充参数
                if (string.IsNullOrEmpty(this.Arguments))
                {
                    this.Arguments = lnkfile.LnkInfo.Arguments;
                }

                //填充工作路径
                if (!string.IsNullOrEmpty(lnkfile.LnkInfo.WorkingDirectory))
                {
                    this.SubPath = lnkfile.LnkInfo.WorkingDirectory;
                }
                else
                {
                    this.SubPath = GetSubPath(this.Path);
                }
            }
            else
            {
                //若未获取到lnk文件信息则按照普通文件处理
                base.GetBaseInfo();
            }
        }
Beispiel #2
0
        public bool DoIt(string[] args)
        {
            if (args.Length >= 2)
            {
                var mapFile = args[1];

                var linkFile = (args.Length >= 3) ? args[2] : null;

                var      map  = new MapFile(mapFile);
                LinkFile link = null;
                if (linkFile != null)
                {
                    link = new LinkFile(linkFile);
                }

                var debug_symbol_table = new HSDStruct((map.Entries.Count + 1) * 0xC);
                int symbol_index       = 0;
                foreach (var e in map.Entries)
                {
                    debug_symbol_table.SetInt32(symbol_index * 0xC, (int)e.Start);
                    debug_symbol_table.SetInt32(symbol_index * 0xC + 4, (int)e.End);

                    if (link != null && link.TryGetAddressSymbol(e.Start, out string sym))
                    {
                        debug_symbol_table.SetString(symbol_index * 0xC + 8, sym, true);
                    }
                    else
                    if (!e.Symbol.StartsWith("zz_"))
                    {
                        debug_symbol_table.SetString(symbol_index * 0xC + 8, e.Symbol, true);
                    }
                    symbol_index++;
                }

                var function = new HSDAccessor()
                {
                    _s = new HSDStruct(0x10)
                };
                function._s.SetInt32(0, map.Entries.Count);
                function._s.SetReferenceStruct(0x04, debug_symbol_table);

                HSDRawFile f = new HSDRawFile();
                f.Roots.Add(new HSDRootNode()
                {
                    Data = function,
                    Name = "mexDebug"
                });

                f.Save("MxDb.dat");


                return(true);
            }

            return(false);
        }
        public LocalPackageStorageItem(
            FileStorageFeed feed, string userName,
            PackageState packageState, PackageName packageName)
        {
            this.feed         = feed;
            this.packageState = packageState;
            this.packageName  = packageName;

            statePath           = GetStatePath(feed.Path, packageState);
            packageRelativePath = GetPackageRelativePath(packageName, "nupkg");

            linkFile      = new LinkFile(Path.Combine(statePath, GetPackageRelativePath(packageName, "txt")), LinkPathDepth);
            this.userName = userName;
        }
Beispiel #4
0
        private async void QueueContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            ContentDialogButtonClickDeferral Deferral = args.GetDeferral();

            try
            {
                if (CurrentUseProgramList.SelectedItem is ProgramPickerItem CurrentItem)
                {
                    SelectedProgram = CurrentItem;
                }
                else if (OtherProgramList.SelectedItem is ProgramPickerItem OtherItem)
                {
                    SelectedProgram = OtherItem;
                }
                else
                {
                    args.Cancel = true;
                }

                if (SelectedProgram != null && UseAsAdmin.IsChecked.GetValueOrDefault() || OpenFromPropertiesWindow)
                {
                    string ExecutablePath = SelectedProgram.Path;

                    if (Path.IsPathRooted(ExecutablePath) && Path.GetExtension(ExecutablePath).Equals(".lnk", StringComparison.OrdinalIgnoreCase))
                    {
                        if (await FileSystemStorageItemBase.OpenAsync(ExecutablePath) is LinkStorageFile LinkFile)
                        {
                            if (await LinkFile.GetRawDataAsync() is LinkDataPackage Package && !string.IsNullOrEmpty(Package.LinkTargetPath))
                            {
                                ExecutablePath = Package.LinkTargetPath;
                            }
                        }
                    }

                    SQLite.Current.SetDefaultProgramPickerRecord(OpenFile.Type, ExecutablePath);
                }
            }
            catch (Exception ex)
            {
                LogTracer.Log(ex);
            }
            finally
            {
                Deferral.Complete();
            }
        }
Beispiel #5
0
        private async void BrowserApp_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker Picker = new FileOpenPicker
            {
                SuggestedStartLocation = PickerLocationId.ComputerFolder,
                ViewMode = PickerViewMode.List
            };

            Picker.FileTypeFilter.Add(".exe");
            Picker.FileTypeFilter.Add(".lnk");

            if ((await Picker.PickSingleFileAsync()) is StorageFile ExecuteFile)
            {
                string ExecutablePath = ExecuteFile.Path;

                if (ExecuteFile.FileType.Equals(".lnk", StringComparison.OrdinalIgnoreCase))
                {
                    if (await FileSystemStorageItemBase.OpenAsync(ExecutablePath) is LinkStorageFile LinkFile)
                    {
                        if (await LinkFile.GetRawDataAsync() is LinkDataPackage Package && !string.IsNullOrEmpty(Package.LinkTargetPath))
                        {
                            ExecutablePath = Package.LinkTargetPath;
                        }
                    }
                }

                if (CurrentUseProgramList.Items.Cast <ProgramPickerItem>().Any((Item) => Item.Path.Equals(ExecutablePath, StringComparison.OrdinalIgnoreCase)))
                {
                    CurrentUseProgramList.SelectedIndex = 0;
                }
                else if (ProgramCollection.FirstOrDefault((Item) => Item.Path.Equals(ExecutablePath, StringComparison.OrdinalIgnoreCase)) is ProgramPickerItem Item)
                {
                    CurrentUseProgramList.SelectedItem = null;
                    OtherProgramList.SelectedItem      = Item;
                    OtherProgramList.ScrollIntoViewSmoothly(Item);
                }
                else if (NotRecommandList.Any((Item) => Item.Path.Equals(ExecutablePath, StringComparison.OrdinalIgnoreCase)))
                {
                    if (ShowMore.Visibility == Visibility.Visible)
                    {
                        ShowMore.Visibility        = Visibility.Collapsed;
                        OtherProgramList.MaxHeight = 300;

                        ProgramCollection.AddRange(await Task.WhenAll(NotRecommandList.Select((File) => ProgramPickerItem.CreateAsync(File))));
                    }

                    CurrentUseProgramList.SelectedItem = null;

                    if (ProgramCollection.FirstOrDefault((Item) => Item.Path.Equals(ExecutablePath, StringComparison.OrdinalIgnoreCase)) is ProgramPickerItem Item1)
                    {
                        OtherProgramList.SelectedItem = Item1;
                        OtherProgramList.ScrollIntoViewSmoothly(Item1);
                    }
                }
                else
                {
                    ProgramCollection.Add(await ProgramPickerItem.CreateAsync(ExecuteFile));
                    CurrentUseProgramList.SelectedItem = null;
                    OtherProgramList.SelectedItem      = ProgramCollection.Last();
                    OtherProgramList.ScrollIntoViewSmoothly(ProgramCollection.Last());
                }

                SQLite.Current.SetProgramPickerRecord(new AssociationPackage(OpenFile.Type, ExecutablePath, true));
            }
        }
Beispiel #6
0
        public bool DoIt(string[] args)
        {
            // Parse Args
            List <string> inputs          = new List <string>();
            LinkFile      linkFile        = new LinkFile();
            List <string> symbols         = new List <string>();
            string        output          = "";
            bool          quiet           = true;
            bool          disableWarnings = true;
            bool          clean           = true;
            int           opLevel         = 2;

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] == "-i")
                {
                    for (int j = i + 1; j < args.Length; j++)
                    {
                        if (File.Exists(args[j]))
                        {
                            inputs.Add(Path.GetFullPath(args[j]));
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                if (args[i] == "-o" && i + 1 < args.Length)
                {
                    output = Path.GetFullPath(args[i + 1]);
                }

                if (args[i] == "-s" && i + 1 < args.Length)
                {
                    for (int j = i + 1; j < args.Length; j++)
                    {
                        if (!string.IsNullOrEmpty(args[j]))
                        {
                            symbols.Add(args[j]);
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                if (args[i] == "-v")
                {
                    quiet = false;
                }
            }

            //
            if (symbols.Count <= 0)
            {
                Console.WriteLine("Error: No symbols specified");
                return(false);
            }

            // if output is null set the name to the symbol name
            if (string.IsNullOrEmpty(output))
            {
                Console.WriteLine("Error: No output path specified");
                return(false);
            }

            // load link file in mex directory
            foreach (var f in Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory))
            {
                if (Path.GetExtension(f).ToLower().Equals(".link"))
                {
                    linkFile.LoadLinkFile(f);
                }
            }

            // print instruction and exit if no input
            if ((inputs.Count == 0) ||
                args.Length == 0)
            {
                return(false);
            }

            // create output path if one isn't entered
            if (string.IsNullOrEmpty(output))
            {
                output = Path.Combine(Path.GetDirectoryName(inputs[0]), Path.GetFileName(inputs[0]).Replace(Path.GetExtension(inputs[0]), ".dat"));
            }

            // compile functions
            var elfs = Compiling.Compile(inputs.ToArray(), disableWarnings, clean, opLevel);

            var lelf = LinkELFs(elfs, linkFile, symbols.ToArray(), quiet);

            var file = BuildDatFile(lelf);

            if (file == null)
            {
                return(false);
            }

            file.Save(output);

            // create DAT file

            /*if (function != null)
             * {
             *  // save new file
             *  if (!string.IsNullOrEmpty(output))
             *  {
             *      var f = new HSDRawFile();
             *      //DatTools.InjectSymbolIntoDat(f, symbolName, function);
             *      f.Save(output);
             *      Console.WriteLine("saving " + output + "...");
             *  }
             *
             *  // We did it boys
             *  Console.WriteLine();
             *  Console.WriteLine("Sucessfully Compiled and Converted to DAT!");
             *
             *  return true;
             * }*/

            return(true);
        }
Beispiel #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public bool DoIt(string[] args)
        {
            // Parse Args
            List <Tuple <int, List <string> > > itemInputs = new List <Tuple <int, List <string> > >();
            List <string> inputs     = new List <string>();
            LinkFile      linkFile   = new LinkFile();
            string        output     = "";
            string        symbolName = "";
            string        datFile    = null;

            string[]      fightFuncTable  = null;
            string        buildPath       = null;
            bool          quiet           = true;
            bool          yesOverwrite    = false;
            bool          disableWarnings = true;
            bool          clean           = false;
            bool          debug           = false;
            int           opLevel         = 2;
            List <string> includes        = new List <string>();

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] == "-i")
                {
                    for (int j = i + 1; j < args.Length; j++)
                    {
                        if (File.Exists(args[j]))
                        {
                            inputs.Add(Path.GetFullPath(args[j]));
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                if (args[i] == "-inc")
                {
                    for (int j = i + 1; j < args.Length; j++)
                    {
                        if (Directory.Exists(args[j]))
                        {
                            includes.Add(Path.GetFullPath(args[j]));
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                if (args[i] == "-item" && i + 2 < args.Length)
                {
                    List <string> itemRefList = new List <string>();

                    for (int j = i + 2; j < args.Length; j++)
                    {
                        if (args[j] != "-item" && File.Exists(args[j]))
                        {
                            itemRefList.Add(Path.GetFullPath(args[j]));
                        }
                        else
                        {
                            break;
                        }
                    }

                    itemInputs.Add(new Tuple <int, List <string> >(int.Parse(args[i + 1]), itemRefList));
                }

                if (args[i] == "-op" && i + 1 < args.Length)
                {
                    opLevel = int.Parse(args[i + 1]);
                }

                if (args[i] == "-o" && i + 1 < args.Length)
                {
                    output = Path.GetFullPath(args[i + 1]);
                }

                if (args[i] == "-dat" && i + 1 < args.Length)
                {
                    datFile = Path.GetFullPath(args[i + 1]);
                }

                if (args[i] == "-s" && i + 1 < args.Length)
                {
                    symbolName = args[i + 1];
                }

                if (args[i] == "-ow")
                {
                    yesOverwrite = true;
                }

                if (args[i] == "-w")
                {
                    disableWarnings = false;
                }

                if (args[i] == "-d")
                {
                    debug = true;
                }

                if (args[i] == "-t" && i + 1 < args.Length)
                {
                    fightFuncTable = File.ReadAllLines(args[i + 1]);
                }

                if (args[i] == "-v")
                {
                    quiet = false;
                }

                if (args[i] == "-b" && i + 1 < args.Length)
                {
                    buildPath = Path.GetFullPath(args[i + 1]);
                }

                if (args[i] == "-l" && i + 1 < args.Length)
                {
                    linkFile.LoadLinkFile(args[i + 1]);
                }
            }

            //
            if (string.IsNullOrEmpty(symbolName))
            {
                Console.WriteLine("Error: Symbol Required; please specify a symbol Ex:\"-s ftFunction\"");
                return(false);
            }

            // if output is null set the name to the symbol name
            if (string.IsNullOrEmpty(datFile) &&
                string.IsNullOrEmpty(output) &&
                !string.IsNullOrEmpty(symbolName))
            {
                output = symbolName + ".dat";
            }

            var symbolPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, symbolName + ".txt");

            // if function table not specified attempt to get it from symbol name
            if (fightFuncTable == null &&
                !string.IsNullOrEmpty(symbolName) &&
                File.Exists(symbolPath))
            {
                fightFuncTable = File.ReadAllLines(symbolPath);
            }

            // load link file in mex directory
            foreach (var f in Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory))
            {
                if (Path.GetExtension(f).ToLower().Equals(".link"))
                {
                    linkFile.LoadLinkFile(f);
                }
            }

            // don't allow both item tables and normal tables
            if (inputs.Count > 0 && itemInputs.Count > 0)
            {
                Console.WriteLine("Only -i or -ii can be used at once, not both");
                return(false);
            }

            // print instruction and exit if no input
            if ((inputs.Count == 0 &&
                 itemInputs.Count == 0) ||
                args.Length == 0)
            {
                Console.WriteLine("No input files were given");
                return(false);
            }

            // check if symbol name is given
            if (string.IsNullOrEmpty(symbolName))
            {
                symbolName = "ftFunction";
                Console.WriteLine("No symbol name given, defaulting to \"ftFunction\"");
            }

            // create output path if one isn't entered
            if (string.IsNullOrEmpty(output) && string.IsNullOrEmpty(datFile))
            {
                output = Path.Combine(Path.GetDirectoryName(inputs[0]), Path.GetFileName(inputs[0]).Replace(Path.GetExtension(inputs[0]), ".dat"));
            }

            // check if output already exists
            if (File.Exists(output) && !yesOverwrite)
            {
                Console.WriteLine(output + " already exists, overwrite? (y/n)");
                if (Console.ReadLine().Trim().ToLower() != "y")
                {
                    return(false);
                }
            }

            // compile functions
            HSDAccessor function = null;

            // create file
            HSDRawFile      newfile    = null;
            HSDRawFile      injectfile = null;
            SBM_FighterData ftData     = null;

            // create new file
            if (!string.IsNullOrEmpty(output))
            {
                newfile = new HSDRawFile();
            }

            // inject existing dat file (or create new one if not found)
            if (!string.IsNullOrEmpty(datFile))
            {
                injectfile = File.Exists(datFile) ? new HSDRawFile(datFile) : new HSDRawFile();
            }

            // find fighter data if it exists
            if (injectfile != null && injectfile.Roots.Count > 0 && injectfile.Roots[0].Data is SBM_FighterData ftdata)
            {
                ftData = ftdata;
            }

            // static param table
            var param_table = new string[] { "param_ext" };

            // single table compile
            if (itemInputs.Count == 0)
            {
                var elfs = CompileElfs(inputs.ToArray(), disableWarnings, clean, opLevel, includes.ToArray(), buildPath, debug, quiet);

                //foreach (var f in Directory.GetFiles(@"C:\devkitPro\libogc\lib\cube"))
                //foreach (var f in Directory.GetFiles(@"C:\devkitPro\devkitPPC\powerpc-eabi\lib"))
                //{
                //    if (Path.GetExtension(f).Equals(".a"))
                //        elfs.AddRange(FighterFunction.LibArchive.GetElfs(f));
                //    if (Path.GetExtension(f).Equals(".o"))
                //        elfs.Add(new RelocELF(File.ReadAllBytes(f)));
                //}
                //elfs.AddRange(FighterFunction.LibArchive.GetElfs(@"C:\devkitPro\devkitPPC\lib\gcc\powerpc-eabi\10.2.0\libgcc.a"));
                //elfs.AddRange(FighterFunction.LibArchive.GetElfs(@"C:\Users\ploaj\Desktop\Modlee\libgc\MemCardDemo\libogc.a"));
                var lelf = GenerateLinkedElf(elfs, fightFuncTable, linkFile, quiet);

                // check for special attribute symbol
                if (ftData != null)
                {
                    foreach (var elf in elfs)
                    {
                        if (elf.SymbolEnumerator.Any(e => e.Symbol.Equals("param_ext")))
                        {
                            var special_attr = CmdGenerateDatFile.BuildDatFile(elf, param_table);

                            if (special_attr != null && special_attr.Roots.Count > 0 && special_attr["param_ext"] != null)
                            {
                                // Console.WriteLine("Found Param_Ext... adding to fighter data...");
                                ftData.Attributes2 = special_attr["param_ext"].Data;
                                break;
                            }
                        }
                    }
                }

                function = GenerateFunctionData(lelf, linkFile, fightFuncTable, quiet, debug);
            }
            else
            {
                // item table compile
                function = new HSDAccessor()
                {
                    _s = new HSDStruct(4)
                };

                int count = 0;
                foreach (var f in itemInputs)
                {
                    count = Math.Max(count, f.Item1 + 1);

                    if (4 + 4 * (f.Item1 + 1) > function._s.Length)
                    {
                        function._s.Resize(4 + 4 * (f.Item1 + 1));
                    }

                    var elfs = CompileElfs(f.Item2.ToArray(), disableWarnings, clean, opLevel, includes.ToArray(), buildPath, debug, quiet);
                    var lelf = GenerateLinkedElf(elfs, fightFuncTable, linkFile, quiet);

                    // check for special attribute symbol
                    if (ftData != null)
                    {
                        foreach (var elf in elfs)
                        {
                            if (elf.SymbolEnumerator.Any(e => e.Symbol.Equals("param_ext")))
                            {
                                var special_attr = CmdGenerateDatFile.BuildDatFile(elf, param_table);

                                if (special_attr != null && special_attr.Roots.Count > 0 && special_attr["param_ext"] != null)
                                {
                                    // Console.WriteLine("Found Param_Ext... adding to fighter data...");
                                    ftData.Articles.Articles[f.Item1].ParametersExt = special_attr["param_ext"].Data;
                                    break;
                                }
                            }
                        }
                    }

                    var relocFunc = GenerateFunctionData(lelf, linkFile, fightFuncTable, quiet, debug);
                    function._s.SetReference(4 + 0x04 * f.Item1, relocFunc);
                }
                function._s.SetInt32(0x00, count);
            }

            // inject symbol to dat file and save
            if (function != null)
            {
                if (newfile != null)
                {
                    DatTools.InjectSymbolIntoDat(newfile, symbolName, function);
                    newfile.Save(output);
                    Console.WriteLine("saving " + output + "...");
                }

                if (injectfile != null)
                {
                    DatTools.InjectSymbolIntoDat(injectfile, symbolName, function);
                    injectfile.Save(datFile);
                    Console.WriteLine("saving " + datFile + "...");
                }

                // We did it boys
                Console.WriteLine();
                Console.WriteLine("Sucessfully Compiled and Converted to DAT!");

                return(true);
            }

            return(false);
        }
Beispiel #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="input"></param>
 /// <param name="fightFuncTable"></param>
 /// <param name="quiet"></param>
 /// <returns></returns>
 private static HSDAccessor GenerateFunctionData(LinkedELF lelf, LinkFile link, string[] funcTable, bool quiet, bool debug)
 {
     return(GenerateFunctionDAT(lelf, link, funcTable, debug, quiet));
 }
Beispiel #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="input"></param>
 /// <param name="fightFuncTable"></param>
 /// <param name="quiet"></param>
 /// <returns></returns>
 private static LinkedELF GenerateLinkedElf(List <RelocELF> elfFiles, string[] funcTable, LinkFile link, bool quiet)
 {
     return(LinkELFs(elfFiles, link, funcTable, quiet));
 }