Skip to content

Commit

Permalink
添加项目文件。
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Aug 8, 2021
0 parents commit f2c4306
Show file tree
Hide file tree
Showing 33 changed files with 9,081 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

*.suo
*.user
*.aps
.vs
Debug
Release
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "cl.exe - 生成和调试活动文件",
"type": "cppvsdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "externalTerminal",
"preLaunchTask": "C/C++: cl.exe 生成活动文件"
}
]
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"vector": "cpp"
}
}
25 changes: 25 additions & 0 deletions BetterPVZ.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26403.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BetterPVZ", "PVZ_Helper\PVZ_Helper.vcxproj", "{F37572F2-BA26-4EB3-89D9-912DF3767EEA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F37572F2-BA26-4EB3-89D9-912DF3767EEA}.Debug|Win32.ActiveCfg = Debug|Win32
{F37572F2-BA26-4EB3-89D9-912DF3767EEA}.Debug|Win32.Build.0 = Debug|Win32
{F37572F2-BA26-4EB3-89D9-912DF3767EEA}.Release|Win32.ActiveCfg = Release|Win32
{F37572F2-BA26-4EB3-89D9-912DF3767EEA}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E94A84D6-0F8C-4D3B-A163-52F3CEFEE6B3}
EndGlobalSection
EndGlobal
88 changes: 88 additions & 0 deletions PVZ_Helper/Asm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include "stdafx.h"
#include "Asm.h"

static const BYTE offset[] = { 0, 3, 1, 2, 6, 7, 5 };

void Asm::runThread(HANDLE hpro, DWORD ThreadAddr)
{
bool NeedFree;
if (ThreadAddr == 0)
{
ThreadAddr = (DWORD)VirtualAllocEx(hpro, NULL, index, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
NeedFree = true;
}
else
{
NeedFree = false;
}
if (ThreadAddr)
{
WriteProcessMemory(hpro, (LPVOID)ThreadAddr, code, index, 0);
HANDLE hth = CreateRemoteThread(hpro, NULL, 0, LPTHREAD_START_ROUTINE(ThreadAddr), NULL, 0, NULL);
WaitForSingleObject(hth, INFINITE);
CloseHandle(hth);
if (NeedFree)
VirtualFreeEx(hpro, (LPVOID)ThreadAddr, 0, MEM_RELEASE);
}
}

void Asm::push_dword(DWORD val)
{
add_byte(0x68);
add_dword(val);
}
void Asm::push_byte(BYTE val)
{
add_byte(0x6a);
add_byte(val);
}
void Asm::mov_exx(RegType exx, DWORD val)
{
add_byte(0xb8 + offset[int(exx)]);
add_dword(val);
}
void Asm::mov_exx_dword_ptr(RegType exx, DWORD val)
{
add_byte(0x8b);
add_byte(5 + offset[int(exx)] * 8);
add_dword(val);
}

void Asm::mov_exx_dword_ptr_eyy_add_byte(RegType exx, RegType eyy, BYTE val)
{
add_byte(0x8b);
add_byte(0x40 + offset[int(exx)] * 8 + offset[int(eyy)]);
add_dword(val);
}

void Asm::mov_exx_dword_ptr_eyy_add_dword(RegType exx, RegType eyy, DWORD val)
{
add_byte(0x8b);
add_byte(0x80 + offset[int(exx)] * 8 + offset[int(eyy)]);
add_dword(val);
}
void Asm::push_exx(RegType exx)
{
add_byte(0x50 + offset[int(exx)]);
}
void Asm::pop_exx(RegType exx)
{
add_byte(0x58 + offset[int(exx)]);
}
void Asm::ret()
{
add_byte(0xc3);
}
void Asm::call(DWORD addr)
{
add_byte(0xe8);
add_dword(2);
add_word(0x06eb);
push_dword(addr);
ret();
}
void Asm::mov_exx_eyy(RegType exx, RegType eyy)
{
push_exx(eyy);
pop_exx(exx);
}
61 changes: 61 additions & 0 deletions PVZ_Helper/Asm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#pragma once
#include "windows.h"
#include "assert.h"

enum class RegType
{
EAX,
EBX,
ECX,
EDX,
ESI,
EDI,
EBP,
};

class Asm
{
public:
Asm(int page = 1)
{
maxLength = 4096 * page;
code = new BYTE[maxLength];
index = 0;
}
~Asm(){ delete[] code; }
void clear(){ index = 0; }
int getLength(){ return index; }
void runThread(HANDLE hpro, DWORD ThreadAddr);
void add_byte(BYTE val)
{
assert(index + 1 < maxLength);
code[index++] = val;
}
void add_word(WORD val)
{
assert(index + 2 < maxLength);
(WORD&)code[index] = val, index += 2;
}
void add_dword(DWORD val)
{
assert(index + 4 < maxLength);
(DWORD&)code[index] = val, index += 4;
}
void push_dword(DWORD val);
void push_byte(BYTE val);
void mov_exx(RegType exx, DWORD val);
void mov_exx_dword_ptr(RegType exx, DWORD val);
void mov_exx_dword_ptr_exx_add_byte(RegType exx, BYTE val){ mov_exx_dword_ptr_eyy_add_byte(exx, exx, val); }
void mov_exx_dword_ptr_eyy_add_byte(RegType exx, RegType eyy, BYTE val);
void mov_exx_dword_ptr_exx_add_dword(RegType exx, DWORD val){mov_exx_dword_ptr_eyy_add_dword(exx, exx, val);}
void mov_exx_dword_ptr_eyy_add_dword(RegType exx, RegType eyy, DWORD val);
void push_exx(RegType exx);
void pop_exx(RegType exx);
void call(DWORD addr);
void ret();
void mov_exx_eyy(RegType exx, RegType eyy);
private:
BYTE* code;
int index;
DWORD maxLength;
};
Loading

0 comments on commit f2c4306

Please sign in to comment.