Thursday, 2 March 2017

Sublime text cutting when I want to delete? (Shift+Delete is Cut)

Selecting some stuff to cut, then selecting rest of code to delete causes what I want to delete to be copied to the clipboard.

Because  Shift+Delete is Cut hotkey for some archaic reason.

A pain in the ass, because obviously I want to delete what I selected and not cut it to the clipboard.
Okay, I could just slow down and wait to left my left pinky depress left shift fully.
But blah, fuck that.

I found I can over-write the default keymap for shift+delete (and some others) made it delete_word which is way more helpful.

Preferences | Key Bindings

Paste this into the User keymap.


[ { "keys": ["shift+delete"], "command": "delete_word" }, { "keys": ["ctrl+insert"], "command": "none" }, { "keys": ["shift+insert"], "command": "none" }, ]

Thursday, 8 December 2016

UnhandledExceptionFilter wont compile in VS2015 but worked in VS2012 Already defined. Also VEH to detect unpacked ASProtect.




If you are using UnhandledExceptionFilter in a C++ application and try to compile with VS2017 (It worked in 2012 just fine)

And you get the error message

Severity Code Description Project File Line Suppression State
Error LNK2005 _UnhandledExceptionFilter@4 already defined in kernel32.lib(KERNEL32.dll) ...
Error LNK1169 one or more multiply defined symbols found ...


And you also have a function called UnhandledExceptionFilter

Try renaming it to something else.

The compiler or linker? im not sure which.
Rename the method to _UnhandledExceptionFilter which conflicts with one in kernel32 when linking....


What the heck.


A bonus content for you.

I detect if the ASProtect packed target executable is unpacked by using a VEH
I use an injected dll to run this code and the rest of my code inside the target process.
I start the process suspended, inject dll then resume the main thread.



VEH Handler

DWORD test = 0;
DWORD exceptionCount = 0;
LONG WINAPI MyUnhandledExceptionFilter(EXCEPTION_POINTERS *pExceptionInfo)
{
void* Eip = (void*)pExceptionInfo->ContextRecord->Eip;

exceptionCount++;

// sprintf(Message, "Exception Count: %i\nException Code: %X\nEIP: %p\nRegisters\n\nEAX: %X EBX: %X ECX: %X EDX: %X\nESP: %X EBP: %X\nESI: %X EDI: %X\n",
// exceptionCount,
// pExceptionInfo->ExceptionRecord->ExceptionCode,
// pExceptionInfo->ContextRecord->Eip,
// pExceptionInfo->ContextRecord->Eax, pExceptionInfo->ContextRecord->Ebx, pExceptionInfo->ContextRecord->Ecx, pExceptionInfo->ContextRecord->Edx,
// pExceptionInfo->ContextRecord->Esp, pExceptionInfo->ContextRecord->Ebp,
// pExceptionInfo->ContextRecord->Esi, pExceptionInfo->ContextRecord->Edi);
//MessageBox(null, Message, "Debug", MB_OK);

// We know the game is unpacked when the exception has a PUSH 0C after it.
// This just seems to be the way it is for asprotect. See Tuts4You Loaders.asprotect1.pdf
BYTE* oData = (BYTE*)Eip;
if (oData[19] == 0x6A && oData[20] == 0x0C)
{
// Game is unpacked in memory and memory security check is done.
// This just detours the games init function. (I couldn't detour it reliably without this code because some faster computers would have already run it, and slower computers might not have even unpacked by the time my dll inits. Sleeps were not a good solution.
origInitGame = (t_InitGameFn)DetourCreate((LPVOID)0x00403180,(LPVOID)initGameHook, DETOUR_TYPE_JMP);

isGameUnpacked = true;
return EXCEPTION_CONTINUE_SEARCH;
}

return EXCEPTION_CONTINUE_SEARCH;
}


Add the VEH

hVEH = AddVectoredExceptionHandler(1, &MyUnhandledExceptionFilter);
if (hVEH == NULL)
{
MessageBox(mainhWnd, "Error VEH 1.", "DLL ERROR", MB_OK + MB_APPLMODAL);
return 0;
}


// Check while its not unpacked. This serves as a timeout.

