c++实现加载so动态库中的资源
实例如下:
#include<stdio.h>
#include<dlfcn.h>
#include<stdlib.h>
#include<iostream>
//编译命令g++-m32EncodeOrDecode.cpp-ldl-oedcode
//名字通过nm-Dxxxxxx.so获取
usingnamespacestd;
intmain(intargc,char**argv){
void*handle=dlopen("./libpub_com_service.so",RTLD_LAZY);
if(!handle){
printf("openlibpuberror,dlerror=%s\n",dlerror());
return-1;
}
stringsrc="05d7151349b7fe9b54306d90f9c938b3";
stringdesKey="pub.%?d5";//58
printf("start..src=[%s].....size=[%d].\n",src.c_str(),src.size());
//encode
typedefstring(*encode_t)(conststringencodeSrc,conststringencodeKey);
encode_tencode=(encode_t)dlsym(handle,"_ZN10NS_PUB_API9DesEncodeESsSs");
if(!encode){
printf("notfoundencodefunction,dlerror=%s\n",dlerror());
dlclose(handle);
return-1;
}
stringencodeStr=encode(src,desKey);
printf("gettheencodefunctionsuccess..encodeStr=[%s].....size=[%d]\n",encodeStr.c_str(),encodeStr.size());
//decode
typedefbool(*decode_t)(conststringdecodeSrc,conststringdecodeKey,string&outResult);
decode_tdecode=(decode_t)dlsym(handle,"_ZN10NS_PUB_API9DesDecodeESsSsRSs");
if(!decode){
printf("notfounddecodefunction,dlerror=%s\n",dlerror());
dlclose(handle);
return-1;
}
stringdecodeOut;
boolret=decode(encodeStr,desKey,decodeOut);
printf("getthedecodefunctionsuccess...ret=[%d]...decodeOut=[%s].....size=[%d]\n",ret,decodeOut.c_str(),decodeOut.size());
//end
dlclose(handle);
return0;
}
以上就是小编为大家带来的c++实现加载so动态库中的资源全部内容了,希望大家多多支持毛票票~
热门推荐
10 朋友新年祝福语大全 简短
11 新年祝福语简短大方兔年
12 搬新家礼物祝福语简短
13 同学见面花束祝福语简短
14 五一假期祝福语幽默简短
15 离职欢送敬酒祝福语简短
16 对学弟的祝福语简短
17 考老师辞职祝福语简短
18 祝福语驱散霉运的话简短