use of com.facebook.buck.charset.NulTerminatedCharsetDecoder in project buck by facebook.
the class SegmentCommandUtilsTest method testUpdatingSegmentCommandInByteBuffer32Bit.
@Test
public void testUpdatingSegmentCommandInByteBuffer32Bit() throws Exception {
byte[] bytes = SegmentCommandTestData.getBigEndian32Bits();
final int commandSize = bytes.length;
SegmentCommand command = SegmentCommandUtils.createFromBuffer(ByteBuffer.wrap(bytes).order(ByteOrder.BIG_ENDIAN), new NulTerminatedCharsetDecoder(StandardCharsets.UTF_8.newDecoder()));
SegmentCommand updated = command.withFilesize(UnsignedLong.fromLongBits(1234)).withVmsize(UnsignedLong.fromLongBits(SegmentCommandUtils.alignValue(4321)));
ByteBuffer buffer = ByteBuffer.allocate(commandSize);
SegmentCommandUtils.updateSegmentCommand(buffer, command, updated);
buffer.position(0);
SegmentCommand commandInBuffer = SegmentCommandUtils.createFromBuffer(buffer, new NulTerminatedCharsetDecoder(StandardCharsets.UTF_8.newDecoder()));
assertThat(commandInBuffer.getFilesize(), equalToObject(updated.getFilesize()));
assertThat(commandInBuffer.getVmsize(), equalToObject(updated.getVmsize()));
}
use of com.facebook.buck.charset.NulTerminatedCharsetDecoder in project buck by facebook.
the class SegmentCommandUtilsTest method testEnumeratingSections32Bit.
@Test
public void testEnumeratingSections32Bit() throws Exception {
final int sectionSize = SectionTestData.getBigEndian32Bit().length;
byte[] sectionData1 = SectionTestData.getBigEndian32Bit();
// offset = 1
sectionData1[43] = (byte) 0x01;
byte[] sectionData2 = SectionTestData.getBigEndian32Bit();
// sectname = "DECTNAME"
sectionData2[0] = (byte) 0x44;
// segname = "DEGNAME"
sectionData2[16] = (byte) 0x44;
// offset = 2
sectionData2[43] = (byte) 0x02;
byte[] sectionData3 = SectionTestData.getBigEndian32Bit();
// sectname = "LECTNAME"
sectionData3[0] = (byte) 0x4C;
// segname = "LEGNAME"
sectionData3[16] = (byte) 0x4C;
// offset = 3
sectionData3[43] = (byte) 0x03;
byte[] segmentBytes = SegmentCommandTestData.getBigEndian32Bits();
// nsects = 3
segmentBytes[51] = (byte) 0x03;
SegmentCommand command = SegmentCommandUtils.createFromBuffer(ByteBuffer.wrap(segmentBytes).order(ByteOrder.BIG_ENDIAN), new NulTerminatedCharsetDecoder(StandardCharsets.UTF_8.newDecoder()));
ByteBuffer buffer = ByteBuffer.allocate(command.getLoadCommandCommonFields().getCmdsize().intValue() + 3 * sectionSize);
buffer.order(ByteOrder.BIG_ENDIAN);
SegmentCommandUtils.writeCommandToBuffer(command, buffer, false);
buffer.put(sectionData1);
buffer.put(sectionData2);
buffer.put(sectionData3);
final List<Section> enumeratedSections = new ArrayList<>();
SegmentCommandUtils.enumerateSectionsInSegmentLoadCommand(buffer, new MachoMagicInfo(UnsignedInteger.fromIntBits(0xFEEDFACE)), command, new NulTerminatedCharsetDecoder(StandardCharsets.UTF_8.newDecoder()), input -> {
enumeratedSections.add(input);
return Boolean.TRUE;
});
assertThat(enumeratedSections.size(), equalTo(3));
assertThat(enumeratedSections.get(0).getSectname(), equalToObject("SECTNAME"));
assertThat(enumeratedSections.get(0).getSegname(), equalToObject("SEGNAME"));
assertThat(enumeratedSections.get(0).getOffset(), equalToObject(UnsignedInteger.fromIntBits(0x01)));
assertThat(enumeratedSections.get(1).getSectname(), equalToObject("DECTNAME"));
assertThat(enumeratedSections.get(1).getSegname(), equalToObject("DEGNAME"));
assertThat(enumeratedSections.get(1).getOffset(), equalToObject(UnsignedInteger.fromIntBits(0x02)));
assertThat(enumeratedSections.get(2).getSectname(), equalToObject("LECTNAME"));
assertThat(enumeratedSections.get(2).getSegname(), equalToObject("LEGNAME"));
assertThat(enumeratedSections.get(2).getOffset(), equalToObject(UnsignedInteger.fromIntBits(0x03)));
}
use of com.facebook.buck.charset.NulTerminatedCharsetDecoder in project buck by facebook.
the class MachOAbsolutifyObjectPathsCommand method invokeWithParams.
@Override
protected int invokeWithParams(CommandRunnerParams params) throws IOException {
try (RandomAccessFile file = new RandomAccessFile(getOutput().toFile(), "rw")) {
NulTerminatedCharsetDecoder decoder = new NulTerminatedCharsetDecoder(StandardCharsets.UTF_8.newDecoder());
ObjectPathsAbsolutifier updater = new ObjectPathsAbsolutifier(file, getOldCompDir(), getUpdatedCompDir(), params.getCell().getFilesystem(), params.getCell().getKnownRoots(), decoder);
updater.updatePaths();
}
return 0;
}
use of com.facebook.buck.charset.NulTerminatedCharsetDecoder in project buck by facebook.
the class SectionTest method testCreatingFromBytesBigEndian32Bit.
@Test
public void testCreatingFromBytesBigEndian32Bit() throws Exception {
Section section = SectionUtils.createFromBuffer(createBuffer(SectionTestData.getBigEndian32Bit(), 30, ByteOrder.BIG_ENDIAN), false, new NulTerminatedCharsetDecoder(StandardCharsets.UTF_8.newDecoder()));
assertThat(section.getOffsetInBinary(), equalTo(30));
checkValues(section);
}
use of com.facebook.buck.charset.NulTerminatedCharsetDecoder in project buck by facebook.
the class SectionUtilsTest method testCreatingFromBytes64Bits.
@Test
public void testCreatingFromBytes64Bits() throws CharacterCodingException {
ByteBuffer buffer = ByteBuffer.allocate(10 + SectionTestData.getBigEndian64Bit().length);
buffer.order(ByteOrder.BIG_ENDIAN);
buffer.position(10);
buffer.put(SectionTestData.getBigEndian64Bit());
buffer.position(10);
Section section = SectionUtils.createFromBuffer(buffer, true, new NulTerminatedCharsetDecoder(StandardCharsets.UTF_8.newDecoder()));
assertThat(section.getOffsetInBinary(), equalTo(10));
SectionTestData.checkValues(section, true);
}
Aggregations