c运行时库 linux,Linux 不使用 chroot 临时替换C运行时库

#include

#include

#include

#include

int

main (int argc, char *argv[])

{

int i;

char buf[1024], path[1024];

char *str, *root, *args[512];

/* get FAKE_ROOT */

root = getenv ("FAKE_ROOT");

if (!root) {

fprintf (stderr, "Please set environment FAKE_ROOT!\n");

return -1;

}

/* export PATH */

str = getenv ("PATH");

if (!str) {

fprintf (stderr, "Get environment PATH failed!\n");

return -2;

}

if (NULL == strstr (str, root)) {

strcpy (buf, root);

strcat (buf, "/bin:");

strcat (buf, str);

if (0 != setenv ("PATH", buf, 1)) {

fprintf (stderr, "Set environment PATH failed!\n");

return -3;

}

}

/* export LD_PRELOAD */

strcpy (buf, root);

strcat (buf, "/lib64/libfakemain.so");

if (0 != setenv ("LD_PRELOAD", buf, 1)) {

fprintf (stderr, "Set environment LD_PRELOAD failed!\n");

return -4;

}

/* export LD_LIBRARY_PATH */

strcpy (buf, root);

strcat (buf, "/lib64");

if (0 != setenv ("LD_LIBRARY_PATH", buf, 1)) {

fprintf (stderr, "Set environment LD_LIBRARY_PATH failed!\n");

return -5;

}

/* set new path */

strcpy (path, root);

strcat (path, "/lib64/ld-2.20.so");

args[0] = path;

/* set real program path */

strcpy (buf, root);

strcat (buf, "/bin/");

strcat (buf, argv[0]);

strcat (buf, ".bin");

args[1] = buf;

/* copy arguments */

for (i=1; i

args[i+1] = argv[i];

args[i+1] = NULL;

/* run real program */

return execv (path, args);;

}

#include

#include

#include

#include

int

main (int argc, char *argv[])

{

int i;

char buf[1024], path[1024];

char *str, *root, *args[512];

/* get FAKE_ROOT */

root = getenv ("FAKE_ROOT");

if (!root) {

fprintf (stderr, "Please set environment FAKE_ROOT!\n");

return -1;

}

/* export PATH */

str = getenv ("PATH");

if (!str) {

fprintf (stderr, "Get environment PATH failed!\n");

return -2;

}

if (NULL == strstr (str, root)) {

strcpy (buf, root);

strcat (buf, "/bin:");

strcat (buf, str);

if (0 != setenv ("PATH", buf, 1)) {

fprintf (stderr, "Set environment PATH failed!\n");

return -3;

}

}

/* export LD_PRELOAD */

strcpy (buf, root);

strcat (buf, "/lib64/libfakemain.so");

if (0 != setenv ("LD_PRELOAD", buf, 1)) {

fprintf (stderr, "Set environment LD_PRELOAD failed!\n");

return -4;

}

/* export LD_LIBRARY_PATH */

strcpy (buf, root);

strcat (buf, "/lib64");

if (0 != setenv ("LD_LIBRARY_PATH", buf, 1)) {

fprintf (stderr, "Set environment LD_LIBRARY_PATH failed!\n");

return -5;

}

/* set new path */

strcpy (path, root);

strcat (path, "/lib64/ld-2.20.so");

args[0] = path;

/* set real program path */

strcpy (buf, root);

strcat (buf, "/bin/");

strcat (buf, argv[0]);

strcat (buf, ".bin");

args[1] = buf;

/* copy arguments */

for (i=1; i

args[i+1] = argv[i];

args[i+1] = NULL;

/* run real program */

return execv (path, args);;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值