解压静态库.a文件

来源:互联网 发布:淘宝金鹰男士 假货 编辑:程序博客网 时间:2024/05/29 13:28

首先先准备一个静态库.a文件,比如叫staticLibrary.a,放在桌面的test目录里。

分离arch

首先先file一下staticLibrary.a,看一下该文件包含几种arch。

<code class="hljs livecodeserver has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;">~  cd Desktop/testtest  lsstaticLibrary.<span class="hljs-operator" style="box-sizing: border-box;">a</span>test  <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">file</span> staticLibrary.<span class="hljs-operator" style="box-sizing: border-box;">a</span> staticLibrary.<span class="hljs-operator" style="box-sizing: border-box;">a</span>: Mach-O universal binary <span class="hljs-operator" style="box-sizing: border-box;">with</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span> architecturesstaticLibrary.<span class="hljs-operator" style="box-sizing: border-box;">a</span> (<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> architecture armv7):   current ar archive <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">random</span> librarystaticLibrary.<span class="hljs-operator" style="box-sizing: border-box;">a</span> (<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> architecture arm64):   current ar archive <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">random</span> library</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li></ul>

可以看到该文件包含两种arch,分别是armv7和arm64。 
由于下面抽离object的时候必须是要单一的库,所以这里我们之抽出armv7并命名为v7.a:

<code class="hljs livecodeserver has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;">lipo staticLibrary.<span class="hljs-operator" style="box-sizing: border-box;">a</span> -thin armv7 -output v7.<span class="hljs-operator" style="box-sizing: border-box;">a</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

这时候应该在test目录下多了一个v7.a文件。

抽离.a文件的object

<code class="hljs livecodeserver has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;">ar -x v7.<span class="hljs-operator" style="box-sizing: border-box;">a</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

你会发现会多出一些.o文件

获取文件

比如刚才多出来了一个View.o文件,使用以下命令进行获取:

<code class="hljs avrasm has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;">nm View<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.o</span> > view<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.m</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

OK 去看一下view.m文件吧

0 0