dnlib icon indicating copy to clipboard operation
dnlib copied to clipboard

InvalidOperationException when md rva isn't alignment

Open CreateAndInject opened this issue 2 years ago • 5 comments

https://github.com/0xd4d/dnlib/blob/71946df40541d1d97f62e249f3f39036e04e60da/src/DotNet/Writer/Metadata.cs#L3695-L3736

this?

		public void SetOffset(FileOffset offset, RVA rva) {
			uint rem = (uint)rva % HEAP_ALIGNMENT;
                        ......
			foreach (var heap in metadataHeader.Heaps) {
				offset = (offset - rem).AlignUp(HEAP_ALIGNMENT) + rem;
				rva = (rva - rem).AlignUp(HEAP_ALIGNMENT) + rem;
				...
			}

CreateAndInject avatar Feb 03 '24 17:02 CreateAndInject

Why isn't it aligned?

wtfsck avatar Feb 07 '24 19:02 wtfsck

test.zip

var module = ModuleDefMD.Load(@"test.exe");
module.NativeWrite("output.exe"); // InvalidOperationException 

CreateAndInject avatar Feb 08 '24 07:02 CreateAndInject

What's wrong?

CreateAndInject avatar Feb 24 '24 18:02 CreateAndInject

I haven't looked at this yet, but if you know how to fix this, you can send a PR.

wtfsck avatar Feb 24 '24 20:02 wtfsck

No idea if alignment is requirement and how the alignment should be.

CreateAndInject avatar Mar 04 '24 18:03 CreateAndInject