查找可字符串的资源ID

时间:2015-12-29 23:39:39

标签: delphi resources string-table

存储字符串表资源ID在哪里?我能够在表中列出字符串,但似乎没有任何类型的标识符"原始资源"它只是一个(数组)USHORT(长度)后跟宽字符(字符串),没有标识符。

PIMAGE_RESOURCE_DIR_STRING_U = ^TIMAGE_RESOURCE_DIR_STRING_U;
TIMAGE_RESOURCE_DIR_STRING_U = Record
  Count : USHORT;//Word;
  Name  : Array [0..0] of WideChar;
End;

PIMAGE_RESOURCE_DATA =^TIMAGE_RESOURCE_DATA;
TIMAGE_RESOURCE_DATA = Record
  rt_type :  DWORD; //RT_STRING
  lpName  :  ShortString; //tables name
  Address :  PDWORD; //address of the table
  dwSize  :  DWORD; //size of the data
end;

procedure GUIDataToString(IRD: TIMAGE_RESOURCE_DATA);
Type
  TStringArray = Array of String;


  Function SplitString(P: PByte; dwplen: Int32): TStringArray;
  //P is a Pointer to the string table, dwPLen is the size of the table
  Var
    Index : Int32;
    offset: Int32;
    dwLen : WORD;
    ST_ID : NativeUInt;
    rt_str: PIMAGE_RESOURCE_DIR_STRING_U;
  Begin
    Index := 0; //String Index
    offset:= 0;
    while (offset <= dwplen) do
    Begin
      SetLength(Result, Length(Result)+1);

      rt_str        := PIMAGE_RESOURCE_DIR_STRING_U(@P[offset]);
      Result[Index] := NameToStr(rt_str);
      //
      Inc(offset, (rt_str.Count * sizeof(WideChar) )+ sizeof(WORD));
      Inc(Index);
    End;
  End;

Var
  Table     : TStringArray;
  dwStrings : DWORD;
  I         : Int32;
  //d         :
begin
  Table   := SplitString(PByte(IRD.Address), IRD.dwSize);
  dwStrings := Length(Table);
  Memo1.Lines.Add('STRINGTABLE');
  Memo1.Lines.Add('{');

  for I := 0 to dwStrings-1 do
  Begin
    Memo1.Lines.Add(#9+Table[I]); //#9 is TAB
  End;
   Memo1.Lines.Add('}');
end;

我读过resourcestring(type)可以强制转换为PResStringRec .Identifier字段会给出一个标识符但是,我尝试使用我的&#34;原始字符串&#34;并且它是一个随机的大数字(比较ID resedit给出),关于如何找到ID的任何建议?

image

2 个答案:

答案 0 :(得分:2)

字符串表中没有存储ID。字符串资源以16个字符串的形式组织。字符串ID实际上是16位整数,其中高12位标识表中包的索引,低4位标识包中字符串的索引。 Raymond Chen在他的MSDN博客上讨论了这个问题:

The format of string resources

What is the highest numerical resource ID permitted by Win32?

答案 1 :(得分:-2)

解决了,在哪里 dwGroups 是组的数量, dwGroup 是包含字符串的组索引, index 是组中字符串(0..15)的索引。

  Function MakeRtStringId(dwGroups, dwGroup, Index: DWORD): DWORD;
  Var
    dwIndex : DWORD;
  Begin
    dwIndex := 4096 - (dwGroups - dwGroup);
    Result  := (dwIndex shl 4) or Index;
  End;

如果您想出任何答案,请发布备用答案。

[编辑]凄惨地,为什么倒下?是因为我不解释?最多有65535个字符串,以16个为一组分组,最多可提供4096个字符串。字符串ID&#34;开始&#34; at,65535和减量,所以如果你有15个字符串,那么ID为655 19 ,655 20 ,655 21 ,[...] , 65535 。等等,因为最后一个id总是65535.最后一个数字是字符串是&#34; index&#34;在组中,因为单个十六进制数字是0-F(0-15)。提示&#34; 16&#34;组。 感谢Remy Lebeau的信息