-
Notifications
You must be signed in to change notification settings - Fork 2
/
DK2_LS_FW2_12.d
70 lines (58 loc) · 2.27 KB
/
DK2_LS_FW2_12.d
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
/*
** Public domain (or any OSS license you want)
** https://github.com/nairol
*/
// How to compile:
// Get the latest DMD compiler from http://dlang.org/ (e.g. DMD v2.067.1)
// Open a cmd window in the folder where this file is. (e.g. in Explorer SHIFT+Right-click => "Open cmd window here")
// Command: dmd <ThisFileName>
import std.stdio : writeln, readf;
import std.conv : parse;
import std.file : read, write;
import std.digest.crc : CRC32;
import std.bitmanip : littleEndianToNative, nativeToLittleEndian;
void main( string[] args )
{
uint lensSeparation = 63500;
if( args.length < 2 )
{
writeln("\nPlease enter the new lens separation in micrometers: (default=63500)");
readf("%s", &lensSeparation);
}
else
{
lensSeparation = args[1].parse!uint();
}
/* HERE COMES THE IMPORTANT PART ... */
// Read the whole file into a buffer
auto buf = cast(ubyte[]) read( "DK2Firmware_2_12.ovrf" );
// Change the code and add the lens separation data
buf[0x00B925..0x00B929] = [0x10, 0xF0, 0x76, 0xBB]; // B.W 0801FFF4
buf[0x01C015..0x01C019] = [0xDF, 0xF8, 0x04, 0x00]; // LDR.W R0, [PC,#4]
buf[0x01C019..0x01C01D] = [0xEF, 0xF7, 0x86, 0xBC]; // B.W 0800F908
buf[0x01C01D..0x01C021] = lensSeparation.nativeToLittleEndian();
// Calculate the CRC32 of the firmware image and its header
// Start at file offset 0x1B and stop after the last byte of the file
CRC32 crc;
crc.put( buf[0x1B..$] );
auto crcResult = crc.finish();
// Replace the old CRC32 value (at file offset 0x17) with the new one
buf[0x000017..0x00001B] = crcResult[];
// Save the new file
write("DK2Firmware_2_12.patched.ovrf", buf);
/* ... END OF THE IMPORTANT PART */
writeln();
writeln("Lens separation has been changed to ",
buf[0x01C01D..0x01C021].littleEndianToNative!uint,
" micrometers.");
writeln();
writeln("Patched firmware was saved as DK2Firmware_2_12.patched.ovrf");
writeln();
writeln("Use the official Oculus configuration tool to upload the new");
writeln(" firmware file to your DK2.");
writeln();
writeln("USE THIS NEW FIRMWARE AT YOUR OWN RISK! Oculus does not support custom");
writeln(" firmware on your device. If it breaks, you will have to fix it yourself.");
writeln();
}