AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi Function (WIMGetMountedImageInfo)
Thema durchsuchen
Ansicht
Themen-Optionen

Function (WIMGetMountedImageInfo)

Ein Thema von SlpLow · begonnen am 16. Dez 2013 · letzter Beitrag vom 19. Dez 2013
Antwort Antwort
Seite 1 von 2  1 2      
SlpLow

Registriert seit: 4. Nov 2013
28 Beiträge
 
#1

Function (WIMGetMountedImageInfo)

  Alt 16. Dez 2013, 17:38
Hallo! Hilfe bitte!
Warum function (WIMGetMountedImageInfo) nicht an zwei montierten Bildern zu arbeiten?
Delphi-Quellcode:
procedure TForm1.btn2Click(Sender: TObject);
var
  Created, Count: DWORD;
  Buffer: WIM_MOUNT_INFO_LEVEL0;
  size: Integer;
  wPath, wFile, wIndex, wWrite: string;
begin
  if not (WIMGetMountedImageInfo(0, @Count, @Buffer, size, @created)) then
  begin
    ShowMessage('Error Open ' + IntToStr(GetLastError));
    Exit;
  end
  else
  begin
    if Count > 0 then
    begin
// for i := 1 to Count - 1 do
      begin
        wPath := Buffer.MountPath;
        wFile := Buffer.WimPath;
        wIndex := IntToStr(Buffer.ImageIndex);
        // Memo1.Lines.Add(BoolToStr(NewInfoBuf.MountedForRW, true));
        if Buffer.MountedForRW then
          wWrite := 'RW'
        else
          wWrite := 'R';
      end;
      Memo1.Lines.Add(wPath);
      Memo1.Lines.Add(wFile);
      Memo1.Lines.Add(wIndex);
      Memo1.Lines.Add(wWrite);
    end;
end;

