Author: ion
Date: Thu Jan 21 15:47:14 2016
New Revision: 70633
URL:
http://svn.reactos.org/svn/reactos?rev=70633&view=rev
Log:
[BOOTLIB]: Cleanup, less magic.
Modified:
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/misc/image.c
trunk/reactos/boot/environ/lib/misc/util.c
Modified: trunk/reactos/boot/environ/include/bl.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?…
==============================================================================
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Thu Jan 21 15:47:14 2016
@@ -154,6 +154,12 @@
#define BL_LOAD_PE_IMG_COMPUTE_HASH 0x10
#define BL_LOAD_PE_IMG_CHECK_SUBSYSTEM 0x80
#define BL_LOAD_PE_IMG_CHECK_FORCED_INTEGRITY 0x200
+
+#define BL_UTL_CHECKSUM_COMPLEMENT 0x10000
+#define BL_UTL_CHECKSUM_ROTATE 0x20000
+#define BL_UTL_CHECKSUM_NEGATE 0x40000
+#define BL_UTL_CHECKSUM_UCHAR_BUFFER 0x01
+#define BL_UTL_CHECKSUM_USHORT_BUFFER 0x02
/* ENUMERATIONS **************************************************************/
@@ -1618,6 +1624,14 @@
NTSTATUS
BlUtlRegisterProgressRoutine (
VOID
+ );
+
+ULONG
+BlUtlCheckSum (
+ _In_ ULONG PartialSum,
+ _In_ PUCHAR Buffer,
+ _In_ ULONG Length,
+ _In_ ULONG Flags
);
NTSTATUS
Modified: trunk/reactos/boot/environ/lib/misc/image.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/imag…
==============================================================================
--- trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] Thu Jan 21 15:47:14 2016
@@ -649,54 +649,6 @@
/* Unallocate the image buffer */
return BlImgUnallocateImageBuffer(ImageBase, ImageSize, ImageFlags);
-}
-
-unsigned int BlUtlCheckSum(unsigned int PartialSum, PUCHAR Source, unsigned int Length,
unsigned int Flags)
-{
- unsigned int Type; // eax@1
- int Type1; // eax@1
- unsigned int AlignedLength; // ebx@3
- unsigned int i; // ebx@21 MAPDST
-
- Type = Flags & 3;
- Type1 = Type - 1;
- if (Type1)
- {
- if (Type1 == 1)
- {
- PartialSum = (unsigned __int16)PartialSum;
- AlignedLength = Length & ~1;
- if (Length & ~1)
- {
- i = 0;
- do
- {
- PartialSum += *(unsigned __int16 *)&Source[i];
- if (Flags & 0x10000)
- PartialSum = (unsigned __int16)((PartialSum >> 16) +
PartialSum);
- i += 2;
- } while (i < AlignedLength);
- }
-
- if (Length != AlignedLength)
- {
- PartialSum += (unsigned __int8)Source[AlignedLength];
- if (Flags & 0x10000)
- PartialSum = (unsigned __int16)((PartialSum >> 16) +
PartialSum);
- }
- if (Flags & 0x40000)
- return ~PartialSum;
- PartialSum = (unsigned __int16)PartialSum;
- }
- }
- else
- {
- EfiPrintf(L"checksum type not supported\r\n");
- }
-
- if (Flags & 0x40000)
- return ~PartialSum;
- return PartialSum;
}
NTSTATUS
@@ -921,7 +873,11 @@
NtHeaders->OptionalHeader.CheckSum = 0;
/* Calculate the checksum of the header, and restore the original one */
- PartialSum = BlUtlCheckSum(0, VirtualAddress, HeaderSize, 0x10002);
+ PartialSum = BlUtlCheckSum(0,
+ VirtualAddress,
+ HeaderSize,
+ BL_UTL_CHECKSUM_COMPLEMENT |
+ BL_UTL_CHECKSUM_USHORT_BUFFER);
NtHeaders->OptionalHeader.CheckSum = CheckSum;
/* Record our current position (right after the headers) */
@@ -1037,7 +993,8 @@
PartialSum = BlUtlCheckSum(PartialSum,
(PUCHAR)SectionStart,
AlignSize,
- 0x10002);
+ BL_UTL_CHECKSUM_COMPLEMENT |
+ BL_UTL_CHECKSUM_USHORT_BUFFER);
}
}
@@ -1114,7 +1071,8 @@
PartialSum = BlUtlCheckSum(PartialSum,
LocalBuffer,
BytesRead,
- 0x10002);
+ BL_UTL_CHECKSUM_COMPLEMENT |
+ BL_UTL_CHECKSUM_USHORT_BUFFER);
}
/* Finally, calculate the final checksum and compare it */
Modified: trunk/reactos/boot/environ/lib/misc/util.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/util…
==============================================================================
--- trunk/reactos/boot/environ/lib/misc/util.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/misc/util.c [iso-8859-1] Thu Jan 21 15:47:14 2016
@@ -720,3 +720,61 @@
return Status;
}
+ULONG
+BlUtlCheckSum (
+ _In_ ULONG PartialSum,
+ _In_ PUCHAR Buffer,
+ _In_ ULONG Length,
+ _In_ ULONG Flags
+ )
+{
+ ULONG i;
+
+ if (Flags & BL_UTL_CHECKSUM_UCHAR_BUFFER)
+ {
+ EfiPrintf(L"Not supported\r\n");
+ return 0;
+ }
+ else if (Flags & BL_UTL_CHECKSUM_USHORT_BUFFER)
+ {
+ PartialSum = (unsigned __int16)PartialSum;
+ Length &= ~1;
+
+ for (i = 0; i < Length; i += 2)
+ {
+ PartialSum += *(unsigned __int16 *)&Buffer[i];
+ if (Flags & BL_UTL_CHECKSUM_COMPLEMENT)
+ {
+ PartialSum = (unsigned __int16)((PartialSum >> 16) + PartialSum);
+ }
+ }
+
+ if (Length != Length)
+ {
+ PartialSum += (unsigned __int8)Buffer[Length];
+ if (Flags & BL_UTL_CHECKSUM_COMPLEMENT)
+ {
+ PartialSum = (unsigned __int16)((PartialSum >> 16) + PartialSum);
+ }
+ }
+
+ if (Flags & BL_UTL_CHECKSUM_NEGATE)
+ {
+ return ~PartialSum;
+ }
+
+ PartialSum = (unsigned __int16)PartialSum;
+ }
+ else
+ {
+ /* Invalid mode */
+ return 0;
+ }
+
+ if (Flags & BL_UTL_CHECKSUM_NEGATE)
+ {
+ return ~PartialSum;
+ }
+
+ return PartialSum;
+}