Im working on a program for interacting with some equipment that sends data that has been encoded and wrapped for sending inside a CDATA block in an XML document.
The software on the device, as far as I know, is written in Python, and I'm writing an interface in Delphi.
the data sent by the device is
\ x00E \ x18 \ x10 \ x14} * UF A \ x81 \ XAC \ x08 &! \ X02 \ x01 \ n \ x15 \ x1a \ xc2PP \ x92 \ x17 \ xc2 \ xc1 \ xa0 \ x0e \ x1a \ xc2 \ xd0K \ x94 \ '\ X830 \ x11 \ x8b \ X84a_ \ xa0 + \ x04 \ x81 \ x17 \ x89 \ x15D \ x91B \ x05. \ X84 \ XF1 \ X1B \ x89% E \ x00 \ x04 \ x9c \ x0e \ xc5 \ xc1 = \ x87 \ x0bE \ xf18 \ X07 \ x1f \ xc8a \ xa5 \ x95 \ x08H \ x80? \ x84 \ x18 \ Tpk \ X8A $ \ t \ XF1 \ XB2 \ x8e (J \ XB0 \ x08 \ x91 \ x1eJ \ xf0W \ x0c- \ x0b \ xf0 \ x0e \ x88 \ X07 \ x0c \ x00 \ X9b \ n \ X910Z \ x06! \ X92 \ xf0W \ x073S \ X08 \ x87 \ XFF \ XFF \ XFF \ xf0 \ x0e \ XFF \ XFF \ XFF \ XFF \ XFF \ xf3 \ x10 \ x0e \ Xba \ XFF \ XFF \ XFF \ xf4C \ Fixed \ Xbb \ xb9_ \ xffDD1 \ g \ XCB \ xbaw \ xf5TD2 \ fixed \ Xbb \ Xba \ x88EUDB \ x0c \ Xba \ Haa \ x99UUDB \ x0c \ Xba \ Haa \ xa9UUD2 \ g \ Xbb \ Haa \ xaaUTD2 \ g \ XCB \ Xbb \ xaaUTC! \ g \ XCB \ Xbb \ xbbUD3! \ x0e \ XDc \ Xbb \ xbb \ xbb \ x0e \ XDc \ XCC \ xbbDC2! \ x0e \ XDc \ XCC \ xcc33 "\ x11 \ x0e \ XDD \ XCC \ xccC3" \ x11 \ x0e \ fixed \ XDc \ XCC \ xf33! \ x10 \ x0e \ Xee \ XDD \ XCC \ xf32! \ X10 \ x0e \ Xee \ XDD \ XDc \ xff2! \ X10 \ x00 \ Xee \ Xee \ XDD \ XFF \ xf2! \ X11 \ x00 \ x0e \ Xee \ XDD \ XFF \ xf2! \ X11 \ x10 \ x0e \ Xee \ Xep \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x 00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00
I need to send similar data back to the device, but the format it is in is
I know that \ x is commonly used to denote ascii characters using their hexadecimal values ββin two-digit pairs, but looking at the data is not the case. I'm struggling to determine the encoding used, and the manufacturer does not provide significant assistance.
what I want to know how can I convert the hex that I have to the format that they use in Delphi xe4?
By the way, two blocks do not contain the same data, but they are the same data type, i.e. format is the same as other encoding
sample data sent
POST ******** HTTP/1.1 Host: 172.16.1.136:8080 Accept-Encoding: identity Content-Length: 1552 Content-Type: text/xml Authorization: 1344354:PASS User-Agent: ********* <?xml version="1.0" encoding="utf-8"?> <Biometrics> <Templates> <Template badge="1075" readerType="6" index="6" ts="2014-11-06T17:28:40.000+01:00" chk="3a6a4924ec04e668186b15e244e6fe73"> <![CDATA[ ['1075_6', 1415294920.3754971, [0, 0], [['3\x04\x00\x00\x00P\x00\x00E\x18\x10\x14}*UF!A\x81\xac\x08&\x02\x01\n\x15\x1a\xc2PP\x92\x17\xc2\xc1\xa0\x0e\x1a\xc2\xd0K\x94\'\x830\x11\x8b \x84a_\xa0+\x04\x81\x17\x89\x15D\x91B\x05.\x84\xf1\x1b\x89%E\x00\x04\x9c\x0e\xc5\xc1=\x87\x0bE\xf18\x07\x1f\xc8a\xa5\x95\x08H\x80?\x84\x18\tPK\x8a$\t\xf1\xb2\x8e(J\xb0\x08\x91\x1eJ\xf0W\x0c-\x0b\xf0\x0e\x88\x07\x0c\x00\x9b\n \x910Z\x06!\x92\xf0W\x073S \x08\x87\xff\xff\xff\xf0\x0e\xff\xff\xff\xff\xff\xf3\x10\x0e\xba\xff\xff\xff\xf4C \xed\xbb\xb9_\xffDD1\r\xcb\xbaw\xf5TD2\xed\xbb\xba\x88EUDB\x0c\xba\xaa\x99UUDB\x0c\xba\xaa\xa9UUD2\r\xbb\xaa\xaaUTD2\r\xcb\xbb\xaaUTC!\r\xcb\xbb\xbbUD3!\x0e\xdc\xbb\xbbDD3!\x0e\xdc\xcc\xbbDC2!\x0e\xdc\xcc\xcc33"\x11\x0e\xdd\xcc\xccC3"\x11\x0e\xed\xdc\xcc\xf33!\x10\x0e\xee\xdd\xcc\xf32!\x10\x0e\xee\xdd\xdc\xff2!\x10\x00\xee\xee\xdd\xff\xf2!\x11\x00\x0e\xee\xdd\xff\xf2!\x11\x10\x0e\xee\xef\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00']]] ]]> </Template> </Templates> </Biometrics> HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Type: text/xml;charset=ISO-8859-1 Transfer-Encoding: chunked Date: Thu, 06 Nov 2014 17:28:41 GMT 52 <?xml version="1.0" encoding="UTF-8"?><OperationStatus uid="">OK</OperationStatus> 0
These are biometric templates used by Suprema Reader, if that helps.
Decision
I have successfully deciphered what is happening with this now. in order to turn the original hexadecimal string into the required format, I use this code, hope this helps someone else in the future. Please feel free to comment and make suggestions for improving the code.
class function TConvert.HexToPythonEscAscii(const aHexString: string): string; var i: Integer; ByteArray: array of Byte; begin Result := ''; SetLength(ByteArray, (length(aHexString) div 2) ); TConvert.HexToBytes(aHexString, ByteArray, length(ByteArray)); for i := Low(ByteArray) to High(ByteArray) do begin if ByteArray[i] in [$20..$7E] then begin case ByteArray[i] of $5c : Result := Result +'\\'; $27 : Result := Result +'\'''; else Result := Result + char(ByteArray[i]) end; end else begin case ansichar(ByteArray[i]) of TAB : Result := Result + '\t'; LF : Result := Result + '\n'; CR : Result := Result + '\r'; else Result := Result + '\x' + LowerCase(IntToHex(ByteArray[i], 2)); end; end; end; end;