Geändert von SlpLow (16. Dez 2013 um 17:41 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von Union
Union

Registriert seit: 18. Mär 2004
Ort: Luxembourg
3.487 Beiträge
 
Delphi 7 Enterprise
 
#2

AW: Function (WIMGetMountedImageInfo)

  Alt 16. Dez 2013, 20:11
See the documentation
Ibi fas ubi proxima merces
sudo /Developer/Library/uninstall-devtools --mode=all
  Mit Zitat antworten Zitat
SlpLow

Registriert seit: 4. Nov 2013
28 Beiträge
 
#3

AW: Function (WIMGetMountedImageInfo)

  Alt 16. Dez 2013, 21:56
Thank you! I studied it for three days.
When one image, everything works. If two simultaneously in different folders is not running. It is clear that there are many records but how to handle it I do not know.
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.152 Beiträge
 
Delphi 12 Athens
 
#4

AW: Function (WIMGetMountedImageInfo)

  Alt 16. Dez 2013, 22:05
Then you did not read properly.

Zitat:
pMountInfo

[out opt] Pointer to a variable that receives the array of mounted image structures. The size of the information written varies depending on the type of structured defined by the fInfoLevelId parameter.

cbMountInfoLength

[in] The size of the buffer pointed to by the pMountInfo parameter, in bytes.

pcbReturnLength ( @created ? )

[out] A pointer to a variable in which the function returns the size of the requested information. If ...
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests

Geändert von himitsu (16. Dez 2013 um 22:11 Uhr)
  Mit Zitat antworten Zitat
SlpLow

Registriert seit: 4. Nov 2013
28 Beiträge
 
#5

AW: Function (WIMGetMountedImageInfo)

  Alt 17. Dez 2013, 00:19
I can tell you one thing! I do not know how to do, how to announce in the variables and how to apply.
Is all that is understood.
 if not (WIMGetMountedImageInfo([COLOR="Red"]MountedImageInfoLevel0[/COLOR], @Count, @Buffer, size, @created)) then Yours!
  Mit Zitat antworten Zitat
SlpLow

Registriert seit: 4. Nov 2013
28 Beiträge
 
#6

AW: Function (WIMGetMountedImageInfo)

  Alt 17. Dez 2013, 00:21
I can tell you one thing! I do not know how to do, how to announce in the variables and how to apply.
Is all that is understood - MountedImageInfoLevel0.
 if not (WIMGetMountedImageInfo(MountedImageInfoLevel0, @Count, @Buffer, size, @created)) then Yours!
  Mit Zitat antworten Zitat
Benutzerbild von Zacherl
Zacherl

Registriert seit: 3. Sep 2004
4.629 Beiträge
 
Delphi 10.2 Tokyo Starter
 
#7

AW: Function (WIMGetMountedImageInfo)

  Alt 17. Dez 2013, 01:44
When one image, everything works
I doubt that ...

You were just "lucky". The uninitialized size variable contained a sufficient size for the returned data struct. The api call in it's current form destroys a random memory region (directly behind the output buffer) in your program (buffer overflow), if there is more than one mounted image.

I cant really test it, because i have no mounted images, but it should work like this. Happy copy and paste:
Delphi-Quellcode:
type
  _WIM_MOUNT_LIST = packed record
    WimPath: array[0..MAX_PATH - 1] of WideChar;
    MountPath: array[0..MAX_PATH - 1] of WideChar;
    ImageIndex: DWord;
    MountedForRW: BOOL;
  end;
  WIM_MOUNT_LIST = _WIM_MOUNT_LIST;
  PWIM_MOUNT_LIST = ^WIM_MOUNT_LIST;
type
  WIM_MOUNT_INFO_LEVEL0 = _WIM_MOUNT_LIST;
  PWIM_MOUNT_INFO_LEVEL0 = ^WIM_MOUNT_LIST;
type
  MOUNTED_IMAGE_INFO_LEVELS = DWord;
const
  MountedImageInfoLevel0 = 1;
var
  WIMGetMountedImageInfo: function(fInfoLevelId: MOUNTED_IMAGE_INFO_LEVELS;
    var dwImageCount: DWord; pMountInfo: Pointer; cbMountInfoLength: DWord;
    var cbReturnLength: DWord): BOOL; stdcall;
type
  PWIM_MOUNT_INFO_LEVEL0_LIST = ^WIM_MOUNT_INFO_LEVEL0_LIST;
  WIM_MOUNT_INFO_LEVEL0_LIST = array[0..0] of WIM_MOUNT_INFO_LEVEL0;
var
  Success: Boolean;
  Buffer: PWIM_MOUNT_INFO_LEVEL0_LIST;
  BufferLength,
  ReturnLength,
  ImageCount: DWord;
  I: Integer;
begin
  @WIMGetMountedImageInfo := GetProcAddress(LoadLibrary('wimgapi.dll'), 'WIMGetMountedImageInfo');
  BufferLength := SizeOf(WIM_MOUNT_INFO_LEVEL0) * 8;
  GetMem(Buffer, BufferLength);
  try
    repeat
      Success := WIMGetMountedImageInfo(MountedImageInfoLevel0, ImageCount, Buffer, BufferLength,
        ReturnLength);
      if (Success) then
      begin
        for I := 0 to ImageCount - 1 do
        begin
          ShowMessage(StrPas(PChar(@Buffer^[I].WimPath[0])));
        end;
      end else if (GetLastError = ERROR_INSUFFICIENT_BUFFER) then
      begin
        ReallocMem(Buffer, ReturnLength);
      end;
    until (Success) or (GetLastError <> ERROR_INSUFFICIENT_BUFFER);
  finally
    FreeMem(Buffer);
  end;
end;
Projekte:
- GitHub (Profil, zyantific)
- zYan Disassembler Engine ( Zydis Online, Zydis GitHub)
  Mit Zitat antworten Zitat
SlpLow

Registriert seit: 4. Nov 2013
28 Beiträge
 
#8

AW: Function (WIMGetMountedImageInfo)

  Alt 17. Dez 2013, 02:35
Zacherl! Vielen, vielen Dank! Ich werde versuchen, zu verstehen.
Adel liegt (sitzt) im Gemüte, nicht im Geblüte.

himitsu! Danke! Ich habe wenig Erfahrung, aber ich werde lernen!

Geändert von SlpLow (17. Dez 2013 um 02:46 Uhr)
  Mit Zitat antworten Zitat
SlpLow

Registriert seit: 4. Nov 2013
28 Beiträge
 
#9

AW: Function (WIMGetMountedImageInfo)

  Alt 17. Dez 2013, 05:27
Thank you again!
Strings and integer okay!
A logical always returns a -1 (RW, R) instead of 0 and 1
Idx: = BoolToStr (Buffer ^ [I]. MountedForRW, False); :
or integer 257 (RW) or 1 (R) instead of 0 and 1
idx: = IntToStr (Integer (Buffer ^ [I]. MountedForRW)); :
Because it LongBool? Is there a solution?

I do not know, correct or not, but the problem disappeared when
Delphi-Quellcode:
const
MountedImageInfoLevel0 = 0;
Is it right decision?

Geändert von SlpLow (17. Dez 2013 um 06:05 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von Zacherl
Zacherl

Registriert seit: 3. Sep 2004
4.629 Beiträge
 
Delphi 10.2 Tokyo Starter
 
#10

AW: Function (WIMGetMountedImageInfo)

  Alt 17. Dez 2013, 22:43
Thats because of the C style boolean definition:
FALSE = 0
TRUE = everything else

You can just check the flag like this:
if (Buffer^[I].MountedForRW) then or
if (not Buffer^[I].MountedForRW) then If your problem is just the bool to string conversion you can go for this:
BoolToStr(Buffer^[I].MountedForRW, true) or just write you an own function, if you dont like the -1 or the default bool strings.
Projekte:
- GitHub (Profil, zyantific)
- zYan Disassembler Engine ( Zydis Online, Zydis GitHub)

Geändert von Zacherl (17. Dez 2013 um 22:46 Uhr)
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:12 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz