Einzelnen Beitrag anzeigen

flash2009

Registriert seit: 15. Dez 2008
11 Beiträge
 
#22

Re: Wie baut man sowas wie writeln/sprintf selbst ?

  Alt 27. Dez 2008, 19:57
ok so sieht das aus und es funktioniert, ist nich ganz schön aber läuft =)

Delphi-Quellcode:
type
  TSprintf = function(Buffer:Pointer;Format1:PChar;dwArray:DWord):Integer;cdecl;

implementation

var
 SprintfOrg : TSprintf;

function translate(Buffer: Pointer; Format1: PChar;dwFirst:DWord):Integer;cdecl;
var
  i : Integer;
  c : Integer;
  ptr1 : Pointer;
begin
  c:= 0;
  i := 0;
  for i := 0 to (length(Format1)-1) do
  if Format1[i] = '%then
  begin
    inc(c);
    if Format1[i+1] = 'sthen // das ist nicht wichtig für die funktion
    begin //von hier
      ptr1 := @dwFirst;
      LogToFileStr(PChar(Pointer(Cardinal(ptr1)+4*(c-1) )^))
    end; //bis hier hin
    if Format1[i+1] = '%then
      dec(c,2);
  end;
  asm
    push eax
    push ebx
    mov eax , c

  @putonstack:
    test eax , eax
    je @stackok
    lea ebx , dwFirst
    shl eax , 2
    add ebx , eax
    shr eax , 2
    sub ebx , 4 //first index = 0 not 1 !
    sub eax , 1
    push DWord ptr [ebx]
    jmp @putonstack

  @stackok:
    push Format1
    push Buffer
    call SprintfOrg //call the orignal function
    mov Result , eax
    mov eax , c //Paremeter Counter
    add eax , 2 //+ Buffer and Format
    shl eax , 2 //Size each 4bytes
    add esp , eax //fix stack because of cdecl
    pop ebx
    pop eax
  end;
end;
greetz flash
  Mit Zitat antworten Zitat