@@ -398,42 +398,53 @@ void Symbol::restoreXml(const Element *el)
398
398
restoreXmlBody (list.begin ());
399
399
}
400
400
401
- void FunctionSymbol::buildType (int4 size)
401
+ // / Get the number of bytes consumed by a SymbolEntry representing \b this Symbol.
402
+ // / By default, this is the number of bytes consumed by the Symbol's data-type.
403
+ // / This gives the amount of leeway a search has when the address queried does not match
404
+ // / the exact address of the Symbol. With functions, the bytes consumed by a SymbolEntry
405
+ // / may not match the data-type size.
406
+ // / \return the number of bytes in a default SymbolEntry
407
+ int4 Symbol::getBytesConsumed (void ) const
408
+
409
+ {
410
+ return type->getSize ();
411
+ }
412
+
413
+ void FunctionSymbol::buildType (void )
402
414
403
415
{
404
416
TypeFactory *types = scope->getArch ()->types ;
405
417
type = types->getTypeCode ();
406
- // Entries for functions have small size starting at the entry address
407
- // of the function in order to deal with non-contiguous functions
408
- // The size used to always be 1, but now we need sizes (slightly) larger than 1
409
- // to accomodate pointer constants that encode extra information in the lower bit(s)
410
- // of an otherwise aligned pointer. If the encoding is not aprior detected, it is interpreted
411
- // initially as a straight address that comes up 1 (or more) bytes off of the start of the function
412
- // In order to detect this, we need to lay down a slightly larger size than 1
413
- if (size > 1 )
414
- type = types->getTypeArray (size,type);
415
-
416
418
flags |= Varnode::namelock | Varnode::typelock;
417
419
}
418
420
419
421
// / Build a function \e shell, made up of just the name of the function and
420
422
// / a placeholder data-type, without the underlying Funcdata object.
423
+ // / A SymbolEntry for a function has a small size starting at the entry address,
424
+ // / in order to deal with non-contiguous functions.
425
+ // / We need a size (slightly) larger than 1 to accommodate pointer constants that encode
426
+ // / extra information in the lower bit(s) of an otherwise aligned pointer.
427
+ // / If the encoding is not initially detected, it is interpreted
428
+ // / as a straight address that comes up 1 (or more) bytes off of the start of the function
429
+ // / In order to detect this, we need to lay down a slightly larger size than 1
421
430
// / \param sc is the Scope that will contain the new Symbol
422
431
// / \param nm is the name of the new Symbol
423
- // / \param size is the number of bytes the Symbol should consume
432
+ // / \param size is the number of bytes a SymbolEntry should consume
424
433
FunctionSymbol::FunctionSymbol (Scope *sc,const string &nm,int4 size)
425
434
: Symbol(sc)
426
435
{
427
436
fd = (Funcdata *)0 ;
428
- buildType (size);
437
+ consumeSize = size;
438
+ buildType ();
429
439
name = nm;
430
440
}
431
441
432
442
FunctionSymbol::FunctionSymbol (Scope *sc,int4 size)
433
443
: Symbol(sc)
434
444
{
435
445
fd = (Funcdata *)0 ;
436
- buildType (size);
446
+ consumeSize = size;
447
+ buildType ();
437
448
}
438
449
439
450
FunctionSymbol::~FunctionSymbol (void ) {
@@ -469,9 +480,9 @@ void FunctionSymbol::restoreXml(const Element *el)
469
480
fd = new Funcdata (" " ,scope,Address ());
470
481
fd->restoreXml (el);
471
482
name = fd->getName ();
472
- if (type-> getSize () < fd->getSize ()) {
483
+ if (consumeSize < fd->getSize ()) {
473
484
if ((fd->getSize ()>1 )&&(fd->getSize () <= 8 ))
474
- buildType ( fd->getSize () );
485
+ consumeSize = fd->getSize ();
475
486
}
476
487
}
477
488
else { // functionshell
@@ -934,16 +945,17 @@ SymbolEntry *Scope::addMap(const SymbolEntry &entry)
934
945
entry.symbol ->flags |= Varnode::persist;
935
946
936
947
SymbolEntry *res;
948
+ int4 consumeSize = entry.symbol ->getBytesConsumed ();
937
949
if (entry.addr .isInvalid ())
938
- res = addDynamicMapInternal (entry.symbol ,Varnode::mapped,entry.hash ,0 ,entry. symbol -> getType ()-> getSize () ,entry.uselimit );
950
+ res = addDynamicMapInternal (entry.symbol ,Varnode::mapped,entry.hash ,0 ,consumeSize ,entry.uselimit );
939
951
else {
940
952
if (entry.uselimit .empty ()) {
941
953
entry.symbol ->flags |= Varnode::addrtied;
942
954
// Global properties (like readonly and volatile)
943
955
// can only happen if use is not limited
944
956
entry.symbol ->flags |= glb->symboltab ->getProperty (entry.addr );
945
957
}
946
- res = addMapInternal (entry.symbol ,Varnode::mapped,entry.addr ,0 ,entry. symbol -> getType ()-> getSize () ,entry.uselimit );
958
+ res = addMapInternal (entry.symbol ,Varnode::mapped,entry.addr ,0 ,consumeSize ,entry.uselimit );
947
959
if (entry.addr .isJoin ()) {
948
960
// The address is a join, we add extra SymbolEntry maps for each of the pieces
949
961
JoinRecord *rec = glb->findJoin (entry.addr .getOffset ());
0 commit comments