Esempio n. 1
0
// Needed by OllyscriptEditor
extc HWND _export cdecl DebugScript(const char* const filename)
{
	if (filename!="")
	{
		ollylang->LoadScript((LPSTR)filename);
		ollylang->Pause();
		script_state = ollylang->script_state;
		initProgTable();
		SetForegroundWindow(ollylang->wndProg.hw);
		SetFocus(ollylang->wndProg.hw);     
	}
	return ollylang->wndProg.hw;
}
Esempio n. 2
0
// Needed by OllyscriptEditor
extc HWND _export cdecl DebugScript(const char* filename)
{
	string file = filename;
	if (file.length() > 0)
	{
		ollylang->LoadScript(w_strtow(file));
		ollylang->Pause();
		script_state = ollylang->script_state;
		initProgTable(0); // FIX
		SetForegroundWindow(ollylang->wndProg.hw);
		SetFocus(ollylang->wndProg.hw);
	}
	return ollylang->wndProg.hw;
}
Esempio n. 3
0
int Mscriptwindow(t_table* pt, wchar_t* name, ulong index, int mode)
{
	switch (mode)
	{
		case MENU_VERIFY:
			return MENU_NORMAL;

		case MENU_EXECUTE:
			//ODBG_Pluginaction(PM_MAIN, 30, NULL);
			script_menu = build_script_menu();
			script_menu_vec = script_menu.build();
			initProgTable(script_menu_vec.data());
			return MENU_NOREDRAW;

		default:
			return MENU_ABSENT;
	}
}
Esempio n. 4
0
// OllyDbg calls this obligatory function once during startup. I place all
// one-time initializations here. Parameter features is reserved for future
// extentions, do not use it.
extc int _export cdecl ODBG_Plugininit(int ollydbgversion, HWND hw, ulong *features) 
{
	HINSTANCE hinst;

	if(ollydbgversion < PLUGIN_VERSION) {
		MessageBox(hwndOllyDbg(), "Incompatible Ollydbg Version !", "ODbgScript", MB_OK | MB_ICONERROR | MB_TOPMOST);
		return -1;
	}

	// Report plugin in the log window.
	Addtolist(0, 0, "ODbgScript v%i.%i.%i",VERSIONHI,VERSIONLO,VERSIONST);
	Addtolist(0, -1,"  http://odbgscript.sf.net");
	ollylang = new OllyLang();

	if (Createsorteddata(&ollylang->wndProg.data,"ODbgScript Data", 
		sizeof(t_wndprog_data),50, (SORTFUNC *)wndprog_sort_function,NULL)!=0)
			return -1; 

	if (Createsorteddata(&ollylang->wndLog.data,"ODbgScript Log", 
	sizeof(t_wndlog_data),20, (SORTFUNC *)wndlog_sort_function,NULL)!=0)
		return -1;

	hinst = hinstModule();

	if (Registerpluginclass(wndprogclass,NULL,hinst,wndprog_winproc)<0) {
		return -1;
	}
	if (Registerpluginclass(wndlogclass,NULL,hinst,wndlog_winproc)<0) {
		return -1;
	}
	if (Plugingetvalue(VAL_RESTOREWINDOWPOS)!=0 && Pluginreadintfromini(hinst,"Restore Script Log",0)!=0)
		initLogWindow();

	if (Plugingetvalue(VAL_RESTOREWINDOWPOS)!=0 && Pluginreadintfromini(hinst,"Restore Script window",0)!=0)
		initProgTable();

	return 0;
}
Esempio n. 5
0
// Receives commands from windows menus.
extc void _export cdecl ODBG_Pluginaction(int origin, int action, void *item) 
{

  switch (origin)
  {
	case PM_MAIN:
	case PM_DISASM:
		break;
	default:
		//Other windows ignored
		return;
  }

  char s[256];
  HINSTANCE hinst  = hinstModule();
  HWND      hwmain = hwndOllyDbg();
  OPENFILENAME ofn={0};
  switch (action) 
  {
	case 0: // Run script
		       // common dialog box structure
		char szFile[260];       // buffer for file name
		
		// Initialize OPENFILENAME
		//ZeroMemory(&ofn, sizeof(ofn));
		ofn.lStructSize = sizeof(ofn);
		ofn.hwndOwner = hwmain;
		ofn.lpstrFile = szFile; 
		//
		// Set lpstrFile[0] to '\0' so that GetOpenFileName does not 
		// use the contents of szFile to initialize itself.
		//
		ofn.lpstrFile[0] = '\0';
		ofn.nMaxFile = sizeof(szFile);
		ofn.lpstrFilter = "Olly Scripts\0*.osc;*.txt\0All\0*.*\0";
		ofn.nFilterIndex = 1;
		ofn.lpstrFileTitle = NULL;
		ofn.nMaxFileTitle = 0;
		Pluginreadstringfromini(hinst, "ScriptDir", buff, 0);
		ofn.lpstrInitialDir = buff;
		ofn.lpstrTitle = "Select Script";
		ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
		

		// Display the Open dialog box. 
		if (GetOpenFileName(&ofn)==TRUE) //Comdlg32.lib
		{
			// Load script
			ollylang->LoadScript(ofn.lpstrFile);
			if (ollylang->wndProg.hw) {
				SetForegroundWindow(ollylang->wndProg.hw);
				SetFocus(ollylang->wndProg.hw);
			}
			// Start script
			ollylang->Resume();
		}
		break;

	case 1: // Abort
		MessageBox(hwmain,"Script aborted!","ODbgScript",MB_OK|MB_ICONEXCLAMATION);
		ollylang->Reset(); 
		ollylang->Pause();
		break;

	case 2: // Pause
		ollylang->Pause();
		break;

	case 3: // Resume
		ollylang->Resume();
		break;

	case 4: // Step
		ollylang->Step(1);
		script_state = ollylang->script_state;
		break;

	case 5: // Force Pause (like Pause Key)
		focusonstop=4;
		ollylang->Pause();
		script_state = ollylang->script_state;
    	break;

	case 10:
		sprintf(s,"ODbgScript plugin v%i.%i.%i\n"
			      "by [email protected]\n\n"
				  "From OllyScript written by SHaG\n"
				  "PE dumper by R@dier\n"
				  "Byte replacement algo by Hex\n\n"
				  "http://odbgscript.sf.net/ \n\n"
				  "Compiled %s %s",
			VERSIONHI,VERSIONLO,VERSIONST, __DATE__, __TIME__);
		MessageBox(hwmain,s,"ODbgScript",MB_OK|MB_ICONINFORMATION);
		break;
	case 20: 
		{
			string directory, helpfile;
			getPluginDirectory(directory);
			helpfile = directory + "\\ODbgScript.txt";			
			ShellExecute(hwndOllyDbg(),"open",helpfile.c_str(),NULL,directory.c_str(),SW_SHOWDEFAULT);
		}
		break;
	case 21: // MRU List in CPU Window
	case 22:
	case 23:
	case 24:
	case 25:
	case 26:
	case 27:
	case 28:
	case 29:
		{
			action-=20; 
			char key[5]="NRU ";
			key[3]=action+0x30;
						
			ZeroMemory(&buff, sizeof(buff));
			Pluginreadstringfromini(hinst,key,buff,0);

			// Load script
			ollylang->LoadScript(buff);

			mruAddFile(buff);
 
			// Save script directory
			char* buf2;
			GetFullPathName(buff,sizeof(buff),buff,&buf2); *buf2=0;			
			Pluginwritestringtoini(hinst, "ScriptDir", buff);

			ollylang->Resume();
			if (ollylang->wndProg.hw) {
				SetForegroundWindow(ollylang->wndProg.hw);
				SetFocus(ollylang->wndProg.hw);
			}

			break;
		}
	case 30:
		{
			initProgTable();
			break;
		}
	case 31:
		{
			initLogWindow();
			break;
		}
	case 32: // Edit Script
		{
			ShellExecute(hwndOllyDbg(),"open",ollylang->scriptpath.c_str(),NULL,ollylang->currentdir.c_str(),SW_SHOWDEFAULT);
			break;
		}
	case 11:
		{
//			string x = "Hej";
//			string y = ToLower(x);
//			__asm nop;
		}
	case 12:
		{
//			Broadcast(WM_USER_CHALL, 0, 0);
		}
//			t_thread* thr = Findthread(Getcputhreadid());
//			byte buffer[4];
//			ulong fs = thr->reg.limit[2]; // BUG IN ODBG!!!
//			fs += 0x30;
//			Readmemory(buffer, fs, 4, MM_RESTORE);
//			fs = *((ulong*)buffer);
//			fs += 2;
//			buffer[0] = 0;
//			Writememory(buffer, fs, 1, MM_RESTORE);
//			cout << endl;
		
//			ulong addr = t->reg.s[SEG_FS];
//			Readmemory(buffer, addr, 4, MM_RESTORE);
//			cout << hex << &buffer;

			/*
			HMODULE hMod = GetModuleHandle("OllyScript.dll");
			if(hMod) // Check that the other plugin is present and loaded
			{
				// Get address of exported function
				int (*pFunc)(char*) = (int (*)(char*)) GetProcAddress(hMod, "ExecuteScript");
				if(pFunc) // Check that the other plugin exports the correct function
					pFunc("xxx"); // Execute exported function
			}

			cout << hex << hMod << endl;*/
			//403008 401035
			/*DWORD pid = Plugingetvalue(VAL_PROCESSID);
			DebugSetProcessKillOnExit(FALSE);
			DebugActiveProcessStop(pid);
			break;*/
			//t_module* mod = Findmodule(0x401000);
			//cout << hex << mod->codebase;
			
			//cout << hex << mod->codebase;
		
		break;

    default: 
		break;
  }
}