- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
如何将部分从 __TEXT
段中移出并移入 mach-o 二进制文件的新段中?我问的原因是我试图让我的 iPhone 应用程序更小,并且 iOS App Store 在压缩之前加密了它的 __TEXT
部分,因此它根本不会压缩。如果我可以将所有不可执行的部分移出该段并移至一个新的只读段中,那么我可以将应用程序的大小减少大约 9%。
最佳答案
正如@meisel 回答中已经提到的,这可以通过以下方式完成: 所以要设置的值是:
-Wl,-rename_section,__TEXT,__sectionName,__NEW_SEGMENT_NAME,__newSectionName
如果段权限需要调整
-segprot,__NEW_SEGMENT_NAME,rx,rx
小心 rwx
的可执行代码,如果检测到 rxw
运行代码,应用程序将立即被 iOS XNU 内核杀死。它仍然适用于 x86-64 模拟器。本博post涵盖了一些使用示例。
假设您正在使用 Objective-C(或 C),您可以使用 __attribute__ section(...)
。
语法:__attribute__ ((section("segmentName,sectionName,[optional]sectionType,[optional]sectionAttribute,[optional]stubSize")))
来自 https://opensource.apple.com/source/clang/clang-137/src/lib/MC/MCSectionMachO.cpp允许的 sectionTypes
:
{ "regular", "S_REGULAR" }, // 0x00
{ 0, "S_ZEROFILL" }, // 0x01
{ "cstring_literals", "S_CSTRING_LITERALS" }, // 0x02
{ "4byte_literals", "S_4BYTE_LITERALS" }, // 0x03
{ "8byte_literals", "S_8BYTE_LITERALS" }, // 0x04
{ "literal_pointers", "S_LITERAL_POINTERS" }, // 0x05
{ "non_lazy_symbol_pointers", "S_NON_LAZY_SYMBOL_POINTERS" }, // 0x06
{ "lazy_symbol_pointers", "S_LAZY_SYMBOL_POINTERS" }, // 0x07
{ "symbol_stubs", "S_SYMBOL_STUBS" }, // 0x08
{ "mod_init_funcs", "S_MOD_INIT_FUNC_POINTERS" }, // 0x09
{ "mod_term_funcs", "S_MOD_TERM_FUNC_POINTERS" }, // 0x0A
{ "coalesced", "S_COALESCED" }, // 0x0B
{ 0, /*FIXME??*/ "S_GB_ZEROFILL" }, // 0x0C
{ "interposing", "S_INTERPOSING" }, // 0x0D
{ "16byte_literals", "S_16BYTE_LITERALS" }, // 0x0E
{ 0, /*FIXME??*/ "S_DTRACE_DOF" }, // 0x0F
{ 0, /*FIXME??*/ "S_LAZY_DYLIB_SYMBOL_POINTERS" }, // 0x10
{ "thread_local_regular", "S_THREAD_LOCAL_REGULAR" }, // 0x11
{ "thread_local_zerofill", "S_THREAD_LOCAL_ZEROFILL" }, // 0x12
{ "thread_local_variables", "S_THREAD_LOCAL_VARIABLES" }, // 0x13
{ "thread_local_variable_pointers",
"S_THREAD_LOCAL_VARIABLE_POINTERS" }, // 0x14
{ "thread_local_init_function_pointers",
"S_THREAD_LOCAL_INIT_FUNCTION_POINTERS"}, // 0x15
允许的部分属性
:
ENTRY("pure_instructions", S_ATTR_PURE_INSTRUCTIONS)
ENTRY("no_toc", S_ATTR_NO_TOC)
ENTRY("strip_static_syms", S_ATTR_STRIP_STATIC_SYMS)
ENTRY("no_dead_strip", S_ATTR_NO_DEAD_STRIP)
ENTRY("live_support", S_ATTR_LIVE_SUPPORT)
ENTRY("self_modifying_code", S_ATTR_SELF_MODIFYING_CODE)
ENTRY("debug", S_ATTR_DEBUG)
ENTRY("" /*FIXME*/, S_ATTR_SOME_INSTRUCTIONS)
ENTRY("" /*FIXME*/, S_ATTR_EXT_RELOC)
ENTRY("" /*FIXME*/, S_ATTR_LOC_RELOC)
一些例子:
//Variable in brand new segment & section, segment VM access defaults to read/write
int intInCustomPlace __attribute__ ( (section ("__DATA2,__data2") ));
//Read only string constant outside of __TEXT in readonly __LINKEDIT
char *kString __attribute__ ( (section ("__LINKEDIT,__customSection") )) = "value";
//C function in custom segment & section
void foo() __attribute__ ( (section ("__TEXT_EXEC,__customSection") ));
//obj-c method in custom section
@interface YourClass
- (void) foo:(NSInteger)someArg __attribute__ ( (section ("__TEXT, __customSection") ));
@end
@interface YourClass ()
- (void) foo2:(NSInteger)someArg __attribute__ ( (section ("__TEXT, __customSection") ));
@end
#pragma clang attribute push(__attribute__ ( (section ("__TEXT_EXEC,__customSection") )), apply_to=objc_method)
@interface AppDelegate ()
-(void)test;
-(void)test2;
@end
@interface AppDelegate ()
-(void)test3;
-(void)test4;
@end
#pragma clang attribute pop
#pragma clang attribute push(__attribute__ ( (section ("__TEXT,__customTextSection") )), apply_to=objc_method)
@interface AppDelegate
-(void)test5;
-(void)test6;
@end
#pragma clang attribute pop
#pragma clang attribute push(__attribute__ ( (section ("__TEXT_EXEC,__customSection") )), apply_to=function)
void func1();
void func2();
#pragma clang attribute pop
请记住,您很容易破坏东西,MachOView
是检查二进制文件的便捷工具。自定义 ("__TEXT,__cstring")
替换很可能是您的最佳选择。
编辑:默认情况下,不存在的段将作为可读和可写的(就像 __DATA
)发出,因此这不适用于可执行代码。
如果您想探索内联程序集路径,请在此处记录:https://developer.apple.com/library/content/documentation/DeveloperTools/Reference/Assembler/040-Assembler_Directives/asm_directives.html
关于ios - 我如何从 __TEXT 中分离出来并进入 mach-o 二进制文件的新段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47896174/
我在尝试使用 jpa2.0 将包含持久实体和分离实体(新创建的实体)的实体列表更新到我的数据库中时遇到错误。 我的实体包含在合并数据时出现错误(在标题中提到)的内部实体: Class supercla
我在分层 Pane 中有一组面板。我需要一个分隔符来将 sideBar 与 topBar 和 tabbedPanel 分开。我留了一个 10 像素的缓冲区来放置它。不幸的是,可能由于它是 JLayer
在我从数据库中读取的代码中,我还使用自定义适配器打印出每一行,该行中有一个 texttview、2 个按钮和一个 edittext。这一切都很好,但是当按下按钮时,edittext 会递增或递减,有没
我有一个由 Hibernate 4.3.4 管理的实体,它有一个其他实体的一对多集合。 在我的处理过程中,我必须分离父实体(将分离级联到子列表)。但是,当我向列表中添加一个尚未持久化的新项目并执行分离
我想追加一行,该行应该是表格的最后一行。在我的代码中,它似乎在第一次动态添加行时起作用。但是当添加其他行时它不会成为最后一行。 我总是希望“subtot”行成为最后一行,但是当我追加其他行时,它不
我试图用它们之间的空格分隔这 2 个 div(请参见图 1)。问题是当我添加边距或填充时会发生这种情况(请参见图 2)。 这是我的代码,请注意我没有使用 Bootstrap: .row { mar
我的服务器包含一些 ServerActor。该 actor 接收 RegisterClient 消息并将 ActorRefs 添加到已注册客户端列表中。 我还有多个客户端,每个客户端都包含 Clien
假设我有一个需要两个参数的函数,并且参数的顺序会影响结果。 是否可以将第一个参数传递给 partial 或 comp 函数,然后将另一个参数传递给它,如下所示: (defn bar [arg1 arg
如何搜索和分离多个后代键。 例子: (def d {:foo 123 :bar { :baz 456 :bam { :w
我正在尝试为 Slick 表创建一个类型安全的动态 DSL,但不确定如何实现这一点。 用户可以通过以 form/json 格式发送过滤器来将过滤器发布到服务器,我需要使用所有这些来构建一个 Slick
我是新来的,我发现看到充满大量函数和变量初始化以及 UI 的组件时眼睛很痛。是否可以将它们分开? 而不是默认设置,如下所示。如何将业务逻辑分离到另一个文件中? function MyComponent
我试图通过将参数粘贴在一起来使用分离。这应该是一件容易的工作,但不适合我。当我想到使用 eval(parse()) 时,我知道是时候寻求帮助了 通常,如果我加载一个包,我可以按如下方式分离它: det
(dissoc :a m)允许我解除给定的键。但是,有没有办法使用谓词函数来分离 pred 为真的任何键? (dissoc-with-pred pred? m) 所以给了一张 map - {:a 2
我编写了一个使用 devtools 来包含内部数据的包: devtools::use_data(.data, internal = T, overwrite = T) 我最近更改了该数据并重建了包。我
所以我有一个脚本,我想在我的服务器上运行它而不会打扰我。所以我想我会在 tmux 窗口中运行服务器,然后 detach这样我就可以简单地 attach如果我想查看进度(此脚本需要数天才能运行)。 但是
ThreeJS中动画数据和模型数据是否可以解耦? 这样就可以交换模型并保留动画?我认为这可能非常强大 我知道如何在 ThreeJS 中做到这一点的方法是将每个动画一个接一个地打包在一个模型中,这似乎是
我有一堆(Ruby)脚本存储在服务器上。到目前为止,我的团队通过打开一个启动脚本名称列表的访问器应用程序来使用它们,然后他们在工作文件夹中的文件上选择要在该实例中运行的脚本。脚本直接从服务器运行,因此
我想知道 javascript 如何包含在 jsp 中 - 我们是否可以在 .js 文件中放置 jsp 能够识别的任何代码,而不仅仅是 javascript 代码? 我有一些常见的 JavaScrip
您是否可以在 Dockerfile 中指定一个选项,默认使用它构建的容器以分离方式运行。 这将导致与 -d 相同的结果: docker run -d 这样 docker run 默认情况下会分离运
我正在为现有的 Java 程序开发 Java 插件。现有程序使用特定版本的 eclipse.uml2.*,我的插件也是如此。不幸的是,我的插件需要更新版本。 为了运行该插件,我需要将其导出到 Jar
我是一名优秀的程序员,十分优秀!