public
Created

Terrible party buffalo code

  • Download Gist
Processbootsector.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
 
void ProcessBootSector()
{
Exception InvalidSectorsPerCluster = new Exception("FATX: found invalid sectors per cluster");
Exception InvalidBytesPerSector = new Exception("FATX: invalid bytes per cluster for growable file partition");
Exception TooSmallClusterSize = new Exception("FATX: found too small of cluster size");
Exception VolumeTooSmall = new Exception("FATX: volume too small to hold the FAT");
Exception TooManyClusters = new Exception("FATX: too many clusters");
 
// r31 = r3 + 0xa8
long r31 = 0x3A1E69E8;
// move r5 in to r28
long r28 = PartitionSize();//0xD0EA6000;//PartitionSize(); //0x0000000004000000 UNCOMMENT HERE
// Set r10
long r10 = 0x1000;
// Set r30 to sp + 0x50
long r30 = 0;
long SP50 = r30;
// Set r11
long r11 = 0x200; // Drive sector size?
// Set r9
long r9 = r31;
r11 += 0xFFF;
// Set r29
long r29 = (r11 & 0xFFFFF000);
r11 = 0;
long r26 = 0;
if (!(r29 <= 0x1000))
{
// Move r29
r10 = r29;
}
// Load long at r28
r11 = r28; // partition size
long r25 = (r10 & 0xFFFFFFFF);
if (r25 < r11)
{
// BRANCH
//long r7 = 0 /* Should be SP + 0x50, but that's 0. */, r5 = 0, r6 = 0;
long r3 = r31;
// Call fsc map buffer here, but we're not going to
r10 = 0;
r9 = 0;
r3 = 0;
if (r3 == 0)
{
r9 = 0x58544146; // FATX ("XTAF") magic
r11 = Magic();
if ((uint)r9 == Magic())
{
// Read sectors per cluster
r11 = SectorsPerCluster();//0x20;//SectorsPerCluster(); // UNCOMMENT HERE
if (r11 == 0)
{
throw InvalidSectorsPerCluster;
return;
}
if(!(r11 <= 2) && (r11 != 0x4) && (r11 != 0x8) && (r11 != 0x20) && (r11 != 0x40) && (r11 != 0x80))
{
throw InvalidSectorsPerCluster;
}
r9 = 9; // 9 because 0x1000 / 8 = 0x200, 0x200 = sector size
// Shift
r11 = r11 << (int)r9; // cluster size
long r31CC = r11;
if (r11 == 0)
{
// what
r11 = 0;//r30;
}
else // Usually branches here
{
r11 = cntlzw((uint)r11);
r11 = 0x1F - r11;
}
long r31D1 = r11;
if (r26 != 0) // Usually skips this
{
r11 = r31CC;
if (r11 != 0x4000)
{
throw InvalidBytesPerSector;
}
}
r11 = PartitionID();
long r31160 = r11;
r3 = SP50; // becomes pointer to FATX partition
long r27 = RootDirectoryCluster();
// FscUnmapBuffer
SP50 = r30;
r11 = r31CC;
if (r11 < r29)
{
throw TooSmallClusterSize;
}
r9 = (byte)r31D1;
r11 = r28;
r11 = (r11 >> (int)r9);
r11++;
// Entry size?
if (r11 < 0x0000FFF0 && r26 == 0)
{
// Should branch here
r10 = 1;
r11 = ((long)r11 << 1);
}
else if (r11 >= 0x0000FFF0)
{
r10 = 2;
r11 = ((long)r11 << 2);
}
r11 += r29;
long r31D2 = r10;
long r8 = r29 - 1;
r10 = (long)r28;
r11--;
r10 = r10 - r25;
// And with complement
r11 = r11 & ~r8;
r11 &= 0xFFFFFFFF;
if (r11 >= r10)
{
throw VolumeTooSmall;
}
r10 -= r11;
r9 &= 0xFFFFFFFFFFFFFF;
r8 = 0x000000000FFFFFFF;
r10 >>= (int)r9;
long r31C8 = clusters = (uint)r10;
if (r10 >= r8)
{
throw TooManyClusters;
}
Console.WriteLine(Partition.Offset.ToString("X") + " Clusters " + r10.ToString("X"));
fatsize = r11;
Console.WriteLine("r11 " + r11.ToString("X"));
r11 += r25;
Console.WriteLine("r11 " + r11.ToString("X"));
long r31D4 = r25;
r10 = r25 & 0xFFF;
Console.WriteLine("r25 " + r25.ToString("X") + "\r\nr10 " + r10.ToString("X"));
r11 &= 0xFFF;
Console.WriteLine("r11 " + r11.ToString("X"));
//fatsize = r11.UpToNearestCluster(r31CC);
r11 = r31CC;
Console.WriteLine("r11 " + r11.ToString("X"));
r11 &= 0xFFF;
Console.WriteLine("r11 " + r11.ToString("X"));
}
}
else
{
// BRANCH
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.