标签: mach-o

如何将数据嵌入到Mac OS X mach-o二进制文件的TEXT部分?

我有一个Mac OS X命令行工具,可以从二进制文件本身嵌入一些数据中受益.

我知道mach-o文件支持多个段,其中一些段可用于存储任意数据.但我找不到一个命令行工具来做到这一点.

虽然我知道还有其他的,可能更简单的方法(例如将数据文件转换为C源代码并通过gcc链接)以将数据输入到我的二进制文件中,这个问题引起了我的兴趣.谁知道魔术?

macos linker mach-o

11
推荐指数
1
解决办法
2034
查看次数

Apple Mach-O-Linker错误CocoaPods

我一直试图让我的应用程序运行起来.据我所知,该应用程序错过了Cocoapods作为依赖.所以.我安装并添加了Cocoapods.但无论出于何种原因,我仍然会得到同样的错误.我是一个没有经验的开发人员试图自学我必须添加.

Ld /Users/bfarag/Library/Developer/Xcode/DerivedData/Umbrella-cspuzusfqmqgnwdqfhtiyivaqwke/Build/Products/Debug-iphonesimulator/Umbrella.app/Umbrella normal i386 cd"/ Users/bfarag/Desktop/The Nerdery/BRAVO.iOS.CodeChallenge "export IPHONEOS_DEPLOYMENT_TARGET = 7.0 export PATH ="/ Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/ usr/bin:/ bin:/ usr/sbin:/ sbin"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer /Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk -L/Users/bfarag/Library/Developer/Xcode/DerivedData/Umbrella-cspuzusfqmqgnwdqfhtiyivaqwke/Build/Products/Debug-iphonesimulator -F/Users/bfarag/Library/Developer/Xcode/DerivedData/Umbrella-cspuzusfqmqgnwdqfhtiyivaqwke/Build/Products/Debug-iphonesimulator -filelist/Users/bfarag/Library/Developer/Xcode/DerivedData/Um brella-cspuzusfqmqgnwdqfhtiyivaqwke /建造/中间体/ Umbrella.build /调试-iphonesimulator/Umbrella.build /对象 - 正常/ I386/Umbrella.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -ObjC -lPods-伞AFNetworking -framework CoreGraphics中-framework MobileCoreServices -framework Security -framework SystemConfiguration -fobjc-arc -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min = 7.0 -framework加速-framework UIKit -framework Foundation-framework CoreGraphics -lPods -lPods-Umbrella -Xlinker -dependency_info -Xlinker /Users/bfarag/Library/Developer/Xcode/DerivedData/Umbrella-cspuzusfqmqgnwdqfhtiyivaqwke/Build/Intermediates/Umbrella.build/Debug-iphonesimulator/Umbrella.build/Objects-normal/i386/Umbrella_dependency_info.dat -o/Users /bfarag/Library/Developer/Xcode/DerivedData/Umbrella-cspuzusfqmqgnwdqfhtiyivaqwke/Build/Products/Debug-iphonesimulator/Umbrella.app/Umbrella

ld: library not found for -lPods
clang: error: linker command failed …
Run Code Online (Sandbox Code Playgroud)

xcode mach-o objective-c ios cocoapods

11
推荐指数
3
解决办法
2万
查看次数

Mach-O在ELF/linux中的两级命名空间符号解析

任何人都知道在ELF/linux中相当于Mach-O的两级命名空间符号解析?我想要链接到lib + sym的代码,而不是sym.

我正在尝试做一些最好被描述为通常是JIT编译的预编译.我想获得符号的编译时绑定,通常由dlopen/dlsym完成.但是,可能存在冲突,dlopen/dlsym可以很好地避免冲突.

似乎ELF实际上缺乏这个,并且有VERSION的东西,但任何变通办法或建议都将受到赞赏.

linux macos linker mach-o elf

10
推荐指数
1
解决办法
698
查看次数

Xcode Apple Mach-O链接器错误1

每当我尝试构建应用程序重命名我的项目后,我得到一个 Apple Mach-O链接器错误 下面是Xcode本身的输出

