-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrmMain.cpp
More file actions
166 lines (133 loc) · 4.31 KB
/
frmMain.cpp
File metadata and controls
166 lines (133 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "frmMain.h"
#include <windows.h>
#include <psapi.h>
#include <processthreadsapi.h>
#include <processthreadsapi.h>
#include <vector>
#include <string>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
Application->OnException = AppException;
}
//---------------------------------------------------------------------------
AnsiString svuname="";
void __fastcall TMainForm::AppException(TObject *Sender, Exception *E)
{
//Application->ShowException(E);
//Application->Terminate();
//return;
}
void __fastcall TMainForm::CreateParams(Controls::TCreateParams &Params)
{
TForm::CreateParams(Params);
Params.ExStyle = Params.ExStyle | WS_EX_APPWINDOW;
Params.WndParent = ParentWindow;
}
MODULEINFO GetModuleInfo()
{
MODULEINFO modinfo = { 0 };
HMODULE hModule = GetModuleHandle(NULL);
if (hModule == 0)
return modinfo;
GetModuleInformation(GetCurrentProcess(), hModule, &modinfo, sizeof(MODULEINFO));
return modinfo;
}
bool Match(const char* pData, const char* bMask, const char* szMask)
{
for (; *szMask; ++szMask, ++pData, ++bMask) {
if (*szMask == 'x' && *pData != *bMask) {
return false;
}
}
return (*szMask) == NULL;
}
DWORD FindPattern(const char* bMask, const char* szMask)
{
__try {
MODULEINFO mInfo = GetModuleInfo();
DWORD base = (DWORD)mInfo.lpBaseOfDll;
DWORD size = (DWORD)mInfo.SizeOfImage;
// You pattern scan code
for (DWORD i = 0; i < size; i++) {
if(MainForm->CheckBox1->Checked){
__try
{
if (Match((char*)(base + i), bMask, szMask)) {
return (DWORD)(base + i);
}
}
__except (EXCEPTION_EXECUTE_HANDLER) {}
}
else{
break;
}
}
}
__except (EXCEPTION_EXECUTE_HANDLER) {}
return NULL;
}
std::vector<unsigned char> convert_string_to_bytes(const std::string& input) {
std::vector<unsigned char> output;
std::string::const_iterator it = input.begin();
while (it != input.end()) {
if (*it == '\\' && it + 1 != input.end() && *(it + 1) == 'x') {
// Parse the hexadecimal digits following the "\x" prefix.
if (it + 2 != input.end() && isxdigit(*(it + 2)) && it + 3 != input.end() && isxdigit(*(it + 3))) {
output.push_back(static_cast<unsigned char>(std::stoi(std::string(it + 2, it + 4), nullptr, 16)));
it += 4;
} else {
// Invalid "\x" prefix, treat it as a normal character.
output.push_back('\\');
++it;
}
} else {
output.push_back(static_cast<unsigned char>(*it));
++it;
}
}
return output;
}
std::vector<char> convert_string_to_chars(const std::vector<unsigned char>& input) {
std::vector<char> output(input.size());
for (std::size_t i = 0; i < input.size(); ++i) {
output[i] = static_cast<char>(input[i]);
}
return output;
}
DWORD WINAPI scanningpattern(){
MainForm->Edit3->Text="Bekle";
AnsiString k= MainForm->Edit1->Text;
AnsiString ke= MainForm->Edit2->Text;
std::vector<unsigned char> bytes = convert_string_to_bytes(k.c_str());
std::vector<char> charData = convert_string_to_chars(bytes);
const char* a1 =charData.data();
const char* masked=ke.c_str();
DWORD result = FindPattern(a1, masked);
MainForm->Edit3->Text=IntToHex(StrToInt(result));
return 0;
}
void __fastcall TMainForm::StartThread()
{
CreateThread(0, NULL, reinterpret_cast<LPTHREAD_START_ROUTINE>(scanningpattern), this, 0, NULL);
}
void __fastcall TMainForm::Button1Click(TObject *Sender)
{
StartThread();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Button2Click(TObject *Sender)
{
MainForm->Edit1->Clear();
MainForm->Edit2->Clear();
MainForm->Edit3->Clear();
}
//---------------------------------------------------------------------------