MCPcopy Create free account
hub / github.com/Wemino/MarkerPatch / ValidatePatchedFile

Function ValidatePatchedFile

include/LAAPatcher.hpp:143–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141 // ========================
142
143 inline bool ValidatePatchedFile(const fs::path& origPath, const fs::path& patchPath)
144 {
145 wchar_t error[512];
146 std::vector<uint8_t> origData, patchData;
147
148 if (!ReadFile(origPath, origData))
149 {
150 swprintf_s(error, L"Validation failed: Could not read original file.\nPath: %s", origPath.wstring().c_str());
151 ShowError(error);
152 return false;
153 }
154
155 if (!ReadFile(patchPath, patchData))
156 {
157 swprintf_s(error, L"Validation failed: Could not read patched file.\nPath: %s", patchPath.wstring().c_str());
158 ShowError(error);
159 return false;
160 }
161
162 if (origData.empty())
163 {
164 ShowError("Validation failed: Original file is empty.");
165 return false;
166 }
167
168 if (patchData.empty())
169 {
170 ShowError("Validation failed: Patched file is empty.");
171 return false;
172 }
173
174 PEFile origPE(origData);
175 PEFile patchPE(patchData);
176
177 if (!origPE.Validate(error, _countof(error)))
178 {
179 ShowError(error);
180 return false;
181 }
182
183 if (!patchPE.Validate(error, _countof(error)))
184 {
185 ShowError(error);
186 return false;
187 }
188
189 if (origData.size() != patchData.size())
190 {
191 swprintf_s(error, L"Validation failed: File size changed (original=%zu, patched=%zu).", origData.size(), patchData.size());
192 ShowError(error);
193 return false;
194 }
195
196 origPE.EnableLAA();
197 origPE.ClearChecksum();
198 patchPE.ClearChecksum();
199
200 if (memcmp(origData.data(), patchData.data(), origData.size()) != 0)

Callers 1

PerformLAAPatchFunction · 0.85

Calls 8

ReadFileFunction · 0.85
ShowErrorFunction · 0.85
c_strMethod · 0.80
ValidateMethod · 0.80
EnableLAAMethod · 0.80
ClearChecksumMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected