Putting a string in an array of bytes

c++ / delphi package - dll injection and api hooking
Post Reply
cogumel0
Posts: 8
Joined: Wed Nov 10, 2004 2:32 am

Putting a string in an array of bytes

Post by cogumel0 »

I'm trying to send a packet with some information that I must first transform to hex before sending.

The buffer is an array[0..10] of bytes.

Then I got the func that transforms my int64 into hex and returns a string. How do I affect buffer[5] with the str returned?

Here are the 2 funcs:

Main Function

Code: Select all

Function SendPacket(Item: int64): boolean;
var
  buffer: Array[0..10] of Byte;
begin
  buffer[0] := $11;                                     
  buffer[1] := $0;                                       
  buffer[2] := $83;                                  
  buffer[3] := $FF;                                   
  buffer[4] := $FF;                                     
  buffer[5] := $40                
  buffer[6] := $0;
  buffer[7] := $0
  buffer[8] := TransformHex(Item, True);        
  buffer[9] := TransformHex(Item, False);
  buffer[10] := buffer[7]; 
end;
Transforming to Hex Function

Code: Select all


Function TransformHex(originalNumber: int64; firstValue: Boolean): string;
var
  item: String;
  item1: String;
  item2: String;
begin
  item := IntToStr(originalNumber);
  item := IntToHex(StrToInt(item), Length(item));
  Case Length(item) of
      1,2 : item2 := item;
      3:begin
        item1 := Copy(item, 0, 1);
        item2 := Copy(item, Length(Item)-3, Length(Item)-1);
        end;
      4:begin
        item1 := Copy(item, 0, 2);
        item2 := Copy(item, Length(Item)-3, Length(Item)-1);
      end;
  end;
  item1 := '$' + item1;
  item2 := '$' + item2;
  If firstValue = True Then
    TransformHex := item2 //'use true to get the first string
  Else
    TransformHex := item1
end;
Even though the Transform function returns something like $55F, it says byte and string are not compatible. How can I go round this problem?
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

I don't really know what you're trying to do here. You simply can't put a string into a byte. That doesn't make any sense! :confused:
cogumel0
Posts: 8
Joined: Wed Nov 10, 2004 2:32 am

Post by cogumel0 »

solved, all I had to do was transform it into an integer. Didn't know that the $FF and other hex values were going to be transformed into int before being put into the array. It's not exactly logical...
Post Reply