关于Mach-O类型文件那点事
Header结构描述
如果只有一种架构,那么Fat Header的地方直接就是mac_header

Load command结构描述
struct segment_command { /* for 32-bit architectures */
uint32_t cmd; /* LC_SEGMENT */
uint32_t cmdsize; /* includes sizeof section structs */
char segname[16]; /* segment name */
uint32_t vmaddr; /* memory address of this segment */
uint32_t vmsize; /* memory size of this segment */
uint32_t fileoff; /* file offset of this segment */
uint32_t filesize; /* amount to map from the file */
vm_prot_t maxprot; /* maximum VM protection */
vm_prot_t initprot; /* initial VM protection */
uint32_t nsects; /* number of sections in segment */
uint32_t flags; /* flags */
};
#define SEG_PAGEZERO "__PAGEZERO"
#define SEG_TEXT "__TEXT" /* the tradition UNIX text segment */
#define SEG_DATA "__DATA" /* the tradition UNIX data segment */
__TEXT段加载描述

__DATA段加载描述

根据__TEXT段的加载描述, 得到__DATA段内容的偏移地址如下:

ASLR:内存空间布局随机化
image list -o -f
结果如下:
(lldb) image list -o -f
[ 0] 0x0000000000558000 /Users/zhoufei/Library/Developer/Xcode/DerivedData/SorterAndFilter-gcqrjckyrquurscwtbwpiaeebgzj/Build/Products/Release-iphoneos/SorterAndFilter.app/SorterAndFilter
[ 1] 0x0000000100800000 /Users/zhoufei/Library/Developer/Xcode/iOS DeviceSupport/11.4 (15F79)/Symbols/usr/lib/dyld
[ 2] 0x0000000001190000 /Users/zhoufei/Library/Developer/Xcode/iOS DeviceSupport/11.4 (15F79)/Symbols/System/Library/Frameworks/Foundation.framework/Foundation
[ 3] 0x0000000001190000 /Users/zhoufei/Library/Developer/Xcode/iOS DeviceSupport/11.4 (15F79)/Symbols/System/Library/Frameworks/UIKit.framework/UIKit
[ 4] 0x0000000001190000 /Users/zhoufei/Library/Developer/Xcode/iOS DeviceSupport/11.4 (15F79)/Symbols/usr/lib/libobjc.A.dylib
[ 5] 0x0000000001190000 /Users/zhoufei/Library/Developer/Xcode/iOS DeviceSupport/11.4 (15F79)/Symbols/usr/lib/libSystem.B.dylib
[ 6] 0x0000000001190000 /Users/zhoufei/Library/Developer/Xcode/iOS DeviceSupport/11.4 (15F79)/Symbols/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
[ 7] 0x0000000001190000 /Users/zhoufei/Library/Developer/Xcode/iOS DeviceSupport/11.4 (15F79)/Symbols/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics
[ 8] 0x0000000001190000 /Users/zhoufei/Library/Developer/Xcode/iOS DeviceSupport/11.4 (15F79)/Symbols/System/Library/Frameworks/QuartzCore.framework/QuartzCore
[ 9] 0x0000000001190000 /Users/zhoufei/Library/Developer/Xcode/iOS DeviceSupport/11.4 (15F79)/Symbols/usr/lib/libarchive.2.dylib
第0个结果0x0000000000558000 就是要找的ASLR值

