Search in sources :

Example 6 with UnsignedInteger

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)));
}
Also used : UnsignedInteger(com.google.common.primitives.UnsignedInteger) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 7 with UnsignedInteger

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;
}
Also used : UnsignedInteger(com.google.common.primitives.UnsignedInteger)

Example 8 with UnsignedInteger

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)));
}
Also used : UnsignedInteger(com.google.common.primitives.UnsignedInteger)

Aggregations

UnsignedInteger (com.google.common.primitives.UnsignedInteger)8 ByteBuffer (java.nio.ByteBuffer)2 Test (org.junit.Test)2 ByteOrder (java.nio.ByteOrder)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1