Added #2185 16bit MochiCrypt packer support

Changed #2185 MochiCrypt no longer offered for auto decrypt, user needs to choose variant from "Use unpacker" menu
This commit is contained in:
Jindra Petřík
2024-01-21 10:31:51 +01:00
parent 468ef37b64
commit e05df39b3d
4 changed files with 153 additions and 9 deletions

View File

@@ -0,0 +1,135 @@
/*
* Copyright (C) 2010-2023 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.packers;
import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag;
import com.jpexs.helpers.Helper;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;
/**
*
* @author JPEXS
*/
public class MochiCryptPacker16Bit implements Packer {
@Override
public Boolean suitableForBinaryData(DefineBinaryDataTag dataTag) {
/*if (dataTag.getClassNames().contains("mochicrypt.Payload")) {
return true;
}*/
return null;
}
@Override
public boolean decrypt(InputStream is, OutputStream os) throws IOException {
byte[] payload = Helper.readStream(is);
if (!handleXor(payload)) {
return false;
}
try {
Helper.copyStreamEx(new InflaterInputStream(new ByteArrayInputStream(payload)), os);
} catch (IOException ex) {
return false;
}
return true;
}
private boolean handleXor(byte[] payload) {
if (payload.length < 16) {
return false;
}
int[] S = new int[256];
int i = 0;
int j;
int k;
int n;
int u;
int v;
n = payload.length - 16;
while (i < 256) {
S[i] = i;
i++;
}
j = 0;
i = 0;
while (i < 256) {
j = (j + S[i] + (payload[n + (i & 15)] & 0xff)) & 255;
u = S[i];
S[i] = S[j];
S[j] = u;
i++;
}
if (n > 0x20000) {
n = 0x20000;
}
j = 0;
i = 0;
k = 0;
while (k < n) {
i = (i + 1) & 255;
u = S[i];
j = (j + u) & 255;
v = S[j];
S[i] = v;
S[j] = u;
payload[k] = (byte) ((payload[k] & 0xff) ^ S[u + v & 255]);
k++;
}
return true;
}
@Override
public boolean encrypt(InputStream is, OutputStream os) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DeflaterOutputStream def = new DeflaterOutputStream(baos);
Helper.copyStreamEx(is, def);
def.finish();
byte[] payload = baos.toByteArray();
if (!handleXor(payload)) {
return false;
}
os.write(payload);
return true;
}
@Override
public String getName() {
return "MochiCrypt 16bit";
}
@Override
public Boolean suitableForData(byte[] data) {
return null;
}
@Override
public String getIdentifier() {
return "mochicrypt16";
}
}

View File

@@ -30,13 +30,13 @@ import java.util.zip.InflaterInputStream;
*
* @author JPEXS
*/
public class MochiCryptPacker implements Packer {
public class MochiCryptPacker32Bit implements Packer {
@Override
public Boolean suitableForBinaryData(DefineBinaryDataTag dataTag) {
if (dataTag.getClassNames().contains("mochicrypt.Payload")) {
/*if (dataTag.getClassNames().contains("mochicrypt.Payload")) {
return true;
}
}*/
return null;
}
@@ -120,7 +120,7 @@ public class MochiCryptPacker implements Packer {
@Override
public String getName() {
return "MochiCrypt";
return "MochiCrypt 32bit";
}
@Override
@@ -130,6 +130,6 @@ public class MochiCryptPacker implements Packer {
@Override
public String getIdentifier() {
return "mochicrypt";
return "mochicrypt32";
}
}

View File

@@ -23,7 +23,8 @@ import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.configuration.CustomConfigurationKeys;
import com.jpexs.decompiler.flash.configuration.SwfSpecificCustomConfiguration;
import com.jpexs.decompiler.flash.packers.HarmanAirPacker;
import com.jpexs.decompiler.flash.packers.MochiCryptPacker;
import com.jpexs.decompiler.flash.packers.MochiCryptPacker16Bit;
import com.jpexs.decompiler.flash.packers.MochiCryptPacker32Bit;
import com.jpexs.decompiler.flash.packers.Packer;
import com.jpexs.decompiler.flash.tags.base.BinaryDataInterface;
import com.jpexs.decompiler.flash.tags.base.CharacterTag;
@@ -71,7 +72,8 @@ public class DefineBinaryDataTag extends CharacterTag implements BinaryDataInter
private PackedBinaryData sub;
private static final Packer[] PACKERS = {
new MochiCryptPacker(),
new MochiCryptPacker16Bit(),
new MochiCryptPacker32Bit(),
new HarmanAirPacker()
};
@@ -133,8 +135,10 @@ public class DefineBinaryDataTag extends CharacterTag implements BinaryDataInter
BinaryDataInterface binaryData = this;
if (usedPacker != null) {
unpack(usedPacker);
is = new ByteArrayInputStream(sub.getDataBytes().getRangeData());
binaryData = sub;
if (sub != null) {
is = new ByteArrayInputStream(sub.getDataBytes().getRangeData());
binaryData = sub;
}
}
SWF bswf = new SWF(is, null, "(SWF Data)", Configuration.parallelSpeedUp.get(), charset);