@@ -853,17 +853,22 @@ private Address convertAddressToRamSpace(Address address) throws Exception {
853
853
}
854
854
855
855
try {
856
- // If already in RAM space, just return it
857
- if (address .getAddressSpace ().getName ().equals ("ram" )) {
856
+ // Note: Function converts address to ramspace only if it belongs to
857
+ // constant space; if address space is not constant, return
858
+ if (!address .getAddressSpace ().isConstantSpace ()) {
858
859
return address ;
859
860
}
860
861
861
862
// Get the numeric offset and create a new address in RAM space
862
863
long offset = address .getOffset ();
863
864
return program .getAddressFactory ().getDefaultAddressSpace ().getAddress (offset );
864
- } catch (Exception e ) {
865
- println (String .format ("Failed to convert address %s to RAM space: %s" , address , e .getMessage ()));
865
+
866
+ } catch (AddressOutOfBoundsException e ) {
867
+ println (String .format ("Error converting address %s to RAM space: %s" ,
868
+ address , e .getMessage ()));
866
869
return null ;
870
+ } catch (Exception e ) {
871
+ throw new RuntimeException ("Failed converting address to RAM space" , e );
867
872
}
868
873
}
869
874
@@ -924,19 +929,12 @@ private Data getDataReferencedAsConstant(Varnode node) throws Exception {
924
929
925
930
// Ghidra sometime fail to resolve references to Data and show it as const.
926
931
// Check if it is referencing Data as constant from `ram` addresspace.
927
- try {
928
- // Convert the constant value to a potential RAM address
929
- Address ram_address = convertAddressToRamSpace (node .getAddress ());
930
- if (ram_address == null ) {
931
- return null ;
932
- }
933
- return getDataAt (ram_address );
934
-
935
- } catch (AddressOutOfBoundsException e ) {
936
- println ("Address conversion out of bounds for constant: " + e .getMessage ());
932
+ // Convert the constant value to a potential RAM address
933
+ Address ram_address = convertAddressToRamSpace (node .getAddress ());
934
+ if (ram_address == null ) {
935
+ return null ;
937
936
}
938
-
939
- return null ;
937
+ return getDataAt (ram_address );
940
938
}
941
939
942
940
// Serialize an input or output varnode.
0 commit comments