BadImageFormatException on some obfuscated executables

Aperta
#4,343 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
csharp

Direzione di ricerca

Start with the ILSpyCmd reproduction command and the stack traces, then compare the failing paths in ReflectionDisassembler.WriteParameters and InstructionOutputExtensions.WriteTo with the workaround in issue #4203. Reproduce both the original and DE4dot-processed samples to identify where metadata reads go out of bounds. Done means ILSpyCmd handles these malformed signatures without crashing and has regression coverage for both paths.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug

There are some other obfuscated .NET executables which still cause ILSpyCmd version 11.2 to crash.
One such sample is: https://www.virustotal.com/gui/file/9ff205599b9eea5e561170ef0e9843a31578cbb117759d32e3c1df96d7bc9838

This issue appears similar to https://github.com/icsharpcode/ILSpy/issues/4203. (which I've confirmed has been fixed), but with a different stack trace.
Could a similar workaround be implemented like with the previous issue?

Steps to reproduce

Attempt to disassemble an obfuscated sample, such as the above:
ilspycmd -il -o disasm 9ff205599b9eea5e561170ef0e9843a31578cbb117759d32e3c1df96d7bc9838

Error message shown

On the sample as-is:

System.BadImageFormatException: Read out of bounds.
   at System.Reflection.Throw.OutOfBounds() + 0x27
   at ICSharpCode.Decompiler.Disassembler.ReflectionDisassembler.WriteParameters(MetadataReader, IEnumerable`1, MethodSignature`1) + 0x734
   at ICSharpCode.Decompiler.Disassembler.ReflectionDisassembler.DisassembleMethodHeaderInternal(MetadataFile, MethodDefinitionHandle, MetadataGenericContext) + 0xdcb
   at ICSharpCode.Decompiler.Disassembler.ReflectionDisassembler.DisassembleMethod(MetadataFile, MethodDefinitionHandle) + 0xd7
   at ICSharpCode.Decompiler.Disassembler.ReflectionDisassembler.DisassembleType(MetadataFile, TypeDefinitionHandle) + 0xcfd
   at ICSharpCode.Decompiler.Disassembler.ReflectionDisassembler.WriteModuleContents(MetadataFile) + 0x9c
   at ICSharpCode.ILSpyCmd.ILSpyCmdProgram.ShowIL(String assemblyFileName, TextWriter output, CommandLineApplication app) + 0x17e
   at ICSharpCode.ILSpyCmd.ILSpyCmdProgram.<OnExecuteAsync>g__PerformPerFileAction|118_0(String fileName, ILSpyCmdProgram.<>c__DisplayClass118_0&, ILSpyCmdProgram.<>c__DisplayClass118_1&) + 0x784
   at ICSharpCode.ILSpyCmd.ILSpyCmdProgram.<OnExecuteAsync>d__118.MoveNext() + 0x38c

On the sample deobfuscated with DE4Dot:

System.BadImageFormatException: Read out of bounds.
   at System.Reflection.Throw.OutOfBounds() + 0x27
   at System.Reflection.Metadata.Ecma335.SignatureDecoder`2.DecodeMethodSignature(BlobReader&) + 0x27f
   at ICSharpCode.Decompiler.IL.InstructionOutputExtensions.WriteTo(EntityHandle, MetadataFile, ITextOutput, MetadataGenericContext, ILNameSyntax) + 0xc01
   at ICSharpCode.Decompiler.Disassembler.ReflectionDisassembler.DisassembleMethodBlock(MetadataFile, MethodDefinitionHandle, MetadataGenericContext) + 0x130
   at ICSharpCode.Decompiler.Disassembler.ReflectionDisassembler.DisassembleType(MetadataFile, TypeDefinitionHandle) + 0xcfd
   at ICSharpCode.Decompiler.Disassembler.ReflectionDisassembler.WriteModuleContents(MetadataFile) + 0x9c
   at ICSharpCode.ILSpyCmd.ILSpyCmdProgram.ShowIL(String assemblyFileName, TextWriter output, CommandLineApplication app) + 0x17e
   at ICSharpCode.ILSpyCmd.ILSpyCmdProgram.<OnExecuteAsync>g__PerformPerFileAction|118_0(String fileName, ILSpyCmdProgram.<>c__DisplayClass118_0&, ILSpyCmdProgram.<>c__DisplayClass118_1&) + 0x784
   at ICSharpCode.ILSpyCmd.ILSpyCmdProgram.<OnExecuteAsync>d__118.MoveNext() + 0x38c
Details
  • Product in use: ILSpyCmd
  • Version in use: 11.2.0.10050
Lingua principale
C#
Stelle
27.1k
Fork
3.8k
Merge medio
1g 23h
PR unite (30g)
44

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di icsharpcode/ILSpy

Tutte le issue di icsharpcode/ILSpy

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.