Zmiana ikony w skompilowanym programie (*.exe)

0

Witam...

Jak zmienić ikonę w skompilowanym exeku ?

Konkretnie to jak wyciągnąć ikonę z jednego
exeka i zapisać taką do zasobów drugiego ?

Tyle sam udziergałem ale jedyne co to robi
to usuwa ikonę z Project2.exe i pozostaje tylko
ten biały kwadrat...

var
  Handle : THandle;
  Ico : HIcon;
begin
  Ico := ExtractIcon(Hinstance, 'Project1.exe', 0);
  Handle := BeginUpdateResource('Project2.exe', False);
  UpdateResource(Handle, RT_GROUP_ICON, 'MAINICON' , LANG_POLISH, @Ico, SizeOf(Ico));
  EndUpdateResource(Handle, False);
end;

Opis funkcji UpdateResource wygląda tak:

BOOL UpdateResource(
HANDLE hUpdate, // update-file handle
LPCTSTR lpType, // address of resource type to update
LPCTSTR lpName, // address of resource name to update
WORD wLanguage, // language identifier of resource
LPVOID lpData, // address of resource data
DWORD cbData // length of resource data, in bytes
);

wydaje mi się że błąd jest w 5 argumencie (LPVOID lpData)
ale nie mam pojęcia co tam wstawić...

Prosze o pomoc...

0

polecam przejrzeć kod przykładowego edytora zasobów dołączonego w katalogu Demos (ResXplorer, czy jakoś tak)

Funkcja updateresources zadziala tylko na windowsach z serii nt

poza tym jestem pewien na 99%, ze ten temat widzialem juz na forum, wiec poszukaj sobie.

0

polecam przejrzeć kod przykładowego edytora zasobów dołączonego w katalogu Demos (ResXplorer, czy jakoś tak)

Tam jest tylko przeglądarka zasobów, nie ma zamiany.

poza tym jestem pewien na 99%, ze ten temat widzialem juz na forum, wiec poszukaj sobie.

Tak, był kod, który dał chyba Noob Saibot (czy jakoś tak), ale był on potwornie długi i podobno działał tylko dla ikon o wielkości nie przekraczającej ileś tam.

A tak w ogóle, to zdaje się, że język jest źle ustawiony, jeśli mnie pamięć nie myli, to powinno być 1045.

// Dopisane
Z tym językiem miałem rację, ale całość niestety nie działa. Zasób dodaje i jest on widoczny jako icon group, lecz nie można go odczytać, więc pewnie winny jest format danych.

// Dopisane2
Całkiem nieźle to wygląda. Spróbuję coś wykombinować, jak ściągnę.

0

Z tym językiem miałem rację, ale całość niestety nie działa. Zasób dodaje i jest on widoczny jako icon group, lecz nie można go odczytać, więc pewnie winny jest format danych.

hmmm... głupia sprawa, szkoda że nie ma źródeł
programu Resource Hacker, on to potrafi wykonać ;-(

BTW znalazłem jakieś biblioteki ale nie wiem jak ich używać
http://help.madshi.net/madResUnit.htm (madRes) może
one by zadziałały (trzeba ściągnąć cały pakiet madCollection)

[<font color="blue">dopisane</span>]

No dobra teraz bawiłem się w Delphi oglądając wyniki w ResHacker
i mam koncepcję która potwierdza twoją:

zapisałem plik *.ico pod RT_GROUP_ICON 'MAINICON' 1045

normalnie ResHacker wyświetlał coś takiego 32 x 32 (16 colors) - Ordinal name: 1
a w RT_ICON '1' 1045 była właściwa ikona

po operacji pokazało się 32 x 32 (16 colors) - Ordinal name: 22
więc do RT_ICON '22' 1045 wstawiłem plik *.dat
(wygenerowany przez ResHacker opcją Save as Binary, oglądałem
plik w notatniku i wygląda on jak *.bmp lub *.ico bez nagłowków)
szczęśliwie w 'MAINICON' pokazała się ikona ale program, nadal
jej nie wyświetla , tylko ResHacker. . .

0

W desperacji wykodziłem coś takiego hehehehehe

procedure Str2File(FName, Str: String);
var
  F : File of Byte;
begin
  AssignFile(F, FName);
  try
    FileMode := 1;
    Rewrite(F);
    BlockWrite(F, Str[1], Length(Str));
  finally
    CloseFile(F);
  end;
end;

function File2Str(FName: String): String;
var
  F : File of Byte;
begin
  AssignFile(F, FName);
  try
    FileMode := 0;
    Reset(F);
    SetLength(Result, FileSize(F));
    BlockRead(F, Result[1], Length(Result));
  finally
    CloseFile(F);
  end;
end;

procedure Ico2File(Ico, FName: String);
var
  Ikona, Plik : String;
  i : Integer;
begin
  Ikona := File2Str(Ico);
  Delete(Ikona, 1, 22);
  Plik := File2Str(FName);
  i := Pos(Copy(Ikona, 1, 10), Plik);
  Delete(Plik, i, Length(Ikona));
  Insert(Ikona, Plik, i);
  Str2File(FName, Plik);
end;

ale to jest rozwiązanie dobre tylko w moim przypadku
kiedy wiem że ikona ma 32 X 32 pikseli i 16 kolorów,
no i dla mojego konkretnego programu w API który ma
w zasobach tylko jedną ikonę, bo tak się składa że
pierwszych 10 bajtów takich ikon jest taka sama dla
kursorów i przez to ikona może lądować nie tam gdzie
trzeba.

Wie ktoś jak dokładnie określić pozycje ikony w exeku ?

[glowa] Idę spać...

0

Bajty 24..25 od początku pliku pliku zawierają offset do windowsowego nagłówka, a w nim z kolei (bajty 36..37 relatywnie do początku tegoż nagłówka) offset do tablicy zasobów. Jej konstrukcji już nie chce mi się tłumaczyć :P, więc zacytuję dokumentację:


Resource Table
The resource table describes and identifies the location of each resource in the executable file. The table has the following form:
<bcb>
WORD rscAlignShift;
TYPEINFO rscTypes[];
WORD rscEndTypes;
BYTE rscResourceNames[];
BYTE rscEndNames;
</bcb>
Following are the members in the resource table:
rscAlignShift Specifies the alignment shift count for resource data. When the shift count is used as an exponent of 2,
the resulting value specifies the factor, in bytes, for computing the location of a resource in the
executable file.
rscTypes Specifies an array of TYPEINFO structures containing information about resource types. There must
be one TYPEINFO structure for each type of resource in the executable file.
rscEndTypes Specifies the end of the resource type definitions. This member must be zero.
rscResourceNames Specifies the names (if any) associated with the resources in this table. Each name is stored as
consecutive bytes; the first byte specifies the number of characters in the name.
rscEndNames Specifies the end of the resource names and the end of the resource table. This member must be
zero.

Type Information

The TYPEINFO structure has the following form:

<bcb> typedef struct _TYPEINFO { WORD rtTypeID; WORD rtResourceCount; DWORD rtReserved; NAMEINFO rtNameInfo[]; } TYPEINFO;</bcb>

Following are the members in the TYPEINFO structure:

rtTypeID Specifies the type identifier of the resource. This integer value is either a resource-type value or an offset
to a resource-type name. If the high bit in this member is set (0x8000), the value is one of the following
resource-type values:

Value Resource type

RT_ACCELERATOR Accelerator table
RT_BITMAP Bitmap
RT_CURSOR Cursor
RT_DIALOG Dialog box
RT_FONT Font component
RT_FONTDIR Font directory
RT_GROUP_CURSOR Cursor directory
RT_GROUP_ICON Icon directory
RT_ICON Icon
RT_MENU Menu
RT_RCDATA Resource data
RT_STRING String table

If the high bit of the value in this member is not set, the value represents an offset, in bytes relative to the
beginning of the resource table, to a name in the rscResourceNames member.

rtResourceCount Specifies the number of resources of this type in the executable file.
rtReserved Reserved.
rtNameInfo Specifies an array of NAMEINFO structures containing information about individual resources. The
rtResourceCount member specifies the number of structures in the array.

Name Information

The NAMEINFO structure has the following form:

<bcb> typedef struct _NAMEINFO { WORD rnOffset; WORD rnLength; WORD rnFlags; WORD rnID; WORD rnHandle; WORD rnUsage; } NAMEINFO; </bcb>

Following are the members in the NAMEINFO structure:

rnOffset Specifies an offset to the contents of the resource data (relative to the beginning of the file). The offset is in terms of
alignment units specified by the rscAlignShift member at the beginning of the resource table.
rnLength Specifies the resource length, in bytes.
rnFlags Specifies whether the resource is fixed, preloaded, or shareable. This member can be one or more of the following
values:

Value Meaning

0x0010 Resource is movable (MOVEABLE). Otherwise, it is fixed.
0x0020 Resource can be shared (PURE).
0x0040 Resource is preloaded (PRELOAD). Otherwise, it is loaded on demand.

rnID Specifies or points to the resource identifier. If the identifier is an integer, the high bit is set (8000h). Otherwise, it is an
offset to a resource string, relative to the beginning of the resource table.
rnHandle Reserved.
rnUsage Reserved.

0

Dzięki serdeczne, to bardzo cenne informacje, zaraz gdzieś
zapiszę chociaż nie skorzystam bo znalazłem prostsze
trzy linijkowe rozwiązanie z użyciem gotowego unitu . . .
(lenistwo bierze górę hehe)

1 użytkowników online, w tym zalogowanych: 0, gości: 1