Skip to content

Commit

Permalink
fix IO helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
buzzer-re committed Jul 25, 2023
1 parent b2b5faa commit 78f357e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
1 change: 1 addition & 0 deletions Shinigami/Ichigo/Unpacker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ LONG WINAPI GenericUnpacker::VEHandler(EXCEPTION_POINTERS* pExceptionPointers)
ULONG_PTR StartAddress = (ULONG_PTR)pExceptionPointers->ContextRecord->XIP;
Memory* Mem = GenericUnpacker::cUnpacker.IsBeingMonitored(StartAddress);
Mem->IP = (ULONG_PTR) pExceptionPointers->ContextRecord->XIP;

if (GenericUnpacker::cUnpacker.Dump(Mem))
{
PipeLogger::Log(L"Saved stage %d as %s ", GenericUnpacker::cUnpacker.StagesPath.size(), GenericUnpacker::cUnpacker.StagesPath.back().c_str());
Expand Down
28 changes: 10 additions & 18 deletions Shinigami/Ichigo/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,28 @@

BOOL Utils::SaveToFile(const wchar_t* filename, Memory* data, BOOL Paginate)
{
HANDLE hFile = CreateFileW(filename, FILE_APPEND_DATA, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
HANDLE hFile = CreateFileW(filename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
BOOL success = TRUE;

if (hFile == INVALID_HANDLE_VALUE) {
return false;
}

DWORD BytesWritten = 0;

if (Paginate)
{
// Write based on the VirtualQuery output
MEMORY_BASIC_INFORMATION mbi;
DWORD Written = 0;
while (Written < data->Size)
{
VirtualQuery(data->Addr + Written, &mbi, sizeof(mbi));
WriteFile(hFile, data->Addr + Written, mbi.RegionSize, &BytesWritten, NULL);
Written += BytesWritten;
}
}
else
DWORD OldProt;
VirtualProtect(data->Addr, data->Size, PAGE_READWRITE, &OldProt);
success = WriteFile(hFile, data->Addr, data->Size, &BytesWritten, NULL) && (BytesWritten == data->Size);
PipeLogger::Log(L"Written %d bytes of file that has %d bytes\n", BytesWritten, data->Size);
if (BytesWritten != data->Size)
{
success = WriteFile(hFile, data->Addr, data->Size, &BytesWritten, NULL) && (BytesWritten == data->Size);
PipeLogger::Log(L"Error: %d", GetLastError());

}
VirtualProtect(data->Addr, data->Size, OldProt, &OldProt);


CloseHandle(hFile);

return success;
return TRUE;
}


Expand Down

0 comments on commit 78f357e

Please sign in to comment.