|
How to inject a dll to exe process
The dll is compiled by vb (stand dll use Create in Visual Basic version 2)
Now i succeed inject it to a process ,but the code in the dll dont execute
my code in dll:
Public Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Public Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Public Const DLL_PROCESS_DETACH = 0
Public Const DLL_PROCESS_ATTACH = 1
Public Const DLL_THREAD_ATTACH = 2
Public Const DLL_THREAD_DETACH = 3
Public Const MB_OK = &H0&
Public Function DllMain(hInst As Long, fdwReason As Long, lpvReserved As Long) As Boolean
Select Case fdwReason
Case DLL_PROCESS_DETACH
Case DLL_PROCESS_ATTACH
DllMain = True
MessageBox 0, CStr(GetCurrentProcessId()), "aaa", MB_OK
Case DLL_THREAD_ATTACH
Case DLL_THREAD_DETACH
End Select
End Function
|
|
|
|
|
yoya0303 wrote: How to inject a dll to exe process
yoya0303 wrote: The dll is compiled by vb (stand dll use Create in Visual Basic version 2)
Which version again?? VB2 is REALLY old! Or are you talking about VB.NET 2002, or 2003, or 2005, or 2008??
yoya0303 wrote: Now i succeed inject it to a process ,but the code in the dll dont execute
VB6 does not support creating .DLL's of the type that are required to support "DLL Injection".
Also, just because you injected the code, doesn't mean that the .EXE knows how to call it. Your code has to hook something to be executed in the .EXE that you injected it into, or it has to be called from an outside source.
|
|
|
|
|
I used VB6 with dll addin plus to compile dll file.
Yes,I called from an outside source.but it dont work.
my dll code:
Public Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Public Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Public Const DLL_PROCESS_DETACH = 0
Public Const DLL_PROCESS_ATTACH = 1
Public Const DLL_THREAD_ATTACH = 2
Public Const DLL_THREAD_DETACH = 3
Public Const MB_OK = &H0&
Public Function DllMain(hInst As Long, fdwReason As Long, lpvReserved As Long) As Boolean
Select Case fdwReason
Case DLL_PROCESS_DETACH
Case DLL_PROCESS_ATTACH
DllMain = True
MessageBox 0, CStr(GetCurrentProcessId()), "aaa", MB_OK
Case DLL_THREAD_ATTACH
MessageBox 0, CStr(GetCurrentProcessId()), "aaa", MB_OK
Case DLL_THREAD_DETACH
End Select
End Function
my ouside code
Public Const PROCESS_VM_READ = &H10
Public Const TH32CS_SNAPPROCESS = &H2
Public Const MEM_COMMIT = 4096
Public Const PAGE_READWRITE = 4
Public Const PROCESS_CREATE_THREAD = (&H2)
Public Const PROCESS_VM_OPERATION = (&H8)
Public Const PROCESS_VM_WRITE = (&H20)
Public Const MB_OK = &H0&
Public Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByVal lpBuffer As String, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Public Declare Function GetLastError Lib "kernel32" () As Long
Public Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
Public Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByVal lpBuffer As String, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Public Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Public Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
Public Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Public Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Public Declare Function CreateRemoteThread Lib "kernel32" (ByVal hProcess As Long, ByVal lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, ByVal lpParameter As Long, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Public Declare Function Process32Next Lib "kernel32" (ByVal hSapshot As Long, lppe As PROCESSENTRY32) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Public Type PROCESSENTRY32
dwSize As Long
cntUseage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
swFlags As Long
szExeFile As String * 1024
End Type
Public Function EnumAndInject(ByVal ProcessName As String, ByVal DllFileName As String) As Boolean
Dim MySnapHandle As Long
Dim ProcessInfo As PROCESSENTRY32
Dim MyRemoteProcessId As Long
Dim MyDllFileLength As Long
Dim MyDllFileBuffer As Long
Dim MyReturn As Long
Dim MyStartAddr As Long
Dim MyResult As Long
Dim temp As Long
MySnapHandle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
ProcessInfo.dwSize = Len(ProcessInfo)
If Process32First(MySnapHandle, ProcessInfo) <> 0 Then
Do
Debug.Print ProcessInfo.szExeFile
If InStr(LCase(ProcessInfo.szExeFile), ProcessName) > 0 Then
MyRemoteProcessId = OpenProcess(PROCESS_CREATE_THREAD + PROCESS_VM_OPERATION + PROCESS_VM_WRITE + PROCESS_VM_READ, False, ProcessInfo.th32ProcessID)
MyDllFileLength = Len(DllFileName) + 1
MyDllFileBuffer = VirtualAllocEx(MyRemoteProcessId, 0, MyDllFileLength, MEM_COMMIT, PAGE_READWRITE)
MyReturn = WriteProcessMemory(MyRemoteProcessId, MyDllFileBuffer, DllFileName, MyDllFileLength, temp)
MyStartAddr = GetProcAddress(GetModuleHandle("Kernel32"), "LoadLibraryA")
MyResult = CreateRemoteThread(MyRemoteProcessId, 0, 0, MyStartAddr, MyDllFileBuffer, 0, temp)
End If
Loop While Process32Next(MySnapHandle, ProcessInfo) <> 0
End If
CloseHandle MySnapHandle
End Function
|
|
|
|
|
OK. I see what you're trying to do, but it's never going to work. VB 6 cannot generate the kind of DLL that is required for "DLL Injection". VB6 can only generate a COM-based DLL, which won't work for you because the required exports are not there. There is no way to "force" VB6 to generate those exports. You'd have to use some other wrapper around your DLL code to get this to work. Don't ask - I don't have any idea if someone has written one - let alone how to use whatever you find.
|
|
|
|
|
Thank you .I'll try to use C++ compile the dll.
|
|
|
|
|
For example i have a query table named (Qsupplier) consist of 3 rows and 5 columns.
EXAMPLE:
Supplier 1 2 3 4
Software Inc. 20000 90
Science Technology Co. Ltd 2000 800 500 80
Book Electronic Co. Ltd 30000 30000 24000 25
1. using the data reader how can i know if how many suppliers are there in the Qsupplier?
Thanks in advance guys.
die_nadel;)
|
|
|
|
|
Look up the COUNT statement, it's SQL to find out how many objects exist based on a query.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
In a DataReader, there is no way to tell how many records it's going to read. It's a forward-only reader that returns rows, one at a time. It doesn't know how many are going to be returned.
Like Christian said, you can execute the same query with a COUNT expression in the SQL statement returning the exact same rows with the same WHERE clause, then execute your DataReader.
Or, you can count the number of rows returned AS they are returned by the DataReader.
Or, scrap the DataReader entirely and use a DataAdapter to fill a DataTable object that will tell you the number of rows it's holding.
|
|
|
|
|
Thanks dave it is clear now that I need to use a dataadapter for this one.
Thanks guys......
|
|
|
|
|
Hello,
I have a class that manages forms (held in a list->collection.generic) running within multiple applications. I provide a different form to allow the user to see all the forms running called "what's running" - clever I know. This form needs to be "topmost" (behaving like a dialogbox). Setting this property does keep this form above any of the running forms but you can still work the forms behind it even though they don't come into focus. So I disabled the running forms which corrected the situation. When my "what's running" form is closed the dispose event reenables all the running forms. The problem is when the last one in the list enables it comes into focus(dotnet disign?) instead of leaving the zorder of all the forms running alone. So -> When "what's running" is visible, form A is directly under "what running". But when I close "what's running" I run through the list reenabling all forms and because form B is last in the list form B is becomes active instead of form A.
Assuming you understand what I'm asking, is there a correction to this behavior or do you have an alternative to the disabling/enabling?
Note: I can't show the form by doing 'showdialog'.
Thanks,
Nathan
|
|
|
|
|
Hi Nathan,
At the risk of sounding like a smart-ass, if your app collects and shows the forms in a certain order, and assuming that form A is the first and form Z the last, could you not simply reverse the order in which you reactivate the forms?
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
Hi Johan,
No worries about being a smart-ass. I thought of that as well. However, normal windows handling says, I might startup a, b ,c but look a, open word, look at c, open excel, look at b open outlook, etc. So your assumption is I never changed the order in which I opened them. Because I'm a multi-tasker, enabling c, b, a doesn't necessarily work because I could of been looking at b when I opened 'what's running' and if I enabled a last then it would be the one I'm looking at. So it's not accurate.
Nathan
|
|
|
|
|
Hi Nathan,
I think I understand the problem, and I am sorry to say that I don't know a direct answer to your original question.
All I dare suggest is, if it really matters which window is activated last, you could consider keeping score. In other words, assuming that you have some sort of list in memory somehow, assign a priority number to each form in the list, and active each form by this number. If you would like the last form that you have looked at to be activated (or by some other rule), you could try to change the number dynamically.
For what it's worth...
Good luck,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
I do samll project in VB.NET and asking the report from sql server. But I dont know how can create the quiry as per my requirment as mentioned below
1 Medical appointment schedulling for one person asking more than one time.
2. report should show the date time as last transaction from transaction table.
3. print the report from current form in one click command
|
|
|
|
|
|
thank you very much for introducing the web site it is more help full for me
|
|
|
|
|
Hello all, I have an attach button that open up so that a user may attach a file on a vb.net form using visual studio 2005. My question is how do I get the window to open up to the desktop to open a file. As of right now it is opening in my debug file. I just need it to open at the desktop first. Thanks a million.
-- modified at 16:06 Thursday 4th October, 2007
|
|
|
|
|
Hi,
if you are using open file dialog you could code this was as shown below:
<br />
OpenFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)<br />
If (OpenFileDialog1.ShowDialog()) Then<br />
Dim strFilename As String<br />
strFilename = OpenFileDialog1.FileName<br />
End If<br />
happy coding...;)
Balaji
|
|
|
|
|
I've been looking all over for the answer to this, and I'm apparently too dense today to implement the various solutions I've found. It seems this should be simple...
I have a config file that looks like this:
KZZZ (City2)|KZZZ-FM|...other values
KQQQ (City1)|KQQQ-AM|...other values
Right now there are only 2 values for each line, but I want the flexibility to add fields in the future. I want to read this file into an Array(ish Collection) and then sort it based on the second column.
Here's the code so far...
' set up needed variables
Dim ConfigFileReader As IO.StreamReader = New IO.StreamReader(My.Settings.DataRoot & My.Settings.StationConfigFileName)
Dim Configline, ConfigFields() As String
Dim ConfigDelimiter() As Char = {Convert.ToChar("|")}
Dim LineCount, FieldCount As Integer
Dim InsertLine As String = Nothing
' read in 1st line
Configline = ConfigFileReader.ReadLine
' parse line, placing each field into StationList array
Do Until Configline = Nothing
ConfigFields = Configline.Split(ConfigDelimiter)
For FieldCount = 0 To UBound(ConfigFields)
StationList(LineCount, FieldCount) = ConfigFields(FieldCount)
Next
' resize array to the right width
ReDim Preserve StationList(999, FieldCount)
' increment counters, read next line
LineCount += 1
FieldCount = 0
Configline = ConfigFileReader.ReadLine
Loop
End Sub
The issues:
I don't like declaring the oversize array (initialized as 999,1). Seems like an ArrayList would be the solution, but I'm not getting how to make a multi-dimensional ArrayList.
I'm apparently too dense today to implement a "sort on the second field" routine.
Thanks for your help!
Scott
|
|
|
|
|
+don't use an arraylist use generic list (of)
+Create a class that implements 'IComparer' this will allow you to specify how you want the list sorted.
'declare the list
Dim oaFuncInfo as new list(of FuncInfo)
'populate the list
Dim oFunc as New FuncInfo
oFunc.sFunc = sFunc
oFunc.sStatus = sStatus
oFunc.sComment = sComment
oaFuncInfos.Add(oFunc)
'sort the list: the reason for the (new funcinfo) is because I am using the same class for the sorting instead of using a different class that implements the icomparer
oaFuncInfos.Sort(New FuncInfo)
'The Class:
Friend Class FuncInfo
Implements IComparer(Of FuncInfo)
Public sFunc As String
Public sStatus As String
Public sComment As String
'define how how want to sort
Public Function Compare(ByVal x As FuncInfo, ByVal y As FuncInfo) As Integer Implements System.Collections.Generic.IComparer(Of FuncInfo).Compare
If x.sFunc < y.sFunc Then
Return -1
ElseIf x.sFunc = y.sFunc Then
Return 0
Else
Return 1
End If
End Function
End Class
|
|
|
|
|
I'm trying to pass multiple DataKeynames after a selection is made in the Gridview, and to view them in a DataList where the selection matches them. Right now it will only display the first selected parameter (jacket).
Here is my code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" Visible="false"
BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" DataKeyNames="jacket, closure, shielding" ForeColor="Black" GridLines="Vertical" Width="750px" OnPageIndexChanging="gridViewPublishers_PageIndexChanging" OnSorting="gridViewPublishers_Sorting"
AllowPaging="True" PageSize="20" AllowSorting="True" PagerSettings-Mode="NumericFirstLast">
<FooterStyle BackColor="#CCCCCC" />
<Columns>
<asp:CommandField ItemStyle-Width="70" ShowSelectButton="True" />
<asp:BoundField ItemStyle-Width="130" DataField="partnumber" HeaderText="Partnumber" ReadOnly="True" SortExpression="partnumber" />
<asp:BoundField ItemStyle-Width="100" DataField="jacket" HeaderText="Jacket" SortExpression="jacket" />
<asp:BoundField ItemStyle-Width="220" DataField="closure" HeaderText="Closure" SortExpression="Closure" />
<asp:BoundField ItemStyle-Width="110" DataField="shape" HeaderText="Shape" SortExpression="shape" />
<asp:BoundField ItemStyle-Width="130" DataField="shielding" HeaderText="Shielding" SortExpression="Shielding" />
</Columns>
<SelectedRowStyle BackColor="#7c7979" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#CCCCCC" />
<PagerSettings Mode="NumericFirstLast" />
</asp:GridView><br /><br />
<asp:DataList ID="DataList1" runat="server" BackColor="#1679d5" BorderColor="#999999"
BorderStyle="Solid" BorderWidth="1px" CellPadding="3"
ForeColor="White" GridLines="Vertical" DataSourceID="SqlDataSource1" Visible="false">
<FooterStyle BackColor="#CCCCCC" />
<SelectedItemStyle BackColor="Blue" Font-Bold="False" ForeColor="White" />
<ItemTemplate>
<table>
<tr>
<td style="width:120px; font-weight:bold;">
<asp:Label ID="materialLabel" runat="server" Text='<%# Eval("material") %>' />
</td>
<td style="width:450px;">
<asp:Label ID="Label" runat="server" TabIndex="1" Text='<%# Eval("marketing_tagline") %>' />
</td>
<td style="width:150px; text-align:center;">
<div class="SearchDataLink">
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("material", "dataSheet.aspx?id={0}") %>' TabIndex="2" Target="_blank" Text="View datasheet" />
</div>
</td>
</tr>
</table>
</ItemTemplate>
<AlternatingItemStyle BorderWidth="1" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ZippertubingConnectionString %>" SelectCommand="SELECT * FROM [ProductVerbage] WHERE ([material] = @jacket) OR ([material] = @closure) OR ([material] = @shielding) " >
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="jacket" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="GridView1" Name="closure" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="GridView1" Name="shielding" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
|
|
|
|
|
This question belongs in the ASP.NET forum. It's got nothing to do with VB.NET.
|
|
|
|
|
I Need A Complete Article About SMO .
Plz Help me.
|
|
|
|
|
Google for "SMO" and see what you get.
|
|
|
|
|
Hi everyone,
In the ASP page, I store the output (in the form of html strings) from the rich-text editor in a database; when time comes, I retrieve the required HTML string (I use VB as a server-side language) (htmlCode variable.) The I wish to pass this htmlCode to some JavaScript function:
<body onload="populateWithHTML('<%=htmlCode%>')">
BUT! Here is the problem. This html string can contain " (quote) and ' (apostrophe) symbols, that break the resulting HTML.
How should I fix this? Thank you much in advance!
-------------------------
Listen up! "Teamwork" means staying out of my way! (Seifer, Final Fantasy 8).
|
|
|
|
|