void TileObjectDoodad::draw(Renderer &r, TileView &view, Vec2<float> screenPosition, TileViewMode mode) { std::ignore = view; // Mode isn't used as TileView::tileToScreenCoords already transforms according to the mode auto doodad = this->doodad.lock(); if (!doodad) { LogError("Called with no owning doodad object"); return; } sp<Image> sprite; Vec2<float> transformedScreenPos = screenPosition; switch (mode) { case TileViewMode::Isometric: sprite = doodad->getSprite(); transformedScreenPos -= doodad->getImageOffset(); break; case TileViewMode::Strategy: // no doodads on strategy view? return; default: LogError("Unsupported view mode"); } r.draw(sprite, transformedScreenPos); }
void cTabFile::performInternalCheck() { if(!getOffsetsCount()) { m_Valid = false; return; } int prev = -1; m_maxPackedImageSize = 0; for(int i = 0; i < getOffsetsCount(); ++i) { int next = getImageOffset(i); if(next <= prev) { clear(); return; } if (i>0) m_maxPackedImageSize = std::max(m_maxPackedImageSize, next - prev); prev = next; } m_Valid = true; }
bool NAmigaHunkDecoder::readHeader() { #ifdef DEBUG_VERBOSE DEBUG_OUT<<"amiga readHeader\n"; #endif // DEBUG_VERBOSE if(!checkSanity()) return false; #ifdef DEBUG_VERBOSE DEBUG_OUT<<"Amiga"; DEBUG_OUT<<" binary at "<<(ULONG)getImageOffset()<<"\n"; #endif // DEBUG_VERBOSE ld->getModule()->setNeedsReloc(true); LSB=false; offset=4; unsigned int nameLen=map->read32(offset+getImageOffset(),LSB); offset+=4; if(nameLen) { #ifdef DEBUG_VERBOSE DEBUG_OUT<<"nameLen="<<nameLen<<"\n"; #endif // DEBUG_VERBOSE offset+=4*nameLen; } numHunks=map->read32(offset+getImageOffset(),LSB); offset+=4; #ifdef DEBUG_VERBOSE DEBUG_OUT<<"numHunks="<<numHunks<<" "; #endif // DEBUG_VERBOSE unsigned int F=map->read32(offset+getImageOffset(),LSB); offset+=4; #ifdef DEBUG_VERBOSE DEBUG_OUT<<"F="<<F<<" "; #endif // DEBUG_VERBOSE unsigned int L=map->read32(offset+getImageOffset(),LSB); offset+=4; #ifdef DEBUG_VERBOSE DEBUG_OUT<<"L="<<L<<"\n"; #endif // DEBUG_VERBOSE offset+=(L-F+1)*4; return true; }
// Radix 2 fft (pad zeros if in source). kernel void makeimagedata( const int numberOfLines, // total number of lines in the sample. const int lineSize, // the number of vectors in a line, const int vectorSize, // the number of pixels in a vector. const int vectorDataPixelLength, // the length of a single pixel data. const int usecolormask, // if 1 then use the colormask. global float* colormask, // the mask to apply to the colors. // [RGBA_IMAGE_N_BYTES * vectorDataPixelLength * 3 or null] // the three diffrent data sets are for RGB values. global unsigned char* vectors, // the data source to read from. global unsigned char* imagedata // the image data to write to. ) { // active vector index. const int vectorIndex = get_global_id(0); // read the index. const int vecOffset = vectorIndex*vectorSize*vectorDataPixelLength; const int imgOffset = getImageOffset(vectorIndex, numberOfLines, lineSize, vectorSize); int veci = 0; int pixi = 0; // reading the vector data into the image data. for (veci = 0; veci < vectorSize; veci++) { int vpi = vecOffset + veci*vectorDataPixelLength; // the vector pixel index. int imgi = imgOffset + veci*RGBA_IMAGE_N_BYTES; if (usecolormask == 1) { // Set the colormask and populate the image. //ApplyColorMaskAndPopulateImage(vpi, imgi, vectorDataPixelLength, colormask, vectors, imagedata); imagedata[imgi] = calculateMaskAvarage(0, vpi, vectorDataPixelLength, colormask, vectors); imagedata[imgi + 1] = calculateMaskAvarage(1, vpi, vectorDataPixelLength, colormask, vectors);; imagedata[imgi + 2] = calculateMaskAvarage(2, vpi, vectorDataPixelLength, colormask, vectors);; imagedata[imgi + 3] = 255; } else { // using avarage to calculate. unsigned char color = getGrayscaleColor(vpi, vectorDataPixelLength, vectors); imagedata[imgi] = color; imagedata[imgi + 1] = color; imagedata[imgi + 2] = color; imagedata[imgi + 3] = 255; } } }
bool NAmigaHunkDecoder::readSymbols(bool external) { AList *syms=map->getFirstModule()->getSymbols(); EMapSymbol *s=(EMapSymbol *)NULL; bool readingEntries=true; unsigned int n,num,type,ttype,t,val; char tname[100]; while(readingEntries) { n=map->read32(offset+getImageOffset(),LSB); offset+=4; if(n) { type=(n>>24)&0xff; n&=0xffffff; //DEBUG_OUT<<"symbol type "<<type<<" : "; for(t=0;t<n*4;t++) { tname[t]=map->read8(offset+getImageOffset()+t); //DEBUG_OUT<<tname[t]; } tname[n*4]=0; //DEBUG_OUT<<"\n"; offset+=n*4; // skip name switch(type) { case 0: // symbol val=map->read32(offset+getImageOffset(),LSB); offset+=4; if(external) ttype=EMAP_SYMBOL_EXTERN; else ttype=EMAP_SYMBOL_NORMAL; s=new EMapSymbol(tname,0,val,0,ttype,nextHunk-1); if(syms) syms->insert(s); break; case 1: // def case 2: // abs case 3: // res val=map->read32(offset+getImageOffset(),LSB); offset+=4; if(external) ttype=EMAP_SYMBOL_EXTERN; else ttype=EMAP_SYMBOL_NORMAL; s=new EMapSymbol(tname,0,val,0,ttype,nextHunk-1); if(syms) syms->insert(s); break; case 129: // 32-bit ref case 131: // 16-bit ref case 132: // 8-bit ref num=map->read32(offset+getImageOffset(),LSB); offset+=4; val=map->read32(offset+getImageOffset(),LSB); offset+=4; if(external) ttype=EMAP_SYMBOL_EXTERN; else ttype=EMAP_SYMBOL_RELOC; s=new EMapSymbol(tname,num,val,0,ttype,nextHunk-1); if(syms) syms->insert(s); offset+=num*4; // skip refs break; case 130: // common ref // first size of common block num=map->read32(offset+getImageOffset(),LSB); offset+=4; // then num of refs in it val=map->read32(offset+getImageOffset(),LSB); offset+=4; if(external) ttype=EMAP_SYMBOL_EXTERN; else ttype=EMAP_SYMBOL_NORMAL; s=new EMapSymbol(tname,0,val,num,ttype,nextHunk-1); if(syms) syms->insert(s); offset+=num*4; // skip refs break; default: DEBUG_OUT<<"unknown symbol type...bailing!\n"; readingEntries=false; break; } } else readingEntries=false; }
bool NAmigaHunkDecoder::readNodes() { unsigned int hunkType=0; unsigned int hunkSize=0; bool reading=true; unsigned int hunkCount=0; ULONG loc=0; NBinaryNode *n=(NBinaryNode *)NULL; nextHunk=0; while(reading) { hunkType=map->read32(offset+getImageOffset(),LSB); offset+=4; #ifdef DEBUG_VERBOSE DEBUG_OUT<<hunkType<<" "; #endif // DEBUG_VERBOSE switch(hunkType) { case 0x3e7: #ifdef DEBUG_VERBOSE DEBUG_OUT<<"hunk_unit\n"; #endif // DEBUG_VERBOSE hunkSize=map->read32(offset+getImageOffset(),LSB); offset+=4; hunkSize&=0x3fffffff; // strip any "ATOM" bits if any... #ifdef DEBUG_VERBOSE DEBUG_OUT<<"nameLen="<<hunkSize<<"\n"; #endif // DEBUG_VERBOSE offset+=hunkSize*4; break; case 0x3e8: #ifdef DEBUG_VERBOSE DEBUG_OUT<<"hunk_name\n"; #endif // DEBUG_VERBOSE hunkSize=map->read32(offset+getImageOffset(),LSB); offset+=4; hunkSize&=0x3fffffff; // strip any "ATOM" bits if any... #ifdef DEBUG_VERBOSE DEBUG_OUT<<"nameLen="<<hunkSize<<"\n"; #endif // DEBUG_VERBOSE offset+=hunkSize*4; break; case 0x3e9: #ifdef DEBUG_VERBOSE DEBUG_OUT<<"hunk_code\n"; #endif // DEBUG_VERBOSE hunkSize=map->read32(offset+getImageOffset(),LSB); offset+=4; hunkSize&=0x3fffffff; // strip any "ATOM" bits if any... loc=offset; n=new NBinaryNode("code",hunkCount,N_BIN_PROGBITS,loc,hunkSize*4,offset,E_MEM_ALL); if(n) ld->getModule()->getNodes()->append(n); else { std::cerr<<"Didn't get NBinaryNode!\n"; exit(5); } offset+=hunkSize*4; hunkCount++; nextHunk++; break; case 0x3ea: #ifdef DEBUG_VERBOSE DEBUG_OUT<<"hunk_data\n"; #endif // DEBUG_VERBOSE hunkSize=map->read32(offset+getImageOffset(),LSB); offset+=4; hunkSize&=0x3fffffff; // strip any "ATOM" bits if any... loc=offset; n=new NBinaryNode("data",hunkCount,N_BIN_PROGBITS,loc,hunkSize*4,offset,E_MEM_READ|E_MEM_WRITE); if(n) ld->getModule()->getNodes()->append(n); else { std::cerr<<"Didn't get NBinaryNode!\n"; exit(5); } offset+=hunkSize*4; hunkCount++; nextHunk++; break; case 0x3eb: #ifdef DEBUG_VERBOSE DEBUG_OUT<<"hunk_bss\n"; #endif // DEBUG_VERBOSE hunkSize=map->read32(offset+getImageOffset(),LSB); offset+=4; hunkSize&=0x3fffffff; // strip any "ATOM" bits if any... loc=offset; n=new NBinaryNode("bss",hunkCount,N_BIN_NOBITS,loc,hunkSize*4,0,E_MEM_READ|E_MEM_WRITE); if(n) ld->getModule()->getNodes()->append(n); else { std::cerr<<"Didn't get NBinaryNode!\n"; exit(5); } hunkCount++; nextHunk++; break; case 0x3ec: #ifdef DEBUG_VERBOSE DEBUG_OUT<<"hunk_reloc32\n"; #endif // DEBUG_VERBOSE hunkSize=1; // not really, but it can't be zero readReloc(32); break; case 0x3ed: #ifdef DEBUG_VERBOSE DEBUG_OUT<<"hunk_reloc16\n"; #endif // DEBUG_VERBOSE hunkSize=1; // not really, but it can't be zero readReloc(16); break; case 0x3ee: #ifdef DEBUG_VERBOSE DEBUG_OUT<<"hunk_reloc8\n"; #endif // DEBUG_VERBOSE hunkSize=1; // not really, but it can't be zero readReloc(8); break; case 0x3ef: #ifdef DEBUG_VERBOSE DEBUG_OUT<<"hunk_ext\n"; #endif // DEBUG_VERBOSE hunkSize=1; // not really, but it can't be zero readSymbols(true); break; case 0x3f0: #ifdef DEBUG_VERBOSE DEBUG_OUT<<"hunk_symbol\n"; #endif // DEBUG_VERBOSE hunkSize=1; // not really, but it can't be zero readSymbols(false); break; case 0x3f1: #ifdef DEBUG_VERBOSE DEBUG_OUT<<"hunk_debug\n"; #endif // DEBUG_VERBOSE hunkSize=map->read32(offset+getImageOffset(),LSB); offset+=4; hunkSize&=0x3fffffff; // strip any "ATOM" bits if any... loc=offset; n=new NBinaryNode("debug",0,N_BIN_NOBITS,loc,hunkSize*4,0,E_MEM_READ|E_MEM_WRITE); if(n) ld->getModule()->getNodes()->append(n); else { std::cerr<<"Didn't get NBinaryNode!\n"; exit(5); } offset+=hunkSize*4; break; case 0x3f2: #ifdef DEBUG_VERBOSE DEBUG_OUT<<"hunk_end\n"; #endif // DEBUG_VERBOSE hunkSize=1; // not really, but it can't be zero numHunks--; break; case 0x3f6: #ifdef DEBUG_VERBOSE DEBUG_OUT<<"hunk_break\n"; #endif // DEBUG_VERBOSE hunkSize=1; // not really, but it can't be zero break; default: DEBUG_OUT<<"unknown hunk type...bailing!\n"; reading=false; break; } if(!numHunks) reading=false; } return true; }
bool NElfDecoder::readHeader() { #ifdef DEBUG_VERBOSE DEBUG_OUT<<"elf readHeader\n"; #endif // DEBUG_VERBOSE if(!checkSanity()) return false; #ifdef DEBUG_VERBOSE DEBUG_OUT<<"ELF"; if(bitness==64) DEBUG_OUT<<"64"; else DEBUG_OUT<<"32"; DEBUG_OUT<<" binary at "<<(ULONG)getImageOffset()<<"\n"; #endif // DEBUG_VERBOSE offset=5; LSB=false; if(map->read8(offset+getImageOffset())==1) LSB=true; offset=16; // Skip rest of magic number, etc. ftype=map->read16(offset+getImageOffset(),LSB); offset+=2; arch=map->read16(offset+getImageOffset(),LSB); offset+=2; unsigned int vers=map->read32(offset+getImageOffset(),LSB); offset+=4; if(bitness==64) { ld->setEntry(map->read64(offset+getImageOffset(),LSB)); offset+=8; fphoff=map->read64(offset+getImageOffset(),LSB); offset+=8; fshoff=map->read64(offset+getImageOffset(),LSB); offset+=8; } else { ld->setEntry(map->read32(offset+getImageOffset(),LSB)); offset+=4; fphoff=map->read32(offset+getImageOffset(),LSB); offset+=4; fshoff=map->read32(offset+getImageOffset(),LSB); offset+=4; } unsigned int flags=map->read32(offset+getImageOffset(),LSB); offset+=4; unsigned int hsize=map->read16(offset+getImageOffset(),LSB); offset+=2; fphsize=map->read16(offset+getImageOffset(),LSB); offset+=2; fphnum=map->read16(offset+getImageOffset(),LSB); offset+=2; fshsize=map->read16(offset+getImageOffset(),LSB); offset+=2; fshnum=map->read16(offset+getImageOffset(),LSB); offset+=2; fstind=map->read16(offset+getImageOffset(),LSB); offset+=2; ld->setUnknown(false); switch(ftype) { case 1: #ifdef DEBUG_VERBOSE DEBUG_OUT<<"REL"; #endif // DEBUG_VERBOSE break; case 2: #ifdef DEBUG_VERBOSE DEBUG_OUT<<"EXEC"; #endif // DEBUG_VERBOSE break; case 3: #ifdef DEBUG_VERBOSE DEBUG_OUT<<"DYN"; #endif // DEBUG_VERBOSE break; case 4: #ifdef DEBUG_VERBOSE DEBUG_OUT<<"CORE"; #endif // DEBUG_VERBOSE break; case 16: #ifdef DEBUG_VERBOSE DEBUG_OUT<<"REL?"; #endif // DEBUG_VERBOSE break; default: #ifdef DEBUG_VERBOSE DEBUG_OUT<<"Unknown class (#"<<ftype<<")"; #endif // DEBUG_VERBOSE ld->setUnknown(true); break; } ld->setNeedsReloc(false); if(ftype==1) ld->setNeedsReloc(true); #ifdef DEBUG_VERBOSE DEBUG_OUT<<", "; DEBUG_OUT<<archString()<<"\n"; #endif // DEBUG_VERBOSE if(ld->getUnknown()) { DEBUG_OUT<<"ELF file format error!\n"; //return; } #ifdef DEBUG_VERBOSE DEBUG_OUT<<"Header, Entry at "<<ld->getEntry()<<"\n"; DEBUG_OUT<<"phof="<<fphoff<<" phsz="<<fphsize<<" phnm="<<fphnum<<"\n"; DEBUG_OUT<<"shof="<<fshoff<<" shsz="<<fshsize<<" shnm="<<fshnum<<"\n"; DEBUG_OUT<<"stind="<<fstind<<"\n"; #endif // DEBUG_VERBOSE return true; }
bool NElfDecoder::handleSymbols(NBinaryNode *n) { if(!n) { DEBUG_OUT<<"handleSymbols...NULL node!\n"; err.set(); return false; } unsigned int nsyms=0; if(bitness==32) nsyms=n->size/16; else nsyms=n->size/24; #ifdef DEBUG_VERBOSE DEBUG_OUT<<"handleSymbols for node "<<n->num<<" has "<<nsyms<<" symbols...\n"; #endif // DEBUG_VERBOSE if(bitness==32) offset=n->val+24; else offset=n->val+40; DEBUG_OUT<<"(offset is "<<offset<<")\n"; unsigned int shlink=map->read32(offset+getImageOffset(),LSB); offset+=4; unsigned int shinfo=map->read32(offset+getImageOffset(),LSB); offset+=4; DEBUG_OUT<<"shlink="<<shlink<<" shinfo="<<shinfo<<"\n"; if(!shlink) { DEBUG_OUT<<"shlink was zero, probably not right, giving up...\n"; return false; } NBinaryNode *strings=ld->findNode(shlink); if(strings) { #ifdef DEBUG_VERBOSE DEBUG_OUT<<"Associated strings in node "<<strings->num<<"...\n"; #endif // DEBUG_VERBOSE } else DEBUG_OUT<<"Couldn't find strings for those symbols!\n"; bool working=true; unsigned int stname,stinfo,stother,stind,stbind,sttype; ULONG stvalue,stsize; offset=n->getOffsetToData(); EMapSymbol *s=(EMapSymbol *)NULL; AList *syms=map->getFirstModule()->getSymbols(); for(unsigned int t=0;t<nsyms;t++) { stname=map->read32(offset+getImageOffset(),LSB); offset+=4; if(bitness==32) { stvalue=map->read32(offset+getImageOffset(),LSB); offset+=4; stsize=map->read32(offset+getImageOffset(),LSB); offset+=4; stinfo=map->read8(offset+getImageOffset()); offset+=1; stother=map->read8(offset+getImageOffset()); offset+=1; stind=map->read16(offset+getImageOffset(),LSB); offset+=2; } else { stinfo=map->read8(offset+getImageOffset()); offset+=1; stother=map->read8(offset+getImageOffset()); offset+=1; stind=map->read16(offset+getImageOffset(),LSB); offset+=2; stvalue=map->read64(offset+getImageOffset(),LSB); offset+=8; stsize=map->read64(offset+getImageOffset(),LSB); offset+=8; } stbind=(stinfo>>4)&0xf; sttype=stinfo&0xf; DEBUG_OUT<<"#"<<t<<" stname="<<stname<<" stvalue="<<stvalue<<" stsize="<<stsize<<" stbind="<<stbind<<" stind="<<stind<<" "; unsigned int symType=EMAP_SYMBOL_NORMAL; switch(sttype) { case 0: // No type DEBUG_OUT<<"sttype is No Type.\n"; break; case 1: // object DEBUG_OUT<<"sttype is object.\n"; symType=EMAP_SYMBOL_INT; break; case 2: // func DEBUG_OUT<<"sttype is func.\n"; symType=EMAP_SYMBOL_FUNC; break; case 3: // section DEBUG_OUT<<"sttype is section.\n"; break; case 4: // file DEBUG_OUT<<"sttype is file.\n"; symType=EMAP_SYMBOL_FILENAME; break; default: DEBUG_OUT<<"sttype is default.\n"; break; } if(stname) { DEBUG_OUT<<"New symbol..."; DEBUG_OUT<<""<<getStringAtOffset(stname,strings)<<""; s=new EMapSymbol(getStringAtOffset(stname,strings),t,stvalue,stsize,symType); DEBUG_OUT<<"...adding to map..."; if(syms) syms->insert(s); DEBUG_OUT<<"done.\n"; } } return true; }
bool NElfDecoder::readStringsAndSymbols() { #ifdef DEBUG_VERBOSE DEBUG_OUT<<"NElfDecoder::readStringsAndSymbols()\n"; #endif // DEBUG_VERBOSE NBinaryNode *nodeNames=ld->findNode(fstind); if(!nodeNames) { DEBUG_OUT<<"findNode(fstind) didn't work!\n"; err.set(); } #ifdef DEBUG_VERBOSE DEBUG_OUT<<"Found node "<<fstind<<" with strings, going to fix mod's names now...\n"; #endif // DEBUG_VERBOSE ld->getModule()->getNodes()->reset(); NBinaryNode *n=(NBinaryNode *)NULL; bool working=true; unsigned int shname; while(working) { n=(NBinaryNode *)ld->getModule()->getNodes()->info(); if(n) { #ifdef DEBUG_VERBOSE DEBUG_OUT<<"Node #"<<n->num<<" "; #endif // DEBUG_VERBOSE shname=map->read32(n->val+getImageOffset(),LSB); #ifdef DEBUG_VERBOSE DEBUG_OUT<<"shname="<<shname<<" "; #endif // DEBUG_VERBOSE char *tname=getStringAtOffset(shname,nodeNames); #ifdef DEBUG_VERBOSE //DEBUG_OUT<<"getStringAtOffset was fine\n"; #endif // DEBUG_VERBOSE if(tname) { #ifdef DEBUG_VERBOSE DEBUG_OUT<<"name is "<<tname<<"\n"; #endif // DEBUG_VERBOSE if(tname) n->setName(strdup(tname)); } switch(n->type) { case N_BIN_SYMTAB: case N_BIN_DYNSYM: case N_BIN_DYNAMIC: // shinfo is string table index handleSymbols(n); break; case N_BIN_REL: case N_BIN_RELA: case N_BIN_HASH: // shinfo is symbol table index break; default: break; } } ld->getModule()->getNodes()->advance(); if(ld->getModule()->getNodes()->atEnd()) working=false; } #ifdef DEBUG_VERBOSE DEBUG_OUT<<"readStringsAndSymbols done.\n"; #endif // DEBUG_VERBOSE return true; }
bool NElfDecoder::decode_elf_sh() { #ifdef DEBUG_VERBOSE DEBUG_OUT<<"NElfDecoder::decode_elf_sh()\n"; #endif // DEBUG_VERBOSE if(!checkSanity()) return false; if(ld->getUnknown()) return false; offset=fshoff; unsigned int shname,shtype,shlink,shinfo; ULONG shaddr,shoff,shflags,shsize,shalign,shentsize; ULONG lastAddr=0; bool reloc=false; if(fshnum>1000) fshnum=1000; // Sanity check... for(unsigned int t=0;t<fshnum;t++) { reloc=false; ULONG toffset=offset; shname=map->read32(offset+getImageOffset(),LSB); offset+=4; shtype=map->read32(offset+getImageOffset(),LSB); offset+=4; if(bitness==32) { shflags=map->read32(offset+getImageOffset(),LSB); offset+=4; shaddr=map->read32(offset+getImageOffset(),LSB); offset+=4; shoff=map->read32(offset+getImageOffset(),LSB); offset+=4; shsize=map->read32(offset+getImageOffset(),LSB); offset+=4; } else { shflags=map->read64(offset+getImageOffset(),LSB); offset+=8; shaddr=map->read64(offset+getImageOffset(),LSB); offset+=8; shoff=map->read64(offset+getImageOffset(),LSB); offset+=8; shsize=map->read64(offset+getImageOffset(),LSB); offset+=8; } DEBUG_OUT<<"(offset is "<<offset<<")\n"; shlink=map->read32(offset+getImageOffset(),LSB); offset+=4; shinfo=map->read32(offset+getImageOffset(),LSB); offset+=4; if(bitness==32) { shalign=map->read32(offset+getImageOffset(),LSB); offset+=4; shentsize=map->read32(offset+getImageOffset(),LSB); offset+=4; } else { shalign=map->read64(offset+getImageOffset(),LSB); offset+=8; shentsize=map->read64(offset+getImageOffset(),LSB); offset+=8; } DEBUG_OUT<<"s_node "<<t<<" shname="<<shname<<" shoff="<<shoff<<" shaddr="<<shaddr; DEBUG_OUT<<" shsize="<<shsize<<" shlink="<<shlink<<" "<<"shinfo="<<shinfo; DEBUG_OUT<<" shtype="<<shtype<<" shflags="<<shflags<<" "<<"shentsize="<<shentsize; DEBUG_OUT<<"\n"; if(ld->getNeedsReloc()) { reloc=true; shaddr=lastAddr; lastAddr+=shsize; // Align on 32-bit word (Is this right for 64 bit?) if(lastAddr&0x3) lastAddr=(lastAddr&0xfffffffc)+4; } unsigned int perm=0; if(shflags&1) perm|=E_MEM_WRITE; if(shflags&2) perm|=E_MEM_READ; if(shflags&4) perm|=E_MEM_EXEC; if(shtype) { NBinaryNode *n=new NBinaryNode("node_s",t,shtype,shaddr,shsize,shoff,perm,(BYTE *)NULL,toffset); if(n) ld->getModule()->getNodes()->append(n); else { std::cerr<<"Didn't get NBinaryNode!\n"; exit(5); } } } return true; }
bool NElfDecoder::decode_elf_ph() { #ifdef DEBUG_VERBOSE DEBUG_OUT<<"NElfDecoder::decode_elf_ph()\n"; #endif // DEBUG_VERBOSE if(!checkSanity()) return false; offset=fphoff; unsigned int phtype,phflags; ULONG phaddr,phpaddr; ULONG phoff,phsize,phfsize,phalign; ULONG lastAddr=0; if(fphnum>1000) fphnum=1000; // Sanity check... for(unsigned int t=0;t<fphnum;t++) { phtype=map->read32(offset+getImageOffset(),LSB); offset+=4; if(bitness==32) { phoff=map->read32(offset+getImageOffset(),LSB); offset+=4; phaddr=map->read32(offset+getImageOffset(),LSB); offset+=4; phpaddr=map->read32(offset+getImageOffset(),LSB); offset+=4; phfsize=map->read32(offset+getImageOffset(),LSB); offset+=4; phsize=map->read32(offset+getImageOffset(),LSB); offset+=4; phflags=map->read32(offset+getImageOffset(),LSB); offset+=4; phalign=map->read32(offset+getImageOffset(),LSB); offset+=4; } else { phflags=map->read32(offset+getImageOffset(),LSB); offset+=4; phoff=map->read64(offset+getImageOffset(),LSB); offset+=8; phaddr=map->read64(offset+getImageOffset(),LSB); offset+=8; phpaddr=map->read64(offset+getImageOffset(),LSB); offset+=8; phfsize=map->read64(offset+getImageOffset(),LSB); offset+=8; phsize=map->read64(offset+getImageOffset(),LSB); offset+=8; phalign=map->read64(offset+getImageOffset(),LSB); offset+=8; } DEBUG_OUT<<"p_node "<<t<<" phtype="<<phtype<<" "<<" phoff="<<phoff; DEBUG_OUT<<" phaddr="<<phaddr<<" "<<" phpaddr="<<phpaddr<<" phfsize="<<phfsize; DEBUG_OUT<<" phsize="<<phsize<<" "<<" phflags="<<phflags; DEBUG_OUT<<"\n"; if(ld->getNeedsReloc()) { phaddr=lastAddr; lastAddr+=phsize; // Align on 32-bit word (Is this right for 64 bit?) if(lastAddr&0x3) lastAddr=(lastAddr&0xfffffffc)+4; } /* if(phtype) { NBinaryNode *n=new NBinaryNode("node_p"),t,phtype,phaddr, phsize,phoff,E_MEM_ALL); if(n) ld->getModule()->getNodes()->append(n); else std::cerr<<"Didn't get NBinaryNode!\n"); } */ } return true; }