Fixed: AS3 decompilation: increment/decrement on properties

This commit is contained in:
Jindra Petřík
2021-02-21 20:36:17 +01:00
parent 08424221d6
commit 11c3c2a8a7
10 changed files with 128 additions and 25 deletions

View File

@@ -41,6 +41,7 @@ All notable changes to this project will be documented in this file.
- Focused byte barely visible in hex view
- AS3 P-code editation - only first try offset was saved when multiple try with same label
- AS3 decompilation: try..catch..finally suborder when debugline info not present
- AS3 decompilation: increment/decrement on properties
### Changed
- #1565, #1407, #1350 On BinaryData SWF save, parent SWF is saved

View File

@@ -132,12 +132,81 @@ public class SetPropertyIns extends InstructionDefinition implements SetTypeIns
return;
}
}
if (notCoerced instanceof GetPropertyAVM2Item) {
GetPropertyAVM2Item getProp = (GetPropertyAVM2Item) notCoerced;
if (((FullMultinameAVM2Item) getProp.propertyName).compareSame(multiname)) {
if (getProp.object instanceof DuplicateItem) { //assembled/TestIncrement3
if (getProp.object.value == obj) {
getProp.object = obj;
}
}
stack.pop();
if (isIncrement) {
stack.push(new PostIncrementAVM2Item(ins, localData.lineStartInstruction, getProp));
} else {
stack.push(new PostDecrementAVM2Item(ins, localData.lineStartInstruction, getProp));
}
return;
}
}
}
}
}
}
if ((value instanceof IncrementAVM2Item) || (value instanceof DecrementAVM2Item)) {
boolean isIncrement = (value instanceof IncrementAVM2Item);
boolean hasConvert = value.value instanceof ConvertAVM2Item;
if (value.value.getNotCoercedNoDup() instanceof GetLexAVM2Item) {
GetLexAVM2Item getLex = (GetLexAVM2Item) value.value.getNotCoercedNoDup();
if (localData.abc.constants.getMultiname(multinameIndex).equals(getLex.propertyName)) {
if (hasConvert) {
if (isIncrement) {
output.add(new PostIncrementAVM2Item(ins, localData.lineStartInstruction, getLex));
} else {
output.add(new PostDecrementAVM2Item(ins, localData.lineStartInstruction, getLex));
}
} else {
if (isIncrement) {
output.add(new PreIncrementAVM2Item(ins, localData.lineStartInstruction, getLex));
} else {
output.add(new PreDecrementAVM2Item(ins, localData.lineStartInstruction, getLex));
}
}
return;
}
}
if (value.value.getNotCoercedNoDup() instanceof GetPropertyAVM2Item) {
GetPropertyAVM2Item getProp = (GetPropertyAVM2Item) value.value.getNotCoercedNoDup();
if (((FullMultinameAVM2Item) getProp.propertyName).compareSame(multiname)) {
if (getProp.object instanceof DuplicateItem) {
if (getProp.object.value == obj) {
getProp.object = obj;
}
}
if (hasConvert) {
if (isIncrement) {
output.add(new PostIncrementAVM2Item(ins, localData.lineStartInstruction, getProp));
} else {
output.add(new PostDecrementAVM2Item(ins, localData.lineStartInstruction, getProp));
}
} else {
if (isIncrement) {
output.add(new PreIncrementAVM2Item(ins, localData.lineStartInstruction, getProp));
} else {
output.add(new PreDecrementAVM2Item(ins, localData.lineStartInstruction, getProp));
}
}
return;
}
}
}
//assembled/TestIncrement2
if (value instanceof DuplicateItem) {
GraphTargetItem duplicated = value.value;
@@ -158,29 +227,22 @@ public class SetPropertyIns extends InstructionDefinition implements SetTypeIns
return;
}
}
}
}
}
}
//assembled/TestIncrement3
if ((value instanceof IncrementAVM2Item) || (value instanceof DecrementAVM2Item)) {
boolean isIncrement = (value instanceof IncrementAVM2Item);
if (value.value.getNotCoerced() instanceof GetPropertyAVM2Item) {
GetPropertyAVM2Item getProp = (GetPropertyAVM2Item) value.value.getNotCoerced();
if (getProp.object instanceof DuplicateItem) {
if (getProp.object.value == obj) {
getProp.object = obj;
if (isIncrement) {
output.add(new PreIncrementAVM2Item(ins, localData.lineStartInstruction, getProp));
} else {
output.add(new PreDecrementAVM2Item(ins, localData.lineStartInstruction, getProp));
if (incrementedProp instanceof GetPropertyAVM2Item) {
GetPropertyAVM2Item getProp = (GetPropertyAVM2Item) incrementedProp;
if (((FullMultinameAVM2Item) getProp.propertyName).compareSame(multiname)) {
stack.pop();
if (isIncrement) {
stack.push(new PreIncrementAVM2Item(ins, localData.lineStartInstruction, getProp));
} else {
stack.push(new PreDecrementAVM2Item(ins, localData.lineStartInstruction, getProp));
}
return;
}
}
return;
}
}
}
}
if (value instanceof LocalRegAVM2Item) {
LocalRegAVM2Item valueLocalReg = (LocalRegAVM2Item) value;
LocalRegAVM2Item nameLocalReg = null;

View File

@@ -127,7 +127,7 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT
@Test
public void testIncrement3() {
decompileMethod("assembled", "testIncrement3", "--_loc1_.length;\r\n",
decompileMethod("assembled", "testIncrement3", "_loc1_.length--;\r\n",
false);
}

View File

@@ -294,9 +294,9 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile
public void testDotParent() {
decompileMethod("classic_air", "testDotParent", "var d:* = new TestClass1();\r\n"
+ "var k:* = null;\r\n"
+ "k.(++d.attrib, false);\r\n"
+ "k.(d.attrib++, false);\r\n"
+ "trace(\"between\");\r\n"
+ "var g:* = k.(++d.attrib, false);\r\n"
+ "var g:* = k.(d.attrib++, false);\r\n"
+ "trace(\"end\");\r\n",
false);
}
@@ -855,7 +855,19 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile
+ "var index:uint = 0;\r\n"
+ "chars[index++] = 5;\r\n"
+ "trace(\"arr[++e]\");\r\n"
+ "chars[++index] = 5;\r\n",
+ "chars[++index] = 5;\r\n"
+ "trace(\"attr++\");\r\n"
+ "trace(attrx++);\r\n"
+ "attrx++;\r\n"
+ "trace(\"attr--\");\r\n"
+ "trace(attrx--);\r\n"
+ "attrx--;\r\n"
+ "trace(\"++attr\");\r\n"
+ "trace(++attrx);\r\n"
+ "++attrx;\r\n"
+ "trace(\"--attr\");\r\n"
+ "trace(--attrx);\r\n"
+ "--attrx;\r\n",
false);
}

View File

@@ -848,7 +848,19 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes
+ "chars[_loc7_] = 5;\r\n"
+ "trace(\"arr[++e]\");\r\n"
+ "var _loc8_:* = ++index;\r\n"
+ "chars[_loc8_] = 5;\r\n",
+ "chars[_loc8_] = 5;\r\n"
+ "trace(\"attr++\");\r\n"
+ "trace(this.attrx++);\r\n"
+ "++this.attrx;\r\n"
+ "trace(\"attr--\");\r\n"
+ "trace(this.attrx--);\r\n"
+ "--this.attrx;\r\n"
+ "trace(\"++attr\");\r\n"
+ "trace(++this.attrx);\r\n"
+ "++this.attrx;\r\n"
+ "trace(\"--attr\");\r\n"
+ "trace(--this.attrx);\r\n"
+ "--this.attrx;\r\n",
false);
}

View File

@@ -16,7 +16,7 @@
</define>
<define append="true">
<name>CONFIG::timeStamp</name>
<value>'16.02.2021'</value>
<value>'21.02.2021'</value>
</define>
<define append="true">
<name>CONFIG::air</name>

View File

@@ -16,7 +16,7 @@
</define>
<define append="true">
<name>CONFIG::timeStamp</name>
<value>'16.02.2021'</value>
<value>'21.02.2021'</value>
</define>
<define append="true">
<name>CONFIG::air</name>

View File

@@ -3,6 +3,9 @@ package tests
public class TestIncDec
{
private var attrx:int = 0;
public function run():*
{
var a:* = 5;
@@ -39,6 +42,19 @@ package tests
chars[index++] = 5;
trace("arr[++e]");
chars[++index] = 5;
trace("attr++");
trace(attrx++);
attrx++;
trace("attr--");
trace(attrx--);
attrx--;
trace("++attr");
trace(++attrx);
++attrx;
trace("--attr");
trace(--attrx);
--attrx;
}
}
}