小编Jur*_*ste的帖子

从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
查看次数

使用自动布局在NSClipView/NSScrollView中的NSTableView框架

我正在尝试使用自动布局在代码中创建一个NSTableView内部NSScrollView(标准配置,即).我无法弄清楚如何使这项工作.

这是我的loadView:

- (void)loadView
{
    NSView *view = [[NSView alloc] init];

    NSScrollView *tableScroll = [[NSScrollView alloc] init];
    NSTableView *fileTable = [[NSTableView alloc] init];
    [tableScroll setDocumentView:fileTable];
    [tableScroll setHasVerticalScroller:YES];
    [tableScroll setHasHorizontalScroller:NO];
    fileTable.delegate = self;
    fileTable.dataSource = self;
    [fileTable setHeaderView:nil];
    [fileTable setAllowsColumnReordering:NO];

    NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:@"column1"];
    [fileTable addTableColumn:column];

    [tableScroll setTranslatesAutoresizingMaskIntoConstraints:NO];
    [fileTable setTranslatesAutoresizingMaskIntoConstraints:NO];

    [view addSubview:tableScroll];

    NSDictionary *topViews = NSDictionaryOfVariableBindings(tableScroll);
    [view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[tableScroll]|" options:0 metrics:nil views:topViews]];
    [view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[tableScroll]|" options:0 metrics:nil views:topViews]];

    self.fileTable = fileTable;

    self.view = view;
} …
Run Code Online (Sandbox Code Playgroud)

macos cocoa nstableview nsscrollview autolayout

5
推荐指数
1
解决办法
1623
查看次数

标签 统计

macos ×2

autolayout ×1

cocoa ×1

mach-o ×1

nsscrollview ×1

nstableview ×1

swift ×1