通过log的内容,拿到app的Mach-O文件路径:
[ 0] 0x0000000000558000 /Users/zhoufei/Library/Developer/Xcode/DerivedData/SorterAndFilter-gcqrjckyrquurscwtbwpiaeebgzj/Build/Products/Release-iphoneos/SorterAndFilter.app/SorterAndFilter
其对应的偏移地址0x0000000000558000 就是Mach-O文件从本地添加到内存时,系统自动添加的ASLR:内存空间布局随机化值。
1.cd /Users/zhoufei/Library/Developer/Xcode/DerivedData/SorterAndFilter-gcqrjckyrquurscwtbwpiaeebgzj/Build/Products/Release-iphoneos/SorterAndFilter.app/ 2.size -l -m -x SorterAndFilter
的到结果如下:
SorterAndFilter (for architecture arm64):
Segment __PAGEZERO: 0x100000000 (vmaddr 0x0 fileoff 0)
Segment __TEXT: 0x1c000 (vmaddr 0x100000000 fileoff 0)
Section __text: 0xfde0 (addr 0x100005740 offset 22336)
Section __stubs: 0x1bc (addr 0x100015520 offset 87328)
Section __stub_helper: 0x1d4 (addr 0x1000156dc offset 87772)
Section __const: 0x64 (addr 0x1000158b0 offset 88240)
Section __objc_methname: 0x36b4 (addr 0x100015914 offset 88340)
Section __ustring: 0x134 (addr 0x100018fc8 offset 102344)
Section __cstring: 0xd06 (addr 0x1000190fc offset 102652)
Section __objc_classname: 0x28c (addr 0x100019e02 offset 105986)
Section __objc_methtype: 0x19f2 (addr 0x10001a08e offset 106638)
Section __gcc_except_tab: 0xd8 (addr 0x10001ba80 offset 113280)
Section __unwind_info: 0x4a4 (addr 0x10001bb58 offset 113496)
total 0x168bc
Segment __DATA: 0xc000 (vmaddr 0x10001c000 fileoff 114688)
Section __got: 0x60 (addr 0x10001c000 offset 114688)
Section __la_symbol_ptr: 0x128 (addr 0x10001c060 offset 114784)
Section __const: 0x9f0 (addr 0x10001c188 offset 115080)
Section __cfstring: 0x9a0 (addr 0x10001cb78 offset 117624)
Section __objc_classlist: 0x90 (addr 0x10001d518 offset 120088)
Section __objc_catlist: 0x28 (addr 0x10001d5a8 offset 120232)
Section __objc_protolist: 0x58 (addr 0x10001d5d0 offset 120272)
Section __objc_imageinfo: 0x8 (addr 0x10001d628 offset 120360)
Section __objc_const: 0x55d8 (addr 0x10001d630 offset 120368)
Section __objc_selrefs: 0x9c0 (addr 0x100022c08 offset 142344)
Section __objc_classrefs: 0x138 (addr 0x1000235c8 offset 144840)
Section __objc_superrefs: 0x68 (addr 0x100023700 offset 145152)
Section __objc_ivar: 0xd0 (addr 0x100023768 offset 145256)
Section __objc_data: 0x5a0 (addr 0x100023838 offset 145464)
Section __data: 0x430 (addr 0x100023dd8 offset 146904)
Section __bss: 0x48 (addr 0x100024208 offset 0)
total 0x8250
Segment __LINKEDIT: 0x24000 (vmaddr 0x100028000 fileoff 163840)
total 0x10004c000
在虚拟内存中,Mach-O文件SorterAndFilter的总大小是total 0x10004c000。
2020-01-12 16:47:32.388332+0800 SorterAndFilter[1717:366886] 全局变量:0x10057bf58, 局部变量:0x16f8a57fc, 局部变量—对象指针:0x16f8a57f0, 堆空间-对象地址:0x100aace30
动态链接器dyld的虚拟内存地址
[ 1] 0x0000000100800000 /Users/zhoufei/Library/Developer/Xcode/iOS DeviceSupport/11.4 (15F79)/Symbols/usr/lib/dyld
Mach-O文件SorterAndFilter所有使用的到的image(image都是Mach-O类型文件)文件内存分布,得到虚拟内存中的内存分布如下:

