<rdar://problem/11535465>
authorGreg Clayton <gclayton@apple.com>
Fri, 25 May 2012 18:09:55 +0000 (18:09 +0000)
committerGreg Clayton <gclayton@apple.com>
Fri, 25 May 2012 18:09:55 +0000 (18:09 +0000)
LC_ENCRYPTION_INFO with "cryptid == 0" is not actually encrypted and LLDB fails to read memory from file.

llvm-svn: 157487

lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

index ff643f4..7b0c2e7 100644 (file)
@@ -751,7 +751,6 @@ ObjectFileMachO::ParseSections ()
 {
     lldb::user_id_t segID = 0;
     lldb::user_id_t sectID = 0;
-    struct segment_command_64 load_cmd;
     uint32_t offset = MachHeaderSizeFromMagic(m_header.magic);
     uint32_t i;
     const bool is_core = GetType() == eTypeCoreFile;
@@ -760,24 +759,32 @@ ObjectFileMachO::ParseSections ()
     // First look up any LC_ENCRYPTION_INFO load commands
     typedef RangeArray<uint32_t, uint32_t, 8> EncryptedFileRanges;
     EncryptedFileRanges encrypted_file_ranges;
+    encryption_info_command encryption_cmd;
     for (i=0; i<m_header.ncmds; ++i)
     {
         const uint32_t load_cmd_offset = offset;
-        if (m_data.GetU32(&offset, &load_cmd, 2) == NULL)
+        if (m_data.GetU32(&offset, &encryption_cmd, 2) == NULL)
             break;
         
-        if (load_cmd.cmd == LoadCommandEncryptionInfo)
+        if (encryption_cmd.cmd == LoadCommandEncryptionInfo)
         {
-            EncryptedFileRanges::Entry entry;
-            entry.SetRangeBase(m_data.GetU32(&offset));
-            entry.SetByteSize(m_data.GetU32(&offset));
-            encrypted_file_ranges.Append(entry);
+            if (m_data.GetU32(&offset, &encryption_cmd.cryptoff, 3))
+            {
+                if (encryption_cmd.cryptid != 0)
+                {
+                    EncryptedFileRanges::Entry entry;
+                    entry.SetRangeBase(encryption_cmd.cryptoff);
+                    entry.SetByteSize(encryption_cmd.cryptsize);
+                    encrypted_file_ranges.Append(entry);
+                }
+            }
         }
-        offset = load_cmd_offset + load_cmd.cmdsize;
+        offset = load_cmd_offset + encryption_cmd.cmdsize;
     }
 
     offset = MachHeaderSizeFromMagic(m_header.magic);
 
+    struct segment_command_64 load_cmd;
     for (i=0; i<m_header.ncmds; ++i)
     {
         const uint32_t load_cmd_offset = offset;