Autor Beitrag
Flamefire
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Sa 19.05.07 10:09 
Hi
z.Zt. beschäftige ich mich mit dem modifizieren von exe-dateien, um zusatzfunktionen hinzuzufügen oder eine datei zu packen...
ich mache das Ändern des Section headers mit PEID und das ändern der exe mit Hexworkshop und ollydbg

da das aber sehr aufwendig ist (bei neuen Versionen oder beim Packen) will ich das alles auf einmal mit Delphi machen

Dazu folgende Fragen:

1) Wie kann ich auf einen section-header zugreifen + verändern? (Also z.b. den .data teil um 50h vergrößern und auf ausführbar setzen)
2) Wie kann ich mit Delphi Teile einer exe verändern bzw. etwas an eine stelle einfügen (offset gegeben)
3) Wie kann ich mit Delphi ASM Code in eine exe einfügen ("JMP 048347A", "add eax", "mov [0a34fa3],ecx" z.b.)

Ein paar stichpunkte, befehle oder Tutorials wären nett.
Ich bedanke mich schonmal für die Hilfe.

BTW: Damit es nicht missverstanden wird: Es handelt sich um ein Programm für den Privatgebrauch, um Anzeigedaten (wie andre Währung, Sprache etc) usw. zu verändern. Es wird weder zum Cracken noch zum erstellen eines Virus benutzt.
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: Sa 19.05.07 10:20 
1) Weiß ned.
2) Verändern kannst du ganz einfach mit TFileStream machen. Etwas einfügen würde ich eher nicht machen, da sich dann die Adressen alle verschieben und deine EXE praktisch Schrott ist.
3) Genauso wie in Punkt 2, du musst halt vorher deine Assemblerbefehle in Opcodes umwandeln. Vielleicht schaust du dir mal den Disassembler von user profile iconuall@ogc an.
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Sa 19.05.07 10:41 
Tja da muss man sich gut mit dem PE Header auskennen.
Schau dir mal P/TImageDosHeader P/TImageNtHeaders (windows.pas) an.
Generell gibts viel in der windows.pas für Import Table / Sections und die ganzen Konstanten.
Damit kannst du dann z.b. einer Section andere Rechte geben.
Schwierig wirds beim vergrößern einer Section (wenns die letzte ist gehts noch)
Wenn die aber mitten drin ist (und VirtualSize = RawSize) wirds extrem schwierig.
Dann müssen ventl Relocations / Imports usw gefixt werden.

Wenn die letzte Section (data?) vergrößerst und auf Execute änderst, vergiss nicht eventl. VirtualSize und !Rawsize! zu ändern, und möglicherweise auf noch ImageSize :)

Assemblercode einfügen geht entweder direkt über Delphi hardcoded (dann einfach den code kopieren, achtung sollte keine globalen Variablen enthalten) oder eben selbst generieren oO

Meine Seite is gerade down, von daher gibts erstmal keine Beispielcodes um sowas zu machen :/

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Sa 19.05.07 11:04 
es geht um die letze Section. Die soll vergrößert werden (um 50h) und auf execute gesetzt werden.
Und an die solln dann ebn 50h * "00" angehängt werden (sonst stimmt die Größe ja ne mehr)

Wie gesagt: Mit PEID setze ich das beides ohne probs...aber wills ebn in Delphi

Den ASM-Code habe ich ebn als ASM vorliegen.

Hat nicht jemand mal n Bsp-Code fürs verändern des Headers/Anfügen/Verändern eines Offset?

Außerdem: Ich bräuchte mal ne Hilfe zur Adressen-Angabe in Calls/JMPS etc. Wie läuft das?
Also: Ich habe 2 Variablen mit 2 Adressen. (Integer)
Jetzt soll an Position der 1. Var ein JMP an die Position der 2.Var. Wie sieht der aus?
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Sa 19.05.07 11:14 
Hab ich eigentlich shcon beantwortet: Datei reinladen mit ImageDosHeader / ImageNtHeader an die section kommen, deren rawsize verändern und gut is :)

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Sa 19.05.07 22:04 
hm...keine doku oder tut dazu gefunden...
kannste ne bitte ein Bsp zu dem TImageNtHeader posten?
Ich raffs ne...

PS: mein NAchtrag vom letzten is auch noch ne beantwortet... ^^
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: So 20.05.07 17:07 
PImageNtHeader is normales struct, schaus dir halt an. Da kannste auf alles zugreifen was du brauchst.
Für ne PE Header Beschreibung einfach mal googlen.

Und die extra Frage hab ich net kapiert ;)

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: So 20.05.07 19:27 
gegoogelt hab ich schon und nix brauchbares gefunden =(

zu meiner "extra-Frage":
es sind 2 Variablen gegeben (z.b.:
ausblenden Delphi-Quelltext
1:
2:
3:
var pos1,pos2:Integer;
pos1:=0x0043555;
pos2:=0x00aF542;


Jetzt will ich an Pos1 (als offset dieser Exedatei) einen "JMP pos2" reinknallen
Verständlich? ^^

EDIT:
Hab jetz das mal zusammengeschnipselt aus allen möglichen im netz:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
procedure getsections(name:String;a:TStrings);
var
  { Datei Öffnen }
  savestream,loadstream :tfilestream;
  { Zwischenspeicherung }
  lpBuffer: Pointer;
  { PE-Stuff }
  Alignment: dword;
  ImageNtHeaders: PImageNtHeaders;
  PSections: ^TSections;
  SectionLoop,i: dword;
  s:String;
begin
  loadstream := tfilestream.Create(name,fmOpenRead);
  getmem(lpBuffer,loadstream.size );
  loadstream.read(lpBuffer^,loadstream.Size);
  ImageNtHeaders := PImageNtHeaders(Cardinal(lpBuffer) + Cardinal(PImageDosHeader(lpBuffer)._lfanew));
  PSections := pointer(pchar(@(ImageNtHeaders.OptionalHeader)) + ImageNtHeaders.FileHeader.SizeOfOptionalHeader);
  for SectionLoop := 0 to ImageNtHeaders.FileHeader.NumberOfSections - 1 do
  begin
    if PSections[SectionLoop].Misc.VirtualSize <> 0 then
    begin
      s:='';
      For i:=0 to Length(PSections[SectionLoop].name)-1 do begin
        if(PSections[SectionLoop].name[i]=0) then break;
        s:=s+chr(PSections[SectionLoop].name[i]);
      end;
      a.add(s+' '+inttohex(PSections[SectionLoop].VirtualAddress,8)+' '+inttohex(PSections[SectionLoop].Sizeofrawdata,8)+' '+inttohex(PSections[SectionLoop].Misc.VirtualSize,8)+' '+inttohex(PSections[SectionLoop].Characteristics,8));
      if(s='.rsrc') then begin
        PSections[SectionLoop].Sizeofrawdata:=PSections[SectionLoop].Sizeofrawdata+255;
      end;
    end;
  end;
  savestream := TFilestream.Create('TEMP.exe',fmCreate);
  savestream.CopyFrom(loadstream,0);
  loadstream.Free;
  savestream.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
  getsections('C:\Dokumente und Einstellungen\xxxx\Desktop\sections\Project2.exe',Listbox1.Items);
end;


Das klappt aber anscheinend nur für Delphi dateien...für alle anderen gibts n fehler (lpNumberOfBytesRead=0)
Warum?


Zuletzt bearbeitet von Flamefire am Mo 21.05.07 15:31, insgesamt 1-mal bearbeitet
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Mo 21.05.07 15:09 
hmm ok...das ghet jtzt...
der scheint meinen dateinamen nicht gemachoit zu haben...

also noch offen:

-ASM in Bytes umwandeln
-Veränderten Header speichern
-Bytes anfügen
-Bytes an bestimmtem Offset ändern
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Mi 23.05.07 21:05 
1) asm einfach mit @asmfunktion kopieren
2) veränderten header speicher: einfach im mem abändern und dann speichern oO
3) bytes anfügen: einfach im stream anfügen
4) im stream/mem ändern

also das sollte jetzt alles kein problem mehr sein

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit