aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancis Rowe <info@gluglug.org.uk>2014-12-22 17:37:32 +0000
committerFrancis Rowe <info@gluglug.org.uk>2014-12-22 17:56:33 +0000
commit4908830fdc561d76843220722e594d8e456d45b6 (patch)
tree89ee7ce21c5fd3e211741ec6d0da40b660d9370f
parentaa40313ec2f9f3042f7099e9ff05fe24bccb7164 (diff)
downloadlibrebootfr-4908830fdc561d76843220722e594d8e456d45b6.tar.gz
librebootfr-4908830fdc561d76843220722e594d8e456d45b6.zip
ich9deblob: fail if struct members are in wrong order in memory
-rw-r--r--resources/utilities/ich9deblob/ich9deblob.c61
1 files changed, 59 insertions, 2 deletions
diff --git a/resources/utilities/ich9deblob/ich9deblob.c b/resources/utilities/ich9deblob/ich9deblob.c
index 22c57873..216c8d0c 100644
--- a/resources/utilities/ich9deblob/ich9deblob.c
+++ b/resources/utilities/ich9deblob/ich9deblob.c
@@ -63,6 +63,7 @@ struct DESCRIPTORREGIONRECORD deblobbedFromFactory(struct DESCRIPTORREGIONRECORD
int structSizesIncorrect(struct DESCRIPTORREGIONRECORD descriptorDummy, struct GBEREGIONRECORD_8K gbe8kDummy);
int systemIsBigEndian();
int structBitfieldWrongOrder();
+int structMembersWrongOrder();
int main(int argc, char *argv[])
{
@@ -79,6 +80,7 @@ int main(int argc, char *argv[])
if (structSizesIncorrect(factoryDescriptorStruct, factoryGbeStruct8k)) return 1;
if (systemIsBigEndian()) return 1;
if (structBitfieldWrongOrder()) return 1;
+ if (structMembersWrongOrder()) return 1;
// -----------------------------------------------------------------------------------------------
@@ -295,6 +297,61 @@ int systemIsBigEndian() {
return 0;
}
+// fail if members are presented in the wrong order
+int structMembersWrongOrder() {
+ struct DESCRIPTORREGIONRECORD descriptorDummy;
+
+ // These do not use bitfields.
+ descriptorDummy.meVsccTable.jid0 = 0x01020304; // unsigned int 32-bit
+ descriptorDummy.meVsccTable.vscc0 = 0x10203040; // unsigned int 32-bit
+ descriptorDummy.meVsccTable.jid1 = 0x11223344; // unsigned int 32-bit
+ descriptorDummy.meVsccTable.vscc1 = 0x05060708; // unsigned int 32-bit
+ descriptorDummy.meVsccTable.jid2 = 0x50607080; // unsigned int 32-bit
+ descriptorDummy.meVsccTable.vscc2 = 0x55667788; // unsigned int 32-bit
+ descriptorDummy.meVsccTable.padding[0] = 0xAA; // unsigned char 8-bit
+ descriptorDummy.meVsccTable.padding[1] = 0xBB; // unsigned char 8-bit
+ descriptorDummy.meVsccTable.padding[2] = 0xCC; // unsigned char 8-bit
+ descriptorDummy.meVsccTable.padding[3] = 0xDD; // unsigned char 8-bit
+
+ // Look from the top down, and concatenate the unsigned ints but
+ // with each unsigned in little endian order.
+ // Then, concatenate the unsigned chars in big endian order. (in the padding array)
+
+ // combined, these should become:
+ // 01020304 10203040 11223344 05060708 50607080 55667788 AA BB CC DD (ignore this. big endian. just working it out manually:)
+ // 04030201 40302010 44332211 08070605 80706050 88776655 AA BB CC DD (ignore this. not byte-separated, just working it out:)
+ // 04 03 02 01 40 30 20 10 44 33 22 11 08 07 06 05 80 70 60 50 88 77 66 55 AA BB CC DD <-- it should match this
+
+ unsigned char *meVsccTablePtr = (unsigned char*)&descriptorDummy.meVsccTable;
+
+ printf("\nStruct member order check (descriptorDummy.meVsccTable) with junk/dummy data:");
+ printf("\nShould be: 04 03 02 01 40 30 20 10 44 33 22 11 08 07 06 05 80 70 60 50 88 77 66 55 aa bb cc dd ");
+ printf("\nAnd it is: ");
+ int i;
+ for (i = 0; i < 28; i++) {
+ printf("%02x ", *(meVsccTablePtr + i));
+ }
+ printf("\n");
+
+ if (
+ !
+ (
+ *meVsccTablePtr == 0x04 && *(meVsccTablePtr+1) == 0x03 && *(meVsccTablePtr+2) == 0x02 && *(meVsccTablePtr+3) == 0x01
+ && *(meVsccTablePtr+4) == 0x40 && *(meVsccTablePtr+5) == 0x30 && *(meVsccTablePtr+6) == 0x20 && *(meVsccTablePtr+7) == 0x10
+ && *(meVsccTablePtr+8) == 0x44 && *(meVsccTablePtr+9) == 0x33 && *(meVsccTablePtr+10) == 0x22 && *(meVsccTablePtr+11) == 0x11
+ && *(meVsccTablePtr+12) == 0x08 && *(meVsccTablePtr+13) == 0x07 && *(meVsccTablePtr+14) == 0x06 && *(meVsccTablePtr+15) == 0x05
+ && *(meVsccTablePtr+16) == 0x80 && *(meVsccTablePtr+17) == 0x70 && *(meVsccTablePtr+18) == 0x60 && *(meVsccTablePtr+19) == 0x50
+ && *(meVsccTablePtr+20) == 0x88 && *(meVsccTablePtr+21) == 0x77 && *(meVsccTablePtr+22) == 0x66 && *(meVsccTablePtr+23) == 0x55
+ && *(meVsccTablePtr+24) == 0xAA && *(meVsccTablePtr+25) == 0xBB && *(meVsccTablePtr+26) == 0xCC && *(meVsccTablePtr+27) == 0xDD
+ )
+ ) {
+ printf("Incorrect order.\n");
+ return 1;
+ }
+ printf("Correct order.\n");
+ return 0;
+}
+
// fail if bit fields are presented in the wrong order
int structBitfieldWrongOrder() {
struct DESCRIPTORREGIONRECORD descriptorDummy;
@@ -316,12 +373,12 @@ int structBitfieldWrongOrder() {
unsigned char *flMap0Ptr = (unsigned char*)&descriptorDummy.flMaps.flMap0;
- printf("Bitfield order check (descriptorDummy.flMaps.flMaps0):");
+ printf("\nBitfield order check (descriptorDummy.flMaps.flMaps0) with junk/dummy data:");
printf("\nShould be: a2 e2 d2 e5 ");
printf("\nAnd it is: ");
int i;
for (i = 0; i < 4; i++) {
- printf("%x ", *(flMap0Ptr + i));
+ printf("%02x ", *(flMap0Ptr + i));
}
printf("\n");