use of com.google.common.primitives.UnsignedInteger in project buck by facebook.
the class SymTabCommandUtilsTest method testInsertingNewStringTableEntry.
@Test
public void testInsertingNewStringTableEntry() throws Exception {
byte[] commandBytes = SymTabCommandTestData.getBigEndian();
final int cmdSize = commandBytes.length;
// symoff
commandBytes[11] = (byte) cmdSize;
// nsyms
commandBytes[15] = (byte) 0;
// stroff
commandBytes[19] = (byte) cmdSize;
// strsize
commandBytes[23] = (byte) 20;
final String content = "new_entry";
ByteBuffer byteBuffer = ByteBuffer.allocate(cmdSize + 20 + SymTabCommandUtils.sizeOfStringTableEntryWithContents(content)).order(ByteOrder.BIG_ENDIAN).put(commandBytes).put(new byte[20]);
byteBuffer.position(0);
SymTabCommand symTabCommand = SymTabCommandUtils.createFromBuffer(byteBuffer);
UnsignedInteger offset = SymTabCommandUtils.insertNewStringTableEntry(byteBuffer, symTabCommand, content);
assertThat(offset, equalToObject(UnsignedInteger.fromIntBits(20)));
byteBuffer.position(symTabCommand.getStroff().plus(offset).intValue());
byte[] entryBytes = new byte[content.length()];
byteBuffer.get(entryBytes, 0, content.length());
assertThat(entryBytes, equalTo(content.getBytes(StandardCharsets.UTF_8)));
}
use of com.google.common.primitives.UnsignedInteger in project buck by facebook.
the class ObjectPathsAbsolutifier method updateSymTabCommandByUpdatingNlistEntry.
private SymTabCommand updateSymTabCommandByUpdatingNlistEntry(MachoMagicInfo magicInfo, SymTabCommand symTabCommand, Nlist nlist, Path absolutePath, String absolutePathString) throws IOException {
extendFileSizeToFitNewString(absolutePathString);
UnsignedInteger newEntryLocation = SymTabCommandUtils.insertNewStringTableEntry(buffer, symTabCommand, absolutePathString);
LOG.debug("Inserted new string table entry at %s", newEntryLocation);
updateNlistEntryWithNewContentsLocation(buffer, magicInfo, nlist, absolutePath, newEntryLocation);
LOG.debug("Updated nlist entry to use new string table entry");
symTabCommand = SymTabCommandUtils.updateSymTabCommand(buffer, symTabCommand, absolutePathString);
LOG.debug("Updated SymTabCommand");
return symTabCommand;
}
use of com.google.common.primitives.UnsignedInteger in project buck by facebook.
the class AbstractLinkEditDataCommand method check.
@Value.Check
protected void check() {
UnsignedInteger cmd = getLoadCommandCommonFields().getCmd();
Preconditions.checkArgument(VALID_CMD_VALUES.contains(cmd));
Preconditions.checkArgument(getLoadCommandCommonFields().getCmdsize().equals(UnsignedInteger.fromIntBits(SIZE_IN_BYTES)));
}
Aggregations