Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Help with using Kernel32.dll in C# for DLL injection

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Arko
How do I cheat?
Reputation: 0

Joined: 16 Feb 2015
Posts: 3

PostPosted: Mon Feb 16, 2015 4:05 pm    Post subject: Help with using Kernel32.dll in C# for DLL injection Reply with quote

I am trying to make a DLL injector for my project using C# but I have run into an issue when trying to use the Kernel32.dll inside of C#, the problem I am having is I don't know how to. I have googled about this issue and have found examples but they aren't explained or give any information on how they do it. What I am trying to do is inject a DLL into another process using C#.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 156

Joined: 25 Jan 2006
Posts: 8001
Location: 127.0.0.1

PostPosted: Mon Feb 16, 2015 6:06 pm    Post subject: Reply with quote

Use DllImport to handle the importing of the needed API, like this:
Code:
        /// <summary>
        /// kernel32!GetProcAddress
        /// </summary>
        /// <param name="hModule"></param>
        /// <param name="procName"></param>
        /// <returns></returns>
        [DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
        public static extern IntPtr GetProcAddress(
            IntPtr hModule,
            string procName
            );

        /// <summary>
        /// kernel32!LoadLibraryA
        /// </summary>
        /// <param name="lpFileName"></param>
        /// <returns></returns>
        [DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
        public static extern IntPtr LoadLibraryA(
            string lpFileName
            );

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Arko
How do I cheat?
Reputation: 0

Joined: 16 Feb 2015
Posts: 3

PostPosted: Mon Feb 16, 2015 6:43 pm    Post subject: Reply with quote

atom0s wrote:
Use DllImport to handle the importing of the needed API, like this:
Code:
        /// <summary>
        /// kernel32!GetProcAddress
        /// </summary>
        /// <param name="hModule"></param>
        /// <param name="procName"></param>
        /// <returns></returns>
        [DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
        public static extern IntPtr GetProcAddress(
            IntPtr hModule,
            string procName
            );

        /// <summary>
        /// kernel32!LoadLibraryA
        /// </summary>
        /// <param name="lpFileName"></param>
        /// <returns></returns>
        [DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
        public static extern IntPtr LoadLibraryA(
            string lpFileName
            );


Could you tell me how I would get the API from Kernel32? Like the method and such
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 156

Joined: 25 Jan 2006
Posts: 8001
Location: 127.0.0.1

PostPosted: Mon Feb 16, 2015 8:00 pm    Post subject: Reply with quote

pinvoke's website has nearly all of the Win32 API done here:
http://www.pinvoke.net/

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Arko
How do I cheat?
Reputation: 0

Joined: 16 Feb 2015
Posts: 3

PostPosted: Tue Feb 17, 2015 1:26 pm    Post subject: Reply with quote

Thanks for the help.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites