私はあなたの質問を理解していますが、とにかく助けてくれるのかどうかはわかりません。
$ cat printglobal.c
#include <stdio.h>
char *get();
int main(void)
{
printf("global value=%s\n",get());
return 0;
}
$ gcc printglobal.c -L. -lglobal -lget_orig -o a.out
01:グローバルポインタ
$ cat global.c
char mylongstring[] = "myname is nulled pointer";
$ gcc -fPIC -shared global.c -o libglobal.so
オリジナルライブラリ
$ cat get_orig.c
#include <stdio.h>
extern char * mylongstring;
char *get()
{
mylongstring = "get from orig";
return mylongstring;
}
$ gcc -fPIC -shared get_orig.c -o libget_orig.so -L. -lglobal
フェイクライブラリ
$ cat get_dup.c
#include <stdio.h>
extern char * mylongstring;
char *get()
{
mylongstring = "get from dup";
return mylongstring;
}
$ gcc -fPIC -shared get_dup.c -o libget_dup.so -L. -lglobal
グローバル変数の実際の消費者を含む
ファイル
コマンドotool出力
$ otool -L a.out
a.out:
libglobal.so (compatibility version 0.0.0, current version 0.0.0)
libget_orig.so (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)
実行a.out
$ DYLD_LIBRARY_PATH=./ ./a.out
global value=get from orig
ライブラリ置き換えは
$ cp /tmp/libget_dup.so libget_orig.so
$ DYLD_LIBRARY_PATH=./ ./a.out
global value=get from dup
ところで、私はそう.so
が本当に.dylib
Cのための誤った名称であるMACでこれをテストしていsuでないイントロスペクションを行います。しかし、変数を知っていれば、 'printf("%d "、the_var)'(int型以外は異なる変換型指定子を使用することができます)を簡単に行うことができます。 – Olaf
私が理解するところでは、これは 'LD_PRELOAD'によって可能になるはずです。グローバルな宣言「extern char * the_full_path_name;」(またはその正確な型が何であれ)を使用してシンボルをインポートし、それを印刷しようとしましたか? –
'-rdynamic'でプログラムをコンパイルしましたか? – jxh