最近写的一些好玩的code小片段,与君共享
#include <stdlib.h>
#include <stdio.h>
#include <sys/mman.h>
#include <string.h>
#define PAGESIZE 4096
int main(int argc, char *argv[])
{
void *p1 = &&L1;
unsigned char *buf = calloc(sizeof(unsigned char),30);
void *aligned_addr = (char*)(((unsigned long)buf) & ~(PAGESIZE - 1));
int errno = mprotect(aligned_addr, PAGESIZE, PROT_WRITE | PROT_READ | PROT_EXEC);
if(errno != 0) {
printf("error %d:%s\n",errno,strerror(errno));
return errno;
}
unsigned int offset = (unsigned int)((unsigned long)p1 - (unsigned long)buf - 5);
buf[0] = '\xe9';
buf[1] = (unsigned char)(offset & 0xFF);
buf[2] = (unsigned char)(offset >> 8 & 0xFF);
buf[3] = (unsigned char)(offset >> 16 & 0xFF);
buf[4] = (unsigned char)(offset >> 24 & 0xFF);
asm volatile(
"jmp *%0\n\t"
:
:"r"((void *)buf)
);
goto L1;
return 0;
L1:
printf("hit L1,congratulation!\n");
return 0;
}
...全文
相关推荐
code_something:搞一些好玩的小东西
code_something自己试着 搞一些好玩的小东西http_toolc++ 内存池c++ 线程池Spider_TrainTicket 爬虫爬取火车票epoll + reactor 模式的服务器
君正Linux_开发指南
### 君正Linux开发指南知识点解析#### 一、概述**君正Linux开发指南**是一份详尽的文档,旨在指导用户如何针对君正半导体的不同硬件平台进行Linux系统的开发与调试工作。
君正Linux_开发指南.pdf
- 2009.08.17 (0.2): 添加了关于jz4750d(jz4755)的相关内容,并介绍了使用SD卡烧录整个系统的方法;同时删除了与jdi相关的内容。
vscode-snippets:VS Code的一些便捷片段
该博客介绍了名为'snippets'的Visual Studio Code扩展,用于提供JavaScript、TypeScript和Svelte语言的代码片段功能。此扩展由Joxtacy发布,版本为0
片段生成器::high_voltage:Sublime Text,Atom&VS Code片段生成器
与Sublime Text类似,VS Code的片段存储在`.json`文件中,如`snippets.json`。


