Files
Work/proto/junk/scraps.txt
2024-08-07 09:24:33 -04:00

658 lines
17 KiB
Plaintext

/*
class Comparator
{
public:
bool operator()(const HWND hwnd1,const HWND hwnd2)const{return (int)hwnd1<(int)hwnd2;}
};
typedef map<HWND,int,Comparator> WinMap;
WinMap smWinMap;
*/
#include <common/windows.hpp>
#include <common/library.hpp>
#include <thread/event.hpp>
int messageLoop(void);
void yield();
#include <hookproc/apientry.hpp>
#include <hookproc/procaddr.hpp>
class CBTHook;
typedef ProcAddress<CBTHook> CBTHookProc;
//class CBTHook : protected APIEntry, private CBTHookProc
class CBTHook : protected APIEntry, private CBTHookProc
{
public:
typedef LRESULT (__stdcall *LPFNCBTPROC)(int nCode,WPARAM wParam,LPARAM lParam);
CBTHook();
virtual ~CBTHook();
DWORD getHookAddress(void);
protected:
virtual LRESULT handleActive(WPARAM wParam,LPARAM lParam);
virtual LRESULT handleClickSkipped(WPARAM wParam,LPARAM lParam);
virtual LRESULT handleCreateWnd(WPARAM wParam,LPARAM lParam);
virtual LRESULT handleDestroyWnd(WPARAM wParam,LPARAM lParam);
virtual LRESULT handleKeySkipped(WPARAM wParam,LPARAM lParam);
virtual LRESULT handleMinMax(WPARAM wParam,LPARAM lParam);
virtual LRESULT handleMoveSize(WPARAM wParam,LPARAM lParam);
virtual LRESULT handleQs(WPARAM wParam,LPARAM lParam);
virtual LRESULT handleSetFocus(WPARAM wParam,LPARAM lParam);
virtual LRESULT handleSysCommand(WPARAM wParam,LPARAM lParam);
private:
enum {ParamLength=12};
CBTHook &operator=(const CBTHook &cbtHook);
LRESULT entryProc(int nCode,WPARAM wParam,LPARAM lParam);
HHOOK mhHook;
};
inline
CBTHook::CBTHook(void)
: APIEntry(ParamLength,(DWORD)this,getProcAddress((ProcAddress<CBTHook>::LPFNMETHODVOID)&CBTHook::entryProc)),
mhHook(0)
{
HINSTANCE hProcessInstance=(HINSTANCE)::GetModuleHandle(0);
mhHook=::SetWindowsHookEx(WH_CBT,(HOOKPROC)getHookAddress(),hProcessInstance,0);
}
inline
CBTHook::~CBTHook()
{
if(!mhHook)return;
::UnhookWindowsHookEx(mhHook);
}
inline
CBTHook &CBTHook::operator=(const CBTHook &cbtHook)
{ // no implementation
return *this;
}
inline
DWORD CBTHook::getHookAddress(void)
{
return codeBase();
}
inline
LRESULT CBTHook::entryProc(int nCode,WPARAM wParam,LPARAM lParam)
{
LRESULT result;
::printf("[CBTHook::entryProc]\n");
if(nCode<0)return result=::CallNextHookEx(mhHook,nCode,wParam,lParam);
switch(nCode)
{
case HCBT_ACTIVATE :
result=handleActive(wParam,lParam);
break;
case HCBT_CLICKSKIPPED :
result=handleClickSkipped(wParam,lParam);
break;
case HCBT_CREATEWND :
result=handleCreateWnd(wParam,lParam);
break;
case HCBT_DESTROYWND :
result=handleDestroyWnd(wParam,lParam);
break;
case HCBT_KEYSKIPPED :
result=handleKeySkipped(wParam,lParam);
break;
case HCBT_MINMAX :
result=handleMinMax(wParam,lParam);
break;
case HCBT_MOVESIZE :
result=handleMoveSize(wParam,lParam);
break;
case HCBT_QS :
result=handleQs(wParam,lParam);
break;
case HCBT_SETFOCUS :
result=handleSetFocus(wParam,lParam);
break;
case HCBT_SYSCOMMAND :
result=handleSysCommand(wParam,lParam);
break;
}
return result;
}
// *** virtuals
inline
LRESULT CBTHook::handleActive(WPARAM wParam,LPARAM lParam)
{
return 0;
}
inline
LRESULT CBTHook::handleClickSkipped(WPARAM wParam,LPARAM lParam)
{
return 0;
}
inline
LRESULT CBTHook::handleCreateWnd(WPARAM wParam,LPARAM lParam)
{
return 0;
}
inline
LRESULT CBTHook::handleDestroyWnd(WPARAM wParam,LPARAM lParam)
{
return 0;
}
inline
LRESULT CBTHook::handleKeySkipped(WPARAM wParam,LPARAM lParam)
{
return 0;
}
inline
LRESULT CBTHook::handleMinMax(WPARAM wParam,LPARAM lParam)
{
return 0;
}
inline
LRESULT CBTHook::handleMoveSize(WPARAM wParam,LPARAM lParam)
{
return 0;
}
inline
LRESULT CBTHook::handleQs(WPARAM wParam,LPARAM lParam)
{
return 0;
}
inline
LRESULT CBTHook::handleSetFocus(WPARAM wParam,LPARAM lParam)
{
return 0;
}
inline
LRESULT CBTHook::handleSysCommand(WPARAM wParam,LPARAM lParam)
{
return 0;
}
// *********************************************************************************************
class WinCreateHook : public CBTHook
{
public:
WinCreateHook();
virtual ~WinCreateHook();
protected:
virtual LRESULT handleCreateWnd(WPARAM wParam,LPARAM lParam);
private:
};
inline
WinCreateHook::WinCreateHook()
{
}
inline
WinCreateHook::~WinCreateHook()
{
}
inline
LRESULT WinCreateHook::handleCreateWnd(WPARAM wParam,LPARAM lParam)
{
::printf("[WinCreateHook::handleCreateWnd]");
return 0;
}
// *********************************************************************************************
extern "C"
{
__declspec(dllimport) bool FAR PASCAL unHook(void);
__declspec(dllimport) bool FAR PASCAL setHook(void);
}
void main(int argc,char **argv)
{
// Library library("cbtdll.dll");
// HHOOK mhHook;
// mhHook=::SetWindowsHookEx(WH_CBT,(HOOKPROC)&cbtHookProc,0,0);
// mhHook=::SetWindowsHookEx(WH_CBT,(HOOKPROC)&cbtHookProc,library.getInstance(),0);
/*
if(!library.isOkay())
{
::printf("Library not found");
return;
}
if(!library.procAddress("_cbtHookProc"))
{
::printf("Address not found");
return;
}
mhHook=::SetWindowsHookEx(WH_CBT,(HOOKPROC)library.procAddress("cbtHookProc"),library.getInstance(),0);
*/
if(!setHook())return;
for(int index=0;index<120;index++)
{
yield();
::Sleep(250);
}
unHook();
// HINSTANCE hProcessInstance=(HINSTANCE)::GetModuleHandle(0);
// ::printf("main hInst=0x%08lx",hProcessInstance);
// cbtHookProc(0,0,0);
/*
// Event event;
CBTHook cbtHook;
for(;;)
{
yield();
::Sleep(250);
}
// messageLoop();
// event.waitEvent();
*/
return;
}
int messageLoop(void)
{
MSG msg;
while(::GetMessage(&msg,NULL,0,0))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
return msg.wParam;
}
void yield()
{
MSG msg;
if(::PeekMessage(&msg,0,0,0,PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
}
File inFile;
File outFile;
String strLine;
String midiLine;
String saveLine;
String www;
www="www.burksstudios.com";
if(!inFile.open("d:\\midi.txt","rb"))return false;
outFile.open("d:\\getpage.txt","wb");
while(inFile.readLine(strLine))
{
midiLine=strLine.betweenString('"','"');
if(midiLine.isNull())continue;
Profile::makeFileName(midiLine,saveLine);
outFile.writeLine(www+String(" ")+String("http://")+www+String("/jazz/")+midiLine+String(" d:\\")+saveLine);
}
return 1;
/*
#include <midiseq/midiout.hpp>
#include <midiseq/noteon.hpp>
#include <midiseq/ProgramChange.hpp>
void main(int argc,char **argv)
{
MIDIOutputDevice midiOut;
NoteOn noteOn(PureNote(65,70));
if(!midiOut.openDevice())return;
for(int prog=0;prog<128;prog++)
{
midiOut.midiEvent(ProgramChange(prog).getEvent(0,16));
PureEvent &midiEvent=noteOn.getEvent();
midiOut.midiEvent(midiEvent);
::Sleep(250);
}
// PureEvent getEvent(BYTE deltaTime=0,BYTE channel=0)const;
// PureEvent(BYTE eventType,DWORD deltaTime,BYTE channel,BYTE firstData,BYTE secondData,DWORD tempo=0);
midiOut.closeDevice();
return;
}
*/
/*
35 Acoustic Bass Drum 59 Ride Cymbal 2
36 Bass Drum 1 60 Hi Bongo
37 Side Stick 61 Low Bongo
38 Acoustic Snare 62 Mute Hi Conga
39 Hand Clap 63 Open Hi Conga
40 Electric Snare 64 Low Conga
41 Low Floor Tom 65 High Timbale
42 Closed Hi-Hat 66 Low Timbale
43 High Floor Tom 67 High Agogo
44 Pedal Hi-Hat 68 Low Agogo
45 Low Tom 69 Cabasa
46 Open Hi-Hat 70 Maracas
47 Low-Mid Tom 71 Short Whistle
48 Hi-Mid Tom 72 Long Whistle
49 Crash Cymbal 1 73 Short Guiro
50 High Tom 74 Long Guiro
51 Ride Cymbal 1 75 Claves
52 Chinese Cymbal 76 Hi Wood Block
53 Ride Bell 77 Low Wood Block
54 Tambourine 78 Mute Cuica
55 Splash Cymbal 79 Open Cuica
56 Cowbell 80 Mute Triangle
57 Crash Cymbal 2 81 Open Triangle
58 Vibraslap
*/
/*
bool ClassMapper::createClass(const String &packageName,const String &className,const String &strPathMapFile,const String &strPathTable)
{
File inFile;
File outFile;
String strLine;
String name;
String value;
String methodName;
Block<NameValuePair> variables;
int errors=0;
if(!loadMapping(strPathMapFile))return false;
if(!inFile.open(strPathTable,"rb"))return false;
while(true)
{
inFile.readLine(strLine);
if(strLine.isNull())break;
name=strLine.betweenString(' ',' ');
name=makeHungarian(name);
value=strLine.betweenString(' ',0).betweenString(' ',' ');
if(!mapType(value,value))
{
printf("Don't know how to map %s\n",value.str());
errors++;
continue;
}
variables.insert(&NameValuePair(name,value));
}
inFile.close();
if(errors)return false;
if(!variables.size())return false;
if(!outFile.open(className+String(".java"),"wb"))return false;
if(!packageName.isNull())outFile.writeLine(String("package ")+packageName);
outFile.writeLine("\t");
outFile.writeLine("\t");
outFile.writeLine(String("public class ")+className);
outFile.writeLine("{");
for(int index=0;index<variables.size();index++)
{
NameValuePair &nameValuePair=variables[index];
outFile.writeLine(String(" private ")+nameValuePair.getValue()+String(" ")+nameValuePair.getName()+String(";"));
}
for(index=0;index<variables.size();index++)
{
NameValuePair &nameValuePair=variables[index];
outFile.writeLine(String(" public ")+nameValuePair.getValue()+String(" ")+makeAccessor(nameValuePair.getName())+String("()"));
outFile.writeLine(" {");
outFile.writeLine(String(" return ")+nameValuePair.getName()+String(";"));
outFile.writeLine(" }");
outFile.writeLine(String(" public void ")+makeMutator(nameValuePair.getName())+String("(")+nameValuePair.getValue()+String(" ")+nameValuePair.getName()+String(")"));
outFile.writeLine(" {");
outFile.writeLine(String(" this.")+nameValuePair.getName()+String("=")+nameValuePair.getName()+String(";"));
outFile.writeLine(" }");
}
outFile.writeLine("};");
outFile.close();
printf("class generation completed with %d errors\n",errors);
return true;
}
*/
/*
bool ClassMapper::createResultClass(const String &packageName,const String &className,const String &instanceName,const String &strPathMapFile,const String &strPathTable)
{
File inFile;
File outFile;
String strLine;
String name;
String value;
String methodName;
Block<NameValuePair> variables;
Block<NameValuePair> originals;
int errors=0;
if(!loadMapping(strPathMapFile))return false;
if(!inFile.open(strPathTable,"rb"))return false;
while(true)
{
inFile.readLine(strLine);
if(strLine.isNull())break;
name=strLine.betweenString(' ',' ');
value=strLine.betweenString(' ',0).betweenString(' ',' ');
if(!mapType(value,value))
{
printf("Don't know how to map %s\n",value.str());
errors++;
continue;
}
variables.insert(&NameValuePair(makeHungarian(name),value));
originals.insert(&NameValuePair(name,value));
}
inFile.close();
if(errors)return false;
if(!variables.size())return false;
if(!outFile.open(className+String("RS")+String(".java"),"wb"))return false;
if(!packageName.isNull())outFile.writeLine(String("package ")+packageName);
outFile.writeLine("\t");
outFile.writeLine("\t");
outFile.writeLine("public void processResult()");
outFile.writeLine("{");
outFile.writeLine(String(" ")+className+String(" ")+instanceName+String(";"));
outFile.writeLine(" ResultSet rs;");
outFile.writeLine("// fill in the blanks");
for(int index=0;index<variables.size();index++)
{
NameValuePair &original=originals[index];
NameValuePair &variable=variables[index];
outFile.writeLine(String(" ")+instanceName+String(".")+makeMutator(variable.getName())+String("(rs.get")+makeFirstUpper(variable.getValue())+String("(\"")+original.getName()+String("\"));"));
}
outFile.writeLine("}");
outFile.close();
printf("result set mapping completed with %d errors\n",errors);
return true;
}
*/
ProcessAPI processAPI;
ProcessInfoList processInfoList;
processAPI.enumProcesses(processInfoList);
for(int index=0;index<processInfoList.size();index++)
{
ProcessInfo &processInfo=processInfoList[index];
::OutputDebugString(String(String("ProcessID:")+processInfo.processID().toString()+String("\n")).str());
ModuleInfoList &moduleInfoList=processInfo;
for(int modIndex=0;modIndex<moduleInfoList.size();modIndex++)
{
if(!modIndex)::OutputDebugString(String(moduleInfoList[modIndex].moduleFileName()+String("\n")).str());
else ::OutputDebugString(String(String(" ")+moduleInfoList[modIndex].moduleFileName()+String("\n")).str());
}
::OutputDebugString("************************************************\n");
}
#include <common/file.hpp>
#include <common/library.hpp>
#include <common/filetime.hpp>
#include <common/systime.hpp>
#include <common/process.hpp>
#include <common/pview.hpp>
#include <common/filemap.hpp>
#include <common/openfile.hpp>
#include <image/pehdr.hpp>
#include <psapint/psapi.hpp>
void displayMemory();
void displayProcesses();
void showModule(const String &pathFileName);
void showVersionInfo(const ModuleInfo &moduleInfo,String &moduleBaseName,String &moduleFileName);
void displayAutoRuns();
int main(int argc,char **argv)
{
return 0;
}
void displayAutoRuns()
{
}
void displayProcesses()
{
ProcessIDList processIDList;
ProcessAPI processAPI;
ModuleInfoList moduleInfoList;
processAPI.enumProcesses(processIDList);
for(int index=0;index<processIDList.size();index++)
{
const ProcessID &processID=processIDList[index];
processAPI.enumProcessModules(processID,moduleInfoList);
for(int modIndex=0;modIndex<moduleInfoList.size();modIndex++)
{
String moduleBaseName;
String moduleFileName;
const ModuleInfo &moduleInfo=moduleInfoList[modIndex];
processAPI.getModuleBaseName(processID,moduleInfo.module(),moduleBaseName);
processAPI.getModuleFileName(processID,moduleInfo.module(),moduleFileName);
if(!modIndex)printf("Pid:%s\t%s\t\t%s\n",processID.toString().str(),moduleBaseName.str(),moduleFileName.str());
else printf("\t\t\t%s\t\t%s\n",moduleBaseName.str(),moduleFileName.str());
showVersionInfo(moduleInfo,moduleBaseName,moduleFileName);
}
}
}
void showVersionInfo(const ModuleInfo &moduleInfo,String &moduleBaseName,String &moduleFileName)
{
HGLOBAL hGlobal;
if(moduleBaseName.isNull()&&moduleFileName.isNull())
{
printf("Cannot open module :0x%08lx\n",moduleInfo.module());
return;
}
HRSRC hRsrc=::FindResource(moduleInfo.module(),"VERSION",RT_VERSION);
if(!hRsrc)
{
printf("Module 0x%08lx does not contain version information\n",moduleInfo.module());
return;
}
hGlobal=::LoadResource(moduleInfo.module(),hRsrc);
}
void showModule(const String &moduleFileName)
{
PEHeader peHeader;
Block<ImageImportDescriptor> imageImportDescriptors;
ImageSectionHeader imageSectionHeader;
FileHandle inFile(moduleFileName,FileHandle::Read);
if(!inFile.isOkay())return;
FileMap inMap(inFile);
PureViewOfFile view(inMap);
peHeader<<view;
ImageSectionHeaders &imageSectionHeaders=(ImageSectionHeaders&)peHeader;
for(int index=0;index<imageSectionHeaders.size();index++)
{
printf("\t\t\t\t%s\n",imageSectionHeaders[index].name().str());
}
// peHeader.loadImageImportDescriptors(imageImportDescriptors,imageSectionHeader,view);
}
void displayMemory()
{
MEMORYSTATUS memoryStatus;
HANDLE hCurrentProcess(::GetCurrentProcess());
FILETIME ftCreationTime;
FILETIME ftExitTime;
FILETIME ftKernelTime;
FILETIME ftUserTime;
SystemTime creationTime;
SystemTime exitTime;
SystemTime kernelTime;
SystemTime userTime;
::memset(&memoryStatus,0,sizeof(MEMORYSTATUS));
memoryStatus.dwLength=sizeof(MEMORYSTATUS);
::GlobalMemoryStatus(&memoryStatus);
::printf("Memory Status\n");
::printf("-------------\n");
::printf("Percent In Use:%ld\n",memoryStatus.dwMemoryLoad);
::printf("Physical Memory:%ld\n",memoryStatus.dwTotalPhys);
::printf("Physical Available:%ld\n",memoryStatus.dwAvailPhys);
::printf("Page File Size:%ld (bytes)\n",memoryStatus.dwAvailPageFile);
::printf("Total Virtual:%ld (bytes)\n",memoryStatus.dwTotalVirtual);
::printf("Available Virtual:%ld (bytes)\n",memoryStatus.dwAvailVirtual);
::GetProcessTimes(hCurrentProcess,&ftCreationTime,&ftExitTime,&ftKernelTime,&ftUserTime);
creationTime=FileTime(ftCreationTime);
exitTime=FileTime(ftExitTime);
kernelTime=FileTime(ftKernelTime);
userTime=FileTime(ftUserTime);
::printf("Process Times\n");
::printf("Creation Time:%s\n",creationTime.toString().str());
::printf("Exit Time:%s\n",exitTime.toString().str());
::printf("Kernel Time:%02d:%02d:%02d.%03d\n",kernelTime.hour(),kernelTime.minute(),kernelTime.second(),kernelTime.milliseconds());
::printf("User Time:%02d:%02d:%02d.%03d\n",userTime.hour(),userTime.minute(),userTime.second(),userTime.milliseconds());
::printf("\n");
}