]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/macho/macho.factor
alien.c-types: not necessary to import `short` differently anymore
[factor.git] / extra / macho / macho.factor
index 06f49bc0b6ede933750b407f05ee59d2905b9cf4..1f0732b380e8c14ee5e0009fe30af66e019837cc 100644 (file)
@@ -4,8 +4,7 @@ USING: accessors alien alien.c-types alien.data alien.strings
 alien.syntax classes classes.struct combinators
 combinators.short-circuit io.encodings.ascii io.encodings.string
 kernel literals make math sequences specialized-arrays typed
-fry io.mmap formatting locals splitting io.binary arrays ;
-FROM: alien.c-types => short ;
+io.mmap formatting splitting endian ;
 IN: macho
 
 ! FFI data
@@ -128,6 +127,15 @@ CONSTANT: LC_LAZY_LOAD_DYLIB    0x20
 CONSTANT: LC_ENCRYPTION_INFO    0x21
 CONSTANT: LC_DYLD_INFO          0x22
 CONSTANT: LC_DYLD_INFO_ONLY     0x80000022
+CONSTANT: LC_LOAD_UPWARD_DYLIB 0x80000023
+CONSTANT: LC_VERSION_MIN_MACOSX 0x24
+CONSTANT: LC_VERSION_MIN_IPHONEOS 0x25
+CONSTANT: LC_FUNCTION_STARTS 0x26
+CONSTANT: LC_DYLD_ENVIRONMENT 0x27
+CONSTANT: LC_MAIN 0x80000028
+CONSTANT: LC_DATA_IN_CODE 0x29
+CONSTANT: LC_SOURCE_VERSION 0x2A
+CONSTANT: LC_DYLIB_CODE_SIGN_DRS 0x2B
 
 UNION-STRUCT: lc_str
     { offset    uint     }
@@ -448,6 +456,12 @@ STRUCT: dyld_info_command
     { export_off       uint }
     { export_size      uint } ;
 
+STRUCT: version_min_command
+    { cmd uint32_t }
+    { cmdsize uint32_t }
+    { version uint32_t }
+    { sdk uint32_t } ;
+
 CONSTANT: REBASE_TYPE_POINTER                     1
 CONSTANT: REBASE_TYPE_TEXT_ABSOLUTE32             2
 CONSTANT: REBASE_TYPE_TEXT_PCREL32                3
@@ -514,6 +528,22 @@ STRUCT: fvmfile_command
     { name           lc_str   }
     { header_addr    uint     } ;
 
+STRUCT: entry_point_command
+    { cmd uint32_t }
+    { cmdsize uint32_t }
+    { entryoff uint64_t }
+    { stacksize uint64_t } ;
+
+STRUCT: source_version_command
+    { cmd uint32_t }
+    { cmdsize uint32_t }
+    { version uint64_t } ;
+
+STRUCT: data_in_code_entry
+    { offset uint32_t }
+    { length uint16_t }
+    { kind uint16_t } ;
+
 ! machine.h
 CONSTANT: CPU_STATE_MAX       4
 CONSTANT: CPU_STATE_USER      0
@@ -881,6 +911,15 @@ TYPED: 64-bit? ( macho: mach_header_32/64 -- ? )
         { LC_SUB_CLIENT     [ sub_client_command     ] }
         { LC_DYLD_INFO      [ dyld_info_command      ] }
         { LC_DYLD_INFO_ONLY [ dyld_info_command      ] }
+        { LC_LOAD_UPWARD_DYLIB [ dylib_command ] }
+        { LC_VERSION_MIN_MACOSX [ version_min_command ] }
+        { LC_VERSION_MIN_IPHONEOS [ version_min_command ] }
+        { LC_FUNCTION_STARTS [ linkedit_data_command ] }
+        { LC_DYLD_ENVIRONMENT [ dylinker_command ] }
+        { LC_MAIN [ entry_point_command ] }
+        { LC_DATA_IN_CODE [ data_in_code_entry ] }
+        { LC_SOURCE_VERSION [ source_version_command ] }
+        { LC_DYLIB_CODE_SIGN_DRS [ linkedit_data_command ] }
     } case ;
 
 : read-command ( cmd -- next-cmd )
@@ -904,7 +943,7 @@ TYPED: load-commands ( macho: mach_header_32/64 -- load-commands )
     [ symtab_command? ] filter ; inline
 
 : read-array-string ( uchar-array -- string )
-    ascii decode [ 0 = ] reject ;
+    ascii decode 0 swap remove ;
 
 : segment-sections ( segment-command -- sections )
     {
@@ -919,7 +958,7 @@ TYPED: load-commands ( macho: mach_header_32/64 -- load-commands )
 : sections-array ( segment-commands -- sections-array )
     [
         dup first segment_command_64?
-        [ section_64 ] [ section ] if <struct> ,
+        [ section_64 ] [ section ] if new ,
         segment-commands [ segment-sections [ , ] each ] each
     ] { } make ;