Skip to content

Commit 65c0814

Browse files
committed
Write new size to SWF on insertABC
1 parent bce4abf commit 65c0814

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

Native/BytecodeEditor/source/ANEBytecodeEditorFunctions.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,26 @@ FREObject InsertABCToSWF(FREContext, void*, uint32_t argc, FREObject argv[])
4444
}
4545
});
4646

47-
FREObject lengthObj;
48-
DO_OR_FAIL("Failed to create length object", FRENewObjectFromUint32(finalSize, &lengthObj));
47+
if (finalSize > swfLength)
48+
{
49+
FREObject lengthObj;
50+
DO_OR_FAIL(
51+
"Failed to create length object", FRENewObjectFromUint32(finalSize, &lengthObj));
4952

50-
DO_OR_FAIL(
51-
"Failed to expand bytearray", ANESetObjectProperty(swf, "length", lengthObj, nullptr));
53+
FREObject exception;
54+
DO_OR_FAIL_EXCEPTION("Failed to expand bytearray", exception,
55+
ANESetObjectProperty(swf, "length", lengthObj, &exception));
56+
}
5257

5358
DO_OR_FAIL("Failed to acquire SWF bytearray", FREAcquireByteArray(swf, &swfData));
5459
tags = SWF::SWFFile::getTagsFrom({swfData.bytes, swfLength});
5560

61+
static_assert(std::endian::native == std::endian::little);
62+
swfData.bytes[4] = uint8_t(finalSize);
63+
swfData.bytes[5] = uint8_t(finalSize >> 8);
64+
swfData.bytes[6] = uint8_t(finalSize >> 16);
65+
swfData.bytes[7] = uint8_t(finalSize >> 24);
66+
5667
FREByteArray abcData;
5768
DO_OR_FAIL("Failed to acquire ABC bytearray", FREAcquireByteArray(abc, &abcData));
5869

@@ -153,6 +164,17 @@ FREObject InsertABCToSWF(FREContext, void*, uint32_t argc, FREObject argv[])
153164

154165
DO_OR_FAIL("Failed to release swf bytearray", FREReleaseByteArray(swf));
155166
DO_OR_FAIL("Failed to release abc bytearray", FREReleaseByteArray(abc));
167+
168+
if (finalSize < swfLength)
169+
{
170+
FREObject lengthObj;
171+
DO_OR_FAIL(
172+
"Failed to create length object", FRENewObjectFromUint32(finalSize, &lengthObj));
173+
174+
FREObject exception;
175+
DO_OR_FAIL_EXCEPTION("Failed to shrink bytearray", exception,
176+
ANESetObjectProperty(swf, "length", lengthObj, &exception));
177+
}
156178
}
157179
catch (std::exception& e)
158180
{

0 commit comments

Comments
 (0)