Skip to content

Commit

Permalink
Was working on some stuff I forgot about, anyways I made it use a uni…
Browse files Browse the repository at this point in the history
…que ID in the user agent
  • Loading branch information
Connicpu committed Jun 15, 2019
1 parent 5cd3eb1 commit a136034
Show file tree
Hide file tree
Showing 18 changed files with 446 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

sqpatch/target/

# User-specific files
*.rsuser
*.suo
Expand Down
3 changes: 3 additions & 0 deletions FFXIVLauncher/FFXIVLauncher.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@
<Image Include="dalamud.ico" />
<Image Include="icon_hide.ico" />
</ItemGroup>
<ItemGroup>
<Text Include="PatchFileNotes.txt" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
5 changes: 5 additions & 0 deletions FFXIVLauncher/FFXIVLauncher.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,9 @@
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
<ItemGroup>
<Text Include="PatchFileNotes.txt">
<Filter>Resource Files</Filter>
</Text>
</ItemGroup>
</Project>
40 changes: 37 additions & 3 deletions FFXIVLauncher/Http.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
#include "Common.h"
#include "Http.h"
#include <cassert>
#include <string>

template <typename T> using ComPtr = ATL::CComPtr<T>;

static const char *const USER_AGENT = "SQEXAuthor/2.0.0(Windows 6.2; ja-jp; 15c5fd77b2)";
static char ToHex(uint8_t in)
{
assert(in < 16);
if (in < 10) return '0' + in;
return 'a' + in - 10;
}

static std::string CalcUserAgent()
{
// Just use the MAC address
UUID uuid;
UuidCreateSequential(&uuid);

char mac_string[11] = { 0 };
for (int i = 0; i < 5; ++i)
{
mac_string[i * 2] = ToHex(uuid.Data4[i + 3] >> 4);
mac_string[i * 2 + 1] = ToHex(uuid.Data4[i + 3] & 0xF);
}

return std::string("SQEXAuthor/2.0.0(Windows 6.2; ja-jp; ") + mac_string + ")";
}

static const std::string USER_AGENT = CalcUserAgent();

static const char *const VERBS[2] =
{
Expand Down Expand Up @@ -48,13 +73,22 @@ HRESULT DoRequest(const Request &req, Response &response)
goto cleanup;
}

hI = InternetOpenA(USER_AGENT, INTERNET_OPEN_TYPE_DIRECT, nullptr, nullptr, 0);
hI = InternetOpenA(USER_AGENT.c_str(), INTERNET_OPEN_TYPE_DIRECT, nullptr, nullptr, 0);
if (hI == nullptr) goto fail;

hCon = InternetConnectA(hI, url.host.c_str(), 443, nullptr, nullptr, INTERNET_SERVICE_HTTP, 0, 0);
if (hCon == nullptr) goto fail;

hReq = HttpOpenRequestA(hCon, VERBS[(int)req.method], url.path.c_str(), "HTTP/1.1", nullptr, nullptr, INTERNET_FLAG_SECURE, 0);
hReq = HttpOpenRequestA(
hCon,
VERBS[(int)req.method],
url.path.c_str(),
"HTTP/1.1",
nullptr,
nullptr,
INTERNET_FLAG_SECURE | INTERNET_FLAG_RELOAD,
0
);
if (hReq == nullptr) goto fail;

if (req.headers.size() > 0)
Expand Down
10 changes: 9 additions & 1 deletion FFXIVLauncher/Login.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,15 @@ static LoginResult GetRealSID(const std::string & sid, std::string & result)

