Skip to content

Commit

Permalink
fix bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
9176324 committed Feb 23, 2021
1 parent 4ee1723 commit 7fa6945
Show file tree
Hide file tree
Showing 13 changed files with 285 additions and 244 deletions.
7 changes: 4 additions & 3 deletions Include/Defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@

#define _WIN32_WINNT 0x0500

#include <statusdefs.h>
#include <typesdefs.h>
#include <statusdefs.h>
#include <listdefs.h>

#ifdef __cplusplus
/* Assume byte packing throughout */
Expand Down Expand Up @@ -122,7 +123,7 @@ extern "C" {
(((status)exp) >= 0) ? \
TRUE : \
(vDbgPrint( \
_T("[Shark] %hs[%d] %hs failed < %08x >\n"), \
_T("[FRK] %hs[%d] %hs failed < %08x >\n"), \
__FILE__, \
__LINE__, \
__FUNCDNAME__, \
Expand All @@ -132,7 +133,7 @@ extern "C" {
(((status)exp) >= 0) ? \
TRUE : \
(vDbgPrint( \
"[Shark] %hs[%d] %hs failed < %08x >\n", \
"[FRK] %hs[%d] %hs failed < %08x >\n", \
__FILE__, \
__LINE__, \
__FUNCDNAME__, \
Expand Down
33 changes: 33 additions & 0 deletions Include/DeviceDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,39 @@ extern "C" {
#define DEVICE_STRING L"\\Device\\{94A4D943-9D91-4DFA-AA05-5486E61BF500}"
#define SYMBOLIC_STRING L"\\DosDevices\\{00081140-C743-454D-917B-C3F437C770DC}"

FORCEINLINE
u
NTAPI
GuardCall(
__in_opt PGKERNEL_ROUTINE KernelRoutine,
__in_opt PGSYSTEM_ROUTINE SystemRoutine,
__in_opt PGRUNDOWN_ROUTINE RundownRoutine,
__in_opt PGNORMAL_ROUTINE NormalRoutine
)
{
u Result = 0;

__try {
if (NULL != KernelRoutine) {
Result = KernelRoutine(SystemRoutine, RundownRoutine, NormalRoutine);
}
else if (NULL != SystemRoutine) {
Result = SystemRoutine(RundownRoutine, NormalRoutine);
}
else if (NULL != RundownRoutine) {
Result = RundownRoutine(NormalRoutine);
}
else if (NULL != NormalRoutine) {
Result = NormalRoutine();
}
}
__except (EXCEPTION_EXECUTE_HANDLER) {
NOTHING;
}

return Result;
}

#ifdef __cplusplus
}
#endif /* __cplusplus */
Expand Down
137 changes: 137 additions & 0 deletions Include/listdefs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
*
* Copyright (c) 2015 - 2021 by blindtiger. All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License Version
* 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. SEe the License
* for the specific language governing rights and limitations under the
* License.
*
* The Initial Developer of the Original e is blindtiger.
*
*/

#ifndef _LISTDEFS_H_
#define _LISTDEFS_H_

#include <typesdefs.h>

#ifdef __cplusplus
/* Assume byte packing throughout */
extern "C" {
#endif /* __cplusplus */

typedef struct _list {
struct _list * front;
struct _list * back;
} list;

#define __is_list_empty(head) \
((head)->front == (head))

__inline
void
__empty_list(
list * head
)
{
head->front = head->back = head;
}

__inline
u8
__remove_node(
list * node
)
{
list * back;
list * front;

front = node->front;
back = node->back;
back->front = front;
front->back = back;

return (u8)(front == back);
}

__inline
void
__insert_head(
list * head,
list * node
)
{
list * front;

front = head->front;

node->front = front;
node->back = head;

head->front = node;
front->back = node;
}

__inline
list *
__remove_head(
list * head
)
{
list * front;
list * node;

node = head->front;
front = node->front;
head->front = front;
front->back = head;

return node;
}

__inline
void
__insert_tail(
list * head,
list * node
)
{
list * back;

back = head->back;

node->front = head;
node->back = back;

back->front = node;
head->back = node;
}

__inline
list *
__remove_tail(
list * head
)
{
list * back;
list * node;

node = head->back;
back = node->back;
head->back = back;
back->front = head;

return node;
}

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif // !_LISTDEFS_H_
19 changes: 2 additions & 17 deletions Projects/Shark/AMD64/PatchGuardAMD64.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ InitializePgBlock(
s8 ReservedCrossThreadFlags[] =
"89 83 ?? ?? F0 83 0C 24 00 80 3D ?? ?? ?? ?? ?? 0F";

u64 Btc64[] = { 0xC3C18B48D1BB0F48 };
u64 Btc64[] = { 0xC3C3C0BB0F489148 };
u64 Rol64[] = { 0xC3C0D348CA869148 };
u64 Ror64[] = { 0xC3C8D348CA869148 };

Expand Down Expand Up @@ -1314,21 +1314,6 @@ PgCompareFields(

if (FALSE != Chance) {
if (PgPoolBigPage == VaType) {
PointerPde = GetPdeAddress(BaseAddress);

if (0 == PointerPde->u.Hard.LargePage) {
PointerPte = GetPteAddress(BaseAddress);

if (1 == PointerPte->u.Hard.NoExecute) {
Chance = FALSE;
}
}
else if (1 == PointerPde->u.Hard.NoExecute) {
Chance = FALSE;
}
else {
__debugbreak();
}
}
else {
if (ROUND_TO_PAGES(*(u64ptr)BaseAddress) != RegionSize) {
Expand Down Expand Up @@ -2079,7 +2064,7 @@ PgClearAll(
GetGpBlock(PgBlock)->BugCheckHandle = SafeGuardAttach(
(ptr *)&GetGpBlock(PgBlock)->KeBugCheckEx,
PgBlock->ClearCallback,
NULL,
PgBlock->CaptureContext,
NULL,
PgBlock);
}
Expand Down
8 changes: 3 additions & 5 deletions Projects/Shark/Guard.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ GuardAllocateTrampoline(
{
ptr Result = NULL;

Result = ExAllocatePool(
NonPagedPool,
NumberOfBytes);
Result = __malloc(NumberOfBytes);

if (NULL != Result) {
RtlZeroMemory(Result, NumberOfBytes);
Expand All @@ -49,7 +47,7 @@ GuardFreeTrampoline(
__in u8 NumberOfBytes
)
{
ExFreePool(BaseAddress);
__free(BaseAddress);
}

void
Expand Down Expand Up @@ -353,7 +351,7 @@ HotpatchDetach(
sizeof(ptr));

GuardFreeTrampoline(HotpatchObjct, HotpatchObjct->Header.Length);
}
}
#endif // !_WIN64

PPATCH_HEADER
Expand Down
Loading

0 comments on commit 7fa6945

Please sign in to comment.