bool SpecialCaseList::inSection(StringRef Section, StringRef Prefix, StringRef Query, StringRef Category) const { assert(IsCompiled && "SpecialCaseList::compile() was not called!"); for (auto &SectionIter : Sections) if (SectionIter.SectionMatcher->match(Section) && inSection(SectionIter.Entries, Prefix, Query, Category)) return true; return false; }
void Message::innerDisplay(std::string name, struct netField *message) { uint8_t field= 0; struct netField *nf= message; if (hasSub) { while( nf->type != MP_END) { field++; switch(nf->type) { case MP_ARRAYFIXED: case MP_ARRAY_VAR_SMALL: case MP_ARRAY_VAR_LARGE: case MP_OPTIONAL: { uint32_t addr; if (inSection(&secRdata, nf->refTypeDef)) addr= f2v(&secRdata, nf->refTypeDef); else addr= f2v(&secData, nf->refTypeDef); std::stringstream ss; ss << name << '_' << std::hex << (uint32_t)field; innerDisplay(ss.str(), (struct netField *)addr); } break; default: break; } nf++; } } std::cout << "struct netFieldI " << name << "[] = {" << std::endl; decodeFields(name, message); }
bool BlackList::isIn(const Module &M) { return inSection("src", M.getModuleIdentifier()); }
bool BlackList::isIn(const GlobalVariable &G) { return isIn(*G.getParent()) || inSection("global", G.getName()); }
bool BlackList::isIn(const Function &F) { return isIn(*F.getParent()) || inSection("fun", F.getName()); }
bool BlackList::isInInit(const GlobalVariable &G) { return (isIn(*G.getParent()) || inSection("global-init", G.getName()) || inSection("global-init-type", GetGVTypeString(G))); }
int main(int argc, char *argv[]) { bfd *tmp_bfd = NULL; bfd_byte *p; uint32_t *call; uint32_t *rcv; uint32_t *snd; uint8_t rcvCount; uint8_t sndCount; uint32_t *scan; MessageMap msgs; if (argc < 2) { printf("Specify filename\n"); exit(1); } tmp_bfd = bfd_openr (argv[1], NULL); if (tmp_bfd == NULL) { printf ("Error openning file"); exit(1); } //check if the file is in format if (!bfd_check_format (tmp_bfd, bfd_object)) { if (bfd_get_error () != bfd_error_file_ambiguously_recognized) { printf("Incompatible format\n"); exit(1); } } secText.sec = bfd_get_section_by_name(tmp_bfd, ".text"); bfd_malloc_and_get_section(tmp_bfd, secText.sec, &secText.data); secRdata.sec = bfd_get_section_by_name(tmp_bfd, ".rdata"); if (!secRdata.sec) { printf("Failed to get section\n"); exit(10); } if (!bfd_malloc_and_get_section(tmp_bfd, secRdata.sec, &secRdata.data)) { printf("Alloc error\n"); exit(10); } secData.sec = bfd_get_section_by_name(tmp_bfd, ".data"); if (!secData.sec) { printf("Failed to get section\n"); exit(10); } if (!bfd_malloc_and_get_section(tmp_bfd, secData.sec, &secData.data)) { printf("Alloc error\n"); exit(10); } /* 406060: 68 40 6f 0e 01 push $0x10e6f40 406065: 6a 06 push $0x6 406067: 68 38 6f 0e 01 push $0x10e6f38 40606c: 6a 02 push $0x2 40606e: 33 d2 xor %edx,%edx 406070: 33 c9 xor %ecx,%ecx 406072: e8 e9 16 5e 00 call 0x9e7760 */ for(p= secText.data; p < secText.data+bfd_section_size(tmp_bfd, secText.sec); p++) { if ( p< secText.data+bfd_section_size(tmp_bfd, secText.sec)-22 && isMsgRegister(p, &rcv, &rcvCount, &snd, &sndCount, &call) ) { uint8_t i; bfd_vma dest; scan= NULL; if (rcvCount) { if (inSection(&secRdata, (bfd_vma)rcv)) rcv= (uint32_t *)f2v(&secRdata, (uint32_t)rcv); else rcv= (uint32_t *)f2v(&secData, (uint32_t)rcv); scan= rcv; } if (sndCount) { if (inSection(&secRdata, (bfd_vma)snd)) snd= (uint32_t *)f2v(&secRdata, (uint32_t)snd); else snd= (uint32_t *)f2v(&secData, (uint32_t)snd); scan= snd; } char *text= NULL; char *clitext= NULL; if (scan) { for(uint32_t *cp = scan-0x200; cp < scan; cp++) { char *p; if ((p=strstr((char *)cp, ".cpp")) == NULL) continue; while(*p != '\\') p--; text= &p[1]; if (strstr(text, "Cli")) clitext= text; } if (!text) { printf("Name missing\n"); exit(1); } } #if 0 if (clitext) text= clitext; #endif if (rcvCount) { rcvCount *= 2; for(i=0; i< rcvCount; i++) { if ( !(i%2) && !inSection(&secData, rcv[i]) && !inSection(&secRdata, rcv[i])) { //printf("Not in (r)data section\n"); goto next; } if ( (i%2) && !inSection(&secText, rcv[i])) { //printf("Not in text section 0x%p\n", rcv[i]); goto next; } } for(i=0; i< rcvCount; i+=2) { struct netField *nf= (struct netField *) f2v(&secData, rcv[i]); msgs.insert( MessageEntry(call, Message(text,nf, true) )); } } if (sndCount) { for(i=0; i< sndCount; i++) { if ( !inSection(&secData, snd[i])) goto next; } for(i=0; i< sndCount; i++) { struct netField *nf= (struct netField *) f2v(&secData, snd[i]); msgs.insert( MessageEntry(call, Message(text,nf, false) )); } } } next:; } std::cout << "#ifndef PACKETS_H\n" << "#define PACKETS_H\n" << "#include \"netfield.hpp\"\n" << std::endl; for(MessageMap::iterator m = msgs.begin(); m != msgs.end(); ++m) { Message msg = m->second; msg.display(); } // Server Messages uint32_t *oldcall= NULL; for(MessageMap::iterator m = msgs.begin(); m != msgs.end(); ++m) { uint32_t *call = m->first; Message msg = m->second; if (!msg.isServer) continue; if (oldcall != call) { if (oldcall) std::cout << "\tNULL" << "};\n\n"; std::cout << "struct netFieldI *serverMsgPack_" << msg.getBasicName() << "[] = {" << std::endl; oldcall = call; } std::cout << "\t" << msg.getName() << "," << std::endl; } std::cout << "\tNULL\n" <<"};\n\n" << std::endl; // Client Messages oldcall= NULL; for(MessageMap::iterator m = msgs.begin(); m != msgs.end(); ++m) { uint32_t *call = m->first; Message msg = m->second; if (msg.isServer) continue; if (oldcall != call) { if (oldcall) std::cout << "\tNULL" << "};\n\n"; std::cout << "struct netFieldI *clientMsgPack_" << msg.getBasicName() << "[] = {" << std::endl; oldcall = call; } std::cout << "\t" << msg.getName() << "," << std::endl; } std::cout << "\tNULL\n" <<"};\n\n" << "#endif" << std::endl; return 0; }