Open an IR via protobuf and print every symbol pointing to data.
import com.google.protobuf.ByteString;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
import java.lang.Long;
import java.util.*;
import proto.DataObjectOuterClass.DataObject;
import proto.IROuterClass.IR;
import proto.ModuleOuterClass.Module;
import proto.SymbolOuterClass.Symbol;
class datasymbols {
public static void main(String[] args) {
IR ir = IR.getDefaultInstance();
DataObject data_obj;
if (args.length < 1) {
System.err.println("No GTIRB file specified.");
System.exit(-1);
}
try {
ir = IR.parseFrom(new FileInputStream(args[0]));
} catch (FileNotFoundException fe) {
System.err.println("File not found: " + args[0]);
System.exit(-1);
} catch (IOException ie) {
System.err.println("Problem reading file: " + args[0]);
System.exit(-1);
}
for (Module m : ir.getModulesList()) {
System.out.println("Module " + m.getName());
Map<Long, DataObject> datamap = m.getDataMap();
Map<ByteString, DataObject> data_objects =
new HashMap<ByteString, DataObject>();
for (DataObject d : datamap.values()) {
data_objects.put(d.getUuid(), d);
}
for (Symbol sym : m.getSymbolsList()) {
data_obj = data_objects.get(sym.getReferentUuid());
if (data_obj != null) {
System.out.println(String.format(
"%s:\t0x%08X\t %d bytes", sym.getName(),
data_obj.getAddress(), data_obj.getSize()));
}
}
}
}
}