Skip to content

Commit

Permalink
Refactor driver memory api.
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackINT3 committed Aug 6, 2020
1 parent 35db2f3 commit 339d01f
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 36 deletions.
4 changes: 4 additions & 0 deletions src/OpenArk/OpenArk.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\OpenArkDrv\arkdrv-api\api-memory\api-memory.cpp" />
<ClCompile Include="..\OpenArkDrv\arkdrv-api\api-storage\api-storage.cpp" />
<ClCompile Include="..\OpenArkDrv\arkdrv-api\arkdrv-api.cpp" />
<ClCompile Include="about\about.cpp" />
<ClCompile Include="bundler\bundler.cpp" />
Expand Down Expand Up @@ -338,6 +340,8 @@
</QtRcc>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\OpenArkDrv\arkdrv-api\api-memory\api-memory.h" />
<ClInclude Include="..\OpenArkDrv\arkdrv-api\api-storage\api-storage.h" />
<ClInclude Include="..\OpenArkDrv\arkdrv-api\arkdrv-api.h" />
<ClInclude Include="common\app\app.h" />
<ClInclude Include="common\cache\cache.h" />
Expand Down
18 changes: 18 additions & 0 deletions src/OpenArk/OpenArk.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@
<Filter Include="common\ui-wrapper">
<UniqueIdentifier>{16858abf-3377-4e71-84fa-f20c0e3a4d9d}</UniqueIdentifier>
</Filter>
<Filter Include="kernel\arkdrv-api\api-storage">
<UniqueIdentifier>{78d6877a-f6ca-4711-8aa7-6aefef846466}</UniqueIdentifier>
</Filter>
<Filter Include="kernel\arkdrv-api\api-memory">
<UniqueIdentifier>{ce50d15f-ff76-4aba-a3a7-6b7c249a2017}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="openark\openark.cpp">
Expand Down Expand Up @@ -273,6 +279,12 @@
<ClCompile Include="kernel\memory\memory.cpp">
<Filter>kernel\memory</Filter>
</ClCompile>
<ClCompile Include="..\OpenArkDrv\arkdrv-api\api-storage\api-storage.cpp">
<Filter>kernel\arkdrv-api\api-storage</Filter>
</ClCompile>
<ClCompile Include="..\OpenArkDrv\arkdrv-api\api-memory\api-memory.cpp">
<Filter>kernel\arkdrv-api\api-memory</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<QtMoc Include="openark\openark.h">
Expand Down Expand Up @@ -498,6 +510,12 @@
<ClInclude Include="common\win-wrapper\reg-wrapper.h">
<Filter>common\win-wrapper</Filter>
</ClInclude>
<ClInclude Include="..\OpenArkDrv\arkdrv-api\api-storage\api-storage.h">
<Filter>kernel\arkdrv-api\api-storage</Filter>
</ClInclude>
<ClInclude Include="..\OpenArkDrv\arkdrv-api\api-memory\api-memory.h">
<Filter>kernel\arkdrv-api\api-memory</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="res\OpenArk.ico">
Expand Down
2 changes: 1 addition & 1 deletion src/OpenArk/kernel/memory/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void KernelMemoryRW::ViewMemory(ULONG64 addr, ULONG size)
char *mem = nullptr;
ULONG memsize = 0;
std::string buf;
if (ArkDrvApi::MemoryRead(addr, size, buf)) {
if (ArkDrvApi::Memory::MemoryRead(addr, size, buf)) {
mem = (char*)buf.c_str();
memsize = buf.size();
}
Expand Down
39 changes: 39 additions & 0 deletions src/OpenArkDrv/arkdrv-api/api-memory/api-memory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/****************************************************************************
**
** Copyright (C) 2019 BlackINT3
** Contact: https://github.com/BlackINT3/OpenArk
**
** GNU Lesser General Public License Usage (LGPL)
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
****************************************************************************/
#include "api-memory.h"
#ifdef _ARKDRV_
#else
namespace ArkDrvApi {
namespace Memory {

bool MemoryRead(ULONG64 addr, ULONG size, std::string &readbuf)
{
if (!size) return false;
MEMORY_IN memin;
memin.addr = addr;
memin.size = size;
DWORD outlen;
PMEMORY_OUT memout;
bool ret = IoControlDriver(IOCTL_ARK_MEMORY, MEMORY_READ, &memin, sizeof(memin), (PVOID*)&memout, &outlen);
if (!ret) return false;
readbuf.resize(memout->size);
memcpy(&readbuf[0], memout->readbuf, memout->size);
free(memout);
return true;
}
} // namespace Memory
} // namespace ArkDrvApi
#endif
58 changes: 58 additions & 0 deletions src/OpenArkDrv/arkdrv-api/api-memory/api-memory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/****************************************************************************
**
** Copyright (C) 2019 BlackINT3
** Contact: https://github.com/BlackINT3/OpenArk
**
** GNU Lesser General Public License Usage (LGPL)
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
****************************************************************************/
#pragma once
#include "../arkdrv-api.h"
#ifdef _ARKDRV_
#include <ntifs.h>
#include <windef.h>
#else
#include <Windows.h>
#endif //_NTDDK_

// Memory
enum MEMORY_OPS {
MEMORY_READ,
MEMORY_WRITE,
};
#pragma pack(push, 1)
typedef struct _MEMORY_IN {
ULONG64 addr;
ULONG size;
union {
UCHAR dummy[1];
UCHAR writebuf[1];
} u;
} MEMORY_IN, *PMEMORY_IN;
typedef struct _MEMORY_OUT {
ULONG size;
UCHAR readbuf[1];
} MEMORY_OUT, *PMEMORY_OUT;
#pragma pack(pop)

//#undef _ARKDRV_
#ifdef _ARKDRV_
#include <ntifs.h>
#else
#include <unone.h>
#include <string>
#include <vector>
namespace ArkDrvApi {
namespace Memory {
bool MemoryRead(ULONG64 addr, ULONG size, std::string &readbuf);
bool MemoryWrite(std::string &writebuf, ULONG64 addr);
} // namespace Memory
} // namespace ArkDrvApi
#endif //_NTDDK_
Empty file.
22 changes: 22 additions & 0 deletions src/OpenArkDrv/arkdrv-api/api-storage/api-storage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/****************************************************************************
**
** Copyright (C) 2019 BlackINT3
** Contact: https://github.com/BlackINT3/OpenArk
**
** GNU Lesser General Public License Usage (LGPL)
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
****************************************************************************/
#pragma once
#ifdef _ARKDRV_
#include <ntifs.h>
#include <windef.h>
#else
#include <Windows.h>
#endif //_NTDDK_
15 changes: 0 additions & 15 deletions src/OpenArkDrv/arkdrv-api/arkdrv-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,6 @@ bool NotifyEnumRegistry(std::vector<ULONG64> &routines)
{
return NotifyEnum(NOTIFY_ENUM_REGISTRY, routines);
}
bool MemoryRead(ULONG64 addr, ULONG size, std::string &readbuf)
{
if (!size) return false;
MEMORY_IN memin;
memin.addr = addr;
memin.size = size;
DWORD outlen;
PMEMORY_OUT memout;
bool ret = IoControlDriver(IOCTL_ARK_MEMORY, MEMORY_READ, &memin, sizeof(memin), (PVOID*)&memout, &outlen);
if (!ret) return false;
readbuf.resize(memout->size);
memcpy(&readbuf[0], memout->readbuf, memout->size);
free(memout);
return true;
}
bool HotkeyEnumInfo(std::vector<HOTKEY_ITEM> &hotkeys)
{
if (!ConnectDriver()) return false;
Expand Down
25 changes: 5 additions & 20 deletions src/OpenArkDrv/arkdrv-api/arkdrv-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include <Windows.h>
#endif //_NTDDK_

#include "api-storage/api-storage.h"
#include "api-memory/api-memory.h"

#define ARK_NTDEVICE_NAME L"\\Device\\OpenArkDrv"
#define ARK_DOSDEVICE_NAME L"\\DosDevices\\OpenArkDrv"
#define ARK_USER_SYMBOLINK L"\\\\.\\OpenArkDrv"
Expand Down Expand Up @@ -81,26 +84,6 @@ typedef struct _NOTIFY_REMOVE_INFO {
} NOTIFY_REMOVE_INFO, *PNOTIFY_REMOVE_INFO;
#pragma pack(pop)

// Memory
enum MEMORY_OPS {
MEMORY_READ,
MEMORY_WRITE,
};
#pragma pack(push, 1)
typedef struct _MEMORY_IN {
ULONG64 addr;
ULONG size;
union {
UCHAR dummy[1];
UCHAR writebuf[1];
} u;
} MEMORY_IN, *PMEMORY_IN;
typedef struct _MEMORY_OUT {
ULONG size;
UCHAR readbuf[1];
} MEMORY_OUT, *PMEMORY_OUT;
#pragma pack(pop)

// WinGUI
#define HOTKEY_MAX_VK 0x80
#define HOTKEY_PLACEHOLDER_ID 0x99887766
Expand Down Expand Up @@ -134,9 +117,11 @@ typedef struct _HOTKEY_INFO {
#include <string>
#include <vector>
namespace ArkDrvApi {
extern HANDLE arkdrv;
bool ConnectDriver();
bool DisconnectDriver();
bool HeartBeatPulse();
bool IoControlDriver(DWORD ctlcode, DWORD op, PVOID inbuf, DWORD inlen, PVOID *outbuf, DWORD *outlen);
bool DriverEnumInfo(std::vector<DRIVER_ITEM> &infos);
bool NotifyPatch(NOTIFY_TYPE type, ULONG64 routine);
bool NotifyPatchRegularly(NOTIFY_TYPE type, ULONG64 routine, int interval);
Expand Down

0 comments on commit 339d01f

Please sign in to comment.