a quick hack to set the 32bit flag in corheader

This commit is contained in:
Chris Forbes
2010-08-15 18:03:28 +12:00
parent 9ba50a9c5e
commit cfbededcc4
2 changed files with 47 additions and 1 deletions

View File

@@ -155,9 +155,12 @@ OpenRA.TilesetBuilder.Form1.resources:
tools: editor ralint seqed filex tsbuild
all: game tools
fixheader: packaging/fixheader.cs
@$(CSC) packaging/fixheader.cs $(CSFLAGS) -out:fixheader.exe -t:exe $(COMMON_LIBS:%=-r:%)
define BUILD_ASSEMBLY
$$($(1)_TARGET): $$($(1)_SRCS) Makefile $$($(1)_DEPS)
$$($(1)_TARGET): $$($(1)_SRCS) Makefile $$($(1)_DEPS) fixheader
@echo CSC $$(@)
@$(CSC) $$($(1)_LIBS:%=-r:%) \
-out:$$(@) $(CSFLAGS) $$($(1)_FLAGS) \
@@ -165,6 +168,7 @@ $$($(1)_TARGET): $$($(1)_SRCS) Makefile $$($(1)_DEPS)
-t:"$$($(1)_KIND)" \
$$($(1)_EXTRA) \
$$($(1)_SRCS)
@mono fixheader.exe $$(@)
endef
$(foreach prog,$(PROGRAMS),$(eval $(call BUILD_ASSEMBLY,$(prog))))

42
packaging/fixheader.cs Normal file
View File

@@ -0,0 +1,42 @@
using System;
using System.IO;
namespace fixheader
{
class fixheader
{
static byte[] data;
static int peOffset;
static void Main(string[] args)
{
data = File.ReadAllBytes(args[0]);
peOffset = BitConverter.ToInt32(data, 0x3c);
var corHeaderRva = BitConverter.ToInt32(data, peOffset + 20 + 100 + 14 * 8);
var corHeaderOffset = RvaToOffset(corHeaderRva);
data[corHeaderOffset + 16] |= 2;
File.WriteAllBytes(args[0], data);
}
static int RvaToOffset(int va)
{
var numSections = BitConverter.ToInt16(data, peOffset + 6);
var numDataDirectories = BitConverter.ToInt32(data, peOffset + 24 + 92);
var sectionTableStart = peOffset + 24 + 96 + 8 * numDataDirectories;
for (var i = 0; i < numSections; i++)
{
var virtualSize = BitConverter.ToInt32(data, sectionTableStart + 40 * i + 8);
var virtualAddr = BitConverter.ToInt32(data, sectionTableStart + 40 * i + 12);
var fileOffset = BitConverter.ToInt32(data, sectionTableStart + 40 * i + 20);
if (va >= virtualAddr && va < virtualAddr + virtualSize)
return va - virtualAddr + fileOffset;
}
return 0;
}
}
}