- 论坛徽章:
- 0
|
原帖由 Godbach 于 2009-8-27 14:28 发表 ![]()
能不能将32位上编译出来的那个可执行文件直接放在64位上试一下?
mmap出错。。。
但是这个代码在64位系统上编译后,是可以成功的:
- #include <stdio.h>
- #include <sys/personality.h>
- #include <sys/mman.h>
- typedef void test();
- void testfn()
- {
- printf("testfn success\n");
- }
- int main(int argc, char **argv)
- {
- void *mem;
- //personality(PER_SVR4);
- if ((personality(0xffffffff)) != PER_SVR4) {
- mem = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
- if (mem != NULL) {
- /* for old kernels with SELinux that don't allow RWX anonymous mappings
- luckily they don't have NX support either ;) */
- mem = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
- if (mem != NULL) {
- fprintf(stdout, "UNABLE TO MAP ZERO PAGE!\n");
- return 1;
- }
- }
- } else {
- int ret = mprotect(NULL, 0x1000, PROT_READ | PROT_WRITE | PROT_EXEC);
- if (ret == -1) {
- fprintf(stdout, "UNABLE TO MPROTECT ZERO PAGE!\n");
- return 1;
- }
- }
- printf("success\n");
- *(char *)0 = '\x90';
- *(char *)1 = '\xe9';
- *(unsigned long *)2 = (unsigned long)&testfn - 6;
- ((test *)0)();
- return 0;
- }
复制代码 |
|