Sign in to follow this  
Followers 0
lolp1

Old code re-compiled not working, need help

9 posts in this topic

Well I'm not really sure whats going on. I made some old example DLL injector witht he UDF posted here a while ago, and I had the .exe I compiled from about 3-5 months ago. I decided to change the icon today for fun as I got a new one, and re-compiled it(from the decompiled code from the .EXT made 3-5 months ago). The problem is now it will not inject anything successfully, but it's the same code. Hmm.. any idea?s? (The orignal .exe made 3-5 months ago injects the same DLL successfully)

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.1.14 (beta)
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------


Func _InjectDll($hWnd, $dllpath)
    ;make sure the user passed valid parameters
    If $hWnd <= 0 Then
        SetError(-1)
        Return False
    ElseIf StringLen($dllpath) <= 4 Or StringRight($dllpath, 4) <> ".dll" Then
        SetError(-2)
        Return False
    EndIf

    Local $pid, $pHandle, $pLibRemote, $modHandle, $LoadLibraryA, $hThread

    ;open dll that we'll be using
    Local $kernel32 = DllOpen("kernel32.dll")

    ;get the pid from the window provided
    $pid = DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $hWnd, "int_ptr", 0)
    If IsArray($pid) Then
        $pid = $pid[2]
    Else
        SetError(-3)
        Return False
    EndIf

    ;open the process for writing
    $pHandle = DllCall($kernel32, "int", "OpenProcess", "int", 0x1F0FFF, "int", 0, "int", $pid)
    If IsArray($pHandle) And $pHandle[0] > 0 Then
        $pHandle = $pHandle[0]
    Else
        SetError(-4)
        Return False
    EndIf

    $pLibRemote = DllCall($kernel32, "int", "VirtualAllocEx", "int", $pHandle, "short", 0, "int", 0x1000, "int", 0x1000, "int", 4)
    If IsArray($pLibRemote) Then
        If $pLibRemote[0] > 0 Then
            ;debug
            ConsoleWrite("0x" & Hex($pLibRemote[0], 8) & @CR)
            $pLibRemote = $pLibRemote[0]
        Else
            SetError(-5)
            Return False
        EndIf
    Else
        SetError(-6)
        Return False
    EndIf

    For $i = 0 To StringLen($dllpath)
        $ret = DllCall("kernel32.dll", "int", "WriteProcessMemory", "int", $pHandle, "int", $pLibRemote + $i, "int_ptr", Asc(StringMid($dllpath, $i + 1, 1)), "int", 1, "int", 0)
        If IsArray($ret) Then
            If $ret[0] = 0 Then
                SetError(-7)
                Return False
            EndIf
        Else
            SetError(-8)
            Return False
        EndIf
    Next

    $modHandle = DllCall($kernel32, "long", "GetModuleHandle", "str", "kernel32.dll")
    If IsArray($modHandle) Then
        If $modHandle[0] > 0 Then
            $modHandle = $modHandle[0]
        Else
            SetError(-9)
            Return False
        EndIf
    Else
        SetError(-10)
        Return False
    EndIf

    $LoadLibraryA = DllCall($kernel32, "long", "GetProcAddress", "long", $modHandle, "str", "LoadLibraryA")
    If IsArray($LoadLibraryA) Then
        If $LoadLibraryA[0] > 0 Then
            $LoadLibraryA = $LoadLibraryA[0]
        Else
            SetError(-11)
            Return False
        EndIf
    Else
        SetError (-12)
        Return False
    EndIf

    $hThread = DllCall($kernel32, "int", "CreateRemoteThread", "int", $pHandle, "int", 0, "int", 0, "long", $LoadLibraryA, "long", $pLibRemote, "int", 0, "int", 0)
    If IsArray($hThread) Then
        ConsoleWrite($hThread[0] & @CR)
        If $hThread[0] > 0 Then
            $hThread = $hThread[0]
        Else
            SetError(-13)
            Return False
        EndIf
    Else
        SetError(-14)
        Return False
    EndIf

    DllCall($kernel32, "int", "VirtualFreeEx", "int", $pHandle, "int", $pLibRemote, "int", 0x1000, "int", 0x8000)
    DllCall($kernel32, "int", "CloseHandle", "int", $hThread)
    DllCall($kernel32, "int", "CloseHandle", "int", $pHandle)

    DllClose($kernel32)

    Return True
EndFunc


$switches = IniRead ( "global.ini", "global", "windowname", "");
$rundown = IniRead ( "global.ini", "global", "dllpath", "");

$ret = _InjectDll(WinGetHandle($switches), $rundown)
$err = @error
If $err < 0 Then
    MsgBox(16, $ret, $err)
Else
    MsgBox(64, $ret, "DLL Injected sucssfully")
EndIf

Share this post


Link to post
Share on other sites

I think source of problems will be "int_ptr" in DllCall.

There are AutoIt changes in DllCall types, look into beta changelog.

I'm not sure but maybe int* is new syntax.

And if you want only change icon then needn't recompile your EXE,

just use ResaHacker to replace existing icon inside your EXE <_<

Share this post


Link to post
Share on other sites

I think source of problems will be "int_ptr" in DllCall.

There are AutoIt changes in DllCall types, look into beta changelog.

I'm not sure but maybe int* is new syntax.

And if you want only change icon then needn't recompile your EXE,

just use ResaHacker to replace existing icon inside your EXE <_<

Well I also wanted to make some small changes, but we'll see.

If anyone has time to find some ingenious fix or already has one feel free to post as I'm going to sleep, I'll check this thread in the morning and hope some one has came across this problem and already found a solution.

Share this post


Link to post
Share on other sites

Ok well I checked and from what I see int string has nothing to do with the problem, but I'm not 100% sure.

Anyone have some suggestions?

Share this post


Link to post
Share on other sites

No one can solve this mysterys I suppose. I'll have to find a old version of auto it.

Share this post


Link to post
Share on other sites

You mentioned you got a new printer? If you did, maybe the dll changed a bit.

What in gods name are you talking about? A printer? a new DLL?

This has nothing to do with anything.

Share this post


Link to post
Share on other sites

I decided to change the icon today for fun as I got a new one,

What is the "got a new one"?

Share this post


Link to post
Share on other sites

What is the "got a new one"?

I don't know how much more clear I can be - I got a new icon.

Share this post


Link to post
Share on other sites

Oh.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0