Skip to content

Commit

Permalink
Apply pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lethosor committed Aug 10, 2023
1 parent 2629f66 commit 61f31f6
Show file tree
Hide file tree
Showing 37 changed files with 2,892 additions and 2,898 deletions.
3 changes: 1 addition & 2 deletions codegen_c_hdr.pl
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ sub render_item_compound {
} elsif ($subtype eq 'enum') {
if (!$item->getAttribute('type-name')) {
# inline enum
render_global_enum($sname, $item);
render_global_enum($sname, $item);
render_item_number($item, $name, $sname);
} else {
render_item_number($item, $name);
Expand Down Expand Up @@ -818,4 +818,3 @@ sub render_item_bytes {
for (@lines_full) {
print "$_\n" if $_ =~ /TODO/;
}

4 changes: 2 additions & 2 deletions df_creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@

struct df_job_link {
struct df_job *job;
struct df_job_link *prev; // goes up to DwarfFortress.exe#.data
struct df_job_link *prev; // goes up to DwarfFortress.exe#.data
struct df_job_link *next;
};

Expand Down Expand Up @@ -183,7 +183,7 @@
uint32_t civ; // 108
uint32_t unk_10c;
int32_t unk_110;

std::vector<uint32_t> unk_114;
std::vector<uint32_t> unk_124;
std::vector<uint32_t> unk_134;
Expand Down
72 changes: 36 additions & 36 deletions df_patchmalloc.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
dlc = dasm.decode_c_struct('dll_characteristics', pe.optheader.image_base + pe.coff_offset + pe.header.sizeof(pe) + pe.optheader.offsetof(pe, :dll_characts))
case dlc.dll_characteristics
when 0x8140, 0x8160
dlc.dll_characteristics ^= 0x40
dlc.dll_characteristics ^= 0x40
when 0x8100, 0x8120
puts 'dll_characteristics already patched'
puts 'dll_characteristics already patched'
else
raise 'invalid dll_characteristics!'
raise 'invalid dll_characteristics!'
end


Expand All @@ -45,9 +45,9 @@
raise 'cant find iat?' if not iat
sec_write = Metasm::COFF::SECTION_CHARACTERISTIC_BITS.index('MEM_WRITE')
if iat.characteristics & sec_write > 0
puts 'already patched'
puts 'already patched'
else
iat.characteristics |= sec_write
iat.characteristics |= sec_write
end


Expand All @@ -60,42 +60,42 @@
cur_addr = holes.shift
raise 'no hole' if not cur_addr
assemble = lambda { |src, may_jmp|
# encode the source instructions
sc = Metasm::Shellcode.new(dasm.cpu, cur_addr)
sc.assemble(src)
raw = sc.encode_string
# if they fit in the code, + leave space for a jmp
check_len = raw.length
check_len += ((holes.first > cur_addr+129+raw.length) ? 5 : 2) if may_jmp
ed = dasm.get_edata_at(cur_addr)
if ed.data[ed.ptr, check_len].unpack('C*').uniq == [0xCC]
# patch them in, advance cur_addr
ed[ed.ptr, raw.length] = raw
cur_addr += raw.length
elsif may_jmp
next_addr = holes.shift
raise 'no hole left' if not next_addr
assemble["jmp $+#{next_addr-cur_addr}", false]
cur_addr = next_addr
assemble[src, may_jmp]
else
raise 'hole too small?'
end
# encode the source instructions
sc = Metasm::Shellcode.new(dasm.cpu, cur_addr)
sc.assemble(src)
raw = sc.encode_string
# if they fit in the code, + leave space for a jmp
check_len = raw.length
check_len += ((holes.first > cur_addr+129+raw.length) ? 5 : 2) if may_jmp
ed = dasm.get_edata_at(cur_addr)
if ed.data[ed.ptr, check_len].unpack('C*').uniq == [0xCC]
# patch them in, advance cur_addr
ed[ed.ptr, raw.length] = raw
cur_addr += raw.length
elsif may_jmp
next_addr = holes.shift
raise 'no hole left' if not next_addr
assemble["jmp $+#{next_addr-cur_addr}", false]
cur_addr = next_addr
assemble[src, may_jmp]
else
raise 'hole too small?'
end
}


hooked_new_addr = cur_addr
puts 'store hooked new() at %X' % hooked_new_addr
# whenever the program calls new(), it will call this code instead
hooked_new_asm = <<EOS
push [esp+4] // arg = alloc size
call [#{iat_bak_addr}] // call original new()
push [esp+8] // arg = alloc size (new() is cdecl)
push 0x33 // pattern
push eax // retval = alloced addr
push [esp+4] // arg = alloc size
call [#{iat_bak_addr}] // call original new()
push [esp+8] // arg = alloc size (new() is cdecl)
push 0x33 // pattern
push eax // retval = alloced addr
call [#{iat_memset}]
add esp, 16 // fix stack (memset + new are cdecl)
ret // memset returns the alloced addr
add esp, 16 // fix stack (memset + new are cdecl)
ret // memset returns the alloced addr
EOS

hooked_new_asm.each_line { |l| assemble[l, true] }
Expand All @@ -110,10 +110,10 @@
# on program start, it will patch its IAT for new() to point to hooked_new
iat_hook_asm = <<EOS
push [#{iat_new}]
pop [#{iat_bak_addr}] // save original new() at iat_hook
pop [#{iat_bak_addr}] // save original new() at iat_hook
push #{hooked_new_addr}
pop [#{iat_new}] // put hooked_new address instead
jmp #{orig_entrypoint} // back to entrypoint
pop [#{iat_new}] // put hooked_new address instead
jmp #{orig_entrypoint} // back to entrypoint
EOS

iat_hook_asm.each_line { |l| assemble[l, true] }
Expand Down
Loading

0 comments on commit 61f31f6

Please sign in to comment.