Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -path option for injector (#2) #6

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Dll_Injector/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPAR
return 0;
}

string BrowseFolder()
string BrowseFolder(const char* initialPath)
{
TCHAR path[MAX_PATH];

BROWSEINFO bi = { 0 };
bi.lpszTitle = ("Browse for save folder...");
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
bi.lParam = (LPARAM)initialPath;
bi.lpfn = BrowseCallbackProc;

LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
Expand Down Expand Up @@ -59,14 +60,14 @@ string CurrentPath() {
}

void set_global_path(string path) {
string strMapName("ShareMemory"); // �ڴ�ӳ���������
LPVOID pBuffer; // �����ڴ�ָ��
string strMapName("ShareMemory"); // Memory mapped object name
LPVOID pBuffer; // Shared memory pointer

HANDLE hMap = ::OpenFileMapping(FILE_MAP_ALL_ACCESS, 0, strMapName.c_str());
// ��ʧ�ܣ�����֮
// Failed to open, create it
hMap = ::CreateFileMapping(INVALID_HANDLE_VALUE,NULL,PAGE_READWRITE,0, path.length() + 1,strMapName.c_str());
// ӳ������һ����ͼ���õ�ָ�����ڴ��ָ�룬�������������
// Map a view of the object, get the pointer to the shared memory, and set the data inside
pBuffer = ::MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
strcpy((char*)pBuffer, path.c_str());
//cout << "д�빲���ڴ����ݣ�" << (char *)pBuffer << endl;
//cout << "Write shared memory data: " << (char *)pBuffer << endl;
}
12 changes: 11 additions & 1 deletion Dll_Injector/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@
#define PROCESS_NAME "melonbooksviewer.exe"
#define DLL_NAME "MelonDumper.dll"

// usage: Dll_Injector.exe [-path <initial path to save image file>]
int main(int argc, const char *argv[])
{
std::string path = BrowseFolder();
const char* initialPath = "";
for (int index = 1; index < argc; ++index)
{
if (strcmp(argv[index], "-path") == 0 && index + 1 < argc)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single dash usually use in the short form of argument option, I think it is better to use two dash like --path.

{
++index;
initialPath = argv[index];
}
}
std::string path = BrowseFolder(initialPath);
if (path == "")return EXIT_SUCCESS;
set_global_path(path);

Expand Down