Announcement

Collapse
No announcement yet.

Clipboard put file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Clipboard put file

    I want to put a file on the clipboard so it can be pasted into explorer, something like this should work but I'm unsure how to put a pointer and a file path on the same memory allocation:

    Code:
    User32 [COLOR="#FF0000"]=[/COLOR] Library[COLOR="#FF0000"].[/COLOR]Load([COLOR="#800080"]"user32.dll"[/COLOR]);
    
    SetFile [COLOR="#FF0000"]=[/COLOR] [COLOR="#0000FF"]function[/COLOR](filepath)
     [COLOR="#0000FF"]local[/COLOR] t [COLOR="#FF0000"]=[/COLOR] filepath [COLOR="#FF0000"]..[/COLOR][COLOR="#800080"]"[COLOR="#800080"]\0[/COLOR]"[/COLOR]
     [COLOR="#0000FF"]if[/COLOR] User32[COLOR="#FF0000"].[/COLOR]OpenClipboard(Application[COLOR="#FF0000"].[/COLOR]GetWndHandle()) [COLOR="#FF0000"]==[/COLOR] [COLOR="#000000"]0[/COLOR] [COLOR="#0000FF"]then[/COLOR] [COLOR="#0000FF"]return[/COLOR] [COLOR="#0000FF"]end[/COLOR]
     [COLOR="#0000FF"]if[/COLOR] User32[COLOR="#FF0000"].[/COLOR]EmptyClipboard() [COLOR="#FF0000"]==[/COLOR] [COLOR="#000000"]0[/COLOR] [COLOR="#0000FF"]then[/COLOR] User32[COLOR="#FF0000"].[/COLOR]CloseClipboard() [COLOR="#0000FF"]return[/COLOR] [COLOR="#0000FF"]end[/COLOR]
     [COLOR="#0000FF"]local[/COLOR] h [COLOR="#FF0000"]=[/COLOR] Kernel32[COLOR="#FF0000"].[/COLOR]GlobalAlloc(0x42[COLOR="#FF0000"],[/COLOR]String[COLOR="#FF0000"].[/COLOR]Length(t) + [COLOR="#000000"]21[/COLOR]) [COLOR="#008000"]-- 0x42 = GMEM_MOVEABLE | GMEM_ZEROINIT[/COLOR]
     [COLOR="#0000FF"]if[/COLOR] h [COLOR="#FF0000"]==[/COLOR] [COLOR="#000000"]0[/COLOR] [COLOR="#0000FF"]then[/COLOR] User32[COLOR="#FF0000"].[/COLOR]CloseClipboard() [COLOR="#0000FF"]return[/COLOR] [COLOR="#0000FF"]end[/COLOR]
     [COLOR="#0000FF"]local[/COLOR] l [COLOR="#FF0000"]=[/COLOR] Kernel32[COLOR="#FF0000"].[/COLOR]GlobalLock(h)
     [COLOR="#0000FF"]if[/COLOR] l [COLOR="#FF0000"]==[/COLOR] [COLOR="#000000"]0[/COLOR] [COLOR="#0000FF"]then[/COLOR] User32[COLOR="#FF0000"].[/COLOR]CloseClipboard() [COLOR="#0000FF"]return[/COLOR] [COLOR="#0000FF"]end[/COLOR]
     [COLOR="#008000"]-- http://msdn.microsoft.com/en-us/library/windows/desktop/bb773269%28v=vs.85%29.aspx[/COLOR]
     [COLOR="#008000"]-- MemoryEx.String needs filling with DROPFILES.pFiles for first 20 bytes[/COLOR]
     [COLOR="#008000"]-- then the 'filepath' is to fill the remaining bytes in the buffer[/COLOR]
     MemoryEx[COLOR="#FF0000"].[/COLOR]String(l[COLOR="#FF0000"],[/COLOR]-[COLOR="#000000"]1[/COLOR][COLOR="#FF0000"],[/COLOR]MEMEX_ASCII[COLOR="#FF0000"],[/COLOR]t)
     Kernel32[COLOR="#FF0000"].[/COLOR]GlobalUnlock(h)
     User32[COLOR="#FF0000"].[/COLOR]SetClipboardData([COLOR="#000000"]15[/COLOR][COLOR="#FF0000"],[/COLOR]h)
     User32[COLOR="#FF0000"].[/COLOR]CloseClipboard()
    [COLOR="#0000FF"]end[/COLOR];

  • #2
    I was asked to convey to you the following code:
    Code:
    [font=Courier New][size=2][color=#008000][i]-- CONST[/i][/color]
    
    DROPEFFECT_COPY [color=#FF0000]=[/color] 1;
    
    DROPEFFECT_MOVE [color=#FF0000]=[/color] 2;
    
     
    
    [color=#008000][i]-- Load library[/i][/color]
    
    Kernel32 [color=#FF0000]=[/color] Library[color=#FF0000].[/color]Load([color=#800080]"kernel32.dll"[/color]);
    
    User32   [color=#FF0000]=[/color] Library[color=#FF0000].[/color]Load([color=#800080]"user32.dll"[/color]);
    
     
    
    Clipboard_PutFile [color=#FF0000]=[/color] [color=#0000FF][b]function[/b][/color] (tFilePaths[color=#FF0000],[/color] cType)
    
        assert(type(tFilePaths) [color=#FF0000]=[/color][color=#FF0000]=[/color] [color=#800080]"table"[/color]);
    
     
    
        cType [color=#FF0000]=[/color] cType [color=#0000FF][b]or[/b][/color] DROPEFFECT_COPY
    
     
    
        [color=#0000FF][b]local[/b][/color] CF_HDROP [color=#FF0000]=[/color] 15;
    
     
    
        [color=#008000][i]-- Open Clipboard[/i][/color]
    
        [color=#0000FF][b]local[/b][/color] CF_PREFERREDDROPEFFECT [color=#FF0000]=[/color] User32[color=#FF0000].[/color]RegisterClipboardFormatA([color=#800080]"Preferred DropEffect"[/color]);
    
        [color=#0000FF][b]local[/b][/color] hClip [color=#FF0000]=[/color] User32[color=#FF0000].[/color]OpenClipboard(Application[color=#FF0000].[/color]GetWndHandle());
    
        User32[color=#FF0000].[/color]EmptyClipboard();
    
     
    
        [color=#008000][i]-- Creates a DROPFILES-structure and fill it[/i][/color]
    
        [color=#0000FF][b]local[/b][/color] DROPFILES [color=#FF0000]=[/color] MemoryEx[color=#FF0000].[/color]DefineStruct[color=#FF0000]{[/color]
    
            DWORD([color=#800080]"pFiles"[/color]);
    
            INT([color=#800080]"pt"[/color][color=#FF0000],[/color] 2);
    
            INT([color=#800080]"fNC"[/color]);
    
            INT([color=#800080]"fWide"[/color]);
    
        [color=#FF0000]}[/color];
    
     
    
        [color=#0000FF][b]local[/b][/color] nStructSize [color=#FF0000]=[/color] MemoryEx[color=#FF0000].[/color]StructSize(DROPFILES);
    
        [color=#0000FF][b]local[/b][/color] hMem [color=#FF0000]=[/color] Kernel32[color=#FF0000].[/color]GlobalAlloc(64[color=#FF0000],[/color] nStructSize [color=#FF0000]+[/color] 2 [color=#FF0000]*[/color] ([color=#FF0000]#[/color]Table[color=#FF0000].[/color]Concat(tFilePaths[color=#FF0000],[/color] [color=#800080]""[/color]) [color=#FF0000]+[/color] 1));
    
     
    
        [color=#0000FF][b]local[/b][/color] tDROPFILES [color=#FF0000]=[/color] MemoryEx[color=#FF0000].[/color]AssignStruct(hMem[color=#FF0000],[/color] DROPFILES);
    
        tDROPFILES[color=#FF0000].[/color]fWide [color=#FF0000]=[/color] 1; tDROPFILES[color=#FF0000].[/color]pFiles [color=#FF0000]=[/color] nStructSize;
    
     
    
        [color=#0000FF][b]local[/b][/color] hPtr [color=#FF0000]=[/color] hMem [color=#FF0000]+[/color] nStructSize;
    
        [color=#0000FF][b]for[/b][/color] i [color=#FF0000]=[/color] 1[color=#FF0000],[/color] [color=#FF0000]#[/color]tFilePaths [color=#0000FF][b]do[/b][/color]
    
            MemoryEx[color=#FF0000].[/color]String(hPtr[color=#FF0000],[/color] [color=#FF0000]-[/color]1[color=#FF0000],[/color] MEMEX_UNICODE[color=#FF0000],[/color] tFilePaths[color=#FF0000][[/color]i[color=#FF0000]][/color][color=#FF0000].[/color][color=#FF0000].[/color][color=#800080]"\0"[/color]);
    
            hPtr [color=#FF0000]=[/color] hPtr [color=#FF0000]+[/color] ([color=#FF0000]#[/color]tFilePaths[color=#FF0000][[/color]i[color=#FF0000]][/color] [color=#FF0000]+[/color] 1) [color=#FF0000]*[/color] 2;
    
        [color=#0000FF][b]end[/b][/color]
    
     
    
        [color=#0000FF][b]local[/b][/color] hMem2 [color=#FF0000]=[/color] Kernel32[color=#FF0000].[/color]GlobalAlloc(64[color=#FF0000],[/color] 4);
    
        MemoryEx[color=#FF0000].[/color]DWORD(hMem2[color=#FF0000],[/color] DROPEFFECT_COPY);
    
     
    
        [color=#008000][i]-- Set Clipboard data[/i][/color]
    
        User32[color=#FF0000].[/color]SetClipboardData(CF_HDROP[color=#FF0000],[/color] hMem);
    
        User32[color=#FF0000].[/color]SetClipboardData(CF_PREFERREDDROPEFFECT[color=#FF0000],[/color] hMem2);
    
     
    
        [color=#008000][i]-- Free[/i][/color]
    
        Kernel32[color=#FF0000].[/color]GlobalFree(hMem2); tDROPFILES[color=#FF0000]:[/color]Close();    Kernel32[color=#FF0000].[/color]GlobalFree(hMem); User32[color=#FF0000].[/color]CloseClipboard();
    
    [color=#0000FF][b]end[/b][/color]
    
     
    
    [color=#008000][i]-- List of files to copy/move[/i][/color]
    
     
    
    [color=#0000FF][b]local[/b][/color] tFiles [color=#FF0000]=[/color] [color=#FF0000]{[/color]_WindowsFolder[color=#FF0000].[/color][color=#FF0000].[/color][color=#800080]"\\regedit.exe"[/color][color=#FF0000],[/color] _SystemFolder[color=#FF0000].[/color][color=#FF0000].[/color][color=#800080]"\\calc.exe"[/color][color=#FF0000]}[/color];
    
     
    
    [color=#008000][i]-- Call[/i][/color]
    
    Clipboard_PutFile(tFiles);
    
     
    
    Kernel32[color=#FF0000]:[/color]Close_();
    
    User32[color=#FF0000]:[/color]Close_();[/size][/font]

    Comment


    • #3
      ssvuia, thank you.

      Comment

      Working...
      X