Example #1
0
 private Address LoadAddress(UserData_v4 user, IProcessorArchitecture arch)
 {
     if (user == null || arch == null || user.LoadAddress == null)
         return null;
     if (!arch.TryParseAddress(user.LoadAddress, out Address addr))
         return null;
     return addr;
 }
Example #2
0
 private Address LoadAddress(UserData_v4 user, IProcessorArchitecture arch)
 {
     if (user == null || arch == null || user.LoadAddress == null)
     {
         return(null);
     }
     if (!arch.TryParseAddress(user.LoadAddress, out Address addr))
     {
         return(null);
     }
     return(addr);
 }
Example #3
0
 public void LoadUserData(UserData_v4 sUser, Program program, UserData user, string projectFilePath)
 {
     if (sUser == null)
         return;
     user.OnLoadedScript = sUser.OnLoadedScript;
     if (sUser.Processor != null)
     {
         user.Processor = sUser.Processor.Name;
         if (program.Architecture == null && !string.IsNullOrEmpty(user.Processor))
         {
             program.Architecture = Services.RequireService<IConfigurationService>().GetArchitecture(user.Processor!)!;
         }
         //$BUG: what if architecture isn't supported? fail the whole thing?
         program.Architecture!.LoadUserOptions(XmlOptions.LoadIntoDictionary(sUser.Processor.Options, StringComparer.OrdinalIgnoreCase));
     }
     if (sUser.PlatformOptions != null)
     {
         user.Environment = sUser.PlatformOptions.Name;
         program.Platform.LoadUserOptions(XmlOptions.LoadIntoDictionary(sUser.PlatformOptions.Options, StringComparer.OrdinalIgnoreCase));
     }
     if (sUser.Procedures != null)
     {
         user.Procedures = sUser.Procedures
             .Select(sup => LoadUserProcedure_v1(program, sup))
             .Where(kv => !(kv.Key is null))
             .ToSortedList(kv => kv.Key, kv => kv.Value);
         user.ProcedureSourceFiles = user.Procedures
             .Where(kv => !string.IsNullOrEmpty(kv.Value.OutputFile))
             .ToDictionary(kv => kv.Key!, kv => ConvertToAbsolutePath(projectFilePath, kv.Value.OutputFile)!);
     }
     if (sUser.GlobalData != null)
     {
         user.Globals = sUser.GlobalData
             .Select(sud =>
             {
                 program.Architecture.TryParseAddress(sud.Address, out Address addr);
                 return new KeyValuePair<Address, GlobalDataItem_v2>(
                     addr,
                     sud);
             })
             .Where(kv => !(kv.Key is null))
            .ToSortedList(kv => kv.Key, kv => kv.Value);
     }
   
     if (sUser.Annotations != null)
     {
         user.Annotations = new AnnotationList(sUser.Annotations
             .Select(LoadAnnotation)
             .Where(a => !(a.Address is null))
             .ToList());
     }
     if (sUser.Heuristics != null)
     {
         user.Heuristics.UnionWith(sUser.Heuristics
             .Where(h => !(h.Name is null))
             .Select(h => h.Name!));
     }
     if (sUser.TextEncoding != null)
     {
         Encoding enc = null;
         try
         {
             enc = Encoding.GetEncoding(sUser.TextEncoding);
         }
         catch
         {
             listener.Warn(
                 "Unknown text encoding '{0}'. Defaulting to platform text encoding.", 
                 sUser.TextEncoding);
         }
         user.TextEncoding = enc;
     }
     program.EnvironmentMetadata = project.LoadedMetadata;
     if (sUser.Calls != null)
     {
         program.User.Calls = sUser.Calls
             .Select(c => LoadUserCall(c, program))
             .Where(c => c != null && !(c.Address is null))
             .ToSortedList(k => k!.Address!, v => v!);
     }
     if (sUser.RegisterValues != null)
     {
         program.User.RegisterValues = LoadRegisterValues(sUser.RegisterValues);
     }
     if (sUser.JumpTables != null)
     {
         program.User.JumpTables = sUser.JumpTables.Select(LoadJumpTable_v4)
             .Where(t => t != null && t.Address != null)
             .ToSortedList(k => k!.Address, v => v);
     }
     if (sUser.IndirectJumps != null)
     {
         program.User.IndirectJumps = sUser.IndirectJumps
             .Select(ij => LoadIndirectJump_v4(ij, program))
             .Where(ij => ij.Item1 != null)
             .ToSortedList(k => k!.Item1, v => v!.Item2);
     }
     if (sUser.Segments != null)
     {
         program.User.Segments = sUser.Segments
             .Select(s => LoadUserSegment_v4(s))
             .Where(s => s != null)
             .ToList();
     }
     program.User.ShowAddressesInDisassembly = sUser.ShowAddressesInDisassembly;
     program.User.ShowBytesInDisassembly = sUser.ShowBytesInDisassembly;
     program.User.ExtractResources = sUser.ExtractResources;
     // Backwards compatibility: older versions used single file policy.
     program.User.OutputFilePolicy = sUser.OutputFilePolicy ?? Program.SingleFilePolicy;
     program.User.AggressiveBranchRemoval = sUser.AggressiveBranchRemoval;
 }