Ld /Users/joshevans/Library/Developer/Xcode/DerivedData/Broadcast!-gbvxmzbukuqqgxcmlipegtnzosze/Build/Products/Debug-iphonesimulator/Broadcast!Tests.xctest/Broadcast!Tests normal x86_64
    cd "/Users/joshevans/Desktop/sn app/SwifferApp"
    export IPHONEOS_DEPLOYMENT_TARGET=8.0
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-arch x86_64 -bundle -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk
-L/Users/joshevans/Library/Developer/Xcode/DerivedData/Broadcast!-gbvxmzbukuqqgxcmlipegtnzosze/Build/Products/Debug-iphonesimulator
-F/Users/joshevans/Library/Developer/Xcode/DerivedData/Broadcast!-gbvxmzbukuqqgxcmlipegtnzosze/Build/Products/Debug-iphonesimulator
-F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk/Developer/Library/Frameworks
-F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks
-F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk/Developer/Library/Frameworks
-filelist /Users/joshevans/Library/Developer/Xcode/DerivedData/Broadcast!-gbvxmzbukuqqgxcmlipegtnzosze/Build/Intermediates/Broadcast!.build/Debug-iphonesimulator/Broadcast!Tests.build/Objects-normal/x86_64/Broadcast!Tests.LinkFileList
-Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -rpath -Xlinker @loader_path/Frameworks -bundle_loader /Users/joshevans/Library/Developer/Xcode/DerivedData/Broadcast!-gbvxmzbukuqqgxcmlipegtnzosze/Build/Products/Debug-iphonesimulator/SwifferApp.app/SwifferApp
-Xlinker -objc_abi_version -Xlinker 2 -framework XCTest -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator
-Xlinker -add_ast_path -Xlinker /Users/joshevans/Library/Developer/Xcode/DerivedData/Broadcast!-gbvxmzbukuqqgxcmlipegtnzosze/Build/Intermediates/Broadcast!.build/Debug-iphonesimulator/Broadcast!Tests.build/Objects-normal/x86_64/Broadcast_Tests.swiftmodule
-mios-simulator-version-min=8.0 -Xlinker -dependency_info -Xlinker /Users/joshevans/Library/Developer/Xcode/DerivedData/Broadcast!-gbvxmzbukuqqgxcmlipegtnzosze/Build/Intermediates/Broadcast!.build/Debug-iphonesimulator/Broadcast!Tests.build/Objects-normal/x86_64/Broadcast!Tests_dependency_info.dat
-o /Users/joshevans/Library/Developer/Xcode/DerivedData/Broadcast!-gbvxmzbukuqqgxcmlipegtnzosze/Build/Products/Debug-iphonesimulator/Broadcast!Tests.xctest/Broadcast!Tests ld: file not found: /Users/joshevans/Library/Developer/Xcode/DerivedData/Broadcast!-gbvxmzbukuqqgxcmlipegtnzosze/Build/Products/Debug-iphonesimulator/SwifferApp.app/SwifferApp clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)

感谢您的帮助,因为我是Xcode和快速语言的新手.玩笑

iphone xcode mach-o ios swift

10
推荐指数
2
解决办法
3109
查看次数

如何将LC_LOAD_DYLIB命令插入Mach-O二进制文件(OSX)

我想用一些代码修补一块废弃软件.

该软件是基于碳的,所以我不能使用InputManager(至少,我认为我不能).我的想法是在mach-o标头中添加一个dylib引用,并在调用初始化例程时启动一个新线程.

我使用hexeditor添加了相应的加载命令(LC_ LOAD_DYLIB),并使用mach-o标头.

otool报告我期望看到的内容,因此我非常确信文件格式正确.

Load command 63
          cmd LC_LOAD_DYLIB
      cmdsize 60
         name @executable_path/libAltInput.dylib (offset 24)
   time stamp 1183743291 Fri Jul  6 19:34:51 2007
      current version 0.0.0
compatibility version 0.0.0

但是,启动二进制文件会给我以下错误

dyld: bad external relocation length

我可以猜到这意味着我需要修改LC_ SYMTAB或LC_ DYNSYMTAB部分......

有人有主意吗?

macos mach-o dylib otool dyld

9
推荐指数
1
解决办法
4481
查看次数

在Mac OS X上编辑程序集

