pub unsafe fn run_shellcode(file_name: CString, offset: i64) -> (LPVOID, u32) {
    let file: HANDLE = CreateFileA(
        file_name.as_ptr(),
        GENERIC_READ,
        0,
        null_mut(),
        OPEN_EXISTING,
        FILE_ATTRIBUTE_NORMAL,
        null_mut(),
    );
    if file == INVALID_HANDLE_VALUE {
        println!("[!!] Error trying to open shellcode file...");
        return (null_mut(), 0);
    }
    let file_size: DWORD = GetFileSize(file, null_mut());
    if offset > file_size as i64 {
        println!("[!!] Offset can not be greater than file size...");
        return (null_mut(), 0);
    }
    let buffer: LPVOID = VirtualAlloc(
        null_mut(),
        file_size as usize,
        MEM_COMMIT | MEM_RESERVE,
        PAGE_EXECUTE_READWRITE,
    );

    if buffer == null_mut() {
        CloseHandle(file);
        println!("[!!] Error trying to allocate buffer...");
        return (null_mut(), 0);
    }

    if ReadFile(file, buffer, file_size, null_mut(), null_mut()) == 0 {
        CloseHandle(file);
        VirtualFree(buffer, file_size as usize, MEM_RELEASE);
        println!("[!!] Error trying to read data into buffer...");
        return (null_mut(), 0);
    }


    println!("[x] Allocate successfully!");
    println!("[x] Memory base: 0x{:x}", buffer as u64);
    println!("[x] Offset: 0x{:x}", offset);
    println!("[x] Entry point: 0x{:x}", buffer as i64 + offset);

    CloseHandle(file);
    return (buffer, file_size);
}
// Make sure to VirtualFree this return value
Make sure to VirtualFree this return value
Make sure to VirtualFree this return value
pub unsafe fn run_shellcode(file_name: CString, offset: i64) -> (LPVOID, u32) {
    let file: HANDLE = CreateFileA(
        file_name.as_ptr(),
        GENERIC_READ,
        0,
        null_mut(),
        OPEN_EXISTING,
        FILE_ATTRIBUTE_NORMAL,
        null_mut(),
    );
    if file == INVALID_HANDLE_VALUE {
        println!("[!!] Error trying to open shellcode file...");
        return (null_mut(), 0);
    }
    let file_size: DWORD = GetFileSize(file, null_mut());
    if offset > file_size as i64 {
        println!("[!!] Offset can not be greater than file size...");
        return (null_mut(), 0);
    }
    let buffer: LPVOID = VirtualAlloc(
        null_mut(),
        file_size as usize,
        MEM_COMMIT | MEM_RESERVE,
        PAGE_EXECUTE_READWRITE,
    );
    if buffer == null_mut() {
        CloseHandle(file);
        println!("[!!] Error trying to allocate buffer...");
        return (null_mut(), 0);
    }
    if ReadFile(file, buffer, file_size, null_mut(), null_mut()) == 0 {
        CloseHandle(file);
        VirtualFree(buffer, file_size as usize, MEM_RELEASE);
        println!("[!!] Error trying to read data into buffer...");
        return (null_mut(), 0);
    }
    println!("[x] Allocate successfully!");
    println!("[x] Memory base: 0x{:x}", buffer as u64);
    println!("[x] Offset: 0x{:x}", offset);
    println!("[x] Entry point: 0x{:x}", buffer as i64 + offset);
    CloseHandle(file);
    return (buffer, file_size);
}
pub unsafe fn run_shellcode ( file_name : CString , offset : i64 ) -> ( LPVOID , u32 ) { let file : HANDLE = CreateFileA ( file_name . as_ptr ( ) , GENERIC_READ , 0 , null_mut ( ) , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , null_mut ( ) , ) ; if file == INVALID_HANDLE_VALUE { println ! ( " " ) ; return ( null_mut ( ) , 0 ) ; } let file_size : DWORD = GetFileSize ( file , null_mut ( ) ) ; if offset > file_size as i64 { println ! ( " " ) ; return ( null_mut ( ) , 0 ) ; } let buffer : LPVOID = VirtualAlloc ( null_mut ( ) , file_size as usize , MEM_COMMIT | MEM_RESERVE , PAGE_EXECUTE_READWRITE , ) ; if buffer == null_mut ( ) { CloseHandle ( file ) ; println ! ( " " ) ; return ( null_mut ( ) , 0 ) ; } if ReadFile ( file , buffer , file_size , null_mut ( ) , null_mut ( ) ) == 0 { CloseHandle ( file ) ; VirtualFree ( buffer , file_size as usize , MEM_RELEASE ) ; println ! ( " " ) ; return ( null_mut ( ) , 0 ) ; } println ! ( " " ) ; println ! ( " " buffer as u64 ) ; println ! ( " " offset ) ; println ! ( " " buffer as i64 offset ) ; CloseHandle ( file ) ; return ( buffer , file_size ) ; }
Make sure to VirtualFree this return value
Make sure to VirtualFree this return value
file_name
CString
offset
i64
file_name
CString
offset
i64