Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Can we find address of a winAPI without using GetProcAddress?

Can we find address of a winAPI without using GetProcAddress?

Scheduled Pinned Locked Moved C / C++ / MFC
jsonquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GNUlihd
    wrote on last edited by
    #1

    Hi, Can we get the address of a winAPI (from Advapi32.dll) without using GetProcAddress or IAT scan? Is it possible? Basically, I want to obfuscate the api call in source code level. Thanks, GNU:lihd

    H S 2 Replies Last reply
    0
    • G GNUlihd

      Hi, Can we get the address of a winAPI (from Advapi32.dll) without using GetProcAddress or IAT scan? Is it possible? Basically, I want to obfuscate the api call in source code level. Thanks, GNU:lihd

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      But why you dont want to use GetProcAddress?


      WhiteSky


      G 1 Reply Last reply
      0
      • G GNUlihd

        Hi, Can we get the address of a winAPI (from Advapi32.dll) without using GetProcAddress or IAT scan? Is it possible? Basically, I want to obfuscate the api call in source code level. Thanks, GNU:lihd

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #3

        Yes. This code should point you in the right direction. It outputs the names of all the functions exported by name from "Kernel32.dll":

        // Console.cpp : Defines the entry point for the console application.
        //
         
        #include "stdafx.h"
        #include <iostream>
        #include <windows.h>
         
        LPVOID PrintFunctions(HMODULE hMod)
        {
        // Find the DOS header.
        PIMAGE_DOS_HEADER pDOS = (PIMAGE_DOS_HEADER)hMod;
         
        // Find the address of the "new" header.
        PIMAGE_NT_HEADERS pNew = (PIMAGE_NT_HEADERS)((char*)pDOS+pDOS->e_lfanew);
         
        // Find the address of the "optional" header.
        PIMAGE_OPTIONAL_HEADER pOpt = &(pNew->OptionalHeader);
         
        // Now find the export table.
        PIMAGE_EXPORT_DIRECTORY pExport =
        (PIMAGE_EXPORT_DIRECTORY)((char*)pDOS+pOpt->DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress);
         
        // Write out all the exported names.
        UINT_PTR *pNameArray = (UINT_PTR*)((char*)pDOS+pExport->AddressOfNames);
        for (DWORD i=0; i<pExport->NumberOfNames; ++i)
        {
        LPCSTR pName = (LPCSTR)((char*)pDOS+pNameArray[i]);
        std::cout << pName << std::endl;
        }
         
        return NULL;
        }
         
        int main(int arvc, char* argv[])
        {
        HMODULE hMod = GetModuleHandle("kernel32.dll");
        PrintFunctions(hMod);
         
        return 0;
        }

        Steve

        T 1 Reply Last reply
        0
        • H Hamid Taebi

          But why you dont want to use GetProcAddress?


          WhiteSky


          G Offline
          G Offline
          GNUlihd
          wrote on last edited by
          #4

          to obfuscate the api call in source code level. If i can find the procAddress then i will obfuscate using assembly call and api redirections so that it would be harder to find out which API is being called (looking at the source).

          1 Reply Last reply
          0
          • S Stephen Hewitt

            Yes. This code should point you in the right direction. It outputs the names of all the functions exported by name from "Kernel32.dll":

            // Console.cpp : Defines the entry point for the console application.
            //
             
            #include "stdafx.h"
            #include <iostream>
            #include <windows.h>
             
            LPVOID PrintFunctions(HMODULE hMod)
            {
            // Find the DOS header.
            PIMAGE_DOS_HEADER pDOS = (PIMAGE_DOS_HEADER)hMod;
             
            // Find the address of the "new" header.
            PIMAGE_NT_HEADERS pNew = (PIMAGE_NT_HEADERS)((char*)pDOS+pDOS->e_lfanew);
             
            // Find the address of the "optional" header.
            PIMAGE_OPTIONAL_HEADER pOpt = &(pNew->OptionalHeader);
             
            // Now find the export table.
            PIMAGE_EXPORT_DIRECTORY pExport =
            (PIMAGE_EXPORT_DIRECTORY)((char*)pDOS+pOpt->DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress);
             
            // Write out all the exported names.
            UINT_PTR *pNameArray = (UINT_PTR*)((char*)pDOS+pExport->AddressOfNames);
            for (DWORD i=0; i<pExport->NumberOfNames; ++i)
            {
            LPCSTR pName = (LPCSTR)((char*)pDOS+pNameArray[i]);
            std::cout << pName << std::endl;
            }
             
            return NULL;
            }
             
            int main(int arvc, char* argv[])
            {
            HMODULE hMod = GetModuleHandle("kernel32.dll");
            PrintFunctions(hMod);
             
            return 0;
            }

            Steve

            T Offline
            T Offline
            tom groezer
            wrote on last edited by
            #5

            Hi, Where I could learn this kind of learning. Please point me to the right guides to do kernel/system programming?

            S 1 Reply Last reply
            0
            • T tom groezer

              Hi, Where I could learn this kind of learning. Please point me to the right guides to do kernel/system programming?

              S Offline
              S Offline
              Stephen Hewitt
              wrote on last edited by
              #6

              To learn to understand the code I posted try these resources:   - Microsoft Portable Executable and Common Object File Format Specification[^]   - And this Google search[^].

              Steve

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups