C++函数签名解析
2013-06-05 22:55
543 查看
2013-11-29实际上不同这么烦锁,直接用objdump-C或者c++filesourcefile就行了
orgmangle
首选
vtable重构,使用下个脚本
orgmangle
首选
#!/bin/sh elfname=$1 objname=$2 targetname="" thispid=$$ filename=/tmp/jerry.${thispid} rm-f$filename case$elfnamein *.[sS]) targetname=$elfname; ;; *) objdump-D-z$elfname>${elfname}.s; targetname=${elfname}.s; ;; esac sed-n-e'/'${objname}'/p'$targetname|awk'{print$NF}'|sed-n-e's/<\(.*\)>\(.*\)/\1/p'|sort-d|uniq>>$filename forlinein`sed-n-e'p'$filename` do dename=`c++filt$line` sed-i-e's/'"${line}"'/'"${line}"'\t'"${dename}"'/'${targetname} done rm-f$filename
vtable重构,使用下个脚本
#!/bin/bash filename=$1 startline=$2 endline=$3 #vtable_parse自己写了二进制程序,参见下边 temp=`./vtable_parse$filename$startline$endline` mv$temp$filename
//Makefile PPFLAGS=-I./include vtable_parse:vtable.cppvfile.cppbasic_info.cpp g++$(CPPFLAGS)-g$^-o$@
//./include/basic_info.h #ifndef__JERRY_BASIC_INFO #define__JERRY_BASIC_INFO #include<iostream> #include<fstream> #include<unistd.h> #include<sys/types.h> #include<string.h> #include<stdlib.h> usingnamespacestd; classBASIC_INFO { private: char*strpid; char*infilename; char*outfilename; unsignedintstart_line; unsignedintend_line; BASIC_INFO(constBASIC_INFO&); BASIC_INFO&operator=(constBASIC_INFO&); voidpid_str(char**thiz,intvalue,intbase); public: BASIC_INFO(void); BASIC_INFO(constchar*myinfile,constchar*mystartline,constchar*myendline); ~BASIC_INFO(void); voidstr_new(char**thiz,intlength); voidint_to_str(char*thiz,intvalue,intbase); unsignedintstr_to_int(constchar*thiz,intbase); char*getinfilename(void)const; unsignedintgetstart_line(void)const; unsignedintgetend_line(void)const; char*getoutfilename(void)const; }; #endif
//./include/vfile.h #ifndef__JERRY_VFILE #define__JERRY_VFILE #include<basic_info.h> classVFILE:publicBASIC_INFO { #defineinfile_open_mode(std::ios_base::in) #defineoutfile_open_mode(std::ios_base::out) private: ifstreaminfile; ofstreamoutfile; char*alloc_pool; char*alloc_use_end; unsignedintpool_last; unsignedintstart_label; unsignedintstart_line; unsignedintend_line; voidinfile_read(void); voidoutfile_write(void); voidfile_fix_changed(intline_num); intget_label(void); voidskip_blank(char**ptr); unsignedintlength_to_blank(constchar*src); voidcopy_to_blank(char**src); voidskip_to_punc(char**ptr,charvalue); intis_line_end(char*ptr); VFILE(void); VFILE(constVFILE&); public: VFILE(constchar*myinfilename,constchar*mystartline, constchar*myendline); voidparse_file(void); voidformat_alloc(void); voidparse_write(void); voidlast_write(void); ~VFILE(void); }; #endif
//vtable.cpp #include<basic_info.h> #include<vfile.h> intmain(intargc,char*argv[]) { VFILEvtable(argv[1],argv[2],argv[3]); vtable.parse_file(); vtable.format_alloc(); vtable.parse_write(); vtable.last_write(); cout<<vtable.getoutfilename()<<endl; return0; }
//basic_info.cpp #include<basic_info.h> BASIC_INFO::BASIC_INFO(void): strpid(NULL),infilename(NULL),outfilename(NULL), start_line(0),end_line(0){} BASIC_INFO::BASIC_INFO(constchar*myinfile,constchar*mystartline,constchar*myendline): strpid(NULL),infilename(NULL),outfilename(NULL), start_line(0),end_line(0) { str_new(&strpid,32); pid_str(&strpid,getpid(),10); str_new(&infilename,strlen(myinfile)+1); strcpy(infilename,myinfile); str_new(&outfilename,strlen("/tmp/")+strlen(infilename)+strlen(strpid)+1); strcpy(outfilename,"/tmp/"); strcat(outfilename,infilename); strcat(outfilename,strpid); start_line=str_to_int(mystartline,10); end_line=str_to_int(myendline,10); } BASIC_INFO::~BASIC_INFO(void) { delete[]strpid; delete[]infilename; delete[]outfilename; strpid=NULL; infilename=NULL; outfilename=NULL; start_line=0; end_line=0; } voidBASIC_INFO::pid_str(char**thiz,intvalue,intbase) { intpid_seq=getpid(); int_to_str(*thiz,value,base); } voidBASIC_INFO::str_new(char**thiz,intlength) { if(*thiz!=NULL) delete[](*thiz); *thiz=newchar[length]; if(*thiz==NULL) { cout<<"allocatefailed"<<endl; exit(1); } } voidBASIC_INFO::int_to_str(char*thiz,intvalue,intbase) { char*temp=NULL; str_new(&temp,32); char*start=temp; while(value) { *temp++="0123456789abcdef"[value%base]; value=value/base; } *temp=0; while(--temp>=start) { *thiz++=*temp; } *thiz=0; delete[]start; } unsignedintBASIC_INFO::str_to_int(constchar*thiz,intbase) { unsignedinttemp=0; while(*thiz) { if(!isalnum(*thiz)) break; if(0<=*thiz&&*thiz<='9') temp=(*thiz-'0')+temp*base; if('a'<=*thiz&&*thiz<='f') temp=(*thiz-'a'+10)+temp*base; if('A'<=*thiz&&*thiz<='F') temp=(*thiz-'A'+10)+temp*base; thiz++; } returntemp; } char*BASIC_INFO::getinfilename(void)const { returninfilename; } unsignedintBASIC_INFO::getstart_line(void)const { returnstart_line; } unsignedintBASIC_INFO::getend_line(void)const { returnend_line; } char*BASIC_INFO::getoutfilename(void)const { returnoutfilename; }
//vtable.cpp #include"vfile.h" VFILE::VFILE(void){} VFILE::VFILE(constVFILE&){} VFILE::VFILE(constchar*myinfilename,constchar*mystartline,constchar*myendline): BASIC_INFO(myinfilename,mystartline,myendline), alloc_pool(NULL),start_label(0) { infile.open(getinfilename(),infile_open_mode); outfile.open(getoutfilename(),outfile_open_mode); if(NULL==infile||NULL==outfile) { cout<<"openfilefailed"<<endl; exit(1); } infile.unsetf(ios::skipws); start_line=getstart_line(); end_line=getend_line(); start_label=get_label(); } VFILE::~VFILE(void) { if(infile) infile.close(); if(outfile) outfile.close(); if(alloc_pool) delete[]alloc_pool; alloc_pool=NULL; } voidVFILE::infile_read(void) { infile.getline(alloc_pool,300); } voidVFILE::outfile_write(void) { outfile<<alloc_pool; } voidVFILE::file_fix_changed(intline_num) { if(line_num) { inti=0; for(i=0;i<line_num;i++) { if(!infile.eof()) { infile_read(); outfile_write(); outfile<<'\n'; } } } else { while(!infile.eof()) { infile_read(); outfile_write(); outfile<<'\n'; } } } intVFILE::get_label(void) { str_new(&alloc_pool,300); file_fix_changed(start_line); inttemp=str_to_int(alloc_pool,16); delete[]alloc_pool; alloc_pool=NULL; returntemp; } voidVFILE::skip_blank(char**ptr) { char*temp=*ptr; while(isblank(*temp++)) *ptr=*ptr+1; } unsignedintVFILE::length_to_blank(constchar*src) { unsignedintlength=0; while((!isblank(*src))&&(*src!=0)) { length++; src++; } //while(!isblank(*src++)) //length++; returnlength; } voidVFILE::copy_to_blank(char**src) { unsignedintlength=length_to_blank(*src); if(length>pool_last) { char*temp=newchar[strlen(alloc_pool)+1+50]; strcpy(temp,alloc_pool); delete[]alloc_pool; alloc_pool=temp; alloc_use_end=alloc_pool+strlen(alloc_pool)+1; pool_last=pool_last+50; } pool_last=pool_last-length; for(inti=0;i<length;i++) { *alloc_use_end++=**src; *src=*src+1; } *alloc_use_end=0; } voidVFILE::skip_to_punc(char**ptr,charvalue) { char*temp=*ptr; while(*temp++!=value) *ptr=*ptr+1; *ptr=*ptr+1; } intVFILE::is_line_end(char*ptr) { char*temp=ptr; if(isblank(*temp)&&isblank(*(temp+1))) return1; return0; } voidVFILE::parse_file(void) { pool_last=300; str_new(&alloc_pool,pool_last+1); *alloc_pool=0; alloc_use_end=alloc_pool; char*temp=NULL; str_new(&temp,300); char*temp_start=temp; for(unsignedintline=start_line+1;line<=end_line;line++) { infile.getline(temp,300); skip_blank(&temp); skip_to_punc(&temp,':'); do { skip_blank(&temp); copy_to_blank(&temp); if(*temp==0||*(temp+1)==0) break; if(*temp=='\n'||*(temp+1)=='\n') break; }while(!is_line_end(temp)); } delete[]temp_start; temp=NULL; } voidVFILE::format_alloc(void) { unsignedintalloc_used=alloc_use_end-alloc_pool; alloc_use_end=alloc_pool; intadd_line=(alloc_used/8); char*temp=NULL; str_new(&temp,alloc_used+add_line*11+2); *temp=0; *(temp+alloc_used+add_line*11)='\n'; *(temp+alloc_used+add_line*11+1)=0; intlabel=start_label; for(inti=0;i<add_line;i++) { char*str_label=NULL; str_new(&str_label,32); *str_label=0; int_to_str(str_label,label,16); strcat(temp,""); strcat(temp,str_label); strcat(temp,":\t"); { charstr_array[8]; for(intk=3;k>=0;--k) { ((short*)str_array)[3-k]=((short*)alloc_use_end)[k]; } strncpy(str_label,str_array,8); } alloc_use_end+=8; *(str_label+8)='\n'; *(str_label+9)=0; strcat(temp,str_label); delete[]str_label; label=label+4; } delete[]alloc_pool; alloc_pool=temp; } voidVFILE::parse_write(void) { outfile_write(); } voidVFILE::last_write(void) { str_new(&alloc_pool,300); file_fix_changed(0); delete[]alloc_pool; alloc_pool=NULL; }
相关文章推荐
- C++中的函数签名
- C/C++ sizeof函数解析——解决sizeof求结构体大小的问题
- C++中虚函数解析
- c++中CreateEvent函数解析(1)
- C++使用static的错误:无法解析的外部符号、“static”不应在文件范围内定义的成员函数上使用
- C/C++常见无法解析外部函数及其对应Lib汇总 (最后更新日期 17 Nov 2010)
- C++中虚函数,结合例子解析,然后总结
- c++常见函数解析
- C++的const成员函数解析
- C++普通函数指针与成员函数指针实例解析
- C++中函数模板的用法详细解析
- C++ inline函数解析
- C++中的friend函数详细解析
- 解析C++中的字符串处理函数和指针
- [C++]next_permutation()函数解析
- C++ ODBC 函数报无法解析的外部函数错误的解决方法
- c++虚函数深度解析
- 一个基于QT的解析interproscan结果的C++成员函数
- C++ 虚函数经典深入解析 (good)
- c/c++字符串操作函数源码解析