Exemple #1
0
int __declspec(dllexport) install(struct unit *unit, char *opts) {
  char *modfn = opts;
  struct ndis_driver *driver;
  struct ndis_adapter *adapter;
  hmodule_t hmod;
  int rc;
  ndis_status open_status;
  ndis_status status;
  enum ndis_medium media;
  unsigned int selected_index;

  kprintf("ndis: loading driver %s for unit %08X\n", opts, unit->unitcode);

  // Try to find existing driver
  driver = NULL;
  hmod = getmodule(modfn);
  if (hmod) {
    driver = drivers;
    while (driver) {
      if (driver->hmod == hmod) break;
      driver = driver->next;
    }
  }

  // If driver not loaded, load it now and initialize
  if (!driver) {
    int (__stdcall *entry)(struct ndis_driver *driver, void *reserved);

    hmod = load(modfn, MODLOAD_NOINIT);
    if (!hmod) return -ENOEXEC;

    entry = getentrypoint(hmod);
    if (!entry) return -ENOEXEC;

    driver = kmalloc(sizeof(struct ndis_driver));
    if (!driver) return -ENOMEM;
    memset(driver, 0, sizeof(struct ndis_driver));

    rc = entry(driver, NULL);
    if (rc < 0) {
      kprintf("ndis: driver initialization failed with error code %08X\n", rc);
      kfree(driver);
      unload(hmod);
      return -ENXIO;
    }

    driver->hmod = hmod;
    driver->next = drivers;
    drivers = driver;
  }
Exemple #2
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	char filesizetxt[255];
	char sectionstxt[255];
	char entrypointtxt[255];

    switch(msg)
    {
		case WM_COMMAND:
		{
			if (LOWORD(wParam)==3) 
			{
				opendb();
				if (openfile() == 0) return 0;
				if (chkifexe() == 0) return 0;

				PE_pos = findPE();
				getentrypoint();
				get_num_of_sec();
				crtememspce();
				getheadersections();

				sprintf(filesizetxt,"File Size: %i",filesizedec);
				lb3->caption = filesizetxt;

				sprintf(sectionstxt,"Sections: %i",num_of_sec);
				lb4->caption = sectionstxt;

				sprintf(entrypointtxt,"Entry Point: %x%x%x%x",entrypoinywrd[3],entrypoinywrd[2],entrypoinywrd[1],entrypoinywrd[0]);
				lb5->caption = entrypointtxt;

				//sprintf(entrypointtxt,"Sections: %i",num_of_sec);
				//lb5->caption = entrypointtxt;
				
				fclose(thefile);
				break;
			}

			if (LOWORD(wParam) == 6)
			{
				if (strcmp("",tb1->caption) == 0) return 0;

				if (chkifnum() == false) return 0;

				//if (strcmp(sections[num_of_sec-1].name,".rsrc") == 0)
			//	{
					addnewsizes();

					wfile = fopen(tb1->caption, "r+b");
	
					setnewflesze();
					setnewhp();
					setnewrawsze();
					fillextra();


					fclose(wfile);



					MessageBox(NULL,"Process finshed!","blah",MB_OK);

			//	}

				if (sec_nme != NULL)
				{
					delete sec_nme;
					sec_nme=NULL;
				}
			}
			break;
		}
		case WM_CREATE:
		{
			lb1= new labelbox(hwnd);
			lb1->caption = "Filename:";
			lb1->width=50;

			tb1 = new editbox(hwnd);
			tb1->x = 60;
			tb1->width = 100;
			tb1->caption = "";

			b1 = new button(hwnd);
			b1->caption ="Broswe";
			b1->x =170;
			b1->width = 50;

			lb2 = new labelbox(hwnd);
			lb2->y = 40;
			lb2->width = 85;
			lb2->caption = "Bytes to allocate: ";


			tb2 = new editbox(hwnd);
			tb2->y = 40;
			tb2->x = 100;
			tb2->width = 30;
			tb2->caption = "";

			b2 = new button(hwnd);
			b2->caption ="Go!";
			b2->x =170;
			b2->y = 160;
			b2->width = 50;

			lb3 = new labelbox(hwnd);
			lb3->y = 80;
			lb3->width = 85;
			lb3->caption = "File size: ";

			lb4 = new labelbox(hwnd);
			lb4->y = 100;
			lb4->width = 85;
			lb4->caption = "Sections: ";

			lb5 = new labelbox(hwnd);
			lb5->y = 120;
			lb5->width = 110;
			lb5->caption = "Entry Point: ";

			break;
		}
		case WM_PAINT:
		{
			//BITMAP bm;
			PAINTSTRUCT ps;
		    HDC hdc;
		    hdc = BeginPaint(hwnd,&ps);
			EndPaint(hwnd, &ps);
		}
		break;
		case WM_CLOSE:
			

	
			DestroyWindow(hwnd);
        break;
        case WM_DESTROY:

			
			delete lb1;
			lb1 = NULL;

			delete tb1;
			tb1 = NULL;

			delete b1;
			b1 = NULL;

			delete lb2;
			lb2 = NULL;

			delete lb3;
			lb3 = NULL;

			delete lb4;
			lb4 = NULL;

		//	delete tb2;
		//	tb2 = NULL;
			if (sections != NULL)
			{
				if (sections[0].name!=NULL)
				{
					delete sections[0].name;
					sections[0].name = NULL;
				}
			}

			if (sections != NULL)
			{
				delete[] sections;
				sections = NULL;
			}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

            PostQuitMessage(0);
        break;
        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}