我目前正在Windows上的IDA Pro中拆解Mach-O可执行文件(可执行文件在Mac OS X上运行,具体而言).我有一条我想要改变的指令,但似乎IDA Pro 不允许你这样做.所以,我尝试在OS X上使用otool转储程序集(它做得很好).但是,在otool中编辑程序集后,我尝试使用它重新组装它as <file name of modified otool -tV output>.这给我带来了一堆错误Junk character 43 (+).在Mac OS X上只更改Mach-O二进制中的单个指令的最简单方法是什么?

macos assembly mach-o

9
推荐指数
1
解决办法
3644
查看次数

重复符号_OBJC_CLASS _ $ _ LoginController

我知道这个问题之前已被多次询问过,但现在还没有人解决我的问题.我知道当您在项目中获得多个文件副本时会发生此错误.我试图清理构建,删除编译源中的任何LoginController.m文件,然后构建.很好 - 没有错误.当我在Complie资源中添加我的LoginController.m文件时,编译器再次给出了相同的错误.

接下来我尝试的是从Compile Sources中删除所有.m文件,成功清理和重建,并非常仔细地添加每个.m文件.再次提出同样的错误.我没有找到任何重复的文件,那么为什么会发生这种情况呢?

请有人指导我.非常感谢.

编辑: 错误是:

Ld /Users/svp/Library/Developer/Xcode/DerivedData/TryAgain-dhbbyywxclvxfodbunqysmmfefcl/Build/Products/Debug-iphonesimulator/TryAgain.app/TryAgain normal i386 cd /Users/svp/Desktop/TryAgain setenv MACOSX_DEPLOYMENT_TARGET 10.6 setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -L/Users/svp/Library/Developer/Xcode/DerivedData/TryAgain-dhbbyywxclvxfodbunqysmmfefcl/Build/Products/Debug-iphonesimulator -L/Users/svp/Desktop/TryAgain/TryAgain -L/Users/svp/Desktop/TryAgain/../CorePlot_1.0/Binaries/iOS -F/Users/svp/Library/Developer/Xcode/DerivedData/TryAgain-dhbbyywxclvxfodbunqysmmfefcl/Build/Products/Debug-iphonesimulator -filelist /Users/svp/Library/Developer/Xcode/DerivedData/TryAgain-dhbbyywxclvxfodbunqysmmfefcl/Build/Intermediates/TryAgain.build/Debug-iphonesimulator/TryAgain.build/Objects-normal/i386/TryAgain.LinkFileList -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -ObjC -all_load -fobjc-arc -D__IPHONE_OS_VERSION_MIN_REQUIRED=50000 -framework MediaPlayer -lz -framework AVFoundation -framework MobileCoreServices -framework SystemConfiguration -framework CFNetwork -framework QuartzCore -framework UIKit -framework Foundation -framework CoreGraphics -lCorePlot-CocoaTouch -o /Users/svp/Library/Developer/Xcode/DerivedData/TryAgain-dhbbyywxclvxfodbunqysmmfefcl/Build/Products/Debug-iphonesimulator/TryAgain.app/TryAgain

ld: duplicate symbol _OBJC_CLASS_$_LoginController in /Users/svp/Library/Developer/Xcode/DerivedData/TryAgain-dhbbyywxclvxfodbunqysmmfefcl/Build/Intermediates/TryAgain.build/Debug-iphonesimulator/TryAgain.build/Objects-normal/i386/LoginController.o and /Users/svp/Library/Developer/Xcode/DerivedData/TryAgain-dhbbyywxclvxfodbunqysmmfefcl/Build/Intermediates/TryAgain.build/Debug-iphonesimulator/TryAgain.build/Objects-normal/i386/Navigator.o for architecture i386 Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang failed …

linker mach-o linker-errors duplicate-symbol ios5

9
推荐指数
1
解决办法
5692
查看次数

在OS X上以编程方式查找共享库中的本地符号偏移量

我需要在OS X上的共享库中找到本地符号的偏移量.本地符号与非导出符号中的一样.因此dyld("symbol_name")不会起作用.

但是,我可以用它nm来找到这些偏移量

$ nm /System/Library/PrivateFrameworks/DesktopServicesPriv.framework/DesktopServicesPriv  | grep -e ChildSetLabel -e NodeVolumeEject
000000000006cccd T _NodeVolumeEject
000000000009dbd7 t __ChildSetLabel
Run Code Online (Sandbox Code Playgroud)

在那里我们看到导出的(T)符号NodeVolumeEject,0x6cccd我可以轻松地使用它来显示偏移量dyld("NodeVolumeEject").dyld()将显示当前地址空间中的地址,但我对共享库中的偏移量或地址空间中的绝对地址感到满意.另外,还有local(t)符号_ChildSetLabel,它是offset(0x9dbd7)我无法透露使用dyld().

我希望能够以编程方式做到这一点的分辨率(不gobjdump,nm,otool,或任何其他外部程序).是否有"简单"的方法来实现这一目标?上面提到的工具的源代码包含所需的代码,但我想知道是否有更直接的东西.

域:解决方案只适用于OS X 10.8或更高版本的x86_64 MachO二进制文件.

澄清:我很乐意弄清楚当前偏移的绝对偏移(由ASLR引起)显然不是静态的.但我也很高兴找出相对于该库开头的偏移量,该库保持静态(直到重新编译).从"库中的地址"到"地址空间中的地址"的部分非常简单:

off_t sym_offset_child_set_label = ANSWER_TO_THIS_QUESTION("_ChildSetLabel");
Dl_info info;
void *abs_volume_eject = dlsym(RTLD_DEFAULT, "NodeVolumeEject");
void *abs_child_set_label = NULL;
if (dladdr(abs_volume_eject, &info)) {
    abs_child_set_label = (void *)((char *)info.dli_fbase + sym_offset_child_set_label);

    /* …
Run Code Online (Sandbox Code Playgroud)

macos mach-o shared-libraries dyld

8
推荐指数
1
解决办法
1382
查看次数

可执行格式之间有什么区别?

PEELFMach-O之间有什么主要区别吗?我的意思是,一个人是否拥有其他人没有的能力?一个人能比其他人携带更多信息吗?或者它们只是相同信息的不同容器格式?
我对此不是很了解,但在我看来,它们都带有文本(代码)部分、初始化和未初始化的数据部分等,以及重定位、符号、字符串、导入和导出表。

我并不是在询问微小的差异,例如格式 X 可以分割数据部分,或者格式 Y 可以在硬件中更有效地解析。
我询问的是主要差异,这些差异可能会影响新通用操作系统的选择。或者,如果一个平台具有适用于所有 3 种格式的加载器,那么只需“重新打包”各部分并将表格重写为新格式,即可轻松从一种格式转换为另一种格式。

mach-o elf portable-executable

8
推荐指数
1
解决办法
1772
查看次数

从Swift调用getsectiondata

这个问题和答案描述了如何在现代OS X/macOS版本上使用Objective-C从Mach-O部分读取数据:从getsectbyname中读取字节

描述的答案有效.我正在尝试用Swift实现同样的功能.我不能让它发挥作用.

我在"其他链接器标志"中有以下内容:-Wl,-sectcreate,__LOCALIZATIONS,__base,en.lproj/Localizable.strings,-segprot,__LOCALIZATIONS,r,r.

这个Swift代码为我提供了一个指向嵌入数据的指针,直到我尝试在Xcode之外运行代码并且ASLR打破它:

var size: UInt = 0
let _localizationSection = getsectdata(
    "__LOCALIZATIONS",
    "__base",
    &size)
Run Code Online (Sandbox Code Playgroud)

为了解决ASLR问题,根据上面的问题和答案,并根据我自己的测试,我应该使用getsectiondata.它在Objective-C中运行得很好,但我在Swift中没有运气.以下是我唯一能够通过编译器的东西,但它返回nil:

var size: UInt = 0
var header = _mh_execute_header
let localizationSection = getsectiondata(
    &header,
    "__LOCALIZATIONS",
    "__base",
    &size)
Run Code Online (Sandbox Code Playgroud)

正在拍摄_mh_execute_header问题的副本,有没有办法避免它?我需要一个UnsafePointer<mach_header_64>,但使用&_mh_execute_header第一个参数来getsectiondata导致编译错误.

我正在使用Swift 3.0,并在macOS 10.12上运行我的代码.

macos mach-o swift

8
推荐指数
1
解决办法
557
查看次数