Skip to content

Commit

Permalink
move testSectionAddress into shared
Browse files Browse the repository at this point in the history
  • Loading branch information
tomysshadow committed Oct 14, 2022
1 parent dfe5069 commit e8bf94c
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 64 deletions.
59 changes: 0 additions & 59 deletions source/Extender.cpp
Original file line number Diff line number Diff line change
@@ -1,65 +1,6 @@
#include "shared.h"
#include "Extender.h"
#include <windows.h>
#include <Dbghelp.h>

bool testSectionAddress(HMODULE moduleHandle, VIRTUAL_ADDRESS virtualAddress, VIRTUAL_SIZE virtualSize) {
if (!moduleHandle) {
//showLastError("moduleHandle must not be NULL");
return false;
}

PIMAGE_DOS_HEADER imageDOSHeaderPointer = (PIMAGE_DOS_HEADER)moduleHandle;

if (!imageDOSHeaderPointer) {
//showLastError("imageDOSHeaderPointer must not be NULL");
return false;
}

if (imageDOSHeaderPointer->e_magic != IMAGE_DOS_SIGNATURE) {
//showLastError("e_magic must be IMAGE_DOS_SIGNATURE");
goto error;
}

PIMAGE_NT_HEADERS imageNTHeadersPointer = ImageNtHeader(imageDOSHeaderPointer);

if (!imageNTHeadersPointer) {
//showLastError("imageNTHeadersPointer must not be NULL");
goto error;
}

if (imageNTHeadersPointer->Signature != IMAGE_NT_SIGNATURE) {
//showLastError("Signature must be IMAGE_NT_SIGNATURE");
goto error2;
}

PIMAGE_SECTION_HEADER imageSectionHeaderPointer = (PIMAGE_SECTION_HEADER)(imageNTHeadersPointer + 1);

if (!imageSectionHeaderPointer) {
//showLastError("imageSectionHeaderPointer must not be NULL");
return false;
}

VIRTUAL_ADDRESS moduleVirtualAddress = (VIRTUAL_ADDRESS)moduleHandle;

for (WORD i = 0; i < imageNTHeadersPointer->FileHeader.NumberOfSections; i++) {
if (virtualAddress >= moduleVirtualAddress + imageSectionHeaderPointer->VirtualAddress && virtualAddress + virtualSize <= moduleVirtualAddress + imageSectionHeaderPointer->VirtualAddress + imageSectionHeaderPointer->Misc.VirtualSize) {
imageSectionHeaderPointer = NULL;
imageNTHeadersPointer = NULL;
imageDOSHeaderPointer = NULL;
return true;
}

imageSectionHeaderPointer++;
}

imageSectionHeaderPointer = NULL;
error2:
imageNTHeadersPointer = NULL;
error:
imageDOSHeaderPointer = NULL;
return false;
}

