Created
October 7, 2015 13:01
-
-
Save ytlvy/77b440a0e94ad2bf0083 to your computer and use it in GitHub Desktop.
OSX裸函数应用实战
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.m | |
// debug | |
// | |
// Created by piao on 15/7/20. | |
// Copyright (c) 2015年 piao. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
__attribute__((naked)) uint64_t getRbp() | |
{ | |
__asm__("mov %rbp, %rax\n\n\r" | |
"ret"); | |
} | |
// 嘿嘿,shellcode经常用到滴... | |
__attribute__((naked)) uint64_t getRip() | |
{ | |
__asm__("call 0f\n\n\r" | |
"0:pop %rax\n\n\r" | |
//"sub $5, %rax\n\n\r" // 减去指令长度 | |
"ret"); | |
} | |
__attribute__((naked)) uint64_t getRsp() | |
{ | |
__asm__("mov %rsp, %rax\n\n\r" | |
"ret"); | |
} | |
void piaoyun(){ | |
NSLog(@"[++++]一层返回 = %llx", getRip() - 5); | |
NSLog(@"[++++]二层返回 = %llx", *(uint64_t *)(getRbp() + 0x8)); | |
} | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
piaoyun(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment