Announcement

Collapse
No announcement yet.

Help with some C code to PB

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

  • Help with some C code to PB

    First of all, i'm not sure if i'm allowed to make posts that aren't
    directly related to PB, forgive me and ignore me if this is so..

    --
    I'm converting some C code to PB..

    The full code can be found here http://www.mvps.org/win32/ntfs/dump_ntfs_streams.cpp

    I'm stuck on one line

    WIN32_STREAM_ID & wsi = *( (WIN32_STREAM_ID *) buf );

    What would be the define in PB? You'll probably need to look at the URL
    of the full code to understand what the variables are.

    Thanks for any help.

  • #2
    hi nathan

    this code has already been translated to powerbasic - have a look
    at this thread: http://www.powerbasic.com/support/pb...ead.php?t=3628

    cheers

    florent

    ------------------

    Comment


    • #3
      Ahh, great! Thanks mate

      Just a few alterations to make it a PBDLL and it's done.

      Thanks very much!

      - Nathan.

      Comment


      • #4
        I've found a handle leak in the following sub. Each time this sub
        is run, the handle count of the process increments by 1, and isn't freed.

        I know this can be easily fixed, and made more efficient, if i just
        call it once, say when the program starts up.. But i'm just wondering
        if the Handle has to be left open..

        Happy 4th to all the yanks here

        - Nathan

        Code:
        FUNCTION enableprivs() AS LONG
            LOCAL hToken AS LONG
            LOCAL tToken AS T_TOKEN_PRIVILEGES
        
            tToken.Privileges = HeapAlloc( GetProcessHeap(), %HEAP_ZERO_MEMORY, LEN(LUID_AND_ATTRIBUTES) * 2)
            IF tToken.Privileges = %NULL THEN
                FUNCTION = %NULL
                EXIT FUNCTION
            END IF
        
            DIM tLuid(0:1) AS LUID_AND_ATTRIBUTES AT tToken.Privileges
        
            IF ISFALSE( OpenProcessToken( GetCurrentProcess(), _
                                            %TOKEN_ADJUST_PRIVILEGES OR %TOKEN_QUERY, _
                                            hToken ) )  THEN
                FUNCTION = %FALSE
                GOTO Clean_Up
            END IF
        
            ' enable SeBackupPrivilege, SeRestorePrivilege
            IF ISFALSE( LookUpPrivilegeValue( BYVAL %NULL, $SE_BACKUP_NAME, BYVAL VARPTR(tLuid(0)) ) ) THEN
                FUNCTION = %FALSE
                GOTO Clean_Up
            END IF
        
            IF ISFALSE( LookUpPrivilegeValue( BYVAL %NULL, $SE_RESTORE_NAME, BYVAL VARPTR(tLuid(1)) ) ) THEN
                FUNCTION = %FALSE
                GOTO Clean_Up
            END IF
        
            tToken.PrivilegeCount = 2
            tLuid(0).Attributes = %SE_PRIVILEGE_ENABLED
            tLuid(1).Attributes = %SE_PRIVILEGE_ENABLED
        
            FUNCTION = AdjustTokenPrivileges( hToken, %FALSE, BYVAL VARPTR(tToken), 4 + (LEN(LUID_AND_ATTRIBUTES) * 2), _
                                                BYVAL %NULL, BYVAL %NULL )
        Clean_Up:
            CALL HeapFree( GetProcessHeap(), 0, BYVAL tToken.Privileges )
        
        END FUNCTION

        Comment


        • #5
          I gather hToken is a token handle. Probably, it should be closed before the function exits.

          ------------------
          Tom Hanlin
          PowerBASIC Staff

          Comment


          • #6
            Thanks Tom!

            I used CloseHandle on the hToken.

            I'm only going to call that function once, at the very start of the program.
            Otherwise it would be alot of overhead.

            Thank again.

            - Nathan.

            ------------------

            Comment


            • #7
              Hi Nathan

              typically OpenProcessToken() would only be called once in this
              case and would then be cleaned up at the program's end however
              it's good practice to always clean up open resources when
              you're done Good catch.

              Cheers

              Florent

              ------------------

              Comment

              Working...
              X