de4dot-cex/de4dot.code/deobfuscators/IDeobfuscator.cs

110 lines
3.4 KiB
C#
Raw Permalink Normal View History

2011-09-22 10:55:30 +08:00
/*
2015-10-30 05:45:26 +08:00
Copyright (C) 2011-2015 de4dot@gmail.com
2011-09-22 10:55:30 +08:00
This file is part of de4dot.
de4dot is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
de4dot 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with de4dot. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using dnlib.PE;
using dnlib.DotNet;
using dnlib.DotNet.Writer;
2011-09-22 10:55:30 +08:00
using de4dot.blocks;
2012-01-11 11:38:02 +08:00
using de4dot.blocks.cflow;
using de4dot.code.renamer;
2011-09-22 10:55:30 +08:00
namespace de4dot.code.deobfuscators {
public interface IDeobfuscatorOptions {
2011-09-22 10:55:30 +08:00
bool RenameResourcesInCode { get; }
}
public enum DecrypterType {
Default,
None,
Static,
Delegate,
Emulate,
}
2011-09-22 10:55:30 +08:00
[Flags]
public enum StringFeatures {
AllowNoDecryption = 1,
AllowStaticDecryption = 2,
AllowDynamicDecryption = 4,
2011-09-22 10:55:30 +08:00
AllowAll = AllowNoDecryption | AllowStaticDecryption | AllowDynamicDecryption,
}
[Flags]
public enum RenamingOptions {
RemoveNamespaceIfOneType = 1,
2012-05-03 22:47:34 +08:00
RenameResourceKeys = 2,
}
public interface IDeobfuscator : INameChecker, IDisposable {
2011-09-22 10:55:30 +08:00
string Type { get; }
2011-11-12 18:31:07 +08:00
string TypeLong { get; }
2011-09-22 10:55:30 +08:00
string Name { get; }
IDeobfuscatorOptions TheOptions { get; }
IOperations Operations { get; set; }
2012-12-01 10:24:12 +08:00
MetaDataFlags MetaDataFlags { get; }
StringFeatures StringFeatures { get; }
RenamingOptions RenamingOptions { get; }
DecrypterType DefaultDecrypterType { get; }
IEnumerable<IBlocksDeobfuscator> BlocksDeobfuscators { get; }
2011-09-22 10:55:30 +08:00
// This is non-null only in detect() and deobfuscateBegin().
2011-09-22 10:55:30 +08:00
IDeobfuscatedFile DeobfuscatedFile { get; set; }
// Returns null or the unpacked .NET PE file
2013-01-19 20:03:57 +08:00
byte[] UnpackNativeFile(IPEImage peImage);
2013-01-19 20:03:57 +08:00
void Initialize(ModuleDefMD module);
// Returns 0 if it's not detected, or > 0 if detected (higher value => more likely true).
// This method is always called.
2013-01-19 20:03:57 +08:00
int Detect();
2011-09-22 10:55:30 +08:00
// If the obfuscator has encrypted parts of the file, then this method should return the
// decrypted file. true is returned if args have been initialized, false otherwise.
2013-01-19 20:03:57 +08:00
bool GetDecryptedModule(int count, ref byte[] newFileData, ref DumpedMethods dumpedMethods);
// This is only called if getDecryptedModule() != null, and after the module has been
// reloaded. Should return a new IDeobfuscator with the same options and the new module.
2013-01-19 20:03:57 +08:00
IDeobfuscator ModuleReloaded(ModuleDefMD module);
2011-09-22 10:55:30 +08:00
// Called before all other deobfuscation methods
2013-01-19 20:03:57 +08:00
void DeobfuscateBegin();
2011-09-22 10:55:30 +08:00
// Called before the code is deobfuscated
2013-01-19 20:03:57 +08:00
void DeobfuscateMethodBegin(Blocks blocks);
2011-09-22 10:55:30 +08:00
// Return true if we should deobfuscate control flow again
2013-01-19 20:03:57 +08:00
bool DeobfuscateOther(Blocks blocks);
2011-09-22 10:55:30 +08:00
// Called after deobfuscateMethodBegin() but before deobfuscateMethodEnd()
2013-01-19 20:03:57 +08:00
void DeobfuscateStrings(Blocks blocks);
2011-09-22 10:55:30 +08:00
// Called after the code has been deobfuscated
2013-01-19 20:03:57 +08:00
void DeobfuscateMethodEnd(Blocks blocks);
2011-09-22 10:55:30 +08:00
// Called after all deobfuscation methods
2013-01-19 20:03:57 +08:00
void DeobfuscateEnd();
2011-09-22 10:55:30 +08:00
2012-05-30 01:07:01 +08:00
// Returns all string decrypter method tokens
2013-01-19 20:03:57 +08:00
IEnumerable<int> GetStringDecrypterMethods();
2011-09-22 10:55:30 +08:00
}
}