Example #4
0
        /// <summary>
        /// Loads the user-specified data.
        /// </summary>
        /// <param name="sUser"></param>
        /// <param name="program"></param>
        /// <param name="user"></param>
        public void LoadUserData(UserData_v4 sUser, Program program, UserData user, string projectFilePath)
        {
            if (sUser == null)
            {
                return;
            }
            user.OnLoadedScript = sUser.OnLoadedScript;
            if (sUser.Processor != null)
            {
                user.Processor = sUser.Processor.Name;
                if (program.Architecture == null && !string.IsNullOrEmpty(user.Processor))
                {
                    program.Architecture = Services.RequireService <IConfigurationService>().GetArchitecture(user.Processor);
                }
                program.Architecture.LoadUserOptions(XmlOptions.LoadIntoDictionary(sUser.Processor.Options, StringComparer.OrdinalIgnoreCase));
            }
            if (sUser.PlatformOptions != null)
            {
                user.Environment = sUser.PlatformOptions.Name;
                program.Platform.LoadUserOptions(XmlOptions.LoadIntoDictionary(sUser.PlatformOptions.Options, StringComparer.OrdinalIgnoreCase));
            }
            if (sUser.Procedures != null)
            {
                user.Procedures = sUser.Procedures
                                  .Select(sup => LoadUserProcedure_v1(program, sup))
                                  .Where(kv => kv.Key != null)
                                  .ToSortedList(kv => kv.Key, kv => kv.Value);
                user.ProcedureSourceFiles = user.Procedures
                                            .Where(kv => !string.IsNullOrEmpty(kv.Value.OutputFile))
                                            .ToDictionary(kv => kv.Key, kv => ConvertToAbsolutePath(projectFilePath, kv.Value.OutputFile));
            }
            if (sUser.GlobalData != null)
            {
                user.Globals = sUser.GlobalData
                               .Select(sud =>
                {
                    program.Architecture.TryParseAddress(sud.Address, out Address addr);
                    return(new KeyValuePair <Address, GlobalDataItem_v2>(
                               addr,
                               sud));
                })
                               .Where(kv => kv.Key != null)
                               .ToSortedList(kv => kv.Key, kv => kv.Value);
            }

            if (sUser.Annotations != null)
            {
                user.Annotations = new AnnotationList(sUser.Annotations
                                                      .Select(LoadAnnotation)
                                                      .Where(a => a.Address != null)
                                                      .ToList());
            }
            if (sUser.Heuristics != null)
            {
                user.Heuristics.UnionWith(sUser.Heuristics.Select(h => h.Name));
            }
            if (sUser.TextEncoding != null)
            {
                Encoding enc = null;
                try
                {
                    enc = Encoding.GetEncoding(sUser.TextEncoding);
                }
                catch
                {
                    var diagSvc = Services.RequireService <IDiagnosticsService>();
                    diagSvc.Warn(
                        "Unknown text encoding '{0}'. Defaulting to platform text encoding.",
                        sUser.TextEncoding);
                }
                user.TextEncoding = enc;
            }
            program.EnvironmentMetadata = project.LoadedMetadata;
            if (sUser.Calls != null)
            {
                program.User.Calls = sUser.Calls
                                     .Select(c => LoadUserCall(c, program))
                                     .Where(c => c != null)
                                     .ToSortedList(k => k.Address, v => v);
            }
            if (sUser.RegisterValues != null)
            {
                program.User.RegisterValues = LoadRegisterValues(sUser.RegisterValues);
            }
            if (sUser.JumpTables != null)
            {
                program.User.JumpTables = sUser.JumpTables.Select(LoadJumpTable_v4)
                                          .Where(t => t != null)
                                          .ToSortedList(k => k.Address, v => v);
            }
            if (sUser.IndirectJumps != null)
            {
                program.User.IndirectJumps = sUser.IndirectJumps
                                             .Select(ij => LoadIndirectJump_v4(ij, program))
                                             .Where(ij => ij != null)
                                             .ToSortedList(k => k.Item1, v => v.Item2);
            }
            if (sUser.Segments != null)
            {
                program.User.Segments = sUser.Segments
                                        .Select(s => LoadUserSegment_v4(s))
                                        .Where(s => s != null)
                                        .ToList();
            }
            program.User.ShowAddressesInDisassembly = sUser.ShowAddressesInDisassembly;
            program.User.ShowBytesInDisassembly     = sUser.ShowBytesInDisassembly;
            program.User.ExtractResources           = sUser.ExtractResources;
        }
Example #5
0
 public DecompilerInput_v5()
 {
     User = new UserData_v4();
 }
Example #6
0
        public void LoadUserData(UserData_v4 sUser, Program program, UserData user)
        {
            if (sUser == null)
            {
                return;
            }
            user.OnLoadedScript = sUser.OnLoadedScript;
            if (sUser.Processor != null)
            {
                program.User.Processor = sUser.Processor.Name;
                if (program.Architecture == null && !string.IsNullOrEmpty(program.User.Processor))
                {
                    program.Architecture = Services.RequireService <IConfigurationService>().GetArchitecture(program.User.Processor);
                }
                program.Architecture.LoadUserOptions(XmlOptions.LoadIntoDictionary(sUser.Processor.Options));
            }
            if (sUser.Procedures != null)
            {
                user.Procedures = sUser.Procedures
                                  .Select(sup => LoadUserProcedure_v1(program, sup))
                                  .Where(kv => kv.Key != null)
                                  .ToSortedList(kv => kv.Key, kv => kv.Value);
            }

            if (sUser.PlatformOptions != null)
            {
                program.User.Environment = sUser.PlatformOptions.Name;
                program.Platform.LoadUserOptions(XmlOptions.LoadIntoDictionary(sUser.PlatformOptions.Options));
            }
            if (sUser.GlobalData != null)
            {
                user.Globals = sUser.GlobalData
                               .Select(sud =>
                {
                    Address addr;
                    program.Architecture.TryParseAddress(sud.Address, out addr);
                    return(new KeyValuePair <Address, GlobalDataItem_v2>(
                               addr,
                               sud));
                })
                               .Where(kv => kv.Key != null)
                               .ToSortedList(kv => kv.Key, kv => kv.Value);
            }

            if (sUser.Heuristics != null)
            {
                user.Heuristics.UnionWith(sUser.Heuristics.Select(h => h.Name));
            }
            if (sUser.TextEncoding != null)
            {
                Encoding enc = null;
                try
                {
                    enc = Encoding.GetEncoding(sUser.TextEncoding);
                } catch
                {
                    var diagSvc = Services.RequireService <IDiagnosticsService>();
                    diagSvc.Warn(
                        "Unknown text encoding '{0}'. Defaulting to platform text encoding.",
                        sUser.TextEncoding);
                }
                user.TextEncoding = enc;
            }
            program.EnvironmentMetadata = project.LoadedMetadata;
            if (sUser.Calls != null)
            {
                program.User.Calls = sUser.Calls
                                     .Select(c => LoadUserCall(c, program))
                                     .Where(c => c != null)
                                     .ToSortedList(k => k.Address, v => v);
            }
            if (sUser.RegisterValues != null)
            {
                program.User.RegisterValues = LoadRegisterValues(sUser.RegisterValues);
            }
            if (sUser.JumpTables != null)
            {
                program.User.JumpTables = sUser.JumpTables.Select(LoadJumpTable_v4)
                                          .Where(t => t != null)
                                          .ToSortedList(k => k.Address, v => v);
            }
            if (user.IndirectJumps != null)
            {
                program.User.IndirectJumps = sUser.IndirectJumps
                                             .Select(ij => LoadIndirectJump_v4(ij, program))
                                             .Where(ij => ij != null)
                                             .ToSortedList(k => k.Item1, v => v.Item2);
            }
        }
Example #7
0
        public void LoadUserData(UserData_v4 sUser, Program program, UserData user)
        {
            if (sUser == null)
            {
                return;
            }
            user.OnLoadedScript = sUser.OnLoadedScript;
            if (sUser.Processor != null)
            {
                program.User.Processor = sUser.Processor.Name;
                if (program.Architecture == null && !string.IsNullOrEmpty(program.User.Processor))
                {
                    program.Architecture = Services.RequireService <IConfigurationService>().GetArchitecture(program.User.Processor);
                }
                program.Architecture.LoadUserOptions(LoadWeaklyTypedOptions(sUser.Processor.Options));
            }
            if (sUser.Procedures != null)
            {
                user.Procedures = sUser.Procedures
                                  .Select(sup =>
                {
                    Address addr;
                    program.Architecture.TryParseAddress(sup.Address, out addr);
                    return(new KeyValuePair <Address, Procedure_v1>(addr, sup));
                })
                                  .Where(kv => kv.Key != null)
                                  .ToSortedList(kv => kv.Key, kv => kv.Value);
            }

            if (sUser.PlatformOptions != null)
            {
                program.User.Environment = sUser.PlatformOptions.Name;
                program.Platform.LoadUserOptions(LoadWeaklyTypedOptions(sUser.PlatformOptions.Options));
            }
            if (sUser.GlobalData != null)
            {
                user.Globals = sUser.GlobalData
                               .Select(sud =>
                {
                    Address addr;
                    program.Architecture.TryParseAddress(sud.Address, out addr);
                    return(new KeyValuePair <Address, GlobalDataItem_v2>(
                               addr,
                               sud));
                })
                               .Where(kv => kv.Key != null)
                               .ToSortedList(kv => kv.Key, kv => kv.Value);
            }
            var tlDeser = CreateTypeLibraryDeserializer();

            foreach (var kv in user.Globals)
            {
                var dt   = kv.Value.DataType.Accept(tlDeser);
                var item = new ImageMapItem((uint)dt.Size)
                {
                    Address  = kv.Key,
                    DataType = dt,
                    Name     = kv.Value.Name,
                };
                if (item.Size > 0)
                {
                    program.ImageMap.AddItemWithSize(kv.Key, item);
                }
                else
                {
                    program.ImageMap.AddItem(kv.Key, item);
                }
                //$BUGBUG: what about x86 segmented binaries?
                int offset = (int)kv.Key.ToLinear();
                program.GlobalFields.Fields.Add(offset, dt, kv.Value.Name);
            }

            if (sUser.Heuristics != null)
            {
                user.Heuristics.UnionWith(sUser.Heuristics.Select(h => h.Name));
            }
            if (sUser.TextEncoding != null)
            {
                Encoding enc = null;
                try
                {
                    enc = Encoding.GetEncoding(sUser.TextEncoding);
                } catch
                {
                    var diagSvc = Services.RequireService <IDiagnosticsService>();
                    diagSvc.Warn(string.Format("Unknown text encoding '{0}'. Defaulting to platform text encoding.", sUser.TextEncoding));
                }
                user.TextEncoding = enc;
            }
            program.EnvironmentMetadata = project.LoadedMetadata;
            if (sUser.Calls != null)
            {
                program.User.Calls = sUser.Calls
                                     .Select(c => LoadUserCall(c, program))
                                     .Where(c => c != null)
                                     .ToSortedList(k => k.Address, v => v);
            }
        }