How to test if Aes encryption key is correct

Extraction and unpacking of game archives and compression, encryption, obfuscation, decoding of unknown files
Meonpie
Posts: 16
Joined: Mon Feb 07, 2022 4:18 pm

How to test if Aes encryption key is correct

Post by Meonpie »

I get a conset16 bit sKey when I decompile a SO file, I would like to know how to edit the script to test if this key I found can decrypt the file
Because I didn't decompile the method, I want to test whether the regular method can be decrypted :geek:

this Key:"250d7a1a2a9c7c09"

Code: Select all

using IFix;

public class AES
{
	private static string sKey = "250d7a1a2a9c7c09";

	public static byte[] Encrypt(byte[] sSrc)
	{
		//Discarded unreachable code: IL_0022, IL_0025, IL_002c, IL_0046, IL_0054, IL_0057, IL_005d, IL_0064, IL_007f, IL_0085, IL_008b, IL_0091, IL_0097
		//IL_0002: Expected I8, but got I4
		//IL_0015: Expected I8, but got I4
		//IL_0021: Expected O, but got I8
		//IL_003b: Expected I8, but got I4
		//IL_0057: Expected I8, but got I4
		//IL_0067: Expected I8, but got I4
		long num = 1L;
		bool flag = WrappersManagerImpl.IsPatched(6360);
		int id = 6360;
		long num2 = 0L;
		return WrappersManagerImpl.GetPatch(id).__Gen_Wrap_192(num2);
	}

	public static byte[] Decrypt(byte[] encrypted)
	{
		//Discarded unreachable code: IL_0022, IL_0025, IL_002c, IL_0046, IL_0054, IL_0057, IL_005e, IL_0072, IL_008d, IL_0093, IL_0099, IL_009f, IL_00a5, IL_00ac, IL_00b5
		//IL_0002: Expected I8, but got I4
		//IL_0015: Expected I8, but got I4
		//IL_0021: Expected O, but got I8
		//IL_003b: Expected I8, but got I4
		//IL_0057: Expected I8, but got I4
		//IL_006b: Expected I8, but got I4
		//IL_0075: Expected I8, but got I4
		//IL_00af: Expected I8, but got I4
		long num = 1L;
		bool flag = WrappersManagerImpl.IsPatched(-1342177280);
		int id = 6338;
		long num2 = 0L;
		return WrappersManagerImpl.GetPatch(id).__Gen_Wrap_192(num2);
	}
}
I also found this one

Code: Select all

using Cpp2IlInjected;
using IFix;
using UnityEngine;

public class teset : MonoBehaviour
{
	public static string byteStream = "10, 30, 9, 0, 0, 0, 0, 0, 0, 8, 64, 21, 0, 0, -128, 64";

	public static byte[] ParseBytes()
	{
		throw new Cpp2IlInjected.AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
	}

	public static string Byte2Str(byte[] bytes)
	{
		//Discarded unreachable code: IL_0020, IL_004a
		//IL_0013: Expected I8, but got I4
		//IL_001f: Expected O, but got I8
		//IL_0029: Expected I8, but got I4
		//IL_002c: Expected I8, but got I4
		//IL_0034: Expected I4, but got I8
		bool flag = WrappersManagerImpl.IsPatched(9640);
		int id = 9640;
		long num = 0L;
		return WrappersManagerImpl.GetPatch(id).__Gen_Wrap_114(num);
	}

	private void Start()
	{
		//Discarded unreachable code: IL_001c, IL_0023
		bool flag = WrappersManagerImpl.IsPatched(9641);
		WrappersManagerImpl.GetPatch(9641).__Gen_Wrap_2(this);
	}

	private void AES_Encrypt()
	{
		//Discarded unreachable code: IL_001e, IL_0021, IL_003a, IL_0047, IL_0066, IL_0131
		//IL_0002: Expected I8, but got I4
		//IL_004a: Expected I8, but got I4
		//IL_012b: Expected O, but got I4
		long num = 1L;
		bool flag = WrappersManagerImpl.IsPatched(9642);
		WrappersManagerImpl.GetPatch(9642).__Gen_Wrap_2(this);
	}
testfile.zip
spiritovod
Posts: 719
Joined: Sat Sep 28, 2019 7:00 pm

Re: How to test if Aes encryption key is correct

Post by spiritovod »

What's the game name?
Meonpie
Posts: 16
Joined: Mon Feb 07, 2022 4:18 pm

Re: How to test if Aes encryption key is correct

Post by Meonpie »

spiritovod wrote:What's the game name?
Sorry forgot to mention the name of the game:One Piece Burning Will

I also keep the previous version of the file, the encryption method is the same
babyfive002_body.zip
I also found this py script but it doesn't work for newer versions
https://zenhax.com/viewtopic.php?t=12516
spiritovod
Posts: 719
Joined: Sat Sep 28, 2019 7:00 pm

Re: How to test if Aes encryption key is correct

Post by spiritovod »

@Meonpie: Encryption in latest versions looks the same as before, just with different xor bytes set, I've provided script in the original topic, but output is not compatible with AssetStudio anyway, which is not the encryption issue.