bool unprotectCode(HMODULE moduleHandle, VIRTUAL_ADDRESS codeVirtualAddress, VIRTUAL_SIZE codeVirtualSize, DWORD &oldProtect) {
if (!moduleHandle) {
Expand Down
59 changes: 59 additions & 0 deletions source/shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <string>
#include <sstream>
#include <windows.h>
#include <Dbghelp.h>

static LPCSTR MESSAGE_BOX_CAPTION = "LeechProtectionRemovalHelp Error";

Expand All @@ -21,4 +22,62 @@ bool showLastError(LPCSTR errorMessage) {

BOOL terminateCurrentProcess() {
return TerminateProcess(GetCurrentProcess(), GetLastError());
}

bool testSectionAddress(HMODULE moduleHandle, VIRTUAL_ADDRESS virtualAddress, VIRTUAL_SIZE virtualSize) {
if (!moduleHandle) {
//showLastError("moduleHandle must not be NULL");
return false;
}

PIMAGE_DOS_HEADER imageDOSHeaderPointer = (PIMAGE_DOS_HEADER)moduleHandle;

if (!imageDOSHeaderPointer) {
//showLastError("imageDOSHeaderPointer must not be NULL");
return false;
}

if (imageDOSHeaderPointer->e_magic != IMAGE_DOS_SIGNATURE) {
//showLastError("e_magic must be IMAGE_DOS_SIGNATURE");
goto error;
}

PIMAGE_NT_HEADERS imageNTHeadersPointer = ImageNtHeader(imageDOSHeaderPointer);

if (!imageNTHeadersPointer) {
//showLastError("imageNTHeadersPointer must not be NULL");
goto error;
}

if (imageNTHeadersPointer->Signature != IMAGE_NT_SIGNATURE) {
//showLastError("Signature must be IMAGE_NT_SIGNATURE");
goto error2;
}

PIMAGE_SECTION_HEADER imageSectionHeaderPointer = (PIMAGE_SECTION_HEADER)(imageNTHeadersPointer + 1);

if (!imageSectionHeaderPointer) {
//showLastError("imageSectionHeaderPointer must not be NULL");
return false;
}

VIRTUAL_ADDRESS moduleVirtualAddress = (VIRTUAL_ADDRESS)moduleHandle;

for (WORD i = 0; i < imageNTHeadersPointer->FileHeader.NumberOfSections; i++) {
if (virtualAddress >= moduleVirtualAddress + imageSectionHeaderPointer->VirtualAddress && virtualAddress + virtualSize <= moduleVirtualAddress + imageSectionHeaderPointer->VirtualAddress + imageSectionHeaderPointer->Misc.VirtualSize) {
imageSectionHeaderPointer = NULL;
imageNTHeadersPointer = NULL;
imageDOSHeaderPointer = NULL;
return true;
}

imageSectionHeaderPointer++;
}

imageSectionHeaderPointer = NULL;
error2:
imageNTHeadersPointer = NULL;
error:
imageDOSHeaderPointer = NULL;
return false;
}
3 changes: 2 additions & 1 deletion source/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ inline bool memoryShift(size_t bufferSize, void* buffer, size_t sourceSize, void
}

bool showLastError(LPCSTR errorMessage);
BOOL terminateCurrentProcess();
BOOL terminateCurrentProcess();
bool testSectionAddress(HMODULE moduleHandle, VIRTUAL_ADDRESS virtualAddress, VIRTUAL_SIZE virtualSize = 1);
Binary file modified winproj/Debug/LeechProtectionRemovalHelp.ilk
Binary file not shown.
Binary file modified winproj/Debug/LeechProtectionRemovalHelp.pdb
Binary file not shown.
Binary file modified winproj/Debug/LeechProtectionRemovalHelp.x32
Binary file not shown.
4 changes: 2 additions & 2 deletions winproj/Debug/Script.log
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Platforms\Win32\PlatformToolsets\v141_xp\Toolset.targets(39,5): warning MSB8051: Support for targeting Windows XP is deprecated and will not be present in future releases of Visual Studio. Please see https://go.microsoft.com/fwlink/?linkid=2023588 for more information.
Extender.cpp
c:\users\anthony\documents\visual studio 2017\projects\xdk_win\xdk\examples\script\leechprotectionremovalhelp xtra\source\shared.h(39): warning C4133: '-': incompatible types - from 'void *' to 'char *'
c:\program files (x86)\microsoft sdks\windows\v7.1a\include\dbghelp.h(1540): warning C4091: 'typedef ': ignored on left of '<unnamed-enum-hdBase>' when no variable is declared
c:\program files (x86)\microsoft sdks\windows\v7.1a\include\dbghelp.h(3056): warning C4091: 'typedef ': ignored on left of '<unnamed-enum-sfImage>' when no variable is declared
shared.cpp
c:\users\anthony\documents\visual studio 2017\projects\xdk_win\xdk\examples\script\leechprotectionremovalhelp xtra\source\shared.h(39): warning C4133: '-': incompatible types - from 'void *' to 'char *'
c:\program files (x86)\microsoft sdks\windows\v7.1a\include\dbghelp.h(1540): warning C4091: 'typedef ': ignored on left of '<unnamed-enum-hdBase>' when no variable is declared
c:\program files (x86)\microsoft sdks\windows\v7.1a\include\dbghelp.h(3056): warning C4091: 'typedef ': ignored on left of '<unnamed-enum-sfImage>' when no variable is declared
Generating Code...
Script.cpp
c:\program files (x86)\microsoft sdks\windows\v7.1a\include\sal_supp.h(57): warning C4005: '__useHeader': macro redefinition
Expand Down
Binary file modified winproj/Debug/Script.obj
Binary file not shown.
Binary file modified winproj/Debug/Script.tlog/CL.read.1.tlog
Binary file not shown.
Binary file modified winproj/Debug/vc141.idb
Binary file not shown.
Binary file modified winproj/Debug/vc141.pdb
Binary file not shown.
Binary file modified winproj/Release/LeechProtectionRemovalHelp.pdb
Binary file not shown.
Binary file modified winproj/Release/LeechProtectionRemovalHelp.x32
Binary file not shown.
4 changes: 2 additions & 2 deletions winproj/Release/Script.log
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Platforms\Win32\PlatformToolsets\v141_xp\Toolset.targets(39,5): warning MSB8051: Support for targeting Windows XP is deprecated and will not be present in future releases of Visual Studio. Please see https://go.microsoft.com/fwlink/?linkid=2023588 for more information.
Extender.cpp
c:\users\anthony\documents\visual studio 2017\projects\xdk_win\xdk\examples\script\leechprotectionremovalhelp xtra\source\shared.h(39): warning C4133: '-': incompatible types - from 'void *' to 'char *'
c:\program files (x86)\microsoft sdks\windows\v7.1a\include\dbghelp.h(1540): warning C4091: 'typedef ': ignored on left of '<unnamed-enum-hdBase>' when no variable is declared
c:\program files (x86)\microsoft sdks\windows\v7.1a\include\dbghelp.h(3056): warning C4091: 'typedef ': ignored on left of '<unnamed-enum-sfImage>' when no variable is declared
shared.cpp
c:\users\anthony\documents\visual studio 2017\projects\xdk_win\xdk\examples\script\leechprotectionremovalhelp xtra\source\shared.h(39): warning C4133: '-': incompatible types - from 'void *' to 'char *'
c:\program files (x86)\microsoft sdks\windows\v7.1a\include\dbghelp.h(1540): warning C4091: 'typedef ': ignored on left of '<unnamed-enum-hdBase>' when no variable is declared
c:\program files (x86)\microsoft sdks\windows\v7.1a\include\dbghelp.h(3056): warning C4091: 'typedef ': ignored on left of '<unnamed-enum-sfImage>' when no variable is declared
Generating Code...
Script.cpp
c:\program files (x86)\microsoft sdks\windows\v7.1a\include\sal_supp.h(57): warning C4005: '__useHeader': macro redefinition
Expand Down
Binary file modified winproj/Release/Script.obj
Binary file not shown.
Binary file modified winproj/Release/Script.tlog/CL.read.1.tlog
Binary file not shown.
Binary file modified winproj/Release/vc141.pdb
Binary file not shown.

0 comments on commit e8bf94c

Please sign in to comment.