New Programming Tech. -Combine VB with MASM- ÿþ--------------------------------------------------------------------------------- | SUBJECT: New Programming Technique -Combine VB with MASM- | --------------------------------------------------------------------------------- | Author : theFOX(r) | --------------------------------------------------------------------------------- | LEVEL : Intermediate | --------------------------------------------------------------------------------- Introduction ************* You learned more than one language? if Yes, then didn't you think of using them together? In this tutorial we are going to learn a new programming technique -not so new- which you can use in making your own trainers. Before processing with this tutorial you will have to know how to find your address using whatever tool you have. 0.About the Technique ---------------------- This technique is very good and flexible as it has the following advantages: 1. You can use more than one language in it. 2. It makes you able to make a good small GUI apps. 3. You can use it to protect your own program against cracking -against unprofessional crackers- 4. You can make a template and use it with all your trainers. 0.Tools that we need --------------------- 1. Any win32 ASM programming tool -I use masm32- 2. MSVisualBasic 6.0 -if you need it in VC++ just tell me- 3. As this tuto is for VB then you will have to use the built in Resource Editor that comes with VB. 4. 'Progtest.exe' for testing your trainer. 5. A mind! The beginning ************** Open 'progtest.exe' and find the address for the bar value it should be 0x123456789 now open masm32 'QEditor' and paste the following codes into it: --------------------------- .486 .model flat, stdcall ;32 bit memory model option casemap :none ;case sensitive include windows.inc include masm32.inc include kernel32.inc include user32.inc includelib masm32.lib includelib kernel32.lib includelib user32.lib Poke PROTO :DWORD,:DWORD,:BYTE .Const wndName db "progtest",0 add1 equ 59D5B9h val1 db 090h, 090h, 090h, 090h, 090h, 090h size1 equ 6 .code start: invoke Poke,offset add1,offset val1,offset size1 Poke PROC aHack:DWORD, nVal:DWORD, iSize:BYTE LOCAL phandle :DWORD LOCAL pid :DWORD LOCAL windhand :DWORD Invoke FindWindow, NULL, addr wndName mov windhand,eax Invoke GetWindowThreadProcessId, windhand, addr pid Invoke OpenProcess,PROCESS_ALL_ACCESS, 0, pid mov phandle,eax invoke WriteProcessMemory,phandle, aHack, nVal, iSize, NULL ret Poke ENDP end start --------------------------- Now goto 'Project>>>Build All' menu to compile & link your ASM file and make'BarFreezer.exe' The real work ************** Now after finishing making your -semi- trainer we reached the hard work point which need your mind and your hands. 0.Preparing your resource -------------------------- 1. Open VisualBasic and Start a new 'Standard Exe' Project. 2. Goto 'Add-Ins>>>Add-In Manager' then select 'VB6 Resource Editor' from the list. 3. In the same window check the checkbox entitled 'Loaded/Unloaded' then click 'OK' 4. You should now see the 'VB Resource Editor -' window. 5. In the 'VB6 Resource Editor' window click on the 'Add Custom Resource..." icon. 6. Now, Select your 'BarFreezer.exe" then click 'Open'. 7. After the custom resource appears on the resource editor window with the ID 101, RClick on it and select 'Properties'. 8. Change the Resource Type to 'EXE' and the ID to 'BarFreezer' 9. Now, click 'Save' -the samll disk in the Resource Editor window- 10. Make sure there is no '(Modified)' word appears on the status bar of the window. 0.Load Resource Data: --------------------- Ok, now lets see what we have here: 1. A compiled resource file contains our 'BarFreezer.exe' 2. VisualBasic 6.0 mmmm, Did you guessed what are we going to do? Well, we are going to make a little code that will read the 'EXE' resource from the program -your trainer- and then launch it. OK, lets start coding The main function that we will need is combined from the API's : FindResource, LoadResource, LockResource....etc. This function is built in VB and is called LoadResData and it's used to get the Binary Data from the resource of our project. --------------------------- Syntax: LoadResData(ID as Any, Type as String) and you must know that the ID could be a String or an Integer. --------------------------- Now, lets see how to load our resource data into a variable, but wait what type of variables we should use? Well, first you should understand how does this function work. Any Binary resource is stored in Hexadecimal mode, which means that any resource except for Strings is stored in Hexadecimal mode. So Custom resources will be stored in Hexadecimal mode as well. Ok, now return to our question about loading our resource data. To load any resource except for Strings you will have to use a BYTE array! e.g. You want to load the 'WAVE' resource with the ID '1001' : --------------------------- Dim resData() as Byte resData() = LoadResData(101,"WAVE") --------------------------- And the same for any Custom resource. In our tutorial we want to load the 'EXE' resource with the ID 'BarFreezer'. So we will use the following code: --------------------------- Dim resData() as Byte resData() = LoadResData("BARFREEZER","EXE") --------------------------- 0.Dump Resource Data: --------------------- until mow we did the following : 1. Make our resource file. 2. Loaded it's data to the 'resData()' bArray So, what to do next? Oh yes, Launching our resData(). And to do that we must first dump our data to a file. and to do that we will need to Open a file, then Dump the Data, then Close the file, and of course we will open an EXE file and assign a number to it. There are two ways to dump your binary data, one of them is to open the file as Binary and set Access Write, and the other one with I will use here is to Open your file as an output file but you will have to do some modifications on our resData() -That's why I'm going to use this, as most coders do miss this part- ------------------------------------------------------- 1 Dim FileNumber as Integer 2 FileNumber = FreeFile 3 open "BarFreezer.exe" For Output As FileNumber 4 Print #FileNumber, strConv(strData(),64); 5 Close #FileNumber ------------------------------------------------------- Here is what we did in that code: Line 1: We make an Integer Variable to put the file number in it. Line 2: We make a random file number and assign it to the variable. Line 3: We opened our destination file where we are going to dump our resData() into. Line 4: We printed our data after being converted, and what type of converting is this? We converted our Byte array to a Uni-Code string data so as not to miss any non-ascii char. Note: the ";" is very important so as not to add a new line at the end of the file. Line 5: We closed our file. 0.Launching our Data: --------------------- Ok, now after dumping our file into 'BarFreezer.exe' we need to launch it. So we will use our normal Shell function as the following: -------------------------- Shell "BarFreezer.exe",1 -------------------------- I hear one of you is saying: "but what are we going to do with the dumped file after it has been launched and finished it's work?" I will tell you, We need to delete it. I hear another one is saying: "but what if the 'Barfreezer.exe' was still runing while we are trying to delete it, that will cause a RunTime error, won't it?" Well, actually we are not going to delete our 'Barfreezer.exe' while it's running, I mean that we will wait it to finish all it work then we will Kill it. And we will do that using a very useful API function called 'WaitForSingleObject': --------------------------- Syntax: WaitForSingleObject( hHandle As Long, dwMilliseconds As Long) As Long --------------------------- So as you can see we will need to get the handle of our 'BarFreezer.exe', and that's why we will need to use 'OpenProcess' API Function: --------------------------- Syntax: OpenProcess( dwDesiredAccess As Long, bInheritHandle As Long, dwProcessId As Long) As Long --------------------------- And of course as we used OpenProcess to open an Handle we will use CloseHandle to close it! --------------------------- Syntax: CloseHandle( hObject As Long) As Long --------------------------- And that's how we will use them: --------------------------- 1 Dim pID As Long 2 Dim pHandle As Long 3 Dim retLng As Long 4 pID = Shell("C:\BarFreezer.exe", 1) 5 pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pID) 6 retLng = WaitForSingleObject(pHandle, -1&) 7 retLng = CloseHandle(pHandle) 8 Kill "C:\barfreezer.exe" --------------------------- some explanation: Line 5: We set the Access mode to 'Process_All_Access' which equal '&H1F0FFF'. You can also use 'SYNCHRONIZE' which equals '&H100000' but its for NT/2000/XP only Line 6: We assigned a '-1' to the dwMilliseconds parameter so as to wait and wait and wait..... Line 8: You are a damn killer, you killed our 'BarFreezer.exe', hehe Now, prepare your form and add some buttons graphics... etc and make your trainer. Your code should look something like that: --------------------------- Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Const SYNCHRONIZE = &H100000 Private Sub Command1_Click() Dim resData() as Byte resData() = LoadResData("BARFREEZER","EXE") Dim FileNumber As Integer FileNumber = FreeFile open "C:\BarFreezer.exe" For Output As FileNumber Print #FileNumber, strConv(strData(),64); Close #FileNumber Dim pID As Long Dim pHandle As Long Dim retLng As Long pID = Shell("C:\BarFreezer.exe", 1) pHandle = OpenProcess(SYNCHRONIZE, False, pID) retLng = WaitForSingleObject(pHandle, -1&) retLng = CloseHandle(pHandle) Kill "C:\barfreezer.exe" End Sub --------------------------- Final Words ************ Now, after you finished the tutorial, You must try doing it by yourself without looking here. You can notice that I show you how to think before writing your code and that's the hard thing in programming, as you can write codes using whatever tool you use but if you don't know how to think in your code so no tool would be useful for you. an e.g. for that "You said that you can drive a car, I asked you can you drive FIAT? , you answered no I can drive only FORD!" could that be possible?, I think no, as driving is driving you should only know how to use the car. The same for programming. This technique is good as you can see you limited your codes, and also your compiled files will be small and have a lot of Null spaces that could be compressed to quite reduce the file size. For more information or any questions post it in the form. I hope that you learned something from this tutorial, I don't spend my time writing it for nothing ;) greets to all extalia memebers. All rights reserved to theFOX(r) m_spiderhack@hotmail.com