[Lldb-commits] [lldb] r155423 - /lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Greg Clayton gclayton at apple.com
Mon Apr 23 20:06:14 PDT 2012


Author: gclayton
Date: Mon Apr 23 22:06:13 2012
New Revision: 155423

URL: http://llvm.org/viewvc/llvm-project?rev=155423&view=rev
Log:
Added support for the LC_ENCRYPTION_INFO load command.


Modified:
    lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Modified: lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp?rev=155423&r1=155422&r2=155423&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Mon Apr 23 22:06:13 2012
@@ -17,6 +17,7 @@
 #include "lldb/Core/FileSpecList.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/PluginManager.h"
+#include "lldb/Core/RangeMap.h"
 #include "lldb/Core/Section.h"
 #include "lldb/Core/StreamFile.h"
 #include "lldb/Core/StreamString.h"
@@ -756,6 +757,27 @@
     const bool is_core = GetType() == eTypeCoreFile;
     //bool dump_sections = false;
     ModuleSP module_sp (GetModule());
+    // First look up any LC_ENCRYPTION_INFO load commands
+    typedef RangeArray<uint32_t, uint32_t, 8> EncryptedFileRanges;
+    EncryptedFileRanges encrypted_file_ranges;
+    for (i=0; i<m_header.ncmds; ++i)
+    {
+        const uint32_t load_cmd_offset = offset;
+        if (m_data.GetU32(&offset, &load_cmd, 2) == NULL)
+            break;
+        
+        if (load_cmd.cmd == LoadCommandEncryptionInfo)
+        {
+            EncryptedFileRanges::Entry entry;
+            entry.SetRangeBase(m_data.GetU32(&offset));
+            entry.SetByteSize(m_data.GetU32(&offset));
+            encrypted_file_ranges.Append(entry);
+        }
+        offset = load_cmd_offset + load_cmd.cmdsize;
+    }
+
+    offset = MachHeaderSizeFromMagic(m_header.magic);
+
     for (i=0; i<m_header.ncmds; ++i)
     {
         const uint32_t load_cmd_offset = offset;
@@ -785,7 +807,7 @@
                     SectionSP segment_sp;
                     if (segment_name || is_core)
                     {
-                        segment_sp.reset(new Section (module_sp,            // Module to which this section belongs
+                        segment_sp.reset(new Section (module_sp,              // Module to which this section belongs
                                                       ++segID << 8,           // Section ID is the 1 based segment index shifted right by 8 bits as not to collide with any of the 256 section IDs that are possible
                                                       segment_name,           // Name of this section
                                                       eSectionTypeContainer,  // This section is a container of other sections.
@@ -1020,8 +1042,12 @@
                                                           sect64.offset == 0 ? 0 : sect64.size,
                                                           sect64.flags));
                         // Set the section to be encrypted to match the segment
-                        section_sp->SetIsEncrypted (segment_is_encrypted);
+                        
+                        bool section_is_encrypted = false;
+                        if (!segment_is_encrypted && load_cmd.filesize != 0)
+                            section_is_encrypted = encrypted_file_ranges.FindEntryThatContains(sect64.offset) != NULL;
 
+                        section_sp->SetIsEncrypted (segment_is_encrypted || section_is_encrypted);
                         segment_sp->GetChildren().AddSection(section_sp);
 
                         if (segment_sp->IsFake())





More information about the lldb-commits mailing list