develop
Petr Mrázek 2010-09-24 19:07:38 +02:00
commit ec032240aa
10 changed files with 108 additions and 9 deletions

@ -920,3 +920,15 @@ bool SHMProcess::Private::Aux_Core_Attach(bool & versionOK, pid_t & PID)
#endif #endif
return true; return true;
} }
string SHMProcess::getPath()
{
char cwd_name[256];
char target_name[1024];
int target_result;
sprintf(cwd_name,"/proc/%d/cwd", getPID());
// resolve /proc/PID/exe link
target_result = readlink(cwd_name, target_name, sizeof(target_name));
target_name[target_result] = '\0';
return(string(target_name));
}

@ -624,3 +624,15 @@ string WineProcess::readClassName (uint32_t vptr)
raw.resize(raw.length() - 2);// trim @@ from end raw.resize(raw.length() - 2);// trim @@ from end
return raw; return raw;
} }
string WineProcess::getPath()
{
char cwd_name[256];
char target_name[1024];
int target_result;
sprintf(cwd_name,"/proc/%d/cwd", getPID());
// resolve /proc/PID/exe link
target_result = readlink(cwd_name, target_name, sizeof(target_name));
target_name[target_result] = '\0';
return(string(target_name));
}

@ -586,3 +586,15 @@ string NormalProcess::readClassName (uint32_t vptr)
size_t end = raw.length(); size_t end = raw.length();
return raw.substr(start,end-start); return raw.substr(start,end-start);
} }
string NormalProcess::getPath()
{
char cwd_name[256];
char target_name[1024];
int target_result;
sprintf(cwd_name,"/proc/%d/cwd", getPID());
// resolve /proc/PID/exe link
target_result = readlink(cwd_name, target_name, sizeof(target_name));
target_name[target_result] = '\0';
return(string(target_name));
}

@ -929,6 +929,17 @@ string SHMProcess::readClassName (uint32_t vptr)
return raw; return raw;
} }
string SHMProcess::getPath()
{
HMODULE hmod;
DWORD junk;
char String[255];
HANDLE hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, d->process_ID ); //get the handle from the process ID
EnumProcessModules(hProcess, &hmod, 1 * sizeof(HMODULE), &junk); //get the module from the handle
GetModuleFileNameEx(hProcess,hmod,String,sizeof(String)); //get the filename from the module
string out(String);
return(out.substr(0,out.find_last_of("\\")));
}
// get module index by name and version. bool 0 = error // get module index by name and version. bool 0 = error
bool SHMProcess::getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) bool SHMProcess::getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT)
{ {

@ -488,3 +488,13 @@ string NormalProcess::readClassName (uint32_t vptr)
raw.resize(raw.length() - 2);// trim @@ from end raw.resize(raw.length() - 2);// trim @@ from end
return raw; return raw;
} }
string NormalProcess::getPath()
{
HMODULE hmod;
DWORD junk;
char String[255];
EnumProcessModules(d->my_handle, &hmod, 1 * sizeof(HMODULE), &junk); //get the module from the handle
GetModuleFileNameEx(d->my_handle,hmod,String,sizeof(String)); //get the filename from the module
string out(String);
return(out.substr(0,out.find_last_of("\\")));
}

@ -163,6 +163,8 @@ namespace DFHack
virtual VersionInfo *getDescriptor() = 0; virtual VersionInfo *getDescriptor() = 0;
/// get the DF Process ID /// get the DF Process ID
virtual int getPID() = 0; virtual int getPID() = 0;
/// get the DF Process FilePath
virtual std::string getPath() = 0;
/// get module index by name and version. bool 1 = error /// get module index by name and version. bool 1 = error
virtual bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) = 0; virtual bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) = 0;
/// get the SHM start if available /// get the SHM start if available
@ -230,6 +232,7 @@ namespace DFHack
void getMemRanges(std::vector<t_memrange> & ranges ); void getMemRanges(std::vector<t_memrange> & ranges );
VersionInfo *getDescriptor(); VersionInfo *getDescriptor();
int getPID(); int getPID();
std::string getPath();
// get module index by name and version. bool 1 = error // get module index by name and version. bool 1 = error
bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) { OUTPUT=0; return false;}; bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) { OUTPUT=0; return false;};
// get the SHM start if available // get the SHM start if available
@ -295,6 +298,7 @@ namespace DFHack
void getMemRanges(std::vector<t_memrange> & ranges ); void getMemRanges(std::vector<t_memrange> & ranges );
VersionInfo *getDescriptor(); VersionInfo *getDescriptor();
int getPID(); int getPID();
std::string getPath();
// get module index by name and version. bool 1 = error // get module index by name and version. bool 1 = error
bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT); bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT);
// get the SHM start if available // get the SHM start if available
@ -364,6 +368,7 @@ namespace DFHack
// get the SHM start if available // get the SHM start if available
char * getSHMStart (void){return 0;}; char * getSHMStart (void){return 0;};
bool SetAndWait (uint32_t state){return false;}; bool SetAndWait (uint32_t state){return false;};
std::string getPath();
}; };
#endif #endif
} }

@ -25,9 +25,9 @@ distribution.
#ifndef KEYS_H_INCLUDED #ifndef KEYS_H_INCLUDED
#define KEYS_H_INCLUDED #define KEYS_H_INCLUDED
#include "dfhack/DFPragma.h" #include "../DFPragma.h"
#include "dfhack/DFExport.h" #include "../DFExport.h"
#include "dfhack/DFModule.h" #include "../DFModule.h"
namespace DFHack namespace DFHack
{ {

@ -130,20 +130,19 @@ WindowIO::~WindowIO ()
void WindowIO::TypeStr (const char *input, int delay, bool useShift) void WindowIO::TypeStr (const char *input, int delay, bool useShift)
{ {
//sendmessage needs a window handle HWND, so have to get that from the process HANDLE //sendmessage needs a window handle HWND, so have to get that from the process HANDLE
HWND currentWindow = GetForegroundWindow();
window myWindow; window myWindow;
myWindow.pid = d->p->getPID(); myWindow.pid = d->p->getPID();
EnumWindows (EnumWindowsProc, (LPARAM) &myWindow); EnumWindows (EnumWindowsProc, (LPARAM) &myWindow);
char cChar; char cChar;
DWORD dfProccess = GetWindowThreadProcessId(myWindow.windowHandle,NULL); DWORD dfProcess = GetWindowThreadProcessId(myWindow.windowHandle,NULL);
DWORD currentProccess = GetWindowThreadProcessId(currentWindow,NULL); DWORD currentProcess = GetCurrentThreadId();
AttachThreadInput(currentProccess,dfProccess,TRUE); //The two threads have to have attached input in order to change the keyboard state, which is needed to set the shift state AttachThreadInput(currentProcess,dfProcess,TRUE); //The two threads have to have attached input in order to change the keyboard state, which is needed to set the shift state
while ( (cChar = *input++)) // loops through chars while ( (cChar = *input++)) // loops through chars
{ {
short vk = VkKeyScan (cChar); // keycode of char short vk = VkKeyScan (cChar); // keycode of char
if (useShift || (vk >> 8) &1) // char is capital, so need to hold down shift if (useShift || (vk >> 8) &1) // char is capital, so need to hold down shift
{ {
vk = vk & 0xFF; // remove the shift state from the virtual key code
BYTE keybstate[256] = {0}; BYTE keybstate[256] = {0};
BYTE keybstateOrig[256] = {0}; BYTE keybstateOrig[256] = {0};
GetKeyboardState((LPBYTE)&keybstateOrig); GetKeyboardState((LPBYTE)&keybstateOrig);
@ -160,7 +159,7 @@ void WindowIO::TypeStr (const char *input, int delay, bool useShift)
SendMessage(myWindow.windowHandle,WM_KEYUP,vk,0); SendMessage(myWindow.windowHandle,WM_KEYUP,vk,0);
} }
} }
AttachThreadInput(currentProccess,dfProccess,FALSE); //detach the threads AttachThreadInput(currentProcess,dfProcess,FALSE); //detach the threads
Sleep (delay); Sleep (delay);
} }

@ -60,6 +60,13 @@ TARGET_LINK_LIBRARIES(dfcatsplosion dfhack)
ADD_EXECUTABLE(dfcopypaste copypaste.cpp) ADD_EXECUTABLE(dfcopypaste copypaste.cpp)
TARGET_LINK_LIBRARIES(dfcopypaste dfhack) TARGET_LINK_LIBRARIES(dfcopypaste dfhack)
# paths
# Author: belal
# dumps the current path to the DF exe, as well as the relative paths to the
# current tileset and color files
ADD_EXECUTABLE(dfpaths paths.cpp)
TARGET_LINK_LIBRARIES(dfpaths dfhack)
# this needs the C bindings # this needs the C bindings
IF(BUILD_DFHACK_C_BINDINGS) IF(BUILD_DFHACK_C_BINDINGS)
# for trying out some 'stuff' # for trying out some 'stuff'

@ -0,0 +1,31 @@
#include <iostream>
using namespace std;
#include <DFHack.h>
using namespace DFHack;
int main ()
{
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context *DF = DFMgr.getSingleContext();
try
{
DF->Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DFHack::Process * Process = DF->getProcess();
DFHack::Gui * gui = DF->getGui();
cout << Process->getPath() << endl;
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();
#endif
return 0;
}