I am writing a small C# program that reads an exectuable files imports into a list. I am having a program with this method:
More specifically the error is "Object reference not set to an instance of an object."
I am attaching all the code to bottom in case it helps.
Thanks for any help.
Regards,
Max_Power
EDIT: Added attachment.
Code:
public void ListImports(ListBox lstList, int hMod)
{
IMAGE_DOS_HEADER idhDosHeader = new IMAGE_DOS_HEADER();
IMAGE_NT_HEADERS inhNtHeaders = new IMAGE_NT_HEADERS();
IMAGE_IMPORT_DESCRIPTOR iidImportDesc = new IMAGE_IMPORT_DESCRIPTOR();
int intImportDesc;
Marshal.PtrToStructure(new IntPtr(hMod), idhDosHeader);
Marshal.PtrToStructure(new IntPtr(hMod + idhDosHeader.e_lfanew), inhNtHeaders);
if (inhNtHeaders.OptionalHeader.DataDirectory0.VirtualAddress == 0)
return;
intImportDesc = hMod + inhNtHeaders.OptionalHeader.DataDirectory0.VirtualAddress;
Marshal.PtrToStructure(new IntPtr(intImportDesc), iidImportDesc);
do
{
///////////////////////////////////////////
//ERRORS HERE
///////////////////////////////////////////
MessageBox.Show(Marshal.PtrToStringAnsi(new IntPtr(hMod + iidImportDesc.Name)));
intImportDesc += Marshal.SizeOf(iidImportDesc);
Marshal.PtrToStructure(new IntPtr(intImportDesc), iidImportDesc);
} while(iidImportDesc.Name != 0);
}//End ListImports
More specifically the error is "Object reference not set to an instance of an object."
I am attaching all the code to bottom in case it helps.
Thanks for any help.
Regards,
Max_Power
EDIT: Added attachment.