查看通用二进制文件包含的架构
lipo -info test
瘦身通用二进制文件,到包含指定架构(armv7)的瘦二进制文件
lipo test -thin armv7 -output test_armv7
合并两个瘦二进制文件到一个通用二进制文件
lipo -create test_armv7 test_arm64 -output test2
image list -o -f
class-dump -H test -o Headers
MachOView: GUI工具查看Mach-O文件
关于Mach-O类型文件那点事的更多相关文章
- 在文件夹中 的指定类型文件中 查找字符串(CodeBlocks+GCC编译,控制台程序,仅能在Windows上运行)
说明: 程序使用 io.h 中的 _findfirst 和 _findnext 函数遍历文件夹,故而程序只能在 Windows 下使用. 程序遍历当前文件夹,对其中的文件夹执行递归遍历.同时检查遍历到 ...
- C#项目打开/保存文件夹/指定类型文件,获取路径
C#项目打开/保存文件夹/指定类型文件,获取路径 转:http://q1q2q363.xiaoxiang.blog.163.com/blog/static/1106963682011722424325 ...
- asp.net word ecxel类型文件在线预览
asp.net word ecxel类型文件在线预览 首先得引用COM: Microsoft Excel 10 Object Library Microsoft Word 10 Object Libr ...
- Linux下find一次查找多个指定类型文件,指定文件或者排除某类文件,在 GREP 中匹配多个关键 批量修改文件名等
http://blog.sina.com.cn/s/blog_62e7fe670101dg9d.html linux下二进制文件查找: strings 0000.ts | grep -o " ...
- CSharp tar类型文件压缩与解压
最近闲暇时间开始写点通用基础类在写到tar类型文件压缩与解压时遇到点问题 压缩用的类库我是下载的 SharpZipLib_0860版本 先上代码 加压核心 /// <summary> // ...
- java_eclipse_svn 与服务器同步时 ,忽略某类型文件和文件夹
1. 在项目开发中使用svn ,带来很大的方便,有时我们会把整个项目上传的svn服务器上 这样就包含了 编译过的class文件 以及 一些 .svn,.log文件,有些文件时本地complie 的 ...
- linux下删除目录及其子目录下某种类型文件
Linux下,如果想要删除目录及其子目录下某种类型文件,比如说所有的txt文件,则可以使用下面的命令: find . -name "*.txt" -type f -print -e ...
- 各种类型文件的Content-Type
各种类型文件的Content-Type 2017年11月27日 10:00:56 thebigdipperbdx 阅读数:7360 版权声明:本文为博主原创文章,未经博主允许不得转载. https ...
- 游戏开发中IIS常见支持MIME类型文件解析
游戏开发中IIS常见支持MIME类型文件解析 .apkapplication/vnd.android .ipaapplication/vnd.iphone .csbapplication/octet- ...
随机推荐
- C# Dapper 基本使用 增删改查事务
来源:https://blog.csdn.net/Tomato2313/article/details/78880969 using DapperTest.Models; using System.C ...
- 洛谷P4018 Roy&October之取石子 题解 博弈论
题目链接:https://www.luogu.org/problem/P4018 首先碰到这道题目还是没有思路,于是寻思还是枚举找一找规律. 然后写了一下代码: #include <bits/s ...
- HTML让文字在图片上显示的几种方法
第一种方式是image 作为背景图片,即:background:url("......."); 第二种方式是将img块与文字块(文字块采用span标签显示)放在同一个div 中,然 ...
- java Math和Random和UUID
Math类 public final class Math extends Object 以下X表示double,float,int, long abs(X x):求绝对值 max(X x1,X x2 ...
- JQuery操作select下拉框
JQuery操作select下拉框 获取Select选择的Text和Value $("#select_id").change(function(){//code...}); //为 ...
- 无限调用函数add(1)(2)(3)......
无限调用函数,并且累计结果 其实这也算一道面试题吧,笔者曾经被提问过,可惜当时没能答上来...
- Django入门7--博客撰写页面开发
- 在js中arguments对象的理解
一.在函数调用的时候,浏览器每次都会传递进两个隐式参数 函数的上下文对象this 封装实参的对象arguments 二.arguments 对象 arguments 对象实际上是所在函数的一个内置类数 ...
- html2canvas生成图片报错处理办法
详见大佬博客链接: link.(https://www.jianshu.com/p/22bd5b98e38a) 需要注意的是要生成的网页中带的网络图片地址(如放在阿里云服务器图库的图片)经常有跨域报错 ...
- JS求数组最大值常用方法
第一种方法: 循环数组 let ary = [1,2,22,3,99,100],maxNum = ary[0] function getMaxNum(ary){ for(let i = 1,len = ...