bool IsLobbyServerReady()
{
Request req = { Method::GET, ARRSTATUS_URL };
Request req =
{
Method::GET,
ARRSTATUS_URL,
{
{"Referer", "https://arrstatus.com/"},
{"Cookie", "status=1"},
}
};

Response resp;
auto hr = DoRequest(req, resp);
Expand Down
41 changes: 41 additions & 0 deletions FFXIVLauncher/PatchFileNotes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Very very incomplete notes, the ramblings of an insane girl who wants to make her own patcher for some godsforsaken reason

# Patch file

# HIST Entry

# APLY Entry
Entry length : 4 bytes (big endian)
Signature : 4 bytes "APLY"
??? : 4 bytes (big endian)
Entry data : [Entry length] bytes

# SQPK Entry
Container length : 4 bytes (big endian)
Signature : 4 bytes "SQPK"
Container length : 4 bytes (big endian) (yes it seems to be duplicated; data integrity reasons?)
Container data : [Container length] bytes

All containers seem to start with a 2 byte magic marker that determines
what kind of data is stored in there.

Types:
- "T" (TBD)
- "X" (TBD)
- "FA" (Raw file record?)

# Raw file record?

Type marker? : 2 bytes "FA"
??? : 14 bytes (usually all 0 but not always? has nothing to do with padding len)
Output file len : 4 bytes (big endian)
File name len : 4 bytes (big endian)
??? : 4 bytes (always 0?)
File name : [File name len] bytes
??? : 4 bytes (little endian?) (appears to always be 0x10)
??? : 4 bytes (always 0?)
Data len 1 : 4 bytes (little endian) (is the array len if compressed, ??? when uncompressed)
Data len 2 : 4 bytes (little endian) (output length, and array len if compressed)
Patch data : [File data len] bytes
Padding : ??????? bytes (whyyyyy)

Binary file modified FFXIVLauncher/Resource.aps
Binary file not shown.
Binary file modified FFXIVLauncher/Resource.rc
Binary file not shown.
2 changes: 1 addition & 1 deletion FFXIVLauncher/StatusWait.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ static void InitializeUI(HWND dialog) noexcept
auto appIcon = LoadIconW(GetModuleHandleW(nullptr), MAKEINTRESOURCE(IDI_APPICON));
SendMessageW(dialog, WM_SETICON, ICON_BIG, (LPARAM)appIcon);

SetTimer(dialog, 69, 15'000, nullptr);
SetTimer(dialog, /*id=*/69, 20'000/*ms*/, nullptr);
SendDlgItemMessageW(dialog, IDC_PROGRESS1, PBM_SETMARQUEE, TRUE, 1);
}
14 changes: 14 additions & 0 deletions sqpatch/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions sqpatch/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "sqpatch"
version = "0.1.0"
authors = ["Connie Hilarides <[email protected]>"]
edition = "2018"

[dependencies]
byteorder = "1.3.1"
25 changes: 25 additions & 0 deletions sqpatch/src/aply.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use crate::{Parse, Stream};

use std::io;

use byteorder::{ReadBytesExt, BE};

pub const SQPK_SIG: u32 = 0x53_51_50_4B; // SQPK

#[derive(Copy, Clone, Debug)]
pub struct Aply {
pub data: [u32; 4],
}

impl Parse for Aply {
fn parse(stream: &mut impl Stream) -> io::Result<Aply> {
let data = [
stream.read_u32::<BE>()?,
stream.read_u32::<BE>()?,
stream.read_u32::<BE>()?,
stream.read_u32::<BE>()?,
];

Ok(Aply { data })
}
}
48 changes: 48 additions & 0 deletions sqpatch/src/container.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use crate::{Parse, Position, Stream};

use byteorder::{ReadBytesExt, BE};

#[derive(Copy, Clone)]
pub struct Container {
/// Does not include the 4 bytes at the beginning of the data
pub length: u32,
pub signature: [u8; 4],
pub data: Position,
}

impl Container {
pub fn read_contents<D>(&self, stream: &mut impl Stream) -> std::io::Result<D>
where
D: Parse,
{
stream.seek_to(self.data)?;
D::parse(stream)
}
}

impl Parse for Container {
fn parse(stream: &mut impl Stream) -> std::io::Result<Self> {
let length = stream.read_u32::<BE>()?;
let mut signature = [0; 4];
stream.read_exact(&mut signature)?;
let data = stream.pos()?;
stream.seek_by(length as i64 + 4)?;

Ok(Container {
length,
signature,
data,
})
}
}

impl std::fmt::Debug for Container {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
let sig = String::from_utf8_lossy(&self.signature);
fmt.debug_struct("Container")
.field("length", &self.length)
.field("signature", &sig)
.field("data", &self.data)
.finish()
}
}
94 changes: 94 additions & 0 deletions sqpatch/src/file_record.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
use crate::{Parse, Position, Stream};

use std::cmp::min;

use byteorder::{ReadBytesExt, BE, LE};

pub struct FileRecord {
pub header: [u8; 4],
pub unk0: u32,
pub file_offset: u32,
pub unk1: u32,
pub file_length: u32,
pub unk2: u32,
pub file_name: String,
pub chunks: Vec<FileChunk>,
pub hash: [u8; 4],
}

impl Parse for FileRecord {
fn parse(stream: &mut impl Stream) -> std::io::Result<FileRecord> {
let mut header = [0; 4];
stream.read_exact(&mut header)?;

let unk0 = stream.read_u32::<BE>()?;
let file_offset = stream.read_u32::<BE>()?;
let unk1 = stream.read_u32::<BE>()?;

let file_length = stream.read_u32::<BE>()?;
let file_name_len = stream.read_u32::<BE>()?;
let unk2 = stream.read_u32::<BE>()?;

let mut file_name = vec![0; file_name_len as usize];
stream.read_exact(&mut file_name)?;
file_name.pop();
let file_name = String::from_utf8_lossy(&file_name).into_owned();

let mut chunks = vec![];
loop {
if stream.peek_u32_le()? != 16 {
break;
}

chunks.push(FileChunk::parse(stream)?);
}

let mut hash = [0; 4];
stream.read_exact(&mut hash)?;

Ok(FileRecord {
header,
unk0,
file_offset,
unk1,
file_length,
unk2,
file_name,
chunks,
hash,
})
}
}

pub struct FileChunk {
pub unk0: u32,
pub unk1: u32,
pub data_len: u32,
pub expanded_len: u32,
pub data: Position,
}

impl Parse for FileChunk {
fn parse(stream: &mut impl Stream) -> std::io::Result<FileChunk> {
let begin = stream.pos()?;

let unk0 = stream.read_u32::<LE>()?;
let unk1 = stream.read_u32::<LE>()?;

let data_len = stream.read_u32::<LE>()?;
let expanded_len = stream.read_u32::<LE>()?;

let data = stream.pos()?;

stream.seek_by(min(data_len, expanded_len) as i64)?;
stream.align_up_from(begin, 0x80)?;

Ok(FileChunk {
unk0,
unk1,
data_len,
expanded_len,
data,
})
}
}
9 changes: 9 additions & 0 deletions sqpatch/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use std::fmt::UpperHex;

pub struct HexFmt<'a, T: UpperHex>(pub &'a T);

impl<T: UpperHex> std::fmt::Debug for HexFmt<'_, T> {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
self.0.fmt(fmt)
}
}
Loading

0 comments on commit a136034

Please sign in to comment.