int pCheckUnpackedCounter = 0;
while (isGameUnpacked == FALSE)
{


if (pCheckUnpackedCounter > 60000)
{
// Roughly 1 minute.
// Unable to detect unpacked game code.
// Remove our vectored exception handler, it has done its job.
RemoveVectoredExceptionHandler(hVEH);
MessageBox(mainhWnd, "Error VEH 2.", "DEBUG", MB_OK + MB_APPLMODAL);
ExitProcess(1);
return 0;
}

Sleep(1);
pCheckUnpackedCounter++;
}


Remove the VEH when its done its job.


// Remove our vectored exception handler, it has done its job.
RemoveVectoredExceptionHandler(hVEH);

Tuesday, 8 November 2016

jQuery make input element select value when it gets focus.

I think this makes inputs more user friendly in that focus can be assigned and the user can start typing to replace the number.

// A behavioural change to all input elements.
// Make them select the text when they get focus.
$(document).ready(function() {
    $('body').on('focusin', 'input', function() {
        console.log('Input selected:', this.id, this.name);
        $(this).select();
    });
});

Friday, 26 August 2016

Private VPN for playing games or using other software as if two or more LAN's were connected.

Got sick of hamachi screwing out.
https://nwgat.ninja/quick-easy-tinc-vpn-between-windows-systems/

And if you want to play games that use IPX but dont want to install IPX use one of these to wrap it with UDP.
http://www.moddb.com/games/cc-red-alert-2/downloads/ra2yr-lan-fix-xp-vista-w7-x86-x64
or
http://www.solemnwarning.net/ipxwrapper/

Wednesday, 23 September 2015

MSSQL Context_Info session value global value.

How to store and read bits from a session value called Context_Info.



SET Context_Info 0xFF; -- bitindex is the value of the bit you want to get for example 7 is a value of 64 or 0x40 -- CONVERT(tinyint,bitindex value) & SUBSTRING(Context_Info(),byteoffset+1, 1) select CONVERT(tinyint,0x01) & SUBSTRING(Context_Info(),1,1) AS '1', CONVERT(tinyint,0x02) & SUBSTRING(Context_Info(),1,1) AS '2', CONVERT(tinyint,0x04) & SUBSTRING(Context_Info(),1,1) AS '4', CONVERT(tinyint,0x08) & SUBSTRING(Context_Info(),1,1) AS '8', CONVERT(tinyint,0x10) & SUBSTRING(Context_Info(),1,1) AS '16', CONVERT(tinyint,0x20) & SUBSTRING(Context_Info(),1,1) AS '32', CONVERT(tinyint,0x40) & SUBSTRING(Context_Info(),1,1) AS '64', CONVERT(tinyint,0x80) & SUBSTRING(Context_Info(),1,1) AS '128'


You can also store strings in it.

DECLARE @MyStatus VARBINARY(128); SET @MyStatus = CAST('TEST' AS VARBINARY(128)); SET Context_Info @MyStatus; SELECT CAST(Context_Info() AS VARCHAR) -- Or substring :D SELECT CAST(SUBSTRING(CONTEXT_INFO(), 1, 4) AS VARCHAR)



This Context_Info value could be useful to store a value for the session and change the control flow of a trigger.

Monday, 19 January 2015

Moving from Tomboy to GNote for note keeping on ubuntu.

So I had a bunch of notes stored in Tomboy on an older version of ubuntu.

When I upgraded to a newer version of linux I found out I just could not use tomboy notes.
I read somewhere that tomboy was officially removed as a default note app/in apt-get repository the author of that message recommended GNote.

When I installed it, it conflicted with google chrome and uninstalled that automatically.
Re installing chrome would remove Tomboy.

The solution is to use GNote which I think is actually nicer and to copy the *.note files from tomboy to your gnote directory in ~/.local/share/.

sudo apt-get update && sudo apt-get install gnote
cp ~/.local/share/tomboy/*.note ~/.local/share/gnote/


You may also want to auto start gnote

mkdir ~/.config/autostart
cp /usr/share/applications/gnote.desktop ~/.config/autostart/
chmod u+x ~/.config/autostart/gnote.desktop


Thanks to http://www.irrational.net/2012/04/27/moving-from-tomboy-to-gnote/

Wednesday, 14 May 2014

Oracle Database not replicating or SSL not working.

Check the date time on the server/computer.....
Make sure its set correctly, Enable Network Time Protocol syncing....

Check the cmos battery.
Yip we had a powercut and a machine we are using as a db server had the cmos battery go flat so the date was in the past. Records created after that date were not synchronized to other servers and the logs were of little use.