Git Product home page Git Product logo

Comments (3)

lars18th avatar lars18th commented on June 16, 2024

Hi,

Good news! I've prepared a simple patch that almost works with nvenc. Here my dirty patch:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5fa8620..aa75df1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,7 +16,8 @@ project(nvlax CXX)
 include(ExternalProject)
 include(cmake/FetchCPM.cmake)

-CPMAddPackage("gh:zyantific/zydis#master")
+#CPMAddPackage("gh:zyantific/zydis#master")
+CPMAddPackage("gh:zyantific/zydis#55dd08c210722aed81b38132f5fd4a04ec1943b5")

 CPMAddPackage(
         NAME LIEF_SRC
diff --git a/src/lax_encode.cc b/src/lax_encode.cc
index 0967a6c..64b194c 100644
--- a/src/lax_encode.cc
+++ b/src/lax_encode.cc
@@ -28,7 +28,10 @@ patch_linux (LIEF::ELF::Binary *bin)
 {
     using namespace LIEF::ELF;

-    PPK_ASSERT_ERROR(bin->imported_libraries().at(0) == "libnvcuvid.so.1");
+//    In WSL2 we can't use this to check the library binary.
+//    The "libnvcuvid.so.1" is no listed with the 'ldd' command,
+//    but it works 'strings /usr/lib/wsl/lib/libnvidia-encode.so.1 | grep libnvcuvid.so.1'
+//    PPK_ASSERT_ERROR(bin->imported_libraries().at(0) == "libnvcuvid.so.1");

     std::cout << "[+] libnvidia-encode.so\n";

@@ -67,6 +70,7 @@ patch_linux (LIEF::ELF::Binary *bin)
     }

     PPK_ASSERT_ERROR(found);
+    std::cout << "[+] Section 1 OK\n";
     found = false;

     {
@@ -83,7 +87,7 @@ patch_linux (LIEF::ELF::Binary *bin)
             if (instr.mnemonic == ZYDIS_MNEMONIC_TEST &&
                 instr.operands[0].reg.value == ZYDIS_REGISTER_EAX &&
                 instr.operands[1].reg.value == ZYDIS_REGISTER_EAX &&
-                (++n) > 1)
+                (++n) > 0)
             {
                 offset += (data - v_func_bytes.data());
                 found = true;
@@ -96,6 +100,7 @@ patch_linux (LIEF::ELF::Binary *bin)
     }

     PPK_ASSERT_ERROR(found);
+    std::cout << "[+] Section 2 OK\n";

     // test eax, eax -> xor eax, eax
     bin->patch_address(offset, 0x31, 0x1);

Feel free to add it to the repository! You only need to add some parameter to enable for WSL.
Regards.

from nvlax.

lars18th avatar lars18th commented on June 16, 2024

Hi,

My updated patch to apply the last fixes from @tytan652:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5fa8620..a013971 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,11 +16,13 @@ project(nvlax CXX)
 include(ExternalProject)
 include(cmake/FetchCPM.cmake)

-CPMAddPackage("gh:zyantific/zydis#master")
+#CPMAddPackage("gh:zyantific/zydis#master")
+CPMAddPackage("gh:zyantific/zydis#55dd08c210722aed81b38132f5fd4a04ec1943b5")

 CPMAddPackage(
         NAME LIEF_SRC
-        GIT_TAG master
+#       GIT_TAG master
+        GIT_TAG b65e7cca03ec4cd91f1d7125e717d01635ea81ba
         GITHUB_REPOSITORY lief-project/LIEF
         DOWNLOAD_ONLY YES
 )
@@ -59,7 +61,8 @@ message(STATUS "LIEF library: ${LIEF_LIBRARIES}")

 CPMAddPackage(
         NAME PPK_ASSERT
-        GIT_TAG master
+#       GIT_TAG master
+        GIT_TAG 833b8b7ea49aea540a49f07ad08bf0bae1faac32
         GITHUB_REPOSITORY gpakosz/PPK_ASSERT
         DOWNLOAD_ONLY YES
 )
diff --git a/src/lax_encode.cc b/src/lax_encode.cc
index 0967a6c..64b194c 100644
--- a/src/lax_encode.cc
+++ b/src/lax_encode.cc
@@ -28,7 +28,10 @@ patch_linux (LIEF::ELF::Binary *bin)
 {
     using namespace LIEF::ELF;

-    PPK_ASSERT_ERROR(bin->imported_libraries().at(0) == "libnvcuvid.so.1");
+//    In WSL2 we can't use this to check the library binary.
+//    The "libnvcuvid.so.1" is no listed with the 'ldd' command,
+//    but it works 'strings /usr/lib/wsl/lib/libnvidia-encode.so.1 | grep libnvcuvid.so.1'
+//    PPK_ASSERT_ERROR(bin->imported_libraries().at(0) == "libnvcuvid.so.1");

     std::cout << "[+] libnvidia-encode.so\n";

@@ -67,6 +70,7 @@ patch_linux (LIEF::ELF::Binary *bin)
     }

     PPK_ASSERT_ERROR(found);
+    std::cout << "[+] Section 1 OK\n";
     found = false;

     {
@@ -83,7 +87,7 @@ patch_linux (LIEF::ELF::Binary *bin)
             if (instr.mnemonic == ZYDIS_MNEMONIC_TEST &&
                 instr.operands[0].reg.value == ZYDIS_REGISTER_EAX &&

And I confirm that with a recent (Jun'23) driver like 515.65.01 it works in WSL2 with Win10 22H2 (without patching at all the stock Windows driver).

from nvlax.

ImVexed avatar ImVexed commented on June 16, 2024

@lars18th Did you cut off the last few lines of that git patch? It's complaining about being corrupt.

from nvlax.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.