iOS安全–使用static inline方式编译函数,防止静态分析

本文详细解析了函数调用方式(普通、内联、静态内联和静态)对逆向工程的复杂性影响。通过对比内联与静态内联函数在编译过程中的行为,以及静态函数如何隐藏符号表,阐述了这些不同调用方式对逆向分析者的挑战。结合实例代码的反汇编结果,直观展示了函数调用的可见性变化,以及如何利用这些差异进行有效的逆向工程策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我们知道一般的函数调用都会通过call的方式来调用,这样让攻击很容易对一个函数做手脚,如果是以inline的方式编译的会,会把该函数的code拷贝到每次调用该函数的地方。而static会让生成的二进制文件中没有清晰的符号表,让逆向的人很难弄清楚逻辑。

下面我们来看看一个普通函数及其反汇编代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int isValidate ( int id ) {
     if (id  >  5 )
         return  1 ;
     else
         return  0 ;
}

int main ( int argc ,  const  char  * argv [ ] )  {
     int id  =  3 ;
     int a = 1 ,b = 2 ,c = 3 ;
    
     if ( !isValidate (id ) )
         return  0 ;
    a  = b  + c ;
     if ( !isValidate (id ) )
         return  0 ;
    c  = a / 2  * b ;
     if ( !isValidate (id ) )
         return  0 ;
    b  = c  / a * 2 ;
     return  1 ;
}

编译,反汇编结果如下:

Snip20150118_6

这样可以很明显的看到isValidate的调用,而且很容易使用断点+commands的方法让其始终返回1.

下面使用inline的方式来编译:

1
int isValidate ( int id ) __attribute__  ( (always_inline ) ) ;

编译,反汇编结果如下:

Snip20150118_7

在每次调用的时候都会把代码拷贝一次。

再来看看static inline的方式来编译的反汇编代码:

1
static  int isValidate ( int id ) __attribute__  ( (always_inline ) ) ;

Snip20150118_8

 

现在没有符号表了。

 

本文链接:http://www.blogfshare.com/ioss-static-inline.html

转载提示:除非注明,AloneMonkey的文章均为原创,转载请以链接形式注明作者和出处。谢谢合作

#include<bits/stdc++.h> #define ll long long using namespace std; static const int N = 1e5+5; static ll a[N]; static ll len; static char ch[20]; static inline ll rd() { ll x = 0; char d = getchar_unlocked(); while (d < '0' || d > '9')d = getchar_unlocked(); while (d >= '0' && d <= '9') { x = (x << 3) + (x << 1) + (d ^ 48); d = getchar_unlocked(); } return x; } static inline void wr(ll x) { if (x == 0) { putchar_unlocked('0'); putchar_unlocked(' '); return; } while (x) { ch[len++] = x % 10 ^ 48; x /= 10; } while (len)putchar_unlocked(ch[--len]); putchar_unlocked(' '); } int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); static ll t, n, k, s; t = rd(); while (t--) { n = rd(), k = rd(); for (int i = 1; i <= n; i++) { a[i] = rd(); s ^= a[i]; } if (n % 2 == 1) { if (k >= 1)for (int i = 1; i <= n; i++)wr(s ^ a[i]); else for (int i = 1; i <= n; i++)wr(a[i]); } else { if (k % 2 == 1)for (int i = 1; i <= n; i++)wr(s ^ a[i]); else for (int i = 1; i <= n; i++)wr(a[i]); } putchar_unlocked('\n'); s = 0; } return 0; } #include <bits/stdc++.h> using namespace std; long long T, n; long long k; long long a[100007], b[100007]; inline void work(){ long long sum = 0; for(int i = 1; i <= n; i++) sum ^= a[i]; for(int i = 1; i <= n; i++) b[i] = sum ^ a[i]; } inline long long read(){ long long x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9'){ if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9'){ x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } return x * f; } int main(){ T = read(); while(T--) { n = read(), k = read(); for(int i = 1; i <= n; i++) a[i] = read(); if(n % 2 == 0 && k % 2 == 0){ for(int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl; continue; } work(); for(int i = 1; i <= n; i++) cout << b[i] << " "; cout << endl; } return 0; }为什么第一份代码总耗时700毫秒,第二份耗时1.2秒?static inline函数是否有优化作用
最